FrmTqnqc21.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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 com.steering.mes.mcp.entity;
  13. using Core.Mes.Client.Comm.Control;
  14. using Core.Mes.Client.Comm.Format;
  15. using Core.Mes.Client.Comm.Tool;
  16. using CoreFS.CA06;
  17. using Infragistics.Win;
  18. using Infragistics.Win.UltraWinGrid;
  19. using NPOI.SS.UserModel;
  20. using Core.StlMes.Client.ZGMil.Entity;
  21. using Core.Mes.Client.Comm.Server;
  22. using Infragistics.Win.UltraWinEditors;
  23. namespace Core.StlMes.Client.ZGMil.Cost
  24. {
  25. public partial class FrmTqnqc21 : FrmBase
  26. {
  27. public FrmTqnqc21()
  28. {
  29. InitializeComponent();
  30. }
  31. private void FrmTqnqc14_Load(object sender, EventArgs e)
  32. {
  33. EntityHelper.ShowGridCaption<Tqnqc21Entity>(ultraGrid1.DisplayLayout.Bands[0]);
  34. Query();
  35. }
  36. public override void ToolBar_Click(object sender, string ToolbarKey)
  37. {
  38. switch (ToolbarKey)
  39. {
  40. case "DoQuery":
  41. Query();
  42. break;
  43. case "doImport":
  44. Import();
  45. break;
  46. case "doSave":
  47. break;
  48. case "doUpdate":
  49. Update();
  50. break;
  51. case "doDelete":
  52. delete();
  53. break;
  54. case "Close":
  55. Close();
  56. break;
  57. }
  58. }
  59. //导入
  60. private void Import()
  61. {
  62. List<Tqnqc21Entity> list = null;
  63. var openFileDialog = new OpenFileDialog
  64. {
  65. Filter = "加工工序基础信息|*.xls;*.xlsx"
  66. };
  67. if (openFileDialog.ShowDialog() == DialogResult.OK)
  68. {
  69. list = ReadExcelToRtdTqnqc21Entity(openFileDialog.FileName);
  70. }
  71. if (list == null) return;
  72. if (list.Count <= 0)
  73. {
  74. MessageBox.Show("Excel无数据");
  75. return;
  76. }
  77. string userName = UserInfo.GetUserName();
  78. var ccp = new CoreClientParam();
  79. ccp.ServerName = "com.steering.mes.cost.FrmTqnqc21";
  80. ccp.MethodName = "DoAddTqnqc21";
  81. ccp.ServerParams = new object[]
  82. {
  83. list.Select(JSONFormat.Format).ToList(),
  84. userName
  85. };
  86. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  87. if (ccp.ReturnCode != -1)
  88. {
  89. MessageUtil.ShowTips(ccp.ReturnInfo);
  90. if (ccp.ReturnInfo.Equals("新增成功"))
  91. {
  92. Query();
  93. }
  94. }
  95. }
  96. private void delete()
  97. {
  98. this.ultraGrid1.UpdateData();
  99. IQueryable<UltraGridRow> checkMagRows = this.ultraGrid1.Rows.AsQueryable().Where(" CHK = 'True'");
  100. if (checkMagRows.Count() == 0)
  101. {
  102. MessageUtil.ShowTips("请选择需要删除的数据!");
  103. return;
  104. }
  105. ArrayList parm = new ArrayList();
  106. foreach (UltraGridRow uRow in checkMagRows)
  107. {
  108. Tqnqc21Entity Tqnqc21Result = (Tqnqc21Entity)uRow.ListObject;
  109. if (Tqnqc21Result.WholeBacklogCode.Equals("") || Tqnqc21Result.WholeBacklogCode == null)
  110. {
  111. MessageUtil.ShowTips("编号为空!");
  112. }
  113. string Tqnqc17Results = JSONFormat.Format(Tqnqc21Result);
  114. parm.Add(Tqnqc17Results);
  115. }
  116. CoreClientParam ccp = new CoreClientParam();
  117. ccp.ServerName = "com.steering.mes.cost.FrmTqnqc21";
  118. ccp.MethodName = "doDelete";
  119. ccp.ServerParams = new object[] { parm };
  120. ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  121. if (ccp.ReturnCode != -1)
  122. {
  123. if (ccp.ReturnInfo.Equals("操作成功"))
  124. {
  125. // DoQueryInList();
  126. Query();
  127. MessageUtil.ShowTips(ccp.ReturnInfo);
  128. }
  129. else
  130. {
  131. MessageUtil.ShowTips(ccp.ReturnInfo);
  132. }
  133. }
  134. }
  135. private void Update()
  136. {
  137. this.ultraGrid1.UpdateData();
  138. IQueryable<UltraGridRow> checkMagRows = this.ultraGrid1.Rows.AsQueryable().Where(" CHK = 'True'");
  139. if (checkMagRows.Count() == 0)
  140. {
  141. MessageUtil.ShowTips("请选择需要修改的数据!");
  142. return;
  143. }
  144. ArrayList parm = new ArrayList();
  145. foreach (UltraGridRow uRow in checkMagRows)
  146. {
  147. Tqnqc21Entity entity = (Tqnqc21Entity)uRow.ListObject;
  148. entity.RecRevisor = UserInfo.GetUserName();
  149. string Tqnqc21ResultTity = JSONFormat.Format(entity);
  150. parm.Add(Tqnqc21ResultTity);
  151. }
  152. CoreClientParam ccp = new CoreClientParam();
  153. ccp.ServerName = "com.steering.mes.cost.FrmTqnqc21";
  154. ccp.MethodName = "doSave";
  155. ccp.ServerParams = new object[] { parm };
  156. ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  157. if (ccp.ReturnCode != -1)
  158. {
  159. if (ccp.ReturnInfo.Equals("操作成功"))
  160. {
  161. // DoQueryInList();
  162. Query();
  163. MessageUtil.ShowTips(ccp.ReturnInfo);
  164. }
  165. else
  166. {
  167. MessageUtil.ShowTips(ccp.ReturnInfo);
  168. }
  169. }
  170. }
  171. private void Query()
  172. {
  173. string cb = "";
  174. string jz = "";
  175. if (chk_cb.Checked == true)
  176. {
  177. cb = text_name.Text;
  178. }
  179. List<Tqnqc21Entity> listSource = EntityHelper.GetData<Tqnqc21Entity>(
  180. "com.steering.mes.cost.FrmTqnqc21.doQuery", new object[] { cb }, this.ob);
  181. tqnqc21EntityBindingSource.DataSource = listSource;
  182. // GridHelper.RefreshAndAutoSize(ultraGrid1);
  183. }
  184. public List<Tqnqc21Entity> ReadExcelToRtdTqnqc21Entity(string fileName)
  185. {
  186. //定义要返回的datatable对象
  187. List<Tqnqc21Entity> Tqnqc21Entitys = new List<Tqnqc21Entity>();
  188. try
  189. {
  190. if (!File.Exists(fileName))
  191. {
  192. return null;
  193. }
  194. //根据指定路径读取文件
  195. using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
  196. {
  197. //根据文件流创建excel数据结构
  198. NPOI.SS.UserModel.IWorkbook workbook = NPOI.SS.UserModel.WorkbookFactory.Create(fs);
  199. //IWorkbook workbook = new HSSFWorkbook(fs);
  200. for (int k = 0; k < workbook.NumberOfSheets; k++)
  201. {
  202. NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(k);
  203. if (sheet != null)
  204. {
  205. //最后一列的标号
  206. int rowCount = sheet.LastRowNum;
  207. for (int i = 1; i <= rowCount; ++i)
  208. {
  209. Tqnqc21Entity entity = new Tqnqc21Entity();
  210. NPOI.SS.UserModel.IRow row = sheet.GetRow(i);
  211. if (row == null) continue; //没有数据的行默认是null       
  212. if (row.Cells.Count < 4)
  213. {
  214. throw new Exception("无足够列");
  215. }
  216. string wholeBacklog = GetCellValue(row.Cells[0]);
  217. string fcbxMc = GetCellValue(row.Cells[1]);
  218. string wholeBacklogCode = GetCellValue(row.Cells[3]);
  219. decimal unitPrice;
  220. decimal.TryParse(GetCellValue(row.Cells[2]), out unitPrice);
  221. entity.WholeBacklog = wholeBacklog;
  222. entity.FcbxMc = fcbxMc;
  223. entity.WholeBacklogCode = wholeBacklogCode;
  224. entity.UnitPrice = unitPrice;
  225. entity.RecCreator = UserInfo.GetUserName();
  226. Tqnqc21Entitys.Add(entity);
  227. }
  228. }
  229. }
  230. }
  231. return Tqnqc21Entitys;
  232. }
  233. catch (Exception ex)
  234. {
  235. MessageBox.Show("EXCEL格式错误:" + ex.Message);
  236. return null;
  237. }
  238. }
  239. private string GetCellValue(ICell cell)
  240. {
  241. string value = "";
  242. switch (cell.CellType)
  243. {
  244. case CellType.Blank:
  245. value = "";
  246. break;
  247. case CellType.Numeric:
  248. short format = cell.CellStyle.DataFormat;
  249. value = cell.NumericCellValue.ToString2();
  250. break;
  251. case CellType.String:
  252. value = cell.StringCellValue;
  253. break;
  254. }
  255. return value;
  256. }
  257. public static DataTable GetComBaseInfo(string sortCode, OpeBase ob)
  258. {
  259. return ServerHelper.GetData("com.steering.mes.signature.FrmMilControlLog.getComBaseInfo", new object[] { sortCode }, ob);
  260. }
  261. public static void SetComboItemHeight(UltraComboEditor cmb)
  262. {
  263. foreach (ValueListItem item in cmb.Items)
  264. {
  265. if (System.Text.RegularExpressions.Regex.IsMatch(item.DisplayText, @"[\u4e00-\u9fa5]+"))
  266. {
  267. item.Appearance.FontData.SizeInPoints = 9.0F;
  268. }
  269. else
  270. {
  271. item.Appearance.FontData.SizeInPoints = 10.5F;
  272. }
  273. }
  274. }
  275. }
  276. }