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 學員課程異動通知 : FormBase { private DAC_訓練課程異動通知 Dao訓練課程異動通知; private DAC_訓練課程異動通知發送紀錄 Dao訓練課程異動通知發送紀錄; protected void Page_Load(object sender, EventArgs e) { FunctionName = "學員課程異動通知"; Dao訓練課程異動通知 = new DAC_訓練課程異動通知(conn); Dao訓練課程異動通知發送紀錄 = new DAC_訓練課程異動通知發送紀錄(conn); if (IsPostBack) { gv異動通知.DataBind(); gv學員.DataBind(); } } protected void Page_LoadComplete(object sender, EventArgs e) { } protected void btn查詢_Click(object sender, EventArgs e) { if (訓練企劃搜尋.訓練企劃編號 == 0) { Panel1.Visible = false; lbMessage.Text = "請選擇課程企劃"; return; } Get課程資料(); ddl計畫.DataBind(); } protected void btn查詢學員_Click(object sender, EventArgs e) { gv學員.DataBind(); gv異動通知.DataBind(); } private void Get課程資料() { int 課程企劃id = 訓練企劃搜尋.訓練企劃編號; 訓練課程企劃List 訓練課程企劃 = Dao訓練課程企劃.SelectOne(課程企劃id); if (訓練課程企劃.Count > 0) { txt聯絡人.Text = Dao員工.Get員工姓名(訓練課程企劃[0].承辦); txt聯絡人電話.Text = Dao員工.Get公司電話(訓練課程企劃[0].承辦); txt聯絡人email.Text = Dao員工.Get電子郵件(訓練課程企劃[0].承辦); Panel1.Visible = true; } } protected void btn發送_Click(object sender, EventArgs e) { 發送通知郵件(0, 0, txt通知內容.Text, true); gv異動通知.DataBind(); if (gv異動通知.Rows.Count > 0) gv異動通知.SelectedIndex = gv異動通知.Rows.Count - 1; gv異動通知_SelectedIndexChanged(sender, e); ClientShowMessage("學員課程異動通知發送完畢"); } private void 發送通知郵件(int 編號, int 異動通知項次, string 通知內容, bool 新通知) { int 課程企劃id = 訓練企劃搜尋.訓練企劃編號; 發送郵件 發送郵件 = new 發送郵件(); 發送郵件.Context = this.Context; 訓練課程企劃List 訓練課程企劃 = Dao訓練課程企劃.SelectOne(課程企劃id); string 場地名稱 = GetData.取得選定場地(課程企劃id).場地名稱; string 公司名稱 = new DAC_公司別().GetName(CompanyId); // 檢查是否有勾選 bool hasChecked = false; foreach (GridViewRow row in gv學員.Rows) { if (row.RowType != DataControlRowType.DataRow) continue; CheckBox cb寄送 = FindControl(row.Cells[0], "cb寄送"); if (cb寄送 == null || !cb寄送.Checked) continue; hasChecked = true; break; } if (!hasChecked) { ClientShowMessage("請勾選要發送異動通知的學員"); return; } if (新通知) { 訓練課程異動通知 newValue = new 訓練課程異動通知(); newValue.編號 = 訓練企劃搜尋.訓練企劃編號; newValue.異動通知日期 = DateTime.UtcNow.AddHours(8).Date; newValue.異動通知內容 = 通知內容; newValue.DB_CRUSR = UserId; Dao訓練課程異動通知.InsertOne(newValue); 編號 = newValue.編號; 異動通知項次 = newValue.異動通知項次; } // 發送學員通知 foreach (GridViewRow row in gv學員.Rows) { if (row.RowType != DataControlRowType.DataRow) continue; CheckBox cb寄送 = FindControl(row.Cells[0], "cb寄送"); Label 姓名 = FindControl