F_PM_0103_1.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. 
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Reflection;
  6. using System.Windows.Forms;
  7. using Dongke.IBOSS.PRD.Client.CommonModule;
  8. using Dongke.WinForm.Controls;
  9. namespace Dongke.IBOSS.PRD.Client.PMModule
  10. {
  11. public partial class F_PM_0103_1 : FormDialog
  12. {
  13. public F_PM_0103_1()
  14. {
  15. InitializeComponent();
  16. }
  17. public DataGridView BarCodeGrid
  18. {
  19. get;
  20. set;
  21. }
  22. public List<string> ERROR_LIST
  23. {
  24. get;
  25. set;
  26. }
  27. private void tsbtnClose_Click(object sender, System.EventArgs e)
  28. {
  29. ERROR_LIST = null;
  30. this.DialogResult = DialogResult.Cancel;
  31. this.Close();
  32. }
  33. private void tsbtnClearCondition_Click(object sender, System.EventArgs e)
  34. {
  35. this.txtBarCodes.Clear();
  36. }
  37. private void tsbtnBindss_Click(object sender, System.EventArgs e)
  38. {
  39. if (this.BarCodeGrid == null ||
  40. string.IsNullOrWhiteSpace(this.txtBarCodes.Text))
  41. {
  42. return;
  43. }
  44. try
  45. {
  46. string[] barcode_lines = this.txtBarCodes.Lines;
  47. string barcode = null;
  48. string goodscode = null;
  49. bool bindFlag = false;
  50. ERROR_LIST = new List<string>();
  51. DataTable dt = this.BarCodeGrid.DataSource as DataTable;
  52. foreach (string item in barcode_lines)
  53. {
  54. if (string.IsNullOrWhiteSpace(item))
  55. {
  56. continue;
  57. }
  58. if (item.Contains("\t"))
  59. {
  60. string[] ss = item.Split('\t');
  61. barcode = ss[0];
  62. goodscode = ss[1];
  63. }
  64. else if (item.Contains("@"))
  65. {
  66. string[] ss = item.Split('@');
  67. barcode = ss[0];
  68. goodscode = ss[1];
  69. }
  70. else
  71. {
  72. barcode = item;
  73. goodscode = null;
  74. }
  75. if (barcode?.Length != 11 || !long.TryParse(barcode, out long logbarcode))
  76. {
  77. ERROR_LIST.Add(item);
  78. continue;
  79. }
  80. if (dt?.Select($"barcode='{barcode}'")?.Length > 0)
  81. {
  82. ERROR_LIST.Add(item);
  83. continue;
  84. }
  85. bindFlag = false;
  86. foreach (DataGridViewRow row in this.BarCodeGrid.Rows)
  87. {
  88. if (row.Cells["BarCode"].ReadOnly)
  89. {
  90. continue;
  91. }
  92. string bc = row.Cells["BarCode"].Value + "";
  93. string sf = row.Cells["ScrapFlag"].Value + "";
  94. string gf = row.Cells["GroutingFlag"].Value + "";
  95. string gc = row.Cells["GoodsCode"].Value + "";
  96. if (!string.IsNullOrWhiteSpace(bc) || gf != "1" || sf != "0")
  97. {
  98. continue;
  99. }
  100. if (!string.IsNullOrWhiteSpace(goodscode) && goodscode != gc)
  101. {
  102. continue;
  103. }
  104. bindFlag = true;
  105. row.Cells["BarCode"].Value = barcode;
  106. (row.DataBoundItem as DataRowView)?.EndEdit();
  107. break;
  108. }
  109. if (!bindFlag)
  110. {
  111. ERROR_LIST.Add(item);
  112. }
  113. }
  114. this.DialogResult = DialogResult.OK;
  115. this.Close();
  116. }
  117. catch (Exception ex)
  118. {
  119. // 对异常进行共通处理
  120. ExceptionManager.HandleEventException(this.ToString(),
  121. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  122. }
  123. }
  124. private void tsbtnClearBarCode_Click(object sender, EventArgs e)
  125. {
  126. if (this.BarCodeGrid == null)
  127. {
  128. return;
  129. }
  130. try
  131. {
  132. //DataTable dd = this.BarCodeGrid.DataSource as DataTable;
  133. foreach (DataGridViewRow row in this.BarCodeGrid.Rows)
  134. {
  135. if (!row.Cells["BarCode"].ReadOnly)
  136. {
  137. row.Cells["BarCode"].Value = DBNull.Value;
  138. (row.DataBoundItem as DataRowView)?.EndEdit();
  139. }
  140. }
  141. }
  142. catch (Exception ex)
  143. {
  144. // 对异常进行共通处理
  145. ExceptionManager.HandleEventException(this.ToString(),
  146. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  147. }
  148. }
  149. }
  150. }