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( "导出失败!" );
}
}
} ) );
} );
}
///
/// 是否保存
///
public bool IsSaveed = false;
///
/// 相片集合
///
ImageList mlistImage = new ImageList();
///
/// 窗体加载事件
///
///
///
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);
}
///
/// 窗体加载事件
///
///
///
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();
}
///
/// 创建默认分组
///
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;
}
}
}
///
/// 商品类别选择
///
///
///
void cmbtrrevProductCategory_ComboBoxTree_NodeMouseClick( object sender, TreeNodeMouseClickEventArgs e )
{
this.cmbtrrevProductCategory.SelectedNode = this.cmbtrrevProductCategory.GetNodeItem_TextToTag( this.cmbtrrevProductCategory.Text.Trim() );
this.PublicFunctionRows();
}
///
/// 回车查询
///
///
///
void txtQueryText_KeyDown( object sender, KeyEventArgs e )
{
if ( e.KeyCode == Keys.Enter )
{
this.PublicFunctionRows();
}
}
///
/// 查询
///
///
///
void btnQuery_Click( object sender, EventArgs e )
{
this.PublicFunctionRows();
}
///
/// 报警商品
///
///
///
void chkAlarmProduct_Click( object sender, EventArgs e )
{
this.PublicFunctionRows();
}
///
/// 盘点
///
///
///
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();
}
}
}
}
///
/// 采购
///
///
///
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 clist = new List();
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( "列表中商品不能为空!请添加商品!" );
}
}
///
/// 关闭
///
///
///
void btnCloseed_Click( object sender, EventArgs e )
{
this.Close();
}
///
/// 窗体大小变化事件
///
///
///
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 );
}
///
/// 添加
///
///
///
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();
}
}
///
/// 移除
///
///
///
void btnRemove_Click( object sender, EventArgs e )
{
if ( this.listViewData_Selected.Items.Count > 0 && this.listViewData_Selected.SelectedItems.Count > 0 )
{
List delList = new List();
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 );
}
}
}
///
/// 双击源商品选中
///
///
///
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 );
}
}
}
///
/// 双击已选择的商品移除
///
///
///
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 );
}
}
}
///
/// 右键查看图片
///
///
///
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();
}
}
///
/// 右键查看图片
///
///
///
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();
}
}
///
/// 右键菜单选择事件
///
///
///
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;
}
}
}
///
/// 文本框控件离开事件
///
///
///
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;
}
///
/// 限制输入
///
///
///
void txtText_KeyPress( object sender, KeyPressEventArgs e )
{
if ( !Char.IsNumber( e.KeyChar ) && !Char.IsControl( e.KeyChar ) )
{
e.Handled = true;
}
}
///
/// 创建行
///
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 );
}
}
}