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.

2624 lines
128 KiB

  1. using System;
  2. using System.Collections;
  3. using System.Globalization;
  4. using System.IO;
  5. using System.Net;
  6. using System.Text;
  7. using System.Threading;
  8. using System.Web;
  9. using System.Web.UI;
  10. using System.Data;
  11. using System.Web.UI.WebControls;
  12. using log4net;
  13. using System.Web.Security;
  14. using OT.Controls.Toolbar;
  15. namespace OT.Web.Ap_Code
  16. {
  17. public class BasePage : System.Web.UI.Page
  18. {
  19. #region 定義全局變量
  20. public static string gstrUserDptID; //登入者用戶部門
  21. public static string gstrOrganizationID; //組織編號
  22. public string gstrUserID; //登入者用戶ID
  23. public static string gstrUserRoleId; //登入者所在的角色Id 一個用戶會對應多種角色
  24. public string gstrUserGuid; //登入者的Guid
  25. public string gstrGroupGuid; //登入者所在單位的Guid
  26. public string gstrUserGroupId; //登入者所在單位(部門)
  27. public string gstrUserDocOrCFO; //登入者如果是Doc:文管部門,CFO:財務部門
  28. public string gstrProgramId; //程式代號
  29. public string gstrProgramName; //程式名稱
  30. public string gstrProgramTableName; //程式所使用的主TABLE (山富要求)
  31. public string gstrUICulture; //頁面多語言
  32. public string gstrLocalPath; //項目的物理路徑
  33. public string gstrVirtualPath; //項目的虛擬路徑
  34. public DateTime gdteUserLoginTime; //登入時間
  35. public static DateTime gdteNowTime = DateTime.Now; //當前系統DB時間 new OT.BLL.CommonClass().GetDate()
  36. public static string gstrUploadFilePath = "Upload"; //檔案上傳路徑
  37. public static string gstrUploadFilePathPage; //頁面區塊上傳的文件夾,先放在DMImg內
  38. public static int gintGirdViewPageSize = 15; //GridView分頁筆數
  39. public static int gintGirdViewPageButtonSize = 10; //GridView分頁頁碼顯示數量
  40. public static DataTable gdtProgramList; //系統所有程式列表
  41. public static string gstrUploadType = "jpg|gif|bmp|tif|png"; //圖示上傳類型
  42. public static string gstrDocNo; //文管部門EIP編號
  43. public static string gstrCFONo; //財務部門EIP編號
  44. public static int gintUploadSize = 2; //檔案上傳大小*MB
  45. public static int gintUploadCloseFileCount = 30; //檔案上傳大小*MB
  46. public static int gintUploadCloseImgSize = 5; //檔案上傳大小*MB
  47. public static int gintUploadCloseImgCount = 30; //檔案上傳大小*MB
  48. public static string gstrStartTime = "9";
  49. public static string gstrEndTime = "22";
  50. public bool gbl_AllowView; //檢視權限
  51. public bool gbl_AllowAdd; //新增權限
  52. public bool gbl_AllowReAdd; //儲存後新增權限 增加儲存後新增權限 Add by ted 2014/11/14
  53. public bool gbl_AllowCopy; //複製權限 增加複製權限 Add by ted 2014/11/14
  54. public bool gbl_AllowEdit; //修改權限
  55. public bool gbl_AllowDel; //刪除權限
  56. public bool gbl_AllowPrint; //列印權限
  57. public bool gbl_AllowExport; //匯出權限
  58. public bool gbl_AllowQuery; //查詢權限
  59. public bool gbl_AllowSub; //送審權限
  60. public bool gbl_AllowChk; //審核權限
  61. public bool gbl_AllowUpd; //查詢權限
  62. public bool gbl_AllowMail; //發送Mail的權限
  63. public bool gbl_AllowRpt; //報表的最高權限
  64. public string gbl_ProgramStatus; //程式的狀態
  65. public static string[] garyAllowRight = new string[]{ "Add", "ReAdd", "Save", "Del"
  66. , "Clear", "Upd", "Qry", "Exp"
  67. , "Imp", "Leave", "Cpy"
  68. , "Sub", "Chk", "Tmp", "Print"
  69. ,"View","RptAd"}; //系統所有可用權限
  70. public static DataTable dtAllowRightText = new DataTable();
  71. public static readonly ILog mo_Log = LogManager.GetLogger(
  72. System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);//記錄異常
  73. #endregion
  74. #region 定義頁面變量
  75. #endregion
  76. #region 定義屬性區域
  77. #endregion
  78. #region 公有方法區域
  79. #region DateDiff
  80. /// <summary>
  81. /// 取得時間差(小時),超過y
  82. /// </summary>
  83. /// <param name="DateTime1"></param>
  84. /// <param name="DateTime2"></param>
  85. /// <returns></returns>
  86. public int fnDateDiff(DateTime DateTime1, DateTime DateTime2)
  87. {
  88. int dateDiff = 0;
  89. TimeSpan ts1 = new TimeSpan(Convert.ToDateTime(DateTime1.ToString("yyyy/MM/dd")).Ticks);
  90. TimeSpan ts2 = new TimeSpan(Convert.ToDateTime(DateTime2.ToString("yyyy/MM/dd")).Ticks);
  91. TimeSpan ts = ts1.Subtract(ts2).Duration();
  92. dateDiff = ts.Days + 1;
  93. return dateDiff;
  94. }
  95. #endregion
  96. #region GroupRows
  97. /// <summary>
  98. /// 合併GridView欄位相同的行
  99. /// </summary>
  100. /// <param name="GridView1">GridView物件</param>
  101. /// <param name="cellNum">需要合併欄位的索引</param>
  102. public void fnGroupRows(GridView GridView1, int cellNum)
  103. {
  104. int i = 0, rowSpanNum = 1;
  105. while (i < GridView1.Rows.Count - 1)
  106. {
  107. GridViewRow gvr = GridView1.Rows[i];
  108. for (++i; i < GridView1.Rows.Count; i++)
  109. {
  110. GridViewRow gvrNext = GridView1.Rows[i];
  111. if (gvr.Cells[cellNum].Text == gvrNext.Cells[cellNum].Text)
  112. {
  113. gvrNext.Cells[cellNum].Visible = false;
  114. rowSpanNum++;
  115. }
  116. else
  117. {
  118. gvr.Cells[cellNum].RowSpan = rowSpanNum;
  119. rowSpanNum = 1;
  120. break;
  121. }
  122. if (i == GridView1.Rows.Count - 1)
  123. {
  124. gvr.Cells[cellNum].RowSpan = rowSpanNum;
  125. }
  126. }
  127. }
  128. }
  129. #endregion
  130. #region fnGetRightText
  131. public string fnGetRightText(string strRightValue)
  132. {
  133. string strReturn = string.Empty;
  134. switch (strRightValue.Trim())
  135. {
  136. case "Add":
  137. strReturn = "新增";
  138. break;
  139. case "ReAdd":
  140. strReturn = "儲存後新增";
  141. break;
  142. case "Save":
  143. strReturn = "儲存";
  144. break;
  145. case "Del":
  146. strReturn = "刪除";
  147. break;
  148. case "Clear":
  149. strReturn = "清除";
  150. break;
  151. case "Upd":
  152. strReturn = "修改";
  153. break;
  154. case "Qry":
  155. strReturn = "查詢";
  156. break;
  157. case "Exp":
  158. strReturn = "匯出";
  159. break;
  160. case "Imp":
  161. strReturn = "匯入";
  162. break;
  163. case "Leave":
  164. strReturn = "離開";
  165. break;
  166. case "Cpy":
  167. strReturn = "複製";
  168. break;
  169. case "Sub":
  170. strReturn = "送審";
  171. break;
  172. case "Chk":
  173. strReturn = "審核";
  174. break;
  175. case "Tmp":
  176. strReturn = "新增範例";
  177. break;
  178. case "Print":
  179. strReturn = "列印";
  180. break;
  181. case "View":
  182. strReturn = "檢視";
  183. break;
  184. case "RptAd":
  185. strReturn = "報表管理";
  186. break;
  187. }
  188. return strReturn;
  189. }
  190. #endregion
  191. #region fnDataSetToDataTable
  192. /// <summary>
  193. /// 返回DataSet中第一個DataTable
  194. /// </summary>
  195. /// <param name="ds">需要轉換的DataSet</param>
  196. /// <returns></returns>
  197. public static DataTable fnDataSetToDataTable(DataSet ds)
  198. {
  199. DataTable dt = new DataTable();
  200. if (ds != null && ds.Tables.Count > 0)
  201. {
  202. dt = ds.Tables[0];
  203. }
  204. return dt;
  205. }
  206. #endregion
  207. #region fnDataSetToDataTable
  208. /// <summary>
  209. /// 返回DataSet中第一個DataTable
  210. /// </summary>
  211. /// <param name="ds">需要轉換的DataSet</param>
  212. /// <param name="strTableName">Table的名稱</param>
  213. /// <returns></returns>
  214. public static DataTable fnDataSetToDataTable(DataSet ds, string strTableName)
  215. {
  216. DataTable dt = new DataTable();
  217. if (ds != null && ds.Tables.Count > 0 && ds.Tables[strTableName] != null)
  218. {
  219. dt = ds.Tables[strTableName];
  220. }
  221. return dt;
  222. }
  223. #endregion
  224. #region fnExportToOfficeFile
  225. /// <summary>
  226. /// 將GridView內容以HTML存成Excel、Word檔案,儲存後內容含格式資訊
  227. /// 須設定頁面EnableEventValidation="false"
  228. /// </summary>
  229. /// <param name="vGridView">GridView物件名稱</param>
  230. /// <param name="vHtmlTable">包含Excel標題的物件名稱,註:不能含有Button</param>
  231. /// <param name="vFileName">存檔檔名</param>
  232. /// <param name="vPage">來源Page頁面(ex:Page)</param>
  233. /// <remarks>
  234. /// 程式做法:
  235. /// 利用GridView自行Render出與網頁上格式相同的HTML,
  236. /// 配合application/vnd.xls MIME Type,讓資料可以直接在Excel、Word中重現
  237. /// 註:
  238. /// 使用此 Function 須 using System.Web
  239. /// </remarks>
  240. public void fnExportToOfficeFile(System.Web.UI.WebControls.GridView vGridView, System.Web.UI.HtmlControls.HtmlTable vHtmlTable, string vFileName, System.Web.UI.Page vPage)
  241. {
  242. if (vGridView.Rows.Count == 0)
  243. {
  244. ShowArtAlert("A00072"); //無資料匯出
  245. return;
  246. }
  247. //關閉換頁跟排序
  248. //說明:若GridView無分頁功能、或有啟用分頁但只有1頁的資料時,則直接將資料Render出來
  249. //若有啟用分頁功能且頁數有2頁以上,當DataSource為null時,則不進行轉換為Excel的動作
  250. //if (vGridView.AllowPaging && vGridView.DataSource != null)
  251. //{
  252. //vGridView.AllowSorting = false;
  253. //vGridView.AllowPaging = false;
  254. //vGridView.DataBind();
  255. //}
  256. //瀏覽器為IE時將檔名編碼,避免存檔後中文檔名會變亂碼
  257. string strFileName = string.Empty;
  258. if (HttpContext.Current.Request.Browser.Browser == "IE")
  259. {
  260. strFileName = HttpUtility.UrlPathEncode(vFileName);
  261. }
  262. else
  263. {
  264. strFileName = vFileName;
  265. }
  266. HttpContext.Current.Response.Clear();
  267. HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
  268. HttpContext.Current.Response.ContentType = "application/vnd.xls";
  269. HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + strFileName);
  270. HttpContext.Current.Response.AddHeader("mata", "http-equiv=Content-Type content=text/html;charset=utf-8");
  271. //註:若中文字會變亂碼,則替換下面的程式試試
  272. //HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("big5");
  273. //HttpContext.Current.Response.Write("<meta http-equiv=Content-Type content=text/html;charset=utf-8>")
  274. //HttpContext.Current.Response.Write("<head><meta http-equiv=Content-Type content=text/html;charset=big5></head>")
  275. //HttpContext.Current.Response.Charset = "big5";
  276. System.IO.StringWriter sw = new System.IO.StringWriter();
  277. System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
  278. //建立假HtmlForm避免以下錯誤:
  279. //Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server
  280. //另一種做法是建立 override VerifyRenderingInServerForm function,在function內不寫程式碼
  281. //這樣就可以直接執行 GridView1.RenderControl(htw)
  282. //出現上面的錯誤在Page添加 EnableEventValidation="false"
  283. System.Web.UI.HtmlControls.HtmlForm hf = new System.Web.UI.HtmlControls.HtmlForm();
  284. vPage.Controls.Add(hf);
  285. vHtmlTable.RenderControl(htw);
  286. hf.Controls.Add(vGridView);
  287. hf.RenderControl(htw);
  288. string strHtml = sw.ToString().Replace("<div>", "").Replace("</div>", "");
  289. int iS = strHtml.IndexOf("<input", 0);
  290. if (iS != -1)
  291. {
  292. int iE = strHtml.IndexOf("/>", iS);
  293. strHtml = strHtml.Substring(0, iS) + strHtml.Substring(iE + 2, strHtml.Length - iE - 2);
  294. }
  295. //System.Web.UI.HtmlControls.HtmlMeta meta = new System.Web.UI.HtmlControls.HtmlMeta();
  296. //meta. = "";
  297. string strMeta = "<meta http-equiv=\"Content-Type\" content=\"text/html\"; charset=\"utf-8\" />";
  298. strHtml = strMeta + strHtml;
  299. HttpContext.Current.Response.Write(strHtml);
  300. HttpContext.Current.Response.End();
  301. }
  302. #endregion
  303. #region fnExportToOfficeFile
  304. /// <summary>
  305. /// 將GridView內容以HTML存成Excel、Word檔案,儲存後內容含格式資訊
  306. /// 須設定頁面EnableEventValidation="false"
  307. /// </summary>
  308. /// <param name="vGridView">GridView物件名稱</param>
  309. /// <param name="vHtmlTable">包含Excel標題的物件名稱,註:不能含有Button</param>
  310. /// <param name="vFileName">存檔檔名</param>
  311. /// <param name="vPage">來源Page頁面(ex:Page)</param>
  312. /// <remarks>
  313. /// 程式做法:
  314. /// 利用GridView自行Render出與網頁上格式相同的HTML,
  315. /// 配合application/vnd.xls MIME Type,讓資料可以直接在Excel、Word中重現
  316. /// 註:
  317. /// 使用此 Function 須 using System.Web
  318. /// </remarks>
  319. 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)
  320. {
  321. if (vGridView.Rows.Count == 0)
  322. {
  323. ShowArtAlert("A00072"); //無資料匯出
  324. return;
  325. }
  326. //關閉換頁跟排序
  327. //說明:若GridView無分頁功能、或有啟用分頁但只有1頁的資料時,則直接將資料Render出來
  328. //若有啟用分頁功能且頁數有2頁以上,當DataSource為null時,則不進行轉換為Excel的動作
  329. if (vGridView.AllowPaging && vGridView.DataSource != null)
  330. {
  331. vGridView.AllowSorting = false;
  332. vGridView.AllowPaging = false;
  333. vGridView.DataBind();
  334. }
  335. //瀏覽器為IE時將檔名編碼,避免存檔後中文檔名會變亂碼
  336. string strFileName = string.Empty;
  337. if (HttpContext.Current.Request.Browser.Browser == "IE")
  338. {
  339. strFileName = HttpUtility.UrlPathEncode(vFileName);
  340. }
  341. else
  342. {
  343. strFileName = vFileName;
  344. }
  345. HttpContext.Current.Response.Clear();
  346. HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
  347. HttpContext.Current.Response.ContentType = "application/vnd.xls";
  348. HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + strFileName);
  349. HttpContext.Current.Response.AddHeader("mata", "http-equiv=Content-Type content=text/html;charset=big5");
  350. //註:若中文字會變亂碼,則替換下面的程式試試
  351. //HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("big5");
  352. //HttpContext.Current.Response.Write("<meta http-equiv=Content-Type content=text/html;charset=utf-8>")
  353. //HttpContext.Current.Response.Write("<head><meta http-equiv=Content-Type content=text/html;charset=big5></head>")
  354. //HttpContext.Current.Response.Charset = "big5";
  355. System.IO.StringWriter sw = new System.IO.StringWriter();
  356. System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
  357. //建立假HtmlForm避免以下錯誤:
  358. //Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server
  359. //另一種做法是建立 override VerifyRenderingInServerForm function,在function內不寫程式碼
  360. //這樣就可以直接執行 GridView1.RenderControl(htw)
  361. //出現上面的錯誤在Page添加 EnableEventValidation="false"
  362. System.Web.UI.HtmlControls.HtmlForm hf = new System.Web.UI.HtmlControls.HtmlForm();
  363. vPage.Controls.Add(hf);
  364. vHtmlTableHead.RenderControl(htw);
  365. hf.Controls.Add(vGridView);
  366. hf.RenderControl(htw);
  367. vHtmlTableFoot.RenderControl(htw);
  368. string strHtml = sw.ToString().Replace("<div>", "").Replace("</div>", "");
  369. int iS = strHtml.IndexOf("<input", 0);
  370. if (iS != -1)
  371. {
  372. int iE = strHtml.IndexOf("/>", iS);
  373. strHtml = strHtml.Substring(0, iS) + strHtml.Substring(iE + 2, strHtml.Length - iE - 2);
  374. }
  375. HttpContext.Current.Response.Write(strHtml);
  376. HttpContext.Current.Response.End();
  377. }
  378. #endregion
  379. #region fnExportToOfficeFile
  380. /// <summary>
  381. /// 將GridView內容以HTML存成Excel、Word檔案,儲存後內容含格式資訊
  382. /// 須設定頁面EnableEventValidation="false"
  383. /// </summary>
  384. /// <param name="vGridView">GridView物件名稱</param>
  385. /// <param name="vHtmlTable">包含Excel標題的物件名稱,註:不能含有Button</param>
  386. /// <param name="vFileName">存檔檔名</param>
  387. /// <param name="vPage">來源Page頁面(ex:Page)</param>
  388. /// <remarks>
  389. /// 程式做法:
  390. /// 利用GridView自行Render出與網頁上格式相同的HTML,
  391. /// 配合application/vnd.xls MIME Type,讓資料可以直接在Excel、Word中重現
  392. /// 註:
  393. /// 使用此 Function 須 using System.Web
  394. /// </remarks>
  395. public void fnExportToOfficeFile(System.Web.UI.WebControls.GridView vGridView, string vFileName, System.Web.UI.Page vPage)
  396. {
  397. if (vGridView.Rows.Count == 0)
  398. {
  399. ShowArtAlert("A00072"); //無資料匯出
  400. return;
  401. }
  402. //關閉換頁跟排序
  403. //說明:若GridView無分頁功能、或有啟用分頁但只有1頁的資料時,則直接將資料Render出來
  404. //若有啟用分頁功能且頁數有2頁以上,當DataSource為null時,則不進行轉換為Excel的動作
  405. if (vGridView.AllowSorting && vGridView.DataSource != null)
  406. {
  407. vGridView.AllowSorting = false;
  408. vGridView.DataBind();
  409. }
  410. //瀏覽器為IE時將檔名編碼,避免存檔後中文檔名會變亂碼
  411. string strFileName = string.Empty;
  412. if (HttpContext.Current.Request.Browser.Browser == "IE")
  413. {
  414. strFileName = HttpUtility.UrlPathEncode(vFileName);
  415. }
  416. else
  417. {
  418. strFileName = vFileName;
  419. }
  420. HttpContext.Current.Response.Clear();
  421. HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
  422. HttpContext.Current.Response.ContentType = "application/vnd.xls";
  423. HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + strFileName);
  424. HttpContext.Current.Response.AddHeader("mata", "http-equiv=Content-Type content=text/html;charset=big5");
  425. //HttpContext.Current.Response.AddHeader("mata", "http-equiv=Content-Type content=text/html;charset=utf-8");
  426. //註:若中文字會變亂碼,則替換下面的程式試試
  427. HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("big5");
  428. //HttpContext.Current.Response.Write("<meta http-equiv=Content-Type content=text/html;charset=utf-8>")
  429. HttpContext.Current.Response.Write("<head><meta http-equiv=Content-Type content=text/html;charset=big5></head>");
  430. HttpContext.Current.Response.Charset = "big5";
  431. System.IO.StringWriter sw = new System.IO.StringWriter();
  432. System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
  433. //建立假HtmlForm避免以下錯誤:
  434. //Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server
  435. //另一種做法是建立 override VerifyRenderingInServerForm function,在function內不寫程式碼
  436. //這樣就可以直接執行 GridView1.RenderControl(htw)
  437. //出現上面的錯誤在Page添加 EnableEventValidation="false"
  438. System.Web.UI.HtmlControls.HtmlForm hf = new System.Web.UI.HtmlControls.HtmlForm();
  439. vPage.Controls.Add(hf);
  440. hf.Controls.Add(vGridView);
  441. hf.RenderControl(htw);
  442. string strHtml = sw.ToString().Replace("<div>", "").Replace("</div>", "");
  443. int iS = strHtml.IndexOf("<input", 0);
  444. if (iS != -1)
  445. {
  446. int iE = strHtml.IndexOf("/>", iS);
  447. strHtml = strHtml.Substring(0, iS) + strHtml.Substring(iE + 2, strHtml.Length - iE - 2);
  448. }
  449. HttpContext.Current.Response.Write(strHtml);
  450. HttpContext.Current.Response.Flush();
  451. HttpContext.Current.Response.End();
  452. }
  453. #endregion
  454. #region fnExportToOfficeFile
  455. /// <summary>
  456. /// 將GridView內容以HTML存成Excel、Word檔案,儲存後內容含格式資訊
  457. /// 須設定頁面EnableEventValidation="false"
  458. /// </summary>
  459. /// <param name="vGridView">GridView物件名稱</param>
  460. /// <param name="vHtmlTable">包含Excel標題的物件名稱,註:不能含有Button</param>
  461. /// <param name="vFileName">存檔檔名</param>
  462. /// <param name="vPage">來源Page頁面(ex:Page)</param>
  463. /// <remarks>
  464. /// 程式做法:
  465. /// 利用GridView自行Render出與網頁上格式相同的HTML,
  466. /// 配合application/vnd.xls MIME Type,讓資料可以直接在Excel、Word中重現
  467. /// 註:
  468. /// 使用此 Function 須 using System.Web
  469. /// </remarks>
  470. public void fnExportToOfficeFile(System.Web.UI.HtmlControls.HtmlTable vHtmlTable, string vFileName, System.Web.UI.Page vPage)
  471. {
  472. if (vHtmlTable.Rows.Count == 0)
  473. {
  474. ShowArtAlert("A00072"); //無資料匯出
  475. return;
  476. }
  477. //瀏覽器為IE時將檔名編碼,避免存檔後中文檔名會變亂碼
  478. string strFileName = string.Empty;
  479. if (HttpContext.Current.Request.Browser.Browser == "IE")
  480. {
  481. strFileName = HttpUtility.UrlPathEncode(vFileName);
  482. }
  483. else
  484. {
  485. strFileName = vFileName;
  486. }
  487. HttpContext.Current.Response.Clear();
  488. HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
  489. HttpContext.Current.Response.ContentType = "application/vnd.xls";
  490. HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + strFileName);
  491. HttpContext.Current.Response.AddHeader("mata", "http-equiv=Content-Type content=text/html;charset=big5");
  492. //註:若中文字會變亂碼,則替換下面的程式試試
  493. //HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("big5");
  494. //HttpContext.Current.Response.Write("<meta http-equiv=Content-Type content=text/html;charset=utf-8>")
  495. //HttpContext.Current.Response.Write("<head><meta http-equiv=Content-Type content=text/html;charset=big5></head>")
  496. //HttpContext.Current.Response.Charset = "big5";
  497. System.IO.StringWriter sw = new System.IO.StringWriter();
  498. System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
  499. //建立假HtmlForm避免以下錯誤:
  500. //Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server
  501. //另一種做法是建立 override VerifyRenderingInServerForm function,在function內不寫程式碼
  502. //這樣就可以直接執行 GridView1.RenderControl(htw)
  503. //出現上面的錯誤在Page添加 EnableEventValidation="false"
  504. System.Web.UI.HtmlControls.HtmlForm hf = new System.Web.UI.HtmlControls.HtmlForm();
  505. vPage.Controls.Add(hf);
  506. hf.Controls.Add(vHtmlTable);
  507. //vHtmlTable.RenderControl(htw);
  508. hf.RenderControl(htw);
  509. //string strCSSUrl = GetRootURI() + "/App_Themes/Default/ReportStyle.css";
  510. //string strCss = @"";
  511. //strCss = fnReadFully(strCSSUrl);
  512. //HttpContext.Current.Response.Write("<style type=\"text/css\">" + strCss + "</style>");
  513. HttpContext.Current.Response.Write(sw.ToString().Replace("<div>", "").Replace("</div>", ""));
  514. HttpContext.Current.Response.End();
  515. }
  516. #endregion
  517. #region fnExportToOfficeFile
  518. /// <summary>
  519. /// 將GridView內容以HTML存成Excel、Word檔案,儲存後內容含格式資訊
  520. /// 須設定頁面EnableEventValidation="false"
  521. /// </summary>
  522. /// <param name="vGridView">GridView物件名稱</param>
  523. /// <param name="vHtmlTable">包含Excel標題的物件名稱,註:不能含有Button</param>
  524. /// <param name="vFileName">存檔檔名</param>
  525. /// <param name="vPage">來源Page頁面(ex:Page)</param>
  526. /// <param name="strStringColIndexs">文字欄位(ex:例如報表第一列和第四列為文字類型,則傳"0;3;")</param>
  527. /// <remarks>
  528. /// 程式做法:
  529. /// 利用GridView自行Render出與網頁上格式相同的HTML,
  530. /// 配合application/vnd.xls MIME Type,讓資料可以直接在Excel、Word中重現
  531. /// 註:
  532. /// 使用此 Function 須 using System.Web
  533. /// </remarks>
  534. public void fnExportToOfficeFile(System.Web.UI.WebControls.GridView vGridView, string vFileName, System.Web.UI.Page vPage, string strStringColIndexs)
  535. {
  536. if (vGridView.Rows.Count == 0)
  537. {
  538. ShowArtAlert("A00072"); //無資料匯出
  539. return;
  540. }
  541. //關閉換頁跟排序
  542. //說明:若GridView無分頁功能、或有啟用分頁但只有1頁的資料時,則直接將資料Render出來
  543. //若有啟用分頁功能且頁數有2頁以上,當DataSource為null時,則不進行轉換為Excel的動作
  544. if (vGridView.AllowPaging && vGridView.DataSource != null)
  545. {
  546. vGridView.Attributes.Add("StringColIndexs", strStringColIndexs);
  547. vGridView.RowDataBound += new GridViewRowEventHandler(vGridView_RowDataBound);
  548. vGridView.AllowSorting = false;
  549. vGridView.AllowPaging = false;
  550. vGridView.DataBind();
  551. }
  552. //瀏覽器為IE時將檔名編碼,避免存檔後中文檔名會變亂碼
  553. string strFileName = string.Empty;
  554. if (HttpContext.Current.Request.Browser.Browser == "IE")
  555. {
  556. strFileName = HttpUtility.UrlPathEncode(vFileName);
  557. }
  558. else
  559. {
  560. strFileName = vFileName;
  561. }
  562. HttpContext.Current.Response.Clear();
  563. HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
  564. HttpContext.Current.Response.ContentType = "application/vnd.xls";
  565. HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + strFileName);
  566. HttpContext.Current.Response.AddHeader("mata", "http-equiv=Content-Type content=text/html;charset=big5");
  567. //註:若中文字會變亂碼,則替換下面的程式試試
  568. //HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("big5");
  569. //HttpContext.Current.Response.Write("<meta http-equiv=Content-Type content=text/html;charset=utf-8>")
  570. //HttpContext.Current.Response.Write("<head><meta http-equiv=Content-Type content=text/html;charset=big5></head>")
  571. //HttpContext.Current.Response.Charset = "big5";
  572. System.IO.StringWriter sw = new System.IO.StringWriter();
  573. System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
  574. //建立假HtmlForm避免以下錯誤:
  575. //Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server
  576. //另一種做法是建立 override VerifyRenderingInServerForm function,在function內不寫程式碼
  577. //這樣就可以直接執行 GridView1.RenderControl(htw)
  578. //出現上面的錯誤在Page添加 EnableEventValidation="false"
  579. System.Web.UI.HtmlControls.HtmlForm hf = new System.Web.UI.HtmlControls.HtmlForm();
  580. vPage.Controls.Add(hf);
  581. hf.Controls.Add(vGridView);
  582. hf.RenderControl(htw);
  583. string strHtml = sw.ToString().Replace("<div>", "").Replace("</div>", "");
  584. int iS = strHtml.IndexOf("<input", 0);
  585. if (iS != -1)
  586. {
  587. int iE = strHtml.IndexOf("/>", iS);
  588. strHtml = strHtml.Substring(0, iS) + strHtml.Substring(iE + 2, strHtml.Length - iE - 2);
  589. }
  590. HttpContext.Current.Response.Write(strHtml);
  591. HttpContext.Current.Response.End();
  592. }
  593. #endregion
  594. #region fnExportToOfficeFile
  595. /// <summary>
  596. /// 將GridView內容以HTML存成Excel、Word檔案,儲存後內容含格式資訊
  597. /// 須設定頁面EnableEventValidation="false"
  598. /// </summary>
  599. /// <param name="vGridView">GridView物件名稱</param>
  600. /// <param name="vHtmlTable">包含Excel標題的物件名稱,註:不能含有Button</param>
  601. /// <param name="vFileName">存檔檔名</param>
  602. /// <param name="vPage">來源Page頁面(ex:Page)</param>
  603. /// <param name="strStringColIndexs">文字欄位(ex:例如報表第一列和第四列為文字類型,則傳"0;3;")</param>
  604. /// <remarks>
  605. /// 程式做法:
  606. /// 利用GridView自行Render出與網頁上格式相同的HTML,
  607. /// 配合application/vnd.xls MIME Type,讓資料可以直接在Excel、Word中重現
  608. /// 註:
  609. /// 使用此 Function 須 using System.Web
  610. /// </remarks>
  611. public void fnExportToOfficeFile(System.Web.UI.WebControls.GridView vGridView, System.Web.UI.HtmlControls.HtmlTable vHtmlTable, string vFileName, System.Web.UI.Page vPage, string strStringColIndexs)
  612. {
  613. if (vGridView.Rows.Count == 0)
  614. {
  615. ShowArtAlert("A00072"); //無資料匯出
  616. return;
  617. }
  618. //關閉換頁跟排序
  619. //說明:若GridView無分頁功能、或有啟用分頁但只有1頁的資料時,則直接將資料Render出來
  620. //若有啟用分頁功能且頁數有2頁以上,當DataSource為null時,則不進行轉換為Excel的動作
  621. //if (vGridView.AllowPaging && vGridView.DataSource != null)
  622. //{
  623. //vGridView.AllowSorting = false;
  624. //vGridView.AllowPaging = false;
  625. //vGridView.DataBind();
  626. //}
  627. if (vGridView.DataSource != null)
  628. {
  629. vGridView.Attributes.Add("StringColIndexs", strStringColIndexs);
  630. vGridView.RowDataBound += new GridViewRowEventHandler(vGridView_RowDataBound);
  631. vGridView.AllowSorting = false;
  632. vGridView.AllowPaging = false;
  633. vGridView.DataBind();
  634. }
  635. //瀏覽器為IE時將檔名編碼,避免存檔後中文檔名會變亂碼
  636. string strFileName = string.Empty;
  637. //新增判斷 by Gary 2013/12/30
  638. if (HttpContext.Current.Request.Browser.Browser == "IE" || HttpContext.Current.Request.Browser.Browser == "InternetExplorer")
  639. {
  640. strFileName = HttpUtility.UrlPathEncode(vFileName);
  641. }
  642. else
  643. {
  644. strFileName = vFileName;
  645. }
  646. HttpContext.Current.Response.Clear();
  647. HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
  648. HttpContext.Current.Response.ContentType = "application/vnd.xls";
  649. HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + strFileName);
  650. HttpContext.Current.Response.AddHeader("mata", "http-equiv=Content-Type content=text/html;charset=utf-8");
  651. //註:若中文字會變亂碼,則替換下面的程式試試
  652. //HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("big5");
  653. //HttpContext.Current.Response.Write("<meta http-equiv=Content-Type content=text/html;charset=utf-8>")
  654. //HttpContext.Current.Response.Write("<head><meta http-equiv=Content-Type content=text/html;charset=big5></head>")
  655. //HttpContext.Current.Response.Charset = "big5";
  656. System.IO.StringWriter sw = new System.IO.StringWriter();
  657. System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
  658. //建立假HtmlForm避免以下錯誤:
  659. //Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server
  660. //另一種做法是建立 override VerifyRenderingInServerForm function,在function內不寫程式碼
  661. //這樣就可以直接執行 GridView1.RenderControl(htw)
  662. //出現上面的錯誤在Page添加 EnableEventValidation="false"
  663. System.Web.UI.HtmlControls.HtmlForm hf = new System.Web.UI.HtmlControls.HtmlForm();
  664. vPage.Controls.Add(hf);
  665. vHtmlTable.RenderControl(htw);
  666. hf.Controls.Add(vGridView);
  667. hf.RenderControl(htw);
  668. string strHtml = sw.ToString().Replace("<div>", "").Replace("</div>", "");
  669. int iS = strHtml.IndexOf("<input", 0);
  670. if (iS != -1)
  671. {
  672. int iE = strHtml.IndexOf("/>", iS);
  673. strHtml = strHtml.Substring(0, iS) + strHtml.Substring(iE + 2, strHtml.Length - iE - 2);
  674. }
  675. //System.Web.UI.HtmlControls.HtmlMeta meta = new System.Web.UI.HtmlControls.HtmlMeta();
  676. //meta. = "";
  677. string strMeta = "<meta http-equiv=\"Content-Type\" content=\"text/html\"; charset=\"utf-8\" />";
  678. strHtml = strMeta + strHtml;
  679. //HttpContext.Current.Response.Write(strHtml);
  680. //HttpContext.Current.Response.End();
  681. Session["FileName"] = strFileName;
  682. Session["Data"] = strHtml;
  683. Response.Redirect("~/ExpFile.aspx", true);
  684. //Context.Items.Add("FileName", strFileName);
  685. //Context.Items.Add("Data", strHtml);
  686. //Server.Transfer("~/ExpFile.aspx",true);
  687. }
  688. #endregion
  689. public class RemotePost
  690. {
  691. private System.Collections.Specialized.NameValueCollection Inputs = new System.Collections.Specialized.NameValueCollection();
  692. public string Url = "";
  693. public string Method = "post";
  694. public string FormName = "form1";
  695. public void Add(string name, string value)
  696. {
  697. Inputs.Add(name, value);
  698. }
  699. public void Post()
  700. {
  701. System.Web.HttpContext.Current.Response.Clear();
  702. System.Web.HttpContext.Current.Response.Write("<html><head>");
  703. System.Web.HttpContext.Current.Response.Write(string.Format("</head><body onload='document.{0}.submit()'>", FormName));
  704. System.Web.HttpContext.Current.Response.Write(string.Format("<form name='{0}' method='{1}' action='{2}' >", FormName, Method, Url));
  705. for (int i = 0; i < Inputs.Keys.Count; i++)
  706. {
  707. System.Web.HttpContext.Current.Response.Write(string.Format("<input name='{0}' type='hidden' value='{1}'>", Inputs.Keys[i], Inputs[Inputs.Keys[i]]));
  708. }
  709. System.Web.HttpContext.Current.Response.Write("</form>");
  710. System.Web.HttpContext.Current.Response.Write("</body></html>");
  711. System.Web.HttpContext.Current.Response.End();
  712. }
  713. }
  714. #region vGridView_RowDataBound
  715. /// <summary>
  716. /// 把含有數字的欄位的值轉換成字符串
  717. /// </summary>
  718. /// <param name="sender"></param>
  719. /// <param name="e"></param>
  720. protected void vGridView_RowDataBound(object sender, GridViewRowEventArgs e)
  721. {
  722. string strStringColIndexs = ((GridView)sender).Attributes["StringColIndexs"];
  723. if (!string.IsNullOrEmpty(strStringColIndexs))
  724. {
  725. foreach (string index in strStringColIndexs.Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries))
  726. {
  727. e.Row.Cells[int.Parse(index)].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
  728. }
  729. }
  730. }
  731. #endregion
  732. #region fnUrlEncode
  733. /// <summary>
  734. /// Url編碼
  735. /// </summary>
  736. /// <param name="strSource">需要編碼的原始字符串</param>
  737. /// <returns>url編碼後的字符串</returns>
  738. public string fnUrlEncode(string strSource)
  739. {
  740. return Server.UrlEncode(strSource);
  741. }
  742. #endregion
  743. #region fnUrlDecode
  744. /// <summary>
  745. /// Url解碼
  746. /// </summary>
  747. /// <param name="strSource">需要解碼的原始字符串</param>
  748. /// <returns>url解碼後的字符串</returns>
  749. public string fnUrlDecode(string strSource)
  750. {
  751. return Server.UrlDecode(strSource);
  752. }
  753. #endregion
  754. #region fnGetSortColumnIndex
  755. /// <summary>
  756. /// 獲取Gridview指定排序欄位的索引
  757. /// </summary>
  758. /// <param name="gv">目標Gridview</param>
  759. /// <param name="strSortExpression">排序欄位名稱</param>
  760. /// <returns>Gridview指定排序欄位的索引</returns>
  761. public int fnGetSortColumnIndex(GridView gv, string strFile)
  762. {
  763. int intIndex = -1;
  764. foreach (DataControlField field in gv.Columns)
  765. {
  766. if (field.SortExpression == strFile)
  767. {
  768. intIndex = gv.Columns.IndexOf(field);
  769. break;
  770. }
  771. }
  772. return intIndex;
  773. }
  774. #endregion
  775. #region fnAddSortImage
  776. /// <summary>
  777. /// 為排序欄位添加圖示
  778. /// </summary>
  779. /// <param name="columnIndex">排序欄位的索引</param>
  780. /// <param name="headerRow">GirdView的HeaderRow</param>
  781. public void fnAddSortImage(int columnIndex, string strSortDirection, GridViewRow headerRow)
  782. {
  783. System.Web.UI.HtmlControls.HtmlAnchor sortImage = new System.Web.UI.HtmlControls.HtmlAnchor();
  784. if (strSortDirection == "ASC")
  785. {
  786. sortImage.Attributes.Add("class", "sortedascendingheaderstyle");
  787. }
  788. else
  789. {
  790. sortImage.Attributes.Add("class", "sorteddescendingheaderstyle");
  791. }
  792. sortImage.InnerText = headerRow.Cells[columnIndex].Text;
  793. headerRow.Cells[columnIndex].Controls.Add(sortImage);
  794. }
  795. #endregion
  796. #region fnAddSortImage
  797. /// <summary>
  798. /// 為排序欄位添加圖示
  799. /// </summary>
  800. /// <param name="columnIndex">排序欄位的索引</param>
  801. /// <param name="headerCell">GirdView的DataControlFieldHeaderCell</param>
  802. public void fnAddSortImage(string strSortDirection, DataControlFieldHeaderCell headerCell)
  803. {
  804. System.Web.UI.HtmlControls.HtmlAnchor sortImage = new System.Web.UI.HtmlControls.HtmlAnchor();
  805. if (strSortDirection == "ASC")
  806. {
  807. sortImage.Attributes.Add("class", "sortedascendingheaderstyle");
  808. }
  809. else
  810. {
  811. sortImage.Attributes.Add("class", "sorteddescendingheaderstyle");
  812. }
  813. //sortImage.InnerText = strSortDirection;
  814. headerCell.Controls.Add(sortImage);
  815. }
  816. #endregion
  817. #region fnLoadSetting
  818. /// <summary>
  819. /// 加載系統參數設定
  820. /// </summary>
  821. public static void fnLoadSetting()
  822. {
  823. try
  824. {
  825. gstrUserDptID = "001";
  826. gstrUserRoleId = "Admin";
  827. gstrOrganizationID = "Origtek";
  828. OT.BLL.OTB_SYS_SystemSetting o_SYS_SystemSetting_BLL = new OT.BLL.OTB_SYS_SystemSetting();
  829. DataTable dtSystemSetting = fnDataSetToDataTable(o_SYS_SystemSetting_BLL.GetAllList());
  830. if (dtSystemSetting.Rows.Count > 0)
  831. {
  832. //如果存在資料
  833. int.TryParse(GetSystemSetting(dtSystemSetting, "GridRecords"), out gintGirdViewPageSize); //GridView分頁筆數
  834. if (gintGirdViewPageSize == 0)
  835. {
  836. gintGirdViewPageSize = 15; //預設分頁筆數
  837. }
  838. int.TryParse(GetSystemSetting(dtSystemSetting, "GridPages"), out gintGirdViewPageButtonSize); //GridView分頁頁碼顯示數量
  839. if (gintGirdViewPageSize == 0)
  840. {
  841. gintGirdViewPageSize = 10; //預設顯示頁碼數
  842. }
  843. gstrUploadFilePath = GetSystemSetting(dtSystemSetting, "UploadPath"); //文檔上傳路徑
  844. gstrUploadFilePath = gstrUploadFilePath ?? "Upload";
  845. gstrUploadType = GetSystemSetting(dtSystemSetting, "UploadImgTpe"); //圖片格式
  846. gstrUploadType = gstrUploadType ?? "jpg|gif|bmp|tif|png";
  847. //string strAllowRight = GetSystemSetting(dtSystemSetting, "AllowRight");//系統所有可用權限
  848. //if (string.IsNullOrEmpty(strAllowRight))
  849. //{
  850. // garyAllowRight = new string[]{ "Add", "ReAdd", "Save", "Del"
  851. // , "Clear", "Upd", "Qry", "Exp"
  852. // , "Imp", "Leave", "Cpy"
  853. // , "Sub", "Chk", "Tmp"};
  854. //}
  855. //else
  856. //{
  857. // garyAllowRight = strAllowRight.Split('|');
  858. //}
  859. int.TryParse(GetSystemSetting(dtSystemSetting, "UploadSize"), out gintUploadSize);//檔案上傳大小*MB
  860. if (gintUploadSize == 0)
  861. {
  862. gintUploadSize = 2;
  863. }
  864. int.TryParse(GetSystemSetting(dtSystemSetting, "CloseFileCount"), out gintUploadCloseFileCount);//檔案上傳大小*MB
  865. if (gintUploadCloseFileCount == 0)
  866. {
  867. gintUploadCloseFileCount = 30;
  868. }
  869. int.TryParse(GetSystemSetting(dtSystemSetting, "CloesImgSize"), out gintUploadCloseImgSize);//檔案上傳大小*MB
  870. if (gintUploadCloseImgSize == 0)
  871. {
  872. gintUploadCloseImgSize = 5;
  873. }
  874. int.TryParse(GetSystemSetting(dtSystemSetting, "CloseImgCount"), out gintUploadCloseImgCount);//檔案上傳大小*MB
  875. if (gintUploadCloseImgCount == 0)
  876. {
  877. gintUploadCloseImgCount = 30;
  878. }
  879. gstrStartTime = GetSystemSetting(dtSystemSetting, "StartTime") ?? "9"; //日期控件默認的開始時間
  880. gstrEndTime = GetSystemSetting(dtSystemSetting, "EndTime") ?? "21"; //日期控件的默認結束時間
  881. gstrDocNo = GetSystemSetting(dtSystemSetting, "DocNo") ?? ""; //文管部門EIP編號
  882. gstrCFONo = GetSystemSetting(dtSystemSetting, "CFONo") ?? ""; //財務部門EIP編號
  883. gstrUploadFilePathPage = GetSystemSetting(dtSystemSetting, "UploadFilePathPage");
  884. if (gstrUploadFilePathPage == "")
  885. {
  886. gstrUploadFilePathPage = "DMImg";
  887. }
  888. }
  889. }
  890. catch (Exception ex)
  891. {
  892. mo_Log.Debug("BasePage.fnLoadSetting Debug:" + ex.Message, ex);
  893. mo_Log.Error("BasePage.fnLoadSetting Erroe:" + ex.Message, ex);
  894. }
  895. }
  896. #endregion
  897. #region fnLoadProgramList
  898. /// <summary>
  899. /// 加載系統程式列表
  900. /// </summary>
  901. public static void fnLoadProgramList()
  902. {
  903. OT.BLL.OTB_SYS_ProgramList o_OTB_SYS_ProgramList_BLL = new OT.BLL.OTB_SYS_ProgramList();
  904. gdtProgramList = fnDataSetToDataTable(o_OTB_SYS_ProgramList_BLL.GetAllList());
  905. }
  906. #endregion
  907. #region fnOpenFile
  908. /// <summary>
  909. /// 開啟文檔
  910. /// </summary>
  911. /// <param name="strPath">檔案路徑</param>
  912. /// <param name="strFileName">檔案名稱(包含後綴名)</param>
  913. /// <remarks>例如:檔案路徑:LoanTemp/LoanCount.xls;檔案名稱:XX.doc</remarks>
  914. public void fnOpenFile(string strPath, string strFileName)
  915. {
  916. strPath = Convert.ToBase64String(Encoding.Default.GetBytes(strPath));
  917. strPath = strPath.Replace('=', '!').Replace("/", "@").Replace("+", "*");
  918. Response.Redirect(string.Format("~/OpenFile.aspx?U={0}&FileName={1}", strPath, strFileName), false);
  919. }
  920. #endregion
  921. //#region fnUpLoadFile
  922. ///// <summary>
  923. ///// 檔案上傳
  924. ///// </summary>
  925. ///// <param name="file">文件上傳控件</param>
  926. ///// <returns></returns>
  927. //public string fnUpLoadFile(FileUpload file)
  928. //{
  929. // string strReturn = string.Empty;
  930. // if (file.HasFile && file.PostedFile.ContentLength <= gintUploadSize * 1024 * 1024)
  931. // {
  932. // strReturn = Guid.NewGuid().ToString();
  933. // try
  934. // {
  935. // int bufferSize = 1024;
  936. // byte[] buffer = new byte[bufferSize];
  937. // int uploadFileLength = 0;
  938. // string strSubFileName = System.IO.Path.GetExtension(file.FileName).ToLower();
  939. // string saveFullPath = Server.MapPath("~") + "\\" + gstrUploadFilePath + "\\" + strReturn.Replace("-", "") + strSubFileName;
  940. // string strFilePath = "~/" + gstrUploadFilePath.Trim('/').Trim('\\') + "/" + strReturn.Replace("-", "") + strSubFileName;
  941. // if (!Directory.Exists(Server.MapPath("~") + "\\" + gstrUploadFilePath + "\\"))
  942. // {
  943. // DirectoryInfo dir = Directory.CreateDirectory(Server.MapPath("~") + "\\" + gstrUploadFilePath + "\\");
  944. // }
  945. // using (FileStream fs = new FileStream(saveFullPath, FileMode.Create))
  946. // {
  947. // while (uploadFileLength < file.PostedFile.ContentLength)
  948. // {
  949. // //从输入流放进缓冲区
  950. // int bytes = file.PostedFile.InputStream.Read(buffer, 0, bufferSize);
  951. // fs.Write(buffer, 0, bytes);
  952. // fs.Flush(); // 字节写入文件流
  953. // uploadFileLength += bytes;// 更新大小
  954. // }
  955. // fs.Close();
  956. // }
  957. // OT.BLL.OTB_SYS_AttachmentFiles o_SYS_Attachments_BLL = new OT.BLL.OTB_SYS_AttachmentFiles();
  958. // OT.Model.OTB_SYS_AttachmentFiles o_SYS_Attachments_Model = new OT.Model.OTB_SYS_AttachmentFiles();
  959. // o_SYS_Attachments_Model.TargetRelationID = strReturn;
  960. // o_SYS_Attachments_Model.FileName = file.FileName;
  961. // o_SYS_Attachments_Model.FilePath = strFilePath;
  962. // o_SYS_Attachments_Model.SubFileName = strSubFileName;
  963. // o_SYS_Attachments_Model.FileSize = uploadFileLength;
  964. // o_SYS_Attachments_BLL.Add(o_SYS_Attachments_Model);
  965. // uploadFileLength = 0;
  966. // }
  967. // catch (Exception ex)
  968. // {
  969. // strReturn = string.Empty;
  970. // mo_Log.Error(ex.Message, ex);
  971. // }
  972. // }
  973. // else if (file.HasFile && file.PostedFile.ContentLength > gintUploadSize * 1024 * 1024)
  974. // {
  975. // ShowArtAlert("A00076", gintUploadSize.ToString());//上傳檔案超過指定大小{0}MB.
  976. // }
  977. // return strReturn;
  978. //}
  979. //#endregion
  980. #region fnUpLoadFilePage
  981. /// <summary>
  982. /// 檔案上傳
  983. /// </summary>
  984. /// <param name="file">文件上傳控件</param>
  985. /// <returns></returns>
  986. public string fnUpLoadFilePage(FileUpload file)
  987. {
  988. string strReturn = string.Empty;
  989. if (file.HasFile && file.PostedFile.ContentLength <= gintUploadSize * 1024 * 1024)
  990. {
  991. try
  992. {
  993. int bufferSize = 1024;
  994. byte[] buffer = new byte[bufferSize];
  995. int uploadFileLength = 0;
  996. string saveFullPath = Server.MapPath("~") + "\\" + gstrUploadFilePathPage + "\\" + file.FileName;
  997. string strFilePath = "~/" + gstrUploadFilePathPage.Trim('/').Trim('\\') + "/" + file.FileName;
  998. if (!Directory.Exists(Server.MapPath("~") + "\\" + gstrUploadFilePathPage + "\\"))
  999. {
  1000. DirectoryInfo dir = Directory.CreateDirectory(Server.MapPath("~") + "\\" + gstrUploadFilePathPage + "\\");
  1001. }
  1002. using (FileStream fs = new FileStream(saveFullPath, FileMode.Create))
  1003. {
  1004. while (uploadFileLength < file.PostedFile.ContentLength)
  1005. {
  1006. //从输入流放进缓冲区
  1007. int bytes = file.PostedFile.InputStream.Read(buffer, 0, bufferSize);
  1008. fs.Write(buffer, 0, bytes);
  1009. fs.Flush(); // 字节写入文件流
  1010. uploadFileLength += bytes;// 更新大小
  1011. }
  1012. fs.Close();
  1013. }
  1014. strReturn = strFilePath;
  1015. }
  1016. catch (Exception ex)
  1017. {
  1018. strReturn = string.Empty;
  1019. mo_Log.Error(ex.Message, ex);
  1020. }
  1021. }
  1022. else if (file.HasFile && file.PostedFile.ContentLength > gintUploadSize * 1024 * 1024)
  1023. {
  1024. ShowArtAlert("A00076", gintUploadSize.ToString());//上傳檔案超過指定大小{0}MB.
  1025. }
  1026. return strReturn;
  1027. }
  1028. #endregion
  1029. //#region fnUpLoadFileByInput
  1030. ///// <summary>
  1031. ///// 檔案上傳
  1032. ///// </summary>
  1033. ///// <param name="file">文件上傳控件</param>
  1034. ///// <returns></returns>
  1035. //public string fnUpLoadFileByInput(HttpPostedFile file, string strSourceRelationID)
  1036. //{
  1037. // string strReturn = string.Empty;
  1038. // if (file != null && file.FileName != "" && Request.TotalBytes <= gintUploadSize * 1024 * 1024)
  1039. // {
  1040. // strReturn = Guid.NewGuid().ToString();
  1041. // try
  1042. // {
  1043. // int bufferSize = 1024;
  1044. // byte[] buffer = new byte[bufferSize];
  1045. // int uploadFileLength = 0;
  1046. // string strSubFileName = System.IO.Path.GetExtension(file.FileName).ToLower();
  1047. // string saveFullPath = Server.MapPath("~") + "\\" + gstrUploadFilePath + "\\" + strReturn.Replace("-", "") + strSubFileName;
  1048. // string strFilePath = "~/" + gstrUploadFilePath.Trim('/').Trim('\\') + "/" + strReturn.Replace("-", "") + strSubFileName;
  1049. // if (!Directory.Exists(Server.MapPath("~") + "\\" + gstrUploadFilePath + "\\"))
  1050. // {
  1051. // DirectoryInfo dir = Directory.CreateDirectory(Server.MapPath("~") + "\\" + gstrUploadFilePath + "\\");
  1052. // }
  1053. // using (FileStream fs = new FileStream(saveFullPath, FileMode.Create))
  1054. // {
  1055. // while (uploadFileLength < file.ContentLength)
  1056. // {
  1057. // //从输入流放进缓冲区
  1058. // int bytes = file.InputStream.Read(buffer, 0, bufferSize);
  1059. // fs.Write(buffer, 0, bytes);
  1060. // fs.Flush(); // 字节写入文件流
  1061. // uploadFileLength += bytes;// 更新大小
  1062. // }
  1063. // fs.Close();
  1064. // }
  1065. // OT.BLL.OTB_SYS_AttachmentFiles o_SYS_Attachments_BLL = new OT.BLL.OTB_SYS_AttachmentFiles();
  1066. // OT.Model.OTB_SYS_AttachmentFiles o_SYS_Attachments_Model = new OT.Model.OTB_SYS_AttachmentFiles();
  1067. // o_SYS_Attachments_Model.TargetRelationID = strReturn;
  1068. // o_SYS_Attachments_Model.SourceRelationID = strSourceRelationID;
  1069. // o_SYS_Attachments_Model.FileName = file.FileName;
  1070. // o_SYS_Attachments_Model.FilePath = strFilePath;
  1071. // o_SYS_Attachments_Model.SubFileName = strSubFileName;
  1072. // o_SYS_Attachments_Model.FileSize = uploadFileLength;
  1073. // o_SYS_Attachments_BLL.Add(o_SYS_Attachments_Model);
  1074. // uploadFileLength = 0;
  1075. // }
  1076. // catch (Exception ex)
  1077. // {
  1078. // strReturn = string.Empty;
  1079. // mo_Log.Error(ex.Message, ex);
  1080. // }
  1081. // }
  1082. // else if (Request.TotalBytes > gintUploadSize * 1024 * 1024)
  1083. // {
  1084. // ShowArtAlert("A00076", gintUploadSize.ToString());//上傳檔案超過指定大小{0}MB.
  1085. // }
  1086. // return strReturn;
  1087. //}
  1088. //#endregion
  1089. //#region FileDelete
  1090. ///// <summary>
  1091. ///// 刪除文件
  1092. ///// </summary>
  1093. ///// <param name="strFilePath"></param>
  1094. ///// <param name="strFileName"></param>
  1095. ///// <returns></returns>
  1096. //public Boolean fnFileDelete(string strFileGuid, string strOrganizationID)
  1097. //{
  1098. // try
  1099. // {
  1100. // string strFileFullName = fnGetFilePathByGuid(strFileGuid, strOrganizationID);
  1101. // OT.BLL.OTB_SYS_AttachmentFiles o_SYS_Attachments_BLL = new OT.BLL.OTB_SYS_AttachmentFiles();
  1102. // o_SYS_Attachments_BLL.Delete(strFileGuid, strOrganizationID);
  1103. // if (System.IO.File.Exists(Server.MapPath(strFileFullName)))
  1104. // {
  1105. // System.IO.File.SetAttributes(Server.MapPath(strFileFullName), System.IO.FileAttributes.Normal);
  1106. // System.IO.File.Delete(Server.MapPath(strFileFullName));
  1107. // }
  1108. // }
  1109. // catch (System.Exception ex)
  1110. // {
  1111. // mo_Log.Error(ex.Message);
  1112. // mo_Log.Fatal(ex.ToString());
  1113. // return false;
  1114. // }
  1115. // return true;
  1116. //}
  1117. //#endregion
  1118. //#region fnGetFilePathByGuid
  1119. ///// <summary>
  1120. ///// 依據文件Guid獲取文件路徑
  1121. ///// </summary>
  1122. ///// <param name="strGuid">文件Guid</param>
  1123. ///// <returns></returns>
  1124. //public string fnGetFilePathByGuid(string strGuid, string strOrganizationID)
  1125. //{
  1126. // string strReturn = string.Empty;
  1127. // try
  1128. // {
  1129. // OT.BLL.OTB_SYS_AttachmentFiles o_SYS_Attachments_BLL = new OT.BLL.OTB_SYS_AttachmentFiles();
  1130. // OT.Model.OTB_SYS_AttachmentFiles o_SYS_Attachments_Model = o_SYS_Attachments_BLL.GetModel(strGuid, strOrganizationID);
  1131. // strReturn = o_SYS_Attachments_Model.FilePath;
  1132. // }
  1133. // catch (Exception ex)
  1134. // {
  1135. // strReturn = string.Empty;
  1136. // mo_Log.Error(ex.Message, ex);
  1137. // }
  1138. // return strReturn;
  1139. //}
  1140. //#endregion
  1141. #region fnSetDropDownList
  1142. /// <summary>
  1143. /// 依據最大編號自動產生排序下拉框
  1144. /// </summary>
  1145. /// <param name="dropControl">需要產生值的下拉選單</param>
  1146. /// <param name="intMaxItemNo">下拉選單的最大值</param>
  1147. public void fnSetDropDownList(DropDownList dropControl, int intMaxItemNo)
  1148. {
  1149. dropControl.Items.Clear();
  1150. for (int i = 1; i <= intMaxItemNo; i++)
  1151. {
  1152. dropControl.Items.Add(new ListItem(i.ToString(), i.ToString()));
  1153. }
  1154. }
  1155. #endregion
  1156. #region fnGetSystemSettingValueBySettingItem
  1157. /// <summary>
  1158. /// 依據設定項目獲取系統參數配置的值
  1159. /// </summary>
  1160. /// <param name="strSettingItem">設定項目</param>
  1161. /// <returns>設定值</returns>
  1162. public string fnGetSystemSettingValueBySettingItem(string strSettingItem)
  1163. {
  1164. string strSettingValue = string.Empty;
  1165. try
  1166. {
  1167. OT.Model.OTB_SYS_SystemSetting o_OTB_SYS_SystemSetting_Model = new OT.BLL.OTB_SYS_SystemSetting().GetModel(strSettingItem);
  1168. if (o_OTB_SYS_SystemSetting_Model != null && o_OTB_SYS_SystemSetting_Model.Effective == "Y")
  1169. {
  1170. strSettingValue = o_OTB_SYS_SystemSetting_Model.SettingValue;
  1171. }
  1172. }
  1173. catch (Exception ex)
  1174. {
  1175. mo_Log.Error(ex.Message, ex);
  1176. }
  1177. return strSettingValue;
  1178. }
  1179. #endregion
  1180. #region GetMaxNumber
  1181. #region GetMaxNumberClass
  1182. /// <summary>
  1183. /// 取得類別的自動編號
  1184. /// </summary>
  1185. /// <param name="ClassId">類別代號</param>
  1186. /// <returns></returns>
  1187. public string GetMaxNumberClass(string ClassId, string ModifyUser)
  1188. {
  1189. OT.BLL.CommonClass o_Common_BLL = new OT.BLL.CommonClass();
  1190. return o_Common_BLL.GetArgumentClassMaxNumber(ClassId, ModifyUser, 5);
  1191. }
  1192. #endregion
  1193. #region GetMaxNumberClass
  1194. /// <summary>
  1195. /// 取得類別的自動編號
  1196. /// </summary>
  1197. /// <param name="ClassId">類別代號</param>
  1198. /// <param name="intLen">長度</param>
  1199. /// <returns></returns>
  1200. public string GetMaxNumberClass(string ClassId, string ModifyUser, int intLen)
  1201. {
  1202. OT.BLL.CommonClass o_Common_BLL = new OT.BLL.CommonClass();
  1203. return o_Common_BLL.GetArgumentClassMaxNumber(ClassId, ModifyUser, intLen);
  1204. }
  1205. #endregion
  1206. #region GetMaxNumberCatData
  1207. /// <summary>
  1208. /// 取得類別下資料的自動編號
  1209. /// </summary>
  1210. /// <param name="ClassId">類別代號</param>
  1211. /// <param name="ItemId">參數代號</param>
  1212. /// <param name="intLen">長度</param>
  1213. /// <returns></returns>
  1214. public string GetMaxNumberCatData(string ClassId, string ItemId, string ModifyUser)
  1215. {
  1216. OT.BLL.CommonClass o_Common_BLL = new OT.BLL.CommonClass();
  1217. return o_Common_BLL.GetArgumentMaxNumber(ClassId, ItemId, ModifyUser, 5);
  1218. }
  1219. #endregion
  1220. #region GetMaxNumberCatData
  1221. /// <summary>
  1222. /// 取得類別下資料的自動編號
  1223. /// </summary>
  1224. /// <param name="ClassId">類別代號</param>
  1225. /// <param name="ItemId">參數代號</param>
  1226. /// <param name="intLen">長度</param>
  1227. /// <returns></returns>
  1228. public string GetMaxNumberCatData(string ClassId, string ItemId, string ModifyUser, int intLen)
  1229. {
  1230. OT.BLL.CommonClass o_Common_BLL = new OT.BLL.CommonClass();
  1231. return o_Common_BLL.GetArgumentMaxNumber(ClassId, ItemId, ModifyUser, 5);
  1232. }
  1233. #endregion
  1234. #region GetMaxNumberByType
  1235. /// <summary>
  1236. /// 取得類型下資料的自動編號
  1237. /// </summary>
  1238. /// <param name="Type">類別代號</param>
  1239. /// <param name="Flag">自動編號方式 Y:年;M:月;D:日;O:其他(不按照年月日編號)</param>
  1240. /// <returns>返回5位流水號不夠左邊補零</returns>
  1241. public static string GetMaxNumberByType(string Type, MaxNumberType Flag, string ModifyUser)
  1242. {
  1243. OT.BLL.CommonClass o_Common_BLL = new OT.BLL.CommonClass();
  1244. string strRetrun = string.Empty;
  1245. switch (Flag)
  1246. {
  1247. case MaxNumberType.Year:
  1248. strRetrun += gdteNowTime.ToString("yyyy");
  1249. break;
  1250. case MaxNumberType.Month:
  1251. strRetrun += gdteNowTime.ToString("yyyyMM");
  1252. break;
  1253. case MaxNumberType.Day:
  1254. strRetrun += gdteNowTime.ToString("yyyyMMdd");
  1255. break;
  1256. default:
  1257. strRetrun = string.Empty;
  1258. break;
  1259. }
  1260. return strRetrun += o_Common_BLL.GetMaxNumberByType(Type, Flag.ToString(), ModifyUser, 5);
  1261. }
  1262. /// <summary>
  1263. /// 取得類型下資料的自動編號
  1264. /// </summary>
  1265. /// <param name="Type">類別代號</param>
  1266. /// <param name="Flag">自動編號方式 Y:年;M:月;D:日;O:其他(不按照年月日編號)</param>
  1267. /// <param name="intLen">返回字符長度不夠左邊補零</param>
  1268. /// <returns>返回intLen位流水號不夠左邊補零</returns>
  1269. public static string GetMaxNumberByType(string Type, MaxNumberType Flag, string ModifyUser, int intLen)
  1270. {
  1271. OT.BLL.CommonClass o_Common_BLL = new OT.BLL.CommonClass();
  1272. string strRetrun = string.Empty;
  1273. switch (Flag)
  1274. {
  1275. case MaxNumberType.Year:
  1276. strRetrun += gdteNowTime.ToString("yyyy");
  1277. break;
  1278. case MaxNumberType.Month:
  1279. strRetrun += gdteNowTime.ToString("yyyyMM");
  1280. break;
  1281. case MaxNumberType.Day:
  1282. strRetrun += gdteNowTime.ToString("yyyyMMdd");
  1283. break;
  1284. default:
  1285. strRetrun = string.Empty;
  1286. break;
  1287. }
  1288. return strRetrun += o_Common_BLL.GetMaxNumberByType(Type, Flag.ToString(), ModifyUser, intLen);
  1289. }
  1290. /// <summary>
  1291. /// 取得類型下資料的自動編號
  1292. /// </summary>
  1293. /// <param name="Type">類別代號</param>
  1294. /// <param name="Flag">自動編號方式 Y:年;M:月;D:日;O:其他(不按照年月日編號)</param>
  1295. /// <param name="intLen">返回字符長度不夠左邊補零</param>
  1296. /// <param name="blIsAddPre">是否添加前綴</param>
  1297. /// <returns>返回intLen位流水號不夠左邊補零並且添加Type為前綴</returns>
  1298. public static string GetMaxNumberByType(string Type, MaxNumberType Flag, string ModifyUser, int intLen, bool blIsAddPre)
  1299. {
  1300. OT.BLL.CommonClass o_Common_BLL = new OT.BLL.CommonClass();
  1301. string strRetrun = string.Empty;
  1302. switch (Flag)
  1303. {
  1304. case MaxNumberType.Year:
  1305. strRetrun += gdteNowTime.ToString("yyyy");
  1306. break;
  1307. case MaxNumberType.Month:
  1308. strRetrun += gdteNowTime.ToString("yyyyMM");
  1309. break;
  1310. case MaxNumberType.Day:
  1311. strRetrun += gdteNowTime.ToString("yyyyMMdd");
  1312. break;
  1313. case MaxNumberType.Other:
  1314. strRetrun += gdteNowTime.ToString("yyMMdd");
  1315. break;
  1316. default:
  1317. strRetrun = string.Empty;
  1318. break;
  1319. }
  1320. if (blIsAddPre)
  1321. {
  1322. strRetrun = Type + strRetrun;
  1323. }
  1324. return strRetrun += o_Common_BLL.GetMaxNumberByType(Type, Flag.ToString(), ModifyUser, intLen);
  1325. }
  1326. /// <summary>
  1327. /// 取得類型下資料的自動編號
  1328. /// </summary>
  1329. /// <param name="Type">類別代號</param>
  1330. /// <param name="Flag">自動編號方式 Y:年;M:月;D:日;O:其他(不按照年月日編號)</param>
  1331. /// <returns>返回5位流水號不夠左邊補零</returns>
  1332. public string GetMaxNumberByType(string Type, string ModifyUser)
  1333. {
  1334. OT.BLL.CommonClass o_Common_BLL = new OT.BLL.CommonClass();
  1335. return o_Common_BLL.GetMaxNumberByType(Type, "O", ModifyUser, 5);
  1336. }
  1337. /// <summary>
  1338. /// 取得類型下資料的自動編號
  1339. /// </summary>
  1340. /// <param name="Type">類別代號</param>
  1341. /// <param name="Flag">自動編號方式 Y:年;M:月;D:日;O:其他(不按照年月日編號)</param>
  1342. /// <param name="intLen">返回字符長度不夠左邊補零</param>
  1343. /// <returns>返回intLen位流水號不夠左邊補零</returns>
  1344. public string GetMaxNumberByType(string Type, string ModifyUser, int intLen)
  1345. {
  1346. OT.BLL.CommonClass o_Common_BLL = new OT.BLL.CommonClass();
  1347. return o_Common_BLL.GetMaxNumberByType(Type, "O", ModifyUser, intLen);
  1348. }
  1349. /// <summary>
  1350. /// 取得類型下資料的自動編號
  1351. /// </summary>
  1352. /// <param name="Type">類別代號</param>
  1353. /// <param name="Flag">自動編號方式 Y:年;M:月;D:日;O:其他(不按照年月日編號)</param>
  1354. /// <param name="intLen">返回字符長度不夠左邊補零</param>
  1355. /// <param name="blIsAddPre">是否添加前綴</param>
  1356. /// <returns>返回intLen位流水號不夠左邊補零並且添加Type為前綴</returns>
  1357. public string GetMaxNumberByType(string Type, string ModifyUser, int intLen, bool blIsAddPre)
  1358. {
  1359. OT.BLL.CommonClass o_Common_BLL = new OT.BLL.CommonClass();
  1360. string strRetrun = string.Empty;
  1361. if (blIsAddPre)
  1362. {
  1363. strRetrun = Type + strRetrun;
  1364. }
  1365. return strRetrun + o_Common_BLL.GetMaxNumberByType(Type, "O", ModifyUser, intLen);
  1366. }
  1367. #endregion
  1368. #endregion
  1369. #region ShowMsg
  1370. /// <summary>
  1371. /// 彈出信息提示,並轉向指的頁面
  1372. /// </summary>
  1373. /// <param name="strCode">信息代號</param>
  1374. /// <param name="StrPara"></param>
  1375. /// <param name="url">參數</param>
  1376. ///
  1377. public void fnUpdRemove()
  1378. {
  1379. ScriptManager.RegisterStartupScript(Page, Page.GetType(), "fnUpdRemove", "<script> fnUpdRemove(); </script>", false);
  1380. }
  1381. public void fnUpdRemove(string fields)
  1382. {
  1383. ScriptManager.RegisterStartupScript(Page, Page.GetType(), "fnUpdRemove", "<script> fnUpdRemove('" + fields + "'); </script>", false);
  1384. }
  1385. public void OpenPageTab(string strProgramId)
  1386. {
  1387. ScriptManager.RegisterStartupScript(Page, Page.GetType(), "OpenPageTab", "<script> parent.OpenPageTab('" + strProgramId + "'); </script>", false);
  1388. }
  1389. public void OpenPageTab(string strProgramId, string parameters)
  1390. {
  1391. ScriptManager.RegisterStartupScript(Page, Page.GetType(), "OpenPageTab", "<script> parent.OpenPageTab('" + strProgramId + "','" + parameters + "'); </script>", false);
  1392. }
  1393. public void ShowAndRedirect(string strCode, string strPara, string url)
  1394. {
  1395. ScriptManager.RegisterStartupScript(Page, Page.GetType(), "messageRedirect", "<script> ShowAndRedirect('" + strCode + "','" + strPara + "','" + url + "','" + gstrUICulture + "'); </script>", false);
  1396. }
  1397. public void ShowArtCodeAndGo(string strCode, string strTipsPara, string strPara, string url)
  1398. {
  1399. ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ShowArtCodeAndGo", "<script> ShowArtCodeAndGo('" + strCode + "','" + strTipsPara + "','" + strPara + "','" + url + "','" + gstrUICulture + "'); </script>", false);
  1400. }
  1401. public void ShowArtCodeAndClose(string strCode)
  1402. {
  1403. ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ShowArtCodeAndClose", "<script> ShowArtCodeAndClose('" + strCode + "'); </script>", false);
  1404. }
  1405. public void ShowArtCodeAndClose(string strCode, string strID)
  1406. {
  1407. ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ShowArtCodeAndClose", "<script> ShowArtCodeAndClose('" + strCode + "','" + strID + "'); </script>", false);
  1408. }
  1409. public void ShowArtCodeAndCloseAndClickBtn(string strCode)
  1410. {
  1411. ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ShowArtCodeAndCloseAndClickBtn", "<script> ShowArtCodeAndCloseAndClickBtn('" + strCode + "'); </script>", false);
  1412. }
  1413. public void ShowArtCodeAndCloseAndClickBtn(string strCode, string strID, string strbtnid)
  1414. {
  1415. ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ShowArtCodeAndCloseAndClickBtn", "<script> ShowArtCodeAndCloseAndClickBtn('" + strCode + "','" + strID + "','" + strbtnid + "'); </script>", false);
  1416. }
  1417. public void ShowArtAlert(string straCode)
  1418. {
  1419. ScriptManager.RegisterStartupScript(Page, this.GetType(), "ShowArtAlert", "<script> ShowArtAlert('" + straCode + "','','" + gstrUICulture + "'); </script>", false);
  1420. }
  1421. public void ShowArtAlert(string straCode, string straPara)
  1422. {
  1423. ScriptManager.RegisterStartupScript(Page, this.GetType(), "ShowArtAlert", "<script> ShowArtAlert('" + straCode + "','" + straPara + "','" + gstrUICulture + "'); </script>", false);
  1424. }
  1425. //public void ShowArtAlert(string strmessage)
  1426. //{
  1427. // ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ShowArtAlert", "<script> ShowArtAlert('" + strmessage + "'); </script>", false);
  1428. //}
  1429. /// <summary>
  1430. /// 彈出信息提示,並轉向指的頁面
  1431. /// </summary>
  1432. /// <param name="strCode">信息代號</param>
  1433. /// <param name="StrPara"></param>
  1434. /// <param name="url">參數</param>
  1435. public void ShowAndBaseRedirect(string straCode, string straPara, string straUrl)
  1436. {
  1437. ScriptManager.RegisterStartupScript(Page, this.GetType(), "messageRedirect", "<script> ShowAndBaseRedirect('" + straCode + "','" + straPara + "','" + straUrl + "','" + gstrUICulture + "'); </script>", false);
  1438. }
  1439. /// <summary>
  1440. /// 在頁面上彈出信息提示
  1441. /// </summary>
  1442. /// <param name="s_aCode">信息代號</param>
  1443. /// <param name="s_aPara">參數</param>
  1444. /// eg:show("000001","你好"); //你好
  1445. public void Show(string straCode, string straPara)
  1446. {
  1447. ScriptManager.RegisterStartupScript(Page, this.GetType(), "messageshow", "<script> Show('" + straCode + "','" + straPara + "','" + gstrUICulture + "'); </script>", false);
  1448. }
  1449. /// <summary>
  1450. /// 在頁面上彈出信息提示
  1451. /// </summary>
  1452. /// <param name="s_aCode">信息代號</param>
  1453. /// eg:show("000001"); //你好
  1454. public void Show(string straCode)
  1455. {
  1456. ScriptManager.RegisterStartupScript(Page, this.GetType(), "messageshow", "<script> Show('" + straCode + "','','" + gstrUICulture + "'); </script>", false);
  1457. }
  1458. /// <summary>
  1459. /// 給指定的Web控件,彈出確認框信息提示
  1460. /// </summary>
  1461. /// <param name="StrCode">信息代號</param>
  1462. /// <param name="StrPara">參數</param>
  1463. public void ShowConfirm(string StrCode, string StrPara)
  1464. {
  1465. ScriptManager.RegisterStartupScript(Page, this.GetType(), "messageshowcon", "<script> return ShowConfirm('" + StrCode + "','" + StrPara + "','" + gstrUICulture + "'); </script>", false);
  1466. }
  1467. ///Author :Luther
  1468. /// <summary>
  1469. /// 給指定的Web控件,彈出確認框信息提示
  1470. /// </summary>
  1471. /// <param name="Control">Web控件</param>
  1472. /// <param name="StrCode">信息代號</param>
  1473. public void ShowConfirm(string StrCode)
  1474. {
  1475. ScriptManager.RegisterStartupScript(Page, this.GetType(), "messageshowcon", "<script> return ShowConfirm('" + StrCode + "','','" + gstrUICulture + "'); </script>", false);
  1476. }
  1477. #endregion
  1478. #region fnConvertToInt
  1479. /// <summary>
  1480. /// 將字符轉化成數字,如果轉化失敗則返回0
  1481. /// </summary>
  1482. /// <param name="strSource">需要轉化的字符串</param>
  1483. /// <returns></returns>
  1484. public static int fnConvertToInt(string strSource)
  1485. {
  1486. int intReturn;
  1487. int.TryParse(strSource, out intReturn);
  1488. return intReturn;
  1489. }
  1490. #endregion
  1491. #region GetUserNameByUserId
  1492. /// <summary>
  1493. /// 依據登入帳號獲取用戶名稱
  1494. /// </summary>
  1495. /// <param name="strUserId">登入帳號</param>
  1496. /// <returns></returns>
  1497. public string GetUserNameByUserId(string strUserId)
  1498. {
  1499. string strUserName = string.Empty;
  1500. try
  1501. {
  1502. if (!string.IsNullOrEmpty(strUserId))
  1503. {
  1504. strUserName = new OT.BLL.OTB_SYS_Members().GetModel(strUserId).MemberName;
  1505. //strUserName = new OT.BLL.CommonClass().GetActiveUserInfo(strUserId).NAME;
  1506. }
  1507. else
  1508. {
  1509. strUserName = "";
  1510. }
  1511. }
  1512. catch (Exception ex)
  1513. {
  1514. mo_Log.Debug(string.Format("BasePage.GetUserNameByUserId Debug : strUserId:{0}", strUserId), ex);
  1515. mo_Log.Fatal(ex.Message, ex);
  1516. }
  1517. return strUserName;
  1518. }
  1519. #endregion
  1520. #region fnOpenRpt
  1521. /// <summary>
  1522. /// 開啟報表
  1523. /// </summary>
  1524. /// <param name="strRptPath">報表的相對路徑</param>
  1525. /// <example>fnOpenRpt("");</example>
  1526. public void fnOpenRpt(string strRptPath)
  1527. {
  1528. //註意:只用使用window.open,使用其他無法列印。
  1529. 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);
  1530. }
  1531. #endregion
  1532. #endregion
  1533. #region 私有方法區域
  1534. #region BasePage
  1535. /// <summary>
  1536. /// 初始化參數
  1537. /// </summary>
  1538. static BasePage()
  1539. {
  1540. dtAllowRightText = fnDataSetToDataTable(new OT.BLL.CommonClass().GetArgumentListByArgumentClassID("99999"));
  1541. DataView dvView = new DataView(dtAllowRightText);
  1542. dvView.Sort = " OrderByValue ASC ";
  1543. dtAllowRightText = dvView.ToTable();
  1544. if (dtAllowRightText.Rows.Count > 0)
  1545. {
  1546. garyAllowRight = new string[dtAllowRightText.Rows.Count];
  1547. for (int i = 0, j = dtAllowRightText.Rows.Count; i < j; i++)
  1548. {
  1549. garyAllowRight[i] = dtAllowRightText.Rows[i]["ArgumentID"].ToString();
  1550. }
  1551. }
  1552. else
  1553. {
  1554. garyAllowRight = new string[]{ "Add", "ReAdd", "Save", "Del"
  1555. , "Clear", "Upd", "Qry", "Exp"
  1556. , "Imp", "Leave", "Cpy"
  1557. , "Sub", "Chk", "Tmp", "Print"
  1558. ,"View","RptAd"};
  1559. }
  1560. fnLoadSetting(); //加載系統參數設定
  1561. fnLoadProgramList(); //加載系統程式列表
  1562. }
  1563. #endregion
  1564. #region GetSystemSetting
  1565. /// <summary>
  1566. /// 依據參數代碼取得系統參數設定值
  1567. /// </summary>
  1568. /// <param name="strItemCode">參數代碼</param>
  1569. /// <returns>系統參數設定值</returns>
  1570. private static string GetSystemSetting(DataTable dtSysSetting, string strItemCode)
  1571. {
  1572. string strSettingValue = null;
  1573. try
  1574. {
  1575. DataRow[] drSettings = dtSysSetting.Select(" SettingItem = '" + strItemCode + "' ");
  1576. foreach (DataRow dr in drSettings)
  1577. {
  1578. strSettingValue = dr["SettingValue"].ToString().Trim();
  1579. }
  1580. }
  1581. catch (Exception ex)
  1582. {
  1583. mo_Log.Debug(string.Format("BasePage.GetSystemSetting Debug : Param:dtSysSetting{0};strItemCode={1}", Common.Serialize(dtSysSetting), strItemCode));
  1584. mo_Log.Error(ex.Message, ex);
  1585. }
  1586. return strSettingValue;
  1587. }
  1588. #endregion
  1589. #region GetProgramId
  1590. /// <summary>
  1591. /// 得到当前程式代号
  1592. /// </summary>
  1593. /// <returns></returns>
  1594. private void GetProgramId()
  1595. {
  1596. try
  1597. {
  1598. gstrProgramId = Request.AppRelativeCurrentExecutionFilePath;
  1599. //取程式名稱
  1600. string[] ary = gstrProgramId.Split('/');
  1601. if (ary.Length > 0)
  1602. {
  1603. gstrProgramId = ary[ary.Length - 1];
  1604. }
  1605. //去除後綴名和參數
  1606. string[] aryP = gstrProgramId.Split('.');
  1607. if (aryP.Length > 0)
  1608. {
  1609. gstrProgramId = aryP[0];
  1610. }
  1611. }
  1612. catch (Exception ex)
  1613. {
  1614. mo_Log.Debug("BasePage.GetProgramId Debug : Param:null");
  1615. mo_Log.Error(ex.Message, ex);
  1616. }
  1617. }
  1618. #endregion
  1619. #region CheckIsLogin
  1620. /// <summary>
  1621. /// CheckIsLogin
  1622. /// </summary>
  1623. protected virtual void CheckIsLogin()
  1624. {
  1625. try
  1626. {
  1627. string UnCheckPageName = ""; //所有排除驗證是否登錄的頁面
  1628. string testsss = gstrUserID;
  1629. if (Session["gstrUserId"] != null && Session["gstrUserLoginTime"] != null) //&& Session["gstrUserId"] != null 重複設定
  1630. {
  1631. //登入成功
  1632. gstrUserID = Session["gstrUserId"] == null ? "" : Session["gstrUserId"].ToString(); //登入者ID
  1633. DateTime.TryParse(Session["gstrUserLoginTime"].ToString(), out gdteUserLoginTime);
  1634. GetProgramRight(gstrProgramId);
  1635. if (gbl_ProgramStatus == "W" || gbl_ProgramStatus == "N")
  1636. {
  1637. //維修中,停用 Add by Alina 201401029 當畫面的狀態是維修中,停用,顯示對應的畫面
  1638. //如果是ADMIN 帳號 那就繼續使用以方便測試
  1639. if (gstrUserID.ToLower() != "admin")
  1640. {
  1641. Response.Redirect("~/Waiting.aspx?PageTile=" + gbl_ProgramStatus, false);
  1642. }
  1643. }
  1644. else
  1645. {
  1646. if (!gbl_AllowView && Request.Url.ToString().ToLower().IndexOf("page/") > -1)
  1647. {
  1648. //如果沒有cha權限則提示使用者沒有權限
  1649. Response.Redirect("~/NotView.aspx?PageTile=" + fnUrlEncode(gstrProgramName), false);//true-->false //轉入登入頁面
  1650. }
  1651. //FormsAuthentication.RedirectFromLoginPage(gstrUserID, true);
  1652. }
  1653. }
  1654. else if (UnCheckPageName.Contains(gstrProgramId) == false)
  1655. {
  1656. //Response.Redirect("~/Login.aspx", false);//true-->false//轉入登入頁面
  1657. //mo_Log.Debug("BasePage.CheckIsLogin Debug : Session['gstrUserId'] :" + Session["gstrUserId"] );
  1658. ClientScript.RegisterStartupScript(GetType(), "Load", "<script type='text/javascript'>window.top.location.href = '/Login.aspx'; </script>");
  1659. }
  1660. else
  1661. {
  1662. mo_Log.Debug("BasePage.CheckIsLogin Debug : Session['gstrUserId'] :" + Session["gstrUserId"] + "有ID 但沒有登入的程式!!");
  1663. ClientScript.RegisterStartupScript(GetType(), "Load", "<script type='text/javascript'>window.top.location.href = '/Error.aspx'; </script>");
  1664. }
  1665. }
  1666. catch (Exception ex)
  1667. {
  1668. mo_Log.Debug("BasePage.CheckIsLogin Debug : Param:null");
  1669. mo_Log.Error(ex.Message, ex);
  1670. }
  1671. }
  1672. #endregion
  1673. #region GetProgramRight
  1674. /// <summary>
  1675. /// 取得當前頁面的權限信息
  1676. /// </summary>
  1677. /// <param name="strCurrProgramId"></param>
  1678. private void GetProgramRight(string strCurrProgramId)
  1679. {
  1680. try
  1681. {
  1682. OT.BLL.OTB_SYS_Authorize o_SYS_Authorize_BLL = new OT.BLL.OTB_SYS_Authorize();
  1683. OT.Model.OTB_SYS_Authorize o_SYS_Authorize_Model = o_SYS_Authorize_BLL.GetModel(gstrUserID, strCurrProgramId);//gstrUserRoleId-->gstrUserID
  1684. if (o_SYS_Authorize_Model != null) //當不為子程式時判斷權限
  1685. {
  1686. gbl_AllowView = CheckButtonRight("View"); //檢視
  1687. gbl_AllowAdd = CheckButtonRight("Add"); //新增
  1688. gbl_AllowReAdd = CheckButtonRight("ReAdd"); //儲存後新增 增加儲存後新增權限判斷 Add by ted 2014/11/14
  1689. gbl_AllowCopy = CheckButtonRight("Cpy"); //複製 增加複製權限判斷 Add by ted 2014/11/14
  1690. gbl_AllowEdit = CheckButtonRight("Upd"); //編輯
  1691. gbl_AllowDel = CheckButtonRight("Del"); //刪除
  1692. gbl_AllowPrint = CheckButtonRight("Prt"); //列印
  1693. gbl_AllowExport = CheckButtonRight("Exp"); //匯出
  1694. gbl_AllowQuery = CheckButtonRight("Qry"); //查詢
  1695. gbl_AllowSub = CheckButtonRight("Sub"); //送審
  1696. gbl_AllowChk = CheckButtonRight("Chk"); //審核
  1697. gbl_AllowMail = CheckButtonRight("KeepPlaceMail_Pop", "View"); //檢驗是否有發送Mail的權限
  1698. gbl_AllowRpt = CheckButtonRight("RptAd"); //報表的最高權限
  1699. gbl_ProgramStatus = o_SYS_Authorize_Model.ProgramStatus;//程式的狀態
  1700. }
  1701. else
  1702. { //Modify By Ted 2014/08/07 觸發並查無資料代表是子程式,所以權限不判斷直接通過
  1703. gbl_AllowView = true;
  1704. gbl_AllowAdd = true; //新增
  1705. gbl_AllowEdit = true; //編輯
  1706. gbl_AllowDel = true; //刪除
  1707. gbl_AllowPrint = true; //列印
  1708. gbl_AllowExport = true; //匯出
  1709. gbl_AllowQuery = true; //查詢
  1710. gbl_AllowSub = true; //送審
  1711. gbl_AllowChk = true; //審核
  1712. gbl_AllowMail = true; //檢驗是否有發送Mail的權限
  1713. gbl_AllowRpt = true; //報表的最高權限
  1714. gbl_ProgramStatus = "Y";//程式的狀態,預設啟用
  1715. }
  1716. }
  1717. catch (Exception ex)
  1718. {
  1719. mo_Log.Debug(string.Format("BasePage.GetProgramRight Debug : Param:strCurrProgramId={0}", strCurrProgramId));
  1720. mo_Log.Error(ex.Message, ex);
  1721. }
  1722. }
  1723. #endregion
  1724. //#region fnDelFileWhenDelSouce
  1725. ///// <summary>
  1726. ///// 刪除數據來源時也刪除掉附件的方法
  1727. ///// </summary>
  1728. ///// <param name="string">附件編號</param>
  1729. //public void fnDelFileWhenDelSouce(string strAttID)
  1730. //{
  1731. // try
  1732. // {
  1733. // //Add by Alina 20140210 合約刪除時刪除附件資料 Star
  1734. // DataSet dsFiles = new OT.BLL.CommonClass().GetFileListBySourceRelationID(strAttID);
  1735. // if (dsFiles != null && dsFiles.Tables.Count > 0)
  1736. // {
  1737. // DataTable dtFiles = dsFiles.Tables[0];
  1738. // foreach (DataRow dr in dtFiles.Rows)
  1739. // {
  1740. // string strTargetRelationID = dr["TargetRelationID"].ToString();
  1741. // string strOrganizationID = dr["OrganizationID"].ToString();
  1742. // if (!string.IsNullOrEmpty(strTargetRelationID))
  1743. // {
  1744. // string strFileFullName = fnGetFilePathByGuid(strTargetRelationID, strOrganizationID);
  1745. // OT.BLL.OTB_SYS_AttachmentFiles o_SYS_Attachments_BLL = new OT.BLL.OTB_SYS_AttachmentFiles();
  1746. // o_SYS_Attachments_BLL.Delete(strTargetRelationID, strOrganizationID);
  1747. // if (System.IO.File.Exists(Server.MapPath(strFileFullName)))
  1748. // {
  1749. // System.IO.File.Delete(Server.MapPath(strFileFullName));
  1750. // }
  1751. // }
  1752. // }
  1753. // }
  1754. // //Add by Alina 20140210 合約刪除時刪除附件資料 End
  1755. // }
  1756. // catch (Exception ex)
  1757. // {
  1758. // mo_Log.Error(ex.Message, ex);
  1759. // }
  1760. //}
  1761. //#endregion
  1762. #region GetRightInfo
  1763. /// <summary>
  1764. /// 取得權限信息
  1765. /// </summary>
  1766. /// <param name="strRight"></param>
  1767. /// <param name="Index"></param>
  1768. private string GetRightInfo(string strRight)
  1769. {
  1770. int index = 0;
  1771. return GetRightInfo(strRight, ref index);
  1772. }
  1773. /// <summary>
  1774. /// 取得權限信息
  1775. /// </summary>
  1776. /// <param name="strRight"></param>
  1777. /// <param name="index"></param>
  1778. private string GetRightInfo(string strRight, ref int index)
  1779. {
  1780. string strReturn = string.Empty;
  1781. try
  1782. {
  1783. //Add by Alina 20140718 因為按鈕不顯示出來 添加的
  1784. dtAllowRightText = fnDataSetToDataTable(new OT.BLL.CommonClass().GetArgumentListByArgumentClassID("99999"));
  1785. foreach (DataRow drDataRow in dtAllowRightText.Select(string.Format(" ArgumentID='{0}' ", strRight)))
  1786. {
  1787. strReturn = drDataRow["ArgumentValue"].ToString();
  1788. index = string.IsNullOrEmpty(drDataRow["OrderByValue"].ToString()) ? 0 : Convert.ToInt32(drDataRow["OrderByValue"].ToString());
  1789. }
  1790. }
  1791. catch (Exception ex)
  1792. {
  1793. mo_Log.Debug(string.Format("BasePage.GetRightInfo Debug : Param:strRight={0}", strRight));
  1794. mo_Log.Fatal(ex.Message, ex);
  1795. }
  1796. return strReturn;
  1797. }
  1798. #endregion
  1799. #region CheckButtonRight
  1800. /// <summary>
  1801. /// 驗證按鈕是否有權限
  1802. /// </summary>
  1803. /// <param name="strAction">按鈕動作名稱</param>
  1804. private bool CheckButtonRight(string strAction)
  1805. {
  1806. bool blHasRight = false;
  1807. try
  1808. {
  1809. DataTable dtAuthorize;
  1810. if (Session["dtAuthorize"] == null)
  1811. {
  1812. dtAuthorize = fnDataSetToDataTable(new OT.BLL.OTB_SYS_Authorize().GetListByRuleID(gstrUserID));//gstrUserRoleId-->gstrUserID
  1813. }
  1814. else
  1815. {
  1816. dtAuthorize = (DataTable)Session["dtAuthorize"];
  1817. }
  1818. DataRow[] drAuthorizes = dtAuthorize.Select(" ProgramID = '" + gstrProgramId + "' ");
  1819. foreach (DataRow dr in drAuthorizes)
  1820. {
  1821. blHasRight = dr["AllowRight"].ToString().Contains(strAction.Replace("btn", ""));
  1822. if (blHasRight)
  1823. {
  1824. break;
  1825. }
  1826. }
  1827. }
  1828. catch (Exception ex)
  1829. {
  1830. mo_Log.Debug(string.Format("BasePage.CheckButtonRight Debug : Param:strAction={0}", strAction));
  1831. mo_Log.Error(ex.Message, ex);
  1832. }
  1833. return blHasRight;
  1834. }
  1835. private bool CheckButtonRight(string strProgramId, string strAction)
  1836. {
  1837. bool blHasRight = false;
  1838. try
  1839. { //Add by Alina 201401016 添加的這部分是為了顯示修改按鈕,但是權限還是按照真正是否有權限去處理的 Star
  1840. //目的是讓客戶知道還有一個修改的權限,如果要修改,需要去給權限,修改權限才可以用
  1841. if (strProgramId.Contains("_Upd") && strAction == "Upd")
  1842. {
  1843. blHasRight = true;
  1844. }//Add by Alina 201401016 添加的這部分是為了顯示修改按鈕,但是權限還是按照真正是否有權限去處理的 End
  1845. else
  1846. {
  1847. DataTable dtAuthorize;
  1848. if (Session["dtAuthorize"] == null)
  1849. {
  1850. dtAuthorize = fnDataSetToDataTable(new OT.BLL.OTB_SYS_Authorize().GetListByRuleID(gstrUserID));//gstrUserRoleId-->gstrUserID
  1851. }
  1852. else
  1853. {
  1854. dtAuthorize = (DataTable)Session["dtAuthorize"];
  1855. }
  1856. DataRow[] drAuthorizes = dtAuthorize.Select(" ProgramID = '" + strProgramId + "' ");
  1857. foreach (DataRow dr in drAuthorizes)
  1858. {
  1859. blHasRight = dr["AllowRight"].ToString().Contains(strAction.Replace("btn", ""));
  1860. if (blHasRight)
  1861. {
  1862. break;
  1863. }
  1864. }
  1865. }
  1866. }
  1867. catch (Exception ex)
  1868. {
  1869. mo_Log.Debug(string.Format("BasePage.CheckButtonRight Debug : Param:strAction={0}", strAction));
  1870. mo_Log.Error(ex.Message, ex);
  1871. }
  1872. return blHasRight;
  1873. }
  1874. #endregion
  1875. #region SetButtonRight
  1876. /// <summary>
  1877. /// 設定按鈕權限(顯示|隱藏)
  1878. /// </summary>
  1879. private void SetButtonRight()
  1880. {
  1881. try
  1882. {
  1883. //Added by Ethan,2014/04/22 Start. 如果程式有可用權限則添加按鈕。
  1884. if (!IsPostBack)
  1885. {
  1886. //非頁面第一次加載才執行
  1887. Toolbar toolbar = (Toolbar)Page.FindControl("Toolbar1");
  1888. if (toolbar != null)
  1889. {
  1890. string strCuryProgramAllowRights = GetProgramByColName("AllowRight");
  1891. foreach (
  1892. string strRight in
  1893. strCuryProgramAllowRights.Trim()
  1894. .Split(new char[1] { '|' }, StringSplitOptions.RemoveEmptyEntries))
  1895. {
  1896. ToolbarButton btnUpd = new ToolbarButton();
  1897. int intIndex = 0;
  1898. string strRightText = GetRightInfo(strRight, ref intIndex);
  1899. btnUpd.Key = strRight;
  1900. btnUpd.Text = strRightText;
  1901. btnUpd.Index = intIndex;
  1902. btnUpd.Enabled = true;
  1903. //btnUpd.CssClass = "icon-" + strRight.ToLower() + " btn01-" + strRight.ToLower() + " ";
  1904. btnUpd.CssClass = "btn";
  1905. if (CheckButtonRight(gstrProgramId, strRight))
  1906. {
  1907. btnUpd.Visible = true;
  1908. //如果Visible = trur 才有必要進行下列判斷,Visible=false 就沒有判斷的必要了
  1909. switch (strRight)
  1910. {
  1911. case "Leave":
  1912. btnUpd.Js += "if(fnLeaveInBack()){}else{if(fnCustomBack()){}else{parent.OpenPageTab('" + gstrProgramId.Substring(0, gstrProgramId.LastIndexOf("_")) + "_Qry" + "')};return false;}";
  1913. //使用fnUpdInBack() js判斷是否需要進入後台,如果為false,則只通過前台js達到解鎖效果
  1914. //目前fnUpdInBack預設為false,如頁面需要進入後台者,
  1915. //則在該頁面添加fnUpdInBack() js,並讓回傳值等於true
  1916. //Add by Gary 2014/05/30
  1917. //使用fnCustomBack() js判斷是否有自定義的需求,如果沒有則自動前往該頁的Qry畫面。 //Add by Gary 2014/07/31
  1918. break;
  1919. case "Clear":
  1920. btnUpd.CausesValidation = false;
  1921. btnUpd.Js += "try{if(!Page_ClientValidate('NotCheck')){return false;}}catch(e){;}";
  1922. //Add by Jack 20140724 重新定義了一個清除的js Start
  1923. btnUpd.Js += "fnAllPageClear();if(fnClientAllClear()){}else{setTimeout($.unblockUI,100); return false;}";//註冊清除js
  1924. //Add by Jack 20140724 重新定義了一個清除的js End
  1925. //Del by Jack 20140724 重新定義了一個清除的js(舊的不用了) Start
  1926. //modfiy by Alina 20140723 查詢畫面清空查詢條件即可 Star
  1927. //if (Request.QueryString["Action"] == "Qry" )
  1928. //if (Request.QueryString["Action"] == "Qry" || Request.QueryString["Action"] == null)
  1929. //modfiy by Alina 20140723 查詢畫面清空查詢條件即可 End
  1930. //{
  1931. // btnUpd.Js += "fnALLClear('#searchbar');if(fnClientAllClear()){}else{return false;};";
  1932. //}
  1933. //else
  1934. //{
  1935. //btnUpd.Js += "fnALLClear();if(fnClientAllClear()){}else{return false;}"; //比較建議,各自Upd的清空自行填寫 Add By Dean
  1936. //}
  1937. //Del by Jack 20140724 重新定義了一個清除的js(舊的不用了) Start
  1938. break;
  1939. case "Del": //刪除
  1940. btnUpd.Js += "if(!ShowConfirm('A00013','','',this)){___CloseWaitingForm();return false;}"; //增加刪除前提醒
  1941. btnUpd.Js += "this.value='刪除中…';"; //預設一開始是無法使用的
  1942. break;
  1943. case "Save": //儲存
  1944. btnUpd.Js += "try{if(!Page_ClientValidate()){___CloseWaitingForm();return false;}}catch(e){;}"; //可以回傳是否驗證通過
  1945. btnUpd.Js += "this.disabled=true;this.value='儲存中…';"; //預設一開始是無法使用的
  1946. break;
  1947. case "ReAdd"://儲存後新增
  1948. btnUpd.Js += "try{if(!Page_ClientValidate()){___CloseWaitingForm();return false;}}catch(e){;}"; //可以回傳是否驗證通過
  1949. btnUpd.Js += "this.disabled=true;this.value='儲存中…';"; //預設一開始是無法使用的
  1950. break;
  1951. case "Sub":
  1952. btnUpd.Js += "try{if(!Page_ClientValidate()){___CloseWaitingForm();return false;}}catch(e){;}";
  1953. break;
  1954. case "Chk":
  1955. btnUpd.Js += "try{if(!Page_ClientValidate()){___CloseWaitingForm();return false;}}catch(e){;}";
  1956. break;
  1957. case "Upd":
  1958. btnUpd.Js += "if(fnUpdInBack()){}else{fnUpdRemove();setTimeout($.unblockUI,100);$(this).addClass('displayNone');return false;}";
  1959. //使用fnUpdInBack() js判斷是否需要進入後台,如果為false,則只通過前台js達到解鎖效果
  1960. //目前fnUpdInBack預設為false,如頁面需要進入後台者,
  1961. //則在該頁面添加fnUpdInBack() js,並讓回傳值等於true
  1962. //Add by Gary 2014/05/30
  1963. break;
  1964. case "Exp":
  1965. btnUpd.Js += "setTimeout($.unblockUI,3000);";
  1966. break;
  1967. }
  1968. }
  1969. else
  1970. {
  1971. btnUpd.Visible = false;
  1972. }
  1973. if (Request.QueryString["Action"] == "Upd" && "|ReAdd".Contains("|" + strRight))
  1974. {
  1975. //隱藏按鈕,因為以上按鈕是不應該出現在編輯畫面Toolbar上的。
  1976. }
  1977. else if (Request.QueryString["Action"] == "Add" && ("|Del".Contains("|" + strRight) || "|Upd".Contains("|" + strRight) || "|Print".Contains("|" + strRight) || "|Exp".Contains("|" + strRight)))
  1978. {
  1979. //隱藏按鈕,因為以上按鈕是不應該出現在新增畫面Toolbar上的。
  1980. }
  1981. else if ("|View".Contains("|" + strRight))
  1982. {
  1983. //隱藏按鈕,因為以上按鈕是不應該出現在新增畫面Toolbar上的。
  1984. }
  1985. else if ("|Upd".Contains("|" + strRight) && (strCuryProgramAllowRights.IndexOf("Upd", StringComparison.InvariantCultureIgnoreCase) == -1 || strCuryProgramAllowRights.IndexOf("Save", StringComparison.InvariantCultureIgnoreCase) == -1))
  1986. {
  1987. //修改按鈕,無儲存權限 也應該沒有修改的權限
  1988. }
  1989. else if ("|Save".Contains("|" + strRight) && (strCuryProgramAllowRights.IndexOf("Upd", StringComparison.InvariantCultureIgnoreCase) == -1 || strCuryProgramAllowRights.IndexOf("Save", StringComparison.InvariantCultureIgnoreCase) == -1))
  1990. {
  1991. //儲存按鈕,如果有按修改,此功能方可作用
  1992. }
  1993. else if ("|Clear".Contains("|" + strRight) && gstrProgramId.IndexOf("_Upd", StringComparison.CurrentCultureIgnoreCase) > -1 && (strCuryProgramAllowRights.IndexOf("Upd", StringComparison.InvariantCultureIgnoreCase) == -1 || strCuryProgramAllowRights.IndexOf("Save", StringComparison.InvariantCultureIgnoreCase) == -1))
  1994. {
  1995. //清除按鈕,如果有按修改,此功能方可作用
  1996. }
  1997. else if (strRight.Contains("Upd") && gstrProgramId.IndexOf("_Upd", StringComparison.CurrentCultureIgnoreCase) == -1)
  1998. {
  1999. //隱藏編輯按鈕,因為編輯按鈕是不應該出現在Toolbar上的。2014/04/25添加判斷是否為修改畫面如果不是修改畫面不應該出現修改按鈕。
  2000. }
  2001. else
  2002. {
  2003. toolbar.Items.Add(btnUpd);
  2004. }
  2005. }
  2006. toolbar.Items.Sort();
  2007. }
  2008. }
  2009. //else
  2010. //{
  2011. // //每次都要更新按鈕是否顯示的狀態
  2012. // Toolbar toolbar = (Toolbar) Page.FindControl("Toolbar1");
  2013. // if (toolbar != null)
  2014. // {
  2015. // }
  2016. //}
  2017. //Added by Ethan,2014/04/22 End. 如果程式有可用權限則添加按鈕。
  2018. //Delete By Gary 2014/08/12 Start 這部分以該用ToolBar,所以以下代碼判斷沒有使用到,如果至8/31日前沒有發現問題即可刪除。
  2019. //foreach (string btnId in garyAllowRight)
  2020. //{
  2021. // Control btn = Page.FindControl("btn" + btnId);
  2022. // if (btn != null)
  2023. // {
  2024. // string strCuryProgramAllowRight = GetProgramByColName("AllowRight");
  2025. // strCuryProgramAllowRight = "|" + strCuryProgramAllowRight.Trim('|');
  2026. // if (strCuryProgramAllowRight.Contains("|" + btnId))
  2027. // {
  2028. // btn.Visible = CheckButtonRight("btn" + btnId);
  2029. // }
  2030. // else
  2031. // {
  2032. // btn.Visible = false;
  2033. // }
  2034. // if (Request.QueryString["Action"] == "Upd" && "|ReAdd".Contains("|" + btnId))
  2035. // {
  2036. // //隱藏按鈕,因為以上按鈕是不應該出現在編輯畫面Toolbar上的。
  2037. // btn.Visible = false;
  2038. // }
  2039. // else if (Request.QueryString["Action"] == "Add" && "|Del".Contains("|" + btnId))
  2040. // {
  2041. // //隱藏按鈕,因為以上按鈕是不應該出現在新增畫面Toolbar上的。
  2042. // btn.Visible = false;
  2043. // }
  2044. // if (btnId.Contains("Upd") && gstrProgramId.IndexOf("_Upd", StringComparison.CurrentCultureIgnoreCase) == -1)
  2045. // {
  2046. // //隱藏編輯按鈕,因為編輯按鈕是不應該出現在Toolbar上的。2014/04/25添加判斷是否為修改畫面如果不是修改畫面不應該出現修改按鈕。
  2047. // btn.Visible = false;
  2048. // }
  2049. // if (btnId.Contains("Del"))
  2050. // {
  2051. // //btn
  2052. // }
  2053. // }
  2054. //}
  2055. //Delete By Gary 2014/08/12 End 這部分以該用ToolBar,所以以下代碼判斷沒有使用到,如果至8/31日前沒有發現問題即可刪除。
  2056. }
  2057. catch (Exception ex)
  2058. {
  2059. mo_Log.Debug(string.Format("BasePage.SetButtonRight Debug : Param:null"));
  2060. mo_Log.Error(ex.Message, ex);
  2061. }
  2062. }
  2063. #endregion
  2064. #region GetRootURI
  2065. /// <summary>
  2066. /// 獲取網站的根Uri
  2067. /// </summary>
  2068. /// <returns></returns>
  2069. private string GetRootURI()
  2070. {
  2071. string AppPath = "";
  2072. try
  2073. {
  2074. if (Request.ApplicationPath != null || Request.ApplicationPath != "/")
  2075. {
  2076. AppPath = Request.ApplicationPath;
  2077. }
  2078. }
  2079. catch (Exception ex)
  2080. {
  2081. mo_Log.Error(ex.Message, ex);
  2082. }
  2083. return AppPath;
  2084. }
  2085. #endregion
  2086. #region RegisterStartupScript
  2087. /// <summary>
  2088. /// 注意BasePage的Page_Load事件在 繼承它的頁面的Page_Load事件之後執行
  2089. /// </summary>
  2090. /// <param name="sender"></param>
  2091. /// <param name="e"></param>
  2092. private void RegisterStartupScript()
  2093. {
  2094. //要在這掛載JS之前請先問過Dean
  2095. //自動添加JS
  2096. StringBuilder sbCommonString = new StringBuilder();
  2097. sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/jquery-1.10.2.min.js'></script>");
  2098. sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/jquery-ui-1.10.3.custom.min.js'></script>");
  2099. //sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/jquery-migrate-1.2.1.min.js'></script>"); //支援1.9版以前
  2100. //sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/jquery.ui.datepicker-zh-TW.js'></script>");
  2101. //sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/jquery-ui-sliderAccess.js'></script>");
  2102. sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/jquery-ui-timepicker-addon.js'></script>");
  2103. sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/jquery-ui-timepicker-zh-TW.js'></script>");
  2104. //sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/jquery.lightbox-0.5.min.js'></script>");
  2105. //sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/jquery.lazyload.js'></script>");
  2106. //sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/jquery.lightbox-0.5.pack.js'></script>");
  2107. //sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/shadowbox.js'></script>");
  2108. sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/jquery.artDialog.js?skin=simple'></script>");
  2109. sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/iframeTools.js'></script>");
  2110. sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/PageTab.js'></script>");
  2111. sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/MessageBox.js'></script>");
  2112. sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/blockUI.js'></script>"); //Add By Ted 2014/07/31 等待畫面的JS
  2113. sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/jquery.floatThead.min.js'></script>"); //Add By Ted 2014/08/04 浮動資料表頭JS
  2114. sbCommonString.AppendLine("<script type='text/javascript' src='{0}/Js/Common.js'></script>");
  2115. //sbCommonString.AppendLine("<script defer=\"defer\">fnSetToolbarVisible(window);</script>");
  2116. string strStartUpScript = "<script defer=\"defer\">try{setTimeout(fnSetToolbarVisible(window),100);}catch(e){;}</script>";
  2117. ScriptManager.RegisterStartupScript(Page, this.Page.GetType(), "BasepageJs001", strStartUpScript, false); //RegisterStartupScript
  2118. string strUnDisScript = @"<script>
  2119. function SetUnDis() {
  2120. $('[disabled]').each(function (i, n) {
  2121. $(n).removeAttr('disabled');
  2122. $(n).removeAttr('onmouseover');
  2123. $(n).removeAttr('onclick');
  2124. $(n).attr('readonly', 'readonly');
  2125. });
  2126. }
  2127. $(document).ready(function () {
  2128. $('[disabled]').each(function (i, n) {
  2129. $(n).removeAttr('disabled');
  2130. $(n).attr('readonly', 'readonly');
  2131. $(n).focus(function () {
  2132. SetUnDis();
  2133. $(n).attr('disabled', 'disabled');
  2134. $(n).removeAttr('onmouseover');
  2135. $(n).removeAttr('onclick');
  2136. $(n).blur();
  2137. return false;
  2138. });
  2139. $(n).mousemove(function () {
  2140. SetUnDis();
  2141. $(n).attr('disabled', 'disabled');
  2142. $(n).removeAttr('onmouseover');
  2143. $(n).removeAttr('onclick');
  2144. $(n).blur();
  2145. return false;
  2146. });
  2147. $(n).focusin(function () {
  2148. SetUnDis();
  2149. $(n).attr('disabled', 'disabled');
  2150. $(n).removeAttr('onmouseover');
  2151. $(n).removeAttr('onclick');
  2152. $(n).blur();
  2153. return false;
  2154. });
  2155. });
  2156. });</script>";
  2157. //ScriptManager.RegisterClientScriptBlock(Page, this.Page.GetType(), "BasepageJs002UnDis", strUnDisScript, false); //RegisterStartupScript
  2158. Literal ltrUnDisScript = new Literal();
  2159. ltrUnDisScript.Text = strUnDisScript;
  2160. //Page.Controls.Add(ltrUnDisScript);
  2161. Literal ltrScript = new Literal();
  2162. ltrScript.Text = string.Format(sbCommonString.ToString(), GetRootURI().TrimEnd('/'));
  2163. //Page.Header.Controls.Add(ltrScript);
  2164. Page.Header.Controls.AddAt(0, ltrScript); //Modify By Gary 修正js加入順序
  2165. //Del by Jack 20140724 重新定義了一個給頁面賦值的js Start
  2166. //ScriptManager.RegisterClientScriptBlock(Page, this.Page.GetType(), "BasepageJs002", string.Format(sbCommonString.ToString(), GetRootURI().TrimEnd('/')), false); //RegisterStartupScript
  2167. //if ((!IsPostBack && Request.QueryString["Action"] == "Upd") || Request.QueryString["Action"] == "Upd" || Request.QueryString["Action"] == "Add" || (!IsPostBack && Request.QueryString["Action"] == "Add"))
  2168. //modfiy by Alina 20140723 修改此版的原因是因為查詢畫面不需要註冊“_Value”屬性,直接清空 Star
  2169. // 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
  2170. //if ((!IsPostBack && Request.QueryString["Action"] == "Upd") || (!IsPostBack && Request.QueryString["Action"] == "Add") || (!IsPostBack && Request.QueryString["Action"] == "Qry"))
  2171. ////modfiy by Alina 20140723 修改此版的原因是因為查詢畫面不需要註冊“_Value”屬性,直接清空 End
  2172. //{
  2173. // //頁面第一次加載執行
  2174. // ScriptManager.RegisterStartupScript(Page, Page.GetType(), "BasepageJs003", "try{setTimeout(fnLoadPageSaveValueAAA,200);}catch(e){;}", true);
  2175. //}
  2176. //Del by Jack 20140724 重新定義了一個給頁面賦值的js End
  2177. //Add by Jack 20140724 重新定義了一個給頁面賦值的js Start
  2178. if (!IsPostBack && Request.QueryString["Action"] == null)
  2179. //在查詢畫面賦值(只在第一次加載頁面賦值)
  2180. {
  2181. ScriptManager.RegisterStartupScript(Page, Page.GetType(), "BasepageJs003", "try{setTimeout(fnLoadPageSaveArrayValue('#searchbar'),400);fnLoadPageSaveValueAAA();}catch(e){;}", true);
  2182. //btnUpd.Js += "fnLoadPageSaveArrayValue('#searchbar');if(fnClientAllClear()){}else{return false;};";
  2183. }
  2184. else if ((!IsPostBack && Request.QueryString["Action"] == "Upd") || (!IsPostBack && Request.QueryString["Action"] == "Add") || (!IsPostBack && Request.QueryString["Action"] == "Qry"))
  2185. //在編輯畫面賦值(只在頁面第一次加載賦值)
  2186. {
  2187. ScriptManager.RegisterStartupScript(Page, Page.GetType(), "BasepageJs003", "try{setTimeout(fnLoadPageSaveArrayValue(),200);}catch(e){;}", true);
  2188. }
  2189. if (!string.IsNullOrEmpty(Request.QueryString["ErrMsg"]) && Request.QueryString["ErrMsg"] == "FileMaxError")
  2190. {
  2191. ShowArtAlert("A00076", gintUploadSize.ToString());
  2192. }
  2193. //Add by Jack 20140724 重新定義了一個給頁面賦值的js End
  2194. // string strLoadMsg = @"<div id='doing' style='CURSOR: wait; Z-INDEX: 12000; LEFT: 0px; WIDTH: 100%; POSITION: absolute; TOP: 0px; HEIGHT: 100%;'>
  2195. // 頁面加載中……
  2196. // </div>
  2197. // <script language='javascript' type='text/javascript'>
  2198. // function MyOnload() {
  2199. // document.getElementById('doing').style.display = 'none';
  2200. // }
  2201. // setTimeout(MyOnload,200);
  2202. // </script>";
  2203. // Literal ltrLoadMsgScript = new Literal();
  2204. // ltrLoadMsgScript.Text = strLoadMsg;
  2205. // Page.Controls.Add(ltrLoadMsgScript);
  2206. }
  2207. #endregion
  2208. #region SetTheme
  2209. /// <summary>
  2210. /// 設定頁面樣式
  2211. /// </summary>
  2212. private void SetTheme()
  2213. {
  2214. string strTheme = Common.GetAppSettings("DefaultTheme");
  2215. try
  2216. {
  2217. if (Session["THEME"] != null)
  2218. {
  2219. //如果有記錄Session值,則去Session設定。
  2220. strTheme = Session["THEME"].ToString();
  2221. HttpCookie cookie = new HttpCookie("OTK.Theme", Session["THEME"].ToString());
  2222. cookie.Expires = DateTime.Now.AddDays(1);
  2223. Response.Cookies.Add(cookie);
  2224. }
  2225. else
  2226. {
  2227. if (Request.Cookies["OTK.Theme"] != null && string.IsNullOrEmpty(Request.Cookies["OTK.Theme"].ToString()))
  2228. {
  2229. //如果沒有記錄Session值但有Cookie时,則取Cookie的設定。
  2230. strTheme = Request.Cookies["OTK.Theme"].Value.ToString();
  2231. }
  2232. Session["THEME"] = strTheme;
  2233. }
  2234. }
  2235. catch (Exception ex)
  2236. {
  2237. strTheme = Common.GetAppSettings("DefaultTheme").ToString().ToLower();
  2238. Session["THEME"] = gstrUICulture;
  2239. mo_Log.Error(ex.Message, ex);
  2240. }
  2241. Page.Theme = strTheme;
  2242. }
  2243. #endregion
  2244. #region SetPageTitle
  2245. /// <summary>
  2246. /// 設定程式的Title
  2247. /// </summary>
  2248. /// <param name="strProgramId"></param>
  2249. /// Add By Dean 2014/05/21 增加各畫面顯示使用資料表名稱
  2250. private void SetPageTitle()
  2251. {
  2252. try
  2253. {
  2254. if (gdtProgramList == null)
  2255. {
  2256. fnLoadProgramList();
  2257. }
  2258. if (gdtProgramList.Rows.Count > 0)
  2259. {
  2260. Label lbFunctionTitle = ((Label)FindControl("lbFunctionTitle"));
  2261. if (lbFunctionTitle != null)
  2262. {
  2263. lbFunctionTitle.Text = gstrProgramName;
  2264. }
  2265. Label lbMainTableName = ((Label)FindControl("lbMainTableName")); /*Add By Dean 2014/05/21*/
  2266. if (lbMainTableName != null)
  2267. {
  2268. lbMainTableName.Text = "(Use:" + gstrProgramTableName + ")";
  2269. }
  2270. }
  2271. }
  2272. catch (Exception ex)
  2273. {
  2274. mo_Log.Error(ex.Message, ex);
  2275. }
  2276. }
  2277. #endregion
  2278. #region GetProgramByColName
  2279. /// <summary>
  2280. /// 通過欄位名稱獲取當前程式的信息
  2281. /// </summary>
  2282. /// <param name="strProgramId"></param>
  2283. private string GetProgramByColName(string strColName)
  2284. {
  2285. string strReturn = string.Empty;
  2286. try
  2287. {
  2288. if (gdtProgramList == null)
  2289. {
  2290. fnLoadProgramList();
  2291. }
  2292. if (gdtProgramList.Rows.Count > 0)
  2293. {
  2294. DataRow[] drs = gdtProgramList.Select(" ProgramID = '" + gstrProgramId + "'");
  2295. foreach (DataRow dr in drs)
  2296. {
  2297. strReturn = dr[strColName].ToString();
  2298. }
  2299. }
  2300. }
  2301. catch (Exception ex)
  2302. {
  2303. mo_Log.Error(ex.Message, ex);
  2304. }
  2305. return strReturn;
  2306. }
  2307. #endregion
  2308. #endregion
  2309. #region 頁面事件觸發區域
  2310. #region InitializeCulture
  2311. /// <summary>
  2312. /// 多語言設定
  2313. /// </summary>
  2314. protected override void InitializeCulture()
  2315. {
  2316. try
  2317. {
  2318. if (Session["CULTURE"] != null)
  2319. {
  2320. //如果有記錄Session值,則去Session設定。
  2321. gstrUICulture = Session["CULTURE"].ToString();
  2322. HttpCookie cookie = new HttpCookie("AD1688.Language", Session["CULTURE"].ToString());
  2323. cookie.Expires = DateTime.Now.AddDays(1);
  2324. Response.Cookies.Add(cookie);
  2325. }
  2326. else
  2327. {
  2328. if (Request.Cookies["AD1688.Language"] != null && string.IsNullOrEmpty(Request.Cookies["AD1688.Language"].ToString()))
  2329. {
  2330. //如果沒有記錄Session值但有Cookie时,則取Cookie的設定。
  2331. gstrUICulture = Request.Cookies["AD1688.Language"].Value.ToString();
  2332. }
  2333. else if (Request.UserLanguages != null && !string.IsNullOrEmpty(Request.UserLanguages[0]))
  2334. {
  2335. //如果沒有記錄Session值和Cookie时,則取客戶端瀏覽器預設語言。
  2336. gstrUICulture = Request.UserLanguages[0].ToLower();
  2337. }
  2338. else
  2339. {
  2340. //如果沒有記錄Session值和Cookie时,取客戶端瀏覽器預設語言失敗則取系統設定的預設語言。
  2341. gstrUICulture = Common.GetAppSettings("DefaultLanguage").ToString().ToLower();
  2342. }
  2343. Session["CULTURE"] = gstrUICulture;
  2344. }
  2345. }
  2346. catch (Exception ex)
  2347. {
  2348. gstrUICulture = Common.GetAppSettings("DefaultLanguage").ToString().ToLower();
  2349. Session["CULTURE"] = gstrUICulture;
  2350. mo_Log.Error(ex.Message, ex);
  2351. }
  2352. string real_culture = "";
  2353. switch (gstrUICulture)
  2354. {
  2355. case "TW":
  2356. UICulture = "zh-TW";
  2357. Culture = "zh-TW";
  2358. real_culture = "zh-TW";
  2359. break;
  2360. case "CN":
  2361. UICulture = "zh-CN";
  2362. Culture = "zh-CN";
  2363. real_culture = "zh-CN";
  2364. break;
  2365. default:
  2366. UICulture = "en-US";
  2367. Culture = "en-US";
  2368. real_culture = "en-US";
  2369. break;
  2370. }
  2371. UICulture = real_culture;
  2372. Culture = real_culture;
  2373. Thread.CurrentThread.CurrentCulture =
  2374. CultureInfo.CreateSpecificCulture(real_culture);
  2375. Thread.CurrentThread.CurrentUICulture = new
  2376. CultureInfo(real_culture);
  2377. base.InitializeCulture();
  2378. }
  2379. #endregion
  2380. #region OnPreInit
  2381. /// <summary>
  2382. /// 頁面進入前出發事件
  2383. /// </summary>
  2384. /// <param name="e"></param>
  2385. protected override void OnPreInit(EventArgs e)
  2386. {
  2387. SetTheme();
  2388. base.OnPreInit(e);
  2389. }
  2390. #endregion
  2391. #region OnInit
  2392. /// <summary>
  2393. /// 頁面進入事件
  2394. /// </summary>
  2395. /// <param name="e"></param>
  2396. protected override void OnInit(EventArgs e)
  2397. {
  2398. GetProgramId(); //得到当前程式代号
  2399. gstrProgramName = GetProgramByColName("ProgramName"); //獲取程式的Title
  2400. gstrProgramTableName = GetProgramByColName("MainTableName"); //獲取程式所使用的主TableName
  2401. CheckIsLogin(); //驗證是否成功登入
  2402. base.OnInit(e);
  2403. gstrVirtualPath = Page.Request.ApplicationPath; //項目的虛擬路徑
  2404. gstrLocalPath = this.Server.MapPath(Page.Request.ApplicationPath); //項目的物理路徑
  2405. }
  2406. #endregion
  2407. #region OnLoad
  2408. /// <summary>
  2409. /// 頁面加載事件
  2410. /// </summary>
  2411. /// <param name="e"></param>
  2412. protected override void OnLoad(System.EventArgs e)
  2413. {
  2414. RegisterStartupScript(); //註冊腳本
  2415. SetPageTitle(); //設定程式的Title
  2416. SetButtonRight(); //設定按鈕權限(顯示|隱藏)
  2417. //Modified by Gary,20140325 Start. 因應旅遊業系統,在編輯畫面先把所有編輯功能鎖定
  2418. if (!string.IsNullOrEmpty(Request.QueryString["Action"]) && Request.QueryString["Action"].ToUpper() == "UPD")
  2419. {
  2420. if (!IsPostBack) //只在第一次載入時作業 Modify By Gary 20140326
  2421. {
  2422. if (gbl_AllowEdit)
  2423. {
  2424. //modfiy by Alina 20140426 加載編輯畫面時,Toobar上應該放開修改,離開,列印按鈕,其他按鈕在點擊修改後再放開 End
  2425. // ScriptManager.RegisterStartupScript(Page, Page.GetType(), "NotUpdJS", "try{setTimeout(fnUnDisabledThisCtl(),20);}catch(e){;}", true);
  2426. //modfiy by Alina 20141115 有修改權限,修改按鈕隱藏掉。
  2427. // ScriptManager.RegisterStartupScript(Page, Page.GetType(), "NotUpdJS", "try{setTimeout(fnUnDisabledThisCtl('Toolbar1_Leave,Toolbar1_Print,Toolbar1_Upd'),20);}catch(e){;}", true);
  2428. ScriptManager.RegisterStartupScript(Page, Page.GetType(), "NotUpdJS", "try{setTimeout(fnHiddenUpd(),20);}catch(e){;}", true);
  2429. //modfiy by Alina 20140426 加載編輯畫面時,Toobar上應該放開修改,離開,列印按鈕,其他按鈕在點擊修改後再放開 Star
  2430. }
  2431. else
  2432. {
  2433. //當編輯資料的時候發現沒有權限,則禁止畫面修改。
  2434. //Modified by Ethan,20130528 Start. 修改結案報表編輯畫面無法列印的問題
  2435. //ScriptManager.RegisterStartupScript(Page, Page.GetType(), "NotUpdJS", "try{setTimeout(fnUnDisabledThisCtl('btnLeave'),20);}catch(e){;}", true);
  2436. ScriptManager.RegisterStartupScript(Page, Page.GetType(), "NotUpdJS", "try{setTimeout(fnUnDisabledThisCtl('Toolbar1_Leave,btnLeave,btnPrint','NoUpd'),20);}catch(e){;}", true);
  2437. //Modified by Gary,20140325 在fnUnDisabledThisCtl添加第二個參數判斷是否有權限修改
  2438. //Modified by Ethan,20130528 End. 修改結案報表編輯畫面無法列印的問題
  2439. }
  2440. }
  2441. }
  2442. //Modified by Gary,20140325 End. 因應旅遊業系統,在編輯畫面先把所有編輯功能鎖定
  2443. base.OnLoad(e);
  2444. }
  2445. #endregion
  2446. #region OnPreRender
  2447. /// <summary>
  2448. /// 頁面呈現前事件
  2449. /// </summary>
  2450. /// <param name="e"></param>
  2451. protected override void OnPreRender(EventArgs e)
  2452. {
  2453. base.OnPreRender(e);
  2454. }
  2455. #endregion
  2456. #region Render
  2457. /// <summary>
  2458. /// 繪製頁面內容
  2459. /// </summary>
  2460. /// <param name="writer"></param>
  2461. protected override void Render(HtmlTextWriter writer)
  2462. {
  2463. StringWriter stringWriter = new StringWriter();
  2464. HtmlTextWriter oldwriter = new HtmlTextWriter(stringWriter);
  2465. base.Render(oldwriter);
  2466. string oldContent = stringWriter.ToString();
  2467. string newContent = oldContent.Replace("{Theme}", Page.Theme).Replace("App_Themes/Default/", string.Format("App_Themes/{0}/", Page.Theme)); //修改Image的路徑為當前樣式的路徑
  2468. writer.Write(newContent);
  2469. }
  2470. #endregion
  2471. #region OnError
  2472. /// <summary>
  2473. /// 頁面錯誤觸發事件
  2474. /// </summary>
  2475. /// <param name="e"></param>
  2476. protected override void OnError(EventArgs e)
  2477. {
  2478. Exception Error = Server.GetLastError();
  2479. mo_Log.Error(Error.Message, Error);
  2480. string strUrl = string.Format("~/Error.aspx?ErrMsg={0}", fnUrlEncode(Error.Message));
  2481. Response.Redirect(strUrl, false);//true-->false
  2482. }
  2483. #endregion
  2484. #endregion
  2485. }
  2486. }