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 FrmDelivery : LYFZ.Software.UI.InventoryManagement.FrmDelivery
{
private delegate void UpdateControl();
public FrmDelivery()
{
this.ucPagerEx1.EventPaging += ucPagerEx1_EventPaging;
this.dgv1.CellMouseDown += dgv1_CellMouseDown;
this.dgv1.DataGridViewConMenu_ItemClicked += dgv1_DataGridViewConMenu_ItemClicked;
this.dgv2.CellMouseDown += dgv2_CellMouseDown;
this.dgv2.DataGridViewConMenu_ItemClicked += dgv2_DataGridViewConMenu_ItemClicked;
}
#region 加载
protected override void FrmDelivery_Shown(object sender, EventArgs e)
{
this.CtvSelect.TextFindTag("全部");
bind();
SelectGoods();
btnLibrary.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.DeliveryCompetence, CustomAttributes.OperatingAuthority.Delivery);
btnDelete.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.DeliveryCompetence, CustomAttributes.OperatingAuthority.Delete);
}
#region 获取所有商品
///
/// 获取所有商品
///
public void bind()
{
this.ucPagerEx1.PageCurrent = 1;
this.ucPagerEx1.PageSize = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetPageSize();//3;分页条数
this.ucPagerEx1.Bind();
}
#endregion
#region 获取出库记录表
///
/// 获取出库记录表
///
public void GetProductOutStorage()
{
this.ucPagerEx1.PageCurrent = 1;
this.ucPagerEx1.PageSize = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetPageSize();//3;分页条数
this.ucPagerEx1.Bind();
}
#endregion
#endregion
#region 新增出库
protected override void btnLibrary_Click(object sender, EventArgs e)
{
try
{
if (dgv1.SelectedRows.Count == 0)
{
MessageBoxCustom.Show("请选择你要出库的商品!");
return;
}
for (int t = 0; t < dgv1.SelectedRows.Count; t++)
{
int Prod_Quantity = Convert.ToInt32(dgv1.SelectedRows[t].Cells["Pos_OutQuantity"].Value);
string Ir_ProductName = dgv1.SelectedRows[t].Cells["Ir_ProductName"].Value.ToString();
if (Prod_Quantity == 0)
{
MessageBoxCustom.Show(Ir_ProductName + " 出库数量不能0,请输入!");
return;
}
}
for (int i = 0; i < dgv1.SelectedRows.Count; i++)
{
#region 新增出库记录表
LYFZ.Model.Model_ErpProductOutStorage ProductOutStorageModel = new Model.Model_ErpProductOutStorage();
LYFZ.BLL.BLL_ErpProductOutStorage ProductOutStorageBll = new BLL.BLL_ErpProductOutStorage();
ProductOutStorageModel.Pos_DividedShop = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetCompanyInfoID();
ProductOutStorageModel.Pos_ProductCategory = dgv1.SelectedRows[i].Cells["Pos_ProductCategory"].Value.ToString();
ProductOutStorageModel.Pos_ProductNumber = dgv1.SelectedRows[i].Cells["Pos_ProductNumber"].Value.ToString();
ProductOutStorageModel.Pos_OutQuantity = Convert.ToInt32(dgv1.SelectedRows[i].Cells["Pos_OutQuantity"].Value);
ProductOutStorageModel.Pos_OutTime = Convert.ToDateTime(LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetServerDateTime().ToString("yyyy-MM-dd"));
ProductOutStorageModel.Pos_Remark = dgv1.SelectedRows[i].Cells["Pos_Remark"].Value.ToString();
ProductOutStorageModel.Pos_OutName = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
ProductOutStorageBll.Add(ProductOutStorageModel);
#endregion
#region 更新商品库存数量
string Prod_Number = dgv1.SelectedRows[i].Cells["Pos_ProductNumber"].Value.ToString();
int Prod_Quantity = Convert.ToInt32(dgv1.SelectedRows[i].Cells["Pos_OutQuantity"].Value);
LYFZ.BLL.BLL_ErpProduct ProductBll = new BLL.BLL_ErpProduct();
DataTable dt = ProductBll.GetList("Prod_Number='" + Prod_Number + "'").Tables[0];
int sum = Convert.ToInt32(dt.Rows[0]["Prod_Quantity"]) - Prod_Quantity;
ProductBll.UpdateProduct("Prod_Quantity=" + sum + "", Prod_Number);
#endregion
}
//绑定数据表
bind();
MessageBoxCustom.Show("出库成功!");
}
catch (Exception ex)
{
MessageBoxCustom.Show(ex.Message);
}
}
#endregion
#region 只能输入数字
protected override void dgv1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
try
{
if (dgv1.Rows.Count > 0)
{
if (dgv1.CurrentRow.Cells["Pos_OutQuantity"].Value == null)
{
MessageBoxCustom.Show("出库数量不能为空!");
dgv1.CurrentRow.Cells["Pos_OutQuantity"].Value = "0";
return;
}
if (Command.Command_Validate.IsNumber(dgv1.CurrentRow.Cells["Pos_OutQuantity"].Value.ToString()) == false)
{
MessageBoxCustom.Show("只能输入纯数字!");
//int id = Convert.ToInt32(dgv1.CurrentRow.Cells["ID"].Value);
//LYFZ.BLL.BLL_ErpProduct bll = new BLL.BLL_ErpProduct();
dgv1.CurrentRow.Cells["Pos_OutQuantity"].Value = "0";//bll.GetList("ID=" + id + "").Tables[0].Rows[0]["Prod_Quantity"].ToString();
return;
}
}
}
catch (Exception ex)
{
MessageBoxCustom.Show(ex.Message);
}
}
#endregion
#region 出库
protected override void radLibrary_Click(object sender, EventArgs e)
{
try
{
dgv2.Visible = false;
dgv1.Visible = true;
btnLibrary.Visible = true;
btnDelete.Visible = false;
//绑定数据表
bind();
}
catch (Exception ex)
{
MessageBoxCustom.Show(ex.Message);
}
}
#endregion
#region 出库记录
protected override void radLibraryRecord_Click(object sender, EventArgs e)
{
try
{
dgv2.Visible = true;
dgv1.Visible = false;
btnLibrary.Visible = false;
btnDelete.Visible = true;
//绑定数据表
GetProductOutStorage();
}
catch (Exception ex)
{
MessageBoxCustom.Show(ex.Message);
}
}
#endregion
#region 绑定查询商品类别
///
/// 绑定查询商品类别
///
public void SelectGoods()
{
CtvSelect.TreeView.Nodes.Clear();
#region 绑定二级商品类别
LYFZ.BLL.BLL_ErpSystemCategory BLLSystemCategory = new BLL.BLL_ErpSystemCategory();
DataTable tbl = BLLSystemCategory.GetList("Sc_ClassParentID='1'").Tables[0];
if (tbl.Rows.Count > 0)
{
TreeNode root = null;
for (int i = 0; i < tbl.Rows.Count; i++)
{
if (i == 0)
{
root = new TreeNode("全部");
this.CtvSelect.TreeView.Nodes.Add(root);
}
root = new TreeNode();
root.Text = tbl.Rows[i]["Sc_ClassName"].ToString();
root.Tag = tbl.Rows[i]["Sc_ClassCode"].ToString();
this.CreateTreeViewShop(root.Nodes, tbl.Rows[i]["ID"].ToString());
this.CtvSelect.TreeView.Nodes.Add(root);
}
}
#endregion
}
#endregion
#region 绑定三级商品类别
#region 绑定第三级商品类别
///
/// 绑定第三级商品类别
///
/// TreeView的节点集合
/// 数据源
///
private void CreateTreeViewShop(TreeNodeCollection nodes, string ClassCode)
{
if (ClassCode != "")
{
LYFZ.BLL.BLL_ErpSystemCategory BLLSystemCategory = new BLL.BLL_ErpSystemCategory();
DataTable tbl = BLLSystemCategory.GetList("Sc_ClassParentID=" + ClassCode + "").Tables[0];
if (tbl.Rows.Count > 0)
{
TreeNode node;
for (int i = 0; i < tbl.Rows.Count; i++)
{
node = new TreeNode();
node.Text = tbl.Rows[i]["Sc_ClassName"].ToString();
node.Tag = tbl.Rows[i]["Sc_ClassCode"].ToString();
nodes.Add(node);
}
}
}
}
#endregion
#endregion
#region 商品查询
protected override void CtvSelect_ComboBoxTreeViewEx_TextChanged(object sender, TreeViewEventArgs e)
{
try
{
bind();
GetProductOutStorage();
}
catch (Exception ex)
{
MessageBoxCustom.Show(ex.Message);
}
}
#endregion
#region 画分页
///
/// 画分页
///
///
///
private int ucPagerEx1_EventPaging(UCPager.EventPagingArg e)
{
#region 出库
if (radLibrary.Checked)
{
dgv1.Rows.Clear();
DataTable dt = new DataTable();
StringBuilder str = new StringBuilder();
if (CtvSelect.Text == "" || CtvSelect.Tag == null || CtvSelect.Text == "全部")
{
str.Append(" 1=1 and Prod_IsEnabled='1' and Prod_Availability=1"); //and Prod_DividedShop='" + LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetCompanyInfoID() + "'
}
if (CtvSelect.Tag != null)
{
str.Append(" 1=1 and Prod_IsEnabled='1' and Prod_Class='" + CtvSelect.Tag.ToString() + "' and Prod_Availability=1"); //and Prod_DividedShop='" + LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetCompanyInfoID() + "'
}
LYFZ.UCPager.PageData pageData = new LYFZ.UCPager.PageData();
LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
{
pageData.TableName = "View_tb_ErpProduct";
pageData.PageIndex = this.ucPagerEx1.PageCurrent;
pageData.PageSize = this.ucPagerEx1.PageSize;
pageData.QueryCondition = str.ToString();
pageData.QueryFieldName = "ID,Prod_Number,Prod_DividedShop,Prod_Name,Prod_Class,Prod_Unit,Prod_CostPrice,Prod_SalesPrice,Prod_SpecialPrice,Prod_AlarmQuantity,Prod_IsEnabled,Prod_Quantity,Prod_Expedited,Prod_CreateDatetime,Prod_PreSaleQuantity,Prod_Batch,Prod_ClassName,Sc_ClassCode,Prod_ClassName2,Prod_IsEnabledName,Prod_Availability";
pageData.OrderStr = " ID desc ";
DataSet da = pageData.QueryDataTable();
dt = da.Tables[0];
if (dt.Rows.Count > 0)
{
this.Invoke(new UpdateControl(delegate()
{
#region
for (int t = 0; t < dt.Rows.Count; t++)
{
DataGridViewRow dgvr = new DataGridViewRow();
DataGridViewCell cell = null;
cell = new DataGridViewTextBoxCell();
cell.Value = dt.Rows[t]["ID"].ToString().Trim();
dgvr.Cells.Add(cell);
cell = new DataGridViewTextBoxCell();
cell.Value = dt.Rows[t]["Prod_Name"].ToString().Trim();
dgvr.Cells.Add(cell);
cell = new DataGridViewTextBoxCell();
cell.Value = dt.Rows[t]["Prod_Quantity"].ToString().Trim();
dgvr.Cells.Add(cell);
cell = new DataGridViewTextBoxCell();
cell.Value = dt.Rows[t]["Prod_ClassName"].ToString().Trim();
dgvr.Cells.Add(cell);
cell = new DataGridViewTextBoxCell();
cell.Value = dt.Rows[t]["Prod_AlarmQuantity"].ToString().Trim();
dgvr.Cells.Add(cell);
cell = new DataGridViewTextBoxCell();
cell.Value = dt.Rows[t]["Prod_PreSaleQuantity"].ToString().Trim();
dgvr.Cells.Add(cell);
cell = new DataGridViewTextBoxCell();
cell.Value = "0";
dgvr.Cells.Add(cell);
cell = new DataGridViewTextBoxCell();
cell.Value = "";
dgvr.Cells.Add(cell);
cell = new DataGridViewTextBoxCell();
cell.Value = dt.Rows[t]["Prod_Class"].ToString().Trim();
dgvr.Cells.Add(cell);
cell = new DataGridViewTextBoxCell();
cell.Value = dt.Rows[t]["Prod_Number"].ToString().Trim();
dgvr.Cells.Add(cell);
this.dgv1.Rows.Add(dgvr);
dgv1.ClearSelection();
}
#endregion
}));
}
#region 变色
for (int i = 0; i < dgv1.Rows.Count; i++)
{
int Prod_Quantity = Convert.ToInt32(dgv1.Rows[i].Cells["Prod_Quantity"].Value);
int Prod_AlarmQuantity = Convert.ToInt32(dgv1.Rows[i].Cells["Prod_AlarmQuantity"].Value);
if (Prod_Quantity <= Prod_AlarmQuantity)
{
this.dgv1.Rows[i].DefaultCellStyle.ForeColor = Color.Red;
}
}
#endregion
});
try
{
this.ucPagerEx1.TbDataSource = dt;
}
catch { }
return pageData.TotalCount;
}
#endregion
#region 出库记录
if (radLibraryRecord.Checked)
{
dgv2.Rows.Clear();
DataTable dt = new DataTable();
StringBuilder str = new StringBuilder();
if (CtvSelect.Text == "" || CtvSelect.Tag == null || CtvSelect.Text == "全部")
{
str.Append(" 1=1 and Pos_DividedShop='" + LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetCompanyInfoID() + "' ");
}
if (CtvSelect.Tag != null)
{
str.Append(" 1=1 and Pos_ProductCategory='" + CtvSelect.Tag.ToString() + "' and Pos_DividedShop='" + LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetCompanyInfoID() + "' ");
}
LYFZ.UCPager.PageData pageData = new LYFZ.UCPager.PageData();
LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
{
pageData.TableName = "View_ErpProductOutStorage";
pageData.PageIndex = this.ucPagerEx1.PageCurrent;
pageData.PageSize = this.ucPagerEx1.PageSize;
pageData.QueryCondition = str.ToString();
pageData.QueryFieldName = "ID,Pos_DividedShop,Pos_ProductCategory,Pos_ProductNumber,Pos_OutQuantity,Pos_OutTime,Pos_OutNameID,Pos_OutName,Pos_Remark,Pos_ProductCategoryName,Pos_ProductNumberName";
pageData.OrderStr = " ID desc ";
DataSet da = pageData.QueryDataTable();
dt = da.Tables[0];
if (dt.Rows.Count > 0)
{
this.Invoke(new UpdateControl(delegate()
{
#region
for (int t = 0; t < dt.Rows.Count; t++)
{
DataGridViewRow dgvr = new DataGridViewRow();
DataGridViewCell cell = null;
cell = new DataGridViewTextBoxCell();
cell.Value = dt.Rows[t]["ID"].ToString().Trim();
dgvr.Cells.Add(cell);
cell = new DataGridViewTextBoxCell();
cell.Value = dt.Rows[t]["Pos_ProductCategory"].ToString().Trim();
dgvr.Cells.Add(cell);
cell = new DataGridViewTextBoxCell();
cell.Value = dt.Rows[t]["Pos_ProductNumber"].ToString().Trim();
dgvr.Cells.Add(cell);
cell = new DataGridViewTextBoxCell();
cell.Value = dt.Rows[t]["Pos_ProductCategoryName"].ToString().Trim();
dgvr.Cells.Add(cell);
cell = new DataGridViewTextBoxCell();
cell.Value = dt.Rows[t]["Pos_ProductNumberName"].ToString().Trim();
dgvr.Cells.Add(cell);
cell = new DataGridViewTextBoxCell();
cell.Value = dt.Rows[t]["Pos_OutQuantity"].ToString().Trim();
dgvr.Cells.Add(cell);
cell = new DataGridViewTextBoxCell();
cell.Value = dt.Rows[t]["Pos_OutName"].ToString().Trim();
dgvr.Cells.Add(cell);
cell = new DataGridViewTextBoxCell();
cell.Value = Convert.ToDateTime(dt.Rows[t]["Pos_OutTime"]).ToString("yyyy-MM-dd").Trim();
dgvr.Cells.Add(cell);
cell = new DataGridViewTextBoxCell();
cell.Value = dt.Rows[t]["Pos_Remark"].ToString().Trim();
dgvr.Cells.Add(cell);
this.dgv2.Rows.Add(dgvr);
dgv2.ClearSelection();
}
#endregion
}));
}
});
try
{
this.ucPagerEx1.TbDataSource = dt;
}
catch { }
return pageData.TotalCount;
}
#endregion
return 0;
}
#endregion
#region 删除
protected override void btnDelete_Click(object sender, EventArgs e)
{
try
{
if (this.dgv2.SelectedRows.Count == 0)
{
MessageBoxCustom.Show("请选中你要删除的数据!");
return;
}
LYFZ.BLL.BLL_ErpProductOutStorage ProductOutStoragbll = new BLL.BLL_ErpProductOutStorage();
LYFZ.BLL.BLL_ErpProduct Productbll = new BLL.BLL_ErpProduct();
DataTable dt = new DataTable();
if (MessageBoxCustom.Show("你确定要删除吗?", "删除提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
int id = Convert.ToInt32(this.dgv2.CurrentRow.Cells["dataGridViewTextBoxColumn1"].Value);
string Pro_number = dgv2.CurrentRow.Cells["dataGridViewTextBoxColumn9"].Value.ToString();
int Quantity = Convert.ToInt32(this.dgv2.CurrentRow.Cells["dataGridViewTextBoxColumn4"].Value);
//删除出库记录
if (ProductOutStoragbll.Delete(id))
{
#region 更新商品库存数量
//获取商品数量
dt = Productbll.GetList("Prod_Number='" + Pro_number + "'").Tables[0];
if (dt.Rows.Count > 0)
{
int Count = Convert.ToInt32(Convert.ToInt32(dt.Rows[0]["Prod_Quantity"]) + Quantity);
Productbll.UpdateProduct("Prod_Quantity=" + Count + "", Pro_number);
}
#endregion
}
MessageBoxCustom.Show("删除成功!");
GetProductOutStorage();
}
}
catch (Exception ex)
{
MessageBoxCustom.Show(ex.Message);
}
}
#endregion
///
/// 右键菜单点击
///
///
///
void dgv1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
ToolStripMenuItem item = null;
item = new ToolStripMenuItem();
item.Text = "查看商品图片";
item.Tag = "View";
this.dgv1.conMenu.Items.Add(item);
}
}
void dgv1_DataGridViewConMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
ToolStripItem item = e.ClickedItem;
if (item.Tag.ToString().Trim() == "View")
{
LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.ProductViewPhoto(this.dgv1.CurrentRow.Cells["Pos_ProductNumber"].Value.ToString().Trim());
}
}
///
/// 右键菜单点击
///
///
///
void dgv2_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
ToolStripMenuItem item = null;
item = new ToolStripMenuItem();
item.Text = "查看商品图片";
item.Tag = "View";
this.dgv2.conMenu.Items.Add(item);
}
}
void dgv2_DataGridViewConMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
ToolStripItem item = e.ClickedItem;
if (item.Tag.ToString().Trim() == "View")
{
LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.ProductViewPhoto(this.dgv2.CurrentRow.Cells["dataGridViewTextBoxColumn9"].Value.ToString().Trim());
}
}
}
}