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.

736 lines
27 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7. using System.Security.Cryptography;
  8. using System.Data;
  9. using System.Data.Sql;
  10. using System.Data.SqlClient;
  11. using System.Windows.Forms;
  12. using System.Configuration;
  13. using System.Drawing;
  14. namespace ManagementSystem.Utility
  15. {
  16. public static class UtilityClass
  17. {
  18. #region 加解密相關
  19. /// <summary>
  20. /// 進行DES加密
  21. /// </summary>
  22. /// <param name="pToEncrypt">要加密的字串</param>
  23. /// <param name="key">金鑰,必須為8位</param>
  24. /// <returns>以Base64格式返回的加密字串</returns>
  25. public static string EncryptDES(string pToEncrypt, string sKey)
  26. {
  27. using (DESCryptoServiceProvider des = new DESCryptoServiceProvider())
  28. {
  29. byte[] inputByteArray = Encoding.UTF8.GetBytes(pToEncrypt);
  30. des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
  31. des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
  32. System.IO.MemoryStream ms = new System.IO.MemoryStream();
  33. using (CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write))
  34. {
  35. cs.Write(inputByteArray, 0, inputByteArray.Length);
  36. cs.FlushFinalBlock();
  37. cs.Close();
  38. }
  39. string str = Convert.ToBase64String(ms.ToArray());
  40. ms.Close();
  41. return str;
  42. }
  43. }
  44. public static string DecryptDES(string pToDecrypt, string sKey)
  45. {
  46. try
  47. {
  48. //判斷是否為空值
  49. if (pToDecrypt == "")
  50. {
  51. return "";
  52. }
  53. byte[] inputByteArray = Convert.FromBase64String(pToDecrypt);
  54. using (DESCryptoServiceProvider des = new DESCryptoServiceProvider())
  55. {
  56. des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
  57. des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
  58. MemoryStream ms = new MemoryStream();
  59. using (CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write))
  60. {
  61. cs.Write(inputByteArray, 0, inputByteArray.Length);
  62. cs.FlushFinalBlock();
  63. cs.Close();
  64. }
  65. string str = Encoding.UTF8.GetString(ms.ToArray());
  66. ms.Close();
  67. return str;
  68. }
  69. }
  70. catch (Exception ex)
  71. {
  72. return "";
  73. }
  74. }
  75. public static string EncryptDES(int pToEncrypt, string sKey)
  76. {
  77. return EncryptDES(pToEncrypt.ToString(), sKey);
  78. }
  79. #endregion
  80. #region 取得系統參數資料
  81. public static DataSet GetSystemArgument(string strSysArgumentClassID, string strLanguageID)
  82. {
  83. DataSet dsData = new DataSet();
  84. try
  85. {
  86. string strCommand = string.Format("Select ArgumentID,ArgumentValue,LanguageID,OrderByValue From OTB_SYS_Arguments Where ArgumentClassID='{0}'", strSysArgumentClassID);
  87. if (strLanguageID != "")
  88. {
  89. strCommand += string.Format(" And LanguageID = '{0}'", strLanguageID);
  90. }
  91. using (SqlConnection sqlConn = GetConn(MainForm.strAccountingBookID))
  92. {
  93. using (SqlDataAdapter sqlAdapter = new SqlDataAdapter(strCommand, sqlConn))
  94. {
  95. if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態
  96. {
  97. sqlConn.Open();
  98. }
  99. sqlAdapter.Fill(dsData, "Arguments");
  100. //增加空白選項
  101. DataRow drData = dsData.Tables["Arguments"].NewRow();
  102. drData["ArgumentID"] = " ";
  103. drData["ArgumentValue"] = "請選擇";
  104. drData["OrderByValue"] = 0;
  105. dsData.Tables["Arguments"].Rows.Add(drData);
  106. //資料進行排序
  107. dsData.Tables["Arguments"].DefaultView.Sort = "OrderByValue ASC";
  108. }
  109. }
  110. return dsData;
  111. }
  112. catch (Exception ex)
  113. {
  114. throw ex;
  115. }
  116. }
  117. #endregion
  118. #region 取得組織結構
  119. public static DataSet GetOrgList()
  120. {
  121. DataSet dsData = new DataSet();
  122. try
  123. {
  124. string strCommand = string.Format("Select OrganizationID,OrganizationName From OTB_SYS_Organization Where Effective='Y'");
  125. using (SqlConnection sqlConn = GetConn(MainForm.strAccountingBookID))
  126. {
  127. using (SqlDataAdapter sqlAdapter = new SqlDataAdapter(strCommand, sqlConn))
  128. {
  129. if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態
  130. {
  131. sqlConn.Open();
  132. }
  133. sqlAdapter.Fill(dsData, "Organizations");
  134. //增加空白選項
  135. DataRow drData = dsData.Tables["Organizations"].NewRow();
  136. drData["OrganizationID"] = " ";
  137. drData["OrganizationName"] = "請選擇";
  138. dsData.Tables["Organizations"].Rows.Add(drData);
  139. //資料進行排序
  140. dsData.Tables["Organizations"].DefaultView.Sort = "OrganizationID ASC";
  141. }
  142. }
  143. return dsData;
  144. }
  145. catch (Exception ex)
  146. {
  147. throw ex;
  148. }
  149. }
  150. public static DataSet GetOrganization()
  151. {
  152. DataSet dsData = new DataSet();
  153. try
  154. {
  155. string strCommand = string.Format("Select DepartmentID,DepartmentName,DepartmentShortName,ParentDepartmentID,LevelOfDepartment,OrderByValue From OTB_SYS_Departments Where Effective='Y'");
  156. using (SqlConnection sqlConn = GetConn(MainForm.strAccountingBookID))
  157. {
  158. using (SqlDataAdapter sqlAdapter = new SqlDataAdapter(strCommand, sqlConn))
  159. {
  160. if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態
  161. {
  162. sqlConn.Open();
  163. }
  164. sqlAdapter.Fill(dsData, "Departments");
  165. //增加資料
  166. foreach (DataRow drDatas in dsData.Tables["Departments"].Rows)
  167. {
  168. drDatas["DepartmentName"] = GetOrgTree(drDatas["DepartmentID"].ToString());
  169. }
  170. //增加空白選項
  171. DataRow drData = dsData.Tables["Departments"].NewRow();
  172. drData["DepartmentID"] = " ";
  173. drData["DepartmentName"] = "請選擇";
  174. drData["OrderByValue"] = 0;
  175. dsData.Tables["Departments"].Rows.Add(drData);
  176. //資料進行排序
  177. dsData.Tables["Departments"].DefaultView.Sort = "LevelOfDepartment ASC, OrderByValue ASC";
  178. }
  179. }
  180. return dsData;
  181. }
  182. catch (Exception ex)
  183. {
  184. throw ex;
  185. }
  186. }
  187. public static string GetOrgTree(string strOrgID)
  188. {
  189. try
  190. {
  191. DataSet dsData = new DataSet();
  192. string strCommand = string.Format("Select DepartmentName,DepartmentShortName,ParentDepartmentID From OTB_SYS_Departments Where DepartmentID = '{0}'", strOrgID);
  193. using (SqlConnection sqlConn = GetConn(MainForm.strAccountingBookID))
  194. {
  195. using (SqlDataAdapter sqlAdapter = new SqlDataAdapter(strCommand, sqlConn))
  196. {
  197. if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態
  198. {
  199. sqlConn.Open();
  200. }
  201. sqlAdapter.Fill(dsData, "Departments");
  202. if (dsData.Tables["Departments"].Rows[0]["ParentDepartmentID"].ToString().Trim() == "")
  203. {
  204. return dsData.Tables["Departments"].Rows[0]["DepartmentName"].ToString().Trim();
  205. }
  206. else
  207. {
  208. return GetOrgTree(dsData.Tables["Departments"].Rows[0]["ParentDepartmentID"].ToString().Trim()) + "-" + dsData.Tables["Departments"].Rows[0]["DepartmentName"].ToString().Trim();
  209. }
  210. }
  211. }
  212. }
  213. catch (Exception ex)
  214. {
  215. throw ex;
  216. }
  217. }
  218. #endregion
  219. #region 取得指定Table資料
  220. public static DataSet GetTable(string strTableName, string[] strColumnList , string strWhere, string strOrderBy)
  221. {
  222. DataSet dsData = new DataSet();
  223. try
  224. {
  225. string strColumns = "";
  226. foreach (string strColumn in strColumnList) //取得欄位陣列
  227. {
  228. if (strColumns != "")
  229. {
  230. strColumns += "," + strColumn.Trim();
  231. }
  232. else
  233. {
  234. strColumns = strColumn;
  235. }
  236. }
  237. string strCommand = string.Format("Select {0} From {1} ",strColumns, strTableName);
  238. if (strWhere != "") //設定過濾條件
  239. {
  240. strCommand += " Where " + strWhere;
  241. }
  242. if (strOrderBy != "") //取得排序欄位
  243. {
  244. strCommand += " Order By " + strOrderBy;
  245. }
  246. using (SqlConnection sqlConn = GetConn(MainForm.strAccountingBookID))
  247. {
  248. using (SqlDataAdapter sqlAdapter = new SqlDataAdapter(strCommand, sqlConn))
  249. {
  250. if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態
  251. {
  252. sqlConn.Open();
  253. }
  254. sqlAdapter.Fill(dsData, "Result");
  255. }
  256. }
  257. return dsData;
  258. }
  259. catch (Exception ex)
  260. {
  261. throw ex;
  262. }
  263. }
  264. public static DataSet GetTable(string strTableName, string[] strColumnList, string strWhere)
  265. {
  266. return GetTable(strTableName, strColumnList, strWhere, "");
  267. }
  268. public static DataSet GetTable(string strTableName, string[] strColumnList)
  269. {
  270. return GetTable(strTableName, strColumnList,"","");
  271. }
  272. public static DataSet GetTable(string strTableName)
  273. {
  274. return GetTable(strTableName,new string[] {"*"}, "", "");
  275. }
  276. #endregion
  277. #region SQL命令相關程式集
  278. public static SqlConnection GetConn(string strOrg)
  279. {
  280. string strConn = "";
  281. SqlConnection sqlConn = null;
  282. switch(strOrg)
  283. {
  284. case "":
  285. strConn = System.Configuration.ConfigurationManager.ConnectionStrings["OrigtekSQLConn"].ToString();
  286. sqlConn = new SqlConnection(strConn);
  287. break;
  288. case "Origtek":
  289. strConn = System.Configuration.ConfigurationManager.ConnectionStrings["OrigtekSQLConn"].ToString();
  290. sqlConn = new SqlConnection(strConn);
  291. break;
  292. case "OrigtekEnergy":
  293. strConn = System.Configuration.ConfigurationManager.ConnectionStrings["OEnergySQLConn"].ToString();
  294. sqlConn = new SqlConnection(strConn);
  295. break;
  296. }
  297. return sqlConn;
  298. }
  299. public static SqlConnection GetConn()
  300. {
  301. return GetConn("");
  302. }
  303. public static DataSet GetSQLResult(string strSQL)
  304. {
  305. DataSet dsData = new DataSet();
  306. try
  307. {
  308. using (SqlConnection sqlConn = GetConn(MainForm.strAccountingBookID))
  309. {
  310. using (SqlDataAdapter sqlAdapter = new SqlDataAdapter(strSQL, sqlConn))
  311. {
  312. if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態
  313. {
  314. sqlConn.Open();
  315. }
  316. sqlAdapter.Fill(dsData, "Result");
  317. }
  318. }
  319. return dsData;
  320. }
  321. catch(Exception ex)
  322. {
  323. throw ex;
  324. }
  325. }
  326. public static bool IsExist(string strSQL)
  327. {
  328. try
  329. {
  330. DataSet sdResult = GetSQLResult(strSQL);
  331. DataTable dtResult = sdResult.Tables[0];
  332. if (dtResult.Rows.Count > 0)
  333. { return true; }
  334. else
  335. { return false; }
  336. }
  337. catch (Exception ex)
  338. {
  339. throw ex;
  340. }
  341. }
  342. public static bool RunSQLNonReturn(string strSQL)
  343. {
  344. try
  345. {
  346. SqlConnection sqlConn = GetConn(MainForm.strAccountingBookID);
  347. SqlCommand sqlCmd = new SqlCommand(strSQL, sqlConn);
  348. if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態
  349. {
  350. sqlConn.Open();
  351. }
  352. sqlCmd.ExecuteNonQuery();
  353. return true;
  354. }
  355. catch (Exception ex)
  356. {
  357. return false;
  358. }
  359. }
  360. public static string GetSQLCount(string strSQL)
  361. {
  362. string strCount = "";
  363. DataSet dsTemp = GetSQLResult(strSQL);
  364. strCount = dsTemp.Tables[0].Rows.Count.ToString();
  365. //回傳查詢結果
  366. if(strCount == "")
  367. { return "0"; }
  368. else
  369. { return strCount; }
  370. }
  371. #endregion
  372. #region 其它共用程式
  373. public static bool IsNumber(string strSource)
  374. {
  375. float output;
  376. return float.TryParse(strSource, out output);
  377. } //確認是否為數字
  378. public static bool IsDate(string strSource)
  379. {
  380. try
  381. {
  382. //System.Globalization.DateTimeFormatInfo dtInfo = new System.Globalization.DateTimeFormatInfo();
  383. //dtInfo.FullDateTimePattern = "yyyy/MM/dd";
  384. //DateTime dtOutput = DateTime.ParseExact(strSource, "F", dtInfo);
  385. DateTime dtOutput;
  386. if (DateTime.TryParse(strSource, out dtOutput))
  387. {
  388. return true;
  389. }
  390. else
  391. {
  392. return false;
  393. }
  394. }
  395. catch(Exception ex)
  396. {
  397. return false;
  398. }
  399. }
  400. public static string MarkNumber(double dbNumber,int intPoint) //將資料加上三位一撇
  401. {
  402. return string.Format("{0:N" + intPoint + "}", dbNumber);
  403. }
  404. public static string MarkNumber(int intNumber, int intPoint) //將資料加上三位一撇
  405. {
  406. return string.Format("{0:N" + intPoint + "}", intNumber);
  407. }
  408. public static string MarkNumber(string strNumber, int intPoint) //將資料加上三位一撇
  409. {
  410. if (strNumber.IndexOf("%") != -1)
  411. {
  412. return strNumber;
  413. }
  414. if (!string.IsNullOrEmpty(strNumber))
  415. {
  416. if (IsNumber(strNumber))
  417. {
  418. return MarkNumber(Convert.ToDouble(strNumber), intPoint);
  419. }
  420. }
  421. return "";
  422. }
  423. public static string MarkNumber(double dbNumber) //將資料加上三位一撇
  424. {
  425. return string.Format("{0:N0}", dbNumber);
  426. }
  427. public static string MarkNumber(int intNumber) //將資料加上三位一撇
  428. {
  429. return string.Format("{0:N0}", intNumber);
  430. }
  431. public static string MarkNumber(string strNumber) //將資料加上三位一撇
  432. {
  433. if (!string.IsNullOrEmpty(strNumber))
  434. {
  435. if (strNumber.IndexOf("%") != -1)
  436. {
  437. return strNumber;
  438. }
  439. if (IsNumber(strNumber))
  440. {
  441. return MarkNumber(Math.Round(Convert.ToDouble(strNumber)));
  442. }
  443. }
  444. return "";
  445. }
  446. public static DataTable GetAccountingSubjectByID(string strAccountingSubID, string strAccountingBookID)
  447. {
  448. try
  449. {
  450. DataTable dtTemp = new DataTable();
  451. if (strAccountingSubID.Trim() != "")
  452. {
  453. //宣告物件
  454. string strSQL = string.Format("Select AccountingSubID, AccountingClass, DCClass, AccountingSubName From OTB_FNC_AccountingSubjects Where AccountingSubID = '{0}' And AccountingBookID = '{1}'", strAccountingSubID, strAccountingBookID);
  455. using (SqlConnection sqlConn = GetConn(MainForm.strAccountingBookID))
  456. {
  457. using (SqlDataAdapter sqlAdapter = new SqlDataAdapter())
  458. {
  459. //添加參數
  460. sqlAdapter.SelectCommand = new SqlCommand();
  461. sqlAdapter.SelectCommand.Connection = sqlConn;
  462. sqlAdapter.SelectCommand.CommandText = strSQL;
  463. if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態
  464. {
  465. sqlConn.Open();
  466. }
  467. //進行查詢
  468. dtTemp = UtilityClass.GetSQLResult(strSQL).Tables["Result"];
  469. }
  470. }
  471. }
  472. return dtTemp;
  473. }
  474. catch (Exception ex)
  475. {
  476. ErrorHandler.WriteErrorLog("UtilityClass.cs", ex);
  477. return null;
  478. }
  479. }
  480. public static DataTable GetAccountingSubjectByName(string strAccountingSubName)
  481. {
  482. try
  483. {
  484. DataTable dtTemp = new DataTable();
  485. if (strAccountingSubName.Trim() != "")
  486. {
  487. //宣告物件
  488. string strSQL = string.Format("Select AccountingSubID, AccountingClass, DCClass, AccountingSubName From OTB_FNC_AccountingSubjects Where AccountingSubName = '{0}'", strAccountingSubName);
  489. using (SqlConnection sqlConn = GetConn(MainForm.strAccountingBookID))
  490. {
  491. using (SqlDataAdapter sqlAdapter = new SqlDataAdapter())
  492. {
  493. //添加參數
  494. sqlAdapter.SelectCommand = new SqlCommand();
  495. sqlAdapter.SelectCommand.Connection = sqlConn;
  496. sqlAdapter.SelectCommand.CommandText = strSQL;
  497. if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態
  498. {
  499. sqlConn.Open();
  500. }
  501. //進行查詢
  502. dtTemp = UtilityClass.GetSQLResult(strSQL).Tables["Result"];
  503. }
  504. }
  505. }
  506. return dtTemp;
  507. }
  508. catch (Exception ex)
  509. {
  510. ErrorHandler.WriteErrorLog("AccountingEntries.cs", ex);
  511. return null;
  512. }
  513. }
  514. public static string[] GetInsurance(string InsuranceAmount) //取得勞健保資料
  515. {
  516. string strSQL = "Select * From OTB_HR_Insurance Where InsuranceAmountStart <= " + InsuranceAmount + " And InsuranceAmountEnd > " + InsuranceAmount;
  517. string[] intInsurance = new string[6];
  518. DataSet dsData = new DataSet();
  519. try
  520. {
  521. using (SqlConnection sqlConn = GetConn(MainForm.strAccountingBookID))
  522. {
  523. using (SqlDataAdapter sqlAdapter = new SqlDataAdapter(strSQL, sqlConn))
  524. {
  525. if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態
  526. {
  527. sqlConn.Open();
  528. }
  529. sqlAdapter.Fill(dsData, "Result");
  530. intInsurance[0] = dsData.Tables["Result"].Rows[0]["InsuranceLevel"].ToString(); //級距
  531. intInsurance[1] = dsData.Tables["Result"].Rows[0]["C_LaborProtection"].ToString(); //公司提列勞保
  532. intInsurance[2] = dsData.Tables["Result"].Rows[0]["S_LaborProtection"].ToString(); //自行提列勞保
  533. intInsurance[3] = dsData.Tables["Result"].Rows[0]["C_HealthInsuranceAmount"].ToString(); //公司提列健保
  534. intInsurance[4] = dsData.Tables["Result"].Rows[0]["S_HealthInsuranceAmount"].ToString(); //自行提列健保
  535. intInsurance[5] = dsData.Tables["Result"].Rows[0]["RetirementAmount"].ToString(); //勞退金
  536. }
  537. }
  538. return intInsurance;
  539. }
  540. catch (Exception ex)
  541. {
  542. return intInsurance;
  543. }
  544. }
  545. public static string[] GetInsuranceByLevel(string InsuranceLevel) //取得勞健保資料
  546. {
  547. string strSQL = "Select * From OTB_HR_Insurance Where InsuranceLevel = " + InsuranceLevel;
  548. string[] intInsurance = new string[6];
  549. DataSet dsData = new DataSet();
  550. try
  551. {
  552. using (SqlConnection sqlConn = GetConn(MainForm.strAccountingBookID))
  553. {
  554. using (SqlDataAdapter sqlAdapter = new SqlDataAdapter(strSQL, sqlConn))
  555. {
  556. if (sqlConn.State == ConnectionState.Closed) //判斷連線狀態
  557. {
  558. sqlConn.Open();
  559. }
  560. sqlAdapter.Fill(dsData, "Result");
  561. intInsurance[0] = dsData.Tables["Result"].Rows[0]["InsuranceLevel"].ToString(); //級距
  562. intInsurance[1] = dsData.Tables["Result"].Rows[0]["C_LaborProtection"].ToString(); //公司提列勞保
  563. intInsurance[2] = dsData.Tables["Result"].Rows[0]["S_LaborProtection"].ToString(); //自行提列勞保
  564. intInsurance[3] = dsData.Tables["Result"].Rows[0]["C_HealthInsuranceAmount"].ToString(); //公司提列健保
  565. intInsurance[4] = dsData.Tables["Result"].Rows[0]["S_HealthInsuranceAmount"].ToString(); //自行提列健保
  566. intInsurance[5] = dsData.Tables["Result"].Rows[0]["RetirementAmount"].ToString(); //勞退金
  567. }
  568. }
  569. return intInsurance;
  570. }
  571. catch (Exception ex)
  572. {
  573. return intInsurance;
  574. }
  575. }
  576. public static string[] GetAccountingYears(int intAmount) //取得會計年度選單
  577. {
  578. try
  579. {
  580. string[] strYears = new string[intAmount];
  581. DateTime dtNow = DateTime.Now;
  582. for (int intCount = 0; intCount < intAmount; intCount++)
  583. {
  584. strYears[intCount] = (dtNow.Year - intCount).ToString();
  585. }
  586. return strYears;
  587. }
  588. catch (Exception ex)
  589. {
  590. return null;
  591. }
  592. }
  593. public static void CreateDir(string strDirPath) //建立資料夾
  594. {
  595. string[] strDir = strDirPath.Split('\\');
  596. string strCreatePath = "";
  597. foreach (string strPath in strDir)
  598. {
  599. if(strPath != "")
  600. {
  601. strCreatePath += strPath + "\\";
  602. if (!Directory.Exists(strCreatePath))
  603. {
  604. Directory.CreateDirectory(strCreatePath);
  605. }
  606. }
  607. }
  608. }
  609. public static void WriteFile(string strFilePath ,string strContent) //撰寫檔案文字內容
  610. {
  611. using (StreamWriter swFile = new StreamWriter(strFilePath, true))
  612. {
  613. swFile.WriteLine(strContent);
  614. }
  615. }
  616. public static void WriteFile(string strFilePath, string[] strContent) //撰寫檔案文字內容
  617. {
  618. //判斷檔案是否存在
  619. string[] strPathArray = strFilePath.Split('\\');
  620. string strCHKPath = "";
  621. for (int intPath = 0; intPath < strPathArray.Length - 1; intPath ++ )
  622. {
  623. strCHKPath += strPathArray[intPath] + "\\";
  624. }
  625. //檢查資料夾是否存在
  626. if (!File.Exists(strCHKPath))
  627. {
  628. CreateDir(strCHKPath);
  629. }
  630. using (StreamWriter swFile = new StreamWriter(strFilePath, true))
  631. {
  632. foreach(string strContentText in strContent)
  633. {
  634. swFile.WriteLine(strContentText);
  635. }
  636. }
  637. }
  638. public static void SetGridColor(DataGridView dgvGrid) //處理欄位間隔顏色的改變
  639. {
  640. foreach (DataGridViewRow drColor in dgvGrid.Rows)
  641. {
  642. if (drColor.Index % 2 == 0)
  643. {
  644. drColor.DefaultCellStyle.BackColor = Color.LightGray;
  645. }
  646. else
  647. {
  648. drColor.DefaultCellStyle.BackColor = Color.White;
  649. }
  650. }
  651. }
  652. #endregion
  653. #region 計算財務相關公式
  654. #endregion
  655. }
  656. }