Files
thinkyu/branches/1150807/MobileSurvey/SurveyForm.aspx.cs
T
sryang 577060bc78 chore: 首次簽入 Thinkyu ASP.NET 專案
- 加入 Visual Studio / ASP.NET .gitignore
- 排除建置輸出、IDE 設定、NuGet packages、大型 MSI 安裝檔
2026-09-10 09:42:37 +08:00

196 lines
7.9 KiB
C#

using System;
using System.Data.Common;
using System.Web;
using System.Web.UI.WebControls;
using WebLib;
namespace Education.MobileSurvey
{
public partial class SurveyForm : System.Web.UI.Page
{
private DAC_滿意度調查 Dao滿意度調查;
private DAC_心得報告 Dao心得報告;
private DAC_訓練課程內容 Dao訓練課程內容;
private DAC_訓練課程企劃 Dao訓練課程企劃;
private DAC_滿意度調查講師 Dao滿意度調查講師;
private DAC_滿意度調查課程企劃 Dao滿意度調查課程企劃;
private DataListItem footerItem;
private int 課程ID;
private string 學員ID;
protected void Page_Load(object sender, EventArgs e)
{
if (Session[PublicVariable.UserId] == null || string.IsNullOrEmpty(Session[PublicVariable.UserId].ToString()))
{
Response.Redirect("Login.aspx");
return;
}
DbConnection conn = DAC.NewConnection();
Dao滿意度調查 = new DAC_滿意度調查(conn);
Dao心得報告 = new DAC_心得報告(conn);
Dao訓練課程內容 = new DAC_訓練課程內容(conn);
Dao訓練課程企劃 = new DAC_訓練課程企劃(conn);
Dao滿意度調查講師 = new DAC_滿意度調查講師(conn);
Dao滿意度調查課程企劃 = new DAC_滿意度調查課程企劃(conn);
hf課程編號.Value = Request["course"];
hf學員.Value = Request["student"];
課程ID = DAC.GetInt32(hf課程編號.Value);
學員ID = hf學員.Value;
if (string.IsNullOrEmpty(hf課程編號.Value) || string.IsNullOrEmpty(hf學員.Value))
{
lbMessage.Text = "參數錯誤,請從問卷列表重新進入。";
btnSave.Visible = false;
return;
}
if (!IsPostBack)
{
訓練課程企劃List d1 = Dao訓練課程企劃.SelectOne(課程ID);
if (d1.Count > 0)
{
lb課程企劃.Text = string.Format("{0} {1}", d1[0].顯示編號, d1[0].訓練名稱);
}
lb學員.Text = string.Format("{0} {1}", 學員ID, Get員工姓名(學員ID));
心得報告List d = Dao心得報告.Select(false, 課程ID, 學員ID);
if (d.Count > 0)
{
txt心得.Text = d[0].心得;
txt建議.Text = d[0].建議;
}
else
{
txt心得.Text = "";
txt建議.Text = "";
}
訓練課程內容List courses = Dao訓練課程內容.SelectBy課程企劃(課程ID);
DataList1.DataSource = courses;
DataList1.DataBind();
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
if (!CheckRequired())
{
lbMessage.Text = "尚有項目未填寫完整,請填寫完整再儲存!";
ClientShowMessage("尚有項目未填寫完整,請填寫完整再儲存!");
return;
}
foreach (DataListItem item in DataList1.Items)
{
int 課程序號 = DAC.GetInt32((item.FindControl("hf課程序號") as HiddenField).Value);
RadioButtonList rbl1 = item.FindControl("rbl1") as RadioButtonList;
RadioButtonList rbl2 = item.FindControl("rbl2") as RadioButtonList;
RadioButtonList rbl3 = item.FindControl("rbl3") as RadioButtonList;
RadioButtonList rbl4 = item.FindControl("rbl4") as RadioButtonList;
Dao滿意度調查.Update(課程ID, 學員ID, 課程序號, 1, DAC.GetInt32(rbl1.SelectedValue), 學員ID);
Dao滿意度調查.Update(課程ID, 學員ID, 課程序號, 2, DAC.GetInt32(rbl2.SelectedValue), 學員ID);
Dao滿意度調查.Update(課程ID, 學員ID, 課程序號, 3, DAC.GetInt32(rbl3.SelectedValue), 學員ID);
Dao滿意度調查.Update(課程ID, 學員ID, 課程序號, 4, DAC.GetInt32(rbl4.SelectedValue), 學員ID);
Dao滿意度調查講師.Update(課程ID, 學員ID, 課程序號, 學員ID);
}
RadioButtonList frbl1 = footerItem.FindControl("rbl1") as RadioButtonList;
RadioButtonList frbl2 = footerItem.FindControl("rbl2") as RadioButtonList;
RadioButtonList frbl3 = footerItem.FindControl("rbl3") as RadioButtonList;
RadioButtonList frbl4 = footerItem.FindControl("rbl4") as RadioButtonList;
Dao滿意度調查.Update(課程ID, 學員ID, 0, 1, DAC.GetInt32(frbl1.SelectedValue), 學員ID);
Dao滿意度調查.Update(課程ID, 學員ID, 0, 2, DAC.GetInt32(frbl2.SelectedValue), 學員ID);
Dao滿意度調查.Update(課程ID, 學員ID, 0, 3, DAC.GetInt32(frbl3.SelectedValue), 學員ID);
Dao滿意度調查.Update(課程ID, 學員ID, 0, 4, DAC.GetInt32(frbl4.SelectedValue), 學員ID);
Dao滿意度調查課程企劃.Update(課程ID, 學員ID, 學員ID);
Dao心得報告.Update(課程ID, 學員ID, txt建議.Text, txt心得.Text, 學員ID);
Response.Redirect("Complete.aspx");
}
protected void DataList1_ItemCreated(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Footer)
{
footerItem = e.Item;
}
}
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem ||
e.Item.ItemType == ListItemType.Footer)
{
RadioButtonList rbl1 = e.Item.FindControl("rbl1") as RadioButtonList;
RadioButtonList rbl2 = e.Item.FindControl("rbl2") as RadioButtonList;
RadioButtonList rbl3 = e.Item.FindControl("rbl3") as RadioButtonList;
RadioButtonList rbl4 = e.Item.FindControl("rbl4") as RadioButtonList;
int 課程序號 = 0;
if (e.Item.ItemType != ListItemType.Footer)
課程序號 = DAC.GetInt32((e.Item.FindControl("hf課程序號") as HiddenField).Value);
滿意度調查List d1 = Dao滿意度調查.SelectOne(課程ID, 學員ID, 課程序號, 1);
滿意度調查List d2 = Dao滿意度調查.SelectOne(課程ID, 學員ID, 課程序號, 2);
滿意度調查List d3 = Dao滿意度調查.SelectOne(課程ID, 學員ID, 課程序號, 3);
滿意度調查List d4 = Dao滿意度調查.SelectOne(課程ID, 學員ID, 課程序號, 4);
if (d1.Count > 0 && !string.IsNullOrEmpty(DAC.GetString(d1[0].分數)))
rbl1.SelectedValue = DAC.GetString(d1[0].分數);
if (d2.Count > 0 && !string.IsNullOrEmpty(DAC.GetString(d2[0].分數)))
rbl2.SelectedValue = DAC.GetString(d2[0].分數);
if (d3.Count > 0 && !string.IsNullOrEmpty(DAC.GetString(d3[0].分數)))
rbl3.SelectedValue = DAC.GetString(d3[0].分數);
if (d4.Count > 0 && !string.IsNullOrEmpty(DAC.GetString(d4[0].分數)))
rbl4.SelectedValue = DAC.GetString(d4[0].分數);
}
}
private bool CheckRequired()
{
foreach (DataListItem item in DataList1.Items)
{
RadioButtonList rbl1 = item.FindControl("rbl1") as RadioButtonList;
RadioButtonList rbl2 = item.FindControl("rbl2") as RadioButtonList;
RadioButtonList rbl3 = item.FindControl("rbl3") as RadioButtonList;
RadioButtonList rbl4 = item.FindControl("rbl4") as RadioButtonList;
if (rbl1 != null && string.IsNullOrEmpty(rbl1.SelectedValue))
return false;
if (rbl2 != null && string.IsNullOrEmpty(rbl2.SelectedValue))
return false;
if (rbl3 != null && string.IsNullOrEmpty(rbl3.SelectedValue))
return false;
if (rbl4 != null && string.IsNullOrEmpty(rbl4.SelectedValue))
return false;
}
return true;
}
private string Get員工姓名(string 員工ID)
{
DAC_BPSN dao = new DAC_BPSN(DAC.NewConnection());
return dao.Get員工姓名(員工ID);
}
private void ClientShowMessage(string message)
{
ClientScript.RegisterStartupScript(Page.GetType(), "msg",
string.Format("alert(\"{0}\");", message), true);
}
protected void btnBack_Click(object sender, EventArgs e)
{
Response.Redirect("SurveyList.aspx");
}
}
}