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 FrmPurchaseOrder : LYFZ.Software.UI.InventoryManagement.FrmPurchaseOrder { public FrmPurchaseOrder() { } private DataTable tbl_View = new DataTable(); #region 加载 protected override void FrmPurchaseOrder_Shown(object sender, EventArgs e) { try { bind(); radKsq_Click(sender, e); } catch (Exception ex) { MessageBoxCustom.Show(ex.Message); } } #region 获取报警商品 /// /// 获取报警商品 /// public void bind() { dgv1.Rows.Clear(); #region 获取报警商品 LYFZ.BLL.BLL_ErpProduct Productbll = new BLL.BLL_ErpProduct(); DataTable dt = Productbll.View_tb_ErpProduct("Prod_Quantity<=Prod_AlarmQuantity and Prod_IsEnabled='1'").Tables[0]; if (dt.Rows.Count > 0) { for (int t = 0; t < dt.Rows.Count; t++) { LYFZ.BLL.BLL_ErpPurchaseProduct PurchaseProductBll = new BLL.BLL_ErpPurchaseProduct(); DataTable dal = new DataTable(); dal = PurchaseProductBll.GetList("Ppt_ProductNumber='" + dt.Rows[t]["Prod_Number"].ToString().Trim() + "' and (Ppt_PurchaseStatus='0' or Ppt_PurchaseStatus='3') ").Tables[0]; 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(); if (dal.Rows.Count > 0) { if (dal.Rows[0]["Ppt_PurchaseStatus"].ToString().Trim() == "0" || dal.Rows[0]["Ppt_PurchaseStatus"].ToString().Trim() == "3") { dal = PurchaseProductBll.GetList("Ppt_ProductNumber='" + dt.Rows[t]["Prod_Number"].ToString() + "'").Tables[0]; cell.Value = dal.Rows[0]["Ppt_PurchaseQuantity"].ToString(); } } else { cell.Value = "0"; } //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 = 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); cell = new DataGridViewTextBoxCell(); if (dal.Rows.Count > 0) { if (dal.Rows[0]["Ppt_PurchaseStatus"].ToString().Trim() == "0") { cell.Value = LYFZ.EnumPublic.Ppt_PurchaseStatus.采购中.ToString(); } if (dal.Rows[0]["Ppt_PurchaseStatus"].ToString().Trim() == "1") { cell.Value = LYFZ.EnumPublic.Ppt_PurchaseStatus.采购完成.ToString(); } if (dal.Rows[0]["Ppt_PurchaseStatus"].ToString().Trim() == "2") { cell.Value = LYFZ.EnumPublic.Ppt_PurchaseStatus.采购取消.ToString(); } if (dal.Rows[0]["Ppt_PurchaseStatus"].ToString().Trim() == "3") { cell.Value = LYFZ.EnumPublic.Ppt_PurchaseStatus.申请中.ToString(); } } else { cell.Value = "可申请"; } dgvr.Cells.Add(cell); this.dgv1.Rows.Add(dgvr); } for (int i = 0; i < dgv1.Rows.Count; i++) { string Ppt_PurchaseStatus = dgv1.Rows[i].Cells["Status"].Value.ToString(); if (Ppt_PurchaseStatus.ToString() == LYFZ.EnumPublic.Ppt_PurchaseStatus.采购中.ToString() || Ppt_PurchaseStatus.ToString() == LYFZ.EnumPublic.Ppt_PurchaseStatus.申请中.ToString()) { this.dgv1.Rows[i].DefaultCellStyle.ForeColor = Color.YellowGreen; } } lblcount.Text = dgv1.Rows.Count.ToString(); dgv1.ClearSelection(); } #endregion tbl_View = GetDgvToTable(dgv1); } #endregion #region 获取已申请商品 /// /// 获取已申请商品 /// public void GetYsq() { dgv1.Rows.Clear(); #region 获取采购商品表 LYFZ.BLL.BLL_ErpPurchaseProduct PurchaseProductbll = new BLL.BLL_ErpPurchaseProduct(); DataTable dt = PurchaseProductbll.GetList("Ppt_PurchaseStatus='3' or Ppt_PurchaseStatus='0'").Tables[0]; if (dt.Rows.Count > 0) { 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 = PurchaseProductbll.GetProductName(dt.Rows[t]["Ppt_ProductNumber"].ToString().Trim()); dgvr.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["Ppt_PurchaseQuantity"].ToString().Trim(); dgvr.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = PurchaseProductbll.GetProductCategory(dt.Rows[t]["Ppt_ProductCategory"].ToString().Trim()); dgvr.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = ""; dgvr.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = ""; dgvr.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["Ppt_ProductCategory"].ToString().Trim(); dgvr.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["Ppt_ProductNumber"].ToString().Trim(); dgvr.Cells.Add(cell); #region 采购状态 cell = new DataGridViewTextBoxCell(); if (dt.Rows[t]["Ppt_PurchaseStatus"].ToString().Trim() == "0") { cell.Value = LYFZ.EnumPublic.Ppt_PurchaseStatus.采购中.ToString(); } if (dt.Rows[t]["Ppt_PurchaseStatus"].ToString().Trim() == "1") { cell.Value = LYFZ.EnumPublic.Ppt_PurchaseStatus.采购完成.ToString(); } if (dt.Rows[t]["Ppt_PurchaseStatus"].ToString().Trim() == "2") { cell.Value = LYFZ.EnumPublic.Ppt_PurchaseStatus.采购取消.ToString(); } if (dt.Rows[t]["Ppt_PurchaseStatus"].ToString().Trim() == "3") { cell.Value = LYFZ.EnumPublic.Ppt_PurchaseStatus.申请中.ToString(); } dgvr.Cells.Add(cell); #endregion this.dgv1.Rows.Add(dgvr); } #region 变色 for (int i = 0; i < dgv1.Rows.Count; i++) { string Ppt_PurchaseStatus = dgv1.Rows[i].Cells["Status"].Value.ToString(); if (Ppt_PurchaseStatus.ToString() == LYFZ.EnumPublic.Ppt_PurchaseStatus.采购中.ToString() || Ppt_PurchaseStatus.ToString() == LYFZ.EnumPublic.Ppt_PurchaseStatus.申请中.ToString()) { this.dgv1.Rows[i].DefaultCellStyle.ForeColor = Color.YellowGreen; } } #endregion dgv1.ClearSelection(); } #endregion lblcount.Text = dgv1.Rows.Count.ToString(); } #endregion #endregion #region 只能输入数字 protected override void dgv1_CellValueChanged(object sender, DataGridViewCellEventArgs e) { try { if (dgv1.Rows.Count > 0) { if (Command.Command_Validate.IsNumber(dgv1.CurrentRow.Cells["Prod_Quantity"].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["Prod_Quantity"].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 btnProductSelection_Click(object sender, EventArgs e) { try { LYFZ.Software.MainBusiness.InventoryManagement.FrmProductSearch set = new FrmProductSearch(); set.ShowDialog(); if (set.ListArray.Count > 0) { for (int y = 0; y < set.ListArray.Count; y++) { for (int u = 0; u < dgv1.Rows.Count; u++) { string sp=set.ListArray[y].ToString(); if (sp.ToString() == dgv1.Rows[u].Cells["Prod_Number"].Value.ToString()) { MessageBoxCustom.Show("【"+dgv1.Rows[u].Cells["Ir_ProductName"].Value.ToString()+ "】"+ " 商品已经存在列表,不能增加!"); return; } } } for (int i = 0; i < set.ListArray.Count; i++) { #region 获取所有商品 LYFZ.BLL.BLL_ErpProduct Productbll = new BLL.BLL_ErpProduct(); DataTable dt = Productbll.View_tb_ErpProduct(" Prod_Number='" + set.ListArray[i] + "' ").Tables[0]; if (dt.Rows.Count > 0) { 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 = "0"; //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 = 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); cell = new DataGridViewTextBoxCell(); LYFZ.BLL.BLL_ErpPurchaseProduct PurchaseProductBll = new BLL.BLL_ErpPurchaseProduct(); DataTable dal = new DataTable(); dal = PurchaseProductBll.GetList("Ppt_ProductNumber='" + dt.Rows[t]["Prod_Number"].ToString().Trim() + "' and (Ppt_PurchaseStatus='0' or Ppt_PurchaseStatus='3') ").Tables[0]; if (dal.Rows.Count > 0) { if (dal.Rows[0]["Ppt_PurchaseStatus"].ToString().Trim() == "0") { cell.Value = LYFZ.EnumPublic.Ppt_PurchaseStatus.采购中.ToString(); } if (dal.Rows[0]["Ppt_PurchaseStatus"].ToString().Trim() == "1") { cell.Value = LYFZ.EnumPublic.Ppt_PurchaseStatus.采购完成.ToString(); } if (dal.Rows[0]["Ppt_PurchaseStatus"].ToString().Trim() == "2") { cell.Value = LYFZ.EnumPublic.Ppt_PurchaseStatus.采购取消.ToString(); } if (dal.Rows[0]["Ppt_PurchaseStatus"].ToString().Trim() == "3") { cell.Value = LYFZ.EnumPublic.Ppt_PurchaseStatus.申请中.ToString(); } } else { cell.Value = "可申请"; } dgvr.Cells.Add(cell); this.dgv1.Rows.Add(dgvr); } lblcount.Text = dgv1.Rows.Count.ToString(); dgv1.ClearSelection(); } #endregion } } } catch (Exception ex) { MessageBoxCustom.Show(ex.Message); } } #endregion #region 删除 protected override void btndelete_Click(object sender, EventArgs e) { if (dgv1.SelectedCells.Count == 0) { MessageBoxCustom.Show("请选择你要删除的数据!"); return; } string Status = dgv1.CurrentRow.Cells["Status"].Value.ToString(); if (Status.ToString() == "可申请") { if (MessageBoxCustom.Show("你确定要删除吗?", "删除提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { dgv1.Rows.RemoveAt(dgv1.CurrentRow.Index); lblcount.Text = dgv1.Rows.Count.ToString(); } } else { MessageBoxCustom.Show("此商品正在 " + Status + " 不能删除!"); } } #endregion #region 关闭 protected override void btnClose_Click(object sender, EventArgs e) { this.Close(); } #endregion #region 采购 protected override void btnSave_Click(object sender, EventArgs e) { try { #region 检查商品是否可以申请采购 for (int i = 0; i < dgv1.Rows.Count; i++) { string Ir_ProductName = dgv1.Rows[i].Cells["Ir_ProductName"].Value.ToString(); string Status = dgv1.Rows[i].Cells["Status"].Value.ToString(); if (Status.ToString() == LYFZ.EnumPublic.Ppt_PurchaseStatus.采购中.ToString() || Status.ToString() == LYFZ.EnumPublic.Ppt_PurchaseStatus.申请中.ToString()) { MessageBoxCustom.Show(Ir_ProductName + " 正在" + Status + "不能采购!"); return; } } #endregion #region 增加采购单 if (dgv1.Rows.Count > 0) { if (MessageBoxCustom.Show("你确定采购列表中的商品吗?", "增加提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { #region 增加采购订单表 LYFZ.Model.Model_ErpPurchaseOrder PurchaseOrderModel = new Model.Model_ErpPurchaseOrder(); LYFZ.BLL.BLL_ErpPurchaseOrder PurchaseOrderBll = new BLL.BLL_ErpPurchaseOrder(); Random action = new Random(); PurchaseOrderModel.Pord_DividedShop = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetLocalCompanyInfoID(); PurchaseOrderModel.Pord_PurchaseNumber = "St" + LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetServerDateTime().ToString("yyyyMMddHHmmss") + action.Next(100, 1000); PurchaseOrderModel.Pord_PurchaseName = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetServerDateTime().ToString("yyyy-MM-dd") + " 采购单"; PurchaseOrderModel.Pord_RequisitionName = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID; PurchaseOrderModel.Pord_RequisitionTime = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetServerDateTime(); PurchaseOrderModel.Pord_ApprovalStatus = "1"; PurchaseOrderModel.Pord_ApprovalName = ""; PurchaseOrderModel.Pord_ApprovalTime = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetServerDateTime(); PurchaseOrderModel.Pord_ApprovalRemark = ""; PurchaseOrderModel.Pord_PurchaseStatus = "3"; PurchaseOrderBll.Add(PurchaseOrderModel); #endregion #region 增加采购商品表 LYFZ.Model.Model_ErpPurchaseProduct PurchaseProductModel = new Model.Model_ErpPurchaseProduct(); LYFZ.BLL.BLL_ErpPurchaseProduct PurchaseProductBll = new BLL.BLL_ErpPurchaseProduct(); for (int i = 0; i < dgv1.Rows.Count; i++) { PurchaseProductModel.Ppt_PurchaseNumber = PurchaseOrderModel.Pord_PurchaseNumber; PurchaseProductModel.Ppt_ProductCategory = dgv1.Rows[i].Cells["Prod_Class"].Value.ToString(); PurchaseProductModel.Ppt_ProductNumber = dgv1.Rows[i].Cells["Prod_Number"].Value.ToString(); PurchaseProductModel.Ppt_PurchaseQuantity = Convert.ToInt32(dgv1.Rows[i].Cells["Prod_Quantity"].Value); PurchaseProductModel.Ppt_PurchaseVendor = ""; PurchaseProductModel.Ppt_PurchasePrice = 0; PurchaseProductModel.Ppt_PurchaseStatus = "3"; PurchaseProductModel.Ppt_PurchasePerson = ""; PurchaseProductModel.Ppt_PurchaseTime = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetServerDateTime(); PurchaseProductModel.Ppt_AcceptanceQuantity = 0; PurchaseProductModel.Ppt_AcceptanceTime = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetServerDateTime(); PurchaseProductModel.Ppt_AcceptanceName = ""; PurchaseProductModel.Ppt_StorageStatus = "0"; PurchaseProductModel.Ppt_Remark = ""; PurchaseProductBll.Add(PurchaseProductModel); } #endregion MessageBoxCustom.Show("保存成功!采购单号已生成!"); this.Close(); } } else { MessageBoxCustom.Show("列表中商品不能为空!请添加商品!"); } #endregion } catch (Exception ex) { MessageBoxCustom.Show(ex.Message); } } #endregion #region C#如何从DataGridView控件数据,转成获取DataTable public DataTable GetDgvToTable(DataGridView dgv) { DataTable dt = new DataTable(); for (int count = 0; count < dgv.Columns.Count; count++) { DataColumn dc = new DataColumn(dgv.Columns[count].Name.ToString()); dt.Columns.Add(dc); } for (int count = 0; count < dgv.Rows.Count; count++) { DataRow dr = dt.NewRow(); for (int countsub = 0; countsub < dgv.Columns.Count; countsub++) { dr[countsub] = Convert.ToString(dgv.Rows[count].Cells[countsub].Value); } dt.Rows.Add(dr); } return dt; } #endregion #region 已申请 protected override void radAll_Click(object sender, EventArgs e) { GetYsq(); } #endregion #region 可申请 protected override void radKsq_Click(object sender, EventArgs e) { dgv1.Rows.Clear(); if (tbl_View.Rows.Count > 0) { DataRow[] dtr = tbl_View.Select("Status='可申请'"); #region for (int i = 0; i < dtr.Length; i++) { DataGridViewRow dgvl = new DataGridViewRow(); DataGridViewCell cell = null; cell = new DataGridViewTextBoxCell(); cell.Value = dtr[i][0].ToString(); dgvl.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = dtr[i][1].ToString(); dgvl.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = dtr[i][2].ToString(); dgvl.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = dtr[i][3].ToString(); dgvl.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = dtr[i][4].ToString(); dgvl.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = dtr[i][5].ToString(); dgvl.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = dtr[i][6].ToString(); dgvl.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = dtr[i][7].ToString(); dgvl.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = dtr[i][8].ToString(); dgvl.Cells.Add(cell); dgv1.Rows.Add(dgvl); } #endregion } lblcount.Text = dgv1.Rows.Count.ToString(); dgv1.ClearSelection(); } #endregion } }