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.

172 lines
5.5 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 PickCustomer : Form
  16. {
  17. //程式內共用物件
  18. public string strFrmStatus = ""; //表單狀態
  19. public string strPKey = ""; //程式內的Key值
  20. public string strOwnerForm = ""; //設定表單的擁有者
  21. SqlConnection sqlConn = UtilityClass.GetConn(MainForm.strAccountingBookID);
  22. SqlCommand sqlCmd = new SqlCommand();
  23. DataSet sdInsurance = new System.Data.DataSet();
  24. public PickCustomer()
  25. {
  26. InitializeComponent();
  27. }
  28. #region 自定義程式
  29. private void SearchEvent(string strTaxNumber, string strCusName)
  30. {
  31. try
  32. {
  33. StringBuilder strSQL = new StringBuilder("");
  34. strSQL.Append("Select CustomerID, CustomerName, TaxNumber ");
  35. strSQL.Append("From OTB_CRM_Customers ");
  36. strSQL.Append("Where 1 = 1 ");
  37. if (strTaxNumber != "") //統一編號
  38. {
  39. strSQL.Append("And TaxNumber like '" + strTaxNumber + "' ");
  40. }
  41. if (strCusName != "") //客戶名稱
  42. {
  43. strSQL.Append("And CustomerName like '" + strCusName + "' ");
  44. }
  45. //進行查詢
  46. dgvDataMaintain.DataSource = UtilityClass.GetSQLResult(strSQL.ToString()).Tables[0];
  47. }
  48. catch (Exception ex)
  49. {
  50. ErrorHandler.WriteErrorLog("PickCustomer.cs", ex);
  51. }
  52. }
  53. private void CleanForm()
  54. {
  55. txtTaxNumber.Text = "";
  56. txtCustomerName.Text = "";
  57. }
  58. private void PickItem()
  59. {
  60. try
  61. {
  62. //取得資料
  63. string strReturnItem = "";
  64. string strCustomerID = "";
  65. foreach (DataGridViewRow dgvRow in dgvDataMaintain.SelectedRows)
  66. {
  67. strCustomerID = (string)dgvRow.Cells["cCustomerID"].Value;
  68. if (!string.IsNullOrEmpty(strCustomerID))
  69. {
  70. strReturnItem = strCustomerID + "|" + dgvRow.Cells["cCustomerName"].Value.ToString();
  71. }
  72. }
  73. switch (strOwnerForm) //回傳資料
  74. {
  75. case "PayPlanManagement":
  76. PayPlanManagement frmParent = (PayPlanManagement)this.Owner;
  77. frmParent.ReturnCustomer(strReturnItem.Split('|'));
  78. break;
  79. case "CashFlowForecastEdit":
  80. CashFlowForecastEdit frmParent1 = (CashFlowForecastEdit)this.Owner;
  81. frmParent1.ReturnCustomer(strReturnItem.Split('|'));
  82. break;
  83. }
  84. this.Close();
  85. }
  86. catch (Exception ex)
  87. {
  88. ErrorHandler.WriteErrorLog("PickCustomer.cs", ex);
  89. }
  90. }
  91. #endregion
  92. #region 事件觸發及問題處理
  93. private void btnClose_Click(object sender, EventArgs e)
  94. {
  95. this.Close();
  96. }
  97. private void btnClean_Click(object sender, EventArgs e)
  98. {
  99. CleanForm();
  100. string strTaxNumber = txtTaxNumber.Text.Trim();
  101. string strCusName = txtCustomerName.Text.Trim();
  102. SearchEvent(strTaxNumber, strCusName);
  103. }
  104. private void btnSearch_Click(object sender, EventArgs e)
  105. {
  106. string strTaxNumber = txtTaxNumber.Text.Trim();
  107. string strCusName = txtCustomerName.Text.Trim();
  108. SearchEvent(strTaxNumber, strCusName);
  109. }
  110. private void PickCustomer_Load(object sender, EventArgs e)
  111. {
  112. string strTaxNumber = txtTaxNumber.Text.Trim();
  113. string strCusName = txtCustomerName.Text.Trim();
  114. SearchEvent(strTaxNumber, strCusName);
  115. }
  116. private void txtTaxNumber_TextChanged(object sender, EventArgs e)
  117. {
  118. string strTaxNumber = txtTaxNumber.Text.Trim();
  119. string strCusName = txtCustomerName.Text.Trim();
  120. strTaxNumber = string.IsNullOrEmpty(strTaxNumber) ? "" : strTaxNumber + "%";
  121. strCusName = string.IsNullOrEmpty(strCusName) ? "" : "%" + strCusName + "%";
  122. SearchEvent(strTaxNumber, strCusName);
  123. }
  124. private void txtCustomerName_TextChanged(object sender, EventArgs e)
  125. {
  126. string strTaxNumber = txtTaxNumber.Text.Trim();
  127. string strCusName = txtCustomerName.Text.Trim();
  128. strTaxNumber = string.IsNullOrEmpty(strTaxNumber) ? "" : strTaxNumber + "%";
  129. strCusName = string.IsNullOrEmpty(strCusName) ? "" : "%" + strCusName + "%";
  130. SearchEvent(strTaxNumber, strCusName);
  131. }
  132. private void btnPick_Click(object sender, EventArgs e)
  133. {
  134. PickItem();
  135. }
  136. private void dgvDataMaintain_DoubleClick(object sender, EventArgs e)
  137. {
  138. PickItem();
  139. }
  140. #endregion
  141. }
  142. }