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

109 lines
3.2 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.Data;
using WebLib;
namespace Education.Forms.選課
{
public partial class 選課查詢 : FormBase
{
protected void Page_Load(object sender, EventArgs e)
{
FunctionName = "報名查詢及取消報名";
if (IsPostBack)
{
GridView1.DataBind();
}
}
protected void ds選課_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
{
e.ObjectInstance = Dao課程報名;
}
protected void ds選課_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
{
e.InputParameters["學員編號"] = UserId;
e.InputParameters["僅已簽核"] = IsBackend;
e.InputParameters["僅必修"] = false;
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (!(e.Row.DataItem is DataRowView dataItem))
return;
TableCell cell = e.Row.Cells[6];
Literal lt狀態 = FindControl<Literal>(cell, "lb狀態");
lt狀態.Text = "";
int 課程編號 = DAC.GetInt32(dataItem["訓練課程編號"]);
string 報名狀態 = DAC.GetString(dataItem["報名狀態"]);
DateTime 訓練日期 = DAC.GetDateTime(dataItem["訓練日期"]);
int 取消報名截止期限 = DAC.GetInt32(dataItem["取消報名截止期限"]);
// 已過訓練日期,狀態均不顯示
if (訓練日期 < DateTime.UtcNow.AddHours(8).Date)
return;
// 已取消,狀態均不顯示
if (報名狀態 != "Y" && 報名狀態 != "R")
return;
// 選修的,未到取消報名截止期限,可取消
if (報名狀態 == "Y")
{
if (訓練日期.AddDays(-取消報名截止期限) > DateTime.UtcNow.AddHours(8).Date)
{
cell.FindControl("btn取消報名").Visible = true;
}
else
{
lt狀態.Text += "<div style=\"color:red\">已超過取消報名截止期限</div>";
}
}
// 尚未報名
if (報名狀態 == "S")
{
}
}
}
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();
}
}
}
}