| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Windows.Forms;
- using com.steering.mes.mcp.entity;
- using Core.Mes.Client.Comm.Control;
- using Core.Mes.Client.Comm.Format;
- using Core.Mes.Client.Comm.Tool;
- using Core.StlMes.Client.Mcp.Control.Entity;
- using Core.StlMes.Client.Mcp.Mch.Entity;
- using CoreFS.CA06;
- using Infragistics.Win;
- using Infragistics.Win.UltraWinGrid;
- using NPOI.SS.UserModel;
- namespace Core.StlMes.Client.Mcp.Mch.MchResult
- {
- public partial class MesureData : FrmBase
- {
- private string _judgeStove;
- private string _batchNo;
- private string _plineCode = "";
- private string _heatPlanId;
- private string _userName;
- private PlnZyJgxCEntity _jgxPlan = null;
- public List<RtdMeasurePosdataEntity> list = new List<RtdMeasurePosdataEntity>();
- public MesureData(string heatPlanId, string judgeStove, string batchNo,string PlineCode,OpeBase _ob, string userName,bool ShowAdd)
- {
- _judgeStove = judgeStove;
- _batchNo = batchNo;
- _heatPlanId = heatPlanId;
- _plineCode = PlineCode;
- _userName = userName;
- this.ob = _ob;
- InitializeComponent();
- if (!ShowAdd)
- {
- uegAdd.Visible = false;
- }
- Query();
- }
- public MesureData(PlnZyJgxCEntity JgxPlan, OpeBase _ob, string userName, bool ShowAdd, string CustomInfo)
- {
- _jgxPlan = JgxPlan;
- _judgeStove = JgxPlan.JudgeStoveNo;
- _batchNo = JgxPlan.BatchNo;
- _heatPlanId = JgxPlan.HeatPlanNo;
- if (!CustomInfo.Equals("NotPline"))
- {
- _plineCode = JgxPlan.PlineCode;
- }
- _userName = userName;
- this.ob = _ob;
- InitializeComponent();
- if (!ShowAdd)
- {
- uegAdd.Visible = false;
- }
- Query();
- }
- public MesureData(PlnZyJgxCEntity JgxPlan, OpeBase _ob, string userName, bool ShowAdd)
- {
- _jgxPlan = JgxPlan;
- _judgeStove = JgxPlan.JudgeStoveNo;
- _batchNo = JgxPlan.BatchNo;
- _heatPlanId = JgxPlan.HeatPlanNo;
- _plineCode = JgxPlan.PlineCode;
- _userName = userName;
- this.ob = _ob;
- InitializeComponent();
- if (!ShowAdd)
- {
- uegAdd.Visible = false;
- }
- Query();
- }
- protected override void OnLoad(EventArgs e)
- {
- base.OnLoad(e);
- EntityHelper.ShowGridCaption<RtdMeasurePosdataEntity>(ugData.DisplayLayout.Bands[0]);
- ugData.DisplayLayout.Override.AllowRowFiltering = DefaultableBoolean.False;
- ugData.DisplayLayout.Override.HeaderClickAction = HeaderClickAction.Default;
- EntityHelper.ShowGridCaption<RtdMeasurePosdataEntity>(ultraGrid1.DisplayLayout.Bands[0]);
- bindingSource1.DataSource = new List<RtdMeasurePosdataEntity>()
- {
- new RtdMeasurePosdataEntity()
- {
- MatNo = "1",
- ActLen = (decimal)13313,
- ActWeight = 529,
- ProBz = "甲",
- ProBc = "早"
- }
- };
- }
- private void ugData_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
- {
- RtdMeasurePosdataEntity entity = e.Row.ListObject as RtdMeasurePosdataEntity;
- if(entity==null) return;
- if(entity.Flag== "10") e.Row.Appearance.BackColor = Color.Gray;
- else if (entity.Rk != "1") e.Row.Appearance.BackColor = Color.Yellow;
- e.Row.Cells["MatNo"].EditorComponent = entity.Flag == "10" ? uteRecover : uteRemove;
- entity.WtType = entity.OraActWeight == null ? "实重" : "理重";
- }
- private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
- {
- switch (e.Tool.Key)
- {
- case "Save": // ButtonTool
- Query();
- // Place code here
- break;
- case "Show": // ButtonTool
- ShowData();
- // Place code here
- break;
- case "Close": // ButtonTool
- this.DialogResult = DialogResult.Cancel;
- break;
- case "Turn": // ButtonTool
- Turn();
- // Place code here
- break;
- case "Revert": // ButtonTool
- Revert();
- // Place code here
- break;
- }
- }
- private void Query()
- {
- list = EntityHelper.GetData<RtdMeasurePosdataEntity>(
- "com.steering.mes.mcp.Mch.FrmMeasureResult.geRtdMeasurePosdataAll",
- new object[] { _judgeStove,_batchNo,_plineCode.ToString2(), "0" },
- ob);
-
- rtdMeasurePosdataEntityBindingSource.DataSource = chkFlag.Checked ?list: list.Where(p => p.Flag == "00").ToList() ;
- var WasteList = list.Where(p => p.Flag == "10").ToList();
- string message = "共" + list.Where(p=>p.Flag=="00").Select(p=>p.MatNo).Distinct().Count() + "支";
- string messageW=" ";
- if(WasteList.Any())
- messageW = " 已剔除" + WasteList.Count+ "条";
- ugData.DisplayLayout.Bands[0].Summaries[0].DisplayFormat = message;
- ugData.DisplayLayout.Bands[0].Summaries[1].DisplayFormat =
- list.Where(p => p.Flag == "00" && p.Rk == "1").Sum(p => p.ActLen).ToString3();
- ugData.DisplayLayout.Bands[0].Summaries[2].DisplayFormat =
- list.Where(p => p.Flag == "00" && p.Rk == "1").Sum(p => p.ActWeight).ToString3();
- ugData.DisplayLayout.Bands[0].Summaries["Waste"].DisplayFormat = messageW;
- GridHelper.RefreshAndAutoSizeExceptColumns(ugData, "MatInfo" );
- }
- private void Turn()
- {
- if(_jgxPlan==null) return;
-
- using (MesureDataPerWt mesureData = new MesureDataPerWt(ob,_jgxPlan))
- {
- mesureData.ShowDialog();
- if (mesureData.DialogResult == DialogResult.OK)
- {
- Query();
- }
- }
-
- }
- private void Revert()
- {
- if (_jgxPlan == null) return;
- var ccp = new CoreClientParam();
- ccp.ServerName = "com.steering.mes.mcp.Mch.FrmMeasureResult";
- ccp.MethodName = "Revert";
- ccp.ServerParams = new object[]
- {
- _jgxPlan.JudgeStoveNo,
- _jgxPlan.BatchNo,
- _jgxPlan.PlineCode
- };
- ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- if (ccp.ReturnCode != -1)
- {
- if (ccp.ReturnInfo.Equals("操作成功"))
- {
- Query();
- }
- else
- {
- MessageUtil.ShowTips(ccp.ReturnInfo);
- }
- }
- }
- private void chkFlag_CheckedChanged(object sender, EventArgs e)
- {
- rtdMeasurePosdataEntityBindingSource.DataSource = chkFlag.Checked ?list: list.Where(p => p.Flag == "00").ToList() ;
- 按钮显示区域.Tools["Show"].SharedPropsInternal.Caption = chkFlag.Checked ? "隐藏已剔除" : "显示已剔除";
- }
- private void ShowData()
- {
- chkFlag.Checked = !chkFlag.Checked;
- rtdMeasurePosdataEntityBindingSource.DataSource = chkFlag.Checked ? list : list.Where(p => p.Flag == "00").ToList();
- 按钮显示区域.Tools["Show"].SharedPropsInternal.Caption = chkFlag.Checked ? "隐藏已剔除" : "显示已剔除";
- }
- private void uteRemove_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
- {
- RtdMeasurePosdataEntity entity = ugData.ActiveRow.ListObject as RtdMeasurePosdataEntity;
- if (entity == null) return;
- if (entity.MatNoCx != null && !entity.MatNoCx.Equals(""))
- {
- MessageUtil.ShowTips("剔除失败,材料号不为空!!!");
- return;
- }
- var ccp = new CoreClientParam();
- ccp.ServerName = "com.steering.mes.mcp.Mch.FrmMeasureResult";
- ccp.MethodName = "DoRemove";
- ccp.ServerParams = new object[]
- {
- _heatPlanId,
- entity.KeyId
- };
- ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- if (ccp.ReturnCode != -1)
- {
- if (ccp.ReturnInfo.Equals("成功"))
- {
- Query();
- }
- else
- {
- MessageUtil.ShowTips(ccp.ReturnInfo);
- }
- }
- }
- private void uteRecover_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
- {
- RtdMeasurePosdataEntity entity = ugData.ActiveRow.ListObject as RtdMeasurePosdataEntity;
- if (entity == null) return;
- var ccp = new CoreClientParam();
- ccp.ServerName = "com.steering.mes.mcp.Mch.FrmMeasureResult";
- ccp.MethodName = "DoRecover";
- ccp.ServerParams = new object[]
- {
- _heatPlanId,
- entity.KeyId
- };
- ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- if (ccp.ReturnCode != -1)
- {
- if (ccp.ReturnInfo.Equals("成功"))
- {
- Query();
- }
- else
- {
- MessageUtil.ShowTips(ccp.ReturnInfo);
- }
- }
- }
- private void ultraButton1_Click(object sender, EventArgs e)
- {
- if (string.IsNullOrWhiteSpace(utMatNo.Text))
- {
- MessageBox.Show("请输入管号!");
- return;
- }
- double len = 0;
- if (string.IsNullOrWhiteSpace(uteLen.Text) || !double.TryParse(uteLen.Text.Trim(),out len))
- {
- MessageBox.Show("请输入正确的长度!");
- return;
- }
- if (string.IsNullOrWhiteSpace(uteWt.Text) || !double.TryParse(uteWt.Text.Trim(), out len))
- {
- MessageBox.Show("请输入正确的重量!");
- return;
- }
- RtdMeasurePosdataEntity entity = new RtdMeasurePosdataEntity()
- {
- MatNo = utMatNo.Text,
- ActLen = decimal.Parse(uteLen.Text.Trim()),
- ActWeight = decimal.Parse(uteWt.Text.Trim()),
- MatInfo = uteMatInfo.Text,
- Flag = "00",
- JudgeStoveNo = _judgeStove,
- BatchNo = _batchNo,
- CreateUser = _userName,
- ProBc = uceBc.SelectedIndex<0?"":uceBc.SelectedItem.DataValue.ToString2(),
- ProBz = uceBz.SelectedIndex<0?"":uceBz.SelectedItem.DataValue.ToString2()
- };
-
- var ccp = new CoreClientParam();
- ccp.ServerName = "com.steering.mes.mcp.Mch.FrmMeasureResult";
- ccp.MethodName = "DoAddMeasureData";
- ccp.ServerParams = new object[]
- {
- JSONFormat.Format(entity),
- _heatPlanId
- };
- ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- if (ccp.ReturnCode != -1)
- {
- MessageUtil.ShowTips(ccp.ReturnInfo);
- if (ccp.ReturnInfo.Equals("新增成功"))
- {
- Query();
- }
- }
- }
- private void ubt_Click(object sender, EventArgs e)
- {
- GridHelper.ulGridToExcel( ultraGrid1 , "导入模板");
- }
- private void btnExport_Click(object sender, EventArgs e)
- {
- List<RtdMeasurePosdataEntity> list = null;
- var openFileDialog = new OpenFileDialog
- {
- Filter = "测量点数据|*.xls;*.xlsx"
- };
- if (openFileDialog.ShowDialog() == DialogResult.OK)
- {
- list = ReadExcelToRtdMeasurePosdataEntity(openFileDialog.FileName);
-
- }
- if (list == null) return;
- if (list.Count <= 0)
- {
- MessageBox.Show("Excel无数据");
- return;
- }
- var ccp = new CoreClientParam();
- ccp.ServerName = "com.steering.mes.mcp.Mch.FrmMeasureResult";
- ccp.MethodName = "DoAddMeasureData";
- ccp.ServerParams = new object[]
- {
- list.Select(JSONFormat.Format).ToList(),
- _heatPlanId
- };
- ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- if (ccp.ReturnCode != -1)
- {
- MessageUtil.ShowTips(ccp.ReturnInfo);
- if (ccp.ReturnInfo.Equals("新增成功"))
- {
- Query();
- }
- }
- }
- public List<RtdMeasurePosdataEntity> ReadExcelToRtdMeasurePosdataEntity(string fileName)
- {
- //定义要返回的datatable对象
- List<RtdMeasurePosdataEntity> RtdMeasurePosdataEntitys = new List<RtdMeasurePosdataEntity>();
- try
- {
- if (!File.Exists(fileName))
- {
- return null;
- }
- //根据指定路径读取文件
- using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
- {
- //根据文件流创建excel数据结构
- NPOI.SS.UserModel.IWorkbook workbook = NPOI.SS.UserModel.WorkbookFactory.Create(fs);
- //IWorkbook workbook = new HSSFWorkbook(fs);
- for (int k = 0; k < workbook.NumberOfSheets; k++)
- {
- NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(k);
- if (sheet != null)
- {
- //最后一列的标号
- int rowCount = sheet.LastRowNum;
- for (int i = 1; i <= rowCount; ++i)
- {
- NPOI.SS.UserModel.IRow row = sheet.GetRow(i);
- if (row == null) continue; //没有数据的行默认是null
- if (row.Cells.Count < 3)
- {
- throw new Exception("无足够列");
- }
- string bc ="", bz = "";
- if (row.Cells.Count > 5)
- {
- bc = GetCellValue(row.Cells[4]);
- if (bc == "早") bc = "1";
- if (bc == "中") bc = "2";
- if (bc == "晚") bc = "3";
- if (bc == "白") bc = "0";
- if (bc != "" && bc != "1" && bc != "0" && bc != "2" && bc != "3")
- {
- throw new Exception("无法识别班次");
- }
- bz = GetCellValue(row.Cells[5]);
- if (bz == "甲") bz = "1";
- if (bz == "乙") bz = "2";
- if (bz == "丙") bz = "3";
- if (bz == "丁") bz = "4";
- if (bz != "" && bz != "1" && bz != "4" && bz != "2" && bz != "3")
- {
- throw new Exception("无法识别班组");
- }
- }
- RtdMeasurePosdataEntity entity = new RtdMeasurePosdataEntity()
- {
- MatNo = GetCellValue(row.Cells[0]),
- MatInfo= row.Cells.Count <4?"": GetCellValue(row.Cells[3]),
- Flag = "00",
- JudgeStoveNo = _judgeStove,
- BatchNo = _batchNo,
- CreateUser = _userName,
- ProBz = bz,
- ProBc = bc
- };
- decimal actLen;
- decimal actWt;
- decimal.TryParse(GetCellValue(row.Cells[1]), out actLen);
- decimal.TryParse(GetCellValue(row.Cells[2]), out actWt);
-
- if (actLen == null || actLen <= 0)
- {
- throw new Exception("长度异常");
- }
- if (actWt == null || actWt <= 0)
- {
- throw new Exception("重量异常");
- }
- entity.ActLen = actLen;
- entity.ActWeight = actWt;
- RtdMeasurePosdataEntitys.Add(entity);
- }
- }
- }
- }
- return RtdMeasurePosdataEntitys;
- }
- catch (Exception ex)
- {
- MessageBox.Show("EXCEL格式错误:" + ex.Message);
- return null;
- }
- }
- private string GetCellValue(ICell cell)
- {
- string value="";
- switch (cell.CellType)
- {
- case CellType.Blank:
- value = "";
- break;
- case CellType.Numeric:
- short format = cell.CellStyle.DataFormat;
- value = cell.NumericCellValue.ToString2();
- break;
- case CellType.String:
- value = cell.StringCellValue;
- break;
- }
- return value;
- }
- }
- }
|