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.

186 lines
6.1 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Data.Sql;
  11. using System.Data.SqlClient;
  12. using ManagementSystem.Utility;
  13. namespace ManagementSystem
  14. {
  15. public partial class PickAccountingSubject : Form
  16. {
  17. //程式內共用物件
  18. public string strFrmStatus = ""; //表單狀態
  19. public string strPKey = ""; //程式內的Key值
  20. public int intIndex = 0;
  21. public string strOwnerForm = ""; //設定表單的擁有者
  22. public string strAccountingBookID = ""; //取得作用中的帳本
  23. SqlConnection sqlConn = UtilityClass.GetConn(MainForm.strAccountingBookID);
  24. SqlCommand sqlCmd = new SqlCommand();
  25. DataSet sdInsurance = new System.Data.DataSet();
  26. public PickAccountingSubject()
  27. {
  28. InitializeComponent();
  29. }
  30. #region 自定義程式
  31. private void SearchEvent(string strAccID,string strAccName)
  32. {
  33. try
  34. {
  35. StringBuilder strSQL = new StringBuilder("");
  36. strSQL.Append("Select AccountingSubID, AccountingSubName ");
  37. strSQL.Append("From OTB_FNC_AccountingSubjects ");
  38. strSQL.Append("Where AccountingBookID ='" + strAccountingBookID + "' ");
  39. if (strAccID != "") //科目代碼
  40. {
  41. strSQL.Append("And AccountingSubID like '" + strAccID + "' ");
  42. }
  43. if (strAccName != "") //身份證字號
  44. {
  45. strSQL.Append("And AccountingSubName like '" + strAccName + "' ");
  46. }
  47. //進行查詢
  48. dgvDataMaintain.DataSource = UtilityClass.GetSQLResult(strSQL.ToString()).Tables[0];
  49. }
  50. catch (Exception ex)
  51. {
  52. ErrorHandler.WriteErrorLog("PickAccountingSubject.cs", ex);
  53. }
  54. }
  55. private void CleanForm()
  56. {
  57. txtAccountingSubID.Text = "";
  58. txtAccountingSubName.Text = "";
  59. }
  60. private void PickItem()
  61. {
  62. try
  63. {
  64. //取得資料
  65. string strReturnItem = "";
  66. string strAccountingSubID = "";
  67. foreach (DataGridViewRow dgvRow in dgvDataMaintain.SelectedRows)
  68. {
  69. strAccountingSubID = (string)dgvRow.Cells["cAccountingSubID"].Value;
  70. if (!string.IsNullOrEmpty(strAccountingSubID))
  71. {
  72. strReturnItem = intIndex.ToString() + "|" + strAccountingSubID + "|" + dgvRow.Cells["cAccountingSubName"].Value.ToString();
  73. }
  74. }
  75. switch(strOwnerForm)
  76. {
  77. case "AccountingEntries":
  78. //回傳資料
  79. AccountingEntries frmParent = (AccountingEntries)this.Owner;
  80. frmParent.ReturnAccountList(strReturnItem);
  81. break;
  82. case "AccountingLedger":
  83. //回傳資料
  84. AccountingLedger frmParent1 = (AccountingLedger)this.Owner;
  85. frmParent1.ReturnAccountList(strReturnItem);
  86. break;
  87. case "XMLSetting":
  88. //回傳資料
  89. XMLSetting frmParent2 = (XMLSetting)this.Owner;
  90. frmParent2.ReturnAccountList(strReturnItem);
  91. break;
  92. }
  93. this.Close();
  94. }
  95. catch (Exception ex)
  96. {
  97. ErrorHandler.WriteErrorLog("PickAccountingSubject.cs", ex);
  98. }
  99. }
  100. #endregion
  101. #region 事件觸發及問題處理
  102. private void btnClose_Click(object sender, EventArgs e)
  103. {
  104. this.Close();
  105. }
  106. private void btnPick_Click(object sender, EventArgs e)
  107. {
  108. PickItem();
  109. }
  110. private void btnClean_Click(object sender, EventArgs e)
  111. {
  112. CleanForm();
  113. string strAccID = txtAccountingSubID.Text.Trim();
  114. string strAccName = txtAccountingSubName.Text.Trim();
  115. SearchEvent(strAccID, strAccName);
  116. }
  117. private void PickAccountingSubject_Load(object sender, EventArgs e)
  118. {
  119. string strAccID = txtAccountingSubID.Text.Trim();
  120. string strAccName = txtAccountingSubName.Text.Trim();
  121. SearchEvent(strAccID, strAccName);
  122. }
  123. private void btnSearch_Click(object sender, EventArgs e)
  124. {
  125. string strAccID = txtAccountingSubID.Text.Trim();
  126. string strAccName = txtAccountingSubName.Text.Trim();
  127. SearchEvent(strAccID, strAccName);
  128. }
  129. private void dgvDataMaintain_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  130. {
  131. PickItem();
  132. }
  133. private void txtAccountingSubID_TextChanged(object sender, EventArgs e)
  134. {
  135. string strAccID = txtAccountingSubID.Text.Trim();
  136. string strAccName = txtAccountingSubName.Text.Trim();
  137. strAccID = string.IsNullOrEmpty(strAccID) ? "" : strAccID + "%";
  138. strAccName = string.IsNullOrEmpty(strAccName) ? "" : "%" + strAccName + "%";
  139. SearchEvent(strAccID, strAccName);
  140. }
  141. private void txtAccountingSubName_TextChanged(object sender, EventArgs e)
  142. {
  143. string strAccID = txtAccountingSubID.Text.Trim();
  144. string strAccName = txtAccountingSubName.Text.Trim();
  145. strAccID = string.IsNullOrEmpty(strAccID) ? "" : strAccID + "%";
  146. strAccName = string.IsNullOrEmpty(strAccName) ? "" : "%" + strAccName + "%";
  147. SearchEvent(strAccID, strAccName);
  148. }
  149. #endregion
  150. }
  151. }