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.

202 lines
7.2 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 PickProject : Form
  16. {
  17. //程式內共用物件
  18. public string strFrmStatus = ""; //表單狀態
  19. public string strPKey = ""; //程式內的Key值
  20. public string strOwnerForm = ""; //設定表單的擁有者
  21. public int intIndex = 0; //設定被觸發的Grid筆數
  22. SqlConnection sqlConn = UtilityClass.GetConn(MainForm.strAccountingBookID);
  23. SqlCommand sqlCmd = new SqlCommand();
  24. DataSet sdInsurance = new System.Data.DataSet();
  25. public PickProject()
  26. {
  27. InitializeComponent();
  28. }
  29. #region 自定義程式
  30. private void SearchEvent(string strProjectNumber, string strProjectName)
  31. {
  32. try
  33. {
  34. StringBuilder strSQL = new StringBuilder("");
  35. strSQL.Append("Select ProjectNumber, ProjectCName ");
  36. strSQL.Append("From OTB_PRJ_ProjectInfo ");
  37. strSQL.Append("Where 1 = 1 ");
  38. if (strProjectNumber != "") //專案編號
  39. {
  40. strSQL.Append("And ProjectNumber like '" + strProjectNumber + "' ");
  41. }
  42. if (strProjectName != "") //專案名稱
  43. {
  44. strSQL.Append("And ProjectCName like '" + strProjectName + "' ");
  45. }
  46. if (cbClosed.Checked)
  47. {
  48. strSQL.Append("Union ");
  49. strSQL.Append("Select ProjectNumber, ProjectCName ");
  50. strSQL.Append("From OTB_PRJ_ProjectInfo_Closed ");
  51. strSQL.Append("Where 1 = 1 ");
  52. if (strProjectNumber != "") //專案編號
  53. {
  54. strSQL.Append("And ProjectNumber like '" + strProjectNumber + "' ");
  55. }
  56. if (strProjectName != "") //專案名稱
  57. {
  58. strSQL.Append("And ProjectCName like '" + strProjectName + "' ");
  59. }
  60. }
  61. //進行查詢
  62. dgvDataMaintain.DataSource = UtilityClass.GetSQLResult(strSQL.ToString()).Tables[0];
  63. }
  64. catch (Exception ex)
  65. {
  66. ErrorHandler.WriteErrorLog("PickProject.cs", ex);
  67. }
  68. }
  69. private void CleanForm()
  70. {
  71. txtProjectName.Text = "";
  72. txtProjectNumber.Text = "";
  73. cbClosed.Checked = false;
  74. }
  75. private void PickItem() //取得資料
  76. {
  77. try
  78. {
  79. string strReturnItem = "";
  80. string strProjectID = "";
  81. foreach (DataGridViewRow dgvRow in dgvDataMaintain.SelectedRows)
  82. {
  83. strProjectID = (string)dgvRow.Cells["cProjectID"].Value;
  84. if (!string.IsNullOrEmpty(strProjectID))
  85. {
  86. strReturnItem = strProjectID + "|" + dgvRow.Cells["cProjectName"].Value.ToString();
  87. }
  88. }
  89. switch (strOwnerForm)
  90. {
  91. case "AccountingEntries_Header":
  92. AccountingEntries frmParent = (AccountingEntries)this.Owner;
  93. frmParent.ReturnProjectInfo(strReturnItem.Split('|'));
  94. break;
  95. case "AccountingEntries_Detail":
  96. AccountingEntries frmParent1 = (AccountingEntries)this.Owner;
  97. frmParent1.ReturnProjectInfo(intIndex, strReturnItem.Split('|'));
  98. break;
  99. case "ProjectIncomeStatement":
  100. ProjectIncomeStatement frmParent2 = (ProjectIncomeStatement)this.Owner;
  101. frmParent2.ReturnProjectInfo(strReturnItem.Split('|'));
  102. break;
  103. case "CashFlowForecastEdit":
  104. CashFlowForecastEdit frmParent3 = (CashFlowForecastEdit)this.Owner;
  105. frmParent3.ReturnProjectInfo(strReturnItem.Split('|'));
  106. break;
  107. case "HRDataCorrect":
  108. HRDataCorrect frmParent4 = (HRDataCorrect)this.Owner;
  109. frmParent4.ReturnProjectInfo(strReturnItem.Split('|'));
  110. break;
  111. }
  112. this.Close();
  113. }
  114. catch (Exception ex)
  115. {
  116. ErrorHandler.WriteErrorLog("PickProject.cs", ex);
  117. }
  118. }
  119. #endregion
  120. #region 事件觸發及問題處理
  121. private void btnClose_Click(object sender, EventArgs e)
  122. {
  123. this.Close();
  124. }
  125. private void btnClean_Click(object sender, EventArgs e)
  126. {
  127. CleanForm();
  128. string strProjectNumber = txtProjectNumber.Text.Trim();
  129. string strProjectName = txtProjectName.Text.Trim();
  130. SearchEvent(strProjectNumber, strProjectName);
  131. }
  132. private void btnSearch_Click(object sender, EventArgs e)
  133. {
  134. string strProjectNumber = txtProjectNumber.Text.Trim();
  135. string strProjectName = txtProjectName.Text.Trim();
  136. SearchEvent(strProjectNumber, strProjectName);
  137. }
  138. private void txtProjectNumber_TextChanged(object sender, EventArgs e)
  139. {
  140. string strProjuectNumber = txtProjectNumber.Text.Trim();
  141. string strProjectName = txtProjectName.Text.Trim();
  142. strProjuectNumber = string.IsNullOrEmpty(strProjuectNumber) ? "" : strProjuectNumber + "%";
  143. strProjectName = string.IsNullOrEmpty(strProjectName) ? "" : "%" + strProjectName + "%";
  144. SearchEvent(strProjuectNumber, strProjectName);
  145. }
  146. private void txtProjectName_TextChanged(object sender, EventArgs e)
  147. {
  148. string strProjuectNumber = txtProjectNumber.Text.Trim();
  149. string strProjectName = txtProjectName.Text.Trim();
  150. strProjuectNumber = string.IsNullOrEmpty(strProjuectNumber) ? "" : strProjuectNumber + "%";
  151. strProjectName = string.IsNullOrEmpty(strProjectName) ? "" : "%" + strProjectName + "%";
  152. SearchEvent(strProjuectNumber, strProjectName);
  153. }
  154. private void btnPick_Click(object sender, EventArgs e)
  155. {
  156. PickItem();
  157. }
  158. private void dgvDataMaintain_DoubleClick(object sender, EventArgs e)
  159. {
  160. PickItem();
  161. }
  162. private void PickProject_Load(object sender, EventArgs e)
  163. {
  164. SearchEvent("", "");
  165. }
  166. private void cbClosed_CheckedChanged(object sender, EventArgs e)
  167. {
  168. string strProjectNumber = txtProjectNumber.Text.Trim();
  169. string strProjectName = txtProjectName.Text.Trim();
  170. SearchEvent(strProjectNumber, strProjectName);
  171. }
  172. #endregion
  173. }
  174. }