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.SetSmallForm
{
public partial class InventoryPanDianSmallForm : LYFZ.Software.UI.InventoryManagement.SetSmallForm.InventoryPanDianSmallForm
{
LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder();
LYFZ.BLL.BLL_ErpProduct ptbll = new BLL.BLL_ErpProduct();
public InventoryPanDianSmallForm()
{
this.Load += InventoryPanDianSmallForm_Load;
this.Shown += InventoryPanDianSmallForm_Shown;
this.btnSaveed.Click += btnSaveed_Click;
this.btnClose.Click += btnClose_Click;
this.listViewData.MouseDoubleClick += listViewData_MouseDoubleClick;
this.txtText.Leave += txtText_Leave;
this.txtText.KeyPress += txtText_KeyPress;
}
///
/// 是否保存
///
public bool IsSaveed = false;
///
/// 条件
///
public string StrWhere = "";
///
/// 相片集合
///
ImageList mlistImage = new ImageList();
///
/// 窗体加载事件
///
///
///
void InventoryPanDianSmallForm_Load(object sender, EventArgs e)
{
this.listViewData.View = View.Details;
this.listViewData.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 = 400; }
else if (i == 1)
{ ch.Width = 200; }
else
{ ch.Width = this.listViewData.Width - 600 - 23; }
switch (StrColumns[i].Trim())
{
case "库存数量":
ch.TextAlign = HorizontalAlignment.Center;
break;
default:
ch.TextAlign = HorizontalAlignment.Left;
break;
}
this.listViewData.Columns.Add(ch);
}
this.mlistImage.ImageSize = new Size(30, 30);
this.mlistImage.ColorDepth = ColorDepth.Depth32Bit;
this.listViewData.SmallImageList = mlistImage;
this.CreateListViewGroup();
}
///
/// 窗体加载事件
///
///
///
void InventoryPanDianSmallForm_Shown(object sender, EventArgs e)
{
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.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.Groups.Add(man_lvg);
}
}
if (!this.listViewData.ShowGroups)
{ this.listViewData.ShowGroups = true; }
}
}
///
/// 保存
///
///
///
void btnSaveed_Click(object sender, EventArgs e)
{
if (this.listViewData.Items.Count > 0)
{
LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
{
DateTime StrTime = SDateTime.Now;
string StrUserID = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
List clist = new List();
this.Invoke(new LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.UpdateControl(delegate()
{
for (int i = 0; i < this.listViewData.Items.Count; i++)
{
if (this.listViewData.Items[i].SubItems["库存数量"].Tag != null)
{
LYFZ.Model.Model_ErpProduct model = ptbll.GetModel(Convert.ToInt32(this.listViewData.Items[i].Tag));
model.Prod_Quantity = Convert.ToInt32(this.listViewData.Items[i].SubItems["库存数量"].Text.Trim());
model.Prod_UpdateDateTime = StrTime;
model.Prod_UpdateName = StrUserID;
clist.Add(ptbll.GetUpdateCommandInfo(model));
}
}
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.Items.Count; i++)
{
this.listViewData.Items[i].SubItems["库存数量"].Tag = null;
}
}
}
else
{
MessageBoxCustom.Show("没有做任何修改,无须保存!");
}
}));
});
}
}
///
/// 关闭
///
///
///
void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// 双击事件
///
///
///
void listViewData_MouseDoubleClick(object sender, MouseEventArgs e)
{
this.txtText.Visible = false;
ListViewHitTestInfo info = this.listViewData.HitTest(e.X, e.Y);
if (info.SubItem != null)
{
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.Location.X + 3, rect.Location.Y + this.listViewData.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.SelectedItems[0].ImageKey.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; }
}
}
}
}
///
/// 敲开事件
///
///
///
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(); }
}
}
this.listViewData.SelectedItems[0].SubItems[this.txtText.Tag.ToString().Trim()].Text = StrText;
this.listViewData.SelectedItems[0].SubItems[this.txtText.Tag.ToString().Trim()].Tag = "1";
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()
{
this.listViewData.Items.Clear();
if (!string.IsNullOrEmpty(this.StrWhere))
{
LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
{
DataTable dt = orbll.GetView_Custom("tb_ErpProduct", StrWhere: "Prod_Number in (" + this.StrWhere + ")", ShowColumnName: "ID,Prod_Number,Prod_Class,Prod_Name,Prod_Quantity,Prod_Thumbnail").Tables[0];
this.Invoke(new LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.UpdateControl(delegate()
{
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]["ID"].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);
if (this.listViewData.Groups.Count > 0)
{ this.listViewData.Groups[dt.Rows[i]["Prod_Class"].ToString().Trim()].Items.Add(lvItem); }
this.listViewData.Items.Add(lvItem);
}
}));
});
LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.ListViewDrawSingleOrDoubleRows(this.listViewData);
}
}
}
}