FrmTqnqc13.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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 FrmTqnqc13 : FrmBase
  23. {
  24. #region 定义变量
  25. public FrmTqnqc13()
  26. {
  27. InitializeComponent();
  28. EntityHelper.ShowGridCaption<Tqnqc13Entity>(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 "doAdd":
  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. Tqnqc13Entity tqnqc13Entity = (Tqnqc13Entity)uRow.ListObject;
  65. string Tqnqc13Entity = JSONFormat.Format(tqnqc13Entity);
  66. parm.Add(Tqnqc13Entity);
  67. }
  68. CoreClientParam ccp = new CoreClientParam();
  69. ccp.ServerName = "com.steering.mes.cost.FrmTqnqc13";
  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. private void doAdd()
  89. {
  90. List<Tqnqc13Entity> list = null;
  91. var openFileDialog = new OpenFileDialog
  92. {
  93. Filter = "工艺路径|*.xls;*.xlsx"
  94. };
  95. if (openFileDialog.ShowDialog() == DialogResult.OK)
  96. {
  97. list = ReadExcelToSingnhjxhEntity(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.FrmTqnqc13";
  108. ccp.MethodName = "DoAddTqnqc13";
  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<Tqnqc13Entity> ReadExcelToSingnhjxhEntity(string fileName)
  124. {
  125. //定义要返回的datatable对象
  126. List<Tqnqc13Entity> Tqnqc13Entitys = new List<Tqnqc13Entity>();
  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. Tqnqc13Entity entity = new Tqnqc13Entity();
  149. NPOI.SS.UserModel.IRow row = sheet.GetRow(i);
  150. if (row == null) continue; //没有数据的行默认是null       
  151. if (row.Cells.Count < 4)
  152. {
  153. throw new Exception("无足够列");
  154. }
  155. //WHOLE_BACKLOG_NAME
  156. string WholeBacklogName = GetCellValue(row.Cells[0]);
  157. string WholeBacklog = GetCellValue(row.Cells[1]);
  158. string RpCode = GetCellValue(row.Cells[3]);
  159. if (WholeBacklogName == "" || WholeBacklogName == null)
  160. {
  161. throw new Exception("工艺路劲为空");
  162. }
  163. if (WholeBacklog == "" || WholeBacklog == null)
  164. {
  165. throw new Exception("工序为空");
  166. }
  167. if (RpCode == "" || RpCode == null)
  168. {
  169. throw new Exception("代码为空");
  170. }
  171. entity.WholeBacklogName = WholeBacklogName;
  172. entity.WholeBacklog = WholeBacklog;
  173. entity.RpCode = RpCode;
  174. entity.RecCreator = this.UserInfo.GetUserName();
  175. decimal outLtemNum;
  176. decimal.TryParse(GetCellValue(row.Cells[2]), out outLtemNum);
  177. if (outLtemNum < 0 || outLtemNum == null)
  178. {
  179. throw new Exception("序号为空");
  180. }
  181. entity.LtemNum = outLtemNum;
  182. Tqnqc13Entitys.Add(entity);
  183. }
  184. }
  185. }
  186. }
  187. return Tqnqc13Entitys;
  188. }
  189. catch (Exception ex)
  190. {
  191. MessageBox.Show("EXCEL格式错误:" + ex.Message);
  192. return null;
  193. }
  194. }
  195. private string GetCellValue(ICell cell)
  196. {
  197. string value = "";
  198. switch (cell.CellType)
  199. {
  200. case CellType.Blank:
  201. value = "";
  202. break;
  203. case CellType.Numeric:
  204. short format = cell.CellStyle.DataFormat;
  205. value = cell.NumericCellValue.ToString2();
  206. break;
  207. case CellType.String:
  208. value = cell.StringCellValue;
  209. break;
  210. }
  211. return value;
  212. }
  213. /// <summary>
  214. /// 保存
  215. /// </summary>
  216. private void doSave()
  217. {
  218. try
  219. {
  220. this.ultraGrid1.UpdateData();
  221. IQueryable<UltraGridRow> checkMagRows = this.ultraGrid1.Rows.AsQueryable().Where(" XUANZE = 'True'");
  222. if (checkMagRows.Count() == 0)
  223. {
  224. MessageUtil.ShowTips("请选择需要修改的数据!");
  225. return;
  226. }
  227. ArrayList parm = new ArrayList();
  228. foreach (UltraGridRow uRow in checkMagRows)
  229. {
  230. Tqnqc13Entity entity = (Tqnqc13Entity)uRow.ListObject;
  231. entity.RecRevisor = UserInfo.GetUserName();
  232. string Tqnqc13Entity = JSONFormat.Format(entity);
  233. parm.Add(Tqnqc13Entity);
  234. }
  235. CoreClientParam ccp = new CoreClientParam();
  236. ccp.ServerName = "com.steering.mes.cost.FrmTqnqc13";
  237. ccp.MethodName = "doSave";
  238. ccp.ServerParams = new object[] { parm };
  239. ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  240. if (ccp.ReturnCode != -1)
  241. {
  242. if (ccp.ReturnInfo.Equals("操作成功"))
  243. {
  244. // DoQueryInList();
  245. Query();
  246. MessageUtil.ShowTips(ccp.ReturnInfo);
  247. }
  248. else
  249. {
  250. MessageUtil.ShowTips(ccp.ReturnInfo);
  251. }
  252. }
  253. }
  254. catch
  255. {
  256. return;
  257. }
  258. }
  259. /// 查询方法
  260. /// <summary>
  261. /// 查询方法
  262. /// </summary>
  263. private void Query()
  264. {
  265. List<Tqnqc13Entity> listSource = EntityHelper.GetData<Tqnqc13Entity>(
  266. "com.steering.mes.cost.FrmTqnqc13.Query", new object[] { cicText.Text }, this.ob);
  267. singnhjxhEntityBindingSource.DataSource = listSource;
  268. GridHelper.RefreshAndAutoSize(ultraGrid1);
  269. }
  270. /// 保存方法
  271. /// <summary>
  272. /// 保存方法
  273. /// </summary>
  274. private void Save()
  275. {
  276. }
  277. #endregion
  278. #region
  279. #endregion
  280. }
  281. }