123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590 |
- 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 获取所有商品
- /// <summary>
- /// 获取所有商品
- /// </summary>
- public void bind()
- {
- this.ucPagerEx1.PageCurrent = 1;
- this.ucPagerEx1.PageSize = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetPageSize();//3;分页条数
- this.ucPagerEx1.Bind();
- }
- #endregion
- #region 获取出库记录表
- /// <summary>
- /// 获取出库记录表
- /// </summary>
- 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 绑定查询商品类别
- /// <summary>
- /// 绑定查询商品类别
- /// </summary>
- 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 绑定第三级商品类别
- /// <summary>
- /// 绑定第三级商品类别
- /// </summary>
- /// <param name="nodes">TreeView的节点集合</param>
- /// <param name="dataSource">数据源</param>
- /// <param name="parentid"></param>
- 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 画分页
- /// <summary>
- /// 画分页
- /// </summary>
- /// <param name="e"></param>
- /// <returns></returns>
- 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
- /// <summary>
- /// 右键菜单点击
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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());
- }
- }
- /// <summary>
- /// 右键菜单点击
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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());
- }
- }
- }
- }
|