using Core.Mes.Client.Comm.Format;
using Core.Mes.Client.Comm.Server;
using Core.Mes.Client.Comm.Tool;
using Core.StlMes.Client.PlnSaleOrd.炉计划.Entity;
using CoreFS.CA06;
using Infragistics.Win;
using Infragistics.Win.UltraWinEditors;
using Infragistics.Win.UltraWinGrid;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace Core.StlMes.Client.PlnSaleOrd.炉计划.Tool
{
public class StoveHelper
{
///
/// 初始化产线
///
/// 工序
/// 同一分组的产线
/// 下拉框
///
public static void InitDropPline(string processCode, string plineCode, UltraComboEditor ugc, OpeBase ob)
{
DataTable dt = ServerHelper.GetData("com.steering.pss.plnsaleord.processOrder.base.BaseHelper.initPline", new object[] { processCode, "", plineCode }, ob);
if (dt != null && dt.Rows.Count > 0)
{
ugc.DataSource = dt;
ugc.ValueMember = "PLINE_CODE";
ugc.DisplayMember = "PLINE_NAME";
}
}
///
/// 初始化标准类别
///
/// 工序
/// 同一分组的产线
/// 下拉框
///
public static void InitDropStdSty(UltraComboEditor ugc, OpeBase ob)
{
DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.BaseOperations.getStdStyle", new object[] { }, ob);
if (dt != null && dt.Rows.Count > 0)
{
ugc.DataSource = dt;
ugc.ValueMember = "STD_STYLE";
ugc.DisplayMember = "STD_STYLE_DESC";
}
}
///
/// 初始化产线
///
/// 工序
/// 下拉框
/// OpeBase
public static string[] InitDropPline(string processCode,string[] validDataPurviewIds, UltraComboEditor ugc, OpeBase ob)
{
DataTable dt = ServerHelper.GetData("com.steering.pss.plnsaleord.planStove.StoveHelper.initPline", new object[] { processCode, validDataPurviewIds }, ob);
if (dt != null && dt.Rows.Count > 0)
{
ugc.DataSource = dt;
ugc.ValueMember = "PLINE_CODE";
ugc.DisplayMember = "PLINE_NAME";
string[] plineArr = new string[dt.Rows.Count];
for (int i = 0; i < dt.Rows.Count;i++ )
{
plineArr[i] = dt.Rows[i]["PLINE_CODE"].ToString();
}
return plineArr;
}
return null;
}
///
/// 查询选择记录
///
/// ArrayList
public static ArrayList GetChcRows(UltraGrid ug)
{
try { ug.UpdateData(); }
catch (Exception) { return null; }
IQueryable chcRows = ug.Rows.AsQueryable().Where(a => a.GetValue("CHC") == "True");
if (chcRows == null || chcRows.Count() == 0)
{
return null;
}
ArrayList list = new ArrayList();
foreach (UltraGridRow ugr in chcRows)
{
T t = (T)ugr.ListObject;
list.Add(t);
}
return list;
}
public static string[] SetData(string methodId, object[] param, OpeBase ob)
{
CoreClientParam ccp = new CoreClientParam();
ccp.ServerName = methodId.Substring(0, methodId.LastIndexOf("."));
ccp.MethodName = methodId.Substring(methodId.LastIndexOf(".") + 1);
ccp.ServerParams = param;
ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
if (ccp.ReturnCode == -1)
{
return null;
}
else
{
string[] strArray = new string[2];
strArray[0] = ccp.ReturnObject.ToString();
strArray[1] = ccp.ReturnInfo;
return strArray;
}
}
///
/// 排序
///
///
///
///
///
///
public static bool SortPlanOrder(ArrayList entityList, object obj, string processCode, string customInfo, OpeBase ob)
{ //定位行计划
ProducEntityZyM entityD = StoveHelper.GenerationProEntity(obj, processCode);
if (!entityD.ExeStatus.Equals("计划")) { return false; }
//定位行序号
string gxProSeqD = entityD.GxProSeq.ToString();
//移动行序号集合
ArrayList seqList = new ArrayList();
ArrayList list = new ArrayList();
////获取数据库服务器当前时间
//string time = DateTime.Now.ToString("yyyy-MM");
//DataTable dt = ServerHelper.GetData("com.steering.pss.plnsaleord.processOrder.base.ProducHelper.selectSystemTime", null, ob);
//if (dt.Rows.Count > 0)
//{
// time = dt.Rows[0]["DATIME"].ToString().Substring(0, 7);
//}
foreach (object entityM in entityList)
{
ProducEntityZyM entity = StoveHelper.GenerationProEntity(entityM, processCode);
//调整行只能为计划中的
if (!entity.ExeStatus.Equals("计划")) { return false; }
//if (processCode.Equals("D"))
//{
// if (DateTime.Compare(Convert.ToDateTime(entity.ProMonth), Convert.ToDateTime(time)) <= 0)
// {
// if (DateTime.Compare(Convert.ToDateTime(time), Convert.ToDateTime(entityD.ProMonth)) < 0)
// {
// MessageUtil.ShowTips("所选合同:" + entity.OrderNo + ",生产年月小于等于当前日历年月,不能调整至当前日历年月之后 。");
// return false;
// }
// }
// else
// {
// if (DateTime.Compare(Convert.ToDateTime(entityD.ProMonth), Convert.ToDateTime(entity.ProMonth)) != 0)
// {
// MessageUtil.ShowTips("所选合同:" + entity.OrderNo + ",生产年月大于当前日历年月, 。");
// return false;
// }
// }
//}
if (!entity.ZyBatchId.Equals(entityD.ZyBatchId))
{
MessageUtil.ShowTips("所选轧管炉计划ID:" + entity.HeatPlanNo + ",不在一个轧批号内,不能调整顺序。");
return false;
}
seqList.Add(Convert.ToInt32(entity.GxProSeq));
list.Add(entity.JsonStr);
}
seqList.Sort();
//如果鼠标坐标行在调整行的中间,则不允许调整
if (Convert.ToInt32(gxProSeqD) >= (int)seqList[0] && Convert.ToInt32(gxProSeqD) <= (int)seqList[seqList.Count - 1])
{
return false;
}
if (MessageUtil.ShowYesNoAndQuestion("是否调整生产顺序至:" + entityD.GxProSeq + "位?") == DialogResult.No)
{
return false;
}
string[] param = SetData("com.steering.pss.plnsaleord.planStove.StoveHelper.sortPlanOrder", new object[] { list, entityD.JsonStr, processCode, customInfo }, ob);
if (param == null) { MessageUtil.ShowTips("服务端处理失败!"); return false; }
else
{
if ((bool.Parse(param[0]))) { return true; } else { return false; }
}
}
public static ProducEntityZyM GenerationProEntity(object obj, string processCode)
{
ProducEntityZyM proEntity = new ProducEntityZyM();
if (processCode.Equals("C"))
{
//PlnOrderDzSEntity entity = (PlnOrderDzSEntity)obj;
//entity.PlanTimeB = Convert.ToDateTime(entity.PlanTimeB).ToString("yyyy-MM-dd HH:mm:ss");
//proEntity.ProPlanId = entity.ProPlanId;
//proEntity.GxPlanNo = entity.GxPlanNo;
//proEntity.IsPlanOk = entity.IsPlanOk;
//proEntity.IsRepairPln = entity.IsRepairPln;
//proEntity.PlanNum = Convert.ToString(entity.NumS);
//proEntity.PlanWgt = Convert.ToString(entity.WeigthS);
//proEntity.ExeStatus = entity.ExeStatus;
//proEntity.GxProSeq = entity.GxProSeq;
//proEntity.IfStoveIssued = "";
//proEntity.ProMonth = entity.ProMonth;
//proEntity.InWeightS = "0";
//proEntity.InNums = "0";
//proEntity.PlanUseTime = Convert.ToString(entity.PlanUsetime);
//proEntity.JsonStr = JSONFormat.Format(entity);
}
else if (processCode.Equals("D"))
{
PlnZyZgMEntity entity = (PlnZyZgMEntity)obj;
proEntity.HeatPlanNo = entity.HeatPlanNo;
//proEntity.PlanNum = Convert.ToString(entity.NumS);
//proEntity.PlanWgt = Convert.ToString(entity.WeigthS);
proEntity.ExeStatus = entity.Planstatus;
proEntity.GxProSeq = entity.GxProSeq;
proEntity.ProMonth = entity.ProMonth;
proEntity.OrderNo = entity.OrderNo.Substring(0, entity.OrderNo.Length-4);
proEntity.PlineCode = entity.PlineCode;
proEntity.PlineName = entity.PlineName;
proEntity.ZyBatchId = entity.ZyBatchId;
proEntity.JsonStr = JSONFormat.Format(entity);
}
//else if (processCode.Equals("E"))
//{
// PlnOrderDbkSEntity entity = (PlnOrderDbkSEntity)obj;
// entity.PlanTimeB = Convert.ToDateTime(entity.PlanTimeB).ToString("yyyy-MM-dd HH:mm:ss");
// proEntity.ProPlanId = entity.ProPlanId;
// proEntity.GxPlanNo = entity.GxPlanNo;
// proEntity.IsPlanOk = entity.IsPlanOk;
// proEntity.IsRepairPln = entity.IsRepairPln;
// proEntity.PlanNum = Convert.ToString(entity.NumS);
// proEntity.PlanWgt = Convert.ToString(entity.WeigthS);
// proEntity.ExeStatus = entity.ExeStatus;
// proEntity.GxProSeq = entity.GxProSeq;
// proEntity.IfStoveIssued = entity.IfStoveIssued;
// proEntity.InWeightS = entity.InWeightS.ToString();
// proEntity.InNums = entity.InNumS.ToString();
// proEntity.ProMonth = entity.ProMonth;
// //proEntity.WeigthSMin = entity.WeigthSMin.ToString();
// proEntity.PlanUseTime = Convert.ToString(entity.PlanUsetime);
// proEntity.JsonStr = JSONFormat.Format(entity);
//}
//else if (processCode.Equals("F"))
//{
// PlnOrderRclSEntity entity = (PlnOrderRclSEntity)obj;
// entity.PlanTimeB = Convert.ToDateTime(entity.PlanTimeB).ToString("yyyy-MM-dd HH:mm:ss");
// proEntity.ProPlanId = entity.ProPlanId;
// proEntity.GxPlanNo = entity.GxPlanNo;
// proEntity.IsPlanOk = entity.IsPlanOk;
// proEntity.IsRepairPln = entity.IsRepairPln;
// proEntity.PlanNum = Convert.ToString(entity.NumS);
// proEntity.PlanWgt = Convert.ToString(entity.WeigthS);
// proEntity.ExeStatus = entity.ExeStatus;
// proEntity.GxProSeq = entity.GxProSeq;
// proEntity.IfStoveIssued = "";
// proEntity.ProMonth = entity.ProMonth;
// proEntity.InWeightS = entity.InWeightS.ToString();
// proEntity.InNums = entity.InNumS.ToString();
// //proEntity.WeigthSMin = entity.WeigthSMin.ToString();
// proEntity.PlanUseTime = Convert.ToString(entity.PlanUsetime);
// proEntity.JsonStr = JSONFormat.Format(entity);
//}
//else if (processCode.Equals("G"))
//{
// PlnOrderJgxSEntity entity = (PlnOrderJgxSEntity)obj;
// entity.PlanTimeB = Convert.ToDateTime(entity.PlanTimeB).ToString("yyyy-MM-dd HH:mm:ss");
// proEntity.ProPlanId = entity.ProPlanId;
// proEntity.GxPlanNo = entity.GxPlanNo;
// proEntity.IsPlanOk = entity.IsPlanOk;
// proEntity.IsRepairPln = entity.IsRepairPln;
// proEntity.PlanNum = Convert.ToString(entity.NumS);
// proEntity.PlanWgt = Convert.ToString(entity.WeigthS);
// proEntity.ExeStatus = entity.ExeStatus;
// proEntity.GxProSeq = entity.GxProSeq;
// proEntity.IfStoveIssued = "";
// proEntity.ProMonth = entity.ProMonth;
// proEntity.InWeightS = entity.InWeightS.ToString();
// proEntity.InNums = entity.InNumS.ToString();
// proEntity.PlanUseTime = Convert.ToString(entity.PlanUsetime);
// proEntity.JsonStr = JSONFormat.Format(entity);
//}
//else if (processCode.Equals("H"))
//{
// PlnGxJgPropSEntity entity = (PlnGxJgPropSEntity)obj;
// entity.PlanTimeB = Convert.ToDateTime(entity.PlanTimeB).ToString("yyyy-MM-dd HH:mm:ss");
// proEntity.ProPlanId = entity.ProPlanId;
// proEntity.GxPlanNo = entity.GxPlanNo;
// proEntity.IsPlanOk = entity.IsPlanOk;
// proEntity.IsRepairPln = entity.IsRepairPln;
// proEntity.PlanNum = Convert.ToString(entity.GroupNumS);
// proEntity.PlanWgt = Convert.ToString(0);
// proEntity.ExeStatus = entity.ExeStatus;
// proEntity.GxProSeq = entity.GxProSeq;
// proEntity.IfStoveIssued = "";
// proEntity.ProMonth = entity.ProMonth;
// proEntity.InWeightS = entity.GroupBlWtS.ToString();
// proEntity.InNums = entity.GroupBlNumS.ToString();
// proEntity.PlanUseTime = Convert.ToString(entity.PlanUsetime);
// proEntity.JsonStr = JSONFormat.Format(entity);
//}
return proEntity;
}
///
/// 所属权限
///
/// 数据权限
///
/// 字符串数组
public static string[] InitPermissions(string[] validDataPurviewIds, OpeBase ob)
{
string[] arr = null;
DataTable dt = ServerHelper.GetData("com.steering.pss.plnsaleord.planStove.StoveHelper.getSalgPermissions", new object[] { validDataPurviewIds }, ob);
if (dt != null && dt.Rows.Count > 0)
{
arr = new string[dt.Rows.Count];
for (int i = 0; i < dt.Rows.Count; i++)
{
arr[i] = dt.Rows[i][0].ToString();
}
}
return arr;
}
///
/// 设置UltraComboEditor中的中文和非中文统一高度。
///
///
public static void SetComboItemHeight(UltraComboEditor cmb)
{
foreach (ValueListItem item in cmb.Items)
{
if (Regex.IsMatch(item.DisplayText, @"[\u4e00-\u9fa5]+"))
{
item.Appearance.FontData.SizeInPoints = 9.0F;
}
else
{
item.Appearance.FontData.SizeInPoints = 10.5F;
}
}
}
///
/// 禁止排序
///
///
public static void ForbidSort(UltraGrid ugr)
{
foreach (UltraGridColumn ugc in ugr.DisplayLayout.Bands[0].Columns)
{
ugc.SortIndicator = SortIndicator.Disabled;
}
}
///
/// 表示自定义UltraWinGrid控件的列合并模式(以显示文本合并)
///
public class CustomMergedCellEvaluator : Infragistics.Win.UltraWinGrid.IMergedCellEvaluator
{
private string primaryKey;
///
/// 获取或设置合并列的主键列的绑定名称
///
public string PrimaryKey
{
get { return primaryKey; }
set { primaryKey = value; }
}
///
/// CustomMergedCellEvaluator 的构造函数
///
/// 主键列的绑定名称
public CustomMergedCellEvaluator(string primaryKey)
{
this.primaryKey = primaryKey;
}
#region IMergedCellEvaluator 成员
public bool ShouldCellsBeMerged(Infragistics.Win.UltraWinGrid.UltraGridRow row1, Infragistics.Win.UltraWinGrid.UltraGridRow row2, Infragistics.Win.UltraWinGrid.UltraGridColumn column)
{
//确认逻辑:如果是主键列,自动合并,否则通过联合主键来合并
if (column.MergedCellStyle == Infragistics.Win.UltraWinGrid.MergedCellStyle.Always)
{
if (string.IsNullOrEmpty(this.primaryKey))
{
return row1.GetCellText(column) == row2.GetCellText(column);
}
if ((row1.GetCellValue(row1.Cells[this.primaryKey].Column).ToString() == row2.GetCellValue(row1.Cells[this.primaryKey].Column).ToString()) && (row1.GetCellText(column) == row2.GetCellText(column)))
{
return true;
}
}
return false;
}
#endregion
}
public static DataTable ToDataTable(DataRow[] rows)
{
if (rows == null || rows.Length == 0) return null;
DataTable tmp = rows[0].Table.Clone(); // 复制DataRow的表结构
foreach (DataRow row in rows)
{
tmp.ImportRow(row); // 将DataRow添加到DataTable中
}
return tmp;
}
}
}