123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925 |
- using LYFZ.ComponentLibrary;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace LYFZ.Software.MainBusiness.InventoryManagement
- {
- public partial class InventoryDetailFrmMain : LYFZ.Software.UI.InventoryManagement.InventoryDetailFrmMain
- {
- LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder();
- LYFZ.BLL.BLL_ErpPurchaseOrder porbll = new BLL.BLL_ErpPurchaseOrder();
- LYFZ.BLL.BLL_ErpPurchaseProduct pptbll = new BLL.BLL_ErpPurchaseProduct();
- public InventoryDetailFrmMain()
- {
- this.Load += InventoryDetailFrmMain_Load;
- this.Shown += InventoryDetailFrmMain_Shown;
- this.cmbtrrevProductCategory.ComboBoxTree_NodeMouseClick += cmbtrrevProductCategory_ComboBoxTree_NodeMouseClick;
- this.chkAlarmProduct.Click += chkAlarmProduct_Click;
- this.txtQueryText.KeyDown += txtQueryText_KeyDown;
- this.btnQuery.Click += btnQuery_Click;
- this.btnStocktaking.Click += btnStocktaking_Click;
- this.btnPurchaseRequest.Click += btnPurchaseRequest_Click;
- this.btnCloseed.Click += btnCloseed_Click;
- this.Resize += InventoryDetailFrmMain_Resize;
- this.btnAdd.Click += btnAdd_Click;
- this.btnRemove.Click += btnRemove_Click;
- this.listViewData_Source.MouseDoubleClick += listViewData_Source_MouseDoubleClick;
- this.listViewData_Selected.MouseDoubleClick += listViewData_Selected_MouseDoubleClick;
- this.listViewData_Source.MouseDown += listViewData_Source_MouseDown;
- this.listViewData_Selected.MouseDown += listViewData_Selected_MouseDown;
- this.txtText.Leave += txtText_Leave;
- this.txtText.KeyPress += txtText_KeyPress;
- // 导出按钮事件;
- btnExport.Click += BtnExport_Click;
- }
- private void BtnExport_Click( object sender, EventArgs e )
- {
- SaveFileDialog saveFile = new SaveFileDialog();
- saveFile.FileName = "库存明细";
- saveFile.Title = "导出数据报表文件";
- saveFile.Filter = "EXECL文件(*.xls) |*.xls |文本文件(*.txt) |*.txt |所有文件(*.*) |*.*";
- saveFile.FilterIndex = 1;
- DialogResult drst = saveFile.ShowDialog();
- if ( drst == DialogResult.No || drst == DialogResult.Cancel || drst == DialogResult.No || drst == DialogResult.Abort )
- return;
- bool IsExport = false;
- #region 查询条件
- string StrWhere = "Prod_Availability = 1 And Prod_IsEnabled = 1 "; //And Prod_DividedShop = '" + LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetCompanyInfoID() + "'
- if ( !string.IsNullOrEmpty( this.txtQueryText.Text.Trim() ) )
- {
- StrWhere += " and (Prod_Name like '%" + txtQueryText.Text.Trim() + "%' or dbo.fn_ChineseToSpell(Prod_Name) like '%" + txtQueryText.Text.Trim() + "%')";
- }
- if ( this.chkAlarmProduct.Checked )
- {
- StrWhere += " And (Prod_AlarmQuantity >= Prod_Quantity And Prod_AlarmQuantity > 0)";
- }
- if ( this.cmbtrrevProductCategory.Text.Trim() != "全部" && this.cmbtrrevProductCategory.Text.Trim() != "" )
- {
- if ( this.cmbtrrevProductCategory.Nodes.Count > 0 )
- {
- string classString = "'" + this.cmbtrrevProductCategory.Tag.ToString().Trim() + "',";
- for ( int i = 0; i < this.cmbtrrevProductCategory.SelectedNode.Nodes.Count; i++ )
- {
- if ( this.cmbtrrevProductCategory.SelectedNode.Nodes[i].Nodes.Count > 0 )
- {
- for ( int j = 0; j < this.cmbtrrevProductCategory.SelectedNode.Nodes[i].Nodes.Count; j++ )
- {
- if ( this.cmbtrrevProductCategory.SelectedNode.Nodes[i].Nodes[j].Nodes.Count > 0 )
- {
- for ( int k = 0; k < this.cmbtrrevProductCategory.SelectedNode.Nodes[i].Nodes[j].Nodes.Count; k++ )
- {
- classString += "'" + this.cmbtrrevProductCategory.SelectedNode.Nodes[i].Nodes[j].Nodes[k].Tag.ToString().Trim() + "',";
- }
- }
- else
- {
- classString += "'" + this.cmbtrrevProductCategory.SelectedNode.Nodes[i].Nodes[j].Tag.ToString().Trim() + "',";
- }
- }
- }
- else
- {
- classString += "'" + this.cmbtrrevProductCategory.SelectedNode.Nodes[i].Tag.ToString().Trim() + "',";
- }
- }
- StrWhere += " And Prod_Class in(" + classString.TrimEnd( ',' ) + ")";
- }
- }
- #endregion
- LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod( delegate ( object obj, BackgroundWorker backgroundWorker )
- {
- string StrColumnName =
- "Prod_Number as 商品序号," +
- "[Sc_ClassName] as 商品类型," +
- "Prod_Name as 商品名称," +
- "Prod_AlarmQuantity as 报警数量," +
- "Prod_Quantity as 商品库存," +
- "(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 预售数量," +
- " 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 申请状态 ";
- DataTable dt = orbll.GetView_Custom( "tb_ErpProduct Left Join tb_ErpSystemCategory on Prod_Class = Sc_ClassCode", StrWhere: StrWhere, ShowColumnName: StrColumnName ).Tables[0];
- if ( dt.Rows.Count == 0 )
- {
- MessageBoxCustom.Show( "没有数据可导出" );
- return;
- }
- this.Invoke( new LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.UpdateControl( delegate ()
- {
- if ( dt.Rows.Count > 0 )
- {
- try
- {
- //this.Invoke( new LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.UpdateControl( delegate ()
- // {
- // IsExport = LYFZ.Command.Command_ExportExcel.DataTable2Sheet( saveFile.FileName.Trim(), dt, "Sheet1", IsCoveredExistingFile: true );
- // } ) );
- IsExport = LYFZ.WinAPI.CustomPublicMethod.DataGridViewToExcel(saveFile.FileName.Trim(), dt, null, backgroundWorker);
- }
- catch
- {
- }
- if ( IsExport )
- {
- MessageBoxCustom.Show( "导出成功!" );
- }
- else
- {
- MessageBoxCustom.Show( "导出失败!" );
- }
- }
- } ) );
- } );
- }
- /// <summary>
- /// 是否保存
- /// </summary>
- public bool IsSaveed = false;
- /// <summary>
- /// 相片集合
- /// </summary>
- ImageList mlistImage = new ImageList();
- /// <summary>
- /// 窗体加载事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void InventoryDetailFrmMain_Load( object sender, EventArgs e )
- {
- LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindComboBoxTreeView_SystemCategory( "AAAAAAA", this.cmbtrrevProductCategory, IsFirstNodeNull: true, IsFirstNodeName: "全部" );
- this.cmbtrrevProductCategory.TextFindTag( "全部" );
- this.btnPurchaseRequest.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights( LYFZ.BLL.BLL_ErpUser.CurrentUserRights.StockCompetence, CustomAttributes.OperatingAuthority.Add );
- this.btnStocktaking.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights( LYFZ.BLL.BLL_ErpUser.CurrentUserRights.StockCompetence, CustomAttributes.OperatingAuthority.InstockInventory );
- //btnProcurementApplication.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.StockCompetence, CustomAttributes.OperatingAuthority.ProcurementApplication);
- }
- /// <summary>
- /// 窗体加载事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void InventoryDetailFrmMain_Shown( object sender, EventArgs e )
- {
- bool b = LYFZ.Software.MainBusiness.VersionControl.StaticVersion.UIFunctionVersion(
- VersionControl.VersionFunctionEnum.库存管理下单预售统计
- );
- if ( !b )
- {
- this.Close();
- return;
- }
- this.listViewData_Source.View = View.Details;
- this.listViewData_Source.GridLines = true;
- string[] StrColumns = "商品名称,库存数量,报警数量,预售数量,预售库存,申请状态".Split( ',' );
- for ( int i = 0; i < StrColumns.Length; i++ )
- {
- ColumnHeader ch = new ColumnHeader();
- ch.Text = StrColumns[i].Trim();
- if ( i == 0 )
- {
- ch.Width = (((this.listViewData_Source.Width - 23) / 8) * 3) - 5 * 4;
- }
- else
- {
- ch.Width = ((this.listViewData_Source.Width - 23) / 8) + 5;
- }
- switch ( StrColumns[i].Trim() )
- {
- case "库存数量":
- case "报警数量":
- case "预售数量":
- case "申请状态":
- ch.TextAlign = HorizontalAlignment.Center;
- break;
- default:
- ch.TextAlign = HorizontalAlignment.Left;
- break;
- }
- this.listViewData_Source.Columns.Add( ch );
- }
- this.mlistImage.ImageSize = new Size( 30, 30 );
- this.mlistImage.ColorDepth = ColorDepth.Depth32Bit;
- this.listViewData_Source.SmallImageList = mlistImage;
- this.CreateListViewGroup();
- this.listViewData_Selected.View = View.Details;
- this.listViewData_Selected.GridLines = true;
- StrColumns = "商品名称,采购数量".Split( ',' );
- for ( int i = 0; i < StrColumns.Length; i++ )
- {
- ColumnHeader ch = new ColumnHeader();
- ch.Text = StrColumns[i].Trim();
- if ( i == 0 )
- {
- ch.Width = (this.listViewData_Selected.Width - 23) / 4 * 3 - 5;
- }
- else
- {
- ch.Width = (this.listViewData_Selected.Width - 23) / 4 + 5;
- }
- switch ( StrColumns[i].Trim() )
- {
- case "采购数量":
- ch.TextAlign = HorizontalAlignment.Center;
- break;
- default:
- ch.TextAlign = HorizontalAlignment.Left;
- break;
- }
- this.listViewData_Selected.Columns.Add( ch );
- }
- this.mlistImage.ImageSize = new Size( 30, 30 );
- this.mlistImage.ColorDepth = ColorDepth.Depth32Bit;
- this.listViewData_Selected.SmallImageList = mlistImage;
- this.CreateListViewGroup();
- this.PublicFunctionRows();
- }
- /// <summary>
- /// 创建默认分组
- /// </summary>
- void CreateListViewGroup()
- {
- 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];
- if ( dtGroup.Rows.Count > 0 )
- {
- for ( int i = 0; i < dtGroup.Rows.Count; i++ )
- {
- if ( this.listViewData_Source.Groups[dtGroup.Rows[i]["Prod_Class"].ToString().Trim()] == null )
- {
- ListViewGroup man_lvg = new ListViewGroup();
- man_lvg.Name = dtGroup.Rows[i]["Prod_Class"].ToString().Trim();
- man_lvg.Header = dtGroup.Rows[i]["Sc_ClassName"].ToString().Trim();
- man_lvg.HeaderAlignment = HorizontalAlignment.Left;
- this.listViewData_Source.Groups.Add( man_lvg );
- man_lvg = new ListViewGroup();
- man_lvg.Name = dtGroup.Rows[i]["Prod_Class"].ToString().Trim();
- man_lvg.Header = dtGroup.Rows[i]["Sc_ClassName"].ToString().Trim();
- man_lvg.HeaderAlignment = HorizontalAlignment.Left;
- this.listViewData_Selected.Groups.Add( man_lvg );
- }
- }
- if ( !this.listViewData_Source.ShowGroups )
- {
- this.listViewData_Source.ShowGroups = true;
- }
- if ( !this.listViewData_Selected.ShowGroups )
- {
- this.listViewData_Selected.ShowGroups = true;
- }
- }
- }
- /// <summary>
- /// 商品类别选择
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void cmbtrrevProductCategory_ComboBoxTree_NodeMouseClick( object sender, TreeNodeMouseClickEventArgs e )
- {
- this.cmbtrrevProductCategory.SelectedNode = this.cmbtrrevProductCategory.GetNodeItem_TextToTag( this.cmbtrrevProductCategory.Text.Trim() );
- this.PublicFunctionRows();
- }
- /// <summary>
- /// 回车查询
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void txtQueryText_KeyDown( object sender, KeyEventArgs e )
- {
- if ( e.KeyCode == Keys.Enter )
- {
- this.PublicFunctionRows();
- }
- }
- /// <summary>
- /// 查询
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void btnQuery_Click( object sender, EventArgs e )
- {
- this.PublicFunctionRows();
- }
- /// <summary>
- /// 报警商品
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void chkAlarmProduct_Click( object sender, EventArgs e )
- {
- this.PublicFunctionRows();
- }
- /// <summary>
- /// 盘点
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void btnStocktaking_Click( object sender, EventArgs e )
- {
- if ( this.listViewData_Source.Items.Count > 0 && this.listViewData_Source.SelectedItems.Count > 0 )
- {
- string StrWhere = "";
- for ( int i = 0; i < this.listViewData_Source.SelectedItems.Count; i++ )
- {
- StrWhere += "'" + this.listViewData_Source.SelectedItems[i].Tag.ToString().Trim() + "',";
- }
- if ( !string.IsNullOrEmpty( StrWhere ) )
- {
- LYFZ.Software.MainBusiness.InventoryManagement.SetSmallForm.InventoryPanDianSmallForm frm = new SetSmallForm.InventoryPanDianSmallForm();
- frm.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
- frm.Location = new Point( LYFZ.EnumPublic.FormLocation_X, LYFZ.EnumPublic.FormLocation_Y );
- frm.Size = new Size( LYFZ.EnumPublic.FormSize_Width, LYFZ.EnumPublic.FormSize_Height );
- frm.StrWhere = StrWhere.TrimEnd( ',' );
- frm.ShowDialog();
- if ( frm.IsSaveed )
- {
- this.PublicFunctionRows();
- }
- }
- }
- }
- /// <summary>
- /// 采购
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void btnPurchaseRequest_Click( object sender, EventArgs e )
- {
- if ( this.listViewData_Selected.Items.Count > 0 )
- {
- for ( int i = 0; i < this.listViewData_Selected.Items.Count; i++ )
- {
- if ( Convert.ToInt32( this.listViewData_Selected.Items[i].SubItems["采购数量"].Text.Trim() ) <= 0 )
- {
- MessageBoxCustom.Show( this.listViewData_Selected.Items[i].Text.Trim() + " 采购数量不能小于等于0!" );
- return;
- }
- }
- DateTime StrTime = SDateTime.Now;
- List<Helper.CommandInfo> clist = new List<Helper.CommandInfo>();
- string StrUserID = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
- #region 增加采购订单表
- string StrPurchaseNumber = LYFZ.BLL.BLL_ErpOrder.GenerateNewPurchaseNumber();
- LYFZ.Model.Model_ErpPurchaseOrder modelOrder = new Model.Model_ErpPurchaseOrder();
- modelOrder.Pord_DividedShop = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetLocalCompanyInfoID();
- modelOrder.Pord_PurchaseNumber = "St" + StrPurchaseNumber;
- modelOrder.Pord_PurchaseName = StrPurchaseNumber + " 采购单";
- modelOrder.Pord_RequisitionName = StrUserID;
- modelOrder.Pord_RequisitionTime = StrTime;
- modelOrder.Pord_ApprovalStatus = "1";
- modelOrder.Pord_ApprovalName = "";
- modelOrder.Pord_ApprovalTime = StrTime;
- modelOrder.Pord_ApprovalRemark = "";
- modelOrder.Pord_PurchaseStatus = "3";
- clist.Add( porbll.GetAddCommandInfo( modelOrder ) );
- #endregion
- #region 增加采购商品表
- LYFZ.Model.Model_ErpPurchaseProduct modelProduct = null;
- for ( int i = 0; i < this.listViewData_Selected.Items.Count; i++ )
- {
- modelProduct = new Model.Model_ErpPurchaseProduct();
- modelProduct.Ppt_PurchaseNumber = modelOrder.Pord_PurchaseNumber;
- modelProduct.Ppt_ProductCategory = this.listViewData_Selected.Items[i].Group.Name.ToString().Trim();
- modelProduct.Ppt_ProductNumber = this.listViewData_Selected.Items[i].Tag.ToString().Trim();
- modelProduct.Ppt_PurchaseQuantity = Convert.ToInt32( this.listViewData_Selected.Items[i].SubItems["采购数量"].Text.Trim() );
- modelProduct.Ppt_PurchaseVendor = "";
- modelProduct.Ppt_PurchasePrice = 0;
- modelProduct.Ppt_PurchaseStatus = "3";
- modelProduct.Ppt_PurchasePerson = "";
- modelProduct.Ppt_PurchaseTime = StrTime;
- modelProduct.Ppt_AcceptanceQuantity = 0;
- modelProduct.Ppt_AcceptanceTime = StrTime;
- modelProduct.Ppt_AcceptanceName = "";
- modelProduct.Ppt_StorageStatus = "0";
- modelProduct.Ppt_Remark = "";
- clist.Add( pptbll.GetAddCommandInfo( modelProduct ) );
- }
- #endregion
- if ( clist.Count > 0 )
- {
- if ( MessageBoxCustom.Show( "你确定采购列表中的商品吗?", "温馨提示", MessageBoxButtons.YesNo ) == DialogResult.No )
- {
- return;
- }
- if ( LYFZ.BLL.BaseBllOperate.ExecuteSqlTran( clist ) > 0 )
- {
- this.IsSaveed = true;
- MessageBoxCustom.Show( "采购成功!采购单号已生成!" );
- for ( int i = 0; i < this.listViewData_Selected.Items.Count; i++ )
- {
- for ( int j = 0; j < this.listViewData_Source.Items.Count; j++ )
- {
- if ( this.listViewData_Source.Items[j].ImageKey.ToString().Trim() == this.listViewData_Selected.Items[i].ImageKey.ToString().Trim() )
- {
- this.listViewData_Source.Items[j].SubItems["申请状态"].Text = "已申请"; break;
- }
- }
- }
- this.listViewData_Selected.Items.Clear();
- }
- else
- {
- MessageBoxCustom.Show( "采购失败!" );
- }
- }
- }
- else
- {
- MessageBoxCustom.Show( "列表中商品不能为空!请添加商品!" );
- }
- }
- /// <summary>
- /// 关闭
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void btnCloseed_Click( object sender, EventArgs e )
- {
- this.Close();
- }
- /// <summary>
- /// 窗体大小变化事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void InventoryDetailFrmMain_Resize( object sender, EventArgs e )
- {
- this.panelEx3.Width = (this.Width / 5) * 3;
- for ( int i = 0; i < this.listViewData_Source.Columns.Count; i++ )
- {
- if ( i == 0 )
- {
- this.listViewData_Source.Columns[i].Width = (((this.listViewData_Source.Width - 23) / 8) * 4) - 5 * 4;
- }
- else
- {
- this.listViewData_Source.Columns[i].Width = ((this.listViewData_Source.Width - 23) / 8) + 5;
- }
- }
- for ( int i = 0; i < this.listViewData_Selected.Columns.Count; i++ )
- {
- if ( i == 0 )
- {
- this.listViewData_Selected.Columns[i].Width = (this.listViewData_Selected.Width - 23) / 4 * 3 - 5;
- }
- else
- {
- this.listViewData_Selected.Columns[i].Width = ((this.listViewData_Selected.Width - 23) / 4) + 5;
- }
- }
- this.panelEx8.Location = new Point( this.panelEx8.Location.X, (this.panelEx4.Height - this.panelEx8.Height) / 2 );
- }
- /// <summary>
- /// 添加
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void btnAdd_Click( object sender, EventArgs e )
- {
- if ( this.listViewData_Source.Items.Count > 0 && this.listViewData_Source.SelectedItems.Count > 0 )
- {
- string StrMagess = "";
- bool IsAdd = false;
- for ( int i = 0; i < this.listViewData_Source.SelectedItems.Count; i++ )
- {
- if ( !string.IsNullOrEmpty( this.listViewData_Source.SelectedItems[i].SubItems["申请状态"].Text.ToString().Trim() ) )
- {
- StrMagess = "1";
- }
- if ( string.IsNullOrEmpty( StrMagess ) )
- {
- bool IsFind = false;
- for ( int j = 0; j < this.listViewData_Selected.Items.Count; j++ )
- {
- if ( this.listViewData_Selected.Items[j].Tag.ToString().Trim() == this.listViewData_Source.SelectedItems[i].Tag.ToString().Trim() )
- {
- IsFind = true;
- }
- }
- if ( !IsFind )
- {
- IsAdd = true;
- ListViewItem lvItem = new ListViewItem();
- lvItem.Tag = this.listViewData_Source.SelectedItems[i].Tag.ToString().Trim();
- lvItem.ImageKey = this.listViewData_Source.SelectedItems[i].Tag.ToString().Trim();
- lvItem.Text = this.listViewData_Source.SelectedItems[i].Text.ToString().Trim();
- ListViewItem.ListViewSubItem ListSubItem = new ListViewItem.ListViewSubItem();
- ListSubItem.Name = "采购数量";
- ListSubItem.Text = "0";
- lvItem.SubItems.Add( ListSubItem );
- if ( this.listViewData_Selected.Groups.Count > 0 )
- {
- this.listViewData_Selected.Groups[this.listViewData_Source.SelectedItems[i].Group.Name.ToString().Trim()].Items.Add( lvItem );
- }
- this.listViewData_Selected.Items.Add( lvItem );
- }
- }
- }
- if ( IsAdd )
- {
- LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.ListViewDrawSingleOrDoubleRows( this.listViewData_Selected );
- }
- if ( !string.IsNullOrEmpty( StrMagess ) )
- {
- MessageBoxCustom.Show( "对于有已在‘采购中’或‘申请中’的商品不能重复采购!" );
- }
- this.listViewData_Source.Select();
- }
- }
- /// <summary>
- /// 移除
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void btnRemove_Click( object sender, EventArgs e )
- {
- if ( this.listViewData_Selected.Items.Count > 0 && this.listViewData_Selected.SelectedItems.Count > 0 )
- {
- List<ListViewItem> delList = new List<ListViewItem>();
- for ( int i = 0; i < this.listViewData_Selected.SelectedItems.Count; i++ )
- {
- delList.Add( this.listViewData_Selected.SelectedItems[i] );
- }
- if ( delList.Count > 0 )
- {
- for ( int i = 0; i < delList.Count; i++ )
- {
- this.listViewData_Selected.Items.Remove( this.listViewData_Selected.SelectedItems[0] );
- }
- LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.ListViewDrawSingleOrDoubleRows( this.listViewData_Selected );
- }
- }
- }
- /// <summary>
- /// 双击源商品选中
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void listViewData_Source_MouseDoubleClick( object sender, MouseEventArgs e )
- {
- if ( this.listViewData_Source.Items.Count > 0 && this.listViewData_Source.SelectedItems.Count > 0 )
- {
- if ( !string.IsNullOrEmpty( this.listViewData_Source.SelectedItems[0].SubItems["申请状态"].Text.ToString().Trim() ) )
- {
- MessageBoxCustom.Show( "商品已在" + this.listViewData_Source.SelectedItems[0].SubItems["申请状态"].Text.ToString().Trim() + ",不能重复采购" ); return;
- }
- bool IsFind = false;
- for ( int i = 0; i < this.listViewData_Selected.Items.Count; i++ )
- {
- if ( this.listViewData_Selected.Items[i].Tag.ToString().Trim() == this.listViewData_Source.SelectedItems[0].Tag.ToString().Trim() )
- {
- IsFind = true;
- }
- }
- if ( !IsFind )
- {
- ListViewItem lvItem = new ListViewItem();
- lvItem.Tag = this.listViewData_Source.SelectedItems[0].Tag.ToString().Trim();
- lvItem.ImageKey = this.listViewData_Source.SelectedItems[0].Tag.ToString().Trim();
- lvItem.Text = this.listViewData_Source.SelectedItems[0].Text.ToString().Trim();
- ListViewItem.ListViewSubItem ListSubItem = new ListViewItem.ListViewSubItem();
- ListSubItem.Name = "采购数量";
- ListSubItem.Text = "0";
- lvItem.SubItems.Add( ListSubItem );
- if ( this.listViewData_Selected.Groups.Count > 0 )
- {
- this.listViewData_Selected.Groups[this.listViewData_Source.SelectedItems[0].Group.Name.ToString().Trim()].Items.Add( lvItem );
- }
- this.listViewData_Selected.Items.Add( lvItem );
- LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.ListViewDrawSingleOrDoubleRows( this.listViewData_Selected );
- }
- }
- }
- /// <summary>
- /// 双击已选择的商品移除
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void listViewData_Selected_MouseDoubleClick( object sender, MouseEventArgs e )
- {
- this.txtText.Visible = false;
- ListViewHitTestInfo info = this.listViewData_Selected.HitTest( e.X, e.Y );
- if ( !string.IsNullOrEmpty( info.SubItem.Name.Trim() ) )
- {
- Rectangle rect = info.SubItem.Bounds;
- switch ( info.SubItem.Name.Trim() )
- {
- case "采购数量":
- this.txtText.Location = new Point( rect.Location.X + this.listViewData_Selected.Location.X + 3, rect.Location.Y + this.listViewData_Selected.Location.Y + 2 );
- this.txtText.Size = rect.Size;
- this.txtText.Visible = true;
- this.txtText.Tag = info.SubItem.Name.Trim();
- this.txtText.Text = info.SubItem.Text.Trim();
- this.txtText.Focus();
- break;
- }
- }
- else
- {
- //DataTable dt = orbll.GetView_Custom("tb_ErpProduct", StrWhere: "Prod_Number = '" + this.listViewData_Selected.SelectedItems[0].Tag.ToString().Trim() + "'", ShowColumnName: "Prod_Thumbnail").Tables[0];
- //if (dt.Rows.Count > 0)
- //{
- // if (!string.IsNullOrEmpty(dt.Rows[0]["Prod_Thumbnail"].ToString().Trim()))
- // {
- // LYFZ.Software.MainBusiness.InitialSet.Product.FrmProductPic frm = new InitialSet.Product.FrmProductPic();
- // frm.FrmImage = LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetImage(LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.StringToByte(dt.Rows[0]["Prod_Thumbnail"].ToString()));
- // frm.ShowDialog();
- // }
- // else
- // { MessageBoxCustom.Show("产品未上传相片!"); return; }
- //}
- if ( this.listViewData_Selected.Items.Count > 0 && this.listViewData_Selected.SelectedItems.Count > 0 )
- {
- this.listViewData_Selected.Items.Remove( this.listViewData_Selected.SelectedItems[0] );
- LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.ListViewDrawSingleOrDoubleRows( this.listViewData_Selected );
- }
- }
- }
- /// <summary>
- /// 右键查看图片
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void listViewData_Source_MouseDown( object sender, MouseEventArgs e )
- {
- if ( e.Button == MouseButtons.Right )
- {
- LYFZ.ComponentLibrary.ContextMenuStripEx contextmenu = new ContextMenuStripEx();
- contextmenu.Name = "Source";
- contextmenu.ItemClicked += contextmenu_ItemClicked;
- //弹出操作菜单
- contextmenu.Items.Clear();
- contextmenu.Show( MousePosition.X, MousePosition.Y );
- if ( this.listViewData_Source.SelectedItems.Count > 0 )
- {
- ToolStripMenuItem item = new ToolStripMenuItem();
- item.Text = "放大(" + this.listViewData_Source.SelectedItems[0].Text.Trim() + ")";
- item.Name = "ZoomView";
- item.Tag = this.listViewData_Source.SelectedItems[0].Tag.ToString().Trim();
- contextmenu.Items.Add( item );
- }
- contextmenu.Show();
- }
- }
- /// <summary>
- /// 右键查看图片
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void listViewData_Selected_MouseDown( object sender, MouseEventArgs e )
- {
- if ( e.Button == MouseButtons.Right )
- {
- LYFZ.ComponentLibrary.ContextMenuStripEx contextmenu = new ContextMenuStripEx();
- contextmenu.Name = "Source";
- contextmenu.ItemClicked += contextmenu_ItemClicked;
- //弹出操作菜单
- contextmenu.Items.Clear();
- contextmenu.Show( MousePosition.X, MousePosition.Y );
- if ( this.listViewData_Selected.SelectedItems.Count > 0 )
- {
- ToolStripMenuItem item = new ToolStripMenuItem();
- item.Text = "放大(" + this.listViewData_Selected.SelectedItems[0].Text.Trim() + ")";
- item.Name = "ZoomView";
- item.Tag = this.listViewData_Selected.SelectedItems[0].Tag.ToString().Trim();
- contextmenu.Items.Add( item );
- }
- contextmenu.Show();
- }
- }
- /// <summary>
- /// 右键菜单选择事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void contextmenu_ItemClicked( object sender, ToolStripItemClickedEventArgs e )
- {
- ToolStripItem item = e.ClickedItem;
- if ( !string.IsNullOrEmpty( item.Text.Trim() ) )
- {
- switch ( item.Name.Trim() )
- {
- case "ZoomView":
- DataTable tbl = orbll.GetView_Custom( "tb_ErpProduct", StrWhere: "Prod_Number = '" + item.Tag.ToString().Trim() + "'", ShowColumnName: "Prod_Thumbnail" ).Tables[0];
- if ( tbl.Rows.Count > 0 )
- {
- if ( !string.IsNullOrEmpty( tbl.Rows[0]["Prod_Thumbnail"].ToString().Trim() ) )
- {
- LYFZ.Software.MainBusiness.InitialSet.Product.FrmProductPic frm = new InitialSet.Product.FrmProductPic();
- frm.FrmImage = LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetImage( LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.StringToByte( tbl.Rows[0]["Prod_Thumbnail"].ToString() ) );
- frm.ShowDialog();
- }
- else
- {
- MessageBoxCustom.Show( "产品未上传相片!" ); return;
- }
- }
- break;
- }
- }
- }
- /// <summary>
- /// 文本框控件离开事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void txtText_Leave( object sender, EventArgs e )
- {
- try
- {
- if ( this.txtText.Tag != null )
- {
- string StrText = "0";
- switch ( this.txtText.Tag.ToString().Trim() )
- {
- case "采购数量":
- if ( !string.IsNullOrEmpty( this.txtText.Text.Trim() ) )
- {
- if ( LYFZ.Command.Command_Validate.IsNumberSign( this.txtText.Text.Trim() ) )
- {
- if ( this.txtText.Text.Trim() == "0" )
- {
- StrText = "0";
- }
- else
- {
- StrText = this.txtText.Text.Trim();
- }
- }
- }
- if ( Convert.ToInt32( StrText ) < 0 )
- {
- MessageBoxCustom.Show( "请输入正确的采购数量!" ); return;
- }
- this.listViewData_Selected.SelectedItems[0].SubItems[this.txtText.Tag.ToString().Trim()].Text = StrText;
- break;
- }
- }
- }
- catch
- {
- }
- this.txtText.Visible = false;
- }
- /// <summary>
- /// 限制输入
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void txtText_KeyPress( object sender, KeyPressEventArgs e )
- {
- if ( !Char.IsNumber( e.KeyChar ) && !Char.IsControl( e.KeyChar ) )
- {
- e.Handled = true;
- }
- }
- /// <summary>
- /// 创建行
- /// </summary>
- void PublicFunctionRows()
- {
- #region 查询条件
- string StrWhere = "Prod_Availability = 1 And Prod_IsEnabled = 1 "; //And Prod_DividedShop = '" + LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetCompanyInfoID() + "'
- if ( !string.IsNullOrEmpty( this.txtQueryText.Text.Trim() ) )
- {
- StrWhere += " and (Prod_Name like '%" + txtQueryText.Text.Trim() + "%' or dbo.fn_ChineseToSpell(Prod_Name) like '%" + txtQueryText.Text.Trim() + "%')";
- }
- if ( this.chkAlarmProduct.Checked )
- {
- StrWhere += " And (Prod_AlarmQuantity >= Prod_Quantity And Prod_AlarmQuantity > 0)";
- }
- if ( this.cmbtrrevProductCategory.Text.Trim() != "全部" && this.cmbtrrevProductCategory.Text.Trim() != "" )
- {
- if ( this.cmbtrrevProductCategory.Nodes.Count > 0 )
- {
- string classString = "'" + this.cmbtrrevProductCategory.Tag.ToString().Trim() + "',";
- for ( int i = 0; i < this.cmbtrrevProductCategory.SelectedNode.Nodes.Count; i++ )
- {
- if ( this.cmbtrrevProductCategory.SelectedNode.Nodes[i].Nodes.Count > 0 )
- {
- for ( int j = 0; j < this.cmbtrrevProductCategory.SelectedNode.Nodes[i].Nodes.Count; j++ )
- {
- if ( this.cmbtrrevProductCategory.SelectedNode.Nodes[i].Nodes[j].Nodes.Count > 0 )
- {
- for ( int k = 0; k < this.cmbtrrevProductCategory.SelectedNode.Nodes[i].Nodes[j].Nodes.Count; k++ )
- {
- classString += "'" + this.cmbtrrevProductCategory.SelectedNode.Nodes[i].Nodes[j].Nodes[k].Tag.ToString().Trim() + "',";
- }
- }
- else
- {
- classString += "'" + this.cmbtrrevProductCategory.SelectedNode.Nodes[i].Nodes[j].Tag.ToString().Trim() + "',";
- }
- }
- }
- else
- {
- classString += "'" + this.cmbtrrevProductCategory.SelectedNode.Nodes[i].Tag.ToString().Trim() + "',";
- }
- }
- StrWhere += " And Prod_Class in(" + classString.TrimEnd( ',' ) + ")";
- }
- }
- #endregion
- this.listViewData_Source.Items.Clear();
- LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod( delegate ( object obj, BackgroundWorker backgroundWorker )
- {
- string StrColumnName =
- "Prod_Number," +
- "Prod_Class," +
- "Prod_Name," +
- "Prod_AlarmQuantity," +
- "Prod_Quantity," +
- "(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 预售数量," +
- " 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 申请状态," +
- "Prod_Thumbnail";
- DataTable dt = orbll.GetView_Custom( "tb_ErpProduct", StrWhere: StrWhere, ShowColumnName: StrColumnName ).Tables[0];
- this.Invoke( new LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.UpdateControl( delegate ()
- {
- int nRealStock = 0;
- int nPreSaleCount = 0;
- for ( int i = 0; i < dt.Rows.Count; i++ )
- {
- if ( !this.mlistImage.Images.Keys.Contains( dt.Rows[i]["Prod_Number"].ToString().Trim() ) )
- {
- Image img = LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetProductImage( dt.Rows[i]["Prod_Thumbnail"].ToString().Trim() );
- this.mlistImage.Images.Add( dt.Rows[i]["Prod_Number"].ToString().Trim(), img );
- }
- ListViewItem lvItem = new ListViewItem();
- lvItem.Tag = dt.Rows[i]["Prod_Number"].ToString().Trim();
- lvItem.ImageKey = dt.Rows[i]["Prod_Number"].ToString().Trim();
- lvItem.Text = dt.Rows[i]["Prod_Name"].ToString().Trim();
- ListViewItem.ListViewSubItem ListSubItem = new ListViewItem.ListViewSubItem();
- ListSubItem.Name = "库存数量";
- ListSubItem.Text = dt.Rows[i]["Prod_Quantity"].ToString().Trim();
- lvItem.SubItems.Add( ListSubItem );
- ListSubItem = new ListViewItem.ListViewSubItem();
- ListSubItem.Name = "报警数量";
- ListSubItem.Text = dt.Rows[i]["Prod_AlarmQuantity"].ToString().Trim();
- lvItem.SubItems.Add( ListSubItem );
- ListSubItem = new ListViewItem.ListViewSubItem();
- ListSubItem.Name = "预售数量";
- ListSubItem.Text = dt.Rows[i]["预售数量"].ToString().Trim();
- lvItem.SubItems.Add( ListSubItem );
- #region 预售库存 = 库存数量 - 预售数量;
- ListSubItem = new ListViewItem.ListViewSubItem();
- ListSubItem.Name = "预售库存";
- nPreSaleCount = 0;
- int.TryParse( dt.Rows[i]["预售数量"].ToString(), out nPreSaleCount );
- nRealStock = 0;
- int.TryParse( dt.Rows[i]["Prod_Quantity"].ToString(), out nRealStock );
- ListSubItem.Text = (nRealStock - nPreSaleCount).ToString();
- lvItem.SubItems.Add( ListSubItem );
- #endregion
- ListSubItem = new ListViewItem.ListViewSubItem();
- ListSubItem.Name = "申请状态";
- ListSubItem.Text = dt.Rows[i]["申请状态"].ToString().Trim();
- lvItem.SubItems.Add( ListSubItem );
- if ( Convert.ToInt32( dt.Rows[i]["Prod_Quantity"] ) <= Convert.ToInt32( dt.Rows[i]["Prod_AlarmQuantity"] ) )
- {
- lvItem.ForeColor = Color.Red;
- }
- if ( this.listViewData_Source.Groups.Count > 0 )
- {
- this.listViewData_Source.Groups[dt.Rows[i]["Prod_Class"].ToString().Trim()].Items.Add( lvItem );
- }
- this.listViewData_Source.Items.Add( lvItem );
- }
- } ) );
- } );
- LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.ListViewDrawSingleOrDoubleRows( this.listViewData_Source );
- }
- }
- }
|