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.Mch.Entity; using CoreFS.CA06; using Infragistics.Win; using Infragistics.Win.UltraWinGrid; using Core.StlMes.Client.ZGMil.Entity; using NPOI.SS.UserModel; namespace Core.StlMes.Client.ZGMil.Result { 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 list = new List(); 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) { _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(ugData.DisplayLayout.Bands[0]); ugData.DisplayLayout.Override.AllowRowFiltering = DefaultableBoolean.False; ugData.DisplayLayout.Override.HeaderClickAction = HeaderClickAction.Default; EntityHelper.ShowGridCaption(ultraGrid1.DisplayLayout.Bands[0]); bindingSource1.DataSource = new List() { new RtdMeasurePosdataEntity() { MatNo = "1", ActLen = (decimal)13313, ActWeight = 529, } }; } 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 "update": // ButtonTool update(); 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 update() { RtdMeasurePosdataEntity entity = ugData.ActiveRow.ListObject as RtdMeasurePosdataEntity; if (entity == null) return; var ccp = new CoreClientParam(); ccp.ServerName = "com.steering.mes.zgmil.coup.FrmMeasureResultZG"; ccp.MethodName = "Doupdate"; ccp.ServerParams = new object[] { JSONFormat.Format(entity), _heatPlanId }; ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode != -1) { if (ccp.ReturnInfo.Equals("成功")) { Query(); } else { MessageUtil.ShowTips(ccp.ReturnInfo); } } } private void Query() { list = EntityHelper.GetData( "com.steering.mes.zgmil.coup.FrmMeasureResultZG.geRtdMeasurePosdataAll", new object[] { _judgeStove,_batchNo,_plineCode, "0" }, ob); rtdMeasurePosdataEntityBindingSource1.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; // double PerWt = // Math.Round( // (double.Parse(_jgxPlan.Outdiameter.ToString3()) - double.Parse(_jgxPlan.Wallthick.ToString3()))* // double.Parse(_jgxPlan.Wallthick.ToString3())*0.0246615d, 2)/1000d; // var ccp = new CoreClientParam(); // ccp.ServerName = "com.steering.mes.mcp.Mch.FrmMeasureResult"; // ccp.MethodName = "Turn"; // ccp.ServerParams = new object[] // { // PerWt, // _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 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) { rtdMeasurePosdataEntityBindingSource1.DataSource = chkFlag.Checked ?list: list.Where(p => p.Flag == "00").ToList() ; 按钮显示区域.Tools["Show"].SharedPropsInternal.Caption = chkFlag.Checked ? "隐藏已剔除" : "显示已剔除"; } private void ShowData() { chkFlag.Checked = !chkFlag.Checked; rtdMeasurePosdataEntityBindingSource1.DataSource = chkFlag.Checked ? list : list.Where(p => p.Flag == "00").ToList(); 按钮显示区域.Tools["Show"].SharedPropsInternal.Caption = chkFlag.Checked ? "隐藏已剔除" : "显示已剔除"; } private void ShowButton() { if (toolMenu.Toolbars[0].Tools.Exists("CancelFurnace")) { toolMenu.Toolbars[0].Tools["CancelFurnace"].InstanceProps.Visible = DefaultableBoolean.False; } } private void uteRemove_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.zgmil.coup.FrmMeasureResultZG"; 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.zgmil.coup.FrmMeasureResultZG"; 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, }; var ccp = new CoreClientParam(); ccp.ServerName = "com.steering.mes.zgmil.coup.FrmMeasureResultZG"; 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 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.zgmil.coup.FrmMeasureResultZG"; 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 ReadExcelToRtdMeasurePosdataEntity(string fileName) { //定义要返回的datatable对象 List RtdMeasurePosdataEntitys = new List(); 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 < 4) { throw new Exception("无足够列"); } RtdMeasurePosdataEntity entity = new RtdMeasurePosdataEntity() { MatNo = GetCellValue(row.Cells[0]), MatInfo = GetCellValue(row.Cells[3]), Flag = "00", JudgeStoveNo = _judgeStove, BatchNo = _batchNo, CreateUser = _userName, }; 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; } } }