using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Script.Services; using System.Web.Services; using System.Web.UI; using System.Web.UI.WebControls; using WebLib; namespace Education.Forms.辦訓狀況 { public partial class 講師評鑑 : FormBase { protected DAC_講師 daoTeacher; protected DAC_講師外訓滿意度 daoEval; protected int 講師編號; protected int 編號; protected string mode; protected void Page_Load(object sender, EventArgs e) { daoTeacher = new DAC_講師(conn); daoEval = new DAC_講師外訓滿意度(conn); mode = Request["mode"]; 編號 = DAC.GetInt32(Request["id"]); 講師編號 = DAC.GetInt32(Request["teacherid"]); btnSaveAndContinue.Visible = mode == "new"; if (mode == "edit" && !IsPostBack) { LoadOne(); } } protected void ClearInput() { txt日期.Text = ""; txt地點.Text = ""; txt人數.Text = ""; txt對象.Text = ""; txt課程名稱.Text = ""; txt專業度.Text = ""; txt授課技巧.Text = ""; txt互動氛圍.Text = ""; txt內容切題.Text = ""; txt配合度.Text = ""; txt學員滿意度.Text = ""; txt講師授課方式.Text = ""; } protected bool CheckInput() { return this.IsValid; } protected void LoadOne() { var item = daoEval.SelectOne(編號).FirstOrDefault(); if (item != null) { txt日期.Value = item.日期; txt地點.Text = item.地點; txt人數.Text = DAC.GetString(item.人數); txt對象.Text = item.對象; txt課程名稱.Text = item.課程名稱; txt專業度.Text = DAC.GetString(item.專業度); txt授課技巧.Text = DAC.GetString(item.授課技巧); txt互動氛圍.Text = DAC.GetString(item.互動氛圍); txt內容切題.Text = DAC.GetString(item.內容切題); txt配合度.Text = DAC.GetString(item.配合度); txt學員滿意度.Text = DAC.GetString(item.學員滿意度); txt跟課觀察.Text = DAC.GetString(item.跟課觀察); txt講師授課方式.Text = DAC.GetString(item.講師授課方式); } } protected bool SaveOne() { if (mode == "new") { try { var newItem = daoEval.InsertOne(new 講師外訓滿意度Item() { 講師編號 = 講師編號, 日期 = txt日期.Value, 地點 = txt地點.Text, 人數 = DAC.GetInt32(txt人數.Text), 對象 = txt對象.Text, 課程名稱 = txt課程名稱.Text, 專業度 = DAC.GetInt32(txt專業度.Text), 授課技巧 = DAC.GetInt32(txt授課技巧.Text), 互動氛圍 = DAC.GetInt32(txt互動氛圍.Text), 內容切題 = DAC.GetInt32(txt內容切題.Text), 配合度 = DAC.GetInt32(txt配合度.Text), 學員滿意度 = DAC.GetInt32(txt學員滿意度.Text), 跟課觀察 = txt跟課觀察.Text, 講師授課方式 = txt講師授課方式.Text, }); return true; } catch (Exception ex) { ClientShowMessage(string.Format("存檔過程中發生錯誤:\r\n{0}", ex.Message)); return false; } } else if (mode == "edit") { try { var item = daoEval.SelectOne(編號).FirstOrDefault(); if (item != null) { item.日期 = txt日期.Value; item.地點 = txt地點.Text; item.人數 = DAC.GetInt32(txt人數.Text); item.對象 = txt對象.Text; item.課程名稱 = txt課程名稱.Text; item.專業度 = DAC.GetInt32(txt專業度.Text); item.授課技巧 = DAC.GetInt32(txt授課技巧.Text); item.互動氛圍 = DAC.GetInt32(txt互動氛圍.Text); item.內容切題 = DAC.GetInt32(txt內容切題.Text); item.配合度 = DAC.GetInt32(txt配合度.Text); item.學員滿意度 = DAC.GetInt32(txt學員滿意度.Text); item.跟課觀察 = txt跟課觀察.Text; item.講師授課方式 = txt講師授課方式.Text; } daoEval.UpdateOne(item); return true; } catch (Exception ex) { ClientShowMessage(string.Format("存檔過程中發生錯誤:\r\n{0}", ex.Message)); return false; } } return false; } protected void btnSave_Click(object sender, EventArgs e) { if (CheckInput()) { if (SaveOne()) { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "close_dialog", "window.parent.$(\"iframe#externalSite\").closest(\".ui-dialog-content\").dialog(\"close\");", true); } } } protected void btnSaveAndContinue_Click(object sender, EventArgs e) { if (CheckInput()) { if (SaveOne()) { ClearInput(); } } } protected void cv日期_ServerValidate(object source, ServerValidateEventArgs args) { args.IsValid = txt日期.Value.HasValue; } [WebMethod(EnableSession = true)] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public static bool DeleteOne(int id) { try { using (var conn = DAC.NewConnection()) { var daoEval = new DAC_講師外訓滿意度(conn); var item = daoEval.SelectOne(id).FirstOrDefault(); if (item != null) { daoEval.DeleteOne(item); return true; } return false; } } catch { return false; } } protected string GetPhraseClientClick(Control control, string content) { string CID = ""; CID = control.ClientID; if (CID.Length > 0) return String.Format("javascript:FillMessage(\"{0}\", \"{1}\");return false;", CID, content); else return "javascript:return false;"; } } }