using System; using System.Collections.Generic; using System.ComponentModel; using System.Collections; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Windows.Forms; using Core.Mes.Client.Comm.Control; using Core.Mes.Client.Comm.Format; using Core.Mes.Client.Comm.Tool; using CoreFS.CA06; using Infragistics.Win; using Infragistics.Win.UltraWinGrid; using NPOI.SS.UserModel; using Core.StlMes.Client.PnCost.Models; using Core.StlMes.Client.PnCost.NewCost.弹窗; using Core.Mes.Client.Comm.Server; namespace Core.StlMes.Client.PnCost { public partial class FrmTqnqD02 : FrmBase { #region 定义变量 public FrmTqnqD02() { InitializeComponent(); } private DataTable dtgang; #endregion private void doQueryBaseinfo() { DataTable dt = ClsBaseInfo.GetComBaseInfo("4049", ob); cfp.DataSource = dt; cfp.ValueMember = "BASECODE"; cfp.DisplayMember = "BASENAME"; ClsBaseInfo.SetComboItemHeight(cfp); List ls = new List(); ls.Add("不锈钢"); ls.Add("模具钢"); List ls2 = new List(); ls2.Add("高温回火"); ls2.Add("热轧"); hslb.DataSource = ls; jhzt.DataSource = ls2; //DataTable dt2 = ClsBaseInfo.GetComBaseInfo("4049", ob); //hslb.DataSource = dt; //hslb.ValueMember = "BASECODE"; //hslb.DisplayMember = "BASENAME"; //ClsBaseInfo.SetComboItemHeight(hslb); //DataTable dt3 = ClsBaseInfo.GetComBaseInfo("4049", ob); //jhzt.DataSource = dt; //jhzt.ValueMember = "BASECODE"; //jhzt.DisplayMember = "BASENAME"; //ClsBaseInfo.SetComboItemHeight(jhzt); } #region 方法 public override void ToolBar_Click(object sender, string ToolbarKey) { base.ToolBar_Click(sender, ToolbarKey); switch (ToolbarKey) { case "doQuery": Query(); break; case "doSave": doSave(); break; case "doAdd": doAdd(); break; case "doBbsc": doBbsc(); break; case "doSeeBb": doSeeBb(); break; //case "doDelete": // this.doDelete(); // break; case "Close": this.doDelete(); break; } } private void doSeeBb() { this.ultraGrid1.UpdateData(); IQueryable checkMagRows = this.ultraGrid1.Rows.AsQueryable().Where(" XUANZE = 'True'"); if (checkMagRows.Count() > 1) { MessageUtil.ShowTips("选择的条数有误!"); return; } string strurl = ""; foreach (UltraGridRow uRow in checkMagRows) { Tqnqd02Entity tqnqd02Entity = (Tqnqd02Entity)uRow.ListObject; strurl = "http://172.16.2.137:8081/webroot/decision/view/report?viewlet=tqnqd06.cpt" + "&processCode="+tqnqd02Entity.ProcessCode; //+ "&BILL_NO=" + BillNo + "&NAME=" + this.UserInfo.GetUserName(); FrmRepExcel fBug = new FrmRepExcel(ob, strurl); fBug.AutoSize = true; fBug.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height); fBug.WindowState = FormWindowState.Maximized; fBug.Text = "成本测算"; fBug.Show(); } } private void doBbsc() { this.ultraGrid1.UpdateData(); IQueryable checkMagRows = this.ultraGrid1.Rows.AsQueryable().Where(" XUANZE = 'True'"); if (checkMagRows.Count() == 0) { MessageUtil.ShowTips("请选择要生成的数据!"); return; } ArrayList parm = new ArrayList(); foreach (UltraGridRow uRow in checkMagRows) { Tqnqd02Entity tqnqd02Entity = (Tqnqd02Entity)uRow.ListObject; string tqnqd02EntityResult = JSONFormat.Format(tqnqd02Entity); parm.Add(tqnqd02EntityResult); } CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "com.steering.mes.cost.FrmTqnqd02"; ccp.MethodName = "doBbsc"; ccp.ServerParams = new object[] { parm }; ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode != -1) { if (ccp.ReturnInfo.Equals("操作成功")) { // DoQueryInList(); Query(); MessageUtil.ShowTips(ccp.ReturnInfo); } else { MessageUtil.ShowTips(ccp.ReturnInfo); } } } protected override void OnLoad(EventArgs e) { base.OnLoad(e); EntityHelper.ShowGridCaption(ultraGrid1.DisplayLayout.Bands[0]); ultraGrid1.ClickCellButton += new CellEventHandler(ugData_ClickCellButton); doQueryBaseinfo(); Query(); } protected virtual void ugData_ClickCellButton(object sender, CellEventArgs e) { UltraGridCell cell = ultraGrid1.ActiveCell; UltraGridRow row = e.Cell.Row; string strKey = this.ultraGrid1.ActiveCell.Column.ToString(); IQueryable checkMagRows = this.ultraGrid1.Rows.AsQueryable().Where(" XUANZE = 'True'"); if (checkMagRows.Count() == 0) { MessageUtil.ShowTips("请选择数据!"); return; } if(strKey.Equals("OutSgSign")) { FrmTqnqD01T frm = new FrmTqnqD01T(this.ob); frm.ShowDialog(); if (frm.DialogResult == System.Windows.Forms.DialogResult.OK) { row.Cells["OutSgSign"].Value = frm.steelname; row.Cells["OutSgStd"].Value = frm.stdname; row.Cells["OutSteelTypeCode"].Value = frm.steeltype; row.Cells["OutSmeltCode"].Value = frm.cx; } } if(strKey.Equals("SgSign")) { FrmProductManage frm = new FrmProductManage(this.ob); frm.ShowDialog(); if (frm.DialogResult == System.Windows.Forms.DialogResult.OK) { row.Cells["SgSign"].Value = frm.steelname_; row.Cells["SgStd"].Value = frm.stdname_; } } if (strKey.Equals("RpCode")) { FrmTqnqc13T frm = new FrmTqnqc13T(this.ob); frm.ShowDialog(); if (frm.DialogResult == System.Windows.Forms.DialogResult.OK) { row.Cells["RpCode"].Value = frm.rpcede_; row.Cells["WholeBacklogName"].Value = frm.cx_; } } } private void doDelete() { this.ultraGrid1.UpdateData(); IQueryable checkMagRows = this.ultraGrid1.Rows.AsQueryable().Where(" XUANZE = 'True'"); if (checkMagRows.Count() == 0) { MessageUtil.ShowTips("请选择需要删除的数据!"); return; } ArrayList parm = new ArrayList(); foreach (UltraGridRow uRow in checkMagRows) { SingnhjxhEntity SingnhjxhEntity = (SingnhjxhEntity)uRow.ListObject; string OfflineResultTity = JSONFormat.Format(SingnhjxhEntity); parm.Add(OfflineResultTity); } CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "com.steering.mes.cost.Frmsinghjxh"; ccp.MethodName = "doDelete"; ccp.ServerParams = new object[] { parm }; ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode != -1) { if (ccp.ReturnInfo.Equals("操作成功")) { // DoQueryInList(); Query(); MessageUtil.ShowTips(ccp.ReturnInfo); } else { MessageUtil.ShowTips(ccp.ReturnInfo); } } } /// private void doAdd() { this.ultraGrid1.UpdateData(); IQueryable checkMagRows = this.ultraGrid1.Rows.AsQueryable().Where(" XUANZE = 'True'"); if (checkMagRows.Count() == 0) { MessageUtil.ShowTips("请选择需要新增的数据"); return; } ArrayList parm = new ArrayList(); foreach (UltraGridRow uRow in checkMagRows) { Tqnqd02Entity entity = (Tqnqd02Entity)uRow.ListObject; entity.RecCreator = this.UserInfo.GetUserName(); string Tqnqd02Entity = JSONFormat.Format(entity); parm.Add(Tqnqd02Entity); } CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "com.steering.mes.cost.FrmTqnqd02"; ccp.MethodName = "doAdd"; ccp.ServerParams = new object[] { parm }; ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode != -1) { if (ccp.ReturnInfo.Equals("操作成功")) { // DoQueryInList(); Query(); MessageUtil.ShowTips(ccp.ReturnInfo); } else { MessageUtil.ShowTips(ccp.ReturnInfo); } } } public List ReadExcelToSingnhjxhEntity(string fileName) { //定义要返回的datatable对象 List SingnhjxhEntitys = 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) { SingnhjxhEntity entity = new SingnhjxhEntity(); NPOI.SS.UserModel.IRow row = sheet.GetRow(i); if (row == null) continue; //没有数据的行默认是null        if (row.Cells.Count < 4) { throw new Exception("无足够列"); } string SgSign = GetCellValue(row.Cells[0]); string cic = GetCellValue(row.Cells[1]); if (SgSign == "" || SgSign == null) { throw new Exception("牌号为空"); } if (cic == "" || cic == null) { throw new Exception("索引号为空"); } decimal outsife; decimal outhcmnfe; decimal outmcmnfe; decimal outlcmnfe; decimal outhccrfe; decimal outmccrfe; decimal outlccrfe; decimal outwccrfe; decimal outmofe; decimal outvfe; decimal outnbfe; decimal outenl; decimal outcathodecopper; decimal outwcu; decimal outlfrb; decimal outsicaba; decimal outal; decimal outalwire; decimal outtifecorewire; decimal outbfecorewire; decimal outswire; decimal outcawire; decimal outalpowder; decimal outnicalon; decimal outferrosiliconpowder; decimal outblowgraphitepowder; decimal outslagcarburizingball; decimal.TryParse(GetCellValue(row.Cells[2]), out outsife); decimal.TryParse(GetCellValue(row.Cells[3]), out outhcmnfe); decimal.TryParse(GetCellValue(row.Cells[4]), out outmcmnfe); decimal.TryParse(GetCellValue(row.Cells[5]), out outlcmnfe); decimal.TryParse(GetCellValue(row.Cells[6]), out outhccrfe); decimal.TryParse(GetCellValue(row.Cells[7]), out outmccrfe); decimal.TryParse(GetCellValue(row.Cells[8]), out outlccrfe); decimal.TryParse(GetCellValue(row.Cells[9]), out outwccrfe); decimal.TryParse(GetCellValue(row.Cells[10]), out outmofe); decimal.TryParse(GetCellValue(row.Cells[11]), out outvfe); decimal.TryParse(GetCellValue(row.Cells[12]), out outnbfe); decimal.TryParse(GetCellValue(row.Cells[13]), out outenl); decimal.TryParse(GetCellValue(row.Cells[14]), out outcathodecopper); decimal.TryParse(GetCellValue(row.Cells[15]), out outwcu); decimal.TryParse(GetCellValue(row.Cells[16]), out outlfrb); decimal.TryParse(GetCellValue(row.Cells[17]), out outsicaba); decimal.TryParse(GetCellValue(row.Cells[18]), out outal); decimal.TryParse(GetCellValue(row.Cells[19]), out outalwire); decimal.TryParse(GetCellValue(row.Cells[20]), out outtifecorewire); decimal.TryParse(GetCellValue(row.Cells[21]), out outbfecorewire); decimal.TryParse(GetCellValue(row.Cells[22]), out outswire); decimal.TryParse(GetCellValue(row.Cells[23]), out outcawire); decimal.TryParse(GetCellValue(row.Cells[24]), out outalpowder); decimal.TryParse(GetCellValue(row.Cells[25]), out outnicalon); decimal.TryParse(GetCellValue(row.Cells[26]), out outferrosiliconpowder); decimal.TryParse(GetCellValue(row.Cells[27]), out outblowgraphitepowder); decimal.TryParse(GetCellValue(row.Cells[28]), out outslagcarburizingball); entity.OutSife = outsife; entity.OutHcMnfe = outhcmnfe; entity.OutMcMnfe = outmcmnfe; entity.OutLcMnfe = outlcmnfe; entity.OutHcCrfe = outhccrfe; entity.OutMcCrfe = outmccrfe; entity.OutLcCrfe = outlccrfe; entity.OutWcCrfe = outwccrfe; entity.OutMofe = outmofe; entity.OutVfe = outvfe; entity.OutNbfe = outnbfe; entity.OutEni = outenl; entity.OutCathodeCopper = outcathodecopper; entity.OutWcu = outwcu; entity.OutLfrb = outlfrb; entity.OutSicaba = outsicaba; entity.OutAl = outal; entity.OutAlWire = outalwire; entity.OutTifeCoreWire = outtifecorewire; entity.OutBfeCoreWire = outbfecorewire; entity.OutSWire = outswire; entity.OutCaWire = outcawire; entity.OutAlPowder = outalpowder; entity.OutNicalon = outnicalon; entity.OutFerrosiliconPowder = outferrosiliconpowder; entity.OutBlowGraphitePowder = outblowgraphitepowder; entity.OutSlagCarburizingBall = outslagcarburizingball; entity.Cic = cic; entity.SgSign = SgSign; SingnhjxhEntitys.Add(entity); } } } } return SingnhjxhEntitys; } 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; } /// /// 保存 /// private void doSave() { try { this.ultraGrid1.UpdateData(); IQueryable checkMagRows = this.ultraGrid1.Rows.AsQueryable().Where(" XUANZE = 'True'"); if (checkMagRows.Count() == 0) { MessageUtil.ShowTips("请选择需要修改的数据!"); return; } ArrayList parm = new ArrayList(); foreach (UltraGridRow uRow in checkMagRows) { Tqnqd02Entity entity = (Tqnqd02Entity)uRow.ListObject; entity.DuMaker = UserInfo.GetUserName(); string SingnhjxhEntity = JSONFormat.Format(entity); parm.Add(SingnhjxhEntity); } CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "com.steering.mes.cost.FrmTqnqd02"; ccp.MethodName = "doSave"; ccp.ServerParams = new object[] { parm }; ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode != -1) { if (ccp.ReturnInfo.Equals("操作成功")) { // DoQueryInList(); Query(); MessageUtil.ShowTips(ccp.ReturnInfo); } else { MessageUtil.ShowTips(ccp.ReturnInfo); } } } catch { return; } } /// 查询方法 /// /// 查询方法 /// private void Query() { List listSource = EntityHelper.GetData( "com.steering.mes.cost.FrmTqnqd02.doQuery", new object[] { lgcxText.Text, bhcxText.Text, gzlbText.Text, gpphText.Text,gpbzText.Text }, this.ob); singnhjxhEntityBindingSource.DataSource = listSource; GridHelper.RefreshAndAutoSize(ultraGrid1); } /// 保存方法 /// /// 保存方法 /// private void Save() { } #endregion #region #endregion } }