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;
using com.hnshituo.pur.vo;
using Core.Mes.Client.Comm.Control;
using Core.Mes.Client.Comm.Server;
using Core.Mes.Client.Comm.Tool;
using CoreFS.CA06;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using Pur.Entity;
using Pur.Entity.require_planEntiy;
namespace Pur.require_plan
{
public partial class FrmPurRequirePlanSummmary : FrmPmsBase
{
String strCustom = "";
private ArrayList list;
private string tips;
private int loadStyle=0;//0 list为需求行,1 list为需求头
public string Tips
{
get { return tips; }
set { tips = value; }
}
public FrmPurRequirePlanSummmary()
{
InitializeComponent();
}
public FrmPurRequirePlanSummmary(OpeBase opeBase, ArrayList list,int style,String Custom)
{
// TODO: Complete member initialization
this.ob = opeBase;
this.list = list;
this.loadStyle = style;
this.strCustom = Custom;
InitializeComponent();
}
private void FrmPurRequirePlanSummmary_Load(object sender, EventArgs e)//load
{
this.tips = "0";
getRequireType();
init();
GridHelper.SetExcludeColumnsActive(ultraGrid1.DisplayLayout.Bands[0], new string[] { "LASTDELIVERYDATE" });
ultraGrid1.DisplayLayout.Bands[1].Override.AllowUpdate = DefaultableBoolean.False;
//GridHelper.SetExcludeColumnsActive(ultraGrid1.DisplayLayout.Bands[0], new string[] { "LASTDELIVERYDATE" });
//GridHelper.SetExcludeColumnsActive(ultraGrid1.DisplayLayout.Bands[1], new string[] { });
}
#region 按钮方法
///
/// 汇总编制
///
///
///
private void btn_create_Click(object sender, EventArgs e)// 汇总编制
{
try
{
this.Cursor = Cursors.WaitCursor;
ultraGrid1.UpdateData();
ArrayList list1 = new ArrayList();
foreach (UltraGridRow row in ultraGrid1.Rows)
{
if (row != null)
{
String strOldMrLineId = row.GetCellValue("mrLineId").ToString().Trim();
RequirePlanD pd = this.execute("com.hnshituo.pur.requireplan.service.RequirePlanDService", "findById", new object[] { strOldMrLineId });
if (pd == null)
{
MessageUtil.ShowTips("无需求计划行:" + strOldMrLineId+"信息记录,或请刷新界面重新操作!");
return;
}
if (pd.FlagGeneratedPurPlan != "1")
{
MessageUtil.ShowTips("需求计划行:" + strOldMrLineId + "已编制,或请刷新界面重新操作!");
return;
}
RequirePlanD ReqD = new RequirePlanD();
ReqD.LastDeliveryDate = Convert.ToDateTime(row.GetCellValue("LASTDELIVERYDATE"));
ReqD.Qty = Convert.ToDouble(row.GetCellValue("qty"));
ReqD.QtyPur = Convert.ToDouble(row.GetCellValue("qty"));
ReqD.Validflag = "1";
ReqD.ItemUnique = pd.ItemUnique;
ReqD.DeliveryLocationFlag = pd.DeliveryLocationFlag;
ReqD.DeliveryLocation = pd.DeliveryLocation;
ReqD.DeliveryLocationCode = pd.DeliveryLocationCode;
ReqD.ItemCode = pd.ItemCode;//物料编码
ReqD.ItemName = pd.ItemName;//物料名称
ReqD.Remark = pd.Remark;//备注
ReqD.BugPrice = pd.BugPrice;//预算价
ReqD.ItemAttr = pd.ItemAttr;//属性名称
ReqD.ItemUom = pd.ItemUom;//采购单位
ReqD.WeightUnit = pd.WeightUnit;//库存单位
ReqD.ItemUomConefficient = pd.ItemUomConefficient;//转化系数
ReqD.BudgetAmt = ReqD.BugPrice * ReqD.Qty * ReqD.ItemUomConefficient;//消耗预算
ReqD.CreateName = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserName();
ReqD.CreateUserid = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserID();
ReqD.CreateTime = DateTime.Now;
ReqD.FlagGeneratedPurPlan = "1";//默认未接受
ReqD.ItemStandardsCode = pd.ItemStandardsCode;
ReqD.ItemStandardsId = pd.ItemStandardsId;
ReqD.ItemUomId = pd.ItemUomId;
ReqD.ItemAttrId = pd.ItemAttrId;
ReqD.AuditFlag = "";
List list2 = new List();
foreach (UltraGridRow rowd in row.ChildBands[0].Rows)
{
if (rowd.HasParent())
{
list2.Add(rowd.GetValue("mrLIneId").ToString().Trim());
}
}
if(list2.Count<=0)
{
MessageUtil.ShowTips("数据异常!没有拿到第:"+row.Index+"条行信息的关联的源需求计划号!");
return;
}
ReqD.ValidDataPurviewIds=list2.ToArray();
//ReqD.DeleteUserid = UserInfo.GetDeptid();//部门ID
list1.Add(ReqD);
}
}
RequirePlanM ReqM = new RequirePlanM();
ReqM.CreateName = UserInfo.GetUserName();
ReqM.CreateUserid = UserInfo.GetUserID();
ReqM.CreateTime = DateTime.Now;
if (txt_MRPERIODEND.Text == "")
{
MessageUtil.ShowTips("请输入有效的计划月份");
txt_MRPERIODEND.Focus();
return;
}
if (txt_MRPERIODEND.Enabled == false)
{
if (DateTime.Now > DateTime.Parse(DateTime.Now.ToString("yyyy/MM/26")))
{
if (MessageUtil.ShowYesNoAndQuestion("需求提报截止日期为每月25号,若提交将默认为下月需求计划。确定新增?") != DialogResult.Yes)
{
txt_MRPERIODEND.Focus();
return;
}
}
ReqM.MrPeriodEnd = DateTime.Now < DateTime.Parse(DateTime.Now.ToString("yyyy/MM/26")) ? DateTime.Parse(DateTime.Now.AddMonths(1).ToString("yyyy/MM")) : DateTime.Parse(DateTime.Now.AddMonths(2).ToString("yyyy/MM"));
}
else
{
ReqM.MrPeriodEnd = Convert.ToDateTime(txt_MRPERIODEND.Value);
}
ReqM.UrgencyType = txt_URGENCYTYPE.Value.ToString();
ReqM.ReqOrgName = UserInfo.GetDepartment();//申请者机构名称
ReqM.ReqOrgId = UserInfo.GetDeptid();//申请者机构ID
ReqM.Validflag = "1";
ReqM.TenantName = txt_auditName.Text.Trim();
ReqM.TenantId = txt_auditId.Text.Trim();
if (txt_RequeType.SelectedIndex == -1)
{
MessageUtil.ShowTips("需指定需求计划类型");
txt_RequeType.Focus();
return;
}
ReqM.RequireType = txt_RequeType.Value.ToString().Trim();
ReqM.Status = "1";
if (MessageUtil.ShowYesNoAndQuestion("确定编制汇总?") != DialogResult.Yes)
{
return;
}
CoreResult re = this.execute("com.hnshituo.pur.requireplan.service.RequirePlanMService", "SummaryReqPlan", new object[] { ReqM, list1, list,strCustom});
if (re.Resultcode != 0)
{
MessageUtil.ShowTips("操作失败:" + re.Resultmsg);
}
else
{
MessageUtil.ShowTips("操作成功:生成需求计划【" + re.Resultmsg + "】");
setTips();
this.Close();
}
}
catch (Exception ex)
{
MessageUtil.ShowTips("操作失败:" + ex);
}
finally
{
this.Cursor = Cursors.Default;
}
}
///
/// 刷新
///
///
///
private void btn_refresh_Click(object sender, EventArgs e)// 刷新
{
getRequireType();
init();
}
///
/// 关闭
///
///
///
private void btn_Close_Click(object sender, EventArgs e)// 关闭
{
ultraGrid1.Rows.ExpandAll(true);
}
#endregion
#region 界面方法
///
/// 初始化
///
private void init()// 初始化
{
try
{
this.Cursor=Cursors.WaitCursor;
dataSet1.Clear();
DataTable dt = null;
dt = this.execute("com.hnshituo.pur.requireplan.service.RequirePlanDService", "getJoinedByIds", new object[] { list,loadStyle});
dt.Columns.Add("itemModel", typeof(string));
foreach (DataRow dr in dt.Rows)
{
//String StritemUnique = dr["itemUnique"].ToString().Trim();
//string strJit = dr["deliveryLocationFlag"].ToString().Trim();
//string strdeliveryCode = dr["deliveryLocationCode"].ToString().Trim();
//String uniqueId = StritemUnique + "@" + strJit + "@" + strdeliveryCode;
StringBuilder uniqueId = new StringBuilder(dr["itemUnique"].ToString().Trim());
uniqueId.Append("@").Append(dr["deliveryLocationFlag"].ToString().Trim()).Append("@").Append(dr["deliveryLocationCode"].ToString().Trim());
dr["itemModel"] = uniqueId.ToString();
}
DataTable dttest = dt.Copy();
//删除父表中没有的需求订单行
for (int i = 0; i < dttest.Rows.Count; i++)
{
String strItemModel = dttest.Rows[i]["itemModel"].ToString().Trim();
int cou = 0;
for (int j = dt.Rows.Count - 1; j >= 0; j--)
{
String tempItemModel = dt.Rows[j]["itemModel"].ToString().Trim();
if (tempItemModel == strItemModel)
{
cou = cou + 1;
if (cou == 1)
{
//rowt = dt.Rows[j];
}
if (cou >= 2)
{
dt.Rows.RemoveAt(j);
}
}
}
}
GridHelper.CopyDataToDatatable(dt, dataTable1, true);
//行信息
DataTable dt1 = this.execute("com.hnshituo.pur.requireplan.service.RequirePlanDService", "getJoinedByIds", new object[] { list,loadStyle});
dt1.Columns.Add("itemModel", typeof(string));
foreach (DataRow dr1 in dt1.Rows)
{
String StritemUnique = dr1["itemUnique"].ToString().Trim();
string strJit = dr1["deliveryLocationFlag"].ToString().Trim();
string strdeliveryCode = dr1["deliveryLocationCode"].ToString().Trim();
String uniqueId = StritemUnique + "@" + strJit + "@" + strdeliveryCode;
dr1["itemModel"] = uniqueId;
}
GridHelper.CopyDataToDatatable(dt1, dataTable2, true);
RequirePlanM RPM = this.execute("com.hnshituo.pur.requireplan.service.RequirePlanMService", "findById", new object[] {list[0]});
txt_URGENCYTYPE.SelectedIndex = 0;//常规类型
txt_RequeType.Value = "122101";//普采主计划
txt_RequeType.ReadOnly = true;
txt_REQORGNAME.Text = UserInfo.GetDepartment();
txt_REQORGId.Text= UserInfo.GetDeptid();
txt_MRPERIODEND.Enabled = false;
txt_MRPERIODEND.Value = DateTime.Now < DateTime.Parse(DateTime.Now.ToString("yyyy/MM/26")) ? DateTime.Parse(DateTime.Now.AddMonths(1).ToString("yyyy/MM")) : DateTime.Parse(DateTime.Now.AddMonths(2).ToString("yyyy/MM"));
txt_auditId.Text = RPM.TenantId;
txt_auditName.Text = RPM.TenantName;
foreach (UltraGridRow rowg in ultraGrid1.Rows)
{
if (rowg.HasChild())
{
DateTime date=DateTime.Now;
int i=0;
double numall = 0;
foreach (UltraGridRow rowc in rowg.ChildBands[0].Rows)
{
DateTime dateLine = DateTime.Parse(rowc.GetCellValue("LASTDELIVERYDATE").ToString());
if (i == 0)
{
date = dateLine;
}
else
{
date = date > dateLine ? dateLine : date;
}
i = i + 1;
numall = numall + Convert.ToDouble(rowc.GetCellValue("Qty"));
//SQTYPURall = Convert.ToDouble(rowc.GetCellValue("SQTYPUR"));
}
rowg.Cells["Qty"].Value = numall;
rowg.Cells["LASTDELIVERYDATE"].Value = date;
}
}
}
catch (Exception ex)
{
MessageUtil.ShowTips("初始化或刷新界面失败:" + ex);
}
finally
{
this.Cursor=Cursors.Default;
}
}
///
/// 加载计划类型
///
private void getRequireType()//加载计划类型
{
DataTable dt1 = ServerHelper.GetData("com.hnshituo.pur.configure.service.impl.CoreBaseInfoNew.doQuery", new Object[] { "1221" }, this.ob);
comm.FilComboboxAdd(txt_RequeType, dt1, "baseCode", "baseName", "validflag NOT in ('0') and baseCode in ('122103','122101','122104')", false, "", "");
}
///
/// 操作标识
///
private void setTips()// 操作标识
{
if (tips == "0")
{
tips = "1";
}
}
#endregion
private void txt_URGENCYTYPE_ValueChanged(object sender, EventArgs e)
{
if (txt_URGENCYTYPE.SelectedIndex == 1)
{
txt_MRPERIODEND.Enabled = true;
}
else
{
txt_MRPERIODEND.Enabled = false;
txt_MRPERIODEND.Value = DateTime.Now < DateTime.Parse(DateTime.Now.ToString("yyyy/MM/26")) ? DateTime.Parse(DateTime.Now.AddMonths(1).ToString("yyyy/MM")) : DateTime.Parse(DateTime.Now.AddMonths(2).ToString("yyyy/MM"));
}
}
}
}