FrmWalktHrough.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. using Core.Mes.Client.Comm.Control;
  2. using Core.Mes.Client.Comm.Format;
  3. using Core.Mes.Client.Comm.Tool;
  4. using Core.StlMes.Client.PlnSaleOrd.管坯优化.model;
  5. using CoreFS.CA06;
  6. using System;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. using System.ComponentModel;
  10. using System.Data;
  11. using System.Drawing;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Windows.Forms;
  16. using NPOI.SS.UserModel;
  17. using Core.Mes.Client.Comm.Server;
  18. namespace Core.StlMes.Client.PlnSaleOrd
  19. {
  20. public partial class FrmWalktHrough : FrmBase
  21. {
  22. private OpeBase ob;
  23. private string gradeCode = "";
  24. private string outs_billet_fl="";
  25. private string custom = "";
  26. public FrmWalktHrough(OpeBase _ob, string _outs_billet_fl,string _custom)
  27. {
  28. ob = _ob;
  29. outs_billet_fl = _outs_billet_fl;
  30. custom = _custom;
  31. InitializeComponent();
  32. EntityHelper.ShowGridCaption<PlnReqinfGpExcel>(ultraGrid1.DisplayLayout.Bands[0]);
  33. plnReqinfGpExcelBindingSource.DataSource = new List<PlnReqinfGpExcel>()
  34. {
  35. new PlnReqinfGpExcel()
  36. {
  37. GpreqId = "1"
  38. }
  39. };
  40. }
  41. /// <summary>
  42. /// 保存
  43. /// </summary>
  44. /// <param name="sender"></param>
  45. /// <param name="e"></param>
  46. private void ultraButton1_Click(object sender, EventArgs e)
  47. {
  48. if (comGptype.Text.Equals(""))
  49. {
  50. MessageUtil.ShowTips("坯分类不能为空,请选择!");
  51. return;
  52. }
  53. if (txtGrad.Text.Equals(""))
  54. {
  55. MessageUtil.ShowTips("钢种不能为空,请选择!");
  56. return;
  57. }
  58. if (txtCic.Text.Equals(""))
  59. {
  60. MessageUtil.ShowTips("钢种索引码不能为空,请选择!");
  61. return;
  62. }
  63. if (txtDiarm.Text.Equals(""))
  64. {
  65. MessageUtil.ShowTips("断面不能为空,请输入!");
  66. return;
  67. }
  68. if (txtLenGp.Text.Equals(""))
  69. {
  70. MessageUtil.ShowTips("单倍坯长不能为空,请输入!");
  71. return;
  72. }
  73. if (txtGpWt.Text.Equals(""))
  74. {
  75. MessageUtil.ShowTips("需求量不能为空,请输入!");
  76. return;
  77. }
  78. if(txtIsDear.Value.ToString2().Equals(""))
  79. {
  80. MessageUtil.ShowTips("坯料用途不能为空!");
  81. return;
  82. }
  83. int lenGpSingle = Convert.ToInt32(txtLenGp.Value.ToString());
  84. if (lenGpSingle % 10 != 0)
  85. {
  86. MessageUtil.ShowWarning("单倍坯长个位数不是0,请重新输入!");
  87. return;
  88. }
  89. if (txtLengthGp.Text.Equals(""))
  90. {
  91. MessageUtil.ShowTips("管坯长度不能为空,请输入!");
  92. return;
  93. }
  94. if (txtCutNumGp.Text.Equals(""))
  95. {
  96. MessageUtil.ShowTips("倍尺数不能为空,请输入!");
  97. return;
  98. }
  99. ArrayList list = new ArrayList();
  100. list.Add(comGptype.Value.ToString());
  101. list.Add(gradeCode);
  102. list.Add(txtGrad.Text.ToString());
  103. list.Add(txtCic.Text.ToString());
  104. list.Add(txtDiarm.Value.ToString());
  105. list.Add(txtLenGp.Value.ToString());
  106. list.Add(txtGpWt.Value.ToString());
  107. list.Add(this.UserInfo.GetUserName());
  108. list.Add(DateTime.Now.ToString());
  109. list.Add(txtIsDear.Value.ToString2());
  110. list.Add(txtLengthGp.Value.ToString());
  111. list.Add(txtCutNumGp.Value.ToString());
  112. CoreClientParam ccp = new CoreClientParam();
  113. ccp.ServerName = "com.steering.pss.plnsaleord.GpOptimize.CorePlnZgMStoGp";
  114. ccp.MethodName = "addWalktHrough";
  115. ccp.ServerParams = new object[] { list, outs_billet_fl,custom };
  116. ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  117. if (ccp.ReturnCode == -1) return;
  118. MessageUtil.ShowTips(ccp.ReturnInfo);
  119. if (ccp.ReturnInfo.Equals("保存成功!")) { this.Close(); return; }
  120. }
  121. /// <summary>
  122. /// 关闭
  123. /// </summary>
  124. /// <param name="sender"></param>
  125. /// <param name="e"></param>
  126. private void ultraButton2_Click(object sender, EventArgs e)
  127. {
  128. this.Close();
  129. }
  130. /// <summary>
  131. /// 选择钢种,钢种索引码
  132. /// </summary>
  133. /// <param name="sender"></param>
  134. /// <param name="e"></param>
  135. private void txtGrad_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
  136. {
  137. FrmSteelGrade steel = new FrmSteelGrade(ob, outs_billet_fl);
  138. if (outs_billet_fl.Equals("0"))
  139. {
  140. steel.Text = "自炼钢种及钢种索引码";
  141. }
  142. else
  143. {
  144. steel.Text = "外购钢种及钢种索引码";
  145. }
  146. steel.AutoSize = true;
  147. steel.ShowDialog();
  148. if (steel.DialogResult == System.Windows.Forms.DialogResult.OK)
  149. {
  150. //获取弹出窗体的属性值
  151. txtGrad.Text = steel.Gradename;
  152. txtCic.Text = steel.Cic;
  153. gradeCode = steel.Gradecode;
  154. }
  155. }
  156. private void ultraButton3_Click(object sender, EventArgs e)
  157. {
  158. GridHelper.ulGridToExcel(ultraGrid1, "导入模板");
  159. }
  160. private void ultraButton4_Click(object sender, EventArgs e)
  161. {
  162. List<PlnReqinfGpExcel> lists = null;
  163. var openFileDialog = new OpenFileDialog
  164. {
  165. Filter = "测量点数据|*.xls;*.xlsx"
  166. };
  167. if (openFileDialog.ShowDialog() == DialogResult.OK)
  168. {
  169. lists = ReadExcelToPlnReqinfGpExcel(openFileDialog.FileName);
  170. }
  171. if (lists == null) return;
  172. if (lists.Count <= 0)
  173. {
  174. MessageBox.Show("Excel无数据");
  175. return;
  176. }
  177. DataTable dt = ServerHelper.GetData("com.steering.pss.plnsaleord.GpOptimize.CorePlnZgMStoGp.getQueryGrade1", new object[] { outs_billet_fl }, ob);
  178. ArrayList list1 = new ArrayList();
  179. foreach (var plnReqinfGpExcel in lists)
  180. {
  181. ArrayList list = new ArrayList();
  182. DataRow[] drs = dt.Select("GRADENAME ='" + plnReqinfGpExcel.Gradename + "' and STD_IDX = '" + plnReqinfGpExcel.Cic + "'");
  183. plnReqinfGpExcel.Gradecode = drs[0]["GRADECODE"].ToString2();
  184. if (String.IsNullOrEmpty(plnReqinfGpExcel.Gradecode))
  185. {
  186. MessageBox.Show("没有查询到改"+plnReqinfGpExcel.Gradename+"钢种!");
  187. return;
  188. }
  189. list.Add(plnReqinfGpExcel.Gptype);
  190. list.Add(plnReqinfGpExcel.Gradecode);
  191. list.Add(plnReqinfGpExcel.Gradename);
  192. list.Add(plnReqinfGpExcel.Cic);
  193. list.Add(plnReqinfGpExcel.DiameterGp.ToString2());
  194. list.Add(plnReqinfGpExcel.LenGpSingle.ToString2());
  195. list.Add(plnReqinfGpExcel.GpWtLong);
  196. list.Add(this.UserInfo.GetUserName());
  197. list.Add(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  198. list.Add(plnReqinfGpExcel.TypeFlag);
  199. list.Add(plnReqinfGpExcel.LengthGp.ToString2());
  200. list.Add(plnReqinfGpExcel.CutNumGp.ToString2());
  201. list1.Add(list);
  202. }
  203. CoreClientParam ccp = new CoreClientParam();
  204. ccp.ServerName = "com.steering.pss.plnsaleord.GpOptimize.CorePlnZgMStoGp";
  205. ccp.MethodName = "addWalktHroughExcel";
  206. ccp.ServerParams = new object[] { list1, outs_billet_fl, custom };
  207. ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  208. if (ccp.ReturnCode == -1) {
  209. MessageUtil.ShowWarning(ccp.ReturnInfo);
  210. return;
  211. }
  212. if (ccp.ReturnCode == 0) {
  213. MessageUtil.ShowTips(ccp.ReturnInfo);
  214. this.Close(); return;
  215. }
  216. }
  217. public List<PlnReqinfGpExcel> ReadExcelToPlnReqinfGpExcel(string fileName)
  218. {
  219. //定义要返回的datatable对象
  220. List<PlnReqinfGpExcel> plnReqinfGpExcels = new List<PlnReqinfGpExcel>();
  221. try
  222. {
  223. if (!File.Exists(fileName))
  224. {
  225. return null;
  226. }
  227. //根据指定路径读取文件
  228. using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
  229. {
  230. //根据文件流创建excel数据结构
  231. NPOI.SS.UserModel.IWorkbook workbook = NPOI.SS.UserModel.WorkbookFactory.Create(fs);
  232. //IWorkbook workbook = new HSSFWorkbook(fs);
  233. for (int k = 0; k < workbook.NumberOfSheets; k++)
  234. {
  235. NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(k);
  236. if (sheet != null)
  237. {
  238. //最后一列的标号
  239. int rowCount = sheet.LastRowNum;
  240. for (int i = 1; i <= rowCount; ++i)
  241. {
  242. NPOI.SS.UserModel.IRow row = sheet.GetRow(i);
  243. if (row == null) continue; //没有数据的行默认是null       
  244. PlnReqinfGpExcel plnReqinfGpExcel = new PlnReqinfGpExcel();
  245. plnReqinfGpExcel.TypeFlag = GetCellValue(row.Cells[0]);
  246. plnReqinfGpExcel.Gptype = GetCellValue(row.Cells[1]);
  247. plnReqinfGpExcel.Gradecode = GetCellValue(row.Cells[2]);
  248. plnReqinfGpExcel.Gradename = GetCellValue(row.Cells[3]);
  249. plnReqinfGpExcel.Cic = GetCellValue(row.Cells[4]);
  250. decimal lenGpSingle, cutNumGp, lengthGp, diameterGp;
  251. decimal.TryParse(GetCellValue(row.Cells[5]), out lenGpSingle);
  252. decimal.TryParse(GetCellValue(row.Cells[6]), out cutNumGp);
  253. decimal.TryParse(GetCellValue(row.Cells[7]), out lengthGp);
  254. plnReqinfGpExcel.LenGpSingle = lenGpSingle;
  255. plnReqinfGpExcel.CutNumGp = cutNumGp;
  256. plnReqinfGpExcel.LengthGp = lengthGp;
  257. plnReqinfGpExcel.GpWtLong = GetCellValue(row.Cells[8]);
  258. decimal.TryParse(GetCellValue(row.Cells[9]), out diameterGp);
  259. plnReqinfGpExcel.DiameterGp = diameterGp;
  260. plnReqinfGpExcels.Add(plnReqinfGpExcel);
  261. }
  262. }
  263. }
  264. }
  265. return plnReqinfGpExcels;
  266. }
  267. catch (Exception ex)
  268. {
  269. MessageBox.Show("EXCEL格式错误:" + ex.Message);
  270. return null;
  271. }
  272. }
  273. private string GetCellValue(ICell cell)
  274. {
  275. string value = "";
  276. switch (cell.CellType)
  277. {
  278. case CellType.Blank:
  279. value = "";
  280. break;
  281. case CellType.Numeric:
  282. short format = cell.CellStyle.DataFormat;
  283. value = cell.NumericCellValue.ToString2();
  284. break;
  285. case CellType.String:
  286. value = cell.StringCellValue;
  287. break;
  288. }
  289. return value;
  290. }
  291. }
  292. }