Files
thinkyu/branches/1150807/Forms/選課/學員選課.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

129 lines
4.0 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場地遴選;
protected void Page_Load(object sender, EventArgs e)
{
FunctionName = "課程查詢及線上報名";
Dao場地遴選 = new DAC_場地遴選(conn);
if (!IsPostBack)
{
// 查詢範圍初始值為本月月初至下個月月底
DateTextBox1.Value = new DateTime(DateTime.UtcNow.AddHours(8).Date.Year, DateTime.UtcNow.AddHours(8).Date.Month, 1);
DateTextBox2.Value = new DateTime(DateTime.UtcNow.AddHours(8).Date.Year, DateTime.UtcNow.AddHours(8).Date.Month, 1).AddMonths(2).AddDays(-1);
}
else
{
GridView1.DataBind();
}
}
protected string Get訓練地點(object 課程ID)
{
return GetData.取得選定場地(DAC.GetInt32(課程ID)).場地名稱;
}
protected string Get剩餘名額(object 課程ID, object 人數)
{
int 名額 = DAC.GetInt32(人數);
int 已報名人數 = Dao課程報名.Get報名人數(DAC.GetInt32(課程ID));
if (名額 > 已報名人數)
return String.Format("{0}", 名額 - 已報名人數);
else
return "額滿";
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
訓練課程企劃 dataItem = e.Row.DataItem as 訓練課程企劃;
if (dataItem == null)
return;
TableCell cell = e.Row.Cells[5];
Literal lt狀態 = FindControl<Literal>(cell, "lb狀態");
lt狀態.Text = "";
string 報名狀態 = Dao課程報名.Get報名狀態(UserId, dataItem.編號);
int 已報名人數 = Dao課程報名.Get報名人數(dataItem.編號);
// 報名未開放
if (dataItem.開放報名日期 > DateTime.UtcNow.AddHours(8).Date)
{
lt狀態.Text = "<div style=\"color:red\">尚未開放報名</div>";
return;
}
// 已截止報名
if (dataItem.訓練日期.AddDays(-dataItem.報名截止期限) <= DateTime.UtcNow.AddHours(8).Date)
{
lt狀態.Text += "<div style=\"color:red\">已截止報名</div>";
return;
}
// 已額滿
if (已報名人數 >= dataItem.人數)
{
lt狀態.Text += "<div style=\"color:red\">已額滿</div>";
return;
}
// 報名狀態
if (報名狀態 == "Y")
{
lt狀態.Text += "<div style=\"color:green\">已報名(選修)</div>";
return;
}
else if (報名狀態 == "R")
{
lt狀態.Text += "<div style=\"color:green\">已報名(必修)</div>";
return;
}
// 可報名
if (已報名人數 < dataItem.人數 && 報名狀態 == "S")
{
FindControl<Control>(cell, "btn報名").Visible = true;
}
}
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
// 處理報名動作
if (e.CommandName == "報名")
{
// 1. 寫一筆報名紀錄
int 訓練課程編號 = DAC.GetInt32(e.CommandArgument);
Dao課程報名.選修報名(UserId, 訓練課程編號, UserId);
// 2. 發送報名確認郵件
訓練課程企劃List values = Dao訓練課程企劃.SelectOne(訓練課程編號);
string 電子郵件 = Dao員工.Get電子郵件(UserId);
string 員工姓名 = Dao員工.Get員工姓名(UserId);
if (values.Count > 0)
{
發送郵件 發送郵件 = new 發送郵件();
發送郵件.Context = this.Context;
發送郵件.發送報名成功郵件(員工姓名, 電子郵件, values[0].訓練日期,
values[0].訓練日期迄, values[0].訓練名稱);
}
GridView1.DataBind();
}
}
}
}