InventoryDetailFrmMain.cs 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925
  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 InventoryDetailFrmMain : LYFZ.Software.UI.InventoryManagement.InventoryDetailFrmMain
  13. {
  14. LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder();
  15. LYFZ.BLL.BLL_ErpPurchaseOrder porbll = new BLL.BLL_ErpPurchaseOrder();
  16. LYFZ.BLL.BLL_ErpPurchaseProduct pptbll = new BLL.BLL_ErpPurchaseProduct();
  17. public InventoryDetailFrmMain()
  18. {
  19. this.Load += InventoryDetailFrmMain_Load;
  20. this.Shown += InventoryDetailFrmMain_Shown;
  21. this.cmbtrrevProductCategory.ComboBoxTree_NodeMouseClick += cmbtrrevProductCategory_ComboBoxTree_NodeMouseClick;
  22. this.chkAlarmProduct.Click += chkAlarmProduct_Click;
  23. this.txtQueryText.KeyDown += txtQueryText_KeyDown;
  24. this.btnQuery.Click += btnQuery_Click;
  25. this.btnStocktaking.Click += btnStocktaking_Click;
  26. this.btnPurchaseRequest.Click += btnPurchaseRequest_Click;
  27. this.btnCloseed.Click += btnCloseed_Click;
  28. this.Resize += InventoryDetailFrmMain_Resize;
  29. this.btnAdd.Click += btnAdd_Click;
  30. this.btnRemove.Click += btnRemove_Click;
  31. this.listViewData_Source.MouseDoubleClick += listViewData_Source_MouseDoubleClick;
  32. this.listViewData_Selected.MouseDoubleClick += listViewData_Selected_MouseDoubleClick;
  33. this.listViewData_Source.MouseDown += listViewData_Source_MouseDown;
  34. this.listViewData_Selected.MouseDown += listViewData_Selected_MouseDown;
  35. this.txtText.Leave += txtText_Leave;
  36. this.txtText.KeyPress += txtText_KeyPress;
  37. // 导出按钮事件;
  38. btnExport.Click += BtnExport_Click;
  39. }
  40. private void BtnExport_Click( object sender, EventArgs e )
  41. {
  42. SaveFileDialog saveFile = new SaveFileDialog();
  43. saveFile.FileName = "库存明细";
  44. saveFile.Title = "导出数据报表文件";
  45. saveFile.Filter = "EXECL文件(*.xls) |*.xls |文本文件(*.txt) |*.txt |所有文件(*.*) |*.*";
  46. saveFile.FilterIndex = 1;
  47. DialogResult drst = saveFile.ShowDialog();
  48. if ( drst == DialogResult.No || drst == DialogResult.Cancel || drst == DialogResult.No || drst == DialogResult.Abort )
  49. return;
  50. bool IsExport = false;
  51. #region 查询条件
  52. string StrWhere = "Prod_Availability = 1 And Prod_IsEnabled = 1 "; //And Prod_DividedShop = '" + LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetCompanyInfoID() + "'
  53. if ( !string.IsNullOrEmpty( this.txtQueryText.Text.Trim() ) )
  54. {
  55. StrWhere += " and (Prod_Name like '%" + txtQueryText.Text.Trim() + "%' or dbo.fn_ChineseToSpell(Prod_Name) like '%" + txtQueryText.Text.Trim() + "%')";
  56. }
  57. if ( this.chkAlarmProduct.Checked )
  58. {
  59. StrWhere += " And (Prod_AlarmQuantity >= Prod_Quantity And Prod_AlarmQuantity > 0)";
  60. }
  61. if ( this.cmbtrrevProductCategory.Text.Trim() != "全部" && this.cmbtrrevProductCategory.Text.Trim() != "" )
  62. {
  63. if ( this.cmbtrrevProductCategory.Nodes.Count > 0 )
  64. {
  65. string classString = "'" + this.cmbtrrevProductCategory.Tag.ToString().Trim() + "',";
  66. for ( int i = 0; i < this.cmbtrrevProductCategory.SelectedNode.Nodes.Count; i++ )
  67. {
  68. if ( this.cmbtrrevProductCategory.SelectedNode.Nodes[i].Nodes.Count > 0 )
  69. {
  70. for ( int j = 0; j < this.cmbtrrevProductCategory.SelectedNode.Nodes[i].Nodes.Count; j++ )
  71. {
  72. if ( this.cmbtrrevProductCategory.SelectedNode.Nodes[i].Nodes[j].Nodes.Count > 0 )
  73. {
  74. for ( int k = 0; k < this.cmbtrrevProductCategory.SelectedNode.Nodes[i].Nodes[j].Nodes.Count; k++ )
  75. {
  76. classString += "'" + this.cmbtrrevProductCategory.SelectedNode.Nodes[i].Nodes[j].Nodes[k].Tag.ToString().Trim() + "',";
  77. }
  78. }
  79. else
  80. {
  81. classString += "'" + this.cmbtrrevProductCategory.SelectedNode.Nodes[i].Nodes[j].Tag.ToString().Trim() + "',";
  82. }
  83. }
  84. }
  85. else
  86. {
  87. classString += "'" + this.cmbtrrevProductCategory.SelectedNode.Nodes[i].Tag.ToString().Trim() + "',";
  88. }
  89. }
  90. StrWhere += " And Prod_Class in(" + classString.TrimEnd( ',' ) + ")";
  91. }
  92. }
  93. #endregion
  94. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod( delegate ( object obj, BackgroundWorker backgroundWorker )
  95. {
  96. string StrColumnName =
  97. "Prod_Number as 商品序号," +
  98. "[Sc_ClassName] as 商品类型," +
  99. "Prod_Name as 商品名称," +
  100. "Prod_AlarmQuantity as 报警数量," +
  101. "Prod_Quantity as 商品库存," +
  102. "(select sum(OPlist_ProdQuantity) from tb_ErpOrderProductList where OPlist_ProdNumber =Prod_Number and OPlist_Type = '2' and ((CONVERT(int,OPlist_CompletedStatus) + CONVERT(int,OPlist_PickupStatus))=0)) as 预售数量," +
  103. " case when (select Count(ID) from tb_ErpPurchaseProduct where Ppt_ProductNumber = Prod_Number And Ppt_PurchaseStatus = '0') > 0 then '采购中' else (case when (select Count(ID) from tb_ErpPurchaseProduct where Ppt_ProductNumber = Prod_Number And Ppt_PurchaseStatus = '3') > 0 then '申请中' else '' end) end AS 申请状态 ";
  104. DataTable dt = orbll.GetView_Custom( "tb_ErpProduct Left Join tb_ErpSystemCategory on Prod_Class = Sc_ClassCode", StrWhere: StrWhere, ShowColumnName: StrColumnName ).Tables[0];
  105. if ( dt.Rows.Count == 0 )
  106. {
  107. MessageBoxCustom.Show( "没有数据可导出" );
  108. return;
  109. }
  110. this.Invoke( new LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.UpdateControl( delegate ()
  111. {
  112. if ( dt.Rows.Count > 0 )
  113. {
  114. try
  115. {
  116. //this.Invoke( new LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.UpdateControl( delegate ()
  117. // {
  118. // IsExport = LYFZ.Command.Command_ExportExcel.DataTable2Sheet( saveFile.FileName.Trim(), dt, "Sheet1", IsCoveredExistingFile: true );
  119. // } ) );
  120. IsExport = LYFZ.WinAPI.CustomPublicMethod.DataGridViewToExcel(saveFile.FileName.Trim(), dt, null, backgroundWorker);
  121. }
  122. catch
  123. {
  124. }
  125. if ( IsExport )
  126. {
  127. MessageBoxCustom.Show( "导出成功!" );
  128. }
  129. else
  130. {
  131. MessageBoxCustom.Show( "导出失败!" );
  132. }
  133. }
  134. } ) );
  135. } );
  136. }
  137. /// <summary>
  138. /// 是否保存
  139. /// </summary>
  140. public bool IsSaveed = false;
  141. /// <summary>
  142. /// 相片集合
  143. /// </summary>
  144. ImageList mlistImage = new ImageList();
  145. /// <summary>
  146. /// 窗体加载事件
  147. /// </summary>
  148. /// <param name="sender"></param>
  149. /// <param name="e"></param>
  150. void InventoryDetailFrmMain_Load( object sender, EventArgs e )
  151. {
  152. LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindComboBoxTreeView_SystemCategory( "AAAAAAA", this.cmbtrrevProductCategory, IsFirstNodeNull: true, IsFirstNodeName: "全部" );
  153. this.cmbtrrevProductCategory.TextFindTag( "全部" );
  154. this.btnPurchaseRequest.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights( LYFZ.BLL.BLL_ErpUser.CurrentUserRights.StockCompetence, CustomAttributes.OperatingAuthority.Add );
  155. this.btnStocktaking.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights( LYFZ.BLL.BLL_ErpUser.CurrentUserRights.StockCompetence, CustomAttributes.OperatingAuthority.InstockInventory );
  156. //btnProcurementApplication.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.StockCompetence, CustomAttributes.OperatingAuthority.ProcurementApplication);
  157. }
  158. /// <summary>
  159. /// 窗体加载事件
  160. /// </summary>
  161. /// <param name="sender"></param>
  162. /// <param name="e"></param>
  163. void InventoryDetailFrmMain_Shown( object sender, EventArgs e )
  164. {
  165. bool b = LYFZ.Software.MainBusiness.VersionControl.StaticVersion.UIFunctionVersion(
  166. VersionControl.VersionFunctionEnum.库存管理下单预售统计
  167. );
  168. if ( !b )
  169. {
  170. this.Close();
  171. return;
  172. }
  173. this.listViewData_Source.View = View.Details;
  174. this.listViewData_Source.GridLines = true;
  175. string[] StrColumns = "商品名称,库存数量,报警数量,预售数量,预售库存,申请状态".Split( ',' );
  176. for ( int i = 0; i < StrColumns.Length; i++ )
  177. {
  178. ColumnHeader ch = new ColumnHeader();
  179. ch.Text = StrColumns[i].Trim();
  180. if ( i == 0 )
  181. {
  182. ch.Width = (((this.listViewData_Source.Width - 23) / 8) * 3) - 5 * 4;
  183. }
  184. else
  185. {
  186. ch.Width = ((this.listViewData_Source.Width - 23) / 8) + 5;
  187. }
  188. switch ( StrColumns[i].Trim() )
  189. {
  190. case "库存数量":
  191. case "报警数量":
  192. case "预售数量":
  193. case "申请状态":
  194. ch.TextAlign = HorizontalAlignment.Center;
  195. break;
  196. default:
  197. ch.TextAlign = HorizontalAlignment.Left;
  198. break;
  199. }
  200. this.listViewData_Source.Columns.Add( ch );
  201. }
  202. this.mlistImage.ImageSize = new Size( 30, 30 );
  203. this.mlistImage.ColorDepth = ColorDepth.Depth32Bit;
  204. this.listViewData_Source.SmallImageList = mlistImage;
  205. this.CreateListViewGroup();
  206. this.listViewData_Selected.View = View.Details;
  207. this.listViewData_Selected.GridLines = true;
  208. StrColumns = "商品名称,采购数量".Split( ',' );
  209. for ( int i = 0; i < StrColumns.Length; i++ )
  210. {
  211. ColumnHeader ch = new ColumnHeader();
  212. ch.Text = StrColumns[i].Trim();
  213. if ( i == 0 )
  214. {
  215. ch.Width = (this.listViewData_Selected.Width - 23) / 4 * 3 - 5;
  216. }
  217. else
  218. {
  219. ch.Width = (this.listViewData_Selected.Width - 23) / 4 + 5;
  220. }
  221. switch ( StrColumns[i].Trim() )
  222. {
  223. case "采购数量":
  224. ch.TextAlign = HorizontalAlignment.Center;
  225. break;
  226. default:
  227. ch.TextAlign = HorizontalAlignment.Left;
  228. break;
  229. }
  230. this.listViewData_Selected.Columns.Add( ch );
  231. }
  232. this.mlistImage.ImageSize = new Size( 30, 30 );
  233. this.mlistImage.ColorDepth = ColorDepth.Depth32Bit;
  234. this.listViewData_Selected.SmallImageList = mlistImage;
  235. this.CreateListViewGroup();
  236. this.PublicFunctionRows();
  237. }
  238. /// <summary>
  239. /// 创建默认分组
  240. /// </summary>
  241. void CreateListViewGroup()
  242. {
  243. DataTable dtGroup = orbll.GetView_Custom( "tb_ErpProduct Left Join tb_ErpSystemCategory on Prod_Class = Sc_ClassCode", StrWhere: "", ShowColumnName: "Sc_ClassName,Prod_Class", GroupBy: "Sc_ClassName,Prod_Class" ).Tables[0];
  244. if ( dtGroup.Rows.Count > 0 )
  245. {
  246. for ( int i = 0; i < dtGroup.Rows.Count; i++ )
  247. {
  248. if ( this.listViewData_Source.Groups[dtGroup.Rows[i]["Prod_Class"].ToString().Trim()] == null )
  249. {
  250. ListViewGroup man_lvg = new ListViewGroup();
  251. man_lvg.Name = dtGroup.Rows[i]["Prod_Class"].ToString().Trim();
  252. man_lvg.Header = dtGroup.Rows[i]["Sc_ClassName"].ToString().Trim();
  253. man_lvg.HeaderAlignment = HorizontalAlignment.Left;
  254. this.listViewData_Source.Groups.Add( man_lvg );
  255. man_lvg = new ListViewGroup();
  256. man_lvg.Name = dtGroup.Rows[i]["Prod_Class"].ToString().Trim();
  257. man_lvg.Header = dtGroup.Rows[i]["Sc_ClassName"].ToString().Trim();
  258. man_lvg.HeaderAlignment = HorizontalAlignment.Left;
  259. this.listViewData_Selected.Groups.Add( man_lvg );
  260. }
  261. }
  262. if ( !this.listViewData_Source.ShowGroups )
  263. {
  264. this.listViewData_Source.ShowGroups = true;
  265. }
  266. if ( !this.listViewData_Selected.ShowGroups )
  267. {
  268. this.listViewData_Selected.ShowGroups = true;
  269. }
  270. }
  271. }
  272. /// <summary>
  273. /// 商品类别选择
  274. /// </summary>
  275. /// <param name="sender"></param>
  276. /// <param name="e"></param>
  277. void cmbtrrevProductCategory_ComboBoxTree_NodeMouseClick( object sender, TreeNodeMouseClickEventArgs e )
  278. {
  279. this.cmbtrrevProductCategory.SelectedNode = this.cmbtrrevProductCategory.GetNodeItem_TextToTag( this.cmbtrrevProductCategory.Text.Trim() );
  280. this.PublicFunctionRows();
  281. }
  282. /// <summary>
  283. /// 回车查询
  284. /// </summary>
  285. /// <param name="sender"></param>
  286. /// <param name="e"></param>
  287. void txtQueryText_KeyDown( object sender, KeyEventArgs e )
  288. {
  289. if ( e.KeyCode == Keys.Enter )
  290. {
  291. this.PublicFunctionRows();
  292. }
  293. }
  294. /// <summary>
  295. /// 查询
  296. /// </summary>
  297. /// <param name="sender"></param>
  298. /// <param name="e"></param>
  299. void btnQuery_Click( object sender, EventArgs e )
  300. {
  301. this.PublicFunctionRows();
  302. }
  303. /// <summary>
  304. /// 报警商品
  305. /// </summary>
  306. /// <param name="sender"></param>
  307. /// <param name="e"></param>
  308. void chkAlarmProduct_Click( object sender, EventArgs e )
  309. {
  310. this.PublicFunctionRows();
  311. }
  312. /// <summary>
  313. /// 盘点
  314. /// </summary>
  315. /// <param name="sender"></param>
  316. /// <param name="e"></param>
  317. void btnStocktaking_Click( object sender, EventArgs e )
  318. {
  319. if ( this.listViewData_Source.Items.Count > 0 && this.listViewData_Source.SelectedItems.Count > 0 )
  320. {
  321. string StrWhere = "";
  322. for ( int i = 0; i < this.listViewData_Source.SelectedItems.Count; i++ )
  323. {
  324. StrWhere += "'" + this.listViewData_Source.SelectedItems[i].Tag.ToString().Trim() + "',";
  325. }
  326. if ( !string.IsNullOrEmpty( StrWhere ) )
  327. {
  328. LYFZ.Software.MainBusiness.InventoryManagement.SetSmallForm.InventoryPanDianSmallForm frm = new SetSmallForm.InventoryPanDianSmallForm();
  329. frm.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
  330. frm.Location = new Point( LYFZ.EnumPublic.FormLocation_X, LYFZ.EnumPublic.FormLocation_Y );
  331. frm.Size = new Size( LYFZ.EnumPublic.FormSize_Width, LYFZ.EnumPublic.FormSize_Height );
  332. frm.StrWhere = StrWhere.TrimEnd( ',' );
  333. frm.ShowDialog();
  334. if ( frm.IsSaveed )
  335. {
  336. this.PublicFunctionRows();
  337. }
  338. }
  339. }
  340. }
  341. /// <summary>
  342. /// 采购
  343. /// </summary>
  344. /// <param name="sender"></param>
  345. /// <param name="e"></param>
  346. void btnPurchaseRequest_Click( object sender, EventArgs e )
  347. {
  348. if ( this.listViewData_Selected.Items.Count > 0 )
  349. {
  350. for ( int i = 0; i < this.listViewData_Selected.Items.Count; i++ )
  351. {
  352. if ( Convert.ToInt32( this.listViewData_Selected.Items[i].SubItems["采购数量"].Text.Trim() ) <= 0 )
  353. {
  354. MessageBoxCustom.Show( this.listViewData_Selected.Items[i].Text.Trim() + " 采购数量不能小于等于0!" );
  355. return;
  356. }
  357. }
  358. DateTime StrTime = SDateTime.Now;
  359. List<Helper.CommandInfo> clist = new List<Helper.CommandInfo>();
  360. string StrUserID = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
  361. #region 增加采购订单表
  362. string StrPurchaseNumber = LYFZ.BLL.BLL_ErpOrder.GenerateNewPurchaseNumber();
  363. LYFZ.Model.Model_ErpPurchaseOrder modelOrder = new Model.Model_ErpPurchaseOrder();
  364. modelOrder.Pord_DividedShop = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetLocalCompanyInfoID();
  365. modelOrder.Pord_PurchaseNumber = "St" + StrPurchaseNumber;
  366. modelOrder.Pord_PurchaseName = StrPurchaseNumber + " 采购单";
  367. modelOrder.Pord_RequisitionName = StrUserID;
  368. modelOrder.Pord_RequisitionTime = StrTime;
  369. modelOrder.Pord_ApprovalStatus = "1";
  370. modelOrder.Pord_ApprovalName = "";
  371. modelOrder.Pord_ApprovalTime = StrTime;
  372. modelOrder.Pord_ApprovalRemark = "";
  373. modelOrder.Pord_PurchaseStatus = "3";
  374. clist.Add( porbll.GetAddCommandInfo( modelOrder ) );
  375. #endregion
  376. #region 增加采购商品表
  377. LYFZ.Model.Model_ErpPurchaseProduct modelProduct = null;
  378. for ( int i = 0; i < this.listViewData_Selected.Items.Count; i++ )
  379. {
  380. modelProduct = new Model.Model_ErpPurchaseProduct();
  381. modelProduct.Ppt_PurchaseNumber = modelOrder.Pord_PurchaseNumber;
  382. modelProduct.Ppt_ProductCategory = this.listViewData_Selected.Items[i].Group.Name.ToString().Trim();
  383. modelProduct.Ppt_ProductNumber = this.listViewData_Selected.Items[i].Tag.ToString().Trim();
  384. modelProduct.Ppt_PurchaseQuantity = Convert.ToInt32( this.listViewData_Selected.Items[i].SubItems["采购数量"].Text.Trim() );
  385. modelProduct.Ppt_PurchaseVendor = "";
  386. modelProduct.Ppt_PurchasePrice = 0;
  387. modelProduct.Ppt_PurchaseStatus = "3";
  388. modelProduct.Ppt_PurchasePerson = "";
  389. modelProduct.Ppt_PurchaseTime = StrTime;
  390. modelProduct.Ppt_AcceptanceQuantity = 0;
  391. modelProduct.Ppt_AcceptanceTime = StrTime;
  392. modelProduct.Ppt_AcceptanceName = "";
  393. modelProduct.Ppt_StorageStatus = "0";
  394. modelProduct.Ppt_Remark = "";
  395. clist.Add( pptbll.GetAddCommandInfo( modelProduct ) );
  396. }
  397. #endregion
  398. if ( clist.Count > 0 )
  399. {
  400. if ( MessageBoxCustom.Show( "你确定采购列表中的商品吗?", "温馨提示", MessageBoxButtons.YesNo ) == DialogResult.No )
  401. {
  402. return;
  403. }
  404. if ( LYFZ.BLL.BaseBllOperate.ExecuteSqlTran( clist ) > 0 )
  405. {
  406. this.IsSaveed = true;
  407. MessageBoxCustom.Show( "采购成功!采购单号已生成!" );
  408. for ( int i = 0; i < this.listViewData_Selected.Items.Count; i++ )
  409. {
  410. for ( int j = 0; j < this.listViewData_Source.Items.Count; j++ )
  411. {
  412. if ( this.listViewData_Source.Items[j].ImageKey.ToString().Trim() == this.listViewData_Selected.Items[i].ImageKey.ToString().Trim() )
  413. {
  414. this.listViewData_Source.Items[j].SubItems["申请状态"].Text = "已申请"; break;
  415. }
  416. }
  417. }
  418. this.listViewData_Selected.Items.Clear();
  419. }
  420. else
  421. {
  422. MessageBoxCustom.Show( "采购失败!" );
  423. }
  424. }
  425. }
  426. else
  427. {
  428. MessageBoxCustom.Show( "列表中商品不能为空!请添加商品!" );
  429. }
  430. }
  431. /// <summary>
  432. /// 关闭
  433. /// </summary>
  434. /// <param name="sender"></param>
  435. /// <param name="e"></param>
  436. void btnCloseed_Click( object sender, EventArgs e )
  437. {
  438. this.Close();
  439. }
  440. /// <summary>
  441. /// 窗体大小变化事件
  442. /// </summary>
  443. /// <param name="sender"></param>
  444. /// <param name="e"></param>
  445. void InventoryDetailFrmMain_Resize( object sender, EventArgs e )
  446. {
  447. this.panelEx3.Width = (this.Width / 5) * 3;
  448. for ( int i = 0; i < this.listViewData_Source.Columns.Count; i++ )
  449. {
  450. if ( i == 0 )
  451. {
  452. this.listViewData_Source.Columns[i].Width = (((this.listViewData_Source.Width - 23) / 8) * 4) - 5 * 4;
  453. }
  454. else
  455. {
  456. this.listViewData_Source.Columns[i].Width = ((this.listViewData_Source.Width - 23) / 8) + 5;
  457. }
  458. }
  459. for ( int i = 0; i < this.listViewData_Selected.Columns.Count; i++ )
  460. {
  461. if ( i == 0 )
  462. {
  463. this.listViewData_Selected.Columns[i].Width = (this.listViewData_Selected.Width - 23) / 4 * 3 - 5;
  464. }
  465. else
  466. {
  467. this.listViewData_Selected.Columns[i].Width = ((this.listViewData_Selected.Width - 23) / 4) + 5;
  468. }
  469. }
  470. this.panelEx8.Location = new Point( this.panelEx8.Location.X, (this.panelEx4.Height - this.panelEx8.Height) / 2 );
  471. }
  472. /// <summary>
  473. /// 添加
  474. /// </summary>
  475. /// <param name="sender"></param>
  476. /// <param name="e"></param>
  477. void btnAdd_Click( object sender, EventArgs e )
  478. {
  479. if ( this.listViewData_Source.Items.Count > 0 && this.listViewData_Source.SelectedItems.Count > 0 )
  480. {
  481. string StrMagess = "";
  482. bool IsAdd = false;
  483. for ( int i = 0; i < this.listViewData_Source.SelectedItems.Count; i++ )
  484. {
  485. if ( !string.IsNullOrEmpty( this.listViewData_Source.SelectedItems[i].SubItems["申请状态"].Text.ToString().Trim() ) )
  486. {
  487. StrMagess = "1";
  488. }
  489. if ( string.IsNullOrEmpty( StrMagess ) )
  490. {
  491. bool IsFind = false;
  492. for ( int j = 0; j < this.listViewData_Selected.Items.Count; j++ )
  493. {
  494. if ( this.listViewData_Selected.Items[j].Tag.ToString().Trim() == this.listViewData_Source.SelectedItems[i].Tag.ToString().Trim() )
  495. {
  496. IsFind = true;
  497. }
  498. }
  499. if ( !IsFind )
  500. {
  501. IsAdd = true;
  502. ListViewItem lvItem = new ListViewItem();
  503. lvItem.Tag = this.listViewData_Source.SelectedItems[i].Tag.ToString().Trim();
  504. lvItem.ImageKey = this.listViewData_Source.SelectedItems[i].Tag.ToString().Trim();
  505. lvItem.Text = this.listViewData_Source.SelectedItems[i].Text.ToString().Trim();
  506. ListViewItem.ListViewSubItem ListSubItem = new ListViewItem.ListViewSubItem();
  507. ListSubItem.Name = "采购数量";
  508. ListSubItem.Text = "0";
  509. lvItem.SubItems.Add( ListSubItem );
  510. if ( this.listViewData_Selected.Groups.Count > 0 )
  511. {
  512. this.listViewData_Selected.Groups[this.listViewData_Source.SelectedItems[i].Group.Name.ToString().Trim()].Items.Add( lvItem );
  513. }
  514. this.listViewData_Selected.Items.Add( lvItem );
  515. }
  516. }
  517. }
  518. if ( IsAdd )
  519. {
  520. LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.ListViewDrawSingleOrDoubleRows( this.listViewData_Selected );
  521. }
  522. if ( !string.IsNullOrEmpty( StrMagess ) )
  523. {
  524. MessageBoxCustom.Show( "对于有已在‘采购中’或‘申请中’的商品不能重复采购!" );
  525. }
  526. this.listViewData_Source.Select();
  527. }
  528. }
  529. /// <summary>
  530. /// 移除
  531. /// </summary>
  532. /// <param name="sender"></param>
  533. /// <param name="e"></param>
  534. void btnRemove_Click( object sender, EventArgs e )
  535. {
  536. if ( this.listViewData_Selected.Items.Count > 0 && this.listViewData_Selected.SelectedItems.Count > 0 )
  537. {
  538. List<ListViewItem> delList = new List<ListViewItem>();
  539. for ( int i = 0; i < this.listViewData_Selected.SelectedItems.Count; i++ )
  540. {
  541. delList.Add( this.listViewData_Selected.SelectedItems[i] );
  542. }
  543. if ( delList.Count > 0 )
  544. {
  545. for ( int i = 0; i < delList.Count; i++ )
  546. {
  547. this.listViewData_Selected.Items.Remove( this.listViewData_Selected.SelectedItems[0] );
  548. }
  549. LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.ListViewDrawSingleOrDoubleRows( this.listViewData_Selected );
  550. }
  551. }
  552. }
  553. /// <summary>
  554. /// 双击源商品选中
  555. /// </summary>
  556. /// <param name="sender"></param>
  557. /// <param name="e"></param>
  558. void listViewData_Source_MouseDoubleClick( object sender, MouseEventArgs e )
  559. {
  560. if ( this.listViewData_Source.Items.Count > 0 && this.listViewData_Source.SelectedItems.Count > 0 )
  561. {
  562. if ( !string.IsNullOrEmpty( this.listViewData_Source.SelectedItems[0].SubItems["申请状态"].Text.ToString().Trim() ) )
  563. {
  564. MessageBoxCustom.Show( "商品已在" + this.listViewData_Source.SelectedItems[0].SubItems["申请状态"].Text.ToString().Trim() + ",不能重复采购" ); return;
  565. }
  566. bool IsFind = false;
  567. for ( int i = 0; i < this.listViewData_Selected.Items.Count; i++ )
  568. {
  569. if ( this.listViewData_Selected.Items[i].Tag.ToString().Trim() == this.listViewData_Source.SelectedItems[0].Tag.ToString().Trim() )
  570. {
  571. IsFind = true;
  572. }
  573. }
  574. if ( !IsFind )
  575. {
  576. ListViewItem lvItem = new ListViewItem();
  577. lvItem.Tag = this.listViewData_Source.SelectedItems[0].Tag.ToString().Trim();
  578. lvItem.ImageKey = this.listViewData_Source.SelectedItems[0].Tag.ToString().Trim();
  579. lvItem.Text = this.listViewData_Source.SelectedItems[0].Text.ToString().Trim();
  580. ListViewItem.ListViewSubItem ListSubItem = new ListViewItem.ListViewSubItem();
  581. ListSubItem.Name = "采购数量";
  582. ListSubItem.Text = "0";
  583. lvItem.SubItems.Add( ListSubItem );
  584. if ( this.listViewData_Selected.Groups.Count > 0 )
  585. {
  586. this.listViewData_Selected.Groups[this.listViewData_Source.SelectedItems[0].Group.Name.ToString().Trim()].Items.Add( lvItem );
  587. }
  588. this.listViewData_Selected.Items.Add( lvItem );
  589. LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.ListViewDrawSingleOrDoubleRows( this.listViewData_Selected );
  590. }
  591. }
  592. }
  593. /// <summary>
  594. /// 双击已选择的商品移除
  595. /// </summary>
  596. /// <param name="sender"></param>
  597. /// <param name="e"></param>
  598. void listViewData_Selected_MouseDoubleClick( object sender, MouseEventArgs e )
  599. {
  600. this.txtText.Visible = false;
  601. ListViewHitTestInfo info = this.listViewData_Selected.HitTest( e.X, e.Y );
  602. if ( !string.IsNullOrEmpty( info.SubItem.Name.Trim() ) )
  603. {
  604. Rectangle rect = info.SubItem.Bounds;
  605. switch ( info.SubItem.Name.Trim() )
  606. {
  607. case "采购数量":
  608. this.txtText.Location = new Point( rect.Location.X + this.listViewData_Selected.Location.X + 3, rect.Location.Y + this.listViewData_Selected.Location.Y + 2 );
  609. this.txtText.Size = rect.Size;
  610. this.txtText.Visible = true;
  611. this.txtText.Tag = info.SubItem.Name.Trim();
  612. this.txtText.Text = info.SubItem.Text.Trim();
  613. this.txtText.Focus();
  614. break;
  615. }
  616. }
  617. else
  618. {
  619. //DataTable dt = orbll.GetView_Custom("tb_ErpProduct", StrWhere: "Prod_Number = '" + this.listViewData_Selected.SelectedItems[0].Tag.ToString().Trim() + "'", ShowColumnName: "Prod_Thumbnail").Tables[0];
  620. //if (dt.Rows.Count > 0)
  621. //{
  622. // if (!string.IsNullOrEmpty(dt.Rows[0]["Prod_Thumbnail"].ToString().Trim()))
  623. // {
  624. // LYFZ.Software.MainBusiness.InitialSet.Product.FrmProductPic frm = new InitialSet.Product.FrmProductPic();
  625. // frm.FrmImage = LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetImage(LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.StringToByte(dt.Rows[0]["Prod_Thumbnail"].ToString()));
  626. // frm.ShowDialog();
  627. // }
  628. // else
  629. // { MessageBoxCustom.Show("产品未上传相片!"); return; }
  630. //}
  631. if ( this.listViewData_Selected.Items.Count > 0 && this.listViewData_Selected.SelectedItems.Count > 0 )
  632. {
  633. this.listViewData_Selected.Items.Remove( this.listViewData_Selected.SelectedItems[0] );
  634. LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.ListViewDrawSingleOrDoubleRows( this.listViewData_Selected );
  635. }
  636. }
  637. }
  638. /// <summary>
  639. /// 右键查看图片
  640. /// </summary>
  641. /// <param name="sender"></param>
  642. /// <param name="e"></param>
  643. void listViewData_Source_MouseDown( object sender, MouseEventArgs e )
  644. {
  645. if ( e.Button == MouseButtons.Right )
  646. {
  647. LYFZ.ComponentLibrary.ContextMenuStripEx contextmenu = new ContextMenuStripEx();
  648. contextmenu.Name = "Source";
  649. contextmenu.ItemClicked += contextmenu_ItemClicked;
  650. //弹出操作菜单
  651. contextmenu.Items.Clear();
  652. contextmenu.Show( MousePosition.X, MousePosition.Y );
  653. if ( this.listViewData_Source.SelectedItems.Count > 0 )
  654. {
  655. ToolStripMenuItem item = new ToolStripMenuItem();
  656. item.Text = "放大(" + this.listViewData_Source.SelectedItems[0].Text.Trim() + ")";
  657. item.Name = "ZoomView";
  658. item.Tag = this.listViewData_Source.SelectedItems[0].Tag.ToString().Trim();
  659. contextmenu.Items.Add( item );
  660. }
  661. contextmenu.Show();
  662. }
  663. }
  664. /// <summary>
  665. /// 右键查看图片
  666. /// </summary>
  667. /// <param name="sender"></param>
  668. /// <param name="e"></param>
  669. void listViewData_Selected_MouseDown( object sender, MouseEventArgs e )
  670. {
  671. if ( e.Button == MouseButtons.Right )
  672. {
  673. LYFZ.ComponentLibrary.ContextMenuStripEx contextmenu = new ContextMenuStripEx();
  674. contextmenu.Name = "Source";
  675. contextmenu.ItemClicked += contextmenu_ItemClicked;
  676. //弹出操作菜单
  677. contextmenu.Items.Clear();
  678. contextmenu.Show( MousePosition.X, MousePosition.Y );
  679. if ( this.listViewData_Selected.SelectedItems.Count > 0 )
  680. {
  681. ToolStripMenuItem item = new ToolStripMenuItem();
  682. item.Text = "放大(" + this.listViewData_Selected.SelectedItems[0].Text.Trim() + ")";
  683. item.Name = "ZoomView";
  684. item.Tag = this.listViewData_Selected.SelectedItems[0].Tag.ToString().Trim();
  685. contextmenu.Items.Add( item );
  686. }
  687. contextmenu.Show();
  688. }
  689. }
  690. /// <summary>
  691. /// 右键菜单选择事件
  692. /// </summary>
  693. /// <param name="sender"></param>
  694. /// <param name="e"></param>
  695. void contextmenu_ItemClicked( object sender, ToolStripItemClickedEventArgs e )
  696. {
  697. ToolStripItem item = e.ClickedItem;
  698. if ( !string.IsNullOrEmpty( item.Text.Trim() ) )
  699. {
  700. switch ( item.Name.Trim() )
  701. {
  702. case "ZoomView":
  703. DataTable tbl = orbll.GetView_Custom( "tb_ErpProduct", StrWhere: "Prod_Number = '" + item.Tag.ToString().Trim() + "'", ShowColumnName: "Prod_Thumbnail" ).Tables[0];
  704. if ( tbl.Rows.Count > 0 )
  705. {
  706. if ( !string.IsNullOrEmpty( tbl.Rows[0]["Prod_Thumbnail"].ToString().Trim() ) )
  707. {
  708. LYFZ.Software.MainBusiness.InitialSet.Product.FrmProductPic frm = new InitialSet.Product.FrmProductPic();
  709. frm.FrmImage = LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetImage( LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.StringToByte( tbl.Rows[0]["Prod_Thumbnail"].ToString() ) );
  710. frm.ShowDialog();
  711. }
  712. else
  713. {
  714. MessageBoxCustom.Show( "产品未上传相片!" ); return;
  715. }
  716. }
  717. break;
  718. }
  719. }
  720. }
  721. /// <summary>
  722. /// 文本框控件离开事件
  723. /// </summary>
  724. /// <param name="sender"></param>
  725. /// <param name="e"></param>
  726. void txtText_Leave( object sender, EventArgs e )
  727. {
  728. try
  729. {
  730. if ( this.txtText.Tag != null )
  731. {
  732. string StrText = "0";
  733. switch ( this.txtText.Tag.ToString().Trim() )
  734. {
  735. case "采购数量":
  736. if ( !string.IsNullOrEmpty( this.txtText.Text.Trim() ) )
  737. {
  738. if ( LYFZ.Command.Command_Validate.IsNumberSign( this.txtText.Text.Trim() ) )
  739. {
  740. if ( this.txtText.Text.Trim() == "0" )
  741. {
  742. StrText = "0";
  743. }
  744. else
  745. {
  746. StrText = this.txtText.Text.Trim();
  747. }
  748. }
  749. }
  750. if ( Convert.ToInt32( StrText ) < 0 )
  751. {
  752. MessageBoxCustom.Show( "请输入正确的采购数量!" ); return;
  753. }
  754. this.listViewData_Selected.SelectedItems[0].SubItems[this.txtText.Tag.ToString().Trim()].Text = StrText;
  755. break;
  756. }
  757. }
  758. }
  759. catch
  760. {
  761. }
  762. this.txtText.Visible = false;
  763. }
  764. /// <summary>
  765. /// 限制输入
  766. /// </summary>
  767. /// <param name="sender"></param>
  768. /// <param name="e"></param>
  769. void txtText_KeyPress( object sender, KeyPressEventArgs e )
  770. {
  771. if ( !Char.IsNumber( e.KeyChar ) && !Char.IsControl( e.KeyChar ) )
  772. {
  773. e.Handled = true;
  774. }
  775. }
  776. /// <summary>
  777. /// 创建行
  778. /// </summary>
  779. void PublicFunctionRows()
  780. {
  781. #region 查询条件
  782. string StrWhere = "Prod_Availability = 1 And Prod_IsEnabled = 1 "; //And Prod_DividedShop = '" + LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetCompanyInfoID() + "'
  783. if ( !string.IsNullOrEmpty( this.txtQueryText.Text.Trim() ) )
  784. {
  785. StrWhere += " and (Prod_Name like '%" + txtQueryText.Text.Trim() + "%' or dbo.fn_ChineseToSpell(Prod_Name) like '%" + txtQueryText.Text.Trim() + "%')";
  786. }
  787. if ( this.chkAlarmProduct.Checked )
  788. {
  789. StrWhere += " And (Prod_AlarmQuantity >= Prod_Quantity And Prod_AlarmQuantity > 0)";
  790. }
  791. if ( this.cmbtrrevProductCategory.Text.Trim() != "全部" && this.cmbtrrevProductCategory.Text.Trim() != "" )
  792. {
  793. if ( this.cmbtrrevProductCategory.Nodes.Count > 0 )
  794. {
  795. string classString = "'" + this.cmbtrrevProductCategory.Tag.ToString().Trim() + "',";
  796. for ( int i = 0; i < this.cmbtrrevProductCategory.SelectedNode.Nodes.Count; i++ )
  797. {
  798. if ( this.cmbtrrevProductCategory.SelectedNode.Nodes[i].Nodes.Count > 0 )
  799. {
  800. for ( int j = 0; j < this.cmbtrrevProductCategory.SelectedNode.Nodes[i].Nodes.Count; j++ )
  801. {
  802. if ( this.cmbtrrevProductCategory.SelectedNode.Nodes[i].Nodes[j].Nodes.Count > 0 )
  803. {
  804. for ( int k = 0; k < this.cmbtrrevProductCategory.SelectedNode.Nodes[i].Nodes[j].Nodes.Count; k++ )
  805. {
  806. classString += "'" + this.cmbtrrevProductCategory.SelectedNode.Nodes[i].Nodes[j].Nodes[k].Tag.ToString().Trim() + "',";
  807. }
  808. }
  809. else
  810. {
  811. classString += "'" + this.cmbtrrevProductCategory.SelectedNode.Nodes[i].Nodes[j].Tag.ToString().Trim() + "',";
  812. }
  813. }
  814. }
  815. else
  816. {
  817. classString += "'" + this.cmbtrrevProductCategory.SelectedNode.Nodes[i].Tag.ToString().Trim() + "',";
  818. }
  819. }
  820. StrWhere += " And Prod_Class in(" + classString.TrimEnd( ',' ) + ")";
  821. }
  822. }
  823. #endregion
  824. this.listViewData_Source.Items.Clear();
  825. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod( delegate ( object obj, BackgroundWorker backgroundWorker )
  826. {
  827. string StrColumnName =
  828. "Prod_Number," +
  829. "Prod_Class," +
  830. "Prod_Name," +
  831. "Prod_AlarmQuantity," +
  832. "Prod_Quantity," +
  833. "(select sum(OPlist_ProdQuantity) from tb_ErpOrderProductList where OPlist_ProdNumber =Prod_Number and OPlist_Type = '2' and ((CONVERT(int,OPlist_CompletedStatus) + CONVERT(int,OPlist_PickupStatus))=0)) as 预售数量," +
  834. " case when (select Count(ID) from tb_ErpPurchaseProduct where Ppt_ProductNumber = Prod_Number And Ppt_PurchaseStatus = '0') > 0 then '采购中' else (case when (select Count(ID) from tb_ErpPurchaseProduct where Ppt_ProductNumber = Prod_Number And Ppt_PurchaseStatus = '3') > 0 then '申请中' else '' end) end AS 申请状态," +
  835. "Prod_Thumbnail";
  836. DataTable dt = orbll.GetView_Custom( "tb_ErpProduct", StrWhere: StrWhere, ShowColumnName: StrColumnName ).Tables[0];
  837. this.Invoke( new LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.UpdateControl( delegate ()
  838. {
  839. int nRealStock = 0;
  840. int nPreSaleCount = 0;
  841. for ( int i = 0; i < dt.Rows.Count; i++ )
  842. {
  843. if ( !this.mlistImage.Images.Keys.Contains( dt.Rows[i]["Prod_Number"].ToString().Trim() ) )
  844. {
  845. Image img = LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetProductImage( dt.Rows[i]["Prod_Thumbnail"].ToString().Trim() );
  846. this.mlistImage.Images.Add( dt.Rows[i]["Prod_Number"].ToString().Trim(), img );
  847. }
  848. ListViewItem lvItem = new ListViewItem();
  849. lvItem.Tag = dt.Rows[i]["Prod_Number"].ToString().Trim();
  850. lvItem.ImageKey = dt.Rows[i]["Prod_Number"].ToString().Trim();
  851. lvItem.Text = dt.Rows[i]["Prod_Name"].ToString().Trim();
  852. ListViewItem.ListViewSubItem ListSubItem = new ListViewItem.ListViewSubItem();
  853. ListSubItem.Name = "库存数量";
  854. ListSubItem.Text = dt.Rows[i]["Prod_Quantity"].ToString().Trim();
  855. lvItem.SubItems.Add( ListSubItem );
  856. ListSubItem = new ListViewItem.ListViewSubItem();
  857. ListSubItem.Name = "报警数量";
  858. ListSubItem.Text = dt.Rows[i]["Prod_AlarmQuantity"].ToString().Trim();
  859. lvItem.SubItems.Add( ListSubItem );
  860. ListSubItem = new ListViewItem.ListViewSubItem();
  861. ListSubItem.Name = "预售数量";
  862. ListSubItem.Text = dt.Rows[i]["预售数量"].ToString().Trim();
  863. lvItem.SubItems.Add( ListSubItem );
  864. #region 预售库存 = 库存数量 - 预售数量;
  865. ListSubItem = new ListViewItem.ListViewSubItem();
  866. ListSubItem.Name = "预售库存";
  867. nPreSaleCount = 0;
  868. int.TryParse( dt.Rows[i]["预售数量"].ToString(), out nPreSaleCount );
  869. nRealStock = 0;
  870. int.TryParse( dt.Rows[i]["Prod_Quantity"].ToString(), out nRealStock );
  871. ListSubItem.Text = (nRealStock - nPreSaleCount).ToString();
  872. lvItem.SubItems.Add( ListSubItem );
  873. #endregion
  874. ListSubItem = new ListViewItem.ListViewSubItem();
  875. ListSubItem.Name = "申请状态";
  876. ListSubItem.Text = dt.Rows[i]["申请状态"].ToString().Trim();
  877. lvItem.SubItems.Add( ListSubItem );
  878. if ( Convert.ToInt32( dt.Rows[i]["Prod_Quantity"] ) <= Convert.ToInt32( dt.Rows[i]["Prod_AlarmQuantity"] ) )
  879. {
  880. lvItem.ForeColor = Color.Red;
  881. }
  882. if ( this.listViewData_Source.Groups.Count > 0 )
  883. {
  884. this.listViewData_Source.Groups[dt.Rows[i]["Prod_Class"].ToString().Trim()].Items.Add( lvItem );
  885. }
  886. this.listViewData_Source.Items.Add( lvItem );
  887. }
  888. } ) );
  889. } );
  890. LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.ListViewDrawSingleOrDoubleRows( this.listViewData_Source );
  891. }
  892. }
  893. }