Jgxprice.cs 9.7 KB

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