| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315 |
- using Core.Mes.Client.Comm.Control;
- using Core.Mes.Client.Comm.Format;
- using Core.Mes.Client.Comm.Tool;
- using Core.StlMes.Client.PlnSaleOrd.管坯优化.model;
- using CoreFS.CA06;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using NPOI.SS.UserModel;
- using Core.Mes.Client.Comm.Server;
- namespace Core.StlMes.Client.PlnSaleOrd
- {
- public partial class FrmWalktHrough : FrmBase
- {
- private OpeBase ob;
- private string gradeCode = "";
- private string outs_billet_fl="";
- private string custom = "";
- public FrmWalktHrough(OpeBase _ob, string _outs_billet_fl,string _custom)
- {
- ob = _ob;
- outs_billet_fl = _outs_billet_fl;
- custom = _custom;
- InitializeComponent();
- EntityHelper.ShowGridCaption<PlnReqinfGpExcel>(ultraGrid1.DisplayLayout.Bands[0]);
- plnReqinfGpExcelBindingSource.DataSource = new List<PlnReqinfGpExcel>()
- {
- new PlnReqinfGpExcel()
- {
- GpreqId = "1"
- }
- };
- }
- /// <summary>
- /// 保存
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ultraButton1_Click(object sender, EventArgs e)
- {
- if (comGptype.Text.Equals(""))
- {
- MessageUtil.ShowTips("坯分类不能为空,请选择!");
- return;
- }
- if (txtGrad.Text.Equals(""))
- {
- MessageUtil.ShowTips("钢种不能为空,请选择!");
- return;
- }
- if (txtCic.Text.Equals(""))
- {
- MessageUtil.ShowTips("钢种索引码不能为空,请选择!");
- return;
- }
- if (txtDiarm.Text.Equals(""))
- {
- MessageUtil.ShowTips("断面不能为空,请输入!");
- return;
- }
- if (txtLenGp.Text.Equals(""))
- {
- MessageUtil.ShowTips("单倍坯长不能为空,请输入!");
- return;
- }
- if (txtGpWt.Text.Equals(""))
- {
- MessageUtil.ShowTips("需求量不能为空,请输入!");
- return;
- }
- if(txtIsDear.Value.ToString2().Equals(""))
- {
- MessageUtil.ShowTips("坯料用途不能为空!");
- return;
- }
- int lenGpSingle = Convert.ToInt32(txtLenGp.Value.ToString());
- if (lenGpSingle % 10 != 0)
- {
- MessageUtil.ShowWarning("单倍坯长个位数不是0,请重新输入!");
- return;
- }
- if (txtLengthGp.Text.Equals(""))
- {
- MessageUtil.ShowTips("管坯长度不能为空,请输入!");
- return;
- }
- if (txtCutNumGp.Text.Equals(""))
- {
- MessageUtil.ShowTips("倍尺数不能为空,请输入!");
- return;
- }
- ArrayList list = new ArrayList();
- list.Add(comGptype.Value.ToString());
- list.Add(gradeCode);
- list.Add(txtGrad.Text.ToString());
- list.Add(txtCic.Text.ToString());
- list.Add(txtDiarm.Value.ToString());
- list.Add(txtLenGp.Value.ToString());
- list.Add(txtGpWt.Value.ToString());
- list.Add(this.UserInfo.GetUserName());
- list.Add(DateTime.Now.ToString());
- list.Add(txtIsDear.Value.ToString2());
- list.Add(txtLengthGp.Value.ToString());
- list.Add(txtCutNumGp.Value.ToString());
- CoreClientParam ccp = new CoreClientParam();
- ccp.ServerName = "com.steering.pss.plnsaleord.GpOptimize.CorePlnZgMStoGp";
- ccp.MethodName = "addWalktHrough";
- ccp.ServerParams = new object[] { list, outs_billet_fl,custom };
- ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- if (ccp.ReturnCode == -1) return;
- MessageUtil.ShowTips(ccp.ReturnInfo);
- if (ccp.ReturnInfo.Equals("保存成功!")) { this.Close(); return; }
-
- }
- /// <summary>
- /// 关闭
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ultraButton2_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- /// <summary>
- /// 选择钢种,钢种索引码
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void txtGrad_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
- {
- FrmSteelGrade steel = new FrmSteelGrade(ob, outs_billet_fl);
- if (outs_billet_fl.Equals("0"))
- {
- steel.Text = "自炼钢种及钢种索引码";
- }
- else
- {
- steel.Text = "外购钢种及钢种索引码";
- }
- steel.AutoSize = true;
- steel.ShowDialog();
- if (steel.DialogResult == System.Windows.Forms.DialogResult.OK)
- {
- //获取弹出窗体的属性值
- txtGrad.Text = steel.Gradename;
- txtCic.Text = steel.Cic;
- gradeCode = steel.Gradecode;
- }
- }
- private void ultraButton3_Click(object sender, EventArgs e)
- {
- GridHelper.ulGridToExcel(ultraGrid1, "导入模板");
- }
- private void ultraButton4_Click(object sender, EventArgs e)
- {
- List<PlnReqinfGpExcel> lists = null;
- var openFileDialog = new OpenFileDialog
- {
- Filter = "测量点数据|*.xls;*.xlsx"
- };
- if (openFileDialog.ShowDialog() == DialogResult.OK)
- {
- lists = ReadExcelToPlnReqinfGpExcel(openFileDialog.FileName);
- }
- if (lists == null) return;
- if (lists.Count <= 0)
- {
- MessageBox.Show("Excel无数据");
- return;
- }
- DataTable dt = ServerHelper.GetData("com.steering.pss.plnsaleord.GpOptimize.CorePlnZgMStoGp.getQueryGrade1", new object[] { outs_billet_fl }, ob);
-
- ArrayList list1 = new ArrayList();
- foreach (var plnReqinfGpExcel in lists)
- {
- ArrayList list = new ArrayList();
- DataRow[] drs = dt.Select("GRADENAME ='" + plnReqinfGpExcel.Gradename + "' and STD_IDX = '" + plnReqinfGpExcel.Cic + "'");
- plnReqinfGpExcel.Gradecode = drs[0]["GRADECODE"].ToString2();
- if (String.IsNullOrEmpty(plnReqinfGpExcel.Gradecode))
- {
- MessageBox.Show("没有查询到改"+plnReqinfGpExcel.Gradename+"钢种!");
- return;
- }
- list.Add(plnReqinfGpExcel.Gptype);
- list.Add(plnReqinfGpExcel.Gradecode);
- list.Add(plnReqinfGpExcel.Gradename);
- list.Add(plnReqinfGpExcel.Cic);
- list.Add(plnReqinfGpExcel.DiameterGp.ToString2());
- list.Add(plnReqinfGpExcel.LenGpSingle.ToString2());
- list.Add(plnReqinfGpExcel.GpWtLong);
- list.Add(this.UserInfo.GetUserName());
- list.Add(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
- list.Add(plnReqinfGpExcel.TypeFlag);
- list.Add(plnReqinfGpExcel.LengthGp.ToString2());
- list.Add(plnReqinfGpExcel.CutNumGp.ToString2());
- list1.Add(list);
- }
- CoreClientParam ccp = new CoreClientParam();
- ccp.ServerName = "com.steering.pss.plnsaleord.GpOptimize.CorePlnZgMStoGp";
- ccp.MethodName = "addWalktHroughExcel";
- ccp.ServerParams = new object[] { list1, outs_billet_fl, custom };
- ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- if (ccp.ReturnCode == -1) {
- MessageUtil.ShowWarning(ccp.ReturnInfo);
- return;
- }
- if (ccp.ReturnCode == 0) {
- MessageUtil.ShowTips(ccp.ReturnInfo);
- this.Close(); return;
- }
- }
- public List<PlnReqinfGpExcel> ReadExcelToPlnReqinfGpExcel(string fileName)
- {
- //定义要返回的datatable对象
- List<PlnReqinfGpExcel> plnReqinfGpExcels = new List<PlnReqinfGpExcel>();
- 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
- PlnReqinfGpExcel plnReqinfGpExcel = new PlnReqinfGpExcel();
- plnReqinfGpExcel.TypeFlag = GetCellValue(row.Cells[0]);
- plnReqinfGpExcel.Gptype = GetCellValue(row.Cells[1]);
- plnReqinfGpExcel.Gradecode = GetCellValue(row.Cells[2]);
- plnReqinfGpExcel.Gradename = GetCellValue(row.Cells[3]);
- plnReqinfGpExcel.Cic = GetCellValue(row.Cells[4]);
- decimal lenGpSingle, cutNumGp, lengthGp, diameterGp;
- decimal.TryParse(GetCellValue(row.Cells[5]), out lenGpSingle);
- decimal.TryParse(GetCellValue(row.Cells[6]), out cutNumGp);
- decimal.TryParse(GetCellValue(row.Cells[7]), out lengthGp);
- plnReqinfGpExcel.LenGpSingle = lenGpSingle;
- plnReqinfGpExcel.CutNumGp = cutNumGp;
- plnReqinfGpExcel.LengthGp = lengthGp;
- plnReqinfGpExcel.GpWtLong = GetCellValue(row.Cells[8]);
- decimal.TryParse(GetCellValue(row.Cells[9]), out diameterGp);
- plnReqinfGpExcel.DiameterGp = diameterGp;
- plnReqinfGpExcels.Add(plnReqinfGpExcel);
- }
- }
- }
- }
- return plnReqinfGpExcels;
- }
- 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;
- }
- }
- }
|