| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666 |
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Windows.Forms;
- using CoreFS.CA06;
- using Core.Mes.Client.Comm.Tool;
- using Infragistics.Win.UltraWinEditors;
- using Core.StlMes.Client.Qcm;
- using Core.Mes.Client.Comm.Server;
- using Infragistics.Win.UltraWinGrid;
- using CoreFS.SA06;
- using Core.Mes.Client.Comm.Control;
- using Core.Mes.Client.Comm.Format;
- using System.Reflection;
- namespace Core.StlMes.Client.SaleOrder.Control
- {
- public partial class CraftOrdFdWicCtrl : UserControl
- {
- private OpeBase _ob;
- UltraComboEditor Wics = new UltraComboEditor();
- private string ordLnPk = "";
- private string designKey = "";
- public CraftOrdFdWicCtrl(System.Windows.Forms.Control container, string ordLnPk, string designKey, OpeBase ob)
- {
- InitializeComponent();
- _ob = ob;
- this.ordLnPk = ordLnPk;
- this.designKey = designKey;
- container.Controls.Add(this);
- this.Dock = DockStyle.Fill;
- LoadBaseData();
- }
- private void LoadBaseData()
- {
- UltraComboEditor ultraComPsc = new UltraComboEditor();
- UltraComboEditor ultraComProcess = new UltraComboEditor();
- UltraComboEditor ultraComJG = new UltraComboEditor();
- UltraComboEditor cmbProBigType = new UltraComboEditor();
- this.Controls.Add(ultraComPsc);
- this.Controls.Add(ultraComProcess);
- this.Controls.Add(ultraComJG);
- this.Controls.Add(cmbProBigType);
- ultraComPsc.Visible = false;
- ultraComProcess.Visible = false;
- ultraComJG.Visible = false;
- cmbProBigType.Visible = false;
- this.Controls.Add(Wics);
- Wics.Visible = false;
- //绑定数据源 产品规范描述
- QcmBaseCommon.InitDropUltraComEditor(ultraComPsc, "com.steering.pss.qcm.ComBaseQuery.getPsc", "PscDesc", _ob, false);
- //不可编辑
- UltraComboEditor cmbWtr = new UltraComboEditor();
- cmbWtr.DropDownListWidth = -1;
- this.Controls.Add(cmbWtr);
- cmbWtr.Visible = false;
- ClsBaseInfo.FillWtrExpress(cmbWtr, _ob, true);
- entityGrid1.DisplayLayout.Bands[0].Columns["Formula"].EditorComponent = cmbWtr;
- entityGrid1.DisplayLayout.Bands[0].Columns["Formula"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
- QcmBaseQuery.NitializeProductBigType(cmbProBigType, false, _ob);
- ClsBaseInfo.SetComboItemHeight(cmbProBigType);
- ClsBaseInfo.FillComBaseInfo(ultraComboEditor3, "4107", _ob, false);
- ((DataTable)ultraComboEditor3.DataSource).DefaultView.Sort = "BASECODE ASC";
- }
-
- /// <summary>
- /// 查询质量设计水压
- /// </summary>
- /// <param name="designStdWicEntity"></param>
- public void Query()
- {
- CraftOrdDesignStdWicEntityBindingSource.Clear();
- DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CraftOrdFdWic.queryM", new object[]{ ordLnPk }, _ob);
- GridHelper.CopyDataToDatatable(dt, dataTable1, true);
- }
- public void Clear()
- {
- this.CraftOrdDesignStdWicEntityBindingSource.Clear();
- }
- public void Save()
- {
- List<CraftOrdFdWicEntity> parms = new List<CraftOrdFdWicEntity>();
- 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 wic = ultraGrid1.ActiveRow.GetValue("WIC");
- foreach (var row in rows)
- {
- var parm = EntityHelper.CopyEntity<CraftOrdFdWicEntity>(row.ListObject);
- if (parm.PressureY == "" && parm.Pressure == "" && parm.Formula == "")
- {
- MessageUtil.ShowWarning("请输入试验压力或者试验压力公式");
- return;
- }
- if (parm.OutputStyle == "")
- {
- MessageUtil.ShowWarning("请选择工艺文件输出方式");
- return;
- }
- string formula = parm.Formula.Replace("f", "1").Replace("YS", "1").Replace("TS", "1").Replace("D", "2").Replace("t", "1");
- if (!parm.Formula.Equals("") && formula.CompileFormula() == null)
- {
- MessageUtil.ShowWarning("公式不合法,请重新输入");
- return;
- }
- if (parm.SaveTime.Equals(""))
- {
- MessageUtil.ShowWarning("请输入保压时间");
- return;
- }
- if ((parm.Pressure != "" || parm.PressureY != "") && parm.Formula != "")
- {
- if (parm.GetMaxvalue == null && parm.GetMinvalue == null)
- {
- MessageUtil.ShowWarning("请选择取大值或取小值");
- return;
- }
- }
- 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.WicMemo = ultraGrid1.ActiveRow.GetValue("WIC_MEMO");
- parm.MscPline = ultraGrid1.ActiveRow.GetValue("MSC_PLINE");
- parm.ProcessCode = ultraGrid1.ActiveRow.GetValue("PROCESS_CODE");
- parm.Wic = ultraGrid1.ActiveRow.GetValue("WIC");
- parms.Add(parm);
- }
- if (MessageUtil.ShowYesNoAndQuestion("是否确认保存?") == DialogResult.No)
- {
- return;
- }
- List<string> jsons = new List<string>();
- foreach (var craftOrdFdWicEntity in parms)
- {
- jsons.Add(JSONFormat.Format(craftOrdFdWicEntity));
- }
- string chkMscPline = mRow == null ? "" : mRow.GetValue("MSC_PLINE");
- string chkProcessCode = mRow == null ? "" : mRow.GetValue("PROCESS_CODE");
- string chkMemo = mRow == null ? "" : mRow.GetValue("WIC_MEMO");
- ServerHelper.SetData("com.steering.pss.sale.order.CraftOrdFdWic.save",
- new object[] { jsons, ordLnPk, chkMscPline, chkProcessCode, chkMemo }, _ob);
- MessageUtil.ShowTips("保存成功!");
- Relocate(mscPline, processCode, wic);
- }
- public void Delete()
- {
- List<CraftOrdFdWicEntity> parms = new List<CraftOrdFdWicEntity>();
- 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 wic = ultraGrid1.ActiveRow.GetValue("WIC");
- foreach (var row in rows)
- {
- var parm = EntityHelper.CopyEntity<CraftOrdFdWicEntity>(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<string> jsons = new List<string>();
- foreach (var craftOrdDesignStdWicEntity in parms)
- {
- jsons.Add(JSONFormat.Format(craftOrdDesignStdWicEntity));
- }
- string parmMscPline = mRow == null ? "" : mRow.GetValue("MSC_PLINE");
- string parmProcessCode = mRow == null ? "" : mRow.GetValue("PROCESS_CODE");
- ServerHelper.SetData("com.steering.pss.sale.order.CraftOrdFdWic.delete",
- new object[] { jsons, ordLnPk, parmMscPline, parmProcessCode }, _ob);
- MessageUtil.ShowTips("删除成功!");
- Relocate(mscPline, processCode, wic);
- }
- public void CopyNkStd()
- {
- var mRow = ultraGrid1.Rows.Where(a => a.GetValue("CHK") == "True").FirstOrDefault();
- if (mRow == null)
- {
- MessageUtil.ShowWarning("请选择一条水压标准索引码!");
- return;
- }
- if (mRow.GetValue("WIC") == "")
- {
- MessageUtil.ShowWarning("请选择一条水压标准索引码!");
- return;
- }
- if (MessageUtil.ShowYesNoAndQuestion("是否确认复制内控索引码" + mRow.GetValue("WIC") + "?") == DialogResult.No)
- {
- return;
- }
- ServerHelper.SetData("com.steering.pss.sale.order.CraftOrdFdWic.copyNkStd", new object[] { designKey, ordLnPk,
- mRow.GetValue("MSC_PLINE"), mRow.GetValue("PROCESS_CODE"), mRow.GetValue("WIC") }, _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);
- if (e.Cell.Column.Key == "PressureY")
- {
- if (e.Cell.Value.ToString() != "")
- {
- //英制压力转公制压力系数为0.00689476
- e.Cell.Row.Cells["Pressure"].Value = Math.Round(double.Parse(e.Cell.Value.ToString()) * 0.00689476, 2);
- }
- else
- {
- e.Cell.Row.Cells["Pressure"].Value = 0;
- }
- }
- else if (e.Cell.Column.Key == "Pressure")
- {
- if (e.Cell.Value.ToString() != "")
- {
- if (double.Parse(e.Cell.Value.ToString()) > 6894.76)
- {
- MessageUtil.ShowWarning("公制压力上限为68900");
- e.Cell.Row.Cells["Pressure"].Value = 6894.76;
- }
- //公制压力转英制压力系数为14.5
- e.Cell.Row.Cells["PressureY"].Value = Math.Round(double.Parse(e.Cell.Value.ToString()) / 0.00689476, 2);
- }
- else
- {
- e.Cell.Row.Cells["PressureY"].Value = 0;
- }
- }
- }
- private void Relocate(string mscPline, string processCode, string pic)
- {
- Query();
- var mRow = ultraGrid1.Rows.Where(a => a.GetValue("MSC_PLINE") == mscPline && a.GetValue("PROCESS_CODE") == processCode &&
- a.GetValue("WIC") == pic).FirstOrDefault();
- if (mRow != null)
- {
- mRow.Activate();
- }
- }
- 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("wic", mRow.GetValue("WIC"));
- e.Row.Cells["GetMaxvalue"].Value = true;
- e.Row.Cells["GetMinvalue"].Value = false;
- e.Row.Cells["CraftSource"].Value = "1";
- e.Row.Cells["SpeclFl"].Value = "2";
- e.Row.Cells["OrdLnPk"].Value = ordLnPk;
- }
- private void ultraTextEditor1_EditorButtonClick(object sender, EditorButtonEventArgs e)
- {
-
- }
- private void ultraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e)
- {
- }
- private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
- {
- var mRow = ultraGrid1.ActiveRow;
- string wic = mRow.GetValue("WIC");
- string mscPline = mRow.GetValue("MSC_PLINE");
- string processCode = mRow.GetValue("PROCESS_CODE");
- this.CraftOrdDesignStdWicEntityBindingSource.DataSource = EntityHelper.GetData<CraftOrdFdWicEntity>(
- "com.steering.pss.sale.order.CraftOrdFdWic.query",
- new object[] { ordLnPk, mscPline, processCode, wic }, _ob);
- foreach (var row in entityGrid1.Rows)
- {
- GridEdite(row);
- }
- }
- private void ultraTextEditor2_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.CraftOrdFdWic.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 = "工序";
- 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("WIC", popup.ChoicedRow.GetValue("WIC"));
- row.Update();
- }
- }
- }
- }
- private void entityGrid1_BeforeRowInsert(object sender, BeforeRowInsertEventArgs e)
- {
- if (ultraGrid1.ActiveRow == null || ultraGrid1.ActiveRow.GetValue("WIC") == "")
- {
- e.Cancel = true;
- }
- }
- private void ultraGrid1_CellChange(object sender, CellEventArgs e)
- {
- e.Cell.Row.Update();
- if (e.Cell.Column.Key == "CHK")
- {
- UltraGridRow chkRow = e.Cell.Row;
- foreach (UltraGridRow row in ultraGrid1.Rows)
- {
- if (row.Cells["CHK"].Value.ToString() == "True" && row != chkRow)
- {
- row.Cells["CHK"].Value = "False";
- row.Update();
- }
- }
- }
- }
- private void ultraGrid1_ClickCellButton(object sender, CellEventArgs e)
- {
- }
- /// <summary>
- /// 复制
- /// </summary>
- 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((CraftOrdFdWicEntity)chkRows.FirstOrDefault().ListObject);
- foreach (UltraGridRow row in entityGrid1.Rows)
- {
- if (row.GetValue("Chk") != "True") continue;
- DataRow dr = copyTable.NewRow();
- CopyEntityToRow((CraftOrdFdWicEntity)row.ListObject, dr);
- copyTable.Rows.Add(dr);
- }
- DataTable[] copyTabs = new DataTable[] { copyTable, new DataTable() };
- Clipboard.SetData("Wic", copyTabs);
- }
- /// <summary>
- /// 粘贴
- /// </summary>
- public void Paste()
- {
- if (ultraGrid1.ActiveRow == null || ultraGrid1.ActiveRow.GetValue("WIC") == "")
- {
- MessageUtil.ShowWarning("请选择一条成分标准索引码!");
- return;
- }
- DataTable[] copyTabs = (DataTable[])Clipboard.GetData("Wic");
- 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<CraftOrdFdWicEntity> data = (List<CraftOrdFdWicEntity>)CraftOrdDesignStdWicEntityBindingSource.DataSource;
- CraftOrdFdWicEntity activeFd = null;
- foreach (DataRow row in copyTab.Rows)
- {
- CraftOrdFdWicEntity fd = new CraftOrdFdWicEntity();
- fd.Chk = true;
- CopyRowToEntity(row, fd);
- data.Add(fd);
- activeFd = fd;
- }
- CraftOrdDesignStdWicEntityBindingSource.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(CraftOrdFdWicEntity 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(CraftOrdFdWicEntity 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, CraftOrdFdWicEntity 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;
- }
- }
- }
- }
|