244 lines
7.9 KiB
C#
244 lines
7.9 KiB
C#
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<CheckBox>(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<CheckBox>(row.Cells[0], "cb寄送");
|
|
Label 姓名 = FindControl<Label>(row.Cells[1], "lb學員姓名");
|
|
HiddenField 學員編號 = FindControl<HiddenField>(row.Cells[1], "hf學員編號");
|
|
TextBox 電子郵件 = FindControl<TextBox>(row.Cells[1], "txt電子郵件");
|
|
|
|
if (cb寄送 == null)
|
|
continue;
|
|
|
|
if (cb寄送.Checked)
|
|
{
|
|
發送郵件.發送學員異動通知郵件(姓名.Text, 電子郵件.Text,
|
|
txt聯絡人.Text, txt聯絡人電話.Text, txt聯絡人email.Text, 公司名稱,
|
|
訓練課程企劃[0].訓練日期, 訓練課程企劃[0].訓練日期迄, 訓練課程企劃[0].訓練名稱, 場地名稱,
|
|
訓練課程企劃[0].訓練時數, 通知內容);
|
|
|
|
// 標記已發送
|
|
Dao訓練課程異動通知發送紀錄.標記已發送(編號, 異動通知項次, 學員編號.Value, UserId);
|
|
}
|
|
}
|
|
|
|
發送郵件.發送學員異動通知郵件(txt聯絡人.Text, txt聯絡人email.Text,
|
|
txt聯絡人.Text, txt聯絡人電話.Text, txt聯絡人email.Text, 公司名稱,
|
|
訓練課程企劃[0].訓練日期, 訓練課程企劃[0].訓練日期迄, 訓練課程企劃[0].訓練名稱,
|
|
場地名稱, 訓練課程企劃[0].訓練時數, 通知內容);
|
|
}
|
|
|
|
protected void ds已截止未上課_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
|
|
{
|
|
e.ObjectInstance = Dao訓練課程企劃;
|
|
}
|
|
|
|
protected void ds報名學員_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
|
|
{
|
|
e.ObjectInstance = Dao課程報名;
|
|
}
|
|
|
|
protected void ds異動通知_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
|
|
{
|
|
e.ObjectInstance = Dao訓練課程異動通知;
|
|
}
|
|
|
|
protected void gv學員_DataBound(object sender, EventArgs e)
|
|
{
|
|
//
|
|
}
|
|
|
|
private void SetSelected(bool selected, bool 跳過已寄送過 = false)
|
|
{
|
|
foreach (GridViewRow row in gv學員.Rows)
|
|
{
|
|
if (row.RowType != DataControlRowType.DataRow)
|
|
continue;
|
|
|
|
CheckBox cb = FindControl<CheckBox>(row.Cells[0], "cb寄送");
|
|
HiddenField hf = FindControl<HiddenField>(row.Cells[3], "hf通知發送狀態");
|
|
|
|
if (cb == null || hf == null)
|
|
continue;
|
|
|
|
cb.Checked = selected;
|
|
if (selected && 跳過已寄送過 && hf.Value == "Y")
|
|
cb.Checked = false;
|
|
}
|
|
}
|
|
|
|
protected void btn全選_Click(object sender, EventArgs e)
|
|
{
|
|
SetSelected(true);
|
|
}
|
|
|
|
protected void btn不選_Click(object sender, EventArgs e)
|
|
{
|
|
SetSelected(false);
|
|
}
|
|
|
|
protected string Get異動通知發送狀態(object 學員編號)
|
|
{
|
|
if (gv異動通知.SelectedDataKey != null)
|
|
{
|
|
if (Dao訓練課程異動通知發送紀錄.是否已發送(DAC.GetInt32(gv異動通知.SelectedDataKey["編號"]),
|
|
DAC.GetInt32(gv異動通知.SelectedDataKey["異動通知項次"]),
|
|
DAC.GetString(學員編號)))
|
|
return "已發送";
|
|
}
|
|
return "";
|
|
}
|
|
|
|
protected void gv異動通知_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
gv學員.DataBind();
|
|
}
|
|
|
|
protected void gv異動通知_RowCommand(object sender, GridViewCommandEventArgs e)
|
|
{
|
|
訓練課程異動通知List d = Dao訓練課程異動通知.SelectOne(訓練企劃搜尋.訓練企劃編號,
|
|
DAC.GetInt32(e.CommandArgument));
|
|
|
|
if (d.Count > 0)
|
|
{
|
|
發送通知郵件(訓練企劃搜尋.訓練企劃編號, DAC.GetInt32(e.CommandArgument),
|
|
d[0].異動通知內容, false);
|
|
|
|
for (int i=0; i< gv異動通知.DataKeys.Count; i++)
|
|
{
|
|
DataKey k = gv異動通知.DataKeys[i];
|
|
if (DAC.GetInt32(k[1]) == DAC.GetInt32(e.CommandArgument))
|
|
{
|
|
gv異動通知.SelectedIndex = i;
|
|
break;
|
|
}
|
|
}
|
|
|
|
gv學員.DataBind();
|
|
ClientShowMessage("學員課程異動通知發送完畢");
|
|
}
|
|
}
|
|
}
|
|
}
|