chore: 首次簽入 Thinkyu ASP.NET 專案
- 加入 Visual Studio / ASP.NET .gitignore - 排除建置輸出、IDE 設定、NuGet packages、大型 MSI 安裝檔
This commit is contained in:
@@ -0,0 +1,468 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Configuration;
|
||||
using System.Web;
|
||||
using System.Web.Security;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Web.UI.WebControls.WebParts;
|
||||
using System.Web.UI.HtmlControls;
|
||||
using System.Collections;
|
||||
using Wellan.Web.UI;
|
||||
using Wellan.Web.View;
|
||||
using Wellan.Common;
|
||||
using System.Text;
|
||||
using Wellan.Service;
|
||||
using System.Net.Mail;
|
||||
|
||||
public partial class _Default : System.Web.UI.Page
|
||||
{
|
||||
protected string FuserLang = "";
|
||||
private string CurrPage = "";
|
||||
private string FReportDataPath = "";
|
||||
private string CurrPageKey = "__CURRPAGE__";
|
||||
private string ParamListKey = "__PARAMLIST__";
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 頁面的初始化之前事件
|
||||
/// </summary>
|
||||
protected void Page_PreInit(object sender, EventArgs e)
|
||||
{
|
||||
// 設定頁面主題
|
||||
//Page.Theme = "DefaultTheme";
|
||||
lbSystemCaption.Text = WConfig.GetCompanyName() + " " + WConfig.GetSystemName();
|
||||
|
||||
if (Request.ServerVariables["http_user_agent"].IndexOf("Safari", StringComparison.CurrentCultureIgnoreCase) != -1)
|
||||
Page.ClientTarget = "uplevel";
|
||||
//if (Request.UserAgent.Contains("AppleWebKit"))
|
||||
// Request.Browser.Adapters.Clear();
|
||||
}
|
||||
|
||||
/*
|
||||
public override string StyleSheetTheme
|
||||
{
|
||||
get
|
||||
{
|
||||
return "DefaultTheme";
|
||||
}
|
||||
set
|
||||
{
|
||||
base.StyleSheetTheme = value;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
protected void Page_Init(object sender, EventArgs e)
|
||||
{
|
||||
ScriptManager.RegisterClientScriptInclude(Page, Page.GetType(), "vue",
|
||||
ConfigurationManager.AppSettings["DEBUG"].ToUpper() == "Y" ? "utility/vue_dev.js" : "utility/vue.js");
|
||||
/*
|
||||
Hashtable ParamList;
|
||||
if (Session[ParamListKey] != null)
|
||||
ParamList = Session[ParamListKey] as Hashtable;
|
||||
else
|
||||
ParamList = new Hashtable();
|
||||
|
||||
// 需要直接載入某功能
|
||||
if (!IsPostBack && Request[WConstants.LoadForm] != null)
|
||||
{
|
||||
CurrPage = Request[WConstants.LoadForm].ToString();
|
||||
// 取出 Request 的各參數,放入準備傳入 user control 的參數列表中
|
||||
foreach (string key in Request.QueryString.AllKeys)
|
||||
{
|
||||
ParamList.Add(key, Request[key]);
|
||||
}
|
||||
Session.Remove(CurrPageKey);
|
||||
}
|
||||
// 載入目前選到的功能
|
||||
else if (Session[CurrPageKey] != null)
|
||||
{
|
||||
CurrPage = Session[CurrPageKey].ToString();
|
||||
// 移除目前頁的 Session 儲存,以免被誤用
|
||||
Session.Remove(CurrPageKey);
|
||||
}
|
||||
ParamList[WConstants.ReportDataPath] = FReportDataPath;
|
||||
LoadForm(ParamList);
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
/// <summary>
|
||||
/// 樣式表主題
|
||||
/// </summary>
|
||||
public override string StyleSheetTheme
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Default";
|
||||
}
|
||||
set
|
||||
{
|
||||
base.StyleSheetTheme = value;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
// 若 session 已消失,則登出
|
||||
if (Session[WConstants.UserId] == null)
|
||||
{
|
||||
btnLogout_Click(sender, e);
|
||||
return;
|
||||
}
|
||||
|
||||
// 擷取瀏覽器語言設定
|
||||
GetBrowserLanguage();
|
||||
|
||||
// 取得報表實體目錄
|
||||
FReportDataPath = Server.MapPath(@"~\reportData\");
|
||||
|
||||
// 建立主功能表
|
||||
WMenuGenerator menuGen = new WMenuGenerator();
|
||||
menuGen.menu = MainMenu;
|
||||
menuGen.UserLang = FuserLang;
|
||||
menuGen.UserId = Session[WConstants.UserId].ToString();
|
||||
menuGen.MenuConfigFile = WConfig.GetMenuConfig();
|
||||
menuGen.GenerateMenu(WConfig.GetMenuTree());
|
||||
|
||||
// 取出之前儲存的 ParamList
|
||||
Hashtable ParamList;
|
||||
if (Session[ParamListKey] != null)
|
||||
ParamList = Session[ParamListKey] as Hashtable;
|
||||
else
|
||||
ParamList = new Hashtable();
|
||||
|
||||
// 需要直接載入某功能
|
||||
if (!IsPostBack && Request[WConstants.LoadForm] != null)
|
||||
{
|
||||
CurrPage = Request[WConstants.LoadForm].ToString();
|
||||
// 取出 Request 的各參數,放入準備傳入 user control 的參數列表中
|
||||
foreach (string key in Request.QueryString.AllKeys)
|
||||
{
|
||||
if (!ParamList.ContainsKey(key))
|
||||
ParamList.Add(key, Request[key]);
|
||||
else
|
||||
ParamList[key] = Request[key];
|
||||
}
|
||||
Session.Remove(CurrPageKey);
|
||||
}
|
||||
// 載入目前選到的功能
|
||||
else if (Session[CurrPageKey] != null)
|
||||
{
|
||||
CurrPage = Session[CurrPageKey].ToString();
|
||||
// 移除目前頁的 Session 儲存,以免被誤用
|
||||
Session.Remove(CurrPageKey);
|
||||
}
|
||||
ParamList[WConstants.ReportDataPath] = FReportDataPath;
|
||||
|
||||
LoadForm(ParamList);
|
||||
|
||||
// 顯示使用者名稱
|
||||
lbCUSRNAME.Text = Session[WConstants.UserName] != null ? Session[WConstants.UserName].ToString() : "";
|
||||
//lbCCUSTNAME.Text = Session[WConstants.CustName] != null ? Session[WConstants.CustName].ToString() : "";
|
||||
|
||||
// 如果沒有密碼,顯示無密碼提示訊息
|
||||
if (Session["NOPASSWORD"] != null && Session["NOPASSWORD"].ToString() == "TRUE")
|
||||
lbNOPassword.Style[HtmlTextWriterStyle.Display] = "inline";
|
||||
else
|
||||
lbNOPassword.Style[HtmlTextWriterStyle.Display] = "none";
|
||||
|
||||
/*
|
||||
* 移至 Global.asax
|
||||
*
|
||||
// 啟動檔案定時清除
|
||||
// 要停止檔案定時清除,必須停止網站應用程式,或是設定 Enabled = false
|
||||
WDeleteFileService dfs = WDeleteFileService.GetInstance();
|
||||
if (!dfs.Enabled)
|
||||
{
|
||||
dfs.DeletePatterns.Clear();
|
||||
dfs.DeletePatterns.Add(FReportDataPath + "*.mdb");
|
||||
dfs.DeletePatterns.Add(FReportDataPath + "*.rpp");
|
||||
dfs.Interval = 600; // 每幾秒清除一次檔案
|
||||
dfs.FileAgeToDelete = 600; // 要清除最後寫入時間是幾秒之前的檔案
|
||||
dfs.Enabled = true;
|
||||
}
|
||||
|
||||
// 啟動郵件傳送服務
|
||||
// 郵件伺服器相關設定,在 Web.Config 中的 System.Net 節
|
||||
WMailSender mailSender = WMailSender.GetInstance();
|
||||
if (!mailSender.Enabled)
|
||||
{
|
||||
mailSender.Interval = 10;
|
||||
mailSender.Enabled = true;
|
||||
}
|
||||
*/
|
||||
|
||||
// 輸出 CR Viewer 標籤
|
||||
ltCRX.Text = CRAX.CRAXHelper.GetCRAXViewerDeclaration(Context);
|
||||
|
||||
//Page.ClientScript.RegisterStartupScript(Page.GetType(),
|
||||
// "FixMenu",
|
||||
// // "if (typeof(FixMenu) !== \"undefined\") { FixMenu(document.getElementById(\"" + MainMenu.ClientID + "\")); }", true);
|
||||
// "FixMenu(document.getElementById(\"" + MainMenu.ClientID + "\");", true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 將瀏覽器語言設定與應用程式提供的語言設定作比對
|
||||
/// 選出最適合的語系設定
|
||||
/// </summary>
|
||||
private void GetBrowserLanguage()
|
||||
{
|
||||
FuserLang = "";
|
||||
|
||||
// 取得應用程式提供之語言設定
|
||||
string[] MyLanguages = WConfig.GetLanguages();
|
||||
|
||||
if (Request != null && Request.UserLanguages != null)
|
||||
{
|
||||
foreach (string s1 in Request.UserLanguages)
|
||||
{
|
||||
foreach (string s2 in MyLanguages)
|
||||
{
|
||||
if (s1.ToLower().CompareTo(s2.ToLower()) == 0)
|
||||
{
|
||||
FuserLang = s1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 如果找不到,則設定為繁體中文
|
||||
if (FuserLang == "")
|
||||
FuserLang = "zh-tw";
|
||||
|
||||
//設定台灣日曆
|
||||
if (WConfig.GetCY11() == 1911)
|
||||
{
|
||||
System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("zh-TW");
|
||||
ci.DateTimeFormat.Calendar = new System.Globalization.TaiwanCalendar();
|
||||
System.Threading.Thread.CurrentThread.CurrentCulture = ci;
|
||||
}
|
||||
|
||||
// 將 Javascript 中使用的訊息變數及內容輸出至網頁
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append(WConstants.JavaScriptStart);
|
||||
sb.Append("\n<!--\n");
|
||||
sb.Append("var UserLangId=\"" + FuserLang + "\";\n");
|
||||
sb.Append(WStringTable.GetInstance().GetJSMessages(FuserLang));
|
||||
//sb.Append("alert(UserLangId.toUpperCase());\n");
|
||||
sb.Append("// -->\n");
|
||||
sb.Append(WConstants.JavaScriptEnd);
|
||||
ClientScript.RegisterStartupScript(Page.GetType(), "__LANGJS__", sb.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 載入功能
|
||||
/// </summary>
|
||||
/// <param name="ParamList">要傳入的參數</param>
|
||||
private void LoadForm(Hashtable ParamList)
|
||||
{
|
||||
WUserControlBase wctrl = null;
|
||||
|
||||
if (CurrPage != "")
|
||||
{
|
||||
WWebFormController controller = WWebFormController.GetInstance();
|
||||
Control ctrl1 = null;
|
||||
|
||||
try
|
||||
{
|
||||
ctrl1 = LoadControl(controller.FindWebPart(CurrPage));
|
||||
ctrl1.ID = CurrPage;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Session.Remove(CurrPageKey);
|
||||
FormPlace.Controls.Clear();
|
||||
lbFuncNotExist.Visible = true;
|
||||
lbFuncNotExist.Text = ex.Message;
|
||||
return;
|
||||
}
|
||||
|
||||
/* 轉型 WUserControlbase,轉型不成功時,會回傳 null
|
||||
* 當轉型成功後,作以下事情:
|
||||
* 1. 傳入參數
|
||||
* 2. 設定使用者選擇的瀏覽器語言
|
||||
* 3. 執行 DoInit() 自訂方法
|
||||
* 4. 將主程式的 AfterCommand 事件處理器掛上去
|
||||
*/
|
||||
try
|
||||
{
|
||||
wctrl = (WUserControlBase)ctrl1;
|
||||
}
|
||||
catch
|
||||
{
|
||||
wctrl = null;
|
||||
}
|
||||
|
||||
|
||||
/* 清除原來放在 PlaceHolder 中的控制項
|
||||
* 並將剛才載入的控制項放進去
|
||||
*/
|
||||
try
|
||||
{
|
||||
FormPlace.Controls.Clear();
|
||||
|
||||
if (wctrl != null)
|
||||
{
|
||||
wctrl.FunctionName = CurrPage;
|
||||
wctrl.ParamList = ParamList;
|
||||
wctrl.userLang = FuserLang;
|
||||
wctrl.MainMenuId = MainMenu.ClientID;
|
||||
wctrl.AfterCommand += new Wellan.Web.UI.AfterCommandDelegate(AfterCommand);
|
||||
}
|
||||
|
||||
FormPlace.Controls.Add(ctrl1);
|
||||
|
||||
lbFuncNotExist.Visible = false;
|
||||
lbFuncNotExist.Text = "";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FormPlace.Controls.Clear();
|
||||
|
||||
lbFuncNotExist.Visible = true;
|
||||
lbFuncNotExist.Text = ex.Message;
|
||||
}
|
||||
|
||||
Session[CurrPageKey] = CurrPage;
|
||||
Session[ParamListKey] = ParamList;
|
||||
|
||||
// 從主功能表中找出 MenuItem
|
||||
// 還有問題,先不用
|
||||
// lbSiteMap.Text = GetMenuItemPath(MainMenu.Items);
|
||||
}
|
||||
else
|
||||
{
|
||||
Session.Remove(CurrPageKey);
|
||||
FormPlace.Controls.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
private string GetMenuItemPath(MenuItemCollection Items)
|
||||
{
|
||||
string result = "";
|
||||
if (Items == null)
|
||||
return result;
|
||||
|
||||
foreach (MenuItem item in Items)
|
||||
{
|
||||
if (item.Value.Contains("webPart=" + CurrPage))
|
||||
{
|
||||
result = item.Text;
|
||||
return result;
|
||||
}
|
||||
result += GetMenuItemPath(item.ChildItems);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 處理 WUserControlBase 的 AfterCommand 事件
|
||||
/// </summary>
|
||||
/// <param name="Sender">觸發此事件的 User Control</param>
|
||||
/// <param name="CommandName">觸發者自訂的命令識別字</param>
|
||||
/// <param name="NextWebPartName">下一個 web part 在 PageDefine 配置檔中的名稱</param>
|
||||
/// <param name="ParamList">觸發此事件的 User Control 要傳給下一步的參數</param>
|
||||
private void AfterCommand(
|
||||
WUserControlBase Sender,
|
||||
string CommandName,
|
||||
ref Hashtable ParamList)
|
||||
{
|
||||
WWebFormController controller = WWebFormController.GetInstance();
|
||||
try
|
||||
{
|
||||
WWebFormForward forward = controller.FindForward(CurrPage, CommandName);
|
||||
CurrPage = forward.DestinationName;
|
||||
ParamList[WConstants.ForwardSource] = CurrPage;
|
||||
ParamList[WConstants.ForwardCommand] = CommandName;
|
||||
LoadForm(ParamList);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
protected void MainMenu_MenuItemClick(object sender, MenuEventArgs e)
|
||||
{
|
||||
if (e.Item.Value != "")
|
||||
{
|
||||
if (e.Item.Value.StartsWith("webPart="))
|
||||
{
|
||||
FormPlace.Controls.Clear();
|
||||
|
||||
// 取出 webpart 的名字
|
||||
string[] menuInfos = e.Item.Value.Split(',');
|
||||
CurrPage = menuInfos[0].Substring(8);
|
||||
|
||||
// 取出要帶進去的參數列
|
||||
Hashtable paramList = new Hashtable();
|
||||
paramList[WConstants.ForwardSource] = "";
|
||||
|
||||
if (menuInfos.Length > 1)
|
||||
{
|
||||
string[] menuItemParams = menuInfos[1].Split('|');
|
||||
for (int i = 0; i < menuItemParams.Length; i++)
|
||||
{
|
||||
if (!menuItemParams[i].StartsWith("parameters="))
|
||||
continue;
|
||||
|
||||
string[] s1 = menuItemParams[i].Substring(11).Split('&');
|
||||
string aName = "";
|
||||
string aType = "";
|
||||
string aValue = "";
|
||||
for (int j = 0; j < s1.Length; j++)
|
||||
{
|
||||
if (s1[j].StartsWith("name:"))
|
||||
aName = s1[j].Substring(5);
|
||||
if (s1[j].StartsWith("type:"))
|
||||
aType = s1[j].Substring(5);
|
||||
if (s1[j].StartsWith("value:"))
|
||||
aValue = s1[j].Substring(6);
|
||||
}
|
||||
if (aName != "" && aType != "" && aValue != "")
|
||||
{
|
||||
switch (aType)
|
||||
{
|
||||
case "string":
|
||||
paramList.Add(aName, aValue);
|
||||
break;
|
||||
case "int":
|
||||
paramList.Add(aName, Convert.ToInt32(aValue));
|
||||
break;
|
||||
case "double":
|
||||
paramList.Add(aName, Convert.ToDouble(aValue));
|
||||
break;
|
||||
case "datetime":
|
||||
paramList.Add(aName, Convert.ToDateTime(aValue));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
e.Item.Selected = false;
|
||||
LoadForm(paramList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string UserLang
|
||||
{
|
||||
get { return FuserLang; }
|
||||
}
|
||||
|
||||
protected void btnLogout_Click(object sender, EventArgs e)
|
||||
{
|
||||
Session.Remove(CurrPageKey);
|
||||
|
||||
FormsAuthentication.SignOut();
|
||||
FormsAuthentication.RedirectToLoginPage();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user