FrmProductSearch.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. namespace LYFZ.Software.MainBusiness.InventoryManagement
  11. {
  12. public partial class FrmProductSearch : LYFZ.Software.UI.InventoryManagement.FrmProductSearch
  13. {
  14. public FrmProductSearch()
  15. {
  16. }
  17. public ArrayList ListArray = new ArrayList();
  18. #region 获取数据
  19. protected override void FrmProductSearch_Shown(object sender, EventArgs e)
  20. {
  21. try
  22. {
  23. CtvProd_Class.TreeView.Nodes.Clear();
  24. #region 绑定二级商品类别
  25. LYFZ.BLL.BLL_ErpSystemCategory BLLSystemCategory = new BLL.BLL_ErpSystemCategory();
  26. DataTable tbl = BLLSystemCategory.GetList("Sc_ClassParentID='1'").Tables[0];
  27. if (tbl.Rows.Count > 0)
  28. {
  29. TreeNode root = null;
  30. for (int i = 0; i < tbl.Rows.Count; i++)
  31. {
  32. root = new TreeNode(tbl.Rows[i]["Sc_ClassName"].ToString());
  33. root.Tag = tbl.Rows[i]["Sc_ClassCode"].ToString();
  34. this.CreateTreeViewShop(root.Nodes, tbl.Rows[i]["ID"].ToString());
  35. this.CtvProd_Class.TreeView.Nodes.Add(root);
  36. }
  37. }
  38. #endregion
  39. }
  40. catch (Exception ex) { MessageBoxCustom.Show(ex.Message); }
  41. }
  42. #region 绑定三级商品类别
  43. #region 绑定第三级商品类别
  44. /// <summary>
  45. /// 绑定第三级商品类别
  46. /// </summary>
  47. /// <param name="nodes">TreeView的节点集合</param>
  48. /// <param name="dataSource">数据源</param>
  49. /// <param name="parentid"></param>
  50. private void CreateTreeViewShop(TreeNodeCollection nodes, string ClassCode)
  51. {
  52. if (ClassCode != "")
  53. {
  54. LYFZ.BLL.BLL_ErpSystemCategory BLLSystemCategory = new BLL.BLL_ErpSystemCategory();
  55. DataTable tbl = BLLSystemCategory.GetList("Sc_ClassParentID=" + ClassCode + "").Tables[0];
  56. if (tbl.Rows.Count > 0)
  57. {
  58. TreeNode node;
  59. for (int i = 0; i < tbl.Rows.Count; i++)
  60. {
  61. node = new TreeNode();
  62. node.Text = tbl.Rows[i]["Sc_ClassName"].ToString();
  63. node.Tag = tbl.Rows[i]["Sc_ClassCode"].ToString();
  64. nodes.Add(node);
  65. }
  66. }
  67. }
  68. }
  69. #endregion
  70. #endregion
  71. #endregion
  72. #region 选择商品类别 获取商品
  73. protected override void CtvProd_Class_ComboBoxTreeViewEx_TextChanged(object sender, TreeViewEventArgs e)
  74. {
  75. try
  76. {
  77. if (CtvProd_Class.Tag != null)
  78. {
  79. //获取商品表
  80. LYFZ.BLL.BLL_ErpProduct Productbll = new BLL.BLL_ErpProduct();
  81. DataTable dt = Productbll.View_tb_ErpProduct("tb_ErpSystemCategory.Sc_ClassCode='" + CtvProd_Class.Tag.ToString() + "' and Prod_IsEnabled='1' and Prod_Quantity>Prod_AlarmQuantity ").Tables[0];
  82. this.dgv.AutoGenerateColumns = false;
  83. this.dgv.DataSource = dt;
  84. this.dgv.ClearSelection();
  85. }
  86. }
  87. catch (Exception ex) { MessageBoxCustom.Show(ex.Message); }
  88. }
  89. #endregion
  90. #region 查询
  91. protected override void btnSlect_Click(object sender, EventArgs e)
  92. {
  93. LYFZ.BLL.BLL_ErpProduct Productbll = new BLL.BLL_ErpProduct();
  94. DataTable dt = new DataTable();
  95. if (CtvProd_Class.Tag != null)
  96. {
  97. dt = Productbll.View_tb_ErpProduct("tb_ErpSystemCategory.Sc_ClassCode='" + CtvProd_Class.Tag.ToString() + "' and tb_ErpProduct.Prod_Name like '%" + txtProd_Name.Text + "%' and Prod_IsEnabled='1' and Prod_Quantity>Prod_AlarmQuantity ").Tables[0];
  98. }
  99. this.dgv.AutoGenerateColumns = false;
  100. this.dgv.DataSource = dt;
  101. this.dgv.ClearSelection();
  102. }
  103. #endregion
  104. #region 双击事件增加商品
  105. protected override void dgv_DoubleClick(object sender, EventArgs e)
  106. {
  107. try
  108. {
  109. SelectAll(lstGoods);
  110. string Goods = "";
  111. for (int i = 0; i < lstGoods.Items.Count; i++)
  112. {
  113. Goods += lstGoods.SelectedItems[i].ToString() + ",";
  114. }
  115. string Prod_Name = dgv.CurrentRow.Cells["Prod_Name"].Value.ToString();
  116. string Prod_Number = dgv.CurrentRow.Cells["Prod_Number"].Value.ToString();
  117. string sp = "(" + Prod_Number + ")" + Prod_Name;
  118. // string jq = sp.Substring(sp.LastIndexOf(")") + 1);
  119. if (Goods.Contains(sp))
  120. {
  121. MessageBoxCustom.Show("此商品已在列表中!不能添加!");
  122. SelectAll(lstGoods);
  123. return;
  124. }
  125. this.lstGoods.Items.Add(sp);
  126. SelectAll(lstGoods);
  127. }
  128. catch (Exception ex) { MessageBoxCustom.Show(ex.Message); }
  129. }
  130. #endregion
  131. #region <<按钮增加商品
  132. protected override void btnRight_Click(object sender, EventArgs e)
  133. {
  134. try
  135. {
  136. SelectAll(lstGoods);
  137. string Goods = "";
  138. for (int i = 0; i < lstGoods.Items.Count; i++)
  139. {
  140. Goods += lstGoods.SelectedItems[i].ToString() + ",";
  141. }
  142. string Prod_Name = dgv.CurrentRow.Cells["Prod_Name"].Value.ToString();
  143. string Prod_Number = dgv.CurrentRow.Cells["Prod_Number"].Value.ToString();
  144. string sp = "(" + Prod_Number + ")" + Prod_Name;
  145. // string jq = sp.Substring(sp.LastIndexOf(")") + 1);
  146. if (Goods.Contains(sp))
  147. {
  148. MessageBoxCustom.Show("此商品已在列表中!不能添加!");
  149. SelectAll(lstGoods);
  150. return;
  151. }
  152. this.lstGoods.Items.Add(sp);
  153. SelectAll(lstGoods);
  154. }
  155. catch (Exception ex) { MessageBoxCustom.Show(ex.Message); }
  156. }
  157. #endregion
  158. #region 移除商品
  159. protected override void btnLeft_Click(object sender, EventArgs e)
  160. {
  161. try
  162. {
  163. if (lstGoods.Items.Count > 0)
  164. {
  165. lstGoods.Items.Remove(lstGoods.SelectedItem);
  166. }
  167. //Item obj = this.lstGoods.SelectedItem as Item;
  168. //MessageBox.Show("Text:" + obj.strText + " 值:" + obj.strValue);
  169. }
  170. catch (Exception ex) { MessageBoxCustom.Show(ex.Message); }
  171. }
  172. #endregion
  173. #region 确定
  174. protected override void btnSave_Click(object sender, EventArgs e)
  175. {
  176. try
  177. {
  178. FrmPurchaseOrder set = new FrmPurchaseOrder();
  179. if (lstGoods.Items.Count > 0)
  180. {
  181. for (int i = 0; i < lstGoods.Items.Count; i++)
  182. {
  183. string start = lstGoods.Items[i].ToString();
  184. string end = start.Substring(1, start.LastIndexOf(")") - 1);
  185. ListArray.Add(end.ToString());
  186. }
  187. }
  188. this.Close();
  189. }
  190. catch (Exception ex) { MessageBoxCustom.Show(ex.Message); }
  191. }
  192. #endregion
  193. #region 全选
  194. private void SelectAll(ListBox ListBox)
  195. {
  196. for (int i = 0; i < ListBox.Items.Count; i++)
  197. {
  198. ListBox.SelectedIndex = i;
  199. }
  200. }
  201. #endregion
  202. }
  203. }