using com.steering.pss.plnsaleord.jggxpln.model;
using Core.Mes.Client.Comm.Control;
using Core.Mes.Client.Comm.Server;
using Core.Mes.Client.Comm.Tool;
using CoreFS.CA06;
using Infragistics.Win.UltraWinGrid;
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 Core.StlMes.Client.PlnSaleOrd.JGGXPln
{
public partial class FrmMatZcM : FrmBase
{
///
/// 接箍订单号
///
private string proPlanId = "";
///
/// 接箍订单分组号
///
private string jgGroupId = "";
///
/// 炉作业计划号
///
private string zyPlanId = "";
private bool isChecked = false;
public bool IsChecked
{
get { return isChecked; }
set { isChecked = value; }
}
public Infragistics.Win.UltraWinEditors.UltraNumericEditor UltraNumericLenBl
{
get { return ultraNumericLenBl; }
set { ultraNumericLenBl = value; }
}
public FrmMatZcM(string _proPlanId, string _jgGroupId, OpeBase _ob)
{
this.ob = _ob;
proPlanId = _proPlanId;
jgGroupId = _jgGroupId;
InitializeComponent();
}
public FrmMatZcM(string _zyPlanId, OpeBase _ob)
{
this.ob = _ob;
zyPlanId = _zyPlanId;
InitializeComponent();
}
private void FrmMatZcM_Load(object sender, EventArgs e)
{
Init();
RefresDate();
}
private void ultraToolbarsManager1_ToolClick(object sender,
Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
{
switch (e.Tool.Key)
{
case "Query":
DoSeleted();
break;
case "OutBound":
OutBound();
break;
case "ModifyZy":
DoModifyZy();
break;
case "Close":
this.Close();
break;
default:
break;
}
}
///
/// 初始化
///
private void Init()
{
PlanComm.setGridActivation(ultraGridMat.DisplayLayout.Bands[0], "CHC", "CHECKED_NUM");
PlanComm.setGridSummarySet(ultraGridMat, 0, "MAT_NUM", "CHECKED_NUM");
PlanComm.setGridSummarySet(ultraGridMat, 2, "ACT_LEN");
PlanComm.setGridDigitalCol(ultraGridMat.DisplayLayout.Bands[0], 5, 0, "MAT_NUM", "CHECKED_NUM");
PlanComm.setGridDigitalCol(ultraGridMat.DisplayLayout.Bands[0], 5, 2, "ACT_LEN",
"ACT_LEN_MIN", "ACT_LEN_MAX", "ACT_WEIGHT");
if (zyPlanId.Trim().Equals(""))
{
ultraToolbarsManager1.Tools["ModifyZy"].SharedProps.Visible = false;
}
else
{
ultraToolbarsManager1.Tools["OutBound"].SharedProps.Visible = false;
}
}
///
/// 刷新
///
private void RefresDate()
{
//DataTable dt1 = ServerHelper.GetData("com.steering.pss.plnsaleord.jggxpln.CoreJgMPlnZy.queryBaseSort",
// new object[] { "8014" }, this.ob);
//ultraGridMat.DisplayLayout.Bands[1].Columns["PRODUCT_FLAG"].ValueList =
// PlanComm.GeneralValuelist(ref dt1, "BASECODE", "BASENAME");
//DataTable dt2 = ServerHelper.GetData("com.steering.pss.plnsaleord.jggxpln.CoreJgMPlnZy.queryBaseSort",
// new object[] { "801501" }, this.ob);
//ultraGridMat.DisplayLayout.Bands[1].Columns["MAT_STATUS"].ValueList =
// PlanComm.GeneralValuelist(ref dt2, "BASECODE", "BASENAME");
DoSeleted();
}
private void DoSeleted()
{
if (zyPlanId.Trim().Equals(""))
{
DoQuery();
}
else
{
DoQueryModify();
}
}
///
/// 获取接箍订单备料需求号
///
///
///
private string getJgMBlReq(string proPlanId)
{
string blReqIdlist = "";
DataTable dt = ServerHelper.GetData("com.steering.pss.plnsaleord.jggxpln.CoreJgMPlnZy.getJgMBlReq",
new object[] { proPlanId }, this.ob);
if (dt != null && dt.Rows.Count > 0)
{
blReqIdlist = dt.Rows[0]["REQ_BL_ID"].ToString();
}
return blReqIdlist;
}
///
/// 查询
///
private void DoQuery()
{
DataTable dt = null;
DataTable dtLen = null;
double proplen = 0;
string blReqList = getJgMBlReq(proPlanId);
if (blReqList.Trim().Equals(""))
{
dt = ServerHelper.GetData("com.steering.pss.plnsaleord.jggxpln.CoreJgMPlnZy.selectJgMStoverBatch",
new object[] { proPlanId, jgGroupId }, this.ob);
//dtMat = ServerHelper.GetData("com.steering.pss.plnsaleord.jggxpln.CoreJgMPlnZy.selectMatZcM",
// new object[] { proPlanId, jgGroupId }, this.ob);
}
else
{
dt = ServerHelper.GetData("com.steering.pss.plnsaleord.jggxpln.CoreJgMPlnZy.selectJgMStoverBatch",
new object[] { proPlanId, jgGroupId, blReqList }, this.ob);
//dtMat = ServerHelper.GetData("com.steering.pss.plnsaleord.jggxpln.CoreJgMPlnZy.selectMatZcM",
// new object[] { proPlanId, jgGroupId, blReqList }, this.ob);
}
//dataTable1.Clear();
GridHelper.CopyDataToDatatable(dt, dataTable2, true);
//GridHelper.CopyDataToDatatable(dtMat, dataTable1, true);
dtLen = ServerHelper.GetData("com.steering.pss.plnsaleord.jggxpln.CoreJgMPlnZy.queryPlnPropLenSum",
new object[] { proPlanId, jgGroupId }, this.ob);
if (dtLen != null && dtLen.Rows.Count > 0)
{
double.TryParse(dtLen.Rows[0]["PROP_LEN_SUM"].ToString(), out proplen);
}
this.ultraNumericBoundLen.Value = proplen;
this.ultraNumericOutBound.Value = 0;
}
///
/// 修改查询
///
private void DoQueryModify()
{
DataTable dt = null;
DataTable dtLen = null;
double proplen = 0;
string blReqList = getJgMBlReq(proPlanId);
if (blReqList.Trim().Equals(""))
{
dt = ServerHelper.GetData("com.steering.pss.plnsaleord.jggxpln.CoreJgMPlnZy.selectJgMBatchGroupModify",
new object[] { zyPlanId }, this.ob);
}
else
{
dt = ServerHelper.GetData("com.steering.pss.plnsaleord.jggxpln.CoreJgMPlnZy.selectJgMBatchGroupModify",
new object[] { zyPlanId, blReqList }, this.ob);
}
GridHelper.CopyDataToDatatable(dt, dataTable2, true);
if (ultraGridMat.Rows.Count > 0)
{
DataTable dtStatus = null;
dtStatus = ServerHelper.GetData("com.steering.pss.plnsaleord.jggxpln.CoreJgMPlnZy.selectJgZyStatus",
new object[] { zyPlanId }, this.ob);
if (dtStatus != null && dtStatus.Rows.Count > 0)
{
int outNum = 0;//已经组炉的支数
int.TryParse(dtStatus.Rows[0]["PLAN_BL_NUM"].ToString(), out outNum);
ultraGridMat.Rows[0].Cells["CHECKED_NUM"].Value = outNum;
}
}
dtLen = ServerHelper.GetData("com.steering.pss.plnsaleord.jggxpln.CoreJgMPlnZy.queryPlnPropLenSum",
new object[] { proPlanId, jgGroupId, zyPlanId }, this.ob);
if (dtLen != null && dtLen.Rows.Count > 0)
{
double.TryParse(dtLen.Rows[0]["PROP_LEN_SUM"].ToString(), out proplen);
}
this.ultraNumericBoundLen.Value = proplen;
this.ultraNumericOutBound.Value = 0;
}
///
/// 组炉
///
//private void OutBound()
//{
// List> list = new List>();
// foreach (UltraGridRow uRow in ultraGridMat.Rows)
// {
// if (uRow.Cells["CHC"].Value == null || Convert.ToBoolean(uRow.Cells["CHC"].Value))
// {
// List listGroup = new List();
// IQueryable ugrs = uRow.ChildBands[0].Rows.AsQueryable().Where("CHC = 'True'");
// foreach (UltraGridRow ugr in ugrs)
// {
// double actLen = 0;
// MatZcMEntity matZcM = new MatZcMEntity();
// double.TryParse(ugr.Cells["ACT_LEN"].Value.ToString(), out actLen);
// matZcM.MatNo = ugr.Cells["MAT_NO"].Value.ToString();
// matZcM.JudgeStoveNo = ugr.Cells["JUDGE_STOVE_NO"].Value.ToString();
// matZcM.BatchNo = ugr.Cells["BATCH_NO"].Value.ToString();
// matZcM.BatchGroudNo = ugr.Cells["BATCH_GROUD_NO"].Value.ToString();
// matZcM.ActLen = actLen.ToString();
// listGroup.Add(matZcM);
// }
// list.Add(listGroup);
// }
// }
// if (list.Count() == 0)
// {
// MessageUtil.ShowTips("未勾选任何材料。");
// return;
// }
// CoreClientParam ccp = new CoreClientParam();
// ccp.ServerName = "com.steering.pss.plnsaleord.jggxpln.CoreJgMPlnZy";
// ccp.MethodName = "outBound";
// ccp.ServerParams = new object[] { list, proPlanId, jgGroupId, UserInfo.GetUserName() };
// ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
// if (ccp.ReturnCode != -1)
// {
// if (ccp.ReturnObject != null)
// {
// MessageUtil.ShowTips(ccp.ReturnObject.ToString());
// }
// }
// DoQuery();
//}
///
/// 组炉
///
private void OutBound()
{
IQueryable checkRows = null;
List list = new List();
ultraGridMat.UpdateData();
checkRows = ultraGridMat.Rows.AsQueryable().Where("CHC = 'True'");
if (checkRows.Count() == 0)
{
MessageUtil.ShowTips("未勾选任何材料。");
return;
}
IQueryable zeroRows = checkRows.Where(a =>
a.Cells["CHECKED_NUM"].Value.ToString().CompareTo("0") <= 0);
if (zeroRows.Count() != 0)
{
string judgeStoveNo = zeroRows.First().Cells["JUDGE_STOVE_NO"].Value.ToString();
string batchNo = zeroRows.First().Cells["BATCH_NO"].Value.ToString();
string batchGroudNo = zeroRows.First().Cells["BATCH_GROUD_NO"].Value.ToString();
MessageUtil.ShowTips("炉号:" + judgeStoveNo + " 批号:"
+ batchNo + " 组号:" + batchGroudNo + "未指定组炉支数。");
return;
}
foreach (UltraGridRow ugr in checkRows)
{
PlnZyJgEntity zyJgEntity = new PlnZyJgEntity();
zyJgEntity.ProPlanId = proPlanId;
zyJgEntity.JgGroupId = jgGroupId;
zyJgEntity.CreateName = UserInfo.GetUserName();
zyJgEntity.JudgeStoveNo = ugr.Cells["JUDGE_STOVE_NO"].Value.ToString();
zyJgEntity.BatchNo = ugr.Cells["BATCH_NO"].Value.ToString();
zyJgEntity.BatchGroudNo = ugr.Cells["BATCH_GROUD_NO"].Value.ToString();
zyJgEntity.AimlengthBl = ugr.Cells["ACT_LEN"].Value.ToString();
zyJgEntity.PlanBlNum = ugr.Cells["CHECKED_NUM"].Value.ToString();
list.Add(zyJgEntity);
}
CoreClientParam ccp = new CoreClientParam();
ccp.ServerName = "com.steering.pss.plnsaleord.jggxpln.CoreJgMPlnZy";
ccp.MethodName = "outBound";
ccp.ServerParams = new object[] { list, proPlanId, jgGroupId };
ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
if (ccp.ReturnCode != -1)
{
if (ccp.ReturnObject != null)
{
MessageUtil.ShowTips(ccp.ReturnObject.ToString());
}
}
isChecked = true;
DoQuery();
}
///
/// 修改炉次计划
///
private void DoModifyZy()
{
UltraGridRow ugr = ultraGridMat.ActiveRow;
if (ugr == null)
{
return;
}
int modifyNum = 0;
PlnZyJgEntity zyJgEntity = new PlnZyJgEntity();
CoreClientParam ccp = null;
ugr.Update();
int.TryParse(ugr.Cells["CHECKED_NUM"].Value.ToString(), out modifyNum);
if (modifyNum <= 0)
{
MessageUtil.ShowTips("组炉支数必须大于0。");
return;
}
zyJgEntity.ZyPlanId = zyPlanId;
zyJgEntity.PlanBlNum = modifyNum.ToString();
zyJgEntity.UpdateName = UserInfo.GetUserName();
ccp = new CoreClientParam();
ccp.ServerName = "com.steering.pss.plnsaleord.jggxpln.CoreJgMPlnZy";
ccp.MethodName = "modifyZy";
ccp.ServerParams = new object[] { zyJgEntity };
ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
if (ccp.ReturnCode != -1)
{
if (ccp.ReturnObject != null)
{
MessageUtil.ShowTips(ccp.ReturnObject.ToString());
}
}
isChecked = true;
DoQueryModify();
}
///
/// 刷新组炉长度
///
private void setBoundLen()
{
double lenSum = 0;
ultraGridMat.UpdateData();
foreach (UltraGridRow ugr in ultraGridMat.Rows)
{
if (Convert.ToBoolean(ugr.Cells["CHC"].Text))
{
int numChecked = 0;
double actLen = 0;
double.TryParse(ugr.Cells["ACT_LEN"].Value.ToString(), out actLen);
int.TryParse(ugr.Cells["CHECKED_NUM"].Value.ToString(), out numChecked);
lenSum += numChecked * actLen;
}
}
ultraNumericOutBound.Value = lenSum;
}
#region 事件
private void ultraGridMat_CellChange(object sender, CellEventArgs e)
{
UltraGridRow ugr = e.Cell.Row;
if (ugr == null)
{
return;
}
if (e.Cell.Column.Key.Equals("CHECKED_NUM"))
{
setBoundLen();
}
if (e.Cell.Column.Key.Equals("CHC"))
{
setBoundLen();
//ugr.Update();
if (ugr.HasChild())
{
#region 父行选中
//bool isChecked = true;
//if (bool.TryParse(ugr.Cells["CHC"].Text, out isChecked))
//{
// if (isChecked)
// {
// foreach (UltraGridRow uRow in ugr.ChildBands[0].Rows)
// {
// double len = 0;
// uRow.Cells["CHC"].Value = true;
// if (double.TryParse(uRow.Cells["ACT_LEN"].Value.ToString(), out len)
// && len > 0)
// {
// double lenOutBound = 0;
// lenOutBound = Convert.ToDouble(ultraNumericOutBound.Value);
// lenOutBound += len;
// if (lenOutBound >= 0)
// {
// ultraNumericOutBound.Value = lenOutBound;
// }
// }
// }
// }
// else
// {
// foreach (UltraGridRow uRow in ugr.ChildBands[0].Rows)
// {
// double len = 0;
// uRow.Cells["CHC"].Value = false;
// if (double.TryParse(uRow.Cells["ACT_LEN"].Value.ToString(), out len)
// && len > 0)
// {
// double lenOutBound = 0;
// lenOutBound = Convert.ToDouble(ultraNumericOutBound.Value);
// lenOutBound -= len;
// if (lenOutBound >= 0)
// {
// ultraNumericOutBound.Value = lenOutBound;
// }
// }
// }
// }
//}
#endregion
}
else
{
#region 子行选中
//bool isChecked = true;
//if (bool.TryParse(ugr.Cells["CHC"].Text, out isChecked))
//{
// if (isChecked)
// {
// double len = 0;
// IQueryable checkRows = ugr.ParentRow
// .ChildBands[0].Rows.AsQueryable().Where("CHC = 'True'");
// if (double.TryParse(ugr.Cells["ACT_LEN"].Value.ToString(), out len)
// && len > 0)
// {
// double lenOutBound = 0;
// lenOutBound = Convert.ToDouble(ultraNumericOutBound.Value);
// lenOutBound += len;
// if (lenOutBound >= 0)
// {
// ultraNumericOutBound.Value = lenOutBound;
// }
// }
// if (checkRows.Count() == ugr.ParentRow
// .ChildBands[0].Rows.Count)
// {
// ugr.ParentRow.Cells["CHC"].Value = true;
// }
// else
// {
// ugr.ParentRow.Cells["CHC"].Value = null;
// }
// }
// else
// {
// double len = 0;
// IQueryable checkRows = ugr.ParentRow
// .ChildBands[0].Rows.AsQueryable().Where("CHC = 'True'");
// if (double.TryParse(ugr.Cells["ACT_LEN"].Value.ToString(), out len)
// && len > 0)
// {
// double lenOutBound = 0;
// lenOutBound = Convert.ToDouble(ultraNumericOutBound.Value);
// lenOutBound -= len;
// if (lenOutBound >= 0)
// {
// ultraNumericOutBound.Value = lenOutBound;
// }
// }
// if (checkRows.Count() == 0)
// {
// ugr.ParentRow.Cells["CHC"].Value = false;
// }
// else
// {
// ugr.ParentRow.Cells["CHC"].Value = null;
// }
// }
//}
#endregion
}
}
}
private void ultraGridMat_AfterHeaderCheckStateChanged(object sender, AfterHeaderCheckStateChangedEventArgs e)
{
if (e.Column.Key.Equals("CHC"))
{
//foreach (UltraGridRow ugr in e.Rows)
//{
// CellEventArgs eas = new CellEventArgs(ugr.Cells["CHC"]);
// ultraGridMat_CellChange(sender, eas);
//}
setBoundLen();
}
}
private void ultraGridMat_BeforeRowActivate(object sender, RowEventArgs e)
{
UltraGridRow ugr = e.Row;
int matNum = 0;
if (ugr == null)
{
return;
}
if (int.TryParse(ugr.Cells["MAT_NUM"].Value.ToString(), out matNum))
{
ugr.Cells["CHECKED_NUM"].Column.MaxValue = matNum;
}
}
private void ultraGridMat_AfterSelectChange(object sender, AfterSelectChangeEventArgs e)
{
foreach (UltraGridRow uRow in ultraGridMat.Selected.Rows)
{
if (uRow.GetType() != typeof(Infragistics.Win.UltraWinGrid.UltraGridGroupByRow))
{
uRow.Cells["CHC"].Value = true;
}
}
setBoundLen();
}
#endregion
}
}