123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505 |
- using LYFZ.ComponentLibrary;
- using System;
- using System.Collections;
- 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.PurchasingManagement
- {
- public partial class FrmPurchase : LYFZ.Software.UI.InventoryManagement.PurchasingManagement.FrmPurchase
- {
- private delegate void UpdateControl();
- bool bl = false;
- public string Pord_PurchaseNumber;
- public FrmPurchase()
- {
- this.FormClosed += FrmPurchase_FormClosed;
- this.dgv1.CellMouseDown += dgv1_CellMouseDown;
- this.dgv1.DataGridViewConMenu_ItemClicked += dgv1_DataGridViewConMenu_ItemClicked;
- }
- void FrmPurchase_FormClosed(object sender, FormClosedEventArgs e)
- {
- if (bl)
- { this.DialogResult = DialogResult.OK; }
- }
- /// <summary>
- /// 窗体加载事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void FrmPurchase_Shown(object sender, EventArgs e)
- {
- //绑定数据表
- GetPurchaseProduct(Pord_PurchaseNumber);
- BindVendor();
- }
- /// <summary>
- /// 获取采购商品表
- /// </summary>
- public void GetPurchaseProduct(string Ppt_PurchaseNumber)
- {
- dgv1.Rows.Clear();
- LYFZ.BLL.BLL_ErpPurchaseProduct PurchaseProductbll = new BLL.BLL_ErpPurchaseProduct();
- DataTable dt = PurchaseProductbll.View_tb_PurchaseProduct(" and Ppt_PurchaseNumber='" + Ppt_PurchaseNumber + "'").Tables[0];
- if (dt.Rows.Count > 0)
- {
- LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
- {
- 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]["Ppt_PurchaseNumber"].ToString().Trim();
- dgvr.Cells.Add(cell);
- cell = new DataGridViewTextBoxCell();
- cell.Value = dt.Rows[t]["Ppt_ProductNumberName"].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 = dt.Rows[t]["Ppt_ProductCategoryName"].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);
- cell = new DataGridViewTextBoxCell();
- if (dt.Rows[t]["Ppt_PurchasePrice"].ToString().Trim() == "0.00")
- { cell.Value = dt.Rows[t]["Prod_CostPrice"].ToString().Trim(); }
- else
- { cell.Value = dt.Rows[t]["Ppt_PurchasePrice"].ToString().Trim(); }
- dgvr.Cells.Add(cell);
- cell = new DataGridViewTextBoxCell();
- cell.Value = dt.Rows[t]["Ppt_PurchaseVendor"].ToString().Trim();
- dgvr.Cells.Add(cell);
- cell = new DataGridViewTextBoxCell();
- if (dt.Rows[t]["Ppt_PurchaseStatus"].ToString().Trim() == "0")
- {
- cell.Value = LYFZ.EnumPublic.Ppt_PurchaseStatus.采购中.ToString();
- dgvr.DefaultCellStyle.ForeColor = Color.Orange;
- }
- else if (dt.Rows[t]["Ppt_PurchaseStatus"].ToString().Trim() == "1")
- { cell.Value = LYFZ.EnumPublic.Ppt_PurchaseStatus.采购完成.ToString(); }
- else if (dt.Rows[t]["Ppt_PurchaseStatus"].ToString().Trim() == "2")
- { cell.Value = LYFZ.EnumPublic.Ppt_PurchaseStatus.采购取消.ToString(); }
- else if (dt.Rows[t]["Ppt_PurchaseStatus"].ToString().Trim() == "3")
- {
- cell.Value = LYFZ.EnumPublic.Ppt_PurchaseStatus.申请中.ToString();
- dgvr.DefaultCellStyle.ForeColor = Color.Orange;
- }
- dgvr.Cells.Add(cell);
- cell = new DataGridViewTextBoxCell();
- cell.Value = dt.Rows[t]["Ppt_PurchasePerson"].ToString().Trim();
- dgvr.Cells.Add(cell);
- cell = new DataGridViewTextBoxCell();
- cell.Value = Convert.ToDateTime(dt.Rows[t]["Ppt_PurchaseTime"]).ToString("yyyy-MM-dd").Trim();
- dgvr.Cells.Add(cell);
- this.dgv1.Rows.Add(dgvr);
- }
- dgv1.ClearSelection();
- }));
- });
- }
- }
- /// <summary>
- /// 采购
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void btnPurchase_Click(object sender, EventArgs e)
- {
- try
- {
- if (dgv1.SelectedRows.Count == 0)
- {
- MessageBoxCustom.Show("请选择采购的商品!可多选!");
- return;
- }
- LYFZ.BLL.BLL_ErpPurchaseProduct PurchaseProductBll = new BLL.BLL_ErpPurchaseProduct();
- if (dgv1.SelectedRows.Count > 0)
- {
- #region 判断商品厂商不能为空
- for (int i = 0; i < dgv1.SelectedRows.Count; i++)
- {
- string Ppt_PurchaseVendor = dgv1.SelectedRows[i].Cells["Ppt_PurchaseVendor"].Value.ToString();
- if (string.IsNullOrEmpty(Ppt_PurchaseVendor))
- {
- MessageBoxCustom.Show("商品厂商不能为空!");
- return;
- }
- }
- #endregion
- #region 判断采购完成不能修改
- for (int i = 0; i < dgv1.SelectedRows.Count; i++)
- {
- string Status = dgv1.SelectedRows[i].Cells["Status"].Value.ToString();
- string Ir_ProductName = dgv1.SelectedRows[i].Cells["Ir_ProductName"].Value.ToString();
- if (Status.ToString() == "采购完成")
- {
- MessageBoxCustom.Show(Ir_ProductName + " 已经" + Status + "不能修改!");
- return;
- }
- }
- #endregion
- #region 修改采购商品表
- for (int i = 0; i < dgv1.SelectedRows.Count; i++)
- {
- int id = Convert.ToInt32(dgv1.SelectedRows[i].Cells["ID"].Value);
- LYFZ.Model.Model_ErpPurchaseProduct PurchaseProductModel = PurchaseProductBll.GetModel(id);
- PurchaseProductModel.Ppt_PurchaseQuantity = Convert.ToInt32(dgv1.SelectedRows[i].Cells["Prod_Quantity"].Value);
- PurchaseProductModel.Ppt_PurchasePrice = Convert.ToDecimal(dgv1.SelectedRows[i].Cells["Ppt_PurchasePrice"].Value);
- PurchaseProductModel.Ppt_PurchaseVendor = dgv1.SelectedRows[i].Cells["Ppt_PurchaseVendor"].Value.ToString();
- PurchaseProductModel.Ppt_PurchaseStatus = "0";
- PurchaseProductModel.Ppt_PurchasePerson = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_Name;
- PurchaseProductModel.Ppt_PurchaseTime = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetServerDateTime();
- PurchaseProductBll.Update(PurchaseProductModel);
- }
- #endregion
- #region 修改采购订单表状态
- PurchaseProductBll.UpdateCgDd("0", Pord_PurchaseNumber);
- #endregion
- }
- GetPurchaseProduct(Pord_PurchaseNumber);
- bl = true;
- MessageBoxCustom.Show("保存成功!");
- }
- catch (Exception ex)
- { MessageBoxCustom.Show(ex.Message); }
- }
- /// <summary>
- /// 不采购
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void btnNotPurchase_Click(object sender, EventArgs e)
- {
- try
- {
- LYFZ.BLL.BLL_ErpPurchaseProduct PurchaseProductBll = new BLL.BLL_ErpPurchaseProduct();
- if (dgv1.SelectedRows.Count == 0)
- {
- MessageBoxCustom.Show("请选择不采购的商品!可多选!");
- return;
- }
- #region 判断采购完成不能修改
- for (int i = 0; i < dgv1.SelectedRows.Count; i++)
- {
- string Status = dgv1.SelectedRows[i].Cells["Status"].Value.ToString();
- string Ir_ProductName = dgv1.SelectedRows[i].Cells["Ir_ProductName"].Value.ToString();
- if (Status.ToString() == "采购完成")
- {
- MessageBoxCustom.Show(Ir_ProductName + " 已经" + Status + "不能修改!");
- return;
- }
- }
- #endregion
- #region 更新采购商品表状态
- for (int i = 0; i < dgv1.SelectedRows.Count; i++)
- {
- int Id = Convert.ToInt32(dgv1.SelectedRows[i].Cells["ID"].Value);
- PurchaseProductBll.UpdatePpt_PurchaseStatus("Ppt_PurchaseStatus='2',Ppt_PurchasePerson='" + LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_Name + "',Ppt_PurchaseTime='" + LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetServerDateTime().ToString("yyyy-MM-dd") + "' ", Id);
- }
- #endregion
- #region 更新采购订单表状态
- int sum = PurchaseProductBll.GetCount("Ppt_PurchaseNumber='" + Pord_PurchaseNumber + "'");
- int Qx = PurchaseProductBll.GetCount("Ppt_PurchaseNumber='" + Pord_PurchaseNumber + "' and Ppt_PurchaseStatus='2'");
- if (sum == Qx)
- {
- PurchaseProductBll.UpdateCgDd("2", Pord_PurchaseNumber);
- }
- #endregion
- GetPurchaseProduct(Pord_PurchaseNumber);
- bl = true;
- MessageBoxCustom.Show("保存成功!");
- }
- catch (Exception ex)
- { MessageBoxCustom.Show(ex.Message); }
- }
- /// <summary>
- /// 保存更改数量
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void btnSave_Click(object sender, EventArgs e)
- {
- try
- {
- if (dgv1.Rows.Count > 0)
- {
- if (MessageBoxCustom.Show("你确定修改采购列表中的商品吗?", "增加提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
- {
- #region 修改采购商品表
- for (int i = 0; i < dgv1.Rows.Count; i++)
- {
- string Status = dgv1.Rows[i].Cells["Status"].Value.ToString();
- string Ir_ProductName = dgv1.Rows[i].Cells["Ir_ProductName"].Value.ToString();
- if (Status.ToString() == "采购完成")
- {
- MessageBoxCustom.Show(Ir_ProductName + " 已经" + Status + "不能修改!");
- return;
- }
- int id = Convert.ToInt32(dgv1.Rows[i].Cells["ID"].Value);
- LYFZ.BLL.BLL_ErpPurchaseProduct PurchaseProductBll = new BLL.BLL_ErpPurchaseProduct();
- LYFZ.Model.Model_ErpPurchaseProduct PurchaseProductModel = PurchaseProductBll.GetModel(id);
- PurchaseProductModel.Ppt_PurchaseQuantity = Convert.ToInt32(dgv1.Rows[i].Cells["Prod_Quantity"].Value);
- PurchaseProductModel.Ppt_PurchasePrice = Convert.ToDecimal(dgv1.Rows[i].Cells["Ppt_PurchasePrice"].Value);
- PurchaseProductModel.Ppt_PurchaseVendor = dgv1.Rows[i].Cells["Ppt_PurchaseVendor"].Value.ToString();
- PurchaseProductBll.Update(PurchaseProductModel);
- }
- GetPurchaseProduct(Pord_PurchaseNumber);
- MessageBoxCustom.Show("保存成功!");
- #endregion
- }
- }
- }
- catch (Exception ex)
- { MessageBoxCustom.Show(ex.Message); }
- }
- /// <summary>
- /// 关闭
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void btnClose_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- /// <summary>
- /// 只能输入数字
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void dgv1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
- {
- try
- {
- if (dgv1.Rows.Count > 0)
- {
- if (dgv1.CurrentRow.Cells["Prod_Quantity"].Value == null)
- {
- MessageBoxCustom.Show("采购数量不能为空!");
- int id = Convert.ToInt32(dgv1.CurrentRow.Cells["ID"].Value);
- LYFZ.BLL.BLL_ErpPurchaseProduct bll = new BLL.BLL_ErpPurchaseProduct();
- dgv1.CurrentRow.Cells["Prod_Quantity"].Value = bll.GetList("ID=" + id + "").Tables[0].Rows[0]["Ppt_PurchaseQuantity"].ToString();
- return;
- }
- if (dgv1.CurrentRow.Cells["Ppt_PurchasePrice"].Value == null)
- {
- MessageBoxCustom.Show("商品单价不能为空!");
- string Prod_Number = dgv1.CurrentRow.Cells["Prod_Number"].Value.ToString();
- LYFZ.BLL.BLL_ErpProduct Productbll = new BLL.BLL_ErpProduct();
- dgv1.CurrentRow.Cells["Ppt_PurchasePrice"].Value = Productbll.GetList("Prod_Number='" + Prod_Number + "'").Tables[0].Rows[0]["Prod_CostPrice"].ToString();
- return;
- }
- 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_ErpPurchaseProduct bll = new BLL.BLL_ErpPurchaseProduct();
- dgv1.CurrentRow.Cells["Prod_Quantity"].Value = bll.GetList("ID=" + id + "").Tables[0].Rows[0]["Ppt_PurchaseQuantity"].ToString();
- return;
- }
- if (Command.Command_Validate.IsNumeric(dgv1.CurrentRow.Cells["Ppt_PurchasePrice"].Value.ToString()) == false)
- {
- MessageBoxCustom.Show("只能输入数字或者小数!");
- string Prod_Number = dgv1.CurrentRow.Cells["Prod_Number"].Value.ToString();
- LYFZ.BLL.BLL_ErpProduct Productbll = new BLL.BLL_ErpProduct();
- dgv1.CurrentRow.Cells["Ppt_PurchasePrice"].Value = Productbll.GetList("Prod_Number='" + Prod_Number + "'").Tables[0].Rows[0]["Prod_CostPrice"].ToString();
- return;
- }
- }
- }
- catch (Exception ex)
- {
- MessageBoxCustom.Show(ex.Message);
- }
- }
- //<summary>
- //绑定商品厂商
- //</summary>
- public void BindVendor()
- {
- LYFZ.BLL.BLL_ErpOrder Orderbll = new BLL.BLL_ErpOrder();
- DataTable dt = Orderbll.GetView_Custom("tb_ErpVendor", StrWhere: "", ShowColumnName: "distinct Vd_Name").Tables[0];
- if (dt.Rows.Count > 0)
- {
- this.cmbFactory.DataSource = dt;
- this.cmbFactory.ValueMember = "Vd_Name";
- this.cmbFactory.DisplayMember = "Vd_Name";
- cmbFactory.SelectedIndex = -1;
- }
- }
- /// <summary>
- /// 选择商品厂商
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void cmbFactory_SelectedIndexChanged(object sender, EventArgs e)
- {
- for (int i = 0; i < dgv1.SelectedRows.Count; i++)
- {
- dgv1.SelectedRows[i].Cells["Ppt_PurchaseVendor"].Value = cmbFactory.Text;
- }
- }
- /// <summary>
- /// 导出
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void btnExport_Click(object sender, EventArgs e)
- {
- if (dgv1.Rows.Count > 0)
- {
- dgv1.ExportDataTable();
- }
- }
- /// <summary>
- /// 打印
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void btnPrint_Click(object sender, EventArgs e)
- {
- if (dgv1.Rows.Count == 0)
- {
- MessageBoxCustom.Show("无打印数据!");
- return;
- }
- Hashtable htData = new Hashtable();
- htData["dgvData"] = this.dgv1;
- LYFZ.Software.MainBusiness.ReportPrint.ReportFixedFormat.PrintFixedFormat(LYFZ.EnumPublic.PrintTypeEnum.库存采购单, htData);
- }
- /// <summary
- /// dgv控件里面塞下拉框
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void dgv1_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
- {
- if (this.dgv1.Rows.Count > 0)
- {
- if (this.dgv1.CurrentCell.ColumnIndex == this.dgv1.Columns["Ppt_PurchaseVendor"].Index)
- {
- DataGridViewCell cell = this.dgv1.Rows[e.RowIndex].Cells[e.ColumnIndex];
- Rectangle rect = this.dgv1.GetCellDisplayRectangle(cell.ColumnIndex, cell.RowIndex, true);
- this.cmbFactory.Location = new Point(rect.Location.X + this.dgv1.Location.X, rect.Location.Y + this.dgv1.Location.Y);
- this.cmbFactory.Size = rect.Size;
- if (cell.Value != null)
- { this.cmbFactory.Text = (string)cell.Value; }
- this.cmbFactory.Visible = true;
- this.cmbFactory.Focus();
- }
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void cmbFactory_Leave(object sender, EventArgs e)
- {
- this.dgv1.CurrentRow.Cells["Ppt_PurchaseVendor"].Value = this.cmbFactory.Text.Trim();
- this.cmbFactory.Visible = false;
- }
- /// <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);
- item = new ToolStripMenuItem();
- item.Text = "取消厂商";
- item.Tag = "Cancel";
- this.dgv1.conMenu.Items.Add(item);
- item = new ToolStripMenuItem();
- item.Text = "选择厂商";
- item.Tag = "Select";
- 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["Prod_Number"].Value.ToString().Trim());
- }
- else if (item.Tag.ToString().Trim() == "Select")
- {
- LYFZ.Software.MainBusiness.InventoryManagement.PurchasingManagement.FrmSelectManufacturer set = new FrmSelectManufacturer();
- set.ShowDialog();
- if (!string.IsNullOrEmpty(set.NumberSjName))
- {
- for (int i = 0; i < dgv1.SelectedRows.Count; i++)
- { dgv1.SelectedRows[i].Cells["Ppt_PurchaseVendor"].Value = set.NumberSjName; }
- }
- }
- else if (item.Tag.ToString().Trim() == "Cancel")
- {
- if (MessageBoxCustom.Show("您确定要取消厂商吗?", "温馨提示", MessageBoxButtons.YesNo) == DialogResult.No)
- { return; }
- for (int i = 0; i < dgv1.SelectedRows.Count; i++)
- { dgv1.SelectedRows[i].Cells["Ppt_PurchaseVendor"].Value = ""; }
- }
- }
- }
- }
|