FrmInventory.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. using LYFZ.ComponentLibrary;
  2. using System;
  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 FrmInventory : LYFZ.Software.UI.InventoryManagement.FrmInventory
  13. {
  14. private delegate void UpdateControl();
  15. public string ID;
  16. bool bl = false;
  17. public FrmInventory()
  18. {
  19. this.FormClosed += FrmInventory_FormClosed;
  20. }
  21. void FrmInventory_FormClosed(object sender, FormClosedEventArgs e)
  22. {
  23. if (bl)
  24. {
  25. this.DialogResult = DialogResult.OK;
  26. }
  27. }
  28. #region 加载
  29. protected override void FrmInventory_Shown(object sender, EventArgs e)
  30. {
  31. try
  32. {
  33. if (!string.IsNullOrEmpty(ID))
  34. {
  35. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
  36. {
  37. string[] Id = ID.Split(',');
  38. for (int i = 0; i < Id.Length; i++)
  39. {
  40. #region 获取商品
  41. LYFZ.BLL.BLL_ErpProduct Productbll = new BLL.BLL_ErpProduct();
  42. DataTable dt = Productbll.GetList("Id='" + Id[i] + "'").Tables[0];
  43. if (dt.Rows.Count > 0)
  44. {
  45. this.Invoke(new UpdateControl(delegate()
  46. {
  47. for (int t = 0; t < dt.Rows.Count; t++)
  48. {
  49. DataGridViewRow dgvr = new DataGridViewRow();
  50. DataGridViewCell cell = null;
  51. cell = new DataGridViewTextBoxCell();
  52. cell.Value = dt.Rows[t]["ID"].ToString().Trim();
  53. dgvr.Cells.Add(cell);
  54. cell = new DataGridViewTextBoxCell();
  55. cell.Value = dt.Rows[t]["Prod_Name"].ToString().Trim();
  56. dgvr.Cells.Add(cell);
  57. cell = new DataGridViewTextBoxCell();
  58. cell.Value = dt.Rows[t]["Prod_Quantity"].ToString().Trim();
  59. dgvr.Cells.Add(cell);
  60. cell = new DataGridViewTextBoxCell();
  61. cell.Value = dt.Rows[t]["Prod_ClassName"].ToString().Trim();
  62. dgvr.Cells.Add(cell);
  63. this.dgv1.Rows.Add(dgvr);
  64. dgv1.ClearSelection();
  65. }
  66. }));
  67. }
  68. #endregion
  69. }
  70. });
  71. }
  72. lblcount.Text = dgv1.Rows.Count.ToString();
  73. }
  74. catch (Exception ex)
  75. {
  76. MessageBoxCustom.Show(ex.Message);
  77. }
  78. }
  79. #endregion
  80. #region 保存
  81. protected override void btnSave_Click(object sender, EventArgs e)
  82. {
  83. try
  84. {
  85. #region 修改商品库存
  86. if (dgv1.Rows.Count > 0)
  87. {
  88. for (int i = 0; i < dgv1.Rows.Count; i++)
  89. {
  90. int Id = Convert.ToInt32(dgv1.Rows[i].Cells["ID"].Value);
  91. int Prod_Quantity = Convert.ToInt32(dgv1.Rows[i].Cells["Prod_Quantity"].Value);
  92. LYFZ.BLL.BLL_ErpProduct ProductBll = new BLL.BLL_ErpProduct();
  93. LYFZ.Model.Model_ErpProduct ProductModel = ProductBll.GetModel(Id);
  94. ProductModel.Prod_Quantity = Prod_Quantity;
  95. ProductModel.Prod_UpdateDateTime = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetServerDateTime();
  96. ProductModel.Prod_UpdateName = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_Name;
  97. ProductBll.Update(ProductModel);
  98. }
  99. bl = true;
  100. MessageBoxCustom.Show("保存成功!");
  101. }
  102. #endregion
  103. }
  104. catch (Exception ex)
  105. {
  106. MessageBoxCustom.Show(ex.Message);
  107. }
  108. }
  109. #endregion
  110. #region 只能输入数字
  111. protected override void dgv1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  112. {
  113. try
  114. {
  115. if (dgv1.Rows.Count > 0)
  116. {
  117. if (dgv1.CurrentRow.Cells["Prod_Quantity"].Value == null)
  118. {
  119. MessageBoxCustom.Show("库存数量不能为空!");
  120. int id = Convert.ToInt32(dgv1.CurrentRow.Cells["ID"].Value);
  121. LYFZ.BLL.BLL_ErpProduct bll = new BLL.BLL_ErpProduct();
  122. dgv1.CurrentRow.Cells["Prod_Quantity"].Value = bll.GetList("ID=" + id + "").Tables[0].Rows[0]["Prod_Quantity"].ToString();
  123. return;
  124. }
  125. if (Command.Command_Validate.IsNumber(dgv1.CurrentRow.Cells["Prod_Quantity"].Value.ToString()) == false)
  126. {
  127. MessageBoxCustom.Show("只能输入纯数字!");
  128. int id = Convert.ToInt32(dgv1.CurrentRow.Cells["ID"].Value);
  129. LYFZ.BLL.BLL_ErpProduct bll = new BLL.BLL_ErpProduct();
  130. dgv1.CurrentRow.Cells["Prod_Quantity"].Value = bll.GetList("ID=" + id + "").Tables[0].Rows[0]["Prod_Quantity"].ToString();
  131. return;
  132. }
  133. }
  134. }
  135. catch (Exception ex)
  136. {
  137. MessageBoxCustom.Show(ex.Message);
  138. }
  139. }
  140. #endregion
  141. #region 关闭
  142. protected override void btnClose_Click(object sender, EventArgs e)
  143. {
  144. this.Close();
  145. }
  146. #endregion
  147. }
  148. }