FrmBaseprocessbz.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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 Core.Mes.Client.Comm.Control;
  13. using Core.Mes.Client.Comm.Format;
  14. using Core.Mes.Client.Comm.Tool;
  15. using CoreFS.CA06;
  16. using Infragistics.Win;
  17. using Infragistics.Win.UltraWinGrid;
  18. using NPOI.SS.UserModel;
  19. using Core.StlMes.Client.PnCost.Models;
  20. namespace Core.StlMes.Client.PnCost
  21. {
  22. public partial class FrmBaseprocessbz : FrmBase
  23. {
  24. #region 定义变量
  25. public FrmBaseprocessbz()
  26. {
  27. InitializeComponent();
  28. EntityHelper.ShowGridCaption<BaseprocessbzcostEntity>(ultraGrid1.DisplayLayout.Bands[0]);
  29. }
  30. private DataTable dtgang;
  31. #endregion
  32. #region 方法
  33. public override void ToolBar_Click(object sender, string ToolbarKey)
  34. {
  35. base.ToolBar_Click(sender, ToolbarKey);
  36. switch (ToolbarKey)
  37. {
  38. case "Query":
  39. Query();
  40. break;
  41. case "doSave":
  42. doSave();
  43. break;
  44. case "Import":
  45. doAdd();
  46. break;
  47. case "doDelete":
  48. this.doDelete();
  49. break;
  50. }
  51. }
  52. private void doDelete()
  53. {
  54. this.ultraGrid1.UpdateData();
  55. IQueryable<UltraGridRow> checkMagRows = this.ultraGrid1.Rows.AsQueryable().Where(" XUANZE = 'True'");
  56. if (checkMagRows.Count() == 0)
  57. {
  58. MessageUtil.ShowTips("请选择需要删除的数据!");
  59. return;
  60. }
  61. ArrayList parm = new ArrayList();
  62. foreach (UltraGridRow uRow in checkMagRows)
  63. {
  64. BaseprocessbzcostEntity outproductsEntity = (BaseprocessbzcostEntity)uRow.ListObject;
  65. string OutproductsEntity = JSONFormat.Format(outproductsEntity);
  66. parm.Add(OutproductsEntity);
  67. }
  68. CoreClientParam ccp = new CoreClientParam();
  69. ccp.ServerName = "com.steering.mes.cost.FrmBaseprocessbzcost";
  70. ccp.MethodName = "doDelete";
  71. ccp.ServerParams = new object[] { parm };
  72. ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  73. if (ccp.ReturnCode != -1)
  74. {
  75. if (ccp.ReturnInfo.Equals("操作成功"))
  76. {
  77. // DoQueryInList();
  78. Query();
  79. MessageUtil.ShowTips(ccp.ReturnInfo);
  80. }
  81. else
  82. {
  83. MessageUtil.ShowTips(ccp.ReturnInfo);
  84. }
  85. }
  86. }
  87. ///
  88. public void doAdd()
  89. {
  90. List<BaseprocessbzcostEntity> list = null;
  91. var openFileDialog = new OpenFileDialog
  92. {
  93. Filter = "结算数据|*.xls;*.xlsx"
  94. };
  95. if (openFileDialog.ShowDialog() == DialogResult.OK)
  96. {
  97. list = ReadExcelToBaseprocessbzcostEntity(openFileDialog.FileName);
  98. }
  99. if (list == null) return;
  100. if (list.Count <= 0)
  101. {
  102. MessageBox.Show("Excel无数据");
  103. return;
  104. }
  105. string userName = UserInfo.GetUserName();
  106. var ccp = new CoreClientParam();
  107. ccp.ServerName = "com.steering.mes.cost.FrmBaseprocessbzcost";
  108. ccp.MethodName = "DoAddBaseprocessbzcosts";
  109. ccp.ServerParams = new object[]
  110. {
  111. list.Select(JSONFormat.Format).ToList()
  112. };
  113. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  114. if (ccp.ReturnCode != -1)
  115. {
  116. MessageUtil.ShowTips(ccp.ReturnInfo);
  117. if (ccp.ReturnInfo.Equals("导入成功"))
  118. {
  119. Query();
  120. }
  121. }
  122. }
  123. public List<BaseprocessbzcostEntity> ReadExcelToBaseprocessbzcostEntity(string fileName)
  124. {
  125. //定义要返回的datatable对象
  126. List<BaseprocessbzcostEntity> OutproductsEntitys = new List<BaseprocessbzcostEntity>();
  127. try
  128. {
  129. if (!File.Exists(fileName))
  130. {
  131. return null;
  132. }
  133. //根据指定路径读取文件
  134. using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
  135. {
  136. //根据文件流创建excel数据结构
  137. NPOI.SS.UserModel.IWorkbook workbook = NPOI.SS.UserModel.WorkbookFactory.Create(fs);
  138. //IWorkbook workbook = new HSSFWorkbook(fs);
  139. for (int k = 0; k < workbook.NumberOfSheets; k++)
  140. {
  141. NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(k);
  142. if (sheet != null)
  143. {
  144. //最后一列的标号
  145. int rowCount = sheet.LastRowNum;
  146. for (int i = 1; i <= rowCount; ++i)
  147. {
  148. BaseprocessbzcostEntity entity = new BaseprocessbzcostEntity();
  149. NPOI.SS.UserModel.IRow row = sheet.GetRow(i);
  150. if (row == null) continue; //没有数据的行默认是null       
  151. if (row.Cells.Count < 14)
  152. {
  153. throw new Exception("无足够列");
  154. }
  155. //WHOLE_BACKLOG_NAME
  156. string askplanId = GetCellValue(row.Cells[0]);
  157. string ordNo = GetCellValue(row.Cells[1]);
  158. string ordSeq = GetCellValue(row.Cells[2]);
  159. string spetKey = GetCellValue(row.Cells[3]);
  160. string steelCodeKey = GetCellValue(row.Cells[4]);
  161. string steelName = GetCellValue(row.Cells[5]);
  162. string compantype = GetCellValue(row.Cells[6]);
  163. string articlename = GetCellValue(row.Cells[7]);
  164. string modelDesc = GetCellValue(row.Cells[8]);
  165. string stovNo = GetCellValue(row.Cells[11]);
  166. string jsDate = GetCellValue(row.Cells[14]);
  167. string wlName = GetCellValue(row.Cells[15]);
  168. string inceptcorpcode = GetCellValue(row.Cells[16]);
  169. decimal waijin;
  170. decimal bihou;
  171. decimal weight;
  172. decimal money;
  173. decimal.TryParse(GetCellValue(row.Cells[9]), out waijin);
  174. decimal.TryParse(GetCellValue(row.Cells[10]), out bihou);
  175. decimal.TryParse(GetCellValue(row.Cells[12]), out weight);
  176. decimal.TryParse(GetCellValue(row.Cells[13]), out money);
  177. if (askplanId == "" || askplanId == null)
  178. {
  179. throw new Exception("提单号为空");
  180. }
  181. if (ordNo == "" || ordNo == null)
  182. {
  183. throw new Exception("合同号为空");
  184. }
  185. if (ordSeq == "" || ordSeq == null)
  186. {
  187. throw new Exception("合同行号为空");
  188. }
  189. if (steelName == "" || steelName == null)
  190. {
  191. throw new Exception("钢种为空");
  192. }
  193. if (stovNo == "" || stovNo == null)
  194. {
  195. throw new Exception("炉号为空");
  196. }
  197. if (jsDate == "" || jsDate == null)
  198. {
  199. throw new Exception("结算日期为空");
  200. }
  201. entity.AskplanId = askplanId;
  202. entity.OrdNo = ordNo;
  203. entity.OrdSeq = ordSeq;
  204. entity.Spetkey = spetKey;
  205. entity.Steelcodekey = steelCodeKey;
  206. entity.Steelname = steelName;
  207. entity.Companytype = compantype;
  208. entity.Articlename = articlename;
  209. entity.ModelDesc = modelDesc;
  210. entity.StoveNo = stovNo;
  211. entity.JsDate = jsDate;
  212. entity.Waijin = waijin;
  213. entity.Bihou = bihou;
  214. entity.Weight = weight;
  215. entity.Money = money;
  216. entity.Wlname = wlName;
  217. entity.Inceptcorpcode = inceptcorpcode;
  218. OutproductsEntitys.Add(entity);
  219. }
  220. }
  221. }
  222. }
  223. return OutproductsEntitys;
  224. }
  225. catch (Exception ex)
  226. {
  227. MessageBox.Show("EXCEL格式错误:" + ex.Message);
  228. return null;
  229. }
  230. }
  231. private string GetCellValue(ICell cell)
  232. {
  233. string value = "";
  234. switch (cell.CellType)
  235. {
  236. case CellType.Blank:
  237. value = "";
  238. break;
  239. case CellType.Numeric:
  240. short format = cell.CellStyle.DataFormat;
  241. value = cell.NumericCellValue.ToString2();
  242. break;
  243. case CellType.String:
  244. value = cell.StringCellValue;
  245. break;
  246. }
  247. return value;
  248. }
  249. /// <summary>
  250. /// 保存
  251. /// </summary>
  252. private void doSave()
  253. {
  254. try
  255. {
  256. this.ultraGrid1.UpdateData();
  257. IQueryable<UltraGridRow> checkMagRows = this.ultraGrid1.Rows.AsQueryable().Where(" XUANZE = 'True'");
  258. if (checkMagRows.Count() == 0)
  259. {
  260. MessageUtil.ShowTips("请选择需要修改的数据!");
  261. return;
  262. }
  263. ArrayList parm = new ArrayList();
  264. foreach (UltraGridRow uRow in checkMagRows)
  265. {
  266. BaseprocessbzcostEntity entity = (BaseprocessbzcostEntity)uRow.ListObject;
  267. string OutproductsEntity = JSONFormat.Format(entity);
  268. parm.Add(OutproductsEntity);
  269. }
  270. CoreClientParam ccp = new CoreClientParam();
  271. ccp.ServerName = "com.steering.mes.cost.FrmBaseprocessbzcost";
  272. ccp.MethodName = "doSave";
  273. ccp.ServerParams = new object[] { parm };
  274. ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  275. if (ccp.ReturnCode != -1)
  276. {
  277. if (ccp.ReturnInfo.Equals("操作成功"))
  278. {
  279. // DoQueryInList();
  280. Query();
  281. MessageUtil.ShowTips(ccp.ReturnInfo);
  282. }
  283. else
  284. {
  285. MessageUtil.ShowTips(ccp.ReturnInfo);
  286. }
  287. }
  288. }
  289. catch
  290. {
  291. return;
  292. }
  293. }
  294. /// 查询方法
  295. /// <summary>
  296. /// 查询方法
  297. /// </summary>
  298. private void Query()
  299. {
  300. List<BaseprocessbzcostEntity> listSource = EntityHelper.GetData<BaseprocessbzcostEntity>(
  301. "com.steering.mes.cost.FrmBaseprocessbzcost.Query", new object[] { textTd.Text, textHt.Text }, this.ob);
  302. baseprocessbzcostEntityBindingSource.DataSource = listSource;
  303. GridHelper.RefreshAndAutoSize(ultraGrid1);
  304. }
  305. /// 保存方法
  306. /// <summary>
  307. /// 保存方法
  308. /// </summary>
  309. private void Save()
  310. {
  311. }
  312. #endregion
  313. #region
  314. #endregion
  315. }
  316. }