using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using WebLib; namespace Education.Forms.課程企劃 { public partial class CourseContent : FormBase { private DAC_訓練課程內容 Dao訓練課程內容; private int 課程ID; protected bool 可異動; protected void Page_Load(object sender, EventArgs e) { FunctionName = "訓練課程企劃書 >> 課程內容"; Title = FunctionName; Dao訓練課程內容 = new DAC_訓練課程內容(conn); if (!IsPostBack) { hf課程ID.Value = Request["ID"]; 課程ID = DAC.GetInt32(hf課程ID.Value); 可異動 = Dao表單簽核主檔.表單可異動("課程企劃", DAC.GetString(課程ID)); 訓練課程企劃List v1 = Dao訓練課程企劃.SelectOne(課程ID); if (v1.Count > 0) { lbID.Text = v1[0].顯示編號; lbName.Text = v1[0].訓練名稱; } } else { 課程ID = DAC.GetInt32(hf課程ID.Value); 可異動 = Dao表單簽核主檔.表單可異動("課程企劃", DAC.GetString(課程ID)); gv課程挑選.DataBind(); gv課程內容.DataBind(); } btnRenum.Visible = 可異動; pnlUpdate.Visible = 可異動; gv課程內容.ShowHeader = !可異動; (Master as PopupForm).RefreshOpener = true; } protected void btnSelect課程_Click(object sender, EventArgs e) { if (ddl課程類別Search.SelectedValue == null || ddl課程類別Search.SelectedValue.Length == 0) { lbMessage課程內容.Text = "請選擇一個課程類別再查詢"; return; } gv課程挑選.DataBind(); if (gv課程挑選.Rows.Count == 0) lbMessage課程內容.Text = "找不到合乎條件的課程"; } protected void gv課程挑選_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Select") { // 挑選此課程,把課程相關資料抓出來填入底下 課程List d = Dao課程.SelectOne(e.CommandArgument.ToString()); if (d.Count > 0) { lb類別.Text = d[0].課程類別; lb課程編號.Text = d[0].課程編號; txt課程名稱.Text = d[0].課程名稱; txt課程大綱.Text = d[0].課程內容; txt時數.Text = d[0].課程時數.ToString(); } } } protected void ds課程_ObjectCreating(object sender, ObjectDataSourceEventArgs e) { e.ObjectInstance = Dao課程; } protected void ds課程內容_ObjectCreating(object sender, ObjectDataSourceEventArgs e) { e.ObjectInstance = Dao訓練課程內容; } protected void btnInsertContent_Click(object sender, EventArgs e) { if (lb課程編號.Text.Length > 0) { // 新增課程內容 訓練課程內容 newValue = new 訓練課程內容(); newValue.訓練課程企劃編號 = 課程ID; newValue.課程序號 = Dao訓練課程內容.Next課程序號(newValue.訓練課程企劃編號); newValue.節次 = Dao訓練課程內容.Next節次(newValue.訓練課程企劃編號); newValue.課程類別 = lb類別.Text; newValue.課程編號 = lb課程編號.Text; newValue.課程名稱 = txt課程名稱.Text; newValue.課程大綱 = txt課程大綱.Text; newValue.時數 = DAC.GetInt32(txt時數.Text); newValue.訓練日期 = DAC.GetDateTime(ddl訓練日期.Text); newValue.時間起 = txt時間起.Text; newValue.時間迄 = txt時間迄.Text; newValue.DB_CRDAT = DateTime.UtcNow.AddHours(8); newValue.DB_CRUSR = UserId; Dao訓練課程內容.InsertOne(newValue); gv課程內容.DataBind(); lb類別.Text = ""; lb課程編號.Text = ""; txt課程名稱.Text = ""; txt課程大綱.Text = ""; txt時數.Text = ""; } else { lbMessage.Text = "請選擇課程"; } } protected void gv課程內容_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Up") { Dao訓練課程內容.節次Up(課程ID, DAC.GetInt32(e.CommandArgument)); gv課程內容.DataBind(); } if (e.CommandName == "Down") { Dao訓練課程內容.節次Down(課程ID, DAC.GetInt32(e.CommandArgument)); gv課程內容.DataBind(); } } protected void btnRenum_Click(object sender, EventArgs e) { Dao訓練課程內容.重排節次(課程ID); gv課程內容.DataBind(); } protected void dsBCLS_ObjectCreating(object sender, ObjectDataSourceEventArgs e) { e.ObjectInstance = Dao類別; } protected string Get選定講師(object 訓練課程企劃編號, object 課程序號) { int id = DAC.GetInt32(訓練課程企劃編號); int classNo = DAC.GetInt32(課程序號); 講師 d = GetData.取得選定講師(id, classNo); if (d.編號 == 0) { 講師異動List v = new DAC_講師異動(conn).Select最後異動(id, classNo); if (v.Count > 0 && v[0].講師編號 == 0 && !String.IsNullOrEmpty(v[0].講師姓名)) return Server.HtmlEncode(v[0].講師姓名); return ""; } else return string.Format("[{0:0000}]
{1}", d.編號, d.姓名); } protected void btnRefresh_Click(object sender, EventArgs e) { gv課程內容.DataBind(); } } }