using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Core.StlMes.Client.SaleOrder.BLL;
using CoreFS.CA06;
using Core.Mes.Client.Comm.Tool;
using Infragistics.Win.UltraWinEditors;
using Core.StlMes.Client.Qcm;
using Infragistics.Win.UltraWinGrid;
using CoreFS.SA06;
using Infragistics.Win;
using Core.Mes.Client.Comm.Control;
using Core.Mes.Client.Comm.Server;
using Core.Mes.Client.Comm.Format;
using System.Reflection;
namespace Core.StlMes.Client.SaleOrder.Control
{
public partial class CraftOrdFdCicCtrl : UserControl
{
private UltraComboEditor[] ultras = new UltraComboEditor[13];
private OpeBase _ob;
private string designKey = "";
private string ordLnPk = "";
public CraftOrdFdCicCtrl(System.Windows.Forms.Control container, string ordLnPk, string designKey, OpeBase ob)
{
InitializeComponent();
_ob = ob;
this.designKey = designKey;
this.ordLnPk = ordLnPk;
container.Controls.Add(this);
this.Dock = DockStyle.Fill;
for (int i = 0; i < ultras.Length; i++)
{
ultras[i] = new UltraComboEditor();
Controls.Add(ultras[i]);
ultras[i].Visible = false;
ultras[i].DropDownListWidth = -1;
}
LoadBaseData();
DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CraftOrdFdCic.getFdCicCount",
new object[]{ ordLnPk }, ob);
if (dt.Rows.Count > 0)
{
//ultraNumericEditor1.Value = dt.Rows[0]["SMELTING_CNT_FD"].ToString();
ultraNumericEditor2.Value = dt.Rows[0]["PRODUCT_CNT_FD"].ToString();
ultraComboEditor3.Value = dt.Rows[0]["RATE_FD"].ToString();
ultraComboEditor4.Value = dt.Rows[0]["COMMON"].ToString();
}
}
private void LoadBaseData()
{
ClsBaseInfo.FillComBaseInfo(ultraComboEditor3, "4086", _ob, false);
DataTable dtRate = (DataTable)ultraComboEditor3.DataSource;
dtRate.DefaultView.RowFilter = "BASECODE IN ('408602', '408603')";
UltraGridBand ugbC = entityGrid1.DisplayLayout.Bands[0];
QcmBaseQuery.NitializeSignMin(ultras[0]);
//标准范围下限符号
QcmBaseQuery.BindColumn(ultras[0], "StdminSign", ugbC);
//上限
QcmBaseQuery.NitializeSignMax(ultras[1]);
//标准范围上限符号
QcmBaseQuery.BindColumn(ultras[1], "StdmaxSign", ugbC);
//化学元素描述
QcmBaseQuery.NitializeChemicalElement(ultras[2], false, _ob);
QcmBaseQuery.BindColumn(ultras[2], "ChemCode", ugbC);
//限制元素
QcmBaseQuery.NitializeChemicalElement(ultras[11], true, _ob);
QcmBaseQuery.BindColumn(ultras[11], "EleCode", ugbC);
//替代元素
QcmBaseQuery.BindColumn(ultras[0], "RepMinSign", ugbC);
QcmBaseQuery.BindColumn(ultras[1], "RepMaxSign", ugbC);
QcmBaseQuery.BindColumn(ultras[2], "RepCode", ugbC);
QcmBaseQuery.NitializeProductBigType(ultras[12], false, _ob);
}
///
/// 查询质量设计成分
///
///
public void Query()
{
CraftOrdDesignStdCicEntityBindingSource.Clear();
DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CraftOrdFdCic.queryM", new object[] { ordLnPk }, _ob);
GridHelper.CopyDataToDatatable(dt, dataTable1, true);
}
public void Clear()
{
this.CraftOrdDesignStdCicEntityBindingSource.Clear();
}
public void Save()
{
List parms = new List();
var mRow = ultraGrid1.Rows.Where(a=>a.GetValue("Chk") == "True").FirstOrDefault();
var rows = entityGrid1.Rows.Where(a=>a.GetValue("Chk") == "True");
//if (mRow == null && rows.Count() == 0)
//{
// MessageUtil.ShowWarning("请选择一条记录!");
// return;
//}
//if (ultraNumericEditor1.Value.ToString2() == "0")
//{
// MessageUtil.ShowWarning("熔炼成分套数至少为一套!");
// return;
//}
if (ultraNumericEditor2.Value.ToString2() == "0")
{
MessageUtil.ShowWarning("成品成分套数至少为一套!");
return;
}
if (ultraComboEditor3.Value.ToString2() == "")
{
MessageUtil.ShowWarning("请选择成品成分取样频率!");
return;
}
if (ultraComboEditor4.Value.ToString2() == "")
{
MessageUtil.ShowWarning("请选择是否共样!");
return;
}
//string smeltingCnt = ultraNumericEditor1.Value.ToString2();
string productCnt = ultraNumericEditor2.Value.ToString2();
string rateFd = ultraComboEditor3.Value.ToString2();
string common = ultraComboEditor4.Value.ToString2();
string mscPline = ultraGrid1.ActiveRow.GetValue("MSC_PLINE");
string processCode = ultraGrid1.ActiveRow.GetValue("PROCESS_CODE");
string cic = ultraGrid1.ActiveRow.GetValue("CIC");
foreach (var row in rows)
{
CraftOrdFdCicEntity parm = EntityHelper.CopyEntity(row.ListObject);
if (parm.ChemCode == "")
{
MessageUtil.ShowWarning("请选化学元素!");
row.SetCellActive("ChemCode");
return;
}
if (!parm.StdminSign.Equals(""))
{
if (parm.Stdmin.Equals(""))
{
MessageUtil.ShowWarning("请输入标准范围下限值!");
row.SetCellActive("Stdmin");
return;
}
if (parm.ComplexType.Equals("0"))
{
if (!StringUtil.IsNumber(parm.Stdmin))
{
MessageUtil.ShowWarning("标准范围下限值请输入数字!");
row.SetCellActive("Stdmin");
return;
}
}
else
{
if (!QcmBaseCommon.CheckElement(parm.Stdmin, _ob))
{
MessageUtil.ShowWarning("标准范围下限值输入公式不合法,请重新输入!");
row.SetCellActive("Stdmin");
return;
}
}
}
else
{
if (!parm.Stdmin.Equals(""))
{
MessageUtil.ShowWarning("请选择标准范围下限符号!");
row.SetCellActive("Stdmin");
return;
}
}
if (parm.StdminSign.Equals("=") && !parm.StdmaxSign.Equals(""))
{
MessageUtil.ShowWarning("标准范围下限符号为'=',不能选择上限符号!");
row.SetCellActive("StdminSign");
return;
}
if (parm.Isjudge.ToString().Equals("True") && parm.StdminSign.Equals("") && parm.StdmaxSign.Equals(""))
{
MessageUtil.ShowWarning("请选择标准范围下限符号或者上限符号!");
row.SetCellActive("StdminSign");
return;
}
if (!parm.StdmaxSign.Equals(""))
{
if (parm.Stdmax.Equals(""))
{
MessageUtil.ShowWarning("请输入标准范围上限值!");
row.SetCellActive("Stdmax");
return;
}
if (parm.ComplexType.Equals("0"))
{
if (!StringUtil.IsNumber(parm.Stdmax))
{
MessageUtil.ShowWarning("标准范围上限值请输入数字!");
row.SetCellActive("Stdmax");
return;
}
}
else
{
if (!QcmBaseCommon.CheckElement(parm.Stdmax, _ob))
{
MessageUtil.ShowWarning("标准范围上限值输入公式不合法,请重新输入!");
row.SetCellActive("Stdmax");
return;
}
}
}
else
{
if (!parm.Stdmax.Equals(""))
{
MessageUtil.ShowWarning("请选择标准范围上限符号!");
row.SetCellActive("Stdmax");
return;
}
}
if (parm.ComplexType.Equals("0") && !parm.Stdmin.Equals("") && !parm.Stdmax.Equals("")) //&& double.Parse(stdMin) > double.Parse(stdMax)
{
int i = QcmBaseInfo.CheckStdData(parm.StdminSign, parm.StdmaxSign, parm.Stdmin, parm.Stdmax);
if (i == 0)
{
MessageUtil.ShowWarning("输入的数据不完整!");
return;
}
if (i == 1)
{
MessageUtil.ShowWarning("标准范围下限值与上限值相等,上下限符号请选择<=和>=!");
row.SetCellActive("StdminSign");
return;
}
if (i == 2)
{
MessageUtil.ShowWarning("标准范围下限值不能大于上限值!");
row.SetCellActive("Stdmin");
return;
}
}
if (parm.EleMinSign.Equals("=") && !parm.EleMaxSign.Equals(""))
{
MessageUtil.ShowWarning("限制元素下限符号为'=',不能选择上限符号!");
row.SetCellActive("EleMaxSign");
return;
}
if (parm.SizeMinSign2.Equals("=") && !parm.SizeMaxSign2.Equals(""))
{
MessageUtil.ShowWarning("限制规格(一)下限符号为'=',不能选择上限符号!");
row.SetCellActive("SizeMaxSign2");
return;
}
if (parm.SizeMinSign.Equals("=") && !parm.SizeMaxSign.Equals(""))
{
MessageUtil.ShowWarning("限制规格(二)下限符号为'=',不能选择上限符号!");
row.SetCellActive("SizeMaxSign");
return;
}
if (parm.RepMinSign.Equals("=") && !parm.RepMaxSign.Equals(""))
{
MessageUtil.ShowWarning("替代元素下限符号为'=',不能选择上限符号!");
row.SetCellActive("RepMaxSign");
return;
}
if (!parm.EleName.Equals(""))
{
if (parm.EleName.Equals(parm.ChemName))
{
MessageUtil.ShowWarning("化学元素描述不能与限制元素描述相同!");
row.SetCellActive("ChemName");
return;
}
if (parm.EleMinSign.Equals("") && parm.EleMaxSign.Equals(""))
{
MessageUtil.ShowWarning("请选择限制元素上限符号或者下限符号!");
row.SetCellActive("EleMinSign");
return;
}
if (!parm.EleMinSign.Equals("") && parm.EleMin.Equals(""))
{
MessageUtil.ShowWarning("请输入限制元素下限值!");
row.SetCellActive("EleMin");
return ;
}
if (parm.EleMinSign.Equals("") && !parm.EleMin.Equals(""))
{
MessageUtil.ShowWarning("请选择限制元素下限符号!");
row.SetCellActive("EleMinSign");
return;
}
if (!parm.EleMaxSign.Equals("") && parm.EleMax.Equals(""))
{
MessageUtil.ShowWarning("请输入限制元素上限值!");
row.SetCellActive("EleMax");
return;
}
if (parm.EleMaxSign.Equals("") && !parm.EleMax.Equals(""))
{
MessageUtil.ShowWarning("请选择限制元素上限符号!");
row.SetCellActive("EleMaxSign");
return;
}
if (!parm.EleMax.Equals("") && !StringUtil.IsNumber(parm.EleMax))
{
MessageUtil.ShowWarning("限制元素上限值请输入数字!");
row.SetCellActive("EleMax");
return;
}
if (!parm.EleMin.Equals("") && !StringUtil.IsNumber(parm.EleMin))
{
MessageUtil.ShowWarning("限制元素下限值请输入数字!");
row.SetCellActive("EleMin");
return;
}
if (!parm.EleMaxSign.Equals("") && !parm.EleMinSign.Equals("")) //&& Convert.ToInt32(ele_min) > Convert.ToInt32(ele_max)
{
int i = QcmBaseInfo.CheckStdData(parm.EleMinSign, parm.EleMaxSign, parm.EleMin, parm.EleMax);
if (i == 0)
{
MessageUtil.ShowWarning("输入的数据不完整!");
return;
}
if (i == 1)
{
MessageUtil.ShowWarning("限制元素下限值与上限值相等,上下限符号请选择<=和>=!");
row.SetCellActive("EleMinSign");
return;
}
if (i == 2)
{
MessageUtil.ShowWarning("限制元素下限值不能大于上限值!");
row.SetCellActive("EleMin");
return;
}
}
}
else
{
if (!parm.EleMaxSign.Equals("") || !parm.EleMinSign.Equals("") || !parm.EleMin.Equals("") || !parm.EleMax.Equals(""))
{
MessageUtil.ShowWarning("请选择限制元素描述!");
row.SetCellActive("EleMinSign");
return;
}
}
//-------------------新增的7个字段-----------------------------------------
if (!parm.RepName.Equals(""))
{
if (parm.RepName.Equals(parm.ChemName))
{
MessageUtil.ShowWarning("化学元素描述不能与替代元素描述相同!");
row.SetCellActive("ChemName");
return;
}
if (parm.RepMinSign.Equals("") && parm.RepMaxSign.Equals(""))
{
MessageUtil.ShowWarning("请选择替代元素上限符号或者下限符号!");
row.SetCellActive("RepMinSign");
return;
}
if (!parm.RepMinSign.Equals("") && parm.RepMin.Equals(""))
{
MessageUtil.ShowWarning("请输入替代元素下限值!");
row.SetCellActive("RepMin");
return;
}
if (parm.RepMinSign.Equals("") && !parm.RepMin.Equals(""))
{
MessageUtil.ShowWarning("请选择替代元素下限符号!");
row.SetCellActive("RepMinSign");
return;
}
if (!parm.RepMaxSign.Equals("") && parm.RepMax.Equals(""))
{
MessageUtil.ShowWarning("请输入替代元素上限值!");
row.SetCellActive("RepMax");
return;
}
if (parm.RepMaxSign.Equals("") && !parm.RepMax.Equals(""))
{
MessageUtil.ShowWarning("请选择替代元素上限符号!");
row.SetCellActive("RepMaxSign");
return;
}
if (!parm.RepMax.Equals("") && !StringUtil.IsNumber(parm.RepMax))
{
MessageUtil.ShowWarning("替代元素上限值请输入数字!");
row.SetCellActive("RepMax");
return;
}
if (!parm.RepMin.Equals("") && !StringUtil.IsNumber(parm.RepMin))
{
MessageUtil.ShowWarning("替代元素下限值请输入数字!");
row.SetCellActive("RepMin");
return;
}
if (!parm.RepMaxSign.Equals("") && !parm.RepMinSign.Equals("")) //&& Convert.ToInt32(repmin) > Convert.ToInt32(repmax)
{
int i = QcmBaseInfo.CheckStdData(parm.RepMinSign, parm.RepMaxSign, parm.RepMin, parm.RepMax);
if (i == 0)
{
MessageUtil.ShowWarning("输入的数据不完整!");
return;
}
if (i == 1)
{
MessageUtil.ShowWarning("替代元素下限值与上限值相等,上下限符号请选择<=和>=!");
row.SetCellActive("RepMinSign");
return;
}
if (i == 2)
{
MessageUtil.ShowWarning("替代元素下限值不能大于上限值!");
row.SetCellActive("RepMin");
return;
}
}
}
else
{
if (!parm.RepMaxSign.Equals("") || !parm.RepMinSign.Equals("") || !parm.RepMin.Equals("") || !parm.RepMax.Equals(""))
{
MessageUtil.ShowWarning("请选择替代元素!");
row.SetCellActive("RepMinSign");
return;
}
}
if (parm.ChemType.Equals("单一元素"))
parm.ChemType = "A";
else if (parm.ChemType.Equals("复合元素"))
parm.ChemType = "B";
parm.CreateName = CoreUserInfo.UserInfo.GetUserName();
parm.UpdateName = CoreUserInfo.UserInfo.GetUserName();
parm.DeleteName = CoreUserInfo.UserInfo.GetUserName();
parm.SpeclFl = "2";
parm.DesginKey = designKey;
parm.OrdLnPk = ordLnPk;
parm.CicMemo = ultraGrid1.ActiveRow.GetValue("CIC_MEMO");
parm.MscPline = ultraGrid1.ActiveRow.GetValue("MSC_PLINE");
parm.ProcessCode = ultraGrid1.ActiveRow.GetValue("PROCESS_CODE");
parm.Cic = ultraGrid1.ActiveRow.GetValue("CIC");
parms.Add(parm);
}
if (MessageUtil.ShowYesNoAndQuestion("是否确认保存?") == DialogResult.No)
{
return;
}
List jsons = new List();
foreach (var craftOrdFdCicEntity in parms)
{
jsons.Add(JSONFormat.Format(craftOrdFdCicEntity));
}
string chkMscPline = mRow == null ? "" : mRow.GetValue("MSC_PLINE");
string chkProcessCode = mRow == null ? "" : mRow.GetValue("PROCESS_CODE");
string chkMemo = mRow == null ? "" : mRow.GetValue("CIC_MEMO");
ServerHelper.SetData("com.steering.pss.sale.order.CraftOrdFdCic.save",
new object[] { jsons, ordLnPk, chkMscPline, chkProcessCode, chkMemo, productCnt, rateFd, common}, _ob);
MessageUtil.ShowTips("保存成功!");
Relocate(mscPline, processCode, cic);
}
private void Relocate(string mscPline, string processCode, string cic)
{
Query();
var mRow = ultraGrid1.Rows.Where(a => a.GetValue("MSC_PLINE") == mscPline && a.GetValue("PROCESS_CODE") == processCode &&
a.GetValue("CIC") == cic).FirstOrDefault();
if (mRow != null)
{
mRow.Activate();
}
}
public void Delete()
{
List parms = new List();
var mRow = ultraGrid1.Rows.Where(a => a.GetValue("CHK") == "True").FirstOrDefault();
var rows = entityGrid1.Rows.Where(a => a.GetValue("Chk") == "True");
if (mRow == null && rows.Count() == 0)
{
MessageUtil.ShowWarning("请选择一条记录!");
return;
}
string mscPline = ultraGrid1.ActiveRow.GetValue("MSC_PLINE");
string processCode = ultraGrid1.ActiveRow.GetValue("PROCESS_CODE");
string cic = ultraGrid1.ActiveRow.GetValue("CIC");
foreach (var row in rows)
{
CraftOrdFdCicEntity parm = EntityHelper.CopyEntity(row.ListObject);
parm.CreateName = CoreUserInfo.UserInfo.GetUserName();
parm.UpdateName = CoreUserInfo.UserInfo.GetUserName();
parm.DeleteName = CoreUserInfo.UserInfo.GetUserName();
parm.SpeclFl = "2";
parm.DesginKey = designKey;
parms.Add(parm);
}
if (MessageUtil.ShowYesNoAndQuestion("是否确认删除?") == DialogResult.No)
{
return;
}
List jsons = new List();
foreach (var craftOrdDesignStdCicEntity in parms)
{
jsons.Add(JSONFormat.Format(craftOrdDesignStdCicEntity));
}
string parmMscPline = mRow == null ? "" : mRow.GetValue("MSC_PLINE");
string parmProcessCode = mRow == null ? "" : mRow.GetValue("PROCESS_CODE");
ServerHelper.SetData("com.steering.pss.sale.order.CraftOrdFdCic.delete",
new object[] { jsons, ordLnPk, parmMscPline, parmProcessCode }, _ob);
MessageUtil.ShowTips("删除成功!");
Relocate(mscPline, processCode, cic);
}
public void CopyNkStd()
{
var mRow = ultraGrid1.Rows.Where(a => a.GetValue("CHK") == "True").FirstOrDefault();
if (mRow == null)
{
MessageUtil.ShowWarning("请选择一条成分标准索引码!");
return;
}
if (mRow.GetValue("CIC") == "")
{
MessageUtil.ShowWarning("请选择一条成分标准索引码!");
return;
}
if (MessageUtil.ShowYesNoAndQuestion("是否确认复制内控索引码" + mRow.GetValue("CIC") + "?") == DialogResult.No)
{
return;
}
ServerHelper.SetData("com.steering.pss.sale.order.CraftOrdFdCic.copyNkStd", new object[] { designKey, ordLnPk,
mRow.GetValue("MSC_PLINE"), mRow.GetValue("PROCESS_CODE"), mRow.GetValue("CIC") }, _ob);
MessageUtil.ShowTips("复制成功!");
Query();
}
private void GridEdite(UltraGridRow row)
{
if (row.GetValue("Chk") == "True")
{
foreach (UltraGridCell cell in row.Cells)
{
if (cell.Column.CellActivation == Activation.AllowEdit)
{
cell.Activation = Activation.AllowEdit;
}
}
}
else
{
foreach (UltraGridCell cell in row.Cells)
{
if (cell.Column.Key == "Chk") continue;
if (cell.Column.CellActivation == Activation.AllowEdit)
{
cell.Activation = Activation.ActivateOnly;
}
}
}
}
private void entityGrid1_CellChange(object sender, CellEventArgs e)
{
e.Cell.Row.Update();
GridEdite(e.Cell.Row);
var ugr = e.Cell.Row;
if (e.Cell.Column.Key.Equals("ChemCode")) /// 成分下拉框操作
{
ugr.Cells["ChemName"].Value = ugr.Cells["ChemCode"].Text;
string chemCode = ugr.Cells["ChemCode"].Value.ToString();
DataRow[] dr = ((DataTable)ultras[2].DataSource).Select("CHEM_CODE ='" + chemCode + "'");
if (dr.Length > 0)
{
//ugr.Cells["xh"].Value = Convert.ToInt32(dr[0][0].ToString().Substring(1));
ugr.Cells["ChemType"].Value = dr[0]["CHEM_TYPE_CODE"].ToString();
ugr.Cells["ChemFormula"].Value = dr[0]["CHEM_FORMULA"].ToString();
}
else
{
ugr.Cells["ChemName"].Value = "";
ugr.Cells["ChemType"].Value = "";
ugr.Cells["ChemFormula"].Value = "";
}
}
}
private void entityGrid1_AfterRowInsert(object sender, RowEventArgs e)
{
var mRow = ultraGrid1.ActiveRow;
e.Row.SetValue("mscPline", mRow.GetValue("MSC_PLINE"));
e.Row.SetValue("processCode", mRow.GetValue("PROCESS_CODE"));
e.Row.SetValue("processDesc", mRow.GetValue("PROCESS_DESC"));
e.Row.SetValue("cic", mRow.GetValue("CIC"));
e.Row.Cells["IsCheck"].Value = true;
e.Row.Cells["IsJudge"].Value = true;
e.Row.Cells["IsQuote"].Value = true;
e.Row.Cells["ComplexType"].Value = false;
e.Row.Cells["CraftSource"].Value = "1";
e.Row.Cells["SPeclFl"].Value = "2";
e.Row.Cells["OrdLnPk"].Value = ordLnPk;
e.Row.Update();
}
private void ultraTextEditor1_EditorButtonClick(object sender, EditorButtonEventArgs e)
{
if (ultraGrid1.ActiveCell.Column.Key == "MSC_PLINE")
{
if (entityGrid1.Rows.Count != 0)
{
MessageUtil.ShowWarning("已维护首日检数据,不能修改!");
}
else
{
UltraGridRow row = ultraGrid1.ActiveRow;
string key = ultraGrid1.ActiveCell.Column.Key;
DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CraftOrdFdCic.getMscPlineProcess",
new object[] { designKey }, _ob);
dt.Columns["MSC_PLINE"].Caption = "制程号";
dt.Columns["WHOLE_BACKLOG"].Caption = "全程途径码";
dt.Columns["WHOLE_BACKLOG_DESC"].Caption = "全程途径描述";
dt.Columns["PROCESS_DESC"].Caption = "工序";
dt.DefaultView.RowFilter = "PROCESS_CODE = 'A'";
BaseInfoPopup popup = new BaseInfoPopup(dt, "MSC_PLINE", "PROCESS_CODE");
GridHelper.RefreshAndAutoSize(popup.UltraGrid1);
popup.LabelTextBox1.Caption = "制程号";
if (popup.ShowDialog() == DialogResult.OK)
{
row.SetValue("MSC_PLINE", popup.ChoicedRow.GetValue("MSC_PLINE"));
row.SetValue("PROCESS_DESC", popup.ChoicedRow.GetValue("PROCESS_DESC"));
row.SetValue("PROCESS_CODE", popup.ChoicedRow.GetValue("PROCESS_CODE"));
row.SetValue("CIC", popup.ChoicedRow.GetValue("CIC"));
row.Update();
}
}
}
}
private void ultraGrid1_CellChange(object sender, CellEventArgs e)
{
e.Cell.Row.Update();
}
private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
{
var mRow = ultraGrid1.ActiveRow;
string cic = mRow.GetValue("CIC");
string mscPline = mRow.GetValue("MSC_PLINE");
string processCode = mRow.GetValue("PROCESS_CODE");
this.CraftOrdDesignStdCicEntityBindingSource.DataSource = EntityHelper.GetData(
"com.steering.pss.sale.order.CraftOrdFdCic.query",
new object[] { ordLnPk, mscPline, processCode, cic }, _ob);
foreach (var row in entityGrid1.Rows)
{
GridEdite(row);
}
}
private void entityGrid1_BeforeRowInsert(object sender, BeforeRowInsertEventArgs e)
{
if (ultraGrid1.ActiveRow == null || ultraGrid1.ActiveRow.GetValue("CIC") == "")
{
e.Cancel = true;
}
}
private void ultraGrid1_AfterRowInsert(object sender, RowEventArgs e)
{
e.Row.Update();
}
///
/// 复制
///
public void Copy()
{
var chkRows = entityGrid1.Rows.Where(a=>a.GetValue("chk") == "True");
if (chkRows.Count() == 0)
{
MessageUtil.ShowWarning("请选择记录后,再进行操作!");
return;
}
ultraGrid1.UpdateData();
DataTable copyTable = CreateTableByEntity((CraftOrdFdCicEntity)chkRows.FirstOrDefault().ListObject);
foreach (UltraGridRow row in entityGrid1.Rows)
{
if (row.GetValue("Chk") != "True") continue;
DataRow dr = copyTable.NewRow();
CopyEntityToRow((CraftOrdFdCicEntity)row.ListObject, dr);
copyTable.Rows.Add(dr);
}
DataTable[] copyTabs = new DataTable[] { copyTable, new DataTable() };
Clipboard.SetData("Cic", copyTabs);
}
///
/// 粘贴
///
public void Paste()
{
if (ultraGrid1.ActiveRow == null || ultraGrid1.ActiveRow.GetValue("CIC") == "")
{
MessageUtil.ShowWarning("请选择一条成分标准索引码!");
return;
}
DataTable[] copyTabs = (DataTable[])Clipboard.GetData("Cic");
if (copyTabs == null)
{
MessageUtil.ShowWarning("没有数据,请复制后再进行操作!");
return;
}
DataTable copyTab = copyTabs[0];
DataTable copyTab2 = copyTabs[1];
if (copyTab == null || copyTab.Rows.Count == 0)
{
MessageUtil.ShowWarning("没有数据,请复制后再进行操作!");
return;
}
dataTable1.BeginInit();
List data = (List)CraftOrdDesignStdCicEntityBindingSource.DataSource;
//if (entityGrid1.DataSource is List)
//{
// data = (List)entityGrid1.DataSource;
//}
CraftOrdFdCicEntity activeFd = null;
foreach (DataRow row in copyTab.Rows)
{
CraftOrdFdCicEntity fd = new CraftOrdFdCicEntity();
fd.Chk = true;
CopyRowToEntity(row, fd);
data.Add(fd);
activeFd = fd;
}
CraftOrdDesignStdCicEntityBindingSource.ResetBindings(false);
//CraftOrdDesignStdCicEntityBindingSource.DataSource = data;
dataTable1.EndInit();
entityGrid1.UpdateData();
if (entityGrid1.Rows.Count > 0)
{
entityGrid1.Rows[entityGrid1.Rows.Count - 1].Activate();
}
}
private string GetLineName(string name)
{
string lineName = "";
for (int i = 0; i < name.Length; i++)
{
if (i == 0)
{
lineName += name[i];
}
else
{
if (name[i] >= 'A' && name[i] <= 'Z')
{
lineName += '_';
lineName += name[i];
}
else
{
lineName += name[i];
}
}
}
return lineName.ToUpper();
}
private string GetName(string lineName)
{
string[] strs = lineName.Split('_');
string name = "";
for (int i = 0; i < strs.Length; i++)
{
name += strs[i].Substring(0, 1).ToUpper() + strs[i].Substring(1).ToLower();
}
return name;
}
private DataTable CreateTableByEntity(CraftOrdFdCicEntity fdEntity)
{
DataTable dt = new DataTable();
PropertyInfo[] srcPropertyInfos = fdEntity.GetType().GetProperties();
foreach (PropertyInfo srcPropertyInfo in srcPropertyInfos)
{
dt.Columns.Add(GetLineName(srcPropertyInfo.Name));
}
return dt;
}
private void CopyEntityToRow(CraftOrdFdCicEntity fdEntity, DataRow desRow)
{
PropertyInfo[] pros = fdEntity.GetType().GetProperties();
foreach (PropertyInfo pro in pros)
{
desRow[GetLineName(pro.Name)] = pro.GetValue(fdEntity, null);
}
}
private void CopyRowToEntity(DataRow row, CraftOrdFdCicEntity fdEntity)
{
PropertyInfo[] pros = fdEntity.GetType().GetProperties();
foreach (DataColumn dc in row.Table.Columns)
{
if (dc.ColumnName == "CREATE_TIME") continue;
PropertyInfo pro = fdEntity.GetType().GetProperty(GetName(dc.ColumnName));
if(pro != null)
{
pro.SetValue(fdEntity, ConvertDataType(pro.PropertyType, row[dc.ColumnName].ToString()), null);
}
}
}
private object ConvertDataType(Type type, object objValue)
{
if (type == typeof(bool))
{
bool result;
if (bool.TryParse(objValue.ToString(), out result))
{
return result;
}
else
{
return false;
}
}
else if (type == typeof(bool?))
{
bool result;
if (bool.TryParse(objValue.ToString(), out result))
{
return result;
}
else
{
return null;
}
}
else if (type == typeof(int?))
{
if (objValue.ToString2() == "")
{
return null;
}
else
{
return int.Parse(objValue.ToString());
}
}
else if (type == typeof(long?))
{
if (objValue.ToString2() == "")
{
return null;
}
else
{
return long.Parse(objValue.ToString());
}
}
else if (type == typeof(short?))
{
if (objValue.ToString2() == "")
{
return null;
}
else
{
return short.Parse(objValue.ToString());
}
}
else if (type == typeof(float?))
{
if (objValue.ToString2() == "")
{
return null;
}
else
{
return float.Parse(objValue.ToString());
}
}
else if (type == typeof(double?))
{
if (objValue.ToString2() == "")
{
return null;
}
else
{
return double.Parse(objValue.ToString());
}
}
else if (type == typeof(decimal?))
{
if (objValue.ToString2() == "")
{
return null;
}
else
{
return decimal.Parse(objValue.ToString());
}
}
else if (type == typeof(DateTime?))
{
if (objValue.ToString2() == "")
{
return null;
}
else
{
return DateTime.Parse(objValue.ToString());
}
}
else
{
return objValue == null ? "" : objValue.ToString();
}
}
private void ultraGrid1_BeforeRowInsert(object sender, BeforeRowInsertEventArgs e)
{
if (ultraGrid1.Rows.Count > 0)
{
e.Cancel = true;
}
}
}
}