Files
thinkyu/教育訓練系統/Web/Forms/課程企劃/ChangeTeacher.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

209 lines
7.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using WebLib;
namespace Education.Forms.課程企劃
{
public partial class ChangeTeacher : FormBase
{
private DAC_訓練課程企劃 Dao課程企劃;
private DAC_訓練課程內容 Dao課程內容;
private DAC_講師異動 Dao講師異動;
private int 課程企劃ID;
private int 課程序號;
protected void Page_Load(object sender, EventArgs e)
{
FunctionName = "訓練課程企劃書 >> 課程內容 >> 講師異動";
Title = FunctionName;
if (!IsPostBack)
{
hf課程企劃ID.Value = Request["id"];
hf課程序號.Value = Request["class"];
}
課程企劃ID = DAC.GetInt32(hf課程企劃ID.Value);
課程序號 = DAC.GetInt32(hf課程序號.Value);
Dao課程企劃 = new DAC_訓練課程企劃(conn);
Dao課程內容 = new DAC_訓練課程內容(conn);
Dao講師異動 = new DAC_講師異動(conn);
Form_View = FormView1;
Grid_View = GridView1;
Grid_View.DataBind();
if (!IsPostBack)
UpdateUI();
btnSelect.OnClientClick = String.Format("selectTeacher(\"{0}\", \"{1}\", \"{2}\", \"{3}\", \"{4}\"); return false;",
hf選定講師.ClientID, lb選定講師.ClientID, txt講師姓名.ClientID, txt學歷.ClientID, txt現職.ClientID);
btnClear.OnClientClick = String.Format("clearTeacher(\"{0}\", \"{1}\", \"{2}\", \"{3}\", \"{4}\"); return false;",
hf選定講師.ClientID, lb選定講師.ClientID, txt講師姓名.ClientID, txt學歷.ClientID, txt現職.ClientID);
if (Master is PopupForm popupForm)
{
popupForm.RefreshOpener = true;
}
}
private void UpdateUI()
{
訓練課程企劃List v1 = Dao課程企劃.SelectOne(課程企劃ID);
訓練課程內容List v2 = Dao課程內容.SelectOne(課程企劃ID, 課程序號);
if (v1.Count > 0)
{
lb課程企劃.Text = String.Format("[{0}] {1}", v1[0].顯示編號, v1[0].訓練名稱);
}
if (v2.Count > 0)
{
lb課程內容.Text = String.Format("[{0}] {1}", v2[0].節次, v2[0].課程名稱);
}
講師異動List v3 = Dao講師異動.Select最後異動(課程企劃ID, 課程序號);
if (v3.Count > 0 && v3[0].講師編號 == 0 && !String.IsNullOrEmpty(v3[0].講師姓名))
{
lb目前講師.Text = String.Format("{0}(自由輸入)", v3[0].講師姓名);
}
else
{
講師 d = GetData.取得選定講師(課程企劃ID, 課程序號);
lb目前講師.Text = String.Format("[{0:0000}] {1}", d.編號, d.姓名);
}
gv講師異動.DataBind();
}
protected void dsForm_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
{
e.ObjectInstance = Dao講師;
}
protected void dsGrid_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
{
e.ObjectInstance = Dao講師;
}
protected void btnSearch_Click(object sender, EventArgs e)
{
Grid_View.PageIndex = 0;
Grid_View.DataBind();
}
protected override void FormView_DataBound(object sender, EventArgs e)
{
base.FormView_DataBound(sender, e);
if (Form_View.CurrentMode == FormViewMode.ReadOnly)
{
int 編號 = 0;
Label lb編號 = (Form_View.FindControl("lb編號") as Label);
if (lb編號 != null)
編號 = DAC.GetInt32(lb編號.Text);
Image image1 = (Form_View.FindControl("Image1") as Image);
if (image1 != null)
{
string[] tmp = image1.ImageUrl.Split('?');
if (tmp.Length > 0 && !File.Exists(Server.MapPath(tmp[0])))
{
image1.ImageUrl = "~/picture/nopicture.jpg";
image1.Attributes.Remove("onclick");
image1.Style.Remove("cursor");
}
else
{
image1.Attributes.Add("onclick", GetOpenWindowJS("../Common/ShowLargePicture.aspx", "_picture", "pic", String.Format(Education.PublicVariable.講師照片路徑 + "{0:000000}.jpg", 編號)));
image1.Style.Add("cursor", "pointer");
}
}
}
}
protected string GetFormControlId(string id)
{
if (FormView1.PageIndex >= 0)
{
Control ctrl = FormView1.FindControl(id);
if (ctrl != null)
return FormView1.FindControl(id).ClientID;
else
return "";
}
else
{
return "";
}
}
protected void btnSelect_Click(object sender, EventArgs e)
{
hf選定講師.Value = DAC.GetString(Form_View.SelectedValue);
lb選定講師.Text = String.Format("[{0:0000}] {1}", Form_View.SelectedValue, Get講師姓名(Form_View.SelectedValue));
int 編號 = DAC.GetInt32(Form_View.SelectedValue);
講師List d = Dao講師.SelectOne(編號);
if (d.Count > 0)
{
txt講師姓名.Text = d[0].姓名;
txt講師姓名.Enabled = false;
txt學歷.Text = d[0].最高學歷學校 + d[0].最高學歷科系;
txt學歷.Enabled = false;
txt現職.Text = d[0].現職;
txt現職.Enabled = false;
}
}
protected void btnClear_Click(object sender, EventArgs e)
{
hf選定講師.Value = "";
lb選定講師.Text = "";
txt講師姓名.Text = "";
txt講師姓名.Enabled = true;
txt學歷.Text = "";
txt學歷.Enabled = true;
txt現職.Text = "";
txt現職.Enabled = true;
}
protected void btnSave_Click(object sender, EventArgs e)
{
if (hf選定講師.Value.Length == 0 && String.IsNullOrEmpty(txt講師姓名.Text))
{
lbMessage選擇講師.Text = "請從講師清單選擇或直接輸入講師姓名!";
return;
}
講師異動 newValue = new 講師異動();
newValue.課程企劃編號 = 課程企劃ID;
newValue.課程序號 = 課程序號;
newValue.講師編號 = DAC.GetInt32(hf選定講師.Value);
newValue.講師姓名 = txt講師姓名.Text;
newValue.學歷 = txt學歷.Text;
newValue.現職 = txt現職.Text;
newValue.DB_CRUSR = UserId;
Dao講師異動.InsertOne(newValue);
UpdateUI();
txt講師姓名.Enabled = true;
txt學歷.Enabled = true;
txt現職.Enabled = true;
ClientShowMessage("儲存成功!");
}
protected void gv講師異動_RowDeleted(object sender, GridViewDeletedEventArgs e)
{
UpdateUI();
}
}
}