Modecoefficient.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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 Modecoefficient : FrmBase
  23. {
  24. #region 定义变量
  25. public Modecoefficient()
  26. {
  27. InitializeComponent();
  28. EntityHelper.ShowGridCaption<ModecoefficientEntity>(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. ModecoefficientEntity modecoefficientEntity = (ModecoefficientEntity)uRow.ListObject;
  65. string ModecoefficientEntity = JSONFormat.Format(modecoefficientEntity);
  66. parm.Add(ModecoefficientEntity);
  67. }
  68. CoreClientParam ccp = new CoreClientParam();
  69. ccp.ServerName = "com.steering.mes.cost.FrmModecoefficient";
  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<ModecoefficientEntity> 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.FrmModecoefficient";
  108. ccp.MethodName = "DoAddModecoefficient";
  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<ModecoefficientEntity> ReadExcelToSingnhjxhEntity(string fileName)
  124. {
  125. //定义要返回的datatable对象
  126. List<ModecoefficientEntity> modecoefficientEntitys = new List<ModecoefficientEntity>();
  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. ModecoefficientEntity entity = new ModecoefficientEntity();
  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 ModelDesc = GetCellValue(row.Cells[0]);
  157. string Upsetting = GetCellValue(row.Cells[1]);
  158. string Testing = GetCellValue(row.Cells[2]);
  159. string Threading = GetCellValue(row.Cells[3]);
  160. string Phosphating = GetCellValue(row.Cells[5]);
  161. string Screwing = GetCellValue(row.Cells[6]);
  162. string Hydraulic = GetCellValue(row.Cells[7]);
  163. string Pathway = GetCellValue(row.Cells[8]);
  164. string Lengthweighing = GetCellValue(row.Cells[9]);
  165. string Logopainting = GetCellValue(row.Cells[10]);
  166. string Wrap = GetCellValue(row.Cells[11]);
  167. string Baling = GetCellValue(row.Cells[12]);
  168. decimal Couplings;
  169. decimal Threadcoefficient;
  170. decimal.TryParse(GetCellValue(row.Cells[13]), out Couplings);
  171. decimal.TryParse(GetCellValue(row.Cells[4]), out Threadcoefficient);
  172. if (Couplings == null)
  173. {
  174. throw new Exception("接箍金额为空");
  175. }
  176. if(Threadcoefficient == null){
  177. throw new Exception("系数为空");
  178. }
  179. entity.ModelDesc = ModelDesc;
  180. entity.Upsetting = Upsetting;
  181. entity.Testing = Testing;
  182. entity.Threading = Threading;
  183. entity.Phosphating = Phosphating;
  184. entity.Screwing = Screwing;
  185. entity.Hydraulic = Hydraulic;
  186. entity.Pathway = Pathway;
  187. entity.Lengthweighing = Lengthweighing;
  188. entity.Logopainting = Logopainting;
  189. entity.Wrap = Wrap;
  190. entity.Baling = Baling;
  191. entity.Couplings = Couplings;
  192. entity.Threadcoefficient = Threadcoefficient;
  193. modecoefficientEntitys.Add(entity);
  194. }
  195. }
  196. }
  197. }
  198. return modecoefficientEntitys;
  199. }
  200. catch (Exception ex)
  201. {
  202. MessageBox.Show("EXCEL格式错误:" + ex.Message);
  203. return null;
  204. }
  205. }
  206. private string GetCellValue(ICell cell)
  207. {
  208. string value = "";
  209. switch (cell.CellType)
  210. {
  211. case CellType.Blank:
  212. value = "";
  213. break;
  214. case CellType.Numeric:
  215. short format = cell.CellStyle.DataFormat;
  216. value = cell.NumericCellValue.ToString2();
  217. break;
  218. case CellType.String:
  219. value = cell.StringCellValue;
  220. break;
  221. }
  222. return value;
  223. }
  224. /// <summary>
  225. /// 保存
  226. /// </summary>
  227. private void doSave()
  228. {
  229. try
  230. {
  231. this.ultraGrid1.UpdateData();
  232. IQueryable<UltraGridRow> checkMagRows = this.ultraGrid1.Rows.AsQueryable().Where(" XUANZE = 'True'");
  233. if (checkMagRows.Count() == 0)
  234. {
  235. MessageUtil.ShowTips("请选择需要修改的数据!");
  236. return;
  237. }
  238. ArrayList parm = new ArrayList();
  239. foreach (UltraGridRow uRow in checkMagRows)
  240. {
  241. ModecoefficientEntity entity = (ModecoefficientEntity)uRow.ListObject;
  242. // entity.RecRevisor = UserInfo.GetUserName();
  243. string JgxpriceEntity = JSONFormat.Format(entity);
  244. parm.Add(JgxpriceEntity);
  245. }
  246. CoreClientParam ccp = new CoreClientParam();
  247. ccp.ServerName = "com.steering.mes.cost.FrmModecoefficient";
  248. ccp.MethodName = "doSave";
  249. ccp.ServerParams = new object[] { parm };
  250. ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  251. if (ccp.ReturnCode != -1)
  252. {
  253. if (ccp.ReturnInfo.Equals("操作成功"))
  254. {
  255. // DoQueryInList();
  256. Query();
  257. MessageUtil.ShowTips(ccp.ReturnInfo);
  258. }
  259. else
  260. {
  261. MessageUtil.ShowTips(ccp.ReturnInfo);
  262. }
  263. }
  264. }
  265. catch
  266. {
  267. return;
  268. }
  269. }
  270. /// 查询方法
  271. /// <summary>
  272. /// 查询方法
  273. /// </summary>
  274. private void Query()
  275. {
  276. List<ModecoefficientEntity> listSource = EntityHelper.GetData<ModecoefficientEntity>(
  277. "com.steering.mes.cost.FrmModecoefficient.Query", new object[] { cicText.Text }, this.ob);
  278. modecoefficientEntityBindingSource.DataSource = listSource;
  279. GridHelper.RefreshAndAutoSize(ultraGrid1);
  280. }
  281. /// 保存方法
  282. /// <summary>
  283. /// 保存方法
  284. /// </summary>
  285. private void Save()
  286. {
  287. }
  288. #endregion
  289. #region
  290. #endregion
  291. }
  292. }