InventoryRequisitionUpdateSmallForm.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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.Windows.Forms;
  9. namespace LYFZ.Software.MainBusiness.InventoryManagement.SetSmallForm
  10. {
  11. public partial class InventoryRequisitionUpdateSmallForm : LYFZ.Software.UI.InventoryManagement.SetSmallForm.InventoryRequisitionUpdateSmallForm
  12. {
  13. LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder();
  14. LYFZ.BLL.BLL_ErpPurchaseProduct pptbll = new BLL.BLL_ErpPurchaseProduct();
  15. public InventoryRequisitionUpdateSmallForm()
  16. {
  17. this.Load += InventoryRequisitionUpdateSmallForm_Load;
  18. this.Shown += InventoryRequisitionUpdateSmallForm_Shown;
  19. this.btnDelete.Click += btnDelete_Click;
  20. this.btnPrint.Click += btnPrint_Click;
  21. this.btnSaveed.Click += btnSaveed_Click;
  22. this.btnClose.Click += btnClose_Click;
  23. this.listViewData.MouseDoubleClick += listViewData_MouseDoubleClick;
  24. this.txtText.Leave += txtText_Leave;
  25. this.txtText.KeyPress += txtText_KeyPress;
  26. }
  27. /// <summary>
  28. /// 是否保存
  29. /// </summary>
  30. public bool IsSaveed = false;
  31. /// <summary>
  32. /// 订单号
  33. /// </summary>
  34. public string StrOrderNumber = "";
  35. /// <summary>
  36. /// 相片集合
  37. /// </summary>
  38. ImageList mlistImage = new ImageList();
  39. /// <summary>
  40. /// 窗体加载事件
  41. /// </summary>
  42. /// <param name="sender"></param>
  43. /// <param name="e"></param>
  44. void InventoryRequisitionUpdateSmallForm_Load(object sender, EventArgs e)
  45. {
  46. this.listViewData.View = View.Details;
  47. this.listViewData.GridLines = true;
  48. string[] StrColumns = "商品名称,采购数量,采购状态".Split(',');
  49. for (int i = 0; i < StrColumns.Length; i++)
  50. {
  51. ColumnHeader ch = new ColumnHeader();
  52. ch.Text = StrColumns[i].Trim();
  53. if (i == 0)
  54. { ch.Width = (this.listViewData.Width - 23) - 200 * 2; }
  55. else
  56. { ch.Width = 200; }
  57. switch (StrColumns[i].Trim())
  58. {
  59. case "采购数量":
  60. case "采购状态":
  61. ch.TextAlign = HorizontalAlignment.Center;
  62. break;
  63. default:
  64. ch.TextAlign = HorizontalAlignment.Left;
  65. break;
  66. }
  67. this.listViewData.Columns.Add(ch);
  68. }
  69. this.mlistImage.ImageSize = new Size(30, 30);
  70. this.mlistImage.ColorDepth = ColorDepth.Depth32Bit;
  71. this.listViewData.SmallImageList = mlistImage;
  72. this.listViewData.ShowGroups = true;
  73. }
  74. /// <summary>
  75. /// 窗体加载事件
  76. /// </summary>
  77. /// <param name="sender"></param>
  78. /// <param name="e"></param>
  79. void InventoryRequisitionUpdateSmallForm_Shown(object sender, EventArgs e)
  80. {
  81. this.txtProcurementOrderNumber.Text = this.StrOrderNumber;
  82. this.PublicFunctionRows();
  83. }
  84. /// <summary>
  85. /// 删除
  86. /// </summary>
  87. /// <param name="sender"></param>
  88. /// <param name="e"></param>
  89. void btnDelete_Click(object sender, EventArgs e)
  90. {
  91. if (this.listViewData.Items.Count > 0 && this.listViewData.SelectedItems.Count > 0)
  92. {
  93. LYFZ.Model.Model_ErpPurchaseProduct model = pptbll.GetModel(Convert.ToInt32(this.listViewData.SelectedItems[0].Tag));
  94. if (model.Ppt_PurchaseStatus.Trim() != "3")
  95. { MessageBoxCustom.Show("商品‘" + this.listViewData.SelectedItems[0].Text.Trim() + "’已经" + Enum.GetName(typeof(LYFZ.EnumPublic.Ppt_PurchaseStatus), Convert.ToInt32(model.Ppt_PurchaseStatus)) + "不能删除!"); return; }
  96. if (MessageBoxCustom.Show("您确定要删除吗?", "温馨提示", MessageBoxButtons.YesNo) == DialogResult.No)
  97. { return; }
  98. if (pptbll.Delete(model))
  99. {
  100. MessageBoxCustom.Show("删除成功!");
  101. this.listViewData.Items.Remove(this.listViewData.SelectedItems[0]);
  102. LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.ListViewDrawSingleOrDoubleRows(this.listViewData);
  103. }
  104. else
  105. { MessageBoxCustom.Show("删除失败!"); }
  106. }
  107. }
  108. /// <summary>
  109. /// 打印
  110. /// </summary>
  111. /// <param name="sender"></param>
  112. /// <param name="e"></param>
  113. void btnPrint_Click(object sender, EventArgs e)
  114. {
  115. if (this.listViewData.Items.Count <= 0)
  116. {
  117. MessageBoxCustom.Show("无打印数据!");
  118. return;
  119. }
  120. LYFZ.Software.MainBusiness.ReportPrint.ReportFixedFormat.PrintFixedFormat(LYFZ.EnumPublic.PrintTypeEnum.库存采购申请单, this.StrOrderNumber);
  121. }
  122. /// <summary>
  123. /// 保存
  124. /// </summary>
  125. /// <param name="sender"></param>
  126. /// <param name="e"></param>
  127. void btnSaveed_Click(object sender, EventArgs e)
  128. {
  129. if (this.listViewData.Items.Count > 0 && this.listViewData.SelectedItems.Count > 0)
  130. {
  131. List<Helper.CommandInfo> clist = new List<Helper.CommandInfo>();
  132. for (int i = 0; i < this.listViewData.Items.Count; i++)
  133. {
  134. if (this.listViewData.Items[i].SubItems["采购数量"].Tag != null)
  135. {
  136. LYFZ.Model.Model_ErpPurchaseProduct model = pptbll.GetModel(Convert.ToInt32(this.listViewData.Items[i].Tag));
  137. model.Ppt_PurchaseQuantity = Convert.ToInt32(this.listViewData.Items[i].SubItems["采购数量"].Text.Trim());
  138. clist.Add(pptbll.GetUpdateCommandInfo(model));
  139. }
  140. }
  141. if (clist.Count > 0)
  142. {
  143. if (MessageBoxCustom.Show("您确定要保存修改的数据吗?", "温馨提示", MessageBoxButtons.YesNo) == DialogResult.No)
  144. { return; }
  145. if (LYFZ.BLL.BaseBllOperate.ExecuteSqlTran(clist) > 0)
  146. { MessageBoxCustom.Show("保存成功!"); }
  147. else
  148. { MessageBoxCustom.Show("保存失败!"); }
  149. }
  150. else
  151. { MessageBoxCustom.Show("没做任何修改无须保存"); }
  152. }
  153. }
  154. /// <summary>
  155. /// 关闭
  156. /// </summary>
  157. /// <param name="sender"></param>
  158. /// <param name="e"></param>
  159. void btnClose_Click(object sender, EventArgs e)
  160. {
  161. this.Close();
  162. }
  163. /// <summary>
  164. /// 列表双击事件
  165. /// </summary>
  166. /// <param name="sender"></param>
  167. /// <param name="e"></param>
  168. void listViewData_MouseDoubleClick(object sender, MouseEventArgs e)
  169. {
  170. this.txtText.Visible = false;
  171. ListViewHitTestInfo info = this.listViewData.HitTest(e.X, e.Y);
  172. if (!string.IsNullOrEmpty(info.SubItem.Name.Trim()))
  173. {
  174. if (this.listViewData.SelectedItems[0].SubItems["采购状态"].Text.Trim() == "申请中")
  175. {
  176. Rectangle rect = info.SubItem.Bounds;
  177. switch (info.SubItem.Name.Trim())
  178. {
  179. case "采购数量":
  180. this.txtText.Location = new Point(rect.Location.X + this.listViewData.Location.X + 3, rect.Location.Y + this.listViewData.Location.Y + 2);
  181. this.txtText.Size = rect.Size;
  182. this.txtText.Visible = true;
  183. this.txtText.Tag = info.SubItem.Name.Trim();
  184. this.txtText.Text = info.SubItem.Text.Trim();
  185. this.txtText.Focus();
  186. break;
  187. }
  188. }
  189. }
  190. else
  191. {
  192. DataTable dt = orbll.GetView_Custom("tb_ErpProduct", StrWhere: "Prod_Number = '" + this.listViewData.SelectedItems[0].Tag.ToString().Trim() + "'", ShowColumnName: "Prod_Thumbnail").Tables[0];
  193. if (dt.Rows.Count > 0)
  194. {
  195. if (!string.IsNullOrEmpty(dt.Rows[0]["Prod_Thumbnail"].ToString().Trim()))
  196. {
  197. LYFZ.Software.MainBusiness.InitialSet.Product.FrmProductPic frm = new InitialSet.Product.FrmProductPic();
  198. frm.FrmImage = LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetImage(LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.StringToByte(dt.Rows[0]["Prod_Thumbnail"].ToString()));
  199. frm.ShowDialog();
  200. }
  201. else
  202. { MessageBoxCustom.Show("产品未上传相片!"); return; }
  203. }
  204. }
  205. }
  206. /// <summary>
  207. /// 文本框离开事件
  208. /// </summary>
  209. /// <param name="sender"></param>
  210. /// <param name="e"></param>
  211. void txtText_Leave(object sender, EventArgs e)
  212. {
  213. try
  214. {
  215. if (this.txtText.Tag != null)
  216. {
  217. string StrText = "0";
  218. switch (this.txtText.Tag.ToString().Trim())
  219. {
  220. case "采购数量":
  221. if (!string.IsNullOrEmpty(this.txtText.Text.Trim()))
  222. {
  223. if (LYFZ.Command.Command_Validate.IsNumberSign(this.txtText.Text.Trim()))
  224. { StrText = this.txtText.Text.Trim(); }
  225. }
  226. this.listViewData.SelectedItems[0].SubItems[this.txtText.Tag.ToString().Trim()].Text = StrText;
  227. this.listViewData.SelectedItems[0].SubItems[this.txtText.Tag.ToString().Trim()].Tag = "1";
  228. break;
  229. }
  230. }
  231. }
  232. catch
  233. { }
  234. this.txtText.Visible = false;
  235. }
  236. /// <summary>
  237. /// 文本框限制输入
  238. /// </summary>
  239. /// <param name="sender"></param>
  240. /// <param name="e"></param>
  241. void txtText_KeyPress(object sender, KeyPressEventArgs e)
  242. {
  243. if (!Char.IsNumber(e.KeyChar) && !Char.IsControl(e.KeyChar))
  244. { e.Handled = true; }
  245. }
  246. /// <summary>
  247. /// 创建行
  248. /// </summary>
  249. void PublicFunctionRows()
  250. {
  251. string StrColumnName = "tb_ErpPurchaseProduct.ID,Prod_Class,Sc_ClassName,Prod_Number,Prod_Name,Ppt_PurchaseQuantity,Ppt_PurchaseStatus,Prod_Thumbnail";
  252. string StrTableName = "tb_ErpPurchaseProduct Left Join tb_ErpProduct on Prod_Number = Ppt_ProductNumber Left Join tb_ErpSystemCategory on Sc_ClassCode = Ppt_ProductCategory";
  253. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
  254. {
  255. DataTable dt = orbll.GetView_Custom(StrTableName, StrWhere: "Ppt_PurchaseNumber = '" + this.StrOrderNumber + "'", ShowColumnName: StrColumnName).Tables[0];
  256. this.Invoke(new LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.UpdateControl(delegate()
  257. {
  258. for (int i = 0; i < dt.Rows.Count; i++)
  259. {
  260. if (!this.mlistImage.Images.Keys.Contains(dt.Rows[i]["Prod_Number"].ToString().Trim()))
  261. {
  262. Image img = LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetProductImage(dt.Rows[i]["Prod_Thumbnail"].ToString().Trim());
  263. this.mlistImage.Images.Add(dt.Rows[i]["Prod_Number"].ToString().Trim(), img);
  264. }
  265. ListViewItem lvItem = new ListViewItem();
  266. lvItem.Tag = dt.Rows[i]["ID"].ToString().Trim();
  267. lvItem.ImageKey = dt.Rows[i]["Prod_Number"].ToString().Trim();
  268. lvItem.Text = dt.Rows[i]["Prod_Name"].ToString().Trim();
  269. ListViewItem.ListViewSubItem ListSubItem = new ListViewItem.ListViewSubItem();
  270. ListSubItem.Name = "采购数量";
  271. ListSubItem.Text = dt.Rows[i]["Ppt_PurchaseQuantity"].ToString().Trim();
  272. lvItem.SubItems.Add(ListSubItem);
  273. ListSubItem = new ListViewItem.ListViewSubItem();
  274. ListSubItem.Name = "采购状态";
  275. ListSubItem.Text = Enum.GetName(typeof(LYFZ.EnumPublic.Ppt_PurchaseStatus), Convert.ToInt32(dt.Rows[i]["Ppt_PurchaseStatus"]));
  276. lvItem.SubItems.Add(ListSubItem);
  277. if (this.listViewData.Groups[dt.Rows[i]["Prod_Class"].ToString().Trim()] == null)
  278. {
  279. ListViewGroup man_lvg = new ListViewGroup();
  280. man_lvg.Name = dt.Rows[i]["Prod_Class"].ToString().Trim();
  281. man_lvg.Header = dt.Rows[i]["Sc_ClassName"].ToString().Trim();
  282. man_lvg.HeaderAlignment = HorizontalAlignment.Left;
  283. this.listViewData.Groups.Add(man_lvg);
  284. }
  285. if (this.listViewData.Groups.Count > 0)
  286. { this.listViewData.Groups[dt.Rows[i]["Prod_Class"].ToString().Trim()].Items.Add(lvItem); }
  287. this.listViewData.Items.Add(lvItem);
  288. }
  289. }));
  290. });
  291. LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.ListViewDrawSingleOrDoubleRows(this.listViewData);
  292. }
  293. }
  294. }