| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337 |
- 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;
- namespace Core.StlMes.Client.PnCost
- {
- public partial class FrmBaseprocessbz : FrmBase
- {
- #region 定义变量
- public FrmBaseprocessbz()
- {
- InitializeComponent();
- EntityHelper.ShowGridCaption<BaseprocessbzcostEntity>(ultraGrid1.DisplayLayout.Bands[0]);
- }
- private DataTable dtgang;
- #endregion
- #region 方法
- public override void ToolBar_Click(object sender, string ToolbarKey)
- {
- base.ToolBar_Click(sender, ToolbarKey);
- switch (ToolbarKey)
- {
- case "Query":
- Query();
- break;
- case "doSave":
- doSave();
- break;
- case "Import":
- doAdd();
- break;
- case "doDelete":
- this.doDelete();
- break;
- }
- }
- private void doDelete()
- {
- this.ultraGrid1.UpdateData();
- IQueryable<UltraGridRow> checkMagRows = this.ultraGrid1.Rows.AsQueryable().Where(" XUANZE = 'True'");
- if (checkMagRows.Count() == 0)
- {
- MessageUtil.ShowTips("请选择需要删除的数据!");
- return;
- }
- ArrayList parm = new ArrayList();
- foreach (UltraGridRow uRow in checkMagRows)
- {
- BaseprocessbzcostEntity outproductsEntity = (BaseprocessbzcostEntity)uRow.ListObject;
- string OutproductsEntity = JSONFormat.Format(outproductsEntity);
- parm.Add(OutproductsEntity);
- }
- CoreClientParam ccp = new CoreClientParam();
- ccp.ServerName = "com.steering.mes.cost.FrmBaseprocessbzcost";
- 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);
- }
- }
- }
- ///
- public void doAdd()
- {
- List<BaseprocessbzcostEntity> list = null;
- var openFileDialog = new OpenFileDialog
- {
- Filter = "结算数据|*.xls;*.xlsx"
- };
- if (openFileDialog.ShowDialog() == DialogResult.OK)
- {
- list = ReadExcelToBaseprocessbzcostEntity(openFileDialog.FileName);
- }
- if (list == null) return;
- if (list.Count <= 0)
- {
- MessageBox.Show("Excel无数据");
- return;
- }
- string userName = UserInfo.GetUserName();
- var ccp = new CoreClientParam();
- ccp.ServerName = "com.steering.mes.cost.FrmBaseprocessbzcost";
- ccp.MethodName = "DoAddBaseprocessbzcosts";
- ccp.ServerParams = new object[]
- {
- list.Select(JSONFormat.Format).ToList()
- };
- ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- if (ccp.ReturnCode != -1)
- {
- MessageUtil.ShowTips(ccp.ReturnInfo);
- if (ccp.ReturnInfo.Equals("导入成功"))
- {
- Query();
- }
- }
- }
- public List<BaseprocessbzcostEntity> ReadExcelToBaseprocessbzcostEntity(string fileName)
- {
- //定义要返回的datatable对象
- List<BaseprocessbzcostEntity> OutproductsEntitys = new List<BaseprocessbzcostEntity>();
- 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)
- {
- BaseprocessbzcostEntity entity = new BaseprocessbzcostEntity();
- NPOI.SS.UserModel.IRow row = sheet.GetRow(i);
- if (row == null) continue; //没有数据的行默认是null
- if (row.Cells.Count < 14)
- {
- throw new Exception("无足够列");
- }
- //WHOLE_BACKLOG_NAME
- string askplanId = GetCellValue(row.Cells[0]);
- string ordNo = GetCellValue(row.Cells[1]);
- string ordSeq = GetCellValue(row.Cells[2]);
- string spetKey = GetCellValue(row.Cells[3]);
- string steelCodeKey = GetCellValue(row.Cells[4]);
- string steelName = GetCellValue(row.Cells[5]);
- string compantype = GetCellValue(row.Cells[6]);
- string articlename = GetCellValue(row.Cells[7]);
- string modelDesc = GetCellValue(row.Cells[8]);
- string stovNo = GetCellValue(row.Cells[11]);
- string jsDate = GetCellValue(row.Cells[14]);
- string wlName = GetCellValue(row.Cells[15]);
- string inceptcorpcode = GetCellValue(row.Cells[16]);
- decimal waijin;
- decimal bihou;
- decimal weight;
- decimal money;
- decimal.TryParse(GetCellValue(row.Cells[9]), out waijin);
- decimal.TryParse(GetCellValue(row.Cells[10]), out bihou);
- decimal.TryParse(GetCellValue(row.Cells[12]), out weight);
- decimal.TryParse(GetCellValue(row.Cells[13]), out money);
- if (askplanId == "" || askplanId == null)
- {
- throw new Exception("提单号为空");
- }
- if (ordNo == "" || ordNo == null)
- {
- throw new Exception("合同号为空");
- }
- if (ordSeq == "" || ordSeq == null)
- {
- throw new Exception("合同行号为空");
- }
- if (steelName == "" || steelName == null)
- {
- throw new Exception("钢种为空");
- }
- if (stovNo == "" || stovNo == null)
- {
- throw new Exception("炉号为空");
- }
- if (jsDate == "" || jsDate == null)
- {
- throw new Exception("结算日期为空");
- }
- entity.AskplanId = askplanId;
- entity.OrdNo = ordNo;
- entity.OrdSeq = ordSeq;
- entity.Spetkey = spetKey;
- entity.Steelcodekey = steelCodeKey;
- entity.Steelname = steelName;
- entity.Companytype = compantype;
- entity.Articlename = articlename;
- entity.ModelDesc = modelDesc;
- entity.StoveNo = stovNo;
- entity.JsDate = jsDate;
- entity.Waijin = waijin;
- entity.Bihou = bihou;
- entity.Weight = weight;
- entity.Money = money;
- entity.Wlname = wlName;
- entity.Inceptcorpcode = inceptcorpcode;
- OutproductsEntitys.Add(entity);
- }
- }
- }
- }
- return OutproductsEntitys;
- }
- 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;
- }
- /// <summary>
- /// 保存
- /// </summary>
- private void doSave()
- {
- try
- {
- this.ultraGrid1.UpdateData();
- IQueryable<UltraGridRow> checkMagRows = this.ultraGrid1.Rows.AsQueryable().Where(" XUANZE = 'True'");
- if (checkMagRows.Count() == 0)
- {
- MessageUtil.ShowTips("请选择需要修改的数据!");
- return;
- }
- ArrayList parm = new ArrayList();
- foreach (UltraGridRow uRow in checkMagRows)
- {
- BaseprocessbzcostEntity entity = (BaseprocessbzcostEntity)uRow.ListObject;
- string OutproductsEntity = JSONFormat.Format(entity);
- parm.Add(OutproductsEntity);
- }
- CoreClientParam ccp = new CoreClientParam();
- ccp.ServerName = "com.steering.mes.cost.FrmBaseprocessbzcost";
- 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;
- }
-
- }
- /// 查询方法
- /// <summary>
- /// 查询方法
- /// </summary>
- private void Query()
- {
- List<BaseprocessbzcostEntity> listSource = EntityHelper.GetData<BaseprocessbzcostEntity>(
- "com.steering.mes.cost.FrmBaseprocessbzcost.Query", new object[] { textTd.Text, textHt.Text }, this.ob);
- baseprocessbzcostEntityBindingSource.DataSource = listSource;
- GridHelper.RefreshAndAutoSize(ultraGrid1);
- }
- /// 保存方法
- /// <summary>
- /// 保存方法
- /// </summary>
- private void Save()
- {
-
- }
- #endregion
- #region
- #endregion
- }
- }
|