FrmTqnqc12.cs 11 KB

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