| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426 |
- 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 com.steering.mes.mcp.entity;
- 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.ZGMil.Entity;
- using Core.Mes.Client.Comm.Server;
- using Infragistics.Win.UltraWinEditors;
- namespace Core.StlMes.Client.ZGMil.Cost
- {
- public partial class FrmTqnqc17 : FrmBase
- {
- public FrmTqnqc17()
- {
- InitializeComponent();
- }
- private void FrmTqnqc14_Load(object sender, EventArgs e)
- {
-
- EntityHelper.ShowGridCaption<Tqnqc17Entity>(ultraGrid1.DisplayLayout.Bands[0]);
- Query();
- doQueryjz();
- doQueryBaseInfo();
- }
- public override void ToolBar_Click(object sender, string ToolbarKey)
- {
- switch (ToolbarKey)
- {
- case "DoQuery":
- Query();
- break;
- case "doImport":
- Import();
- break;
- case "doSave":
- break;
- case "doUpdate":
- Update();
- break;
- case "doDelete":
- delete();
- break;
- case "Close":
- Close();
- break;
- }
- }
- //导入
- private void Import()
- {
- List<Tqnqc17Entity> list = null;
- var openFileDialog = new OpenFileDialog
- {
- Filter = "定额成才率基础信息|*.xls;*.xlsx"
- };
- if (openFileDialog.ShowDialog() == DialogResult.OK)
- {
- list = ReadExcelToRtdTqnqc17Entity(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.FrmTqnqc17";
- ccp.MethodName = "DoAddTqnqc17";
- ccp.ServerParams = new object[]
- {
- list.Select(JSONFormat.Format).ToList(),
- userName
- };
- ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- if (ccp.ReturnCode != -1)
- {
- MessageUtil.ShowTips(ccp.ReturnInfo);
- if (ccp.ReturnInfo.Equals("新增成功"))
- {
- Query();
- }
- }
- }
- private void delete()
- {
- this.ultraGrid1.UpdateData();
- IQueryable<UltraGridRow> checkMagRows = this.ultraGrid1.Rows.AsQueryable().Where(" CHK = 'True'");
- if (checkMagRows.Count() == 0)
- {
- MessageUtil.ShowTips("请选择需要删除的数据!");
- return;
- }
- ArrayList parm = new ArrayList();
- foreach (UltraGridRow uRow in checkMagRows)
- {
- Tqnqc17Entity Tqnqc17Result = (Tqnqc17Entity)uRow.ListObject;
- if (Tqnqc17Result.RpNum.Equals("") || Tqnqc17Result.RpNum == null)
- {
- MessageUtil.ShowTips("编号为空!");
- }
- string Tqnqc17Results = JSONFormat.Format(Tqnqc17Result);
- parm.Add(Tqnqc17Results);
- }
- CoreClientParam ccp = new CoreClientParam();
- ccp.ServerName = "com.steering.mes.cost.FrmTqnqc17";
- 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 Update()
- {
- this.ultraGrid1.UpdateData();
- IQueryable<UltraGridRow> checkMagRows = this.ultraGrid1.Rows.AsQueryable().Where(" CHK = 'True'");
- if (checkMagRows.Count() == 0)
- {
- MessageUtil.ShowTips("请选择需要修改的数据!");
- return;
- }
- ArrayList parm = new ArrayList();
- foreach (UltraGridRow uRow in checkMagRows)
- {
- Tqnqc17Entity entity = (Tqnqc17Entity)uRow.ListObject;
- entity.Zsunshi = entity.Jiarelu+entity.Rechuli+entity.Rezha+entity.Dinchi
- + entity.Bapi + entity.Quliao + entity.Tksunshi + entity.Lzsunshi + entity.Fp;//jru + rcl + rzqt + dcqt + bp + ql + tkss + lzss + fp;
- entity.Chencailv = 100 - (entity.Jiarelu + entity.Rechuli + entity.Rezha + entity.Dinchi + entity.Bapi + entity.Quliao + entity.Tksunshi + entity.Lzsunshi + entity.Fp);
- entity.RecRevisor = UserInfo.GetUserName();
- string Tqnqc17ResultTity = JSONFormat.Format(entity);
- parm.Add(Tqnqc17ResultTity);
- }
- CoreClientParam ccp = new CoreClientParam();
- ccp.ServerName = "com.steering.mes.cost.FrmTqnqc17";
- 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);
- }
- }
- }
- private void Query()
- {
- string cb = "";
- string jz = "";
- if (chk_cb.Checked == true)
- {
- cb = text_name.Text;
- }
- if (chk_jz.Checked == true)
- {
- jz = text_jz.Text;
- }
- List<Tqnqc17Entity> listSource = EntityHelper.GetData<Tqnqc17Entity>(
- "com.steering.mes.cost.FrmTqnqc17.doQuery", new object[] { cb, jz }, this.ob);
- tqnqc17EntityBindingSource.DataSource = listSource;
- // GridHelper.RefreshAndAutoSize(ultraGrid1);
- }
- public List<Tqnqc17Entity> ReadExcelToRtdTqnqc17Entity(string fileName)
- {
- //定义要返回的datatable对象
- List<Tqnqc17Entity> Tqnqc17Entitys = new List<Tqnqc17Entity>();
- 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)
- {
- Tqnqc17Entity entity = new Tqnqc17Entity();
- NPOI.SS.UserModel.IRow row = sheet.GetRow(i);
- if (row == null) continue; //没有数据的行默认是null
- if (row.Cells.Count < 21)
- {
- throw new Exception("无足够列");
- }
- string factorydiv = GetCellValue(row.Cells[0]);
- string cggz = GetCellValue(row.Cells[1]);
- string jz = GetCellValue(row.Cells[2]);
- string plly = GetCellValue(row.Cells[3]);
- string pdx = GetCellValue(row.Cells[4]);
- string bz = GetCellValue(row.Cells[5]);
- string pzlb = GetCellValue(row.Cells[6]);
- string jhzt = GetCellValue(row.Cells[7]);
- string bmzt = GetCellValue(row.Cells[8]);
- string sfdc = GetCellValue(row.Cells[9]);
- string id = GetCellValue(row.Cells[21]);
- if (factorydiv == "" || factorydiv == null)
- {
- throw new Exception("厂别不能为空");
- }
- if (cggz == "" || cggz == null)
- {
- throw new Exception("常规/特殊钢种不能为空");
- }
- if (jz == "" || jz == null)
- {
- throw new Exception("机组不能为空");
- }
- if (plly == "" || plly == null)
- {
- throw new Exception("坯料来源不能为空");
- }
- if (id == "" || id == null)
- {
- throw new Exception("编号不能为空");
- }
- decimal wcde;
- decimal jru;
- decimal rcl ;
- decimal rzqt;
- decimal dcqt;
- decimal bp;
- decimal ql;
- decimal tkss;
- decimal lzss;
- decimal fp;
- decimal.TryParse(GetCellValue(row.Cells[10]), out wcde);
- decimal.TryParse(GetCellValue(row.Cells[11]), out jru);
- decimal.TryParse(GetCellValue(row.Cells[12]), out rcl);
- decimal.TryParse(GetCellValue(row.Cells[13]), out rzqt);
- decimal.TryParse(GetCellValue(row.Cells[14]), out dcqt);
- decimal.TryParse(GetCellValue(row.Cells[15]), out bp);
- decimal.TryParse(GetCellValue(row.Cells[16]), out ql);
- decimal.TryParse(GetCellValue(row.Cells[17]), out tkss);
- decimal.TryParse(GetCellValue(row.Cells[18]), out lzss);
- decimal.TryParse(GetCellValue(row.Cells[19]), out fp);
- entity.FactoryDiv = factorydiv;
- entity.BilletOrigin = plly;
- entity.IngotName = pdx;
- entity.UnitCode = jz;
- entity.AlloyBak1 = cggz; //常规钢种
- entity.AlloyBak2 = bz; // 标准
- entity.SteelTypeCode = pzlb;
- entity.HotTreatMethod = jhzt;
- entity.SufaceState = bmzt;
- entity.NonLength = sfdc;
- entity.Jiarelu = jru;
- entity.Rechuli = rcl;
- entity.Rezha = rzqt;
- entity.Dinchi = dcqt;
- entity.Bapi = bp;
- entity.Quliao = ql;
- entity.Tksunshi = tkss;//通孔损失
- entity.Lzsunshi = lzss; //理重损失
- entity.Fp = fp;//废品
- entity.RecCreator = UserInfo.GetUserName();
- entity.Zsunshi = jru + rcl + rzqt + dcqt + bp + ql + tkss+lzss+fp;
- entity.Chencailv = 100 - (jru + rcl + rzqt + dcqt + bp + ql + tkss + lzss + fp);
- entity.RpNum = id;
- Tqnqc17Entitys.Add(entity);
- }
- }
- }
- }
- return Tqnqc17Entitys;
- }
- 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 doQueryjz()
- {
- DataTable dt = ServerHelper.GetData("com.steering.mes.cost.FrmTqnqc17.doQueryjz", null, ob);
- text_jz.DataSource = dt;
- text_jz.ValueMember = "BASECODE";
- text_jz.DisplayMember = "BASENAME";
- SetComboItemHeight(text_jz);
- }
- //获取其它数据
- private void doQueryBaseInfo() {
- //工序
- DataTable dt1 = GetComBaseInfo("4105", ob);
- text_name.DataSource = dt1;
- text_name.ValueMember = "BASECODE";
- text_name.DisplayMember = "BASENAME";
- SetComboItemHeight(text_jz);
- //坯料来源
- DataTable dt2 = GetComBaseInfo("20110101", ob);
- plyl.DataSource = dt2;
- plyl.ValueMember = "BASECODE";
- plyl.DisplayMember = "BASENAME";
- SetComboItemHeight(plyl);
- //锭坯型
- DataTable dt3 = GetComBaseInfo("20110102", ob);
- dx.DataSource = dt3;
- dx.ValueMember = "BASECODE";
- dx.DisplayMember = "BASENAME";
- SetComboItemHeight(dx);
- //锭坯型
- DataTable dt4 = GetComBaseInfo("20110103", ob);
- jhstate.DataSource = dt4;
- jhstate.ValueMember = "BASECODE";
- jhstate.DisplayMember = "BASENAME";
- SetComboItemHeight(jhstate);
- DataTable dt5 = GetComBaseInfo("20110104", ob);
- bmstate.DataSource = dt5;
- bmstate.ValueMember = "BASECODE";
- bmstate.DisplayMember = "BASENAME";
- SetComboItemHeight(bmstate);
- List<String> ls = new List<String>();
- ls.Add("常规品种");
- ls.Add("特殊品种");
- List<String> ls2 = new List<String>();
- ls2.Add("是");
- ls2.Add("否");
- ls2.Add("不分");
- cgpz.DataSource = ls;
- sfdc.DataSource = ls2;
-
- }
- public static DataTable GetComBaseInfo(string sortCode, OpeBase ob)
- {
- return ServerHelper.GetData("com.steering.mes.signature.FrmMilControlLog.getComBaseInfo", new object[] { sortCode }, ob);
- }
- public static void SetComboItemHeight(UltraComboEditor cmb)
- {
- foreach (ValueListItem item in cmb.Items)
- {
- if (System.Text.RegularExpressions.Regex.IsMatch(item.DisplayText, @"[\u4e00-\u9fa5]+"))
- {
- item.Appearance.FontData.SizeInPoints = 9.0F;
- }
- else
- {
- item.Appearance.FontData.SizeInPoints = 10.5F;
- }
- }
- }
- }
- }
|