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 FrmReceipt : LYFZ.Software.UI.InventoryManagement.FrmReceipt { private delegate void UpdateControl(); public FrmReceipt() { this.ucPagerEx1.EventPaging += ucPagerEx1_EventPaging; this.dgv2.CellMouseDown += dgv2_CellMouseDown; this.dgv2.DataGridViewConMenu_ItemClicked += dgv2_DataGridViewConMenu_ItemClicked; } protected override void FrmReceipt_Shown(object sender, EventArgs e) { SelectGoods(); //绑定数据表 GetProductIntStorage(); btnWarehousing.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.ReceiptCompetence, CustomAttributes.OperatingAuthority.Receipt); btnDelete.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.ReceiptCompetence, CustomAttributes.OperatingAuthority.Delete); } /// /// 获取入库记录表 /// public void GetProductIntStorage() { this.ucPagerEx1.PageCurrent = 1; this.ucPagerEx1.PageSize = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetPageSize();//3;分页条数 this.ucPagerEx1.Bind(); } /// /// 新增入库 /// /// /// protected override void btnWarehousing_Click(object sender, EventArgs e) { LYFZ.Software.MainBusiness.InventoryManagement.Receipt.FrmWarehousing set = new Receipt.FrmWarehousing(); if (set.ShowDialog() == DialogResult.OK) { GetProductIntStorage(); } } /// /// 绑定查询商品类别 /// public void SelectGoods() { CtvSelect.TreeView.Nodes.Clear(); 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); } } } /// /// 绑定第三级商品类别 /// /// 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); } } } } /// /// 商品查询 /// /// /// protected override void CtvSelect_ComboBoxTreeViewEx_TextChanged(object sender, TreeViewEventArgs e) { GetProductIntStorage(); } /// /// 画分页 /// /// /// private int ucPagerEx1_EventPaging(UCPager.EventPagingArg e) { dgv2.Rows.Clear(); DataTable dt = new DataTable(); StringBuilder str = new StringBuilder(); if (CtvSelect.Text == "" || CtvSelect.Tag == null || CtvSelect.Text == "全部") { str.Append(" 1=1 and Pis_DividedShop='" + LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetCompanyInfoID() + "'"); } else if (CtvSelect.Tag != null) { str.Append(" 1=1 and Pis_ProductCategory='" + CtvSelect.Tag.ToString() + "' and Pis_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_ErpProductIntStorage"; pageData.PageIndex = this.ucPagerEx1.PageCurrent; pageData.PageSize = this.ucPagerEx1.PageSize; pageData.QueryCondition = str.ToString(); pageData.QueryFieldName = "ID,Pis_DividedShop,Pis_ProductCategory,Pis_ProductNumber,Pis_PurchaseQuantity,Pis_PurchaseVendor,Pis_PurchasePrice,Pis_Remark,Pis_CreateDatetime,Pis_CreateNameId,Pis_CreateName,Pis_ProductCategoryName ,Pis_ProductNumberName"; pageData.OrderStr = " ID desc "; DataSet da = pageData.QueryDataTable(); dt = da.Tables[0]; if (dt.Rows.Count > 0) { this.Invoke(new UpdateControl(delegate() { 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]["Pis_ProductCategory"].ToString().Trim(); dgvr.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["Pis_ProductNumber"].ToString().Trim(); dgvr.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["Pis_ProductCategoryName"].ToString().Trim(); dgvr.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["Pis_ProductNumberName"].ToString().Trim(); dgvr.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["Pis_PurchaseQuantity"].ToString().Trim(); dgvr.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["Pis_PurchaseVendor"].ToString().Trim(); dgvr.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["Pis_PurchasePrice"].ToString().Trim(); dgvr.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["Pis_Remark"].ToString().Trim(); dgvr.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["Pis_CreateName"].ToString().Trim(); dgvr.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = Convert.ToDateTime(dt.Rows[t]["Pis_CreateDatetime"]).ToString("yyyy-MM-dd").Trim(); dgvr.Cells.Add(cell); this.dgv2.Rows.Add(dgvr); dgv2.ClearSelection(); } })); } }); try { this.ucPagerEx1.TbDataSource = dt; } catch { } return pageData.TotalCount; } /// /// 删除 /// /// /// protected override void btnDelete_Click(object sender, EventArgs e) { try { if (this.dgv2.SelectedRows.Count == 0) { MessageBoxCustom.Show("请选中你要删除的数据!"); return; } LYFZ.BLL.BLL_ErpProductIntStorage ProductIntStoragebll = new BLL.BLL_ErpProductIntStorage(); 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["ID"].Value); string Pro_number = dgv2.CurrentRow.Cells["Pro_number"].Value.ToString(); int Quantity = Convert.ToInt32(this.dgv2.CurrentRow.Cells["Quantity"].Value); //删除入库记录 if (ProductIntStoragebll.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("删除成功!"); GetProductIntStorage(); } } catch (Exception ex) { MessageBoxCustom.Show(ex.Message); } } /// /// 右键菜单选择事件 /// /// /// 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["Pro_number"].Value.ToString().Trim()); } } } }