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;
using CoreFS.CA06;
using Core.Mes.Client.Comm;
using Core.Mes.Client.Comm.Tool;
using Core.Mes.Client.Comm.Control;
using Infragistics.Win.UltraWinGrid;
using Pur.Entity.ck;
using com.hnshituo.pur.vo;
using System.Collections;
using Pur.configure;
using Pur.Entity.pur_orderEntiy;
using CoreFS.SA06;
using Pur.Entity;
using Pur.Pop_upWindow;
namespace Pur.ck
{
public partial class PurExcDeliveryNoticeOk : FrmPmsBase
{
private string init_deliveryLocationCode = "";
private ArrayList list;
private OrderM orderM;
private DateTime dateEnd=DateTime.Now;
private DateTime dateBegin=DateTime.Now;
public string Tips="0";
public PurExcDeliveryNoticeOk()
{
InitializeComponent();
}
public PurExcDeliveryNoticeOk(OpeBase OB, ArrayList list)
{
// TODO: Complete member initialization
this.ob = OB;
this.list = list;
InitializeComponent();
}
#region 工具栏
///
/// 生成发货通知
///
///
///
private void btn_create_Click(object sender, EventArgs e)// 生成发货通知
{
Add_PurExc();
}
///
/// 刷新数据
///
///
///
private void btn_refresh_Click(object sender, EventArgs e)// 刷新数据
{
init();
}
///
/// 退出
///
///
///
private void btn_close_Click(object sender, EventArgs e)// 退出
{
this.Close();
}
#endregion
///
/// 生成发货通知单
///
private void Add_PurExc()// 生成发货通知单
{
if (testInPut() == false)
{
return;
}
ultraGrid1.UpdateData();
try
{
//验证是否编制有效数量
int i = 0;
foreach (UltraGridRow uge in ultraGrid1.Rows.GetRowEnumerator(GridRowType.DataRow, null, null))
{
if (!uge.HasParent())
{
if (Convert.ToDouble(uge.Cells["canUseQty"].Value) < Convert.ToDouble(uge.Cells["createQty"].Value))
{
MessageUtil.ShowTips("合同交货行总编制数量不能大于可编制数量");
return;
}
}
if (uge.HasParent() &&Convert.ToBoolean(uge.Cells["isSelect"].Value) == true && !string.IsNullOrEmpty(uge.Cells["createQty"].Value.ToString()) && Convert.ToDouble(uge.Cells["createQty"].Value) > 0)
{
i = i + 1;
}
}
if (i == 0)
{
MessageUtil.ShowTips("编制条数为0或者未编制有效数量");
return;
}
//通知单主表信息
ExcDeliveryNoticeM EdnM = new ExcDeliveryNoticeM();
EdnM.Status = "1";
EdnM.Validflag = "1";
EdnM.CreateTime = DateTime.Now;
EdnM.CreateName = CoreUserInfo.UserInfo.GetUserName();
EdnM.CreateUserid = CoreUserInfo.UserInfo.GetUserID();
EdnM.OrderId = orderM.OrderId;
EdnM.SuppName = orderM.SuppName;
EdnM.SuppCode = orderM.SuppCode;
EdnM.DeliveryLocation = txt_DeliveryLocation.Text.ToString().Trim();
EdnM.DeliveryLocationCode = init_deliveryLocationCode;
EdnM.PlanedShipDate = Convert.ToDateTime(txt_MRPERIODSTART.Value);
EdnM.PlanedDeliveryDate =Convert.ToDateTime(txt_MRPERIODEND.Value);
EdnM.Remark = ultraTextEditor1.Text.ToString().Trim();
//通知从表和从-从表信息
ArrayList list1 = new ArrayList();
ArrayList list2 = new ArrayList();
foreach (UltraGridRow uge in ultraGrid1.Rows.GetRowEnumerator(GridRowType.DataRow, null, null))
{
if (!uge.HasParent())
{
String strOrderLineSqe=uge.Cells["OrderLineSqe"].Value.ToString();
String strOrderLineDSqe=uge.Cells["OrderLineDSqe"].Value.ToString();
if (String.IsNullOrEmpty(strOrderLineSqe))
{
MessageUtil.ShowTips("数据异常,发货通知单行编辑区中存在合同行号为空数据");
return;
}
if (String.IsNullOrEmpty(strOrderLineDSqe))
{
MessageUtil.ShowTips("数据异常,发货通知单行编辑区中存在合同交货行号为空数据");
return;
}
OrderC orderC = this.execute("com.hnshituo.pur.order.service.OrderCService", "findById", new object[] { strOrderLineSqe });
if (orderC == null)
{
MessageUtil.ShowTips("数据异常,发货通知单行编辑区中的合同行号:" + strOrderLineSqe + "未在数据库找到对应信息,可能已被废除,获取刷新");
return;
}
OrderCD orderCD = this.execute("com.hnshituo.pur.order.service.OrderCDService", "findById", new object[] { strOrderLineDSqe });
if (orderCD == null)
{
MessageUtil.ShowTips("数据异常,发货通知单行编辑区中的合同交货行号:" + strOrderLineDSqe + "未在数据库找到对应信息,可能已被废除,获取刷新");
return;
}
ExcDeliveryNoticeC EdnC = new ExcDeliveryNoticeC();
EdnC.Status = "1";
EdnC.Validflag = "1";
EdnC.OrderId = orderM.OrderId;
EdnC.CreateTime = DateTime.Now;
EdnC.CreateName = CoreUserInfo.UserInfo.GetUserName();
EdnC.CreateUserid = CoreUserInfo.UserInfo.GetUserID();
EdnC.ItemCode = orderC.ItemCode;
EdnC.ItemDesc = orderC.ItemDesc;
EdnC.ItemDescE = orderC.ItemDescE;
EdnC.ItemName = orderC.ItemName;
EdnC.ItemUom = orderC.ItemUom;
EdnC.ItemAttr = orderC.ItemAttr;
EdnC.ItemAttrId = orderC.ItemAttrId;
EdnC.ItemStandardsCode = orderC.ItemStandardsCode;
EdnC.ItemStandardsId = orderC.ItemStandardsId;
EdnC.ItemUnique = orderC.ItemUnique;
EdnC.ItemUomId = orderC.ItemUomId;
EdnC.ItemUomConefficient = orderC.ItemUomConefficient;
EdnC.ReceiveType = orderC.ReceiveType;
EdnC.BuyerName = orderC.BuyerName;
EdnC.MeteringFlag = orderC.MeteringFlag;
EdnC.BatchFlag = orderC.BatchFlag;
EdnC.PcFlag = orderC.PcFlag;
EdnC.Remark = orderCD.Remark;
EdnC.ItemUseUom = orderC.ItemUseUom;
EdnC.OrderLineSqe = orderC.OrderLineSqe;
EdnC.WeightUnit = orderC.WeightUnit;
EdnC.OrderLineDSqe = orderCD.OrderLineDSqe;
EdnC.Qty = Convert.ToDouble(uge.Cells["createQty"].Value);
list2.Add(EdnC);
}
//确定为从从表信息
if (uge.HasParent())
{
if(Convert.ToBoolean(uge.Cells["isSelect"].Value)==true)
{
if(!string.IsNullOrEmpty(uge.Cells["createQty"].Value.ToString()) && Convert.ToDouble(uge.Cells["createQty"].Value)>0)
{
ExcDeliveryNoticeRpR rp=new ExcDeliveryNoticeRpR();
rp.Qty=Convert.ToDouble(uge.Cells["createQty"].Value.ToString());
rp.RequireLineId=uge.Cells["mrLineId"].Value.ToString();
String StrOrderLineSqe = uge.ParentRow.Cells["orderLineSqe"].Value.ToString();
String StrOrderLineDSqe = uge.ParentRow.Cells["orderLineDSqe"].Value.ToString();
rp.OrderLineDSqe = StrOrderLineDSqe;
rp.CreateTime = DateTime.Now;
rp.CreateName = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserName();
rp.CreateUserId = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserID();
list1.Add(rp);
}
else
{
MessageUtil.ShowTips("需求行"+uge.Cells["mrLineId"].Value.ToString()+"未编制有效数量");
CkClassCommon.doActiveSelRow(ultraGrid1,"mrLineId",uge.Cells["mrLineId"].Value.ToString());
return;
}
}
}
}
if (MessageUtil.ShowYesNoAndQuestion("确定生成发货通知单?") != DialogResult.Yes)
{
return;
}
CoreResult crt = this.execute("com.hnshituo.pur.ck.service.ExcDeliveryNoticeRpRService", "doInsert_Rp", new object[] { EdnM, list2,list1 });
if (crt.Resultcode != 0)
{
MessageUtil.ShowTips("生成失败" + crt.Resultmsg);
return;
}
MessageUtil.ShowTips("发货通知 "+crt.Resultdata+" 单生成成功!");
Tips = "1";
//IQueryable uRows = ultraGrid1.Rows.AsQueryable().Where("CHECK = 'True' ");
//foreach (UltraGridRow uge in uRows)
//{
// if (uge.Cells["SurQty"].Value.ToString() == "0" ||string.IsNullOrEmpty(uge.Cells["SurQty"].Value.ToString()))
// {
// continue;
// }
// ExcDeliveryNoticeC EdnC = new ExcDeliveryNoticeC();
// EdnC.Status = "1";
// EdnC.Validflag = "1";
// EdnC.OrderId = sub;
// EdnC.CreateTime = DateTime.Now;
// EdnC.CreateName = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserName();
// EdnC.CreateUserid = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserID();
// EdnC.ItemCode = uge.Cells["ItemCode"].Value.ToString();
// EdnC.ItemDesc = uge.Cells["ItemDesc"].Value.ToString();
// EdnC.ItemDescE = uge.Cells["ItemDescE"].Value.ToString();
// EdnC.ItemModel = uge.Cells["ItemModel"].Value.ToString();
// EdnC.ItemName = uge.Cells["ItemName"].Value.ToString();
// EdnC.ItemSpec = uge.Cells["ItemSpec"].Value.ToString();
// EdnC.ItemUom = uge.Cells["ItemUom"].Value.ToString();
// if (!string.IsNullOrEmpty(uge.Cells["ItemUomConefficient"].Value.ToString()))
// {
// EdnC.ItemUomConefficient = Convert.ToDouble(uge.Cells["ItemUomConefficient"].Value);
// }
// EdnC.ReceiveType = uge.Cells["ReceiveType"].Value.ToString();
// EdnC.BuyerName = uge.Cells["BuyerName"].Value.ToString();
// EdnC.MeteringFlag = uge.Cells["MeteringFlag"].Value.ToString();
// EdnC.BatchFlag = uge.Cells["BatchFlag"].Value.ToString();
// EdnC.PcFlag = uge.Cells["PcFlag"].Value.ToString();
// EdnC.Remark = uge.Cells["Remark"].Value.ToString();
// EdnC.ItemUseUom = uge.Cells["ItemUseUom"].Value.ToString();
// EdnC.OrderLineSqe = uge.Cells["OrderLineSqe"].Value.ToString();
// EdnC.WeightUnit = uge.Cells["WeightUnit"].Value.ToString();
// EdnC.Qty = Convert.ToDouble(uge.Cells["SurQty"].Value);
// list.Add(EdnC);
//}
//CoreResult crt = this.execute("com.hnshituo.pur.ck.service.ExcDeliveryNoticeMService", "insert_ExcMC", new object[] { EdnM, list });
//if (crt.Resultcode != 0)
//{
// Core.Mes.Client.Comm.Tool.MessageUtil.ShowTips("生成失败" + crt.Resultmsg);
// return;
//}
//Core.Mes.Client.Comm.Tool.MessageUtil.ShowTips("发货通知 "+crt.Resultdata+" 单生成成功!");
}
catch (Exception e)
{
Core.Mes.Client.Comm.Tool.MessageUtil.ShowTips("生成失败"+e);
}
this.Close();
}
///
/// 界面加载
///
///
///
private void PurExcDeliveryNoticeOk_Load(object sender, EventArgs e)// 界面加载
{
init();
}
///
/// 加载数据
///
private void init()// 加载数据
{
try
{
this.Cursor = Cursors.WaitCursor;
//清空数据和显示合同信息
dataSet1.Clear();
if (list.Count <= 0)
{
MessageUtil.ShowTips("未发现待生成的合同交货行信息");
return;
}
//加载交货行信息
DataTable dt = this.execute("com.hnshituo.pur.order.service.OrderCDService", "doQueryOrderCDByList", new object[] { list });
if (dt == null || dt.Rows.Count == 0)
{
MessageUtil.ShowTips("数据库无上述合同交货行信息");
return;
}
//dt.Columns.Add("YEAR", Type.GetType("System.Int32"));
dt.Columns.Add("canUseQty", Type.GetType("System.String"));
dt.Columns.Add("createQty", Type.GetType("System.String"));
foreach (DataRow rows in dt.Rows)
{
//生成数量默认为剩余数量
// rows["SurQty"] = rows["Qty"];
//JIT物料判断
//if (!rows["receiveType"].ToString().Equals("JIT入库"))
//{
// MessageUtil.ShowTips("该合同明细存在非JIT物料,请选择其他通知单生成方式");
// this.Close();
// return;
//}
//行号判断
if (String.IsNullOrEmpty(rows["deleteName"].ToString()))
{
MessageUtil.ShowTips("合同行:" + rows["orderLineSqe"].ToString() + "采购计划行号为空,无法查询到关联的需求计划行");
this.Close();
return;
}
//计算可编制量
rows["Qty"] = rows["Qty"] == DBNull.Value ? 0 : rows["Qty"];
rows["createdQty"] = rows["createdQty"] == DBNull.Value ? 0 : rows["createdQty"];
rows["canUseQty"] = Convert.ToDouble(rows["Qty"]) - Convert.ToDouble(rows["createdQty"]);
rows["createQty"] = 0;
//计算最晚的交期
DateTime strDateEnd = Convert.ToDateTime(rows["DELIVERYDATEEND"]);
dateEnd = strDateEnd < dateEnd ? strDateEnd : dateEnd;
DateTime strDateStart = Convert.ToDateTime(rows["DELIVERYDATESTART"]);
dateBegin = strDateStart < dateBegin ? strDateStart : dateBegin;
}
GridHelper.CopyDataToDatatable(dt, dataTable4, true);
//初始化时间
txt_MRPERIODEND.Value = dateEnd;
txt_MRPERIODSTART.Value = dateBegin;
//加载合同头信息
String StrOrderId = dt.Rows[0]["orderId"].ToString().Trim();
orderM = this.execute("com.hnshituo.pur.order.service.OrderMService", "findById", new object[] { StrOrderId });
if(orderM==null)
{
MessageUtil.ShowTips("数据库未发现合同头:"+StrOrderId+" 信息");
return;
}
COP_OrderId.Text = orderM.OrderId;
COP_SuppName.Text = orderM.SuppName;
//加载需求行信息
DataTable dt1 = this.execute("com.hnshituo.pur.requireplan.service.RequirePlanDService", "getRD_forOrder", new object[] { list });
GridHelper.CopyDataToDatatable(dt1, dataTable3, true);
//统一初始化交货行和需求行--默认选择和推算
foreach (UltraGridRow uge in ultraGrid1.Rows)
{
if (!uge.HasParent())
{
double tepQty = Convert.ToDouble(uge.Cells["canUseQty"].Value);//剩余总可编制
uge.Cells["createQty"].Value = tepQty;
foreach (UltraGridRow uce in uge.ChildBands[0].Rows)
{
if (tepQty > 0)
{
double willUseQty = Convert.ToDouble(uce.Cells["qtyPur"].Value);
if (tepQty > willUseQty)
{
tepQty = tepQty - willUseQty;
uce.Cells["isSelect"].Value = true;
uce.Cells["createQty"].Value = willUseQty;
}
else
{
uce.Cells["isSelect"].Value = true;
uce.Cells["createQty"].Value = tepQty;
tepQty = 0;
}
}
else
{
uce.Cells["isSelect"].Value = false;
uce.Cells["createQty"].Value = 0;
}
}
if (tepQty > 0)
{
uge.Cells["createQty"].Value = Convert.ToDouble(uge.Cells["createQty"].Value)-tepQty;
}
}
}
////需求行初始化
//foreach (UltraGridRow rowd in ultraGrid1.Rows.GetRowEnumerator(GridRowType.DataRow, null, null))
//{
// if (rowd.HasParent())
// {
// rowd.Cells["isSelect"].Value = true;
// rowd.Cells["createQty"].Value = rowd.Cells["qtyPur"].Value;
// }
//}
////交货行初始化
//foreach (UltraGridRow rowd in ultraGrid1.Rows.GetRowEnumerator(GridRowType.DataRow, null, null))
//{
// if (!rowd.HasParent())
// {
// double tempval1 = 0;
// foreach (UltraGridRow rows in rowd.ChildBands[0].Rows)
// {
// if (rows.Cells["createQty"].Value != null && !String.IsNullOrEmpty(rows.Cells["createQty"].Value.ToString()) && Convert.ToBoolean(rows.Cells["isSelect"].Value) == true)
// {
// tempval1 = tempval1 + Convert.ToDouble(rows.Cells["createQty"].Value);
// }
// }
// rowd.Cells["createQty"].Value = tempval1;
// }
//}
ultraGrid1.UpdateData();
GridHelper.SetExcludeColumnsActive(ultraGrid1.DisplayLayout.Bands[0], new string[] { });
GridHelper.SetExcludeColumnsActive(ultraGrid1.DisplayLayout.Bands[1], new string[] {"isSelect","createQty"});
}
catch (Exception ex)
{
MessageUtil.ShowTips("生成通知单界面初始化失败:" + ex.Message);
this.Close();
}
finally
{
this.Cursor = Cursors.Default;
}
}
///
/// 数量输入控制
///
///
///
private void ultraGrid1_CellChange(object sender, CellEventArgs e)// 数量输入控制
{
double Qb_newParentVale = Convert.ToDouble(e.Cell.Row.ParentRow.Cells["canUseQty"].Value);
if (e.Cell.Row.HasParent() && e.Cell.Column.Key=="createQty")
{
double Qb_newcellvalue =Convert.ToDouble(e.Cell.Value);
ultraGrid1.UpdateData();
if (e.Cell.Column.Key.Equals("createQty"))
{
double t1=Convert.ToDouble(e.Cell.Row.Cells["createQty"].Value);
double t2=Convert.ToDouble(e.Cell.Row.Cells["qtyPur"].Value);
if (t1 > t2)
{
e.Cell.Value = Qb_newcellvalue;
e.Cell.Appearance.BorderColor = Color.Red;
return;
}
e.Cell.Appearance.BorderColor = Color.Black;
double tempval1 = 0;
foreach (UltraGridRow rows in e.Cell.Row.ParentRow.ChildBands[0].Rows)
{
if (rows.Cells["createQty"].Value != null && !String.IsNullOrEmpty(rows.Cells["createQty"].Value.ToString()) && Convert.ToBoolean(rows.Cells["isSelect"].Value) == true)
{
tempval1 = tempval1 + Convert.ToDouble(rows.Cells["createQty"].Value);
}
}
if (tempval1 > Qb_newParentVale)
{
e.Cell.Value = Qb_newcellvalue;
e.Cell.Row.ParentRow.Cells["createQty"].Appearance.BorderColor = Color.Red;
return;
}
e.Cell.Row.ParentRow.Cells["createQty"].Appearance.BorderColor = Color.Black;
e.Cell.Row.ParentRow.Cells["createQty"].Value = tempval1;
}
}
if (e.Cell.Row.HasParent() && e.Cell.Column.Key == "isSelect")
{
Boolean oldcheck = Convert.ToBoolean(e.Cell.Value);
ultraGrid1.UpdateData();
Boolean newcheck = Convert.ToBoolean(e.Cell.Value);
double tempval1 = 0;
foreach (UltraGridRow rows in e.Cell.Row.ParentRow.ChildBands[0].Rows)
{
if (rows.Cells["createQty"].Value != null && !String.IsNullOrEmpty(rows.Cells["createQty"].Value.ToString()) && Convert.ToBoolean(rows.Cells["isSelect"].Value) == true)
{
tempval1 = tempval1 + Convert.ToDouble(rows.Cells["createQty"].Value);
}
}
if (tempval1 > Qb_newParentVale)
{
e.Cell.Value = oldcheck;
e.Cell.Row.ParentRow.Cells["createQty"].Appearance.BorderColor = Color.Red;
return;
}
e.Cell.Row.ParentRow.Cells["createQty"].Appearance.BorderColor = Color.Black;
e.Cell.Row.ParentRow.Cells["createQty"].Value = tempval1;
}
}
///
/// 地点选择
///
///
///
private void txt_DeliveryLocation_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)// 地点选择
{
FrmPop_upDeliveryLocation Dz = new FrmPop_upDeliveryLocation(this.ob);
Dz.ShowDialog();
if (Dz.DeliveryLocationCode == null)
{
return;
}
txt_DeliveryLocation.Text = Dz.DeliveryLocation;
init_deliveryLocationCode = Dz.DeliveryLocationCode;
}
///
/// 输入数据校验
///
///
private bool testInPut()
{
if (String.IsNullOrEmpty(txt_MRPERIODSTART.Text))
{
MessageUtil.ShowTips("请输入要求交货开始时间!");
txt_MRPERIODSTART.Focus();
return false;
}
if (String.IsNullOrEmpty(txt_MRPERIODEND.Text))
{
MessageUtil.ShowTips("请输入要求交货结束时间!");
txt_MRPERIODEND.Focus();
return false;
}
if (Convert.ToDateTime(txt_MRPERIODEND.Value) < DateTime.Now)
{
MessageUtil.ShowTips("输入的通知单要求交货结束时间无效,需大于当前时间!");
txt_MRPERIODEND.Focus();
return false;
}
if (Convert.ToDateTime(txt_MRPERIODSTART.Value) >= Convert.ToDateTime(txt_MRPERIODEND.Value))
{
MessageUtil.ShowTips("通知单的要求交货结束时间需大于开始时间");
txt_MRPERIODSTART.Focus();
return false;
}
if (String.IsNullOrEmpty(init_deliveryLocationCode))
{
MessageUtil.ShowTips("通知单的交付地址不能为空!");
txt_DeliveryLocation.Focus();
return false;
}
return true;
}
}
}