FrmStock.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  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 FrmStock : LYFZ.Software.UI.InventoryManagement.FrmStock
  13. {
  14. private delegate void UpdateControl();
  15. public FrmStock()
  16. {
  17. this.ucPagerEx1.EventPaging += ucPagerEx1_EventPaging;
  18. this.dgv1.CellMouseDown += dgv1_CellMouseDown;
  19. this.dgv1.DataGridViewConMenu_ItemClicked += dgv1_DataGridViewConMenu_ItemClicked;
  20. this.dgv1.MouseDoubleClick += dgv1_MouseDoubleClick;
  21. }
  22. /// <summary>
  23. /// 窗体加载事件
  24. /// </summary>
  25. /// <param name="sender"></param>
  26. /// <param name="e"></param>
  27. protected override void FrmStock_Shown(object sender, EventArgs e)
  28. {
  29. bind();
  30. SelectGoods();
  31. btnSave.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.StockCompetence, CustomAttributes.OperatingAuthority.Add);
  32. btndelete.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.StockCompetence, CustomAttributes.OperatingAuthority.Delete);
  33. btnInventory.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.StockCompetence, CustomAttributes.OperatingAuthority.InstockInventory);
  34. btnProcurementApplication.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.StockCompetence, CustomAttributes.OperatingAuthority.ProcurementApplication);
  35. }
  36. /// <summary>
  37. /// 盘点
  38. /// </summary>
  39. /// <param name="sender"></param>
  40. /// <param name="e"></param>
  41. protected override void btnInventory_Click(object sender, EventArgs e)
  42. {
  43. if (dgv1.SelectedRows.Count == 0)
  44. {
  45. MessageBoxCustom.Show("你选择你要盘点的商品,可多选!");
  46. return;
  47. }
  48. string Id = null;
  49. for (int i = 0; i < dgv1.SelectedRows.Count; i++)
  50. {
  51. int id = Convert.ToInt32(dgv1.SelectedRows[i].Cells["ID"].Value);
  52. Id += id + ",";
  53. }
  54. LYFZ.Software.MainBusiness.InventoryManagement.FrmInventory set = new FrmInventory();
  55. set.ID = Id;
  56. if (set.ShowDialog() == DialogResult.OK)
  57. {
  58. dgv1.Rows.Clear();
  59. bind();
  60. }
  61. }
  62. /// <summary>
  63. /// 报警商品
  64. /// </summary>
  65. /// <param name="sender"></param>
  66. /// <param name="e"></param>
  67. protected override void btnPurchaseOrder_Click(object sender, EventArgs e)
  68. {
  69. DataTable dt = PurchaseProductbll.View_tb_ErpProduct(" and Prod_Quantity<=Prod_AlarmQuantity and Prod_Availability=1").Tables[0];
  70. if (dt.Rows.Count > 0)
  71. {
  72. for (int i = 0; i < dt.Rows.Count; i++)
  73. {
  74. if (dgv2.Rows.Count > 0)
  75. {
  76. for (int t = 0; t < dgv2.Rows.Count; t++)
  77. {
  78. if (dt.Rows[i]["Prod_Number"].ToString().Trim() == dgv2.Rows[t].Cells["Prod_Number"].Value.ToString())
  79. {
  80. MessageBoxCustom.Show(dt.Rows[i]["Prod_Name"].ToString().Trim() + " 商品已经存在列表中!不能再增加!");
  81. return;
  82. }
  83. }
  84. }
  85. }
  86. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
  87. {
  88. for (int t = 0; t < dt.Rows.Count; t++)
  89. {
  90. DataGridViewRow dgvr = new DataGridViewRow();
  91. DataGridViewCell cell = null;
  92. cell = new DataGridViewTextBoxCell();
  93. cell.Value = dt.Rows[t]["ID"].ToString().Trim();
  94. dgvr.Cells.Add(cell);
  95. cell = new DataGridViewTextBoxCell();
  96. cell.Value = dt.Rows[t]["Prod_Name"].ToString().Trim();
  97. dgvr.Cells.Add(cell);
  98. cell = new DataGridViewTextBoxCell();
  99. cell.Value = "0";
  100. dgvr.Cells.Add(cell);
  101. cell = new DataGridViewTextBoxCell();
  102. cell.Value = dt.Rows[t]["Prod_ClassName"].ToString().Trim();
  103. dgvr.Cells.Add(cell);
  104. cell = new DataGridViewTextBoxCell();
  105. cell.Value = dt.Rows[t]["Prod_Class"].ToString().Trim();
  106. dgvr.Cells.Add(cell);
  107. cell = new DataGridViewTextBoxCell();
  108. cell.Value = dt.Rows[t]["Prod_Number"].ToString().Trim();
  109. dgvr.Cells.Add(cell);
  110. cell = new DataGridViewTextBoxCell();
  111. cell.Value = "";
  112. dgvr.Cells.Add(cell);
  113. this.Invoke(new UpdateControl(delegate()
  114. {
  115. this.dgv2.Rows.Add(dgvr);
  116. dgv2.ClearSelection();
  117. }));
  118. }
  119. });
  120. }
  121. else
  122. { MessageBoxCustom.Show("无报警商品!"); }
  123. }
  124. /// <summary>
  125. /// 申请采购管理
  126. /// </summary>
  127. /// <param name="sender"></param>
  128. /// <param name="e"></param>
  129. protected override void btnProcurementApplication_Click(object sender, EventArgs e)
  130. {
  131. LYFZ.Software.MainBusiness.InventoryManagement.FrmProcurementApplication set = new FrmProcurementApplication();
  132. set.ShowDialog();
  133. }
  134. /// <summary>
  135. /// 关闭
  136. /// </summary>
  137. /// <param name="sender"></param>
  138. /// <param name="e"></param>
  139. protected override void btnClose_Click(object sender, EventArgs e)
  140. {
  141. this.Close();
  142. }
  143. /// <summary>
  144. /// 商品库存双击事件
  145. /// </summary>
  146. /// <param name="sender"></param>
  147. /// <param name="e"></param>
  148. void dgv1_MouseDoubleClick(object sender, MouseEventArgs e)
  149. {
  150. if (dgv1.Rows.Count > 0)
  151. {
  152. if (e.Location.Y > this.dgv1.ColumnHeadersHeight)
  153. {
  154. string Sp_Number = dgv1.CurrentRow.Cells["Sp_Number"].Value.ToString();
  155. string Ir_ProductName = dgv1.CurrentRow.Cells["Ir_ProductName"].Value.ToString();
  156. if (dgv2.Rows.Count > 0)
  157. {
  158. for (int i = 0; i < dgv2.Rows.Count; i++)
  159. {
  160. if (Sp_Number.ToString() == dgv2.Rows[i].Cells["Prod_Number"].Value.ToString())
  161. {
  162. MessageBoxCustom.Show(Ir_ProductName + " 商品已经存在列表中!不能再增加!");
  163. return;
  164. }
  165. }
  166. }
  167. #region 获取采购商品
  168. LYFZ.BLL.BLL_ErpProduct Productbll = new BLL.BLL_ErpProduct();
  169. DataTable dt = Productbll.View_tb_ErpProduct("Prod_Number='" + Sp_Number + "'").Tables[0];
  170. for (int t = 0; t < dt.Rows.Count; t++)
  171. {
  172. LYFZ.BLL.BLL_ErpPurchaseProduct PurchaseProductBll = new BLL.BLL_ErpPurchaseProduct();
  173. DataTable dal = new DataTable();
  174. dal = PurchaseProductBll.GetList("Ppt_ProductNumber='" + dt.Rows[t]["Prod_Number"].ToString().Trim() + "' and (Ppt_PurchaseStatus='0' or Ppt_PurchaseStatus='3') ").Tables[0];
  175. DataGridViewRow dgvr = new DataGridViewRow();
  176. DataGridViewCell cell = null;
  177. cell = new DataGridViewTextBoxCell();
  178. cell.Value = dt.Rows[t]["ID"].ToString().Trim();
  179. dgvr.Cells.Add(cell);
  180. cell = new DataGridViewTextBoxCell();
  181. cell.Value = dt.Rows[t]["Prod_Name"].ToString().Trim();
  182. dgvr.Cells.Add(cell);
  183. cell = new DataGridViewTextBoxCell();
  184. cell.Value = "0";
  185. dgvr.Cells.Add(cell);
  186. cell = new DataGridViewTextBoxCell();
  187. cell.Value = dt.Rows[t]["Prod_ClassName"].ToString().Trim();
  188. dgvr.Cells.Add(cell);
  189. cell = new DataGridViewTextBoxCell();
  190. cell.Value = dt.Rows[t]["Prod_Class"].ToString().Trim();
  191. dgvr.Cells.Add(cell);
  192. cell = new DataGridViewTextBoxCell();
  193. cell.Value = dt.Rows[t]["Prod_Number"].ToString().Trim();
  194. dgvr.Cells.Add(cell);
  195. cell = new DataGridViewTextBoxCell();
  196. if (dal.Rows.Count > 0)
  197. {
  198. if (dal.Rows[0]["Ppt_PurchaseStatus"].ToString().Trim() == "0")
  199. {
  200. cell.Value = LYFZ.EnumPublic.Ppt_PurchaseStatus.采购中.ToString();
  201. }
  202. else if (dal.Rows[0]["Ppt_PurchaseStatus"].ToString().Trim() == "1")
  203. {
  204. cell.Value = LYFZ.EnumPublic.Ppt_PurchaseStatus.采购完成.ToString();
  205. }
  206. else if (dal.Rows[0]["Ppt_PurchaseStatus"].ToString().Trim() == "2")
  207. {
  208. cell.Value = LYFZ.EnumPublic.Ppt_PurchaseStatus.采购取消.ToString();
  209. }
  210. else if (dal.Rows[0]["Ppt_PurchaseStatus"].ToString().Trim() == "3")
  211. {
  212. cell.Value = LYFZ.EnumPublic.Ppt_PurchaseStatus.申请中.ToString();
  213. }
  214. }
  215. else
  216. { cell.Value = "可申请"; }
  217. dgvr.Cells.Add(cell);
  218. this.dgv2.Rows.Add(dgvr);
  219. }
  220. dgv2.ClearSelection();
  221. #endregion
  222. }
  223. }
  224. }
  225. /// <summary>
  226. /// 商品库存双击事件
  227. /// </summary>
  228. /// <param name="sender"></param>
  229. /// <param name="e"></param>
  230. protected override void dgv1_DoubleClick(object sender, EventArgs e)
  231. {
  232. }
  233. /// <summary>
  234. /// 只能输入数字
  235. /// </summary>
  236. /// <param name="sender"></param>
  237. /// <param name="e"></param>
  238. protected override void dgv2_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  239. {
  240. try
  241. {
  242. if (dgv2.Rows.Count > 0)
  243. {
  244. if (dgv2.CurrentRow.Cells["CgSl"].Value == null)
  245. {
  246. MessageBoxCustom.Show("采购数量不能为空!");
  247. dgv2.CurrentRow.Cells["CgSl"].Value = "0";
  248. return;
  249. }
  250. if (Command.Command_Validate.IsNumber(dgv2.CurrentRow.Cells["CgSl"].Value.ToString()) == false)
  251. {
  252. MessageBoxCustom.Show("只能输入纯数字!");
  253. dgv2.CurrentRow.Cells["CgSl"].Value = "0";
  254. return;
  255. }
  256. }
  257. }
  258. catch (Exception ex)
  259. { MessageBoxCustom.Show(ex.Message); }
  260. }
  261. /// <summary>
  262. /// 删除
  263. /// </summary>
  264. /// <param name="sender"></param>
  265. /// <param name="e"></param>
  266. protected override void btndelete_Click(object sender, EventArgs e)
  267. {
  268. if (dgv2.SelectedCells.Count == 0)
  269. {
  270. MessageBoxCustom.Show("请选择你要删除的数据!");
  271. return;
  272. }
  273. if (MessageBoxCustom.Show("你确定要删除吗?", "删除提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
  274. {
  275. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
  276. {
  277. for (int i = dgv2.SelectedRows.Count; i > 0; i--)
  278. {
  279. this.Invoke(new UpdateControl(delegate()
  280. {
  281. dgv2.Rows.RemoveAt(dgv2.SelectedRows[i - 1].Index);
  282. }));
  283. }
  284. });
  285. }
  286. }
  287. LYFZ.BLL.BLL_ErpPurchaseOrder PurchaseOrderBll = new BLL.BLL_ErpPurchaseOrder();
  288. LYFZ.BLL.BLL_ErpPurchaseProduct PurchaseProductbll = new BLL.BLL_ErpPurchaseProduct();
  289. /// <summary>
  290. /// 采购
  291. /// </summary>
  292. /// <param name="sender"></param>
  293. /// <param name="e"></param>
  294. protected override void btnSave_Click(object sender, EventArgs e)
  295. {
  296. if (dgv2.Rows.Count > 0)
  297. {
  298. for (int i = 0; i < dgv2.Rows.Count; i++)
  299. {
  300. if (Convert.ToInt32(dgv2.Rows[i].Cells["CgSl"].Value) <= 0)
  301. {
  302. MessageBoxCustom.Show(dgv2.Rows[i].Cells["spmc"].Value.ToString().Trim() + " 采购数量不能小于等于0!");
  303. return;
  304. }
  305. }
  306. if (MessageBoxCustom.Show("你确定采购列表中的商品吗?", "增加提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
  307. {
  308. List<Helper.CommandInfo> clist = new List<Helper.CommandInfo>();
  309. #region 增加采购订单表
  310. LYFZ.Model.Model_ErpPurchaseOrder PurchaseOrderModel = new Model.Model_ErpPurchaseOrder();
  311. PurchaseOrderModel.Pord_DividedShop = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetLocalCompanyInfoID();
  312. PurchaseOrderModel.Pord_PurchaseNumber = "St" + LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetServerDateTime().ToString("yyyyMMddHHmmss") + new Random().Next(100, 1000);
  313. PurchaseOrderModel.Pord_PurchaseName = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetServerDateTime().ToString("yyyy-MM-dd") + " 采购单";
  314. PurchaseOrderModel.Pord_RequisitionName = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
  315. PurchaseOrderModel.Pord_RequisitionTime = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetServerDateTime();
  316. PurchaseOrderModel.Pord_ApprovalStatus = "1";
  317. PurchaseOrderModel.Pord_ApprovalName = "";
  318. PurchaseOrderModel.Pord_ApprovalTime = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetServerDateTime();
  319. PurchaseOrderModel.Pord_ApprovalRemark = "";
  320. PurchaseOrderModel.Pord_PurchaseStatus = "3";
  321. clist.Add(PurchaseOrderBll.GetAddCommandInfo(PurchaseOrderModel));
  322. #endregion
  323. #region 增加采购商品表
  324. LYFZ.Model.Model_ErpPurchaseProduct PurchaseProductModel = null;
  325. for (int i = 0; i < dgv2.Rows.Count; i++)
  326. {
  327. PurchaseProductModel = new Model.Model_ErpPurchaseProduct();
  328. PurchaseProductModel.Ppt_PurchaseNumber = PurchaseOrderModel.Pord_PurchaseNumber;
  329. PurchaseProductModel.Ppt_ProductCategory = dgv2.Rows[i].Cells["Prod_Class"].Value.ToString();
  330. PurchaseProductModel.Ppt_ProductNumber = dgv2.Rows[i].Cells["Prod_Number"].Value.ToString();
  331. PurchaseProductModel.Ppt_PurchaseQuantity = Convert.ToInt32(dgv2.Rows[i].Cells["CgSl"].Value);
  332. PurchaseProductModel.Ppt_PurchaseVendor = "";
  333. PurchaseProductModel.Ppt_PurchasePrice = 0;
  334. PurchaseProductModel.Ppt_PurchaseStatus = "3";
  335. PurchaseProductModel.Ppt_PurchasePerson = "";
  336. PurchaseProductModel.Ppt_PurchaseTime = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetServerDateTime();
  337. PurchaseProductModel.Ppt_AcceptanceQuantity = 0;
  338. PurchaseProductModel.Ppt_AcceptanceTime = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetServerDateTime();
  339. PurchaseProductModel.Ppt_AcceptanceName = "";
  340. PurchaseProductModel.Ppt_StorageStatus = "0";
  341. PurchaseProductModel.Ppt_Remark = "";
  342. clist.Add(PurchaseProductbll.GetAddCommandInfo(PurchaseProductModel));
  343. }
  344. #endregion
  345. if (clist.Count > 0)
  346. {
  347. if (LYFZ.BLL.BaseBllOperate.ExecuteSqlTran(clist) > 0)
  348. {
  349. MessageBoxCustom.Show("保存成功!采购单号已生成!");
  350. FrmStock_Shown(sender, e);
  351. dgv2.Rows.Clear();
  352. }
  353. else
  354. { MessageBoxCustom.Show("增加采购失败!"); }
  355. }
  356. }
  357. }
  358. else
  359. { MessageBoxCustom.Show("列表中商品不能为空!请添加商品!"); }
  360. }
  361. /// <summary>
  362. /// 绑定查询商品类别
  363. /// </summary>
  364. public void SelectGoods()
  365. {
  366. CtvSelect.TreeView.Nodes.Clear();
  367. LYFZ.BLL.BLL_ErpSystemCategory BLLSystemCategory = new BLL.BLL_ErpSystemCategory();
  368. DataTable tbl = BLLSystemCategory.GetList("Sc_ClassParentID='1'").Tables[0];
  369. if (tbl.Rows.Count > 0)
  370. {
  371. TreeNode root = null;
  372. for (int i = 0; i < tbl.Rows.Count; i++)
  373. {
  374. if (i == 0)
  375. {
  376. root = new TreeNode("全部");
  377. this.CtvSelect.TreeView.Nodes.Add(root);
  378. }
  379. root = new TreeNode();
  380. root.Text = tbl.Rows[i]["Sc_ClassName"].ToString();
  381. root.Tag = tbl.Rows[i]["Sc_ClassCode"].ToString();
  382. this.CreateTreeViewShop(root.Nodes, tbl.Rows[i]["ID"].ToString());
  383. this.CtvSelect.TreeView.Nodes.Add(root);
  384. }
  385. }
  386. }
  387. /// <summary>
  388. /// 绑定第三级商品类别
  389. /// </summary>
  390. /// <param name="nodes">TreeView的节点集合</param>
  391. /// <param name="dataSource">数据源</param>
  392. /// <param name="parentid"></param>
  393. private void CreateTreeViewShop(TreeNodeCollection nodes, string ClassCode)
  394. {
  395. if (ClassCode != "")
  396. {
  397. LYFZ.BLL.BLL_ErpSystemCategory BLLSystemCategory = new BLL.BLL_ErpSystemCategory();
  398. DataTable tbl = BLLSystemCategory.GetList("Sc_ClassParentID=" + ClassCode + "").Tables[0];
  399. if (tbl.Rows.Count > 0)
  400. {
  401. TreeNode node;
  402. for (int i = 0; i < tbl.Rows.Count; i++)
  403. {
  404. node = new TreeNode();
  405. node.Text = tbl.Rows[i]["Sc_ClassName"].ToString();
  406. node.Tag = tbl.Rows[i]["Sc_ClassCode"].ToString();
  407. nodes.Add(node);
  408. }
  409. }
  410. }
  411. }
  412. /// <summary>
  413. /// 商品查询
  414. /// </summary>
  415. /// <param name="sender"></param>
  416. /// <param name="e"></param>
  417. protected override void CtvSelect_ComboBoxTreeViewEx_TextChanged(object sender, TreeViewEventArgs e)
  418. {
  419. bind();
  420. }
  421. DataTable dt_PurchaseProduct = null;
  422. public void bind()
  423. {
  424. this.ucPagerEx1.PageCurrent = 1;
  425. this.ucPagerEx1.PageSize = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetPageSize();//3;分页条数
  426. this.ucPagerEx1.Bind();
  427. }
  428. /// <summary>
  429. /// 画分页
  430. /// </summary>
  431. /// <param name="e"></param>
  432. /// <returns></returns>
  433. private int ucPagerEx1_EventPaging(UCPager.EventPagingArg e)
  434. {
  435. dgv1.Rows.Clear();
  436. DataTable dt = new DataTable();
  437. LYFZ.UCPager.PageData pageData = new LYFZ.UCPager.PageData();
  438. StringBuilder str = new StringBuilder();
  439. if (CtvSelect.Text == "" || CtvSelect.Tag == null || CtvSelect.Text == "全部")
  440. { str.Append(" 1=1 and Prod_IsEnabled='1' and Prod_DividedShop='" + LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetCompanyInfoID() + "' and Prod_Availability=1"); }
  441. if (CtvSelect.Tag != null)
  442. { str.Append(" 1=1 and Prod_Class='" + CtvSelect.Tag.ToString() + "' and Prod_IsEnabled='1' and Prod_DividedShop='" + LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetCompanyInfoID() + "' and Prod_Availability=1"); }
  443. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
  444. {
  445. pageData.TableName = "View_tb_ErpProduct";
  446. pageData.PageIndex = this.ucPagerEx1.PageCurrent;
  447. pageData.PageSize = this.ucPagerEx1.PageSize;
  448. pageData.QueryCondition = str.ToString();
  449. pageData.QueryFieldName = "ID,Prod_Number,Prod_DividedShop,Prod_Name,Prod_Class,Prod_Unit,Prod_CostPrice,Prod_SalesPrice,Prod_SpecialPrice,Prod_AlarmQuantity,Prod_IsEnabled,Prod_Quantity,Prod_Expedited,Prod_CreateDatetime,Prod_PreSaleQuantity,Prod_Batch,Prod_ClassName,Sc_ClassCode,Prod_ClassName2,Prod_IsEnabledName,Prod_Availability";
  450. pageData.OrderStr = "ID desc";
  451. pageData.OrderType = 1;
  452. DataSet da = pageData.QueryDataTable();
  453. dt = da.Tables[0];
  454. if (dt.Rows.Count > 0)
  455. {
  456. dt_PurchaseProduct = PurchaseProductbll.GetAllList().Tables[0];
  457. this.Invoke(new UpdateControl(delegate()
  458. {
  459. for (int t = 0; t < dt.Rows.Count; t++)
  460. {
  461. DataGridViewRow dgvr = new DataGridViewRow();
  462. DataGridViewCell cell = null;
  463. cell = new DataGridViewTextBoxCell();
  464. cell.Value = dt.Rows[t]["ID"].ToString().Trim();
  465. dgvr.Cells.Add(cell);
  466. cell = new DataGridViewTextBoxCell();
  467. cell.Value = dt.Rows[t]["Prod_Number"].ToString().Trim();
  468. dgvr.Cells.Add(cell);
  469. cell = new DataGridViewTextBoxCell();
  470. cell.Value = dt.Rows[t]["Prod_Name"].ToString().Trim();
  471. dgvr.Cells.Add(cell);
  472. cell = new DataGridViewTextBoxCell();
  473. cell.Value = dt.Rows[t]["Prod_Quantity"].ToString().Trim();
  474. dgvr.Cells.Add(cell);
  475. cell = new DataGridViewTextBoxCell();
  476. cell.Value = dt.Rows[t]["Prod_ClassName"].ToString().Trim();
  477. dgvr.Cells.Add(cell);
  478. cell = new DataGridViewTextBoxCell();
  479. cell.Value = dt.Rows[t]["Prod_AlarmQuantity"].ToString().Trim();
  480. dgvr.Cells.Add(cell);
  481. cell = new DataGridViewTextBoxCell();
  482. cell.Value = dt.Rows[t]["Prod_PreSaleQuantity"].ToString().Trim();
  483. dgvr.Cells.Add(cell);
  484. cell = new DataGridViewTextBoxCell();
  485. DataRow[] dt_PurchaseProduct2 = dt_PurchaseProduct.Select("Ppt_ProductNumber='" + dt.Rows[t]["Prod_Number"].ToString().Trim() + "' and (Ppt_PurchaseStatus='0' or Ppt_PurchaseStatus='3') ");
  486. if (dt_PurchaseProduct2.Length > 0)
  487. { cell.Value = "已申请"; }
  488. else
  489. { cell.Value = ""; }
  490. dgvr.Cells.Add(cell);
  491. if (Convert.ToInt32(dt.Rows[t]["Prod_Quantity"]) <= Convert.ToInt32(dt.Rows[t]["Prod_AlarmQuantity"]))
  492. { dgvr.DefaultCellStyle.ForeColor = Color.Red; }
  493. this.dgv1.Rows.Add(dgvr);
  494. }
  495. dgv1.ClearSelection();
  496. }));
  497. }
  498. });
  499. try
  500. {
  501. this.ucPagerEx1.TbDataSource = dt;
  502. }
  503. catch { }
  504. return pageData.TotalCount;
  505. }
  506. /// <summary>
  507. /// 右键点击事件
  508. /// </summary>
  509. /// <param name="sender"></param>
  510. /// <param name="e"></param>
  511. void dgv1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
  512. {
  513. if (e.Button == MouseButtons.Right)
  514. {
  515. ToolStripMenuItem item = null;
  516. item = new ToolStripMenuItem();
  517. item.Text = "查看商品图片";
  518. item.Tag = "View";
  519. this.dgv1.conMenu.Items.Add(item);
  520. item = new ToolStripMenuItem();
  521. item.Text = "增加采购";
  522. item.Tag = "Add";
  523. this.dgv1.conMenu.Items.Add(item);
  524. }
  525. }
  526. /// <summary>
  527. ///
  528. /// </summary>
  529. /// <param name="sender"></param>
  530. /// <param name="e"></param>
  531. void dgv1_DataGridViewConMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  532. {
  533. ToolStripItem item = e.ClickedItem;
  534. if (item.Tag.ToString().Trim() == "View")
  535. {
  536. LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.ProductViewPhoto(this.dgv1.CurrentRow.Cells["Sp_Number"].Value.ToString().Trim());
  537. }
  538. else if (item.Tag.ToString().Trim() == "Add")
  539. {
  540. if (dgv1.Rows.Count > 0)
  541. {
  542. if (dgv1.SelectedRows.Count == 0)
  543. { MessageBoxCustom.Show("请选择你要采购的商品!"); return; }
  544. for (int i = 0; i < dgv1.SelectedRows.Count; i++)
  545. {
  546. if (dgv2.Rows.Count > 0)
  547. {
  548. for (int t = 0; t < dgv2.Rows.Count; t++)
  549. {
  550. if (dgv1.SelectedRows[i].Cells["Sp_Number"].Value.ToString().Trim() == dgv2.Rows[t].Cells["Prod_Number"].Value.ToString())
  551. {
  552. MessageBoxCustom.Show(dgv1.SelectedRows[i].Cells["Ir_ProductName"].Value.ToString().Trim() + " 商品已经存在列表中!不能再增加!");
  553. return;
  554. }
  555. }
  556. }
  557. }
  558. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
  559. {
  560. for (int i = 0; i < dgv1.SelectedRows.Count; i++)
  561. {
  562. string Sp_Number = dgv1.SelectedRows[i].Cells["Sp_Number"].Value.ToString();
  563. string Ir_ProductName = dgv1.SelectedRows[i].Cells["Ir_ProductName"].Value.ToString();
  564. LYFZ.BLL.BLL_ErpProduct Productbll = new BLL.BLL_ErpProduct();
  565. DataTable dt = Productbll.View_tb_ErpProduct("Prod_Number='" + Sp_Number + "'").Tables[0];
  566. if (dt.Rows.Count > 0)
  567. {
  568. for (int t = 0; t < dt.Rows.Count; t++)
  569. {
  570. LYFZ.BLL.BLL_ErpPurchaseProduct PurchaseProductBll = new BLL.BLL_ErpPurchaseProduct();
  571. DataTable dal = new DataTable();
  572. dal = PurchaseProductBll.GetList("Ppt_ProductNumber='" + dt.Rows[t]["Prod_Number"].ToString().Trim() + "' and (Ppt_PurchaseStatus='0' or Ppt_PurchaseStatus='3') ").Tables[0];
  573. DataGridViewRow dgvr = new DataGridViewRow();
  574. DataGridViewCell cell = null;
  575. cell = new DataGridViewTextBoxCell();
  576. cell.Value = dt.Rows[t]["ID"].ToString().Trim();
  577. dgvr.Cells.Add(cell);
  578. cell = new DataGridViewTextBoxCell();
  579. cell.Value = dt.Rows[t]["Prod_Name"].ToString().Trim();
  580. dgvr.Cells.Add(cell);
  581. cell = new DataGridViewTextBoxCell();
  582. cell.Value = "0";
  583. dgvr.Cells.Add(cell);
  584. cell = new DataGridViewTextBoxCell();
  585. cell.Value = dt.Rows[t]["Prod_ClassName"].ToString().Trim();
  586. dgvr.Cells.Add(cell);
  587. cell = new DataGridViewTextBoxCell();
  588. cell.Value = dt.Rows[t]["Prod_Class"].ToString().Trim();
  589. dgvr.Cells.Add(cell);
  590. cell = new DataGridViewTextBoxCell();
  591. cell.Value = dt.Rows[t]["Prod_Number"].ToString().Trim();
  592. dgvr.Cells.Add(cell);
  593. cell = new DataGridViewTextBoxCell();
  594. if (dal.Rows.Count > 0)
  595. {
  596. if (dal.Rows[0]["Ppt_PurchaseStatus"].ToString().Trim() == "0")
  597. { cell.Value = LYFZ.EnumPublic.Ppt_PurchaseStatus.采购中.ToString(); }
  598. else if (dal.Rows[0]["Ppt_PurchaseStatus"].ToString().Trim() == "1")
  599. { cell.Value = LYFZ.EnumPublic.Ppt_PurchaseStatus.采购完成.ToString(); }
  600. else if (dal.Rows[0]["Ppt_PurchaseStatus"].ToString().Trim() == "2")
  601. { cell.Value = LYFZ.EnumPublic.Ppt_PurchaseStatus.采购取消.ToString(); }
  602. else if (dal.Rows[0]["Ppt_PurchaseStatus"].ToString().Trim() == "3")
  603. { cell.Value = LYFZ.EnumPublic.Ppt_PurchaseStatus.申请中.ToString(); }
  604. }
  605. else
  606. { cell.Value = "可申请"; }
  607. dgvr.Cells.Add(cell);
  608. this.Invoke(new UpdateControl(delegate()
  609. {
  610. this.dgv2.Rows.Add(dgvr);
  611. }));
  612. }
  613. }
  614. }
  615. });
  616. dgv2.ClearSelection();
  617. }
  618. }
  619. }
  620. }
  621. }