123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 |
- 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
- {
- public partial class FrmProcurementApplication : LYFZ.Software.UI.InventoryManagement.FrmProcurementApplication
- {
- LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder();
- LYFZ.BLL.BLL_ErpPurchaseOrder porbll = new BLL.BLL_ErpPurchaseOrder();
- LYFZ.BLL.BLL_ErpPurchaseProduct porptbll = new BLL.BLL_ErpPurchaseProduct();
- private delegate void UpdateControl();
- public FrmProcurementApplication()
- {
- this.btnDeleteOrder.Click += btnDeleteOrder_Click;
- }
- /// <summary>
- /// 加载
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void FrmProcurementApplication_Shown(object sender, EventArgs e)
- {
- this.dgv1.Rows.Clear();
- this.dgv2.Rows.Clear();
- string StrWhere = "";
- if (!string.IsNullOrEmpty(this.cmbPord_PurchaseStatus.Text))
- {
- if (this.cmbPord_PurchaseStatus.Text == "采购中")
- { StrWhere = "Pord_PurchaseStatus='0'"; }
- else if (this.cmbPord_PurchaseStatus.Text == "采购完成")
- { StrWhere = "Pord_PurchaseStatus='1'"; }
- else if (this.cmbPord_PurchaseStatus.Text == "采购取消")
- { StrWhere = "Pord_PurchaseStatus='2'"; }
- else if (this.cmbPord_PurchaseStatus.Text == "申请中")
- { StrWhere = "Pord_PurchaseStatus='3'"; }
- }
- else
- { StrWhere = "Pord_PurchaseStatus='3' or Pord_PurchaseStatus='0'"; }
- DataTable dt = orbll.GetView_Custom("tb_ErpPurchaseOrder Left Join tb_ErpUser on User_EmployeeID = Pord_RequisitionName", StrWhere: StrWhere, ShowColumnName: "tb_ErpPurchaseOrder.ID,Pord_PurchaseNumber AS 采购单号,User_Name AS 采购申请人,dbo.fn_CheckDateTime(Pord_RequisitionTime) AS 申请采购时间,Pord_PurchaseStatus AS 采购状态").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]["采购单号"].ToString().Trim();
- dgvr.Cells.Add(cell);
- cell = new DataGridViewTextBoxCell();
- LYFZ.BLL.BLL_ErpUser ErpUserBll = new BLL.BLL_ErpUser();
- cell.Value = dt.Rows[t]["采购申请人"].ToString().Trim();
- dgvr.Cells.Add(cell);
- cell = new DataGridViewTextBoxCell();
- cell.Value = dt.Rows[t]["申请采购时间"].ToString().Trim();
- dgvr.Cells.Add(cell);
- cell = new DataGridViewTextBoxCell();
- cell.Value = Enum.GetName(typeof(LYFZ.EnumPublic.Ppt_PurchaseStatus), Convert.ToInt32(dt.Rows[t]["采购状态"]));
- dgvr.Cells.Add(cell);
- if (dt.Rows[t]["采购状态"].ToString().Trim() == "0" || dt.Rows[t]["采购状态"].ToString().Trim() == "1")
- { dgvr.DefaultCellStyle.ForeColor = Color.Orange; }
- this.dgv2.Rows.Add(dgvr);
- }
- this.dgv2.ClearSelection();
- }
- }
- /// <summary>
- /// 查询采购订单
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void cmbPord_PurchaseStatus_SelectedIndexChanged(object sender, EventArgs e)
- {
- this.FrmProcurementApplication_Shown(this, null);
- }
- /// <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 dgv2_Click(object sender, EventArgs e)
- {
- if (this.dgv2.Rows.Count > 0)
- {
- this.dgv1.Rows.Clear();
- DataTable dt = orbll.GetView_Custom("tb_ErpPurchaseProduct Left Join tb_ErpProduct on Prod_Number = Ppt_ProductNumber Left Join tb_ErpSystemCategory on Sc_ClassCode = Ppt_ProductCategory", StrWhere: "Ppt_PurchaseNumber = '" + this.dgv2.CurrentRow.Cells["Pord_PurchaseNumber"].Value.ToString().Trim() + "'", ShowColumnName: "tb_ErpPurchaseProduct.ID,Ppt_PurchaseNumber AS 采购单号,Prod_Name AS 商品名称,Ppt_PurchaseQuantity AS 采购数量,Sc_ClassName AS 商品类别,Ppt_PurchaseStatus AS 采购状态,dbo.fn_CheckDateTime(Ppt_PurchaseTime) AS 采购时间").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]["采购单号"].ToString().Trim();
- dgvr.Cells.Add(cell);
- cell = new DataGridViewTextBoxCell();
- cell.Value = dt.Rows[t]["商品名称"].ToString().Trim();
- dgvr.Cells.Add(cell);
- cell = new DataGridViewTextBoxCell();
- cell.Value = dt.Rows[t]["采购数量"].ToString().Trim();
- dgvr.Cells.Add(cell);
- cell = new DataGridViewTextBoxCell();
- cell.Value = dt.Rows[t]["商品类别"].ToString().Trim();
- dgvr.Cells.Add(cell);
- cell = new DataGridViewTextBoxCell();
- cell.Value = Enum.GetName(typeof(LYFZ.EnumPublic.Ppt_PurchaseStatus), Convert.ToInt32(dt.Rows[t]["采购状态"]));
- dgvr.Cells.Add(cell);
- cell = new DataGridViewTextBoxCell();
- cell.Value = dt.Rows[t]["采购时间"].ToString().Trim();
- dgvr.Cells.Add(cell);
- if (dt.Rows[t]["采购状态"].ToString().Trim() == "0" || dt.Rows[t]["采购状态"].ToString().Trim() == "3")
- { dgvr.DefaultCellStyle.ForeColor = Color.Orange; }
- this.dgv1.Rows.Add(dgvr);
- }
- this.dgv1.ClearSelection();
- }
- }
- }
- /// <summary>
- /// 保存
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void btnSave_Click(object sender, EventArgs e)
- {
- if (this.dgv2.Rows.Count > 0)
- {
- List<Helper.CommandInfo> clist = new List<Helper.CommandInfo>();
- List<LYFZ.Model.Model_ErpPurchaseProduct> mlist = porptbll.GetModelList("Ppt_PurchaseNumber = '" + this.dgv2.CurrentRow.Cells["Pord_PurchaseNumber"].Value.ToString().Trim() + "'");
- int NotDelete = 0;
- for (int i = 0; i < mlist.Count; i++)
- {
- for (int j = 0; j < this.dgv1.Rows.Count; j++)
- {
- if (mlist[i].ID.ToString().Trim() == this.dgv1.Rows[j].Cells["ID"].Value.ToString().Trim())
- {
- if (this.dgv1.Rows[j].Cells["Status"].Value.ToString().Trim() != "申请中")
- { NotDelete++; }
- else
- {
- if (this.dgv1.Rows[j].Cells["Prod_Quantity"].Value == null)
- { MessageBoxCustom.Show("采购数量不能为空!"); return; }
- else if (this.dgv1.Rows[j].Cells["Prod_Quantity"].Value.ToString().Trim() == "")
- { MessageBoxCustom.Show("采购数量不能为空!"); return; }
- else if (!Command.Command_Validate.IsNumber(this.dgv1.Rows[j].Cells["Prod_Quantity"].Value.ToString().Trim()))
- { MessageBoxCustom.Show("只能输入纯数字!"); return; }
- mlist[i].Ppt_PurchaseQuantity = Convert.ToInt32(this.dgv1.Rows[j].Cells["Prod_Quantity"].Value);
- clist.Add(porptbll.GetUpdateCommandInfo(mlist[i]));
- }
- break;
- }
- }
- }
- if (clist.Count > 0)
- {
- if (NotDelete > 0)
- {
- if (MessageBoxCustom.Show("有商品不属‘申请中’不能更改数量,您确定要继续保存吗?", "增加提示", MessageBoxButtons.YesNo) == DialogResult.No)
- { return; }
- }
- else
- {
- if (MessageBoxCustom.Show("你确定修改采购列表中的商品数量吗?", "增加提示", MessageBoxButtons.YesNo) == DialogResult.No)
- { return; }
- }
- if (LYFZ.BLL.BaseBllOperate.ExecuteSqlTran(clist) > 0)
- {
- this.dgv2_Click(sender, e);
- MessageBoxCustom.Show("保存成功!");
- }
- else
- { MessageBoxCustom.Show("保存失败!"); }
- }
- else
- {
- if (NotDelete > 0)
- { MessageBoxCustom.Show("商品不属‘申请中’不能更改数量!"); }
- }
- }
- }
- /// <summary>
- /// 删除此商品采购
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void btndelete_Click(object sender, EventArgs e)
- {
- if (this.dgv1.SelectedCells.Count == 0)
- { MessageBoxCustom.Show("请选择你要删除的数据!"); return; }
- string Status = this.dgv1.CurrentRow.Cells["Status"].Value.ToString();
- if (Status.ToString() == "申请中")
- {
- if (MessageBoxCustom.Show("你确定要删除吗?", "删除提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
- {
- int id = Convert.ToInt32(this.dgv1.CurrentRow.Cells["ID"].Value);
- if (porptbll.Delete(id) == true)
- { this.dgv2_Click(sender, e); }
- else
- { MessageBoxCustom.Show("删除失败!"); }
- }
- }
- else
- { MessageBoxCustom.Show("此商品正在 " + Status + " 不能删除!"); }
- }
- /// <summary>
- /// 删除订单
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void btnDeleteOrder_Click(object sender, EventArgs e)
- {
- if (this.dgv2.Rows.Count > 0)
- {
- if (this.dgv2.CurrentRow != null)
- {
- string StrNumber = this.dgv2.CurrentRow.Cells["Pord_PurchaseNumber"].Value.ToString().Trim();
- if (!string.IsNullOrEmpty(StrNumber))
- {
- List<Helper.CommandInfo> clist = new List<Helper.CommandInfo>();
- DataTable dt = orbll.GetView_Custom("tb_ErpPurchaseProduct", StrWhere: "Ppt_PurchaseNumber = '" + StrNumber + "'", ShowColumnName: "ID").Tables[0];
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- clist.Add(porptbll.GetDeleteCommandInfo("ID", "=", Convert.ToInt32(dt.Rows[i]["ID"].ToString().Trim())));
- }
- clist.Add(porbll.GetDeleteCommandInfo("ID", "=", Convert.ToInt32(this.dgv2.CurrentRow.Cells["PID"].Value)));
- if (clist.Count > 0)
- {
- if (MessageBoxCustom.Show("删除订单也会一同删除订单下的采购商品,你确定要删除吗?", "温馨提示!", MessageBoxButtons.YesNo) == DialogResult.No)
- { return; }
- if (LYFZ.BLL.BaseBllOperate.ExecuteSqlTran(clist) > 0)
- {
- MessageBoxCustom.Show("删除成功!");
- this.FrmProcurementApplication_Shown(this, null);
- }
- else
- { MessageBoxCustom.Show("删除失败!"); }
- }
- }
- else
- { MessageBoxCustom.Show("获取采购单号出错!"); }
- }
- else
- { MessageBoxCustom.Show("请选择要删除的采购单号!"); }
- }
- }
- /// <summary>
- /// 导出
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void btnExport_Click(object sender, EventArgs e)
- {
- if (this.dgv1.Rows.Count > 0)
- { this.dgv1.ExportDataTable(); }
- }
- /// <summary>
- /// 打印
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void btnPrint_Click(object sender, EventArgs e)
- {
- if (this.dgv1.Rows.Count == 0)
- { MessageBoxCustom.Show("无打印的数据!"); return; }
- Hashtable htData = new Hashtable();
- htData["dgvData1"] = this.dgv1;
- htData["dgvData2"] = this.dgv2;
- LYFZ.Software.MainBusiness.ReportPrint.ReportFixedFormat.PrintFixedFormat(LYFZ.EnumPublic.PrintTypeEnum.库存采购申请单, htData);
- }
- }
- }
|