FrmTqnqc17.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Collections;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Reflection;
  10. using System.Text;
  11. using System.Windows.Forms;
  12. using com.steering.mes.mcp.entity;
  13. using Core.Mes.Client.Comm.Control;
  14. using Core.Mes.Client.Comm.Format;
  15. using Core.Mes.Client.Comm.Tool;
  16. using CoreFS.CA06;
  17. using Infragistics.Win;
  18. using Infragistics.Win.UltraWinGrid;
  19. using NPOI.SS.UserModel;
  20. using Core.StlMes.Client.ZGMil.Entity;
  21. using Core.Mes.Client.Comm.Server;
  22. using Infragistics.Win.UltraWinEditors;
  23. namespace Core.StlMes.Client.ZGMil.Cost
  24. {
  25. public partial class FrmTqnqc17 : FrmBase
  26. {
  27. public FrmTqnqc17()
  28. {
  29. InitializeComponent();
  30. }
  31. private void FrmTqnqc14_Load(object sender, EventArgs e)
  32. {
  33. EntityHelper.ShowGridCaption<Tqnqc17Entity>(ultraGrid1.DisplayLayout.Bands[0]);
  34. Query();
  35. doQueryjz();
  36. doQueryBaseInfo();
  37. }
  38. public override void ToolBar_Click(object sender, string ToolbarKey)
  39. {
  40. switch (ToolbarKey)
  41. {
  42. case "DoQuery":
  43. Query();
  44. break;
  45. case "doImport":
  46. Import();
  47. break;
  48. case "doSave":
  49. break;
  50. case "doUpdate":
  51. Update();
  52. break;
  53. case "doDelete":
  54. delete();
  55. break;
  56. case "Close":
  57. Close();
  58. break;
  59. }
  60. }
  61. //导入
  62. private void Import()
  63. {
  64. List<Tqnqc17Entity> list = null;
  65. var openFileDialog = new OpenFileDialog
  66. {
  67. Filter = "定额成才率基础信息|*.xls;*.xlsx"
  68. };
  69. if (openFileDialog.ShowDialog() == DialogResult.OK)
  70. {
  71. list = ReadExcelToRtdTqnqc17Entity(openFileDialog.FileName);
  72. }
  73. if (list == null) return;
  74. if (list.Count <= 0)
  75. {
  76. MessageBox.Show("Excel无数据");
  77. return;
  78. }
  79. string userName = UserInfo.GetUserName();
  80. var ccp = new CoreClientParam();
  81. ccp.ServerName = "com.steering.mes.cost.FrmTqnqc17";
  82. ccp.MethodName = "DoAddTqnqc17";
  83. ccp.ServerParams = new object[]
  84. {
  85. list.Select(JSONFormat.Format).ToList(),
  86. userName
  87. };
  88. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  89. if (ccp.ReturnCode != -1)
  90. {
  91. MessageUtil.ShowTips(ccp.ReturnInfo);
  92. if (ccp.ReturnInfo.Equals("新增成功"))
  93. {
  94. Query();
  95. }
  96. }
  97. }
  98. private void delete()
  99. {
  100. this.ultraGrid1.UpdateData();
  101. IQueryable<UltraGridRow> checkMagRows = this.ultraGrid1.Rows.AsQueryable().Where(" CHK = 'True'");
  102. if (checkMagRows.Count() == 0)
  103. {
  104. MessageUtil.ShowTips("请选择需要删除的数据!");
  105. return;
  106. }
  107. ArrayList parm = new ArrayList();
  108. foreach (UltraGridRow uRow in checkMagRows)
  109. {
  110. Tqnqc17Entity Tqnqc17Result = (Tqnqc17Entity)uRow.ListObject;
  111. if (Tqnqc17Result.RpNum.Equals("") || Tqnqc17Result.RpNum == null)
  112. {
  113. MessageUtil.ShowTips("编号为空!");
  114. }
  115. string Tqnqc17Results = JSONFormat.Format(Tqnqc17Result);
  116. parm.Add(Tqnqc17Results);
  117. }
  118. CoreClientParam ccp = new CoreClientParam();
  119. ccp.ServerName = "com.steering.mes.cost.FrmTqnqc17";
  120. ccp.MethodName = "doDelete";
  121. ccp.ServerParams = new object[] { parm };
  122. ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  123. if (ccp.ReturnCode != -1)
  124. {
  125. if (ccp.ReturnInfo.Equals("操作成功"))
  126. {
  127. // DoQueryInList();
  128. Query();
  129. MessageUtil.ShowTips(ccp.ReturnInfo);
  130. }
  131. else
  132. {
  133. MessageUtil.ShowTips(ccp.ReturnInfo);
  134. }
  135. }
  136. }
  137. private void Update()
  138. {
  139. this.ultraGrid1.UpdateData();
  140. IQueryable<UltraGridRow> checkMagRows = this.ultraGrid1.Rows.AsQueryable().Where(" CHK = 'True'");
  141. if (checkMagRows.Count() == 0)
  142. {
  143. MessageUtil.ShowTips("请选择需要修改的数据!");
  144. return;
  145. }
  146. ArrayList parm = new ArrayList();
  147. foreach (UltraGridRow uRow in checkMagRows)
  148. {
  149. Tqnqc17Entity entity = (Tqnqc17Entity)uRow.ListObject;
  150. entity.Zsunshi = entity.Jiarelu+entity.Rechuli+entity.Rezha+entity.Dinchi
  151. + entity.Bapi + entity.Quliao + entity.Tksunshi + entity.Lzsunshi + entity.Fp;//jru + rcl + rzqt + dcqt + bp + ql + tkss + lzss + fp;
  152. entity.Chencailv = 100 - (entity.Jiarelu + entity.Rechuli + entity.Rezha + entity.Dinchi + entity.Bapi + entity.Quliao + entity.Tksunshi + entity.Lzsunshi + entity.Fp);
  153. entity.RecRevisor = UserInfo.GetUserName();
  154. string Tqnqc17ResultTity = JSONFormat.Format(entity);
  155. parm.Add(Tqnqc17ResultTity);
  156. }
  157. CoreClientParam ccp = new CoreClientParam();
  158. ccp.ServerName = "com.steering.mes.cost.FrmTqnqc17";
  159. ccp.MethodName = "doSave";
  160. ccp.ServerParams = new object[] { parm };
  161. ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  162. if (ccp.ReturnCode != -1)
  163. {
  164. if (ccp.ReturnInfo.Equals("操作成功"))
  165. {
  166. // DoQueryInList();
  167. Query();
  168. MessageUtil.ShowTips(ccp.ReturnInfo);
  169. }
  170. else
  171. {
  172. MessageUtil.ShowTips(ccp.ReturnInfo);
  173. }
  174. }
  175. }
  176. private void Query()
  177. {
  178. string cb = "";
  179. string jz = "";
  180. if (chk_cb.Checked == true)
  181. {
  182. cb = text_name.Text;
  183. }
  184. if (chk_jz.Checked == true)
  185. {
  186. jz = text_jz.Text;
  187. }
  188. List<Tqnqc17Entity> listSource = EntityHelper.GetData<Tqnqc17Entity>(
  189. "com.steering.mes.cost.FrmTqnqc17.doQuery", new object[] { cb, jz }, this.ob);
  190. tqnqc17EntityBindingSource.DataSource = listSource;
  191. // GridHelper.RefreshAndAutoSize(ultraGrid1);
  192. }
  193. public List<Tqnqc17Entity> ReadExcelToRtdTqnqc17Entity(string fileName)
  194. {
  195. //定义要返回的datatable对象
  196. List<Tqnqc17Entity> Tqnqc17Entitys = new List<Tqnqc17Entity>();
  197. try
  198. {
  199. if (!File.Exists(fileName))
  200. {
  201. return null;
  202. }
  203. //根据指定路径读取文件
  204. using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
  205. {
  206. //根据文件流创建excel数据结构
  207. NPOI.SS.UserModel.IWorkbook workbook = NPOI.SS.UserModel.WorkbookFactory.Create(fs);
  208. //IWorkbook workbook = new HSSFWorkbook(fs);
  209. for (int k = 0; k < workbook.NumberOfSheets; k++)
  210. {
  211. NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(k);
  212. if (sheet != null)
  213. {
  214. //最后一列的标号
  215. int rowCount = sheet.LastRowNum;
  216. for (int i = 1; i <= rowCount; ++i)
  217. {
  218. Tqnqc17Entity entity = new Tqnqc17Entity();
  219. NPOI.SS.UserModel.IRow row = sheet.GetRow(i);
  220. if (row == null) continue; //没有数据的行默认是null       
  221. if (row.Cells.Count < 21)
  222. {
  223. throw new Exception("无足够列");
  224. }
  225. string factorydiv = GetCellValue(row.Cells[0]);
  226. string cggz = GetCellValue(row.Cells[1]);
  227. string jz = GetCellValue(row.Cells[2]);
  228. string plly = GetCellValue(row.Cells[3]);
  229. string pdx = GetCellValue(row.Cells[4]);
  230. string bz = GetCellValue(row.Cells[5]);
  231. string pzlb = GetCellValue(row.Cells[6]);
  232. string jhzt = GetCellValue(row.Cells[7]);
  233. string bmzt = GetCellValue(row.Cells[8]);
  234. string sfdc = GetCellValue(row.Cells[9]);
  235. string id = GetCellValue(row.Cells[21]);
  236. if (factorydiv == "" || factorydiv == null)
  237. {
  238. throw new Exception("厂别不能为空");
  239. }
  240. if (cggz == "" || cggz == null)
  241. {
  242. throw new Exception("常规/特殊钢种不能为空");
  243. }
  244. if (jz == "" || jz == null)
  245. {
  246. throw new Exception("机组不能为空");
  247. }
  248. if (plly == "" || plly == null)
  249. {
  250. throw new Exception("坯料来源不能为空");
  251. }
  252. if (id == "" || id == null)
  253. {
  254. throw new Exception("编号不能为空");
  255. }
  256. decimal wcde;
  257. decimal jru;
  258. decimal rcl ;
  259. decimal rzqt;
  260. decimal dcqt;
  261. decimal bp;
  262. decimal ql;
  263. decimal tkss;
  264. decimal lzss;
  265. decimal fp;
  266. decimal.TryParse(GetCellValue(row.Cells[10]), out wcde);
  267. decimal.TryParse(GetCellValue(row.Cells[11]), out jru);
  268. decimal.TryParse(GetCellValue(row.Cells[12]), out rcl);
  269. decimal.TryParse(GetCellValue(row.Cells[13]), out rzqt);
  270. decimal.TryParse(GetCellValue(row.Cells[14]), out dcqt);
  271. decimal.TryParse(GetCellValue(row.Cells[15]), out bp);
  272. decimal.TryParse(GetCellValue(row.Cells[16]), out ql);
  273. decimal.TryParse(GetCellValue(row.Cells[17]), out tkss);
  274. decimal.TryParse(GetCellValue(row.Cells[18]), out lzss);
  275. decimal.TryParse(GetCellValue(row.Cells[19]), out fp);
  276. entity.FactoryDiv = factorydiv;
  277. entity.BilletOrigin = plly;
  278. entity.IngotName = pdx;
  279. entity.UnitCode = jz;
  280. entity.AlloyBak1 = cggz; //常规钢种
  281. entity.AlloyBak2 = bz; // 标准
  282. entity.SteelTypeCode = pzlb;
  283. entity.HotTreatMethod = jhzt;
  284. entity.SufaceState = bmzt;
  285. entity.NonLength = sfdc;
  286. entity.Jiarelu = jru;
  287. entity.Rechuli = rcl;
  288. entity.Rezha = rzqt;
  289. entity.Dinchi = dcqt;
  290. entity.Bapi = bp;
  291. entity.Quliao = ql;
  292. entity.Tksunshi = tkss;//通孔损失
  293. entity.Lzsunshi = lzss; //理重损失
  294. entity.Fp = fp;//废品
  295. entity.RecCreator = UserInfo.GetUserName();
  296. entity.Zsunshi = jru + rcl + rzqt + dcqt + bp + ql + tkss+lzss+fp;
  297. entity.Chencailv = 100 - (jru + rcl + rzqt + dcqt + bp + ql + tkss + lzss + fp);
  298. entity.RpNum = id;
  299. Tqnqc17Entitys.Add(entity);
  300. }
  301. }
  302. }
  303. }
  304. return Tqnqc17Entitys;
  305. }
  306. catch (Exception ex)
  307. {
  308. MessageBox.Show("EXCEL格式错误:" + ex.Message);
  309. return null;
  310. }
  311. }
  312. private string GetCellValue(ICell cell)
  313. {
  314. string value = "";
  315. switch (cell.CellType)
  316. {
  317. case CellType.Blank:
  318. value = "";
  319. break;
  320. case CellType.Numeric:
  321. short format = cell.CellStyle.DataFormat;
  322. value = cell.NumericCellValue.ToString2();
  323. break;
  324. case CellType.String:
  325. value = cell.StringCellValue;
  326. break;
  327. }
  328. return value;
  329. }
  330. //获取机组
  331. private void doQueryjz()
  332. {
  333. DataTable dt = ServerHelper.GetData("com.steering.mes.cost.FrmTqnqc17.doQueryjz", null, ob);
  334. text_jz.DataSource = dt;
  335. text_jz.ValueMember = "BASECODE";
  336. text_jz.DisplayMember = "BASENAME";
  337. SetComboItemHeight(text_jz);
  338. }
  339. //获取其它数据
  340. private void doQueryBaseInfo() {
  341. //工序
  342. DataTable dt1 = GetComBaseInfo("4105", ob);
  343. text_name.DataSource = dt1;
  344. text_name.ValueMember = "BASECODE";
  345. text_name.DisplayMember = "BASENAME";
  346. SetComboItemHeight(text_jz);
  347. //坯料来源
  348. DataTable dt2 = GetComBaseInfo("20110101", ob);
  349. plyl.DataSource = dt2;
  350. plyl.ValueMember = "BASECODE";
  351. plyl.DisplayMember = "BASENAME";
  352. SetComboItemHeight(plyl);
  353. //锭坯型
  354. DataTable dt3 = GetComBaseInfo("20110102", ob);
  355. dx.DataSource = dt3;
  356. dx.ValueMember = "BASECODE";
  357. dx.DisplayMember = "BASENAME";
  358. SetComboItemHeight(dx);
  359. //锭坯型
  360. DataTable dt4 = GetComBaseInfo("20110103", ob);
  361. jhstate.DataSource = dt4;
  362. jhstate.ValueMember = "BASECODE";
  363. jhstate.DisplayMember = "BASENAME";
  364. SetComboItemHeight(jhstate);
  365. DataTable dt5 = GetComBaseInfo("20110104", ob);
  366. bmstate.DataSource = dt5;
  367. bmstate.ValueMember = "BASECODE";
  368. bmstate.DisplayMember = "BASENAME";
  369. SetComboItemHeight(bmstate);
  370. List<String> ls = new List<String>();
  371. ls.Add("常规品种");
  372. ls.Add("特殊品种");
  373. List<String> ls2 = new List<String>();
  374. ls2.Add("是");
  375. ls2.Add("否");
  376. ls2.Add("不分");
  377. cgpz.DataSource = ls;
  378. sfdc.DataSource = ls2;
  379. }
  380. public static DataTable GetComBaseInfo(string sortCode, OpeBase ob)
  381. {
  382. return ServerHelper.GetData("com.steering.mes.signature.FrmMilControlLog.getComBaseInfo", new object[] { sortCode }, ob);
  383. }
  384. public static void SetComboItemHeight(UltraComboEditor cmb)
  385. {
  386. foreach (ValueListItem item in cmb.Items)
  387. {
  388. if (System.Text.RegularExpressions.Regex.IsMatch(item.DisplayText, @"[\u4e00-\u9fa5]+"))
  389. {
  390. item.Appearance.FontData.SizeInPoints = 9.0F;
  391. }
  392. else
  393. {
  394. item.Appearance.FontData.SizeInPoints = 10.5F;
  395. }
  396. }
  397. }
  398. }
  399. }