chore: 首次簽入 Thinkyu ASP.NET 專案
- 加入 Visual Studio / ASP.NET .gitignore - 排除建置輸出、IDE 設定、NuGet packages、大型 MSI 安裝檔
This commit is contained in:
@@ -0,0 +1,286 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using WebLib;
|
||||
|
||||
namespace Education
|
||||
{
|
||||
public partial class FormBase : WebLib.FormBase
|
||||
{
|
||||
// 資料存取類別變數
|
||||
//protected DAC_部門 Dao部門 = new DAC_部門();
|
||||
public DAC_GetData GetData;
|
||||
public DAC_場地 Dao場地;
|
||||
public DAC_講師 Dao講師;
|
||||
public DAC_BCLS Dao類別;
|
||||
public DAC_BPSN Dao員工;
|
||||
public DAC_職務 Dao職務;
|
||||
public DAC_組織圖 Dao組織圖;
|
||||
public DAC_課程 Dao課程;
|
||||
public DAC_公司別 Dao公司別 = new DAC_公司別();
|
||||
public DAC_訓練課程企劃 Dao訓練課程企劃;
|
||||
public DAC_課程報名 Dao課程報名;
|
||||
public DAC_表單簽核主檔 Dao表單簽核主檔;
|
||||
public DAC_站別 Dao站別;
|
||||
public DAC_片語 Dao片語;
|
||||
|
||||
protected override void OnPreInit(EventArgs e)
|
||||
{
|
||||
base.OnPreInit(e);
|
||||
systemName = PublicVariable.SystemName;
|
||||
|
||||
GetData = new DAC_GetData();
|
||||
Dao類別 = new DAC_BCLS(conn);
|
||||
Dao員工 = new DAC_BPSN(conn);
|
||||
Dao職務 = new DAC_職務(conn);
|
||||
Dao場地 = new DAC_場地(conn);
|
||||
Dao講師 = new DAC_講師(conn);
|
||||
Dao組織圖 = new DAC_組織圖(conn);
|
||||
Dao課程 = new DAC_課程(conn);
|
||||
Dao訓練課程企劃 = new DAC_訓練課程企劃(conn);
|
||||
Dao課程報名 = new DAC_課程報名(conn);
|
||||
Dao表單簽核主檔 = new DAC_表單簽核主檔(conn);
|
||||
Dao站別 = new DAC_站別(conn);
|
||||
Dao片語 = new DAC_片語(conn);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 向 ScriptManager 註冊要 觸發Postback 的控制項
|
||||
/// </summary>
|
||||
/// <param name="ctrl"></param>
|
||||
public void RegisterPostbackTrigger(Control ctrl)
|
||||
{
|
||||
if (ScriptManager.GetCurrent(Page) != null && ctrl != null)
|
||||
{
|
||||
ScriptManager.GetCurrent(Page).RegisterPostBackControl(ctrl);
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool IsSetMasterPage()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 公司別編號
|
||||
/// </summary>
|
||||
public string CompanyId
|
||||
{
|
||||
get
|
||||
{
|
||||
return DAC.GetString(Session[PublicVariable.CompanyId]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 公司別名稱
|
||||
/// </summary>
|
||||
public string CompanyName
|
||||
{
|
||||
get
|
||||
{
|
||||
return Dao公司別.GetName(Session[PublicVariable.CompanyId]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判斷目前的使用者是否為某個群組的成員
|
||||
/// </summary>
|
||||
/// <param name="group_id"></param>
|
||||
/// <returns></returns>
|
||||
public bool UserInGroup(string group_id)
|
||||
{
|
||||
List<string> groups = (Session[PublicVariable.UserGroups] as List<string>);
|
||||
|
||||
if (groups != null)
|
||||
return groups.Contains(group_id);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 目前的使用者是否屬於管理群組
|
||||
/// </summary>
|
||||
public bool IsManager
|
||||
{
|
||||
get
|
||||
{
|
||||
return DAC.GetBoolean(Session[PublicVariable.IsManager]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 目前的使用者是否屬於承辦人群組
|
||||
/// </summary>
|
||||
public bool IsWorker
|
||||
{
|
||||
get
|
||||
{
|
||||
return DAC.GetBoolean(Session[PublicVariable.IsWorker]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 目前是否登入後台
|
||||
/// </summary>
|
||||
public bool IsBackend
|
||||
{
|
||||
get
|
||||
{
|
||||
return DAC.GetBoolean(Session[PublicVariable.IsBackend]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 設定 Linkbutton 的 Enabled
|
||||
/// </summary>
|
||||
public void SetWebControlEnabled(WebControl ctrl, bool enabled)
|
||||
{
|
||||
if (ctrl == null)
|
||||
return;
|
||||
|
||||
ctrl.Enabled = enabled;
|
||||
if (enabled)
|
||||
{
|
||||
ctrl.Attributes.Remove("disabled");
|
||||
}
|
||||
else
|
||||
{
|
||||
ctrl.Attributes["disabled"] = "disabled";
|
||||
}
|
||||
}
|
||||
|
||||
public void ClientShowMessage(string message, string url = "")
|
||||
{
|
||||
if (System.Web.UI.ScriptManager.GetCurrent(this) != null)
|
||||
{
|
||||
if (url == null || url.Length == 0)
|
||||
{
|
||||
System.Web.UI.ScriptManager.RegisterStartupScript(this, Page.GetType(), "client_mesage",
|
||||
String.Format("alert(\"{0}\");", StringTable.GetString(message)), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Web.UI.ScriptManager.RegisterStartupScript(this, Page.GetType(), "client_mesage",
|
||||
String.Format("alert(\"{0}\"); window.location=\"{1}\";", StringTable.GetString(message), url), true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
base.ClientShowMessage(message, url);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 從 Validator 所在的 FormView 樣板尋找控制項並取得其值。
|
||||
/// </summary>
|
||||
protected string FindFormValue(object source, string controlId)
|
||||
{
|
||||
Control container = (source as Control)?.NamingContainer;
|
||||
while (container != null)
|
||||
{
|
||||
Control control = container.FindControl(controlId);
|
||||
if (control is ListControl list)
|
||||
return list.SelectedValue ?? "";
|
||||
if (control is ITextControl text)
|
||||
return text.Text ?? "";
|
||||
container = container.NamingContainer;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 以泛型取得容器內指定型別的控制項。
|
||||
/// </summary>
|
||||
protected T FindControl<T>(Control container, string controlId) where T : class
|
||||
{
|
||||
return container == null ? null : container.FindControl(controlId) as T;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#region 資料查找相關
|
||||
|
||||
public string Get類別名稱(object 類別大類, object 類別編號)
|
||||
{
|
||||
return Dao類別.Get類別名稱(類別大類, 類別編號);
|
||||
}
|
||||
|
||||
public string Get員工姓名(object 員工編號)
|
||||
{
|
||||
return Dao員工.Get員工姓名(員工編號);
|
||||
}
|
||||
|
||||
public string Get職務名稱(object 職務ID)
|
||||
{
|
||||
return Dao職務.Get職務名稱(職務ID);
|
||||
}
|
||||
|
||||
public string Get組織名稱(object 組織ID)
|
||||
{
|
||||
return Dao組織圖.Get組織名稱(組織ID);
|
||||
}
|
||||
|
||||
public string Get場地名稱(object 場地ID)
|
||||
{
|
||||
return Dao場地.Get場地名稱(場地ID);
|
||||
}
|
||||
|
||||
public string Get講師姓名(object 講師ID)
|
||||
{
|
||||
return Dao講師.Get姓名(講師ID);
|
||||
}
|
||||
|
||||
public string Get訓練企劃名稱(object 訓練企劃ID)
|
||||
{
|
||||
訓練課程企劃List d = Dao訓練課程企劃.SelectOne(DAC.GetInt32(訓練企劃ID));
|
||||
if (d.Count == 0)
|
||||
return "";
|
||||
else
|
||||
return d[0].訓練名稱;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 格式檢查相關
|
||||
|
||||
/// <summary>
|
||||
/// 驗證電子郵件格式
|
||||
/// </summary>
|
||||
public static bool IsValidEmail(string email)
|
||||
{
|
||||
if (string.IsNullOrEmpty(email))
|
||||
return false;
|
||||
|
||||
// 基本格式檢查
|
||||
string pattern = @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$";
|
||||
if (!System.Text.RegularExpressions.Regex.IsMatch(email, pattern))
|
||||
return false;
|
||||
|
||||
// 進階檢查(使用 .NET 內建類別)
|
||||
try
|
||||
{
|
||||
var addr = new System.Net.Mail.MailAddress(email);
|
||||
return (addr.Address == email);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 片語
|
||||
protected string GetPhraseClientClick(string controlId, string content)
|
||||
{
|
||||
string CID = "";
|
||||
CID = (Form_View.FindControl(controlId) as Control).ClientID;
|
||||
if (CID.Length > 0)
|
||||
return String.Format("javascript:FillMessage(\"{0}\", \"{1}\");return false;", CID, content);
|
||||
else
|
||||
return "javascript:return false;";
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user