FrmTqnqc19.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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 FrmTqnqc19 : FrmBase
  23. {
  24. #region 定义变量
  25. public FrmTqnqc19()
  26. {
  27. InitializeComponent();
  28. EntityHelper.ShowGridCaption<Tqnqc19Entity>(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. Tqnqc19Entity tqnqc19Entity = (Tqnqc19Entity)uRow.ListObject;
  65. string Tqnqc19Entity = JSONFormat.Format(tqnqc19Entity);
  66. parm.Add(Tqnqc19Entity);
  67. }
  68. CoreClientParam ccp = new CoreClientParam();
  69. ccp.ServerName = "com.steering.mes.cost.FrmTqnqc19";
  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<Tqnqc19Entity> 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.FrmTqnqc19";
  108. ccp.MethodName = "DoAddTqnqc19";
  109. ccp.ServerParams = new object[]
  110. {
  111. list.Select(JSONFormat.Format).ToList(),
  112. userName
  113. };
  114. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  115. if (ccp.ReturnCode != -1)
  116. {
  117. MessageUtil.ShowTips(ccp.ReturnInfo);
  118. if (ccp.ReturnInfo.Equals("导入成功"))
  119. {
  120. Query();
  121. }
  122. }
  123. }
  124. public List<Tqnqc19Entity> ReadExcelToSingnhjxhEntity(string fileName)
  125. {
  126. //定义要返回的datatable对象
  127. List<Tqnqc19Entity> Tqnqc19Entitys = new List<Tqnqc19Entity>();
  128. try
  129. {
  130. if (!File.Exists(fileName))
  131. {
  132. return null;
  133. }
  134. //根据指定路径读取文件
  135. using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
  136. {
  137. //根据文件流创建excel数据结构
  138. NPOI.SS.UserModel.IWorkbook workbook = NPOI.SS.UserModel.WorkbookFactory.Create(fs);
  139. //IWorkbook workbook = new HSSFWorkbook(fs);
  140. for (int k = 0; k < workbook.NumberOfSheets; k++)
  141. {
  142. NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(k);
  143. if (sheet != null)
  144. {
  145. //最后一列的标号
  146. int rowCount = sheet.LastRowNum;
  147. for (int i = 1; i <= rowCount; ++i)
  148. {
  149. Tqnqc19Entity entity = new Tqnqc19Entity();
  150. NPOI.SS.UserModel.IRow row = sheet.GetRow(i);
  151. if (row == null) continue; //没有数据的行默认是null       
  152. if (row.Cells.Count < 3)
  153. {
  154. throw new Exception("无足够列");
  155. }
  156. //WHOLE_BACKLOG_NAME
  157. string SgSign = GetCellValue(row.Cells[0]);
  158. string SteelTypeCode = GetCellValue(row.Cells[1]);
  159. decimal DifRadio;
  160. decimal.TryParse(GetCellValue(row.Cells[2]), out DifRadio);
  161. if (DifRadio == null)
  162. {
  163. throw new Exception("序号为空");
  164. }
  165. entity.SgSign = SgSign;
  166. entity.SteelTypeCode = SteelTypeCode;
  167. entity.DifRadio = DifRadio;
  168. Tqnqc19Entitys.Add(entity);
  169. }
  170. }
  171. }
  172. }
  173. return Tqnqc19Entitys;
  174. }
  175. catch (Exception ex)
  176. {
  177. MessageBox.Show("EXCEL格式错误:" + ex.Message);
  178. return null;
  179. }
  180. }
  181. private string GetCellValue(ICell cell)
  182. {
  183. string value = "";
  184. switch (cell.CellType)
  185. {
  186. case CellType.Blank:
  187. value = "";
  188. break;
  189. case CellType.Numeric:
  190. short format = cell.CellStyle.DataFormat;
  191. value = cell.NumericCellValue.ToString2();
  192. break;
  193. case CellType.String:
  194. value = cell.StringCellValue;
  195. break;
  196. }
  197. return value;
  198. }
  199. /// <summary>
  200. /// 保存
  201. /// </summary>
  202. private void doSave()
  203. {
  204. try
  205. {
  206. this.ultraGrid1.UpdateData();
  207. IQueryable<UltraGridRow> checkMagRows = this.ultraGrid1.Rows.AsQueryable().Where(" XUANZE = 'True'");
  208. if (checkMagRows.Count() == 0)
  209. {
  210. MessageUtil.ShowTips("请选择需要修改的数据!");
  211. return;
  212. }
  213. ArrayList parm = new ArrayList();
  214. foreach (UltraGridRow uRow in checkMagRows)
  215. {
  216. Tqnqc12Entity entity = (Tqnqc12Entity)uRow.ListObject;
  217. entity.RecRevisor = UserInfo.GetUserName();
  218. string Tqnqc13Entity = JSONFormat.Format(entity);
  219. parm.Add(Tqnqc13Entity);
  220. }
  221. CoreClientParam ccp = new CoreClientParam();
  222. ccp.ServerName = "com.steering.mes.cost.FrmTqnqc19";
  223. ccp.MethodName = "doSave";
  224. ccp.ServerParams = new object[] { parm };
  225. ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  226. if (ccp.ReturnCode != -1)
  227. {
  228. if (ccp.ReturnInfo.Equals("操作成功"))
  229. {
  230. // DoQueryInList();
  231. Query();
  232. MessageUtil.ShowTips(ccp.ReturnInfo);
  233. }
  234. else
  235. {
  236. MessageUtil.ShowTips(ccp.ReturnInfo);
  237. }
  238. }
  239. }
  240. catch
  241. {
  242. return;
  243. }
  244. }
  245. /// 查询方法
  246. /// <summary>
  247. /// 查询方法
  248. /// </summary>
  249. private void Query()
  250. {
  251. List<Tqnqc19Entity> listSource = EntityHelper.GetData<Tqnqc19Entity>(
  252. "com.steering.mes.cost.FrmTqnqc19.Query", new object[] { SgSignText.Text,SteelTypeCodeText.Text }, this.ob);
  253. tqnqc19EntityBindingSource.DataSource = listSource;
  254. GridHelper.RefreshAndAutoSize(ultraGrid1);
  255. }
  256. /// 保存方法
  257. /// <summary>
  258. /// 保存方法
  259. /// </summary>
  260. private void Save()
  261. {
  262. }
  263. #endregion
  264. #region
  265. #endregion
  266. }
  267. }