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 FrmAcceptanceManagement : LYFZ.Software.UI.InventoryManagement.PurchasingManagement.AcceptanceManagement
{
private delegate void UpdateControl();
bool bl = false;
public string Pord_PurchaseNumber;
public FrmAcceptanceManagement()
{
this.FormClosed += FrmAcceptanceManagement_FormClosed;
this.dgv1.CellMouseDown += dgv1_CellMouseDown;
this.dgv1.DataGridViewConMenu_ItemClicked += dgv1_DataGridViewConMenu_ItemClicked;
}
///
/// 窗体关闭事件
///
///
///
void FrmAcceptanceManagement_FormClosed(object sender, FormClosedEventArgs e)
{
if (bl)
{ this.DialogResult = DialogResult.OK; }
}
///
/// 窗体加载事件
///
///
///
protected override void AcceptanceManagement_Shown(object sender, EventArgs e)
{ this.GetPurchaseProduct(Pord_PurchaseNumber); }
///
/// 获取采购商品表
///
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];
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();
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);
cell = new DataGridViewTextBoxCell();
cell.Value = dt.Rows[t]["Ppt_AcceptanceQuantity"].ToString().Trim();
dgvr.Cells.Add(cell);
cell = new DataGridViewTextBoxCell();
cell.Value = dt.Rows[t]["Ppt_AcceptanceName"].ToString().Trim();
dgvr.Cells.Add(cell);
cell = new DataGridViewTextBoxCell();
cell.Value = Convert.ToDateTime(dt.Rows[t]["Ppt_AcceptanceTime"]).ToString("yyyy-MM-dd").Trim();
dgvr.Cells.Add(cell);
cell = new DataGridViewTextBoxCell();
cell.Value = Convert.ToInt32(dt.Rows[t]["Ppt_PurchaseQuantity"].ToString().Trim()) - Convert.ToInt32(dt.Rows[t]["Ppt_AcceptanceQuantity"].ToString().Trim());
dgvr.Cells.Add(cell);
this.dgv1.Rows.Add(dgvr);
}
this.dgv1.ClearSelection();
}));
});
}
///
/// 验收
///
///
///
protected override void btnPurchase_Click(object sender, EventArgs e)
{
try
{
LYFZ.BLL.BLL_ErpPurchaseProduct PurchaseProductBll = new BLL.BLL_ErpPurchaseProduct();
if (dgv1.SelectedRows.Count == 0)
{ MessageBoxCustom.Show("请选择验收的商品!可多选!"); return; }
// 商品采购状态判断
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("商品正在申请中,不能验收!"); return; }
if (Status.ToString() == "采购取消")
{ MessageBoxCustom.Show(Ir_ProductName + " 商品已经取消采购,不能验收!"); return; }
if (Status.ToString() == "采购完成")
{ MessageBoxCustom.Show(Ir_ProductName + " 商品已经采购完成,不能验收!"); return; }
}
if (dgv1.SelectedRows.Count > 0)
{
#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_AcceptanceQuantity = Convert.ToInt32(dgv1.SelectedRows[i].Cells["BcAcceptance"].Value) + Convert.ToInt32(dgv1.SelectedRows[i].Cells["Ppt_AcceptanceQuantity"].Value);
PurchaseProductBll.Update(PurchaseProductModel);
}
#endregion
#region 更新采购商品表状态
for (int i = 0; i < dgv1.SelectedRows.Count; i++)
{
string Prod_Number = dgv1.SelectedRows[i].Cells["Prod_Number"].Value.ToString();
int Id = Convert.ToInt32(dgv1.SelectedRows[i].Cells["ID"].Value);
int Prod_Quantity = Convert.ToInt32(dgv1.SelectedRows[i].Cells["Prod_Quantity"].Value);
int Ppt_AcceptanceQuantity = Convert.ToInt32(PurchaseProductBll.GetList("Ppt_PurchaseNumber='" + Pord_PurchaseNumber + "' and Ppt_ProductNumber='" + Prod_Number + "'").Tables[0].Rows[0]["Ppt_AcceptanceQuantity"]); //Convert.ToInt32(dgv1.SelectedRows[i].Cells["Ppt_AcceptanceQuantity"].Value);
if (Prod_Quantity == Ppt_AcceptanceQuantity)
{
PurchaseProductBll.UpdatePpt_PurchaseStatus("Ppt_PurchaseStatus='1',Ppt_AcceptanceName='" + LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_Name + "',Ppt_AcceptanceTime='" + LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetServerDateTime().ToString("yyyy-MM-dd") + "' ", Id);
}
if (Prod_Quantity < Ppt_AcceptanceQuantity)
{
PurchaseProductBll.UpdatePpt_PurchaseStatus("Ppt_PurchaseStatus='0',Ppt_AcceptanceName='" + LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_Name + "',Ppt_AcceptanceTime='" + 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='1'");
int CgzOrQx = PurchaseProductBll.GetCount("Ppt_PurchaseNumber='" + Pord_PurchaseNumber + "' and (Ppt_PurchaseStatus='0' or Ppt_PurchaseStatus='3')");
if (sum == Qx)
{
PurchaseProductBll.UpdateCgDd("1", Pord_PurchaseNumber);
}
if (CgzOrQx == 0)
{
PurchaseProductBll.UpdateCgDd("1", Pord_PurchaseNumber);
}
#endregion
#region 新增入库
for (int i = 0; i < dgv1.SelectedRows.Count; i++)
{
int id = Convert.ToInt32(dgv1.SelectedRows[i].Cells["ID"].Value);
string Prod_Number = dgv1.SelectedRows[i].Cells["Prod_Number"].Value.ToString();
int BcAcceptance = Convert.ToInt32(dgv1.SelectedRows[i].Cells["BcAcceptance"].Value);
if (BcAcceptance != 0)
{
#region 新增入库记录表
LYFZ.Model.Model_ErpProductIntStorage ProductIntStorageModel = new Model.Model_ErpProductIntStorage();
LYFZ.BLL.BLL_ErpProductIntStorage ProductIntStorageBll = new BLL.BLL_ErpProductIntStorage();
ProductIntStorageModel.Pis_DividedShop = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetCompanyInfoID();
ProductIntStorageModel.Pis_ProductCategory = dgv1.SelectedRows[i].Cells["Prod_Class"].Value.ToString();
ProductIntStorageModel.Pis_ProductNumber = dgv1.SelectedRows[i].Cells["Prod_Number"].Value.ToString();
ProductIntStorageModel.Pis_PurchaseQuantity = Convert.ToInt32(dgv1.SelectedRows[i].Cells["BcAcceptance"].Value);
ProductIntStorageModel.Pis_PurchaseVendor = dgv1.SelectedRows[i].Cells["Ppt_PurchaseVendor"].Value.ToString();
ProductIntStorageModel.Pis_PurchasePrice = Convert.ToDecimal(dgv1.SelectedRows[i].Cells["Ppt_PurchasePrice"].Value);
ProductIntStorageModel.Pis_Remark = "";
ProductIntStorageModel.Pis_CreateDatetime = Convert.ToDateTime(LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetServerDateTime().ToString("yyyy-MM-dd"));
ProductIntStorageModel.Pis_CreateName = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
ProductIntStorageBll.Add(ProductIntStorageModel);
#endregion
#region 更新采购商品入库状态
LYFZ.Model.Model_ErpPurchaseProduct PurchaseProductModel = PurchaseProductBll.GetModel(id);
PurchaseProductModel.Ppt_StorageStatus = "1";
PurchaseProductBll.Update(PurchaseProductModel);
#endregion
#region 更新商品库存数量
LYFZ.BLL.BLL_ErpProduct ProductBll = new BLL.BLL_ErpProduct();
DataTable dt = ProductBll.GetList("Prod_Number='" + Prod_Number + "'").Tables[0];
int sumQuantity = BcAcceptance + Convert.ToInt32(dt.Rows[0]["Prod_Quantity"]);
ProductBll.UpdateProduct("Prod_Quantity=" + sumQuantity + "", Prod_Number);
#endregion
}
}
#endregion
}
GetPurchaseProduct(Pord_PurchaseNumber);
bl = true;
MessageBoxCustom.Show("保存成功!");
}
catch (Exception ex)
{ MessageBoxCustom.Show(ex.Message); }
}
///
/// 不验收
///
///
///
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; }
// 判断商品状态
for (int i = 0; i < dgv1.SelectedRows.Count; i++)
{
string Ir_ProductName = dgv1.SelectedRows[i].Cells["Ir_ProductName"].Value.ToString();
string Status = dgv1.SelectedRows[i].Cells["Status"].Value.ToString();
if (Status.ToString() == "申请中")
{ MessageBoxCustom.Show("商品正在申请中,不能验收!"); return; }
if (Status.ToString() == "采购取消")
{ MessageBoxCustom.Show(Ir_ProductName + " 商品已经取消采购,不能验收!"); return; }
if (Status.ToString() == "采购完成")
{ MessageBoxCustom.Show(Ir_ProductName + " 商品已经采购完成,不能验收!"); return; }
}
#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_AcceptanceName='" + LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_Name + "',Ppt_AcceptanceTime='" + 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'");
int CgzOrQx = PurchaseProductBll.GetCount("Ppt_PurchaseNumber='" + Pord_PurchaseNumber + "' and (Ppt_PurchaseStatus='0' or Ppt_PurchaseStatus='3')");
if (sum == Qx)
{
PurchaseProductBll.UpdateCgDd("2", Pord_PurchaseNumber);
}
if (CgzOrQx == 0)
{
PurchaseProductBll.UpdateCgDd("1", Pord_PurchaseNumber);
}
#endregion
GetPurchaseProduct(Pord_PurchaseNumber);
bl = true;
MessageBoxCustom.Show("保存成功!");
}
catch (Exception ex)
{
MessageBoxCustom.Show(ex.Message);
}
}
///
/// 保存更改数量
///
///
///
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++)
{
int id = Convert.ToInt32(dgv1.Rows[i].Cells["ID"].Value);
//string Ppt_PurchaseVendor = dgv1.Rows[i].Cells["Ppt_PurchaseVendor"].Value.ToString();
//LYFZ.BLL.BLL_ErpVendor VendorBll = new BLL.BLL_ErpVendor();
LYFZ.BLL.BLL_ErpPurchaseProduct PurchaseProductBll = new BLL.BLL_ErpPurchaseProduct();
LYFZ.Model.Model_ErpPurchaseProduct PurchaseProductModel = PurchaseProductBll.GetModel(id);
PurchaseProductModel.Ppt_PurchasePrice = Convert.ToDecimal(dgv1.Rows[i].Cells["Ppt_PurchasePrice"].Value);
PurchaseProductModel.Ppt_PurchaseVendor = dgv1.Rows[i].Cells["Ppt_PurchaseVendor"].Value.ToString();
PurchaseProductModel.Ppt_AcceptanceQuantity = Convert.ToInt32(dgv1.Rows[i].Cells["Ppt_AcceptanceQuantity"].Value);
PurchaseProductBll.Update(PurchaseProductModel);
}
GetPurchaseProduct(Pord_PurchaseNumber);
MessageBoxCustom.Show("保存成功!");
#endregion
}
}
}
catch (Exception ex)
{ MessageBoxCustom.Show(ex.Message); }
}
///
/// 关闭
///
///
///
protected override void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// 只能输入数字
///
///
///
protected override void dgv1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
try
{
if (dgv1.Rows.Count > 0)
{
if (dgv1.CurrentRow.Cells["BcAcceptance"].Value == null)
{
MessageBoxCustom.Show("本次验收数量不能为空!");
dgv1.CurrentRow.Cells["BcAcceptance"].Value = Convert.ToInt32(dgv1.CurrentRow.Cells["Prod_Quantity"].Value) - Convert.ToInt32(dgv1.CurrentRow.Cells["Ppt_AcceptanceQuantity"].Value);
return;
}
if (Command.Command_Validate.IsNumber(dgv1.CurrentRow.Cells["BcAcceptance"].Value.ToString()) == false)
{
MessageBoxCustom.Show("只能输入纯数字!");
dgv1.CurrentRow.Cells["BcAcceptance"].Value = Convert.ToInt32(dgv1.CurrentRow.Cells["Prod_Quantity"].Value) - Convert.ToInt32(dgv1.CurrentRow.Cells["Ppt_AcceptanceQuantity"].Value);
return;
}
}
}
catch (Exception ex)
{ MessageBoxCustom.Show(ex.Message); }
}
///
/// 导出
///
///
///
protected override void btnExport_Click(object sender, EventArgs e)
{
if (dgv1.Rows.Count > 0)
{ dgv1.ExportDataTable(); }
}
///
/// 打印
///
///
///
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);
}
///
/// 左键菜单
///
///
///
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["Prod_Number"].Value.ToString().Trim());
}
}
}
}