You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

2625 lines
128 KiB

using System;
using System.Collections;
using System.Globalization;
using System.IO;
using System.Net;
using System.Text;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Data;
using System.Web.UI.WebControls;
using log4net;
using System.Web.Security;
using OT.Controls.Toolbar;
namespace OT.Web.Ap_Code
{
public class BasePage : System.Web.UI.Page
{
#region 定義全局變量
public static string gstrUserDptID; //登入者用戶部門
public static string gstrOrganizationID; //組織編號
public string gstrUserID; //登入者用戶ID
public static string gstrUserRoleId; //登入者所在的角色Id 一個用戶會對應多種角色
public string gstrUserGuid; //登入者的Guid
public string gstrGroupGuid; //登入者所在單位的Guid
public string gstrUserGroupId; //登入者所在單位(部門)
public string gstrUserDocOrCFO; //登入者如果是Doc:文管部門,CFO:財務部門
public string gstrProgramId; //程式代號
public string gstrProgramName; //程式名稱
public string gstrProgramTableName; //程式所使用的主TABLE (山富要求)
public string gstrUICulture; //頁面多語言
public string gstrLocalPath; //項目的物理路徑
public string gstrVirtualPath; //項目的虛擬路徑
public DateTime gdteUserLoginTime; //登入時間
public static DateTime gdteNowTime = DateTime.Now; //當前系統DB時間 new OT.BLL.CommonClass().GetDate()
public static string gstrUploadFilePath = "Upload"; //檔案上傳路徑
public static string gstrUploadFilePathPage; //頁面區塊上傳的文件夾,先放在DMImg內
public static int gintGirdViewPageSize = 15; //GridView分頁筆數
public static int gintGirdViewPageButtonSize = 10; //GridView分頁頁碼顯示數量
public static DataTable gdtProgramList; //系統所有程式列表
public static string gstrUploadType = "jpg|gif|bmp|tif|png"; //圖示上傳類型
public static string gstrDocNo; //文管部門EIP編號
public static string gstrCFONo; //財務部門EIP編號
public static int gintUploadSize = 2; //檔案上傳大小*MB
public static int gintUploadCloseFileCount = 30; //檔案上傳大小*MB
public static int gintUploadCloseImgSize = 5; //檔案上傳大小*MB
public static int gintUploadCloseImgCount = 30; //檔案上傳大小*MB
public static string gstrStartTime = "9";
public static string gstrEndTime = "22";
public bool gbl_AllowView; //檢視權限
public bool gbl_AllowAdd; //新增權限
public bool gbl_AllowReAdd; //儲存後新增權限 增加儲存後新增權限 Add by ted 2014/11/14
public bool gbl_AllowCopy; //複製權限 增加複製權限 Add by ted 2014/11/14
public bool gbl_AllowEdit; //修改權限
public bool gbl_AllowDel; //刪除權限
public bool gbl_AllowPrint; //列印權限
public bool gbl_AllowExport; //匯出權限
public bool gbl_AllowQuery; //查詢權限
public bool gbl_AllowSub; //送審權限
public bool gbl_AllowChk; //審核權限
public bool gbl_AllowUpd; //查詢權限
public bool gbl_AllowMail; //發送Mail的權限
public bool gbl_AllowRpt; //報表的最高權限
public string gbl_ProgramStatus; //程式的狀態
public static string[] garyAllowRight = new string[]{ "Add", "ReAdd", "Save", "Del"
, "Clear", "Upd", "Qry", "Exp"
, "Imp", "Leave", "Cpy"
, "Sub", "Chk", "Tmp", "Print"
,"View","RptAd"}; //系統所有可用權限
public static DataTable dtAllowRightText = new DataTable();
public static readonly ILog mo_Log = LogManager.GetLogger(
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);//記錄異常
#endregion
#region 定義頁面變量
#endregion
#region 定義屬性區域
#endregion
#region 公有方法區域
#region DateDiff
/// <summary>
/// 取得時間差(小時),超過y
/// </summary>
/// <param name="DateTime1"></param>
/// <param name="DateTime2"></param>
/// <returns></returns>
public int fnDateDiff(DateTime DateTime1, DateTime DateTime2)
{
int dateDiff = 0;
TimeSpan ts1 = new TimeSpan(Convert.ToDateTime(DateTime1.ToString("yyyy/MM/dd")).Ticks);
TimeSpan ts2 = new TimeSpan(Convert.ToDateTime(DateTime2.ToString("yyyy/MM/dd")).Ticks);
TimeSpan ts = ts1.Subtract(ts2).Duration();
dateDiff = ts.Days + 1;
return dateDiff;
}
#endregion
#region GroupRows
/// <summary>
/// 合併GridView欄位相同的行
/// </summary>
/// <param name="GridView1">GridView物件</param>
/// <param name="cellNum">需要合併欄位的索引</param>
public void fnGroupRows(GridView GridView1, int cellNum)
{
int i = 0, rowSpanNum = 1;
while (i < GridView1.Rows.Count - 1)
{
GridViewRow gvr = GridView1.Rows[i];
for (++i; i < GridView1.Rows.Count; i++)
{
GridViewRow gvrNext = GridView1.Rows[i];
if (gvr.Cells[cellNum].Text == gvrNext.Cells[cellNum].Text)
{
gvrNext.Cells[cellNum].Visible = false;
rowSpanNum++;
}
else
{
gvr.Cells[cellNum].RowSpan = rowSpanNum;
rowSpanNum = 1;
break;
}
if (i == GridView1.Rows.Count - 1)
{
gvr.Cells[cellNum].RowSpan = rowSpanNum;
}
}
}
}
#endregion
#region fnGetRightText
public string fnGetRightText(string strRightValue)
{
string strReturn = string.Empty;
switch (strRightValue.Trim())
{
case "Add":
strReturn = "新增";
break;
case "ReAdd":
strReturn = "儲存後新增";
break;
case "Save":
strReturn = "儲存";
break;
case "Del":
strReturn = "刪除";
break;
case "Clear":
strReturn = "清除";
break;
case "Upd":
strReturn = "修改";
break;
case "Qry":
strReturn = "查詢";
break;
case "Exp":
strReturn = "匯出";
break;
case "Imp":
strReturn = "匯入";
break;
case "Leave":
strReturn = "離開";
break;
case "Cpy":
strReturn = "複製";
break;
case "Sub":
strReturn = "送審";
break;
case "Chk":
strReturn = "審核";
break;
case "Tmp":
strReturn = "新增範例";
break;
case "Print":
strReturn = "列印";
break;
case "View":
strReturn = "檢視";
break;
case "RptAd":
strReturn = "報表管理";
break;
}
return strReturn;
}
#endregion
#region fnDataSetToDataTable
/// <summary>
/// 返回DataSet中第一個DataTable
/// </summary>
/// <param name="ds">需要轉換的DataSet</param>
/// <returns></returns>
public static DataTable fnDataSetToDataTable(DataSet ds)
{
DataTable dt = new DataTable();
if (ds != null && ds.Tables.Count > 0)
{
dt = ds.Tables[0];
}
return dt;
}
#endregion
#region fnDataSetToDataTable
/// <summary>
/// 返回DataSet中第一個DataTable
/// </summary>
/// <param name="ds">需要轉換的DataSet</param>
/// <param name="strTableName">Table的名稱</param>
/// <returns></returns>
public static DataTable fnDataSetToDataTable(DataSet ds, string strTableName)
{
DataTable dt = new DataTable();
if (ds != null && ds.Tables.Count > 0 && ds.Tables[strTableName] != null)
{
dt = ds.Tables[strTableName];
}
return dt;
}
#endregion
#region fnExportToOfficeFile
/// <summary>
/// 將GridView內容以HTML存成Excel、Word檔案,儲存後內容含格式資訊
/// 須設定頁面EnableEventValidation="false"
/// </summary>
/// <param name="vGridView">GridView物件名稱</param>
/// <param name="vHtmlTable">包含Excel標題的物件名稱,註:不能含有Button</param>
/// <param name="vFileName">存檔檔名</param>
/// <param name="vPage">來源Page頁面(ex:Page)</param>
/// <remarks>
/// 程式做法:
/// 利用GridView自行Render出與網頁上格式相同的HTML,
/// 配合application/vnd.xls MIME Type,讓資料可以直接在Excel、Word中重現
/// 註:
/// 使用此 Function 須 using System.Web
/// </remarks>
public void fnExportToOfficeFile(System.Web.UI.WebControls.GridView vGridView, System.Web.UI.HtmlControls.HtmlTable vHtmlTable, string vFileName, System.Web.UI.Page vPage)
{
if (vGridView.Rows.Count == 0)
{
ShowArtAlert("A00072"); //無資料匯出
return;
}
//關閉換頁跟排序
//說明:若GridView無分頁功能、或有啟用分頁但只有1頁的資料時,則直接將資料Render出來
//若有啟用分頁功能且頁數有2頁以上,當DataSource為null時,則不進行轉換為Excel的動作
//if (vGridView.AllowPaging && vGridView.DataSource != null)
//{
//vGridView.AllowSorting = false;
//vGridView.AllowPaging = false;
//vGridView.DataBind();
//}
//瀏覽器為IE時將檔名編碼,避免存檔後中文檔名會變亂碼
string strFileName = string.Empty;
if (HttpContext.Current.Request.Browser.Browser == "IE")
{
strFileName = HttpUtility.UrlPathEncode(vFileName);
}
else
{
strFileName = vFileName;
}
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.ContentType = "application/vnd.xls";
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + strFileName);
HttpContext.Current.Response.AddHeader("mata", "http-equiv=Content-Type content=text/html;charset=utf-8");
//註:若中文字會變亂碼,則替換下面的程式試試
//HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("big5");
//HttpContext.Current.Response.Write("<meta http-equiv=Content-Type content=text/html;charset=utf-8>")
//HttpContext.Current.Response.Write("<head><meta http-equiv=Content-Type content=text/html;charset=big5></head>")
//HttpContext.Current.Response.Charset = "big5";
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
//建立假HtmlForm避免以下錯誤:
//Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server
//另一種做法是建立 override VerifyRenderingInServerForm function,在function內不寫程式碼
//這樣就可以直接執行 GridView1.RenderControl(htw)
//出現上面的錯誤在Page添加 EnableEventValidation="false"
System.Web.UI.HtmlControls.HtmlForm hf = new System.Web.UI.HtmlControls.HtmlForm();
vPage.Controls.Add(hf);
vHtmlTable.RenderControl(htw);
hf.Controls.Add(vGridView);
hf.RenderControl(htw);
string strHtml = sw.ToString().Replace("<div>", "").Replace("</div>", "");
int iS = strHtml.IndexOf("<input", 0);
if (iS != -1)
{
int iE = strHtml.IndexOf("/>", iS);
strHtml = strHtml.Substring(0, iS) + strHtml.Substring(iE + 2, strHtml.Length - iE - 2);
}
//System.Web.UI.HtmlControls.HtmlMeta meta = new System.Web.UI.HtmlControls.HtmlMeta();
//meta. = "";
string strMeta = "<meta http-equiv=\"Content-Type\" content=\"text/html\"; charset=\"utf-8\" />";
strHtml = strMeta + strHtml;
HttpContext.Current.Response.Write(strHtml);
HttpContext.Current.Response.End();
}
#endregion
#region fnExportToOfficeFile
/// <summary>
/// 將GridView內容以HTML存成Excel、Word檔案,儲存後內容含格式資訊
/// 須設定頁面EnableEventValidation="false"
/// </summary>
/// <param name="vGridView">GridView物件名稱</param>
/// <param name="vHtmlTable">包含Excel標題的物件名稱,註:不能含有Button</param>
/// <param name="vFileName">存檔檔名</param>
/// <param name="vPage">來源Page頁面(ex:Page)</param>
/// <remarks>
/// 程式做法:
/// 利用GridView自行Render出與網頁上格式相同的HTML,
/// 配合application/vnd.xls MIME Type,讓資料可以直接在Excel、Word中重現
/// 註:
/// 使用此 Function 須 using System.Web
/// </remarks>
public void fnExportToOfficeFile(System.Web.UI.WebControls.GridView vGridView, System.Web.UI.HtmlControls.HtmlTable vHtmlTableHead, System.Web.UI.HtmlControls.HtmlTable vHtmlTableFoot, string vFileName, System.Web.UI.Page vPage)
{
if (vGridView.Rows.Count == 0)
{
ShowArtAlert("A00072"); //無資料匯出
return;
}
//關閉換頁跟排序
//說明:若GridView無分頁功能、或有啟用分頁但只有1頁的資料時,則直接將資料Render出來
//若有啟用分頁功能且頁數有2頁以上,當DataSource為null時,則不進行轉換為Excel的動作
if (vGridView.AllowPaging && vGridView.DataSource != null)
{
vGridView.AllowSorting = false;
vGridView.AllowPaging = false;
vGridView.DataBind();
}
//瀏覽器為IE時將檔名編碼,避免存檔後中文檔名會變亂碼
string strFileName = string.Empty;
if (HttpContext.Current.Request.Browser.Browser == "IE")
{
strFileName = HttpUtility.UrlPathEncode(vFileName);
}
else
{
strFileName = vFileName;
}
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.ContentType = "application/vnd.xls";
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + strFileName);
HttpContext.Current.Response.AddHeader("mata", "http-equiv=Content-Type content=text/html;charset=big5");
//註:若中文字會變亂碼,則替換下面的程式試試
//HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("big5");
//HttpContext.Current.Response.Write("<meta http-equiv=Content-Type content=text/html;charset=utf-8>")
//HttpContext.Current.Response.Write("<head><meta http-equiv=Content-Type content=text/html;charset=big5></head>")
//HttpContext.Current.Response.Charset = "big5";
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
//建立假HtmlForm避免以下錯誤:
//Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server
//另一種做法是建立 override VerifyRenderingInServerForm function,在function內不寫程式碼
//這樣就可以直接執行 GridView1.RenderControl(htw)
//出現上面的錯誤在Page添加 EnableEventValidation="false"
System.Web.UI.HtmlControls.HtmlForm hf = new System.Web.UI.HtmlControls.HtmlForm();
vPage.Controls.Add(hf);
vHtmlTableHead.RenderControl(htw);
hf.Controls.Add(vGridView);
hf.RenderControl(htw);
vHtmlTableFoot.RenderControl(htw);
string strHtml = sw.ToString().Replace("<div>", "").Replace("</div>", "");
int iS = strHtml.IndexOf("<input", 0);
if (iS != -1)
{
int iE = strHtml.IndexOf("/>", iS);
strHtml = strHtml.Substring(0, iS) + strHtml.Substring(iE + 2, strHtml.Length - iE - 2);
}
HttpContext.Current.Response.Write(strHtml);
HttpContext.Current.Response.End();
}
#endregion
#region fnExportToOfficeFile
/// <summary>
/// 將GridView內容以HTML存成Excel、Word檔案,儲存後內容含格式資訊
/// 須設定頁面EnableEventValidation="false"
/// </summary>
/// <param name="vGridView">GridView物件名稱</param>
/// <param name="vHtmlTable">包含Excel標題的物件名稱,註:不能含有Button</param>
/// <param name="vFileName">存檔檔名</param>
/// <param name="vPage">來源Page頁面(ex:Page)</param>
/// <remarks>
/// 程式做法:
/// 利用GridView自行Render出與網頁上格式相同的HTML,
/// 配合application/vnd.xls MIME Type,讓資料可以直接在Excel、Word中重現
/// 註:
/// 使用此 Function 須 using System.Web
/// </remarks>
public void fnExportToOfficeFile(System.Web.UI.WebControls.GridView vGridView, string vFileName, System.Web.UI.Page vPage)
{
if (vGridView.Rows.Count == 0)
{
ShowArtAlert("A00072"); //無資料匯出
return;
}
//關閉換頁跟排序
//說明:若GridView無分頁功能、或有啟用分頁但只有1頁的資料時,則直接將資料Render出來
//若有啟用分頁功能且頁數有2頁以上,當DataSource為null時,則不進行轉換為Excel的動作
if (vGridView.AllowSorting && vGridView.DataSource != null)
{
vGridView.AllowSorting = false;
vGridView.DataBind();
}
//瀏覽器為IE時將檔名編碼,避免存檔後中文檔名會變亂碼
string strFileName = string.Empty;
if (HttpContext.Current.Request.Browser.Browser == "IE")
{
strFileName = HttpUtility.UrlPathEncode(vFileName);
}
else
{
strFileName = vFileName;
}
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.ContentType = "application/vnd.xls";
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + strFileName);
HttpContext.Current.Response.AddHeader("mata", "http-equiv=Content-Type content=text/html;charset=big5");
//HttpContext.Current.Response.AddHeader("mata", "http-equiv=Content-Type content=text/html;charset=utf-8");
//註:若中文字會變亂碼,則替換下面的程式試試
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("big5");
//HttpContext.Current.Response.Write("<meta http-equiv=Content-Type content=text/html;charset=utf-8>")
HttpContext.Current.Response.Write("<head><meta http-equiv=Content-Type content=text/html;charset=big5></head>");
HttpContext.Current.Response.Charset = "big5";
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
//建立假HtmlForm避免以下錯誤:
//Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server
//另一種做法是建立 override VerifyRenderingInServerForm function,在function內不寫程式碼
//這樣就可以直接執行 GridView1.RenderControl(htw)
//出現上面的錯誤在Page添加 EnableEventValidation="false"
System.Web.UI.HtmlControls.HtmlForm hf = new System.Web.UI.HtmlControls.HtmlForm();
vPage.Controls.Add(hf);
hf.Controls.Add(vGridView);
hf.RenderControl(htw);
string strHtml = sw.ToString().Replace("<div>", "").Replace("</div>", "");
int iS = strHtml.IndexOf("<input", 0);
if (iS != -1)
{
int iE = strHtml.IndexOf("/>", iS);
strHtml = strHtml.Substring(0, iS) + strHtml.Substring(iE + 2, strHtml.Length - iE - 2);
}
HttpContext.Current.Response.Write(strHtml);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}
#endregion
#region fnExportToOfficeFile
/// <summary>
/// 將GridView內容以HTML存成Excel、Word檔案,儲存後內容含格式資訊
/// 須設定頁面EnableEventValidation="false"
/// </summary>
/// <param name="vGridView">GridView物件名稱</param>
/// <param name="vHtmlTable">包含Excel標題的物件名稱,註:不能含有Button</param>
/// <param name="vFileName">存檔檔名</param>
/// <param name="vPage">來源Page頁面(ex:Page)</param>
/// <remarks>
/// 程式做法:
/// 利用GridView自行Render出與網頁上格式相同的HTML,
/// 配合application/vnd.xls MIME Type,讓資料可以直接在Excel、Word中重現
/// 註:
/// 使用此 Function 須 using System.Web
/// </remarks>
public void fnExportToOfficeFile(System.Web.UI.HtmlControls.HtmlTable vHtmlTable, string vFileName, System.Web.UI.Page vPage)
{
if (vHtmlTable.Rows.Count == 0)
{
ShowArtAlert("A00072"); //無資料匯出
return;
}
//瀏覽器為IE時將檔名編碼,避免存檔後中文檔名會變亂碼
string strFileName = string.Empty;
if (HttpContext.Current.Request.Browser.Browser == "IE")
{
strFileName = HttpUtility.UrlPathEncode(vFileName);
}
else
{
strFileName = vFileName;
}
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.ContentType = "application/vnd.xls";
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + strFileName);
HttpContext.Current.Response.AddHeader("mata", "http-equiv=Content-Type content=text/html;charset=big5");
//註:若中文字會變亂碼,則替換下面的程式試試
//HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("big5");
//HttpContext.Current.Response.Write("<meta http-equiv=Content-Type content=text/html;charset=utf-8>")
//HttpContext.Current.Response.Write("<head><meta http-equiv=Content-Type content=text/html;charset=big5></head>")
//HttpContext.Current.Response.Charset = "big5";
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
//建立假HtmlForm避免以下錯誤:
//Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server
//另一種做法是建立 override VerifyRenderingInServerForm function,在function內不寫程式碼
//這樣就可以直接執行 GridView1.RenderControl(htw)
//出現上面的錯誤在Page添加 EnableEventValidation="false"
System.Web.UI.HtmlControls.HtmlForm hf = new System.Web.UI.HtmlControls.HtmlForm();
vPage.Controls.Add(hf);
hf.Controls.Add(vHtmlTable);
//vHtmlTable.RenderControl(htw);
hf.RenderControl(htw);
//string strCSSUrl = GetRootURI() + "/App_Themes/Default/ReportStyle.css";
//string strCss = @"";
//strCss = fnReadFully(strCSSUrl);
//HttpContext.Current.Response.Write("<style type=\"text/css\">" + strCss + "</style>");
HttpContext.Current.Response.Write(sw.ToString().Replace("<div>", "").Replace("</div>", ""));
HttpContext.Current.Response.End();
}
#endregion
#region fnExportToOfficeFile
/// <summary>
/// 將GridView內容以HTML存成Excel、Word檔案,儲存後內容含格式資訊
/// 須設定頁面EnableEventValidation="false"
/// </summary>
/// <param name="vGridView">GridView物件名稱</param>
/// <param name="vHtmlTable">包含Excel標題的物件名稱,註:不能含有Button</param>
/// <param name="vFileName">存檔檔名</param>
/// <param name="vPage">來源Page頁面(ex:Page)</param>
/// <param name="strStringColIndexs">文字欄位(ex:例如報表第一列和第四列為文字類型,則傳"0;3;")</param>
/// <remarks>
/// 程式做法:
/// 利用GridView自行Render出與網頁上格式相同的HTML,
/// 配合application/vnd.xls MIME Type,讓資料可以直接在Excel、Word中重現
/// 註:
/// 使用此 Function 須 using System.Web
/// </remarks>
public void fnExportToOfficeFile(System.Web.UI.WebControls.GridView vGridView, string vFileName, System.Web.UI.Page vPage, string strStringColIndexs)
{
if (vGridView.Rows.Count == 0)
{
ShowArtAlert("A00072"); //無資料匯出
return;
}
//關閉換頁跟排序
//說明:若GridView無分頁功能、或有啟用分頁但只有1頁的資料時,則直接將資料Render出來
//若有啟用分頁功能且頁數有2頁以上,當DataSource為null時,則不進行轉換為Excel的動作
if (vGridView.AllowPaging && vGridView.DataSource != null)
{
vGridView.Attributes.Add("StringColIndexs", strStringColIndexs);
vGridView.RowDataBound += new GridViewRowEventHandler(vGridView_RowDataBound);
vGridView.AllowSorting = false;
vGridView.AllowPaging = false;
vGridView.DataBind();
}
//瀏覽器為IE時將檔名編碼,避免存檔後中文檔名會變亂碼
string strFileName = string.Empty;
if (HttpContext.Current.Request.Browser.Browser == "IE")
{
strFileName = HttpUtility.UrlPathEncode(vFileName);
}
else
{
strFileName = vFileName;
}
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.ContentType = "application/vnd.xls";
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + strFileName);
HttpContext.Current.Response.AddHeader("mata", "http-equiv=Content-Type content=text/html;charset=big5");
//註:若中文字會變亂碼,則替換下面的程式試試
//HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("big5");
//HttpContext.Current.Response.Write("<meta http-equiv=Content-Type content=text/html;charset=utf-8>")
//HttpContext.Current.Response.Write("<head><meta http-equiv=Content-Type content=text/html;charset=big5></head>")
//HttpContext.Current.Response.Charset = "big5";
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
//建立假HtmlForm避免以下錯誤:
//Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server
//另一種做法是建立 override VerifyRenderingInServerForm function,在function內不寫程式碼
//這樣就可以直接執行 GridView1.RenderControl(htw)
//出現上面的錯誤在Page添加 EnableEventValidation="false"
System.Web.UI.HtmlControls.HtmlForm hf = new System.Web.UI.HtmlControls.HtmlForm();
vPage.Controls.Add(hf);
hf.Controls.Add(vGridView);
hf.RenderControl(htw);
string strHtml = sw.ToString().Replace("<div>", "").Replace("</div>", "");
int iS = strHtml.IndexOf("<input", 0);
if (iS != -1)
{
int iE = strHtml.IndexOf("/>", iS);
strHtml = strHtml.Substring(0, iS) + strHtml.Substring(iE + 2, strHtml.Length - iE - 2);
}
HttpContext.Current.Response.Write(strHtml);
HttpContext.Current.Response.End();
}
#endregion
#region fnExportToOfficeFile
/// <summary>
/// 將GridView內容以HTML存成Excel、Word檔案,儲存後內容含格式資訊
/// 須設定頁面EnableEventValidation="false"
/// </summary>
/// <param name="vGridView">GridView物件名稱</param>
/// <param name="vHtmlTable">包含Excel標題的物件名稱,註:不能含有Button</param>
/// <param name="vFileName">存檔檔名</param>
/// <param name="vPage">來源Page頁面(ex:Page)</param>
/// <param name="strStringColIndexs">文字欄位(ex:例如報表第一列和第四列為文字類型,則傳"0;3;")</param>
/// <remarks>
/// 程式做法:
/// 利用GridView自行Render出與網頁上格式相同的HTML,
/// 配合application/vnd.xls MIME Type,讓資料可以直接在Excel、Word中重現
/// 註:
/// 使用此 Function 須 using System.Web
/// </remarks>
public void fnExportToOfficeFile(System.Web.UI.WebControls.GridView vGridView, System.Web.UI.HtmlControls.HtmlTable vHtmlTable, string vFileName, System.Web.UI.Page vPage, string strStringColIndexs)
{
if (vGridView.Rows.Count == 0)
{
ShowArtAlert("A00072"); //無資料匯出
return;
}
//關閉換頁跟排序
//說明:若GridView無分頁功能、或有啟用分頁但只有1頁的資料時,則直接將資料Render出來
//若有啟用分頁功能且頁數有2頁以上,當DataSource為null時,則不進行轉換為Excel的動作
//if (vGridView.AllowPaging && vGridView.DataSource != null)
//{
//vGridView.AllowSorting = false;
//vGridView.AllowPaging = false;
//vGridView.DataBind();
//}
if (vGridView.DataSource != null)
{
vGridView.Attributes.Add("StringColIndexs", strStringColIndexs);
vGridView.RowDataBound += new GridViewRowEventHandler(vGridView_RowDataBound);
vGridView.AllowSorting = false;
vGridView.AllowPaging = false;
vGridView.DataBind();
}
//瀏覽器為IE時將檔名編碼,避免存檔後中文檔名會變亂碼
string strFileName = string.Empty;
//新增判斷 by Gary 2013/12/30
if (HttpContext.Current.Request.Browser.Browser == "IE" || HttpContext.Current.Request.Browser.Browser == "InternetExplorer")
{
strFileName = HttpUtility.UrlPathEncode(vFileName);
}
else
{
strFileName = vFileName;
}
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.ContentType = "application/vnd.xls";
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + strFileName);
HttpContext.Current.Response.AddHeader("mata", "http-equiv=Content-Type content=text/html;charset=utf-8");
//註:若中文字會變亂碼,則替換下面的程式試試
//HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("big5");
//HttpContext.Current.Response.Write("<meta http-equiv=Content-Type content=text/html;charset=utf-8>")
//HttpContext.Current.Response.Write("<head><meta http-equiv=Content-Type content=text/html;charset=big5></head>")
//HttpContext.Current.Response.Charset = "big5";
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
//建立假HtmlForm避免以下錯誤:
//Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server
//另一種做法是建立 override VerifyRenderingInServerForm function,在function內不寫程式碼
//這樣就可以直接執行 GridView1.RenderControl(htw)
//出現上面的錯誤在Page添加 EnableEventValidation="false"
System.Web.UI.HtmlControls.HtmlForm hf = new System.Web.UI.HtmlControls.HtmlForm();
vPage.Controls.Add(hf);
vHtmlTable.RenderControl(htw);
hf.Controls.Add(vGridView);
hf.RenderControl(htw);
string strHtml = sw.ToString().Replace("<div>", "").Replace("</div>", "");
int iS = strHtml.IndexOf("<input", 0);
if (iS != -1)
{
int iE = strHtml.IndexOf("/>", iS);
strHtml = strHtml.Substring(0, iS) + strHtml.Substring(iE + 2, strHtml.Length - iE - 2);
}
//System.Web.UI.HtmlControls.HtmlMeta meta = new System.Web.UI.HtmlControls.HtmlMeta();
//meta. = "";
string strMeta = "<meta http-equiv=\"Content-Type\" content=\"text/html\"; charset=\"utf-8\" />";
strHtml = strMeta + strHtml;
//HttpContext.Current.Response.Write(strHtml);
//HttpContext.Current.Response.End();
Session["FileName"] = strFileName;
Session["Data"] = strHtml;
Response.Redirect("~/ExpFile.aspx", true);
//Context.Items.Add("FileName", strFileName);
//Context.Items.Add("Data", strHtml);
//Server.Transfer("~/ExpFile.aspx",true);
}
#endregion
public class RemotePost
{
private System.Collections.Specialized.NameValueCollection Inputs = new System.Collections.Specialized.NameValueCollection();
public string Url = "";
public string Method = "post";
public string FormName = "form1";
public void Add(string name, string value)
{
Inputs.Add(name, value);
}
public void Post()
{
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.Write("<html><head>");
System.Web.HttpContext.Current.Response.Write(string.Format("</head><body onload='document.{0}.submit()'>", FormName));
System.Web.HttpContext.Current.Response.Write(string.Format("<form name='{0}' method='{1}' action='{2}' >", FormName, Method, Url));
for (int i = 0; i < Inputs.Keys.Count; i++)
{
System.Web.HttpContext.Current.Response.Write(string.Format("<input name='{0}' type='hidden' value='{1}'>", Inputs.Keys[i], Inputs[Inputs.Keys[i]]));
}
System.Web.HttpContext.Current.Response.Write("</form>");
System.Web.HttpContext.Current.Response.Write("</body></html>");
System.Web.HttpContext.Current.Response.End();
}
}
#region vGridView_RowDataBound
/// <summary>
/// 把含有數字的欄位的值轉換成字符串
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void vGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
string strStringColIndexs = ((GridView)sender).Attributes["StringColIndexs"];
if (!string.IsNullOrEmpty(strStringColIndexs))
{
foreach (string index in strStringColIndexs.Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries))
{
e.Row.Cells[int.Parse(index)].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
}
}
}
#endregion
#region fnUrlEncode
/// <summary>
/// Url編碼
/// </summary>
/// <param name="strSource">需要編碼的原始字符串</param>
/// <returns>url編碼後的字符串</returns>
public string fnUrlEncode(string strSource)
{
return Server.UrlEncode(strSource);
}
#endregion
#region fnUrlDecode
/// <summary>
/// Url解碼
/// </summary>
/// <param name="strSource">需要解碼的原始字符串</param>
/// <returns>url解碼後的字符串</returns>
public string fnUrlDecode(string strSource)
{
return Server.UrlDecode(strSource);
}
#endregion
#region fnGetSortColumnIndex
/// <summary>
/// 獲取Gridview指定排序欄位的索引
/// </summary>
/// <param name="gv">目標Gridview</param>
/// <param name="strSortExpression">排序欄位名稱</param>
/// <returns>Gridview指定排序欄位的索引</returns>
public int fnGetSortColumnIndex(GridView gv, string strFile)
{
int intIndex = -1;
foreach (DataControlField field in gv.Columns)
{
if (field.SortExpression == strFile)
{
intIndex = gv.Columns.IndexOf(field);
break;
}
}
return intIndex;
}
#endregion
#region fnAddSortImage
/// <summary>
/// 為排序欄位添加圖示
/// </summary>
/// <param name="columnIndex">排序欄位的索引</param>
/// <param name="headerRow">GirdView的HeaderRow</param>
public void fnAddSortImage(int columnIndex, string strSortDirection, GridViewRow headerRow)
{
System.Web.UI.HtmlControls.HtmlAnchor sortImage = new System.Web.UI.HtmlControls.HtmlAnchor();
if (strSortDirection == "ASC")
{
sortImage.Attributes.Add("class", "sortedascendingheaderstyle");
}
else
{
sortImage.Attributes.Add("class", "sorteddescendingheaderstyle");
}
sortImage.InnerText = headerRow.Cells[columnIndex].Text;
headerRow.Cells[columnIndex].Controls.Add(sortImage);
}
#endregion
#region fnAddSortImage
/// <summary>
/// 為排序欄位添加圖示
/// </summary>
/// <param name="columnIndex">排序欄位的索引</param>
/// <param name="headerCell">GirdView的DataControlFieldHeaderCell</param>
public void fnAddSortImage(string strSortDirection, DataControlFieldHeaderCell headerCell)
{
System.Web.UI.HtmlControls.HtmlAnchor sortImage = new System.Web.UI.HtmlControls.HtmlAnchor();
if (strSortDirection == "ASC")
{
sortImage.Attributes.Add("class", "sortedascendingheaderstyle");
}
else
{
sortImage.Attributes.Add("class", "sorteddescendingheaderstyle");
}
//sortImage.InnerText = strSortDirection;
headerCell.Controls.Add(sortImage);
}
#endregion
#region fnLoadSetting
/// <summary>
/// 加載系統參數設定
/// </summary>
public static void fnLoadSetting()
{
try
{
gstrUserDptID = "001";
gstrUserRoleId = "Admin";
gstrOrganizationID = "Origtek";
OT.BLL.OTB_SYS_SystemSetting o_SYS_SystemSetting_BLL = new OT.BLL.OTB_SYS_SystemSetting();
DataTable dtSystemSetting = fnDataSetToDataTable(o_SYS_SystemSetting_BLL.GetAllList());
if (dtSystemSetting.Rows.Count > 0)
{
//如果存在資料
int.TryParse(GetSystemSetting(dtSystemSetting, "GridRecords"), out gintGirdViewPageSize); //GridView分頁筆數
if (gintGirdViewPageSize == 0)
{
gintGirdViewPageSize = 15; //預設分頁筆數
}
int.TryParse(GetSystemSetting(dtSystemSetting, "GridPages"), out gintGirdViewPageButtonSize); //GridView分頁頁碼顯示數量
if (gintGirdViewPageSize == 0)
{
gintGirdViewPageSize = 10; //預設顯示頁碼數
}
gstrUploadFilePath = GetSystemSetting(dtSystemSetting, "UploadPath"); //文檔上傳路徑
gstrUploadFilePath = gstrUploadFilePath ?? "Upload";
gstrUploadType = GetSystemSetting(dtSystemSetting, "UploadImgTpe"); //圖片格式
gstrUploadType = gstrUploadType ?? "jpg|gif|bmp|tif|png";
//string strAllowRight = GetSystemSetting(dtSystemSetting, "AllowRight");//系統所有可用權限
//if (string.IsNullOrEmpty(strAllowRight))
//{
// garyAllowRight = new string[]{ "Add", "ReAdd", "Save", "Del"
// , "Clear", "Upd", "Qry", "Exp"
// , "Imp", "Leave", "Cpy"
// , "Sub", "Chk", "Tmp"};
//}
//else
//{
// garyAllowRight = strAllowRight.Split('|');
//}
int.TryParse(GetSystemSetting(dtSystemSetting, "UploadSize"), out gintUploadSize);//檔案上傳大小*MB
if (gintUploadSize == 0)
{
gintUploadSize = 2;
}
int.TryParse(GetSystemSetting(dtSystemSetting, "CloseFileCount"), out gintUploadCloseFileCount);//檔案上傳大小*MB
if (gintUploadCloseFileCount == 0)
{
gintUploadCloseFileCount = 30;
}
int.TryParse(GetSystemSetting(dtSystemSetting, "CloesImgSize"), out gintUploadCloseImgSize);//檔案上傳大小*MB
if (gintUploadCloseImgSize == 0)
{
gintUploadCloseImgSize = 5;
}
int.TryParse(GetSystemSetting(dtSystemSetting, "CloseImgCount"), out gintUploadCloseImgCount);//檔案上傳大小*MB
if (gintUploadCloseImgCount == 0)
{
gintUploadCloseImgCount = 30;
}
gstrStartTime = GetSystemSetting(dtSystemSetting, "StartTime") ?? "9"; //日期控件默認的開始時間
gstrEndTime = GetSystemSetting(dtSystemSetting, "EndTime") ?? "21"; //日期控件的默認結束時間
gstrDocNo = GetSystemSetting(dtSystemSetting, "DocNo") ?? ""; //文管部門EIP編號
gstrCFONo = GetSystemSetting(dtSystemSetting, "CFONo") ?? ""; //財務部門EIP編號
gstrUploadFilePathPage = GetSystemSetting(dtSystemSetting, "UploadFilePathPage");
if (gstrUploadFilePathPage == "")
{
gstrUploadFilePathPage = "DMImg";
}
}
}
catch (Exception ex)
{
mo_Log.Debug("BasePage.fnLoadSetting Debug:" + ex.Message, ex);
mo_Log.Error("BasePage.fnLoadSetting Erroe:" + ex.Message, ex);
}
}
#endregion
#region fnLoadProgramList
/// <summary>
/// 加載系統程式列表
/// </summary>
public static void fnLoadProgramList()
{
OT.BLL.OTB_SYS_ProgramList o_OTB_SYS_ProgramList_BLL = new OT.BLL.OTB_SYS_ProgramList();
gdtProgramList = fnDataSetToDataTable(o_OTB_SYS_ProgramList_BLL.GetAllList());
}
#endregion
#region fnOpenFile
/// <summary>
/// 開啟文檔
/// </summary>
/// <param name="strPath">檔案路徑</param>
/// <param name="strFileName">檔案名稱(包含後綴名)</param>
/// <remarks>例如:檔案路徑:LoanTemp/LoanCount.xls;檔案名稱:XX.doc</remarks>
public void fnOpenFile(string strPath, string strFileName)
{
strPath = Convert.ToBase64String(Encoding.Default.GetBytes(strPath));
strPath = strPath.Replace('=', '!').Replace("/", "@").Replace("+", "*");
Response.Redirect(string.Format("~/OpenFile.aspx?U={0}&FileName={1}", strPath, strFileName), false);
}
#endregion
//#region fnUpLoadFile
///// <summary>
///// 檔案上傳
///// </summary>
///// <param name="file">文件上傳控件</param>
///// <returns></returns>
//public string fnUpLoadFile(FileUpload file)
//{
// string strReturn = string.Empty;
// if (file.HasFile && file.PostedFile.ContentLength <= gintUploadSize * 1024 * 1024)
// {
// strReturn = Guid.NewGuid().ToString();
// try
// {
// int bufferSize = 1024;
// byte[] buffer = new byte[bufferSize];
// int uploadFileLength = 0;
// string strSubFileName = System.IO.Path.GetExtension(file.FileName).ToLower();
// string saveFullPath = Server.MapPath("~") + "\\" + gstrUploadFilePath + "\\" + strReturn.Replace("-", "") + strSubFileName;
// string strFilePath = "~/" + gstrUploadFilePath.Trim('/').Trim('\\') + "/" + strReturn.Replace("-", "") + strSubFileName;
// if (!Directory.Exists(Server.MapPath("~") + "\\" + gstrUploadFilePath + "\\"))
// {
// DirectoryInfo dir = Directory.CreateDirectory(Server.MapPath("~") + "\\" + gstrUploadFilePath + "\\");
// }
// using (FileStream fs = new FileStream(saveFullPath, FileMode.Create))
// {
// while (uploadFileLength < file.PostedFile.ContentLength)
// {
// //从输入流放进缓冲区
// int bytes = file.PostedFile.InputStream.Read(buffer, 0, bufferSize);
// fs.Write(buffer, 0, bytes);
// fs.Flush(); // 字节写入文件流
// uploadFileLength += bytes;// 更新大小
// }
// fs.Close();
// }
// OT.BLL.OTB_SYS_AttachmentFiles o_SYS_Attachments_BLL = new OT.BLL.OTB_SYS_AttachmentFiles();
// OT.Model.OTB_SYS_AttachmentFiles o_SYS_Attachments_Model = new OT.Model.OTB_SYS_AttachmentFiles();
// o_SYS_Attachments_Model.TargetRelationID = strReturn;
// o_SYS_Attachments_Model.FileName = file.FileName;
// o_SYS_Attachments_Model.FilePath = strFilePath;
// o_SYS_Attachments_Model.SubFileName = strSubFileName;
// o_SYS_Attachments_Model.FileSize = uploadFileLength;
// o_SYS_Attachments_BLL.Add(o_SYS_Attachments_Model);
// uploadFileLength = 0;
// }
// catch (Exception ex)
// {
// strReturn = string.Empty;
// mo_Log.Error(ex.Message, ex);
// }
// }
// else if (file.HasFile && file.PostedFile.ContentLength > gintUploadSize * 1024 * 1024)
// {
// ShowArtAlert("A00076", gintUploadSize.ToString());//上傳檔案超過指定大小{0}MB.
// }
// return strReturn;
//}
//#endregion
#region fnUpLoadFilePage
/// <summary>
/// 檔案上傳
/// </summary>
/// <param name="file">文件上傳控件</param>
/// <returns></returns>
public string fnUpLoadFilePage(FileUpload file)
{
string strReturn = string.Empty;
if (file.HasFile && file.PostedFile.ContentLength <= gintUploadSize * 1024 * 1024)
{
try
{
int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
int uploadFileLength = 0;
string saveFullPath = Server.MapPath("~") + "\\" + gstrUploadFilePathPage + "\\" + file.FileName;
string strFilePath = "~/" + gstrUploadFilePathPage.Trim('/').Trim('\\') + "/" + file.FileName;
if (!Directory.Exists(Server.MapPath("~") + "\\" + gstrUploadFilePathPage + "\\"))
{
DirectoryInfo dir = Directory.CreateDirectory(Server.MapPath("~") + "\\" + gstrUploadFilePathPage + "\\");
}
using (FileStream fs = new FileStream(saveFullPath, FileMode.Create))
{
while (uploadFileLength < file.PostedFile.ContentLength)
{
//从输入流放进缓冲区
int bytes = file.PostedFile.InputStream.Read(buffer, 0, bufferSize);
fs.Write(buffer, 0, bytes);
fs.Flush(); // 字节写入文件流
uploadFileLength += bytes;// 更新大小
}
fs.Close();
}
strReturn = strFilePath;
}
catch (Exception ex)
{
strReturn = string.Empty;
mo_Log.Error(ex.Message, ex);
}
}
else if (file.HasFile && file.PostedFile.ContentLength > gintUploadSize * 1024 * 1024)
{
ShowArtAlert("A00076", gintUploadSize.ToString());//上傳檔案超過指定大小{0}MB.
}
return strReturn;
}
#endregion
//#region fnUpLoadFileByInput
///// <summary>
///// 檔案上傳
///// </summary>
///// <param name="file">文件上傳控件</param>
///// <returns></returns>
//public string fnUpLoadFileByInput(HttpPostedFile file, string strSourceRelationID)
//{
// string strReturn = string.Empty;
// if (file != null && file.FileName != "" && Request.TotalBytes <= gintUploadSize * 1024 * 1024)
// {
// strReturn = Guid.NewGuid().ToString();
// try
// {
// int bufferSize = 1024;
// byte[] buffer = new byte[bufferSize];
// int uploadFileLength = 0;
// string strSubFileName = System.IO.Path.GetExtension(file.FileName).ToLower();
// string saveFullPath = Server.MapPath("~") + "\\" + gstrUploadFilePath + "\\" + strReturn.Replace("-", "") + strSubFileName;
// string strFilePath = "~/" + gstrUploadFilePath.Trim('/').Trim('\\') + "/" + strReturn.Replace("-", "") + strSubFileName;
// if (!Directory.Exists(Server.MapPath("~") + "\\" + gstrUploadFilePath + "\\"))
// {
// DirectoryInfo dir = Directory.CreateDirectory(Server.MapPath("~") + "\\" + gstrUploadFilePath + "\\");
// }
// using (FileStream fs = new FileStream(saveFullPath, FileMode.Create))
// {
// while (uploadFileLength < file.ContentLength)
// {
// //从输入流放进缓冲区
// int bytes = file.InputStream.Read(buffer, 0, bufferSize);
// fs.Write(buffer, 0, bytes);
// fs.Flush(); // 字节写入文件流
// uploadFileLength += bytes;// 更新大小
// }
// fs.Close();
// }
// OT.BLL.OTB_SYS_AttachmentFiles o_SYS_Attachments_BLL = new OT.BLL.OTB_SYS_AttachmentFiles();
// OT.Model.OTB_SYS_AttachmentFiles o_SYS_Attachments_Model = new OT.Model.OTB_SYS_AttachmentFiles();
// o_SYS_Attachments_Model.TargetRelationID = strReturn;
// o_SYS_Attachments_Model.SourceRelationID = strSourceRelationID;
// o_SYS_Attachments_Model.FileName = file.FileName;
// o_SYS_Attachments_Model.FilePath = strFilePath;
// o_SYS_Attachments_Model.SubFileName = strSubFileName;
// o_SYS_Attachments_Model.FileSize = uploadFileLength;
// o_SYS_Attachments_BLL.Add(o_SYS_Attachments_Model);
// uploadFileLength = 0;
// }
// catch (Exception ex)
// {
// strReturn = string.Empty;
// mo_Log.Error(ex.Message, ex);
// }
// }
// else if (Request.TotalBytes > gintUploadSize * 1024 * 1024)
// {
// ShowArtAlert("A00076", gintUploadSize.ToString());//上傳檔案超過指定大小{0}MB.
// }
// return strReturn;
//}
//#endregion
//#region FileDelete
///// <summary>
///// 刪除文件
///// </summary>
///// <param name="strFilePath"></param>
///// <param name="strFileName"></param>
///// <returns></returns>
//public Boolean fnFileDelete(string strFileGuid, string strOrganizationID)
//{
// try
// {
// string strFileFullName = fnGetFilePathByGuid(strFileGuid, strOrganizationID);
// OT.BLL.OTB_SYS_AttachmentFiles o_SYS_Attachments_BLL = new OT.BLL.OTB_SYS_AttachmentFiles();
// o_SYS_Attachments_BLL.Delete(strFileGuid, strOrganizationID);
// if (System.IO.File.Exists(Server.MapPath(strFileFullName)))
// {
// System.IO.File.SetAttributes(Server.MapPath(strFileFullName), System.IO.FileAttributes.Normal);
// System.IO.File.Delete(Server.MapPath(strFileFullName));
// }
// }
// catch (System.Exception ex)
// {
// mo_Log.Error(ex.Message);
// mo_Log.Fatal(ex.ToString());
// return false;
// }
// return true;
//}
//#endregion
//#region fnGetFilePathByGuid
///// <summary>
///// 依據文件Guid獲取文件路徑
///// </summary>
///// <param name="strGuid">文件Guid</param>
///// <returns></returns>
//public string fnGetFilePathByGuid(string strGuid, string strOrganizationID)
//{
// string strReturn = string.Empty;
// try
// {
// OT.BLL.OTB_SYS_AttachmentFiles o_SYS_Attachments_BLL = new OT.BLL.OTB_SYS_AttachmentFiles();
// OT.Model.OTB_SYS_AttachmentFiles o_SYS_Attachments_Model = o_SYS_Attachments_BLL.GetModel(strGuid, strOrganizationID);
// strReturn = o_SYS_Attachments_Model.FilePath;
// }
// catch (Exception ex)
// {
// strReturn = string.Empty;
// mo_Log.Error(ex.Message, ex);
// }
// return strReturn;
//}
//#endregion
#region fnSetDropDownList
/// <summary>
/// 依據最大編號自動產生排序下拉框
/// </summary>
/// <param name="dropControl">需要產生值的下拉選單</param>
/// <param name="intMaxItemNo">下拉選單的最大值</param>
public void fnSetDropDownList(DropDownList dropControl, int intMaxItemNo)
{
dropControl.Items.Clear();
for (int i = 1; i <= intMaxItemNo; i++)
{
dropControl.Items.Add(new ListItem(i.ToString(), i.ToString()));
}
}
#endregion
#region fnGetSystemSettingValueBySettingItem
/// <summary>
/// 依據設定項目獲取系統參數配置的值
/// </summary>
/// <param name="strSettingItem">設定項目</param>
/// <returns>設定值</returns>
public string fnGetSystemSettingValueBySettingItem(string strSettingItem)
{
string strSettingValue = string.Empty;
try
{
OT.Model.OTB_SYS_SystemSetting o_OTB_SYS_SystemSetting_Model = new OT.BLL.OTB_SYS_SystemSetting().GetModel(strSettingItem);
if (o_OTB_SYS_SystemSetting_Model != null && o_OTB_SYS_SystemSetting_Model.Effective == "Y")
{
strSettingValue = o_OTB_SYS_SystemSetting_Model.SettingValue;
}
}
catch (Exception ex)
{
mo_Log.Error(ex.Message, ex);
}
return strSettingValue;
}
#endregion
#region GetMaxNumber
#region GetMaxNumberClass
/// <summary>
/// 取得類別的自動編號
/// </summary>
/// <param name="ClassId">類別代號</param>
/// <returns></returns>
public string GetMaxNumberClass(string ClassId, string ModifyUser)
{
OT.BLL.CommonClass o_Common_BLL = new OT.BLL.CommonClass();
return o_Common_BLL.GetArgumentClassMaxNumber(ClassId, ModifyUser, 5);
}
#endregion
#region GetMaxNumberClass
/// <summary>
/// 取得類別的自動編號
/// </summary>
/// <param name="ClassId">類別代號</param>
/// <param name="intLen">長度</param>
/// <returns></returns>
public string GetMaxNumberClass(string ClassId, string ModifyUser, int intLen)
{
OT.BLL.CommonClass o_Common_BLL = new OT.BLL.CommonClass();
return o_Common_BLL.GetArgumentClassMaxNumber(ClassId, ModifyUser, intLen);
}
#endregion
#region GetMaxNumberCatData
/// <summary>
/// 取得類別下資料的自動編號
/// </summary>
/// <param name="ClassId">類別代號</param>
/// <param name="ItemId">參數代號</param>
/// <param name="intLen">長度</param>
/// <returns></returns>
public string GetMaxNumberCatData(string ClassId, string ItemId, string ModifyUser)
{
OT.BLL.CommonClass o_Common_BLL = new OT.BLL.CommonClass();
return o_Common_BLL.GetArgumentMaxNumber(ClassId, ItemId, ModifyUser, 5);
}
#endregion
#region GetMaxNumberCatData
/// <summary>
/// 取得類別下資料的自動編號
/// </summary>
/// <param name="ClassId">類別代號</param>
/// <param name="ItemId">參數代號</param>
/// <param name="intLen">長度</param>
/// <returns></returns>
public string GetMaxNumberCatData(string ClassId, string ItemId, string ModifyUser, int intLen)
{
OT.BLL.CommonClass o_Common_BLL = new OT.BLL.CommonClass();
return o_Common_BLL.GetArgumentMaxNumber(ClassId, ItemId, ModifyUser, 5);
}
#endregion
#region GetMaxNumberByType
/// <summary>
/// 取得類型下資料的自動編號
/// </summary>
/// <param name="Type">類別代號</param>
/// <param name="Flag">自動編號方式 Y:年;M:月;D:日;O:其他(不按照年月日編號)</param>
/// <returns>返回5位流水號不夠左邊補零</returns>
public static string GetMaxNumberByType(string Type, MaxNumberType Flag, string ModifyUser)
{
OT.BLL.CommonClass o_Common_BLL = new OT.BLL.CommonClass();
string strRetrun = string.Empty;
switch (Flag)
{
case MaxNumberType.Year:
strRetrun += gdteNowTime.ToString("yyyy");
break;
case MaxNumberType.Month:
strRetrun += gdteNowTime.ToString("yyyyMM");
break;
case MaxNumberType.Day:
strRetrun += gdteNowTime.ToString("yyyyMMdd");
break;
default:
strRetrun = string.Empty;
break;
}
return strRetrun += o_Common_BLL.GetMaxNumberByType(Type, Flag.ToString(), ModifyUser, 5);
}
/// <summary>
/// 取得類型下資料的自動編號
/// </summary>
/// <param name="Type">類別代號</param>
/// <param name="Flag">自動編號方式 Y:年;M:月;D:日;O:其他(不按照年月日編號)</param>
/// <param name="intLen">返回字符長度不夠左邊補零</param>
/// <returns>返回intLen位流水號不夠左邊補零</returns>
public static string GetMaxNumberByType(string Type, MaxNumberType Flag, string ModifyUser, int intLen)
{
OT.BLL.CommonClass o_Common_BLL = new OT.BLL.CommonClass();
string strRetrun = string.Empty;
switch (Flag)
{
case MaxNumberType.Year:
strRetrun += gdteNowTime.ToString("yyyy");
break;
case MaxNumberType.Month:
strRetrun += gdteNowTime.ToString("yyyyMM");
break;
case MaxNumberType.Day:
strRetrun += gdteNowTime.ToString("yyyyMMdd");
break;
default:
strRetrun = string.Empty;
break;
}
return strRetrun += o_Common_BLL.GetMaxNumberByType(Type, Flag.ToString(), ModifyUser, intLen);
}
/// <summary>
/// 取得類型下資料的自動編號
/// </summary>
/// <param name="Type">類別代號</param>
/// <param name="Flag">自動編號方式 Y:年;M:月;D:日;O:其他(不按照年月日編號)</param>
/// <param name="intLen">返回字符長度不夠左邊補零</param>
/// <param name="blIsAddPre">是否添加前綴</param>
/// <returns>返回intLen位流水號不夠左邊補零並且添加Type為前綴</returns>
public static string GetMaxNumberByType(string Type, MaxNumberType Flag, string ModifyUser, int intLen, bool blIsAddPre)
{
OT.BLL.CommonClass o_Common_BLL = new OT.BLL.CommonClass();
string strRetrun = string.Empty;
switch (Flag)
{
case MaxNumberType.Year:
strRetrun += gdteNowTime.ToString("yyyy");
break;
case MaxNumberType.Month:
strRetrun += gdteNowTime.ToString("yyyyMM");
break;
case MaxNumberType.Day:
strRetrun += gdteNowTime.ToString("yyyyMMdd");
break;
case MaxNumberType.Other:
strRetrun += gdteNowTime.ToString("yyMMdd");
break;
default:
strRetrun = string.Empty;
break;
}
if (blIsAddPre)
{
strRetrun = Type + strRetrun;
}
return strRetrun += o_Common_BLL.GetMaxNumberByType(Type, Flag.ToString(), ModifyUser, intLen);
}
/// <summary>
/// 取得類型下資料的自動編號
/// </summary>
/// <param name="Type">類別代號</param>
/// <param name="Flag">自動編號方式 Y:年;M:月;D:日;O:其他(不按照年月日編號)</param>
/// <returns>返回5位流水號不夠左邊補零</returns>
public string GetMaxNumberByType(string Type, string ModifyUser)
{
OT.BLL.CommonClass o_Common_BLL = new OT.BLL.CommonClass();
return o_Common_BLL.GetMaxNumberByType(Type, "O", ModifyUser, 5);
}
/// <summary>
/// 取得類型下資料的自動編號
/// </summary>
/// <param name="Type">類別代號</param>
/// <param name="Flag">自動編號方式 Y:年;M:月;D:日;O:其他(不按照年月日編號)</param>
/// <param name="intLen">返回字符長度不夠左邊補零</param>
/// <returns>返回intLen位流水號不夠左邊補零</returns>
public string GetMaxNumberByType(string Type, string ModifyUser, int intLen)
{
OT.BLL.CommonClass o_Common_BLL = new OT.BLL.CommonClass();
return o_Common_BLL.GetMaxNumberByType(Type, "O", ModifyUser, intLen);
}
/// <summary>
/// 取得類型下資料的自動編號
/// </summary>
/// <param name="Type">類別代號</param>
/// <param name="Flag">自動編號方式 Y:年;M:月;D:日;O:其他(不按照年月日編號)</param>
/// <param name="intLen">返回字符長度不夠左邊補零</param>
/// <param name="blIsAddPre">是否添加前綴</param>
/// <returns>返回intLen位流水號不夠左邊補零並且添加Type為前綴</returns>
public string GetMaxNumberByType(string Type, string ModifyUser, int intLen, bool blIsAddPre)
{
OT.BLL.CommonClass o_Common_BLL = new OT.BLL.CommonClass();
string strRetrun = string.Empty;
if (blIsAddPre)
{
strRetrun = Type + strRetrun;
}
return strRetrun + o_Common_BLL.GetMaxNumberByType(Type, "O", ModifyUser, intLen);
}
#endregion
#endregion
#region ShowMsg
/// <summary>
/// 彈出信息提示,並轉向指的頁面
/// </summary>
/// <param name="strCode">信息代號</param>
/// <param name="StrPara"></param>
/// <param name="url">參數</param>
///
public void fnUpdRemove()
{
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "fnUpdRemove", "<script> fnUpdRemove(); </script>", false);
}
public void fnUpdRemove(string fields)
{
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "fnUpdRemove", "<script> fnUpdRemove('" + fields + "'); </script>", false);
}
public void OpenPageTab(string strProgramId)
{
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "OpenPageTab", "<script> parent.OpenPageTab('" + strProgramId + "'); </script>", false);
}
public void OpenPageTab(string strProgramId, string parameters)
{
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "OpenPageTab", "<script> parent.OpenPageTab('" + strProgramId + "','" + parameters + "'); </script>", false);
}
public void ShowAndRedirect(string strCode, string strPara, string url)
{
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "messageRedirect", "<script> ShowAndRedirect('" + strCode + "','" + strPara + "','" + url + "','" + gstrUICulture + "'); </script>", false);
}
public void ShowArtCodeAndGo(string strCode, string strTipsPara, string strPara, string url)
{
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ShowArtCodeAndGo", "<script> ShowArtCodeAndGo('" + strCode + "','" + strTipsPara + "','" + strPara + "','" + url + "','" + gstrUICulture + "'); </script>", false);
}
public void ShowArtCodeAndClose(string strCode)
{
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ShowArtCodeAndClose", "<script> ShowArtCodeAndClose('" + strCode + "'); </script>", false);
}
public void ShowArtCodeAndClose(string strCode, string strID)
{
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ShowArtCodeAndClose", "<script> ShowArtCodeAndClose('" + strCode + "','" + strID + "'); </script>", false);
}
public void ShowArtCodeAndCloseAndClickBtn(string strCode)
{
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ShowArtCodeAndCloseAndClickBtn", "<script> ShowArtCodeAndCloseAndClickBtn('" + strCode + "'); </script>", false);
}
public void ShowArtCodeAndCloseAndClickBtn(string strCode, string strID, string strbtnid)
{
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ShowArtCodeAndCloseAndClickBtn", "<script> ShowArtCodeAndCloseAndClickBtn('" + strCode + "','" + strID + "','" + strbtnid + "'); </script>", false);
}
public void ShowArtAlert(string straCode)
{
ScriptManager.RegisterStartupScript(Page, this.GetType(), "ShowArtAlert", "<script> ShowArtAlert('" + straCode + "','','" + gstrUICulture + "'); </script>", false);
}
public void ShowArtAlert(string straCode, string straPara)
{
ScriptManager.RegisterStartupScript(Page, this.GetType(), "ShowArtAlert", "<script> ShowArtAlert('" + straCode + "','" + straPara + "','" + gstrUICulture + "'); </script>", false);
}
//public void ShowArtAlert(string strmessage)
//{
// ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ShowArtAlert", "<script> ShowArtAlert('" + strmessage + "'); </script>", false);
//}
/// <summary>
/// 彈出信息提示,並轉向指的頁面
/// </summary>
/// <param name="strCode">信息代號</param>
/// <param name="StrPara"></param>
/// <param name="url">參數</param>
public void ShowAndBaseRedirect(string straCode, string straPara, string straUrl)
{
ScriptManager.RegisterStartupScript(Page, this.GetType(), "messageRedirect", "<script> ShowAndBaseRedirect('" + straCode + "','" + straPara + "','" + straUrl + "','" + gstrUICulture + "'); </script>", false);
}
/// <summary>
/// 在頁面上彈出信息提示
/// </summary>
/// <param name="s_aCode">信息代號</param>
/// <param name="s_aPara">參數</param>
/// eg:show("000001","你好"); //你好
public void Show(string straCode, string straPara)
{
ScriptManager.RegisterStartupScript(Page, this.GetType(), "messageshow", "<script> Show('" + straCode + "','" + straPara + "','" + gstrUICulture + "'); </script>", false);
}
/// <summary>
/// 在頁面上彈出信息提示
/// </summary>
/// <param name="s_aCode">信息代號</param>
/// eg:show("000001"); //你好
public void Show(string straCode)
{
ScriptManager.RegisterStartupScript(Page, this.GetType(), "messageshow", "<script> Show('" + straCode + "','','" + gstrUICulture + "'); </script>", false);
}
/// <summary>
/// 給指定的Web控件,彈出確認框信息提示
/// </summary>
/// <param name="StrCode">信息代號</param>
/// <param name="StrPara">參數</param>
public void ShowConfirm(string StrCode, string StrPara)
{
ScriptManager.RegisterStartupScript(Page, this.GetType(), "messageshowcon", "<script> return ShowConfirm('" + StrCode + "','" + StrPara + "','" + gstrUICulture + "'); </script>", false);
}
///Author :Luther
/// <summary>
/// 給指定的Web控件,彈出確認框信息提示
/// </summary>
/// <param name="Control">Web控件</param>
/// <param name="StrCode">信息代號</param>
public void ShowConfirm(string StrCode)
{
ScriptManager.RegisterStartupScript(Page, this.GetType(), "messageshowcon", "<script> return ShowConfirm('" + StrCode + "','','" + gstrUICulture + "'); </script>", false);
}
#endregion
#region fnConvertToInt
/// <summary>
/// 將字符轉化成數字,如果轉化失敗則返回0
/// </summary>
/// <param name="strSource">需要轉化的字符串</param>
/// <returns></returns>
public static int fnConvertToInt(string strSource)
{
int intReturn;
int.TryParse(strSource, out intReturn);
return intReturn;
}
#endregion
#region GetUserNameByUserId
/// <summary>
/// 依據登入帳號獲取用戶名稱
/// </summary>
/// <param name="strUserId">登入帳號</param>
/// <returns></returns>
public string GetUserNameByUserId(string strUserId)
{
string strUserName = string.Empty;
try
{
if (!string.IsNullOrEmpty(strUserId))
{
strUserName = new OT.BLL.OTB_SYS_Members().GetModel(strUserId).MemberName;
//strUserName = new OT.BLL.CommonClass().GetActiveUserInfo(strUserId).NAME;
}
else
{
strUserName = "";
}
}
catch (Exception ex)
{
mo_Log.Debug(string.Format("BasePage.GetUserNameByUserId Debug : strUserId:{0}", strUserId), ex);
mo_Log.Fatal(ex.Message, ex);
}
return strUserName;
}
#endregion
#region fnOpenRpt
/// <summary>
/// 開啟報表
/// </summary>
/// <param name="strRptPath">報表的相對路徑</param>
/// <example>fnOpenRpt("");</example>
public void fnOpenRpt(string strRptPath)
{
//註意:只用使用window.open,使用其他無法列印。
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "fnOpenRptJS", "window.open('../../ViewReportPage.aspx?RptPath=" + strRptPath + "', '', 'height=750, width=1000, toolbar=no, menubar=no, scrollbars=no, resizable=yes, location=no, status=no');", true);
}
#endregion
#endregion
#region 私有方法區域
#region BasePage
/// <summary>
/// 初始化參數
/// </summary>
static BasePage()
{
dtAllowRightText = fnDataSetToDataTable(new OT.BLL.CommonClass().GetArgumentListByArgumentClassID("99999"));
DataView dvView = new DataView(dtAllowRightText);
dvView.Sort = " OrderByValue ASC ";
dtAllowRightText = dvView.ToTable();
if (dtAllowRightText.Rows.Count > 0)
{
garyAllowRight = new string[dtAllowRightText.Rows.Count];
for (int i = 0, j = dtAllowRightText.Rows.Count; i < j; i++)
{
garyAllowRight[i] = dtAllowRightText.Rows[i]["ArgumentID"].ToString();
}
}
else
{
garyAllowRight = new string[]{ "Add", "ReAdd", "Save", "Del"
, "Clear", "Upd", "Qry", "Exp"
, "Imp", "Leave", "Cpy"
, "Sub", "Chk", "Tmp", "Print"
,"View","RptAd"};
}
fnLoadSetting(); //加載系統參數設定
fnLoadProgramList(); //加載系統程式列表
}
#endregion
#region GetSystemSetting
/// <summary>
/// 依據參數代碼取得系統參數設定值
/// </summary>
/// <param name="strItemCode">參數代碼</param>
/// <returns>系統參數設定值</returns>
private static string GetSystemSetting(DataTable dtSysSetting, string strItemCode)
{
string strSettingValue = null;
try
{
DataRow[] drSettings = dtSysSetting.Select(" SettingItem = '" + strItemCode + "' ");
foreach (DataRow dr in drSettings)
{
strSettingValue = dr["SettingValue"].ToString().Trim();
}
}
catch (Exception ex)
{
mo_Log.Debug(string.Format("BasePage.GetSystemSetting Debug : Param:dtSysSetting{0};strItemCode={1}", Common.Serialize(dtSysSetting), strItemCode));
mo_Log.Error(ex.Message, ex);
}
return strSettingValue;
}
#endregion
#region GetProgramId
/// <summary>
/// 得到当前程式代号
/// </summary>
/// <returns></returns>
private void GetProgramId()
{
try
{
gstrProgramId = Request.AppRelativeCurrentExecutionFilePath;
//取程式名稱
string[] ary = gstrProgramId.Split('/');
if (ary.Length > 0)
{
gstrProgramId = ary[ary.Length - 1];
}
//去除後綴名和參數
string[] aryP = gstrProgramId.Split('.');
if (aryP.Length > 0)
{
gstrProgramId = aryP[0];
}
}
catch (Exception ex)
{
mo_Log.Debug("BasePage.GetProgramId Debug : Param:null");
mo_Log.Error(ex.Message, ex);
}
}
#endregion
#region CheckIsLogin
/// <summary>
/// CheckIsLogin
/// </summary>
protected virtual void CheckIsLogin()
{
try
{
string UnCheckPageName = ""; //所有排除驗證是否登錄的頁面
string testsss = gstrUserID;
if (Session["gstrUserId"] != null && Session["gstrUserLoginTime"] != null) //&& Session["gstrUserId"] != null 重複設定
{
//登入成功
gstrUserID = Session["gstrUserId"] == null ? "" : Session["gstrUserId"].ToString(); //登入者ID
DateTime.TryParse(Session["gstrUserLoginTime"].ToString(), out gdteUserLoginTime);
GetProgramRight(gstrProgramId);
if (gbl_ProgramStatus == "W" || gbl_ProgramStatus == "N")
{
//維修中,停用 Add by Alina 201401029 當畫面的狀態是維修中,停用,顯示對應的畫面
//如果是ADMIN 帳號 那就繼續使用以方便測試
if (gstrUserID.ToLower() != "admin")
{
Response.Redirect("~/Waiting.aspx?PageTile=" + gbl_ProgramStatus, false);
}
}
else
{
if (!gbl_AllowView && Request.Url.ToString().ToLower().IndexOf("page/") > -1)
{
//如果沒有cha權限則提示使用者沒有權限
Response.Redirect("~/NotView.aspx?PageTile=" + fnUrlEncode(gstrProgramName), false);//true-->false //轉入登入頁面
}
//FormsAuthentication.RedirectFromLoginPage(gstrUserID, true);
}
}
else if (UnCheckPageName.Contains(gstrProgramId) == false)
{
//Response.Redirect("~/Login.aspx", false);//true-->false//轉入登入頁面
//mo_Log.Debug("BasePage.CheckIsLogin Debug : Session['gstrUserId'] :" + Session["gstrUserId"] );
ClientScript.RegisterStartupScript(GetType(), "Load", "<script type='text/javascript'>window.top.location.href = '/Login.aspx'; </script>");
}
else
{
mo_Log.Debug("BasePage.CheckIsLogin Debug : Session['gstrUserId'] :" + Session["gstrUserId"] + "有ID 但沒有登入的程式!!");
ClientScript.RegisterStartupScript(GetType(), "Load", "<script type='text/javascript'>window.top.location.href = '/Error.aspx'; </script>");
}
}
catch (Exception ex)
{
mo_Log.Debug("BasePage.CheckIsLogin Debug : Param:null");
mo_Log.Error(ex.Message, ex);
}
}
#endregion
#region GetProgramRight
/// <summary>
/// 取得當前頁面的權限信息
/// </summary>
/// <param name="strCurrProgramId"></param>
private void GetProgramRight(string strCurrProgramId)
{
try
{
OT.BLL.OTB_SYS_Authorize o_SYS_Authorize_BLL = new OT.BLL.OTB_SYS_Authorize();
OT.Model.OTB_SYS_Authorize o_SYS_Authorize_Model = o_SYS_Authorize_BLL.GetModel(gstrUserID, strCurrProgramId);//gstrUserRoleId-->gstrUserID
if (o_SYS_Authorize_Model != null) //當不為子程式時判斷權限
{
gbl_AllowView = CheckButtonRight("View"); //檢視
gbl_AllowAdd = CheckButtonRight("Add"); //新增
gbl_AllowReAdd = CheckButtonRight("ReAdd"); //儲存後新增 增加儲存後新增權限判斷 Add by ted 2014/11/14
gbl_AllowCopy = CheckButtonRight("Cpy"); //複製 增加複製權限判斷 Add by ted 2014/11/14
gbl_AllowEdit = CheckButtonRight("Upd"); //編輯
gbl_AllowDel = CheckButtonRight("Del"); //刪除
gbl_AllowPrint = CheckButtonRight("Prt"); //列印
gbl_AllowExport = CheckButtonRight("Exp"); //匯出
gbl_AllowQuery = CheckButtonRight("Qry"); //查詢
gbl_AllowSub = CheckButtonRight("Sub"); //送審
gbl_AllowChk = CheckButtonRight("Chk"); //審核
gbl_AllowMail = CheckButtonRight("KeepPlaceMail_Pop", "View"); //檢驗是否有發送Mail的權限
gbl_AllowRpt = CheckButtonRight("RptAd"); //報表的最高權限
gbl_ProgramStatus = o_SYS_Authorize_Model.ProgramStatus;//程式的狀態
}
else
{ //Modify By Ted 2014/08/07 觸發並查無資料代表是子程式,所以權限不判斷直接通過
gbl_AllowView = true;
gbl_AllowAdd = true; //新增
gbl_AllowEdit = true; //編輯
gbl_AllowDel = true; //刪除
gbl_AllowPrint = true; //列印
gbl_AllowExport = true; //匯出
gbl_AllowQuery = true; //查詢
gbl_AllowSub = true; //送審
gbl_AllowChk = true; //審核
gbl_AllowMail = true; //檢驗是否有發送Mail的權限
gbl_AllowRpt = true; //報表的最高權限
gbl_ProgramStatus = "Y";//程式的狀態,預設啟用
}
}
catch (Exception ex)
{
mo_Log.Debug(string.Format("BasePage.GetProgramRight Debug : Param:strCurrProgramId={0}", strCurrProgramId));
mo_Log.Error(ex.Message, ex);
}
}
#endregion
//#region fnDelFileWhenDelSouce
///// <summary>
///// 刪除數據來源時也刪除掉附件的方法
///// </summary>
///// <param name="string">附件編號</param>
//public void fnDelFileWhenDelSouce(string strAttID)
//{
// try
// {
// //Add by Alina 20140210 合約刪除時刪除附件資料 Star
// DataSet dsFiles = new OT.BLL.CommonClass().GetFileListBySourceRelationID(strAttID);
// if (dsFiles != null && dsFiles.Tables.Count > 0)
// {
// DataTable dtFiles = dsFiles.Tables[0];
// foreach (DataRow dr in dtFiles.Rows)
// {
// string strTargetRelationID = dr["TargetRelationID"].ToString();
// string strOrganizationID = dr["OrganizationID"].ToString();
// if (!string.IsNullOrEmpty(strTargetRelationID))
// {
// string strFileFullName = fnGetFilePathByGuid(strTargetRelationID, strOrganizationID);
// OT.BLL.OTB_SYS_AttachmentFiles o_SYS_Attachments_BLL = new OT.BLL.OTB_SYS_AttachmentFiles();
// o_SYS_Attachments_BLL.Delete(strTargetRelationID, strOrganizationID);
// if (System.IO.File.Exists(Server.MapPath(strFileFullName)))
// {
// System.IO.File.Delete(Server.MapPath(strFileFullName));
// }
// }
// }
// }
// //Add by Alina 20140210 合約刪除時刪除附件資料 End
// }
// catch (Exception ex)
// {
// mo_Log.Error(ex.Message, ex);
// }
//}
//#endregion
#region GetRightInfo
/// <summary>
/// 取得權限信息
/// </summary>
/// <param name="strRight"></param>
/// <param name="Index"></param>
private string GetRightInfo(string strRight)
{
int index = 0;
return GetRightInfo(strRight, ref index);
}
/// <summary>
/// 取得權限信息
/// </summary>
/// <param name="strRight"></param>
/// <param name="index"></param>
private string GetRightInfo(string strRight, ref int index)
{
string strReturn = string.Empty;
try
{
//Add by Alina 20140718 因為按鈕不顯示出來 添加的
dtAllowRightText = fnDataSetToDataTable(new OT.BLL.CommonClass().GetArgumentListByArgumentClassID("99999"));
foreach (DataRow drDataRow in dtAllowRightText.Select(string.Format(" ArgumentID='{0}' ", strRight)))
{
strReturn = drDataRow["ArgumentValue"].ToString();
index = string.IsNullOrEmpty(drDataRow["OrderByValue"].ToString()) ? 0 : Convert.ToInt32(drDataRow["OrderByValue"].ToString());
}
}
catch (Exception ex)
{
mo_Log.Debug(string.Format("BasePage.GetRightInfo Debug : Param:strRight={0}", strRight));
mo_Log.Fatal(ex.Message, ex);
}
return strReturn;
}
#endregion
#region CheckButtonRight
/// <summary>
/// 驗證按鈕是否有權限
/// </summary>
/// <param name="strAction">按鈕動作名稱</param>
private bool CheckButtonRight(string strAction)
{
bool blHasRight = false;
try
{
DataTable dtAuthorize;
if (Session["dtAuthorize"] == null)
{
dtAuthorize = fnDataSetToDataTable(new OT.BLL.OTB_SYS_Authorize().GetListByRuleID(gstrUserID));//gstrUserRoleId-->gstrUserID
}
else
{
dtAuthorize = (DataTable)Session["dtAuthorize"];
}
DataRow[] drAuthorizes = dtAuthorize.Select(" ProgramID = '" + gstrProgramId + "' ");
foreach (DataRow dr in drAuthorizes)
{
blHasRight = dr["AllowRight"].ToString().Contains(strAction.Replace("btn", ""));
if (blHasRight)
{
break;
}
}
}
catch (Exception ex)
{
mo_Log.Debug(string.Format("BasePage.CheckButtonRight Debug : Param:strAction={0}", strAction));
mo_Log.Error(ex.Message, ex);
}
return blHasRight;
}
private bool CheckButtonRight(string strProgramId, string strAction)
{
bool blHasRight = false;
try
{ //Add by Alina 201401016 添加的這部分是為了顯示修改按鈕,但是權限還是按照真正是否有權限去處理的 Star
//目的是讓客戶知道還有一個修改的權限,如果要修改,需要去給權限,修改權限才可以用
if (strProgramId.Contains("_Upd") && strAction == "Upd")
{
blHasRight = true;
}//Add by Alina 201401016 添加的這部分是為了顯示修改按鈕,但是權限還是按照真正是否有權限去處理的 End
else
{
DataTable dtAuthorize;
if (Session["dtAuthorize"] == null)
{
dtAuthorize = fnDataSetToDataTable(new OT.BLL.OTB_SYS_Authorize().GetListByRuleID(gstrUserID));//gstrUserRoleId-->gstrUserID
}
else
{
dtAuthorize = (DataTable)Session["dtAuthorize"];
}
DataRow[] drAuthorizes = dtAuthorize.Select(" ProgramID = '" + strProgramId + "' ");
foreach (DataRow dr in drAuthorizes)
{
blHasRight = dr["AllowRight"].ToString().Contains(strAction.Replace("btn", ""));
if (blHasRight)
{
break;
}
}
}
}
catch (Exception ex)
{
mo_Log.Debug(string.Format("BasePage.CheckButtonRight Debug : Param:strAction={0}", strAction));
mo_Log.Error(ex.Message, ex);
}
return blHasRight;
}
#endregion
#region SetButtonRight
/// <summary>
/// 設定按鈕權限(顯示|隱藏)
/// </summary>
private void SetButtonRight()
{
try
{
//Added by Ethan,2014/04/22 Start. 如果程式有可用權限則添加按鈕。
if (!IsPostBack)
{
//非頁面第一次加載才執行
Toolbar toolbar = (Toolbar)Page.FindControl("Toolbar1");
if (toolbar != null)
{
string strCuryProgramAllowRights = GetProgramByColName("AllowRight");
foreach (
string strRight in
strCuryProgramAllowRights.Trim()
.Split(new char[1] { '|' }, StringSplitOptions.RemoveEmptyEntries))
{
ToolbarButton btnUpd = new ToolbarButton();
int intIndex = 0;
string strRightText = GetRightInfo(strRight, ref intIndex);
btnUpd.Key = strRight;
btnUpd.Text = strRightText;
btnUpd.Index = intIndex;
btnUpd.Enabled = true;
//btnUpd.CssClass = "icon-" + strRight.ToLower() + " btn01-" + strRight.ToLower() + " ";
btnUpd.CssClass = "btn";
if (CheckButtonRight(gstrProgramId, strRight))
{
btnUpd.Visible = true;
//如果Visible = trur 才有必要進行下列判斷,Visible=false 就沒有判斷的必要了
switch (strRight)
{
case "Leave":
btnUpd.Js += "if(fnLeaveInBack()){}else{if(fnCustomBack()){}else{parent.OpenPageTab('" + gstrProgramId.Substring(0, gstrProgramId.LastIndexOf("_")) + "_Qry" + "')};return false;}";
//使用fnUpdInBack() js判斷是否需要進入後台,如果為false,則只通過前台js達到解鎖效果
//目前fnUpdInBack預設為false,如頁面需要進入後台者,
//則在該頁面添加fnUpdInBack() js,並讓回傳值等於true
//Add by Gary 2014/05/30
//使用fnCustomBack() js判斷是否有自定義的需求,如果沒有則自動前往該頁的Qry畫面。 //Add by Gary 2014/07/31
break;
case "Clear":
btnUpd.CausesValidation = false;
btnUpd.Js += "try{if(!Page_ClientValidate('NotCheck')){return false;}}catch(e){;}";
//Add by Jack 20140724 重新定義了一個清除的js Start
btnUpd.Js += "fnAllPageClear();if(fnClientAllClear()){}else{setTimeout($.unblockUI,100); return false;}";//註冊清除js
//Add by Jack 20140724 重新定義了一個清除的js End
//Del by Jack 20140724 重新定義了一個清除的js(舊的不用了) Start
//modfiy by Alina 20140723 查詢畫面清空查詢條件即可 Star
//if (Request.QueryString["Action"] == "Qry" )
//if (Request.QueryString["Action"] == "Qry" || Request.QueryString["Action"] == null)
//modfiy by Alina 20140723 查詢畫面清空查詢條件即可 End
//{
// btnUpd.Js += "fnALLClear('#searchbar');if(fnClientAllClear()){}else{return false;};";
//}
//else
//{
//btnUpd.Js += "fnALLClear();if(fnClientAllClear()){}else{return false;}"; //比較建議,各自Upd的清空自行填寫 Add By Dean
//}
//Del by Jack 20140724 重新定義了一個清除的js(舊的不用了) Start
break;
case "Del": //刪除
btnUpd.Js += "if(!ShowConfirm('A00013','','',this)){___CloseWaitingForm();return false;}"; //增加刪除前提醒
btnUpd.Js += "this.value='刪除中…';"; //預設一開始是無法使用的
break;
case "Save": //儲存
btnUpd.Js += "try{if(!Page_ClientValidate()){___CloseWaitingForm();return false;}}catch(e){;}"; //可以回傳是否驗證通過
btnUpd.Js += "this.disabled=true;this.value='儲存中…';"; //預設一開始是無法使用的
break;
case "ReAdd"://儲存後新增
btnUpd.Js += "try{if(!Page_ClientValidate()){___CloseWaitingForm();return false;}}catch(e){;}"; //可以回傳是否驗證通過
btnUpd.Js += "this.disabled=true;this.value='儲存中…';"; //預設一開始是無法使用的
break;
case "Sub":
btnUpd.Js += "try{if(!Page_ClientValidate()){___CloseWaitingForm();return false;}}catch(e){;}";
break;
case "Chk":
btnUpd.Js += "try{if(!Page_ClientValidate()){___CloseWaitingForm();return false;}}catch(e){;}";
break;
case "Upd":
btnUpd.Js += "if(fnUpdInBack()){}else{fnUpdRemove();setTimeout($.unblockUI,100);$(this).addClass('displayNone');return false;}";
//使用fnUpdInBack() js判斷是否需要進入後台,如果為false,則只通過前台js達到解鎖效果
//目前fnUpdInBack預設為false,如頁面需要進入後台者,
//則在該頁面添加fnUpdInBack() js,並讓回傳值等於true
//Add by Gary 2014/05/30
break;
case "Exp":
btnUpd.Js += "setTimeout($.unblockUI,3000);";
break;
}
}
else
{
btnUpd.Visible = false;
}
if (Request.QueryString["Action"] == "Upd" && "|ReAdd".Contains("|" + strRight))
{
//隱藏按鈕,因為以上按鈕是不應該出現在編輯畫面Toolbar上的。
}
else if (Request.QueryString["Action"] == "Add" && ("|Del".Contains("|" + strRight) || "|Upd".Contains("|" + strRight) || "|Print".Contains("|" + strRight) || "|Exp".Contains("|" + strRight)))
{
//隱藏按鈕,因為以上按鈕是不應該出現在新增畫面Toolbar上的。
}
else if ("|View".Contains("|" + strRight))
{
//隱藏按鈕,因為以上按鈕是不應該出現在新增畫面Toolbar上的。
}
else if ("|Upd".Contains("|" + strRight) && (strCuryProgramAllowRights.IndexOf("Upd", StringComparison.InvariantCultureIgnoreCase) == -1 || strCuryProgramAllowRights.IndexOf("Save", StringComparison.InvariantCultureIgnoreCase) == -1))
{
//修改按鈕,無儲存權限 也應該沒有修改的權限
}
else if ("|Save".Contains("|" + strRight) && (strCuryProgramAllowRights.IndexOf("Upd", StringComparison.InvariantCultureIgnoreCase) == -1 || strCuryProgramAllowRights.IndexOf("Save", StringComparison.InvariantCultureIgnoreCase) == -1))
{
//儲存按鈕,如果有按修改,此功能方可作用
}
else if ("|Clear".Contains("|" + strRight) && gstrProgramId.IndexOf("_Upd", StringComparison.CurrentCultureIgnoreCase) > -1 && (strCuryProgramAllowRights.IndexOf("Upd", StringComparison.InvariantCultureIgnoreCase) == -1 || strCuryProgramAllowRights.IndexOf("Save", StringComparison.InvariantCultureIgnoreCase) == -1))
{
//清除按鈕,如果有按修改,此功能方可作用
}
else if (strRight.Contains("Upd") && gstrProgramId.IndexOf("_Upd", StringComparison.CurrentCultureIgnoreCase) == -1)
{
//隱藏編輯按鈕,因為編輯按鈕是不應該出現在Toolbar上的。2014/04/25添加判斷是否為修改畫面如果不是修改畫面不應該出現修改按鈕。
}
else
{
toolbar.Items.Add(btnUpd);
}
}
toolbar.Items.Sort();
}
}
//else
//{
// //每次都要更新按鈕是否顯示的狀態
// Toolbar toolbar = (Toolbar) Page.FindControl("Toolbar1");
// if (toolbar != null)
// {
// }
//}
//Added by Ethan,2014/04/22 End. 如果程式有可用權限則添加按鈕。
//Delete By Gary 2014/08/12 Start 這部分以該用ToolBar,所以以下代碼判斷沒有使用到,如果至8/31日前沒有發現問題即可刪除。
//foreach (string btnId in garyAllowRight)
//{
// Control btn = Page.FindControl("btn" + btnId);
// if (btn != null)
// {
// string strCuryProgramAllowRight = GetProgramByColName("AllowRight");
// strCuryProgramAllowRight = "|" + strCuryProgramAllowRight.Trim('|');
// if (strCuryProgramAllowRight.Contains("|" + btnId))
// {
// btn.Visible = CheckButtonRight("btn" + btnId);
// }
// else
// {
// btn.Visible = false;
// }
// if (Request.QueryString["Action"] == "Upd" && "|ReAdd".Contains("|" + btnId))
// {
// //隱藏按鈕,因為以上按鈕是不應該出現在編輯畫面Toolbar上的。
// btn.Visible = false;
// }
// else if (Request.QueryString["Action"] == "Add" && "|Del".Contains("|" + btnId))
// {
// //隱藏按鈕,因為以上按鈕是不應該出現在新增畫面Toolbar上的。
// btn.Visible = false;
// }
// if (btnId.Contains("Upd") && gstrProgramId.IndexOf("_Upd", StringComparison.CurrentCultureIgnoreCase) == -1)
// {
// //隱藏編輯按鈕,因為編輯按鈕是不應該出現在Toolbar上的。2014/04/25添加判斷是否為修改畫面如果不是修改畫面不應該出現修改按鈕。
// btn.Visible = false;
// }
// if (btnId.Contains("Del"))
// {
// //btn
// }
// }
//}
//Delete By Gary 2014/08/12 End 這部分以該用ToolBar,所以以下代碼判斷沒有使用到,如果至8/31日前沒有發現問題即可刪除。
}
catch (Exception ex)
{
mo_Log.Debug(string.Format("BasePage.SetButtonRight Debug : Param:null"));
mo_Log.Error(ex.Message, ex);
}
}
#endregion
#region GetRootURI
/// <summary>
/// 獲取網站的根Uri
/// </summary>
/// <returns></returns>
private string GetRootURI()
{
string AppPath = "";
try
{
if (Request.ApplicationPath != null || Request.ApplicationPath != "/")
{
AppPath = Request.ApplicationPath;
}
}
catch (Exception ex)
{
mo_Log.Error(ex.Message, ex);
}
return AppPath;
}
#endregion
#region RegisterStartupScript
/// <summary>
/// 注意BasePage的Page_Load事件在 繼承它的頁面的Page_Load事件之後執行
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void RegisterStartupScript()
{
//要在這掛載JS之前請先問過Dean
//自動添加JS
StringBuilder sbCommonString = new StringBuilder();
sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/jquery-1.10.2.min.js'></script>");
sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/jquery-ui-1.10.3.custom.min.js'></script>");
//sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/jquery-migrate-1.2.1.min.js'></script>"); //支援1.9版以前
//sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/jquery.ui.datepicker-zh-TW.js'></script>");
//sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/jquery-ui-sliderAccess.js'></script>");
sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/jquery-ui-timepicker-addon.js'></script>");
sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/jquery-ui-timepicker-zh-TW.js'></script>");
//sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/jquery.lightbox-0.5.min.js'></script>");
//sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/jquery.lazyload.js'></script>");
//sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/jquery.lightbox-0.5.pack.js'></script>");
//sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/shadowbox.js'></script>");
sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/jquery.artDialog.js?skin=simple'></script>");
sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/iframeTools.js'></script>");
sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/PageTab.js'></script>");
sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/MessageBox.js'></script>");
sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/blockUI.js'></script>"); //Add By Ted 2014/07/31 等待畫面的JS
sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/jquery.floatThead.min.js'></script>"); //Add By Ted 2014/08/04 浮動資料表頭JS
sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/Common.js'></script>");
//sbCommonString.AppendLine("<script defer=\"defer\">fnSetToolbarVisible(window);</script>");
string strStartUpScript = "<script defer=\"defer\">try{setTimeout(fnSetToolbarVisible(window),100);}catch(e){;}</script>";
ScriptManager.RegisterStartupScript(Page, this.Page.GetType(), "BasepageJs001", strStartUpScript, false); //RegisterStartupScript
string strUnDisScript = @"<script>
function SetUnDis() {
$('[disabled]').each(function (i, n) {
$(n).removeAttr('disabled');
$(n).removeAttr('onmouseover');
$(n).removeAttr('onclick');
$(n).attr('readonly', 'readonly');
});
}
$(document).ready(function () {
$('[disabled]').each(function (i, n) {
$(n).removeAttr('disabled');
$(n).attr('readonly', 'readonly');
$(n).focus(function () {
SetUnDis();
$(n).attr('disabled', 'disabled');
$(n).removeAttr('onmouseover');
$(n).removeAttr('onclick');
$(n).blur();
return false;
});
$(n).mousemove(function () {
SetUnDis();
$(n).attr('disabled', 'disabled');
$(n).removeAttr('onmouseover');
$(n).removeAttr('onclick');
$(n).blur();
return false;
});
$(n).focusin(function () {
SetUnDis();
$(n).attr('disabled', 'disabled');
$(n).removeAttr('onmouseover');
$(n).removeAttr('onclick');
$(n).blur();
return false;
});
});
});</script>";
//ScriptManager.RegisterClientScriptBlock(Page, this.Page.GetType(), "BasepageJs002UnDis", strUnDisScript, false); //RegisterStartupScript
Literal ltrUnDisScript = new Literal();
ltrUnDisScript.Text = strUnDisScript;
//Page.Controls.Add(ltrUnDisScript);
Literal ltrScript = new Literal();
ltrScript.Text = string.Format(sbCommonString.ToString(), GetRootURI().TrimEnd('/'));
//Page.Header.Controls.Add(ltrScript);
Page.Header.Controls.AddAt(0, ltrScript); //Modify By Gary 修正js加入順序
//Del by Jack 20140724 重新定義了一個給頁面賦值的js Start
//ScriptManager.RegisterClientScriptBlock(Page, this.Page.GetType(), "BasepageJs002", string.Format(sbCommonString.ToString(), GetRootURI().TrimEnd('/')), false); //RegisterStartupScript
//if ((!IsPostBack && Request.QueryString["Action"] == "Upd") || Request.QueryString["Action"] == "Upd" || Request.QueryString["Action"] == "Add" || (!IsPostBack && Request.QueryString["Action"] == "Add"))
//modfiy by Alina 20140723 修改此版的原因是因為查詢畫面不需要註冊“_Value”屬性,直接清空 Star
// if ((!IsPostBack && Request.QueryString["Action"] == "Upd") || (!IsPostBack && Request.QueryString["Action"] == "Add") || (!IsPostBack && Request.QueryString["Action"] == "Qry") || (!IsPostBack && Request.QueryString["Action"] == null)) //Modify by Gary 2014/06/06
//if ((!IsPostBack && Request.QueryString["Action"] == "Upd") || (!IsPostBack && Request.QueryString["Action"] == "Add") || (!IsPostBack && Request.QueryString["Action"] == "Qry"))
////modfiy by Alina 20140723 修改此版的原因是因為查詢畫面不需要註冊“_Value”屬性,直接清空 End
//{
// //頁面第一次加載執行
// ScriptManager.RegisterStartupScript(Page, Page.GetType(), "BasepageJs003", "try{setTimeout(fnLoadPageSaveValueAAA,200);}catch(e){;}", true);
//}
//Del by Jack 20140724 重新定義了一個給頁面賦值的js End
//Add by Jack 20140724 重新定義了一個給頁面賦值的js Start
if (!IsPostBack && Request.QueryString["Action"] == null)
//在查詢畫面賦值(只在第一次加載頁面賦值)
{
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "BasepageJs003", "try{setTimeout(fnLoadPageSaveArrayValue('#searchbar'),400);fnLoadPageSaveValueAAA();}catch(e){;}", true);
//btnUpd.Js += "fnLoadPageSaveArrayValue('#searchbar');if(fnClientAllClear()){}else{return false;};";
}
else if ((!IsPostBack && Request.QueryString["Action"] == "Upd") || (!IsPostBack && Request.QueryString["Action"] == "Add") || (!IsPostBack && Request.QueryString["Action"] == "Qry"))
//在編輯畫面賦值(只在頁面第一次加載賦值)
{
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "BasepageJs003", "try{setTimeout(fnLoadPageSaveArrayValue(),200);}catch(e){;}", true);
}
if (!string.IsNullOrEmpty(Request.QueryString["ErrMsg"]) && Request.QueryString["ErrMsg"] == "FileMaxError")
{
ShowArtAlert("A00076", gintUploadSize.ToString());
}
//Add by Jack 20140724 重新定義了一個給頁面賦值的js End
// string strLoadMsg = @"<div id='doing' style='CURSOR: wait; Z-INDEX: 12000; LEFT: 0px; WIDTH: 100%; POSITION: absolute; TOP: 0px; HEIGHT: 100%;'>
// 頁面加載中……
// </div>
// <script language='javascript' type='text/javascript'>
// function MyOnload() {
// document.getElementById('doing').style.display = 'none';
// }
// setTimeout(MyOnload,200);
// </script>";
// Literal ltrLoadMsgScript = new Literal();
// ltrLoadMsgScript.Text = strLoadMsg;
// Page.Controls.Add(ltrLoadMsgScript);
}
#endregion
#region SetTheme
/// <summary>
/// 設定頁面樣式
/// </summary>
private void SetTheme()
{
string strTheme = Common.GetAppSettings("DefaultTheme");
try
{
if (Session["THEME"] != null)
{
//如果有記錄Session值,則去Session設定。
strTheme = Session["THEME"].ToString();
HttpCookie cookie = new HttpCookie("OTK.Theme", Session["THEME"].ToString());
cookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(cookie);
}
else
{
if (Request.Cookies["OTK.Theme"] != null && string.IsNullOrEmpty(Request.Cookies["OTK.Theme"].ToString()))
{
//如果沒有記錄Session值但有Cookie时,則取Cookie的設定。
strTheme = Request.Cookies["OTK.Theme"].Value.ToString();
}
Session["THEME"] = strTheme;
}
}
catch (Exception ex)
{
strTheme = Common.GetAppSettings("DefaultTheme").ToString().ToLower();
Session["THEME"] = gstrUICulture;
mo_Log.Error(ex.Message, ex);
}
Page.Theme = strTheme;
}
#endregion
#region SetPageTitle
/// <summary>
/// 設定程式的Title
/// </summary>
/// <param name="strProgramId"></param>
/// Add By Dean 2014/05/21 增加各畫面顯示使用資料表名稱
private void SetPageTitle()
{
try
{
if (gdtProgramList == null)
{
fnLoadProgramList();
}
if (gdtProgramList.Rows.Count > 0)
{
Label lbFunctionTitle = ((Label)FindControl("lbFunctionTitle"));
if (lbFunctionTitle != null)
{
lbFunctionTitle.Text = gstrProgramName;
}
Label lbMainTableName = ((Label)FindControl("lbMainTableName")); /*Add By Dean 2014/05/21*/
if (lbMainTableName != null)
{
lbMainTableName.Text = "(Use:" + gstrProgramTableName + ")";
}
}
}
catch (Exception ex)
{
mo_Log.Error(ex.Message, ex);
}
}
#endregion
#region GetProgramByColName
/// <summary>
/// 通過欄位名稱獲取當前程式的信息
/// </summary>
/// <param name="strProgramId"></param>
private string GetProgramByColName(string strColName)
{
string strReturn = string.Empty;
try
{
if (gdtProgramList == null)
{
fnLoadProgramList();
}
if (gdtProgramList.Rows.Count > 0)
{
DataRow[] drs = gdtProgramList.Select(" ProgramID = '" + gstrProgramId + "'");
foreach (DataRow dr in drs)
{
strReturn = dr[strColName].ToString();
}
}
}
catch (Exception ex)
{
mo_Log.Error(ex.Message, ex);
}
return strReturn;
}
#endregion
#endregion
#region 頁面事件觸發區域
#region InitializeCulture
/// <summary>
/// 多語言設定
/// </summary>
protected override void InitializeCulture()
{
try
{
if (Session["CULTURE"] != null)
{
//如果有記錄Session值,則去Session設定。
gstrUICulture = Session["CULTURE"].ToString();
HttpCookie cookie = new HttpCookie("AD1688.Language", Session["CULTURE"].ToString());
cookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(cookie);
}
else
{
if (Request.Cookies["AD1688.Language"] != null && string.IsNullOrEmpty(Request.Cookies["AD1688.Language"].ToString()))
{
//如果沒有記錄Session值但有Cookie时,則取Cookie的設定。
gstrUICulture = Request.Cookies["AD1688.Language"].Value.ToString();
}
else if (Request.UserLanguages != null && !string.IsNullOrEmpty(Request.UserLanguages[0]))
{
//如果沒有記錄Session值和Cookie时,則取客戶端瀏覽器預設語言。
gstrUICulture = Request.UserLanguages[0].ToLower();
}
else
{
//如果沒有記錄Session值和Cookie时,取客戶端瀏覽器預設語言失敗則取系統設定的預設語言。
gstrUICulture = Common.GetAppSettings("DefaultLanguage").ToString().ToLower();
}
Session["CULTURE"] = gstrUICulture;
}
}
catch (Exception ex)
{
gstrUICulture = Common.GetAppSettings("DefaultLanguage").ToString().ToLower();
Session["CULTURE"] = gstrUICulture;
mo_Log.Error(ex.Message, ex);
}
string real_culture = "";
switch (gstrUICulture)
{
case "TW":
UICulture = "zh-TW";
Culture = "zh-TW";
real_culture = "zh-TW";
break;
case "CN":
UICulture = "zh-CN";
Culture = "zh-CN";
real_culture = "zh-CN";
break;
default:
UICulture = "en-US";
Culture = "en-US";
real_culture = "en-US";
break;
}
UICulture = real_culture;
Culture = real_culture;
Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture(real_culture);
Thread.CurrentThread.CurrentUICulture = new
CultureInfo(real_culture);
base.InitializeCulture();
}
#endregion
#region OnPreInit
/// <summary>
/// 頁面進入前出發事件
/// </summary>
/// <param name="e"></param>
protected override void OnPreInit(EventArgs e)
{
SetTheme();
base.OnPreInit(e);
}
#endregion
#region OnInit
/// <summary>
/// 頁面進入事件
/// </summary>
/// <param name="e"></param>
protected override void OnInit(EventArgs e)
{
GetProgramId(); //得到当前程式代号
gstrProgramName = GetProgramByColName("ProgramName"); //獲取程式的Title
gstrProgramTableName = GetProgramByColName("MainTableName"); //獲取程式所使用的主TableName
CheckIsLogin(); //驗證是否成功登入
base.OnInit(e);
gstrVirtualPath = Page.Request.ApplicationPath; //項目的虛擬路徑
gstrLocalPath = this.Server.MapPath(Page.Request.ApplicationPath); //項目的物理路徑
}
#endregion
#region OnLoad
/// <summary>
/// 頁面加載事件
/// </summary>
/// <param name="e"></param>
protected override void OnLoad(System.EventArgs e)
{
RegisterStartupScript(); //註冊腳本
SetPageTitle(); //設定程式的Title
SetButtonRight(); //設定按鈕權限(顯示|隱藏)
//Modified by Gary,20140325 Start. 因應旅遊業系統,在編輯畫面先把所有編輯功能鎖定
if (!string.IsNullOrEmpty(Request.QueryString["Action"]) && Request.QueryString["Action"].ToUpper() == "UPD")
{
if (!IsPostBack) //只在第一次載入時作業 Modify By Gary 20140326
{
if (gbl_AllowEdit)
{
//modfiy by Alina 20140426 加載編輯畫面時,Toobar上應該放開修改,離開,列印按鈕,其他按鈕在點擊修改後再放開 End
// ScriptManager.RegisterStartupScript(Page, Page.GetType(), "NotUpdJS", "try{setTimeout(fnUnDisabledThisCtl(),20);}catch(e){;}", true);
//modfiy by Alina 20141115 有修改權限,修改按鈕隱藏掉。
// ScriptManager.RegisterStartupScript(Page, Page.GetType(), "NotUpdJS", "try{setTimeout(fnUnDisabledThisCtl('Toolbar1_Leave,Toolbar1_Print,Toolbar1_Upd'),20);}catch(e){;}", true);
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "NotUpdJS", "try{setTimeout(fnHiddenUpd(),20);}catch(e){;}", true);
//modfiy by Alina 20140426 加載編輯畫面時,Toobar上應該放開修改,離開,列印按鈕,其他按鈕在點擊修改後再放開 Star
}
else
{
//當編輯資料的時候發現沒有權限,則禁止畫面修改。
//Modified by Ethan,20130528 Start. 修改結案報表編輯畫面無法列印的問題
//ScriptManager.RegisterStartupScript(Page, Page.GetType(), "NotUpdJS", "try{setTimeout(fnUnDisabledThisCtl('btnLeave'),20);}catch(e){;}", true);
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "NotUpdJS", "try{setTimeout(fnUnDisabledThisCtl('Toolbar1_Leave,btnLeave,btnPrint','NoUpd'),20);}catch(e){;}", true);
//Modified by Gary,20140325 在fnUnDisabledThisCtl添加第二個參數判斷是否有權限修改
//Modified by Ethan,20130528 End. 修改結案報表編輯畫面無法列印的問題
}
}
}
//Modified by Gary,20140325 End. 因應旅遊業系統,在編輯畫面先把所有編輯功能鎖定
base.OnLoad(e);
}
#endregion
#region OnPreRender
/// <summary>
/// 頁面呈現前事件
/// </summary>
/// <param name="e"></param>
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
}
#endregion
#region Render
/// <summary>
/// 繪製頁面內容
/// </summary>
/// <param name="writer"></param>
protected override void Render(HtmlTextWriter writer)
{
StringWriter stringWriter = new StringWriter();
HtmlTextWriter oldwriter = new HtmlTextWriter(stringWriter);
base.Render(oldwriter);
string oldContent = stringWriter.ToString();
string newContent = oldContent.Replace("{Theme}", Page.Theme).Replace("App_Themes/Default/", string.Format("App_Themes/{0}/", Page.Theme)); //修改Image的路徑為當前樣式的路徑
writer.Write(newContent);
}
#endregion
#region OnError
/// <summary>
/// 頁面錯誤觸發事件
/// </summary>
/// <param name="e"></param>
protected override void OnError(EventArgs e)
{
Exception Error = Server.GetLastError();
mo_Log.Error(Error.Message, Error);
string strUrl = string.Format("~/Error.aspx?ErrMsg={0}", fnUrlEncode(Error.Message));
Response.Redirect(strUrl, false);//true-->false
}
#endregion
#endregion
}
}