FrmImportSetOrder.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Collections;
  10. using CoreFS.CA06;
  11. using Core.Mes.Client.Comm.Tool;
  12. using Core.Mes.Client.Comm.Server;
  13. using com.steering.pss.plnsaleord.order.model;
  14. using System.Globalization;
  15. using Core.Mes.Client.Comm;
  16. namespace Core.StlMes.Client.PlnSaleOrd.PopupWindow
  17. {
  18. public partial class FrmImportSetOrder : FrmBase
  19. {
  20. /// <summary>
  21. /// 模板路径
  22. /// </summary>
  23. string modelPatch = "";
  24. /// <summary>
  25. /// 模板路径
  26. /// </summary>
  27. public string ModelPatch
  28. {
  29. get { return modelPatch; }
  30. set { modelPatch = value; }
  31. }
  32. public FrmImportSetOrder()
  33. {
  34. InitializeComponent();
  35. }
  36. public FrmImportSetOrder(OpeBase openbase)
  37. {
  38. this.ob = openbase;
  39. InitializeComponent();
  40. }
  41. private void FrmImportSetOrder_Load(object sender, EventArgs e)
  42. {
  43. Init();
  44. }
  45. /// <summary>
  46. /// 初始化
  47. /// </summary>
  48. private void Init()
  49. {
  50. ultraNumRowStart.Value = 2;
  51. ultraNumRowEnd.Value = 2;
  52. if (!System.IO.File.Exists(ModelPatch))//检察文件是否存在
  53. {
  54. return;
  55. }
  56. try
  57. {
  58. System.IO.File.Move(ModelPatch, ModelPatch);
  59. }
  60. catch
  61. {
  62. MessageUtil.ShowTips("文件已经被打开,请先关闭!");
  63. return;
  64. }
  65. uC_EmbedExcelIntoWinFormNoDLL1.AppExcel_Open(ModelPatch, true);
  66. this.ultraNumRowEnd.Value = getExcelRowsCount();
  67. }
  68. /// <summary>
  69. /// 获取excl的行数
  70. /// </summary>
  71. private int getExcelRowsCount()
  72. {
  73. //获取行数(上限5000)
  74. int colOrderNo = 0;
  75. int j = 4999;
  76. string[,] arr = null;
  77. string[,] head = ObjectToString(uC_EmbedExcelIntoWinFormNoDLL1.GetRangeArray_Value("A" + 1, "BZ" + 1));
  78. if (head == null)
  79. {
  80. return 1;
  81. }
  82. for (int i = 0; i < head.GetLength(1); i++)
  83. {
  84. if (head[0, i].Trim().Equals("合同号"))
  85. {
  86. colOrderNo = i;
  87. break;
  88. }
  89. }
  90. arr = ObjectToString(uC_EmbedExcelIntoWinFormNoDLL1.GetRangeArray_Value(
  91. ExcelHelper.SeqToXlsCol[colOrderNo + 1] + 2,
  92. ExcelHelper.SeqToXlsCol[colOrderNo + 1] + 5001));
  93. if (arr == null)
  94. {
  95. return 1;
  96. }
  97. for (j = 4999; j >= 0; j--)
  98. {
  99. if (!arr[j, 0].Equals(""))
  100. {
  101. break;
  102. }
  103. }
  104. return j + 2;
  105. }
  106. private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
  107. {
  108. switch (e.Tool.Key)
  109. {
  110. case "Save":
  111. doSave();
  112. break;
  113. case "Open":
  114. doOpen();
  115. break;
  116. case "Close":
  117. doClose();
  118. break;
  119. }
  120. }
  121. /// <summary>
  122. /// 保存
  123. /// </summary>
  124. private void doSave()
  125. {
  126. try
  127. {
  128. ArrayList messageErr = new ArrayList();
  129. int startRow = (int)ultraNumRowStart.Value;
  130. int endRow = (int)ultraNumRowEnd.Value;
  131. if (endRow - startRow < 0)
  132. {
  133. MessageUtil.ShowTips("没有任何行数据!");
  134. return;
  135. }
  136. string[,] head = ObjectToString(uC_EmbedExcelIntoWinFormNoDLL1.GetRangeArray_Value("A" + 1, "BZ" + 1));
  137. if (head == null)
  138. {
  139. return;
  140. }
  141. string[] colhead = new string[head.GetLength(1)];
  142. for (int i = 0; i < colhead.Length; i++)
  143. {
  144. colhead[i] = head[0, i];
  145. }
  146. #region 获取合同号等所在列
  147. int colNum = 0;
  148. int colRollMonth = -1;
  149. int colOrderPk = -1;
  150. int colCheckMoth = -1;
  151. int colPriority = -1;
  152. int colPriorityMemo = -1;
  153. for (int i = head.GetLength(1) - 1; i >= 0; i--)
  154. {
  155. if (!head[0, i].Equals("") && colNum == 0)
  156. {
  157. colNum = i;
  158. }
  159. if (head[0, i].Trim().Equals("轧制月份"))
  160. {
  161. colRollMonth = i;
  162. }
  163. if (head[0, i].Trim().Equals("交货编码PK"))
  164. {
  165. colOrderPk = i;
  166. }
  167. if (head[0, i].Trim().Equals("考核年月"))
  168. {
  169. colCheckMoth = i;
  170. }
  171. if (head[0, i].Trim().Equals("合同紧急度"))
  172. {
  173. colPriority = i;
  174. }
  175. if (head[0, i].Trim().Equals("紧急度备注"))
  176. {
  177. colPriorityMemo = i;
  178. }
  179. }
  180. if (colOrderPk == -1)
  181. {
  182. MessageUtil.ShowError("未找到交货编码PK的列");
  183. return;
  184. }
  185. #endregion
  186. ArrayList list = new ArrayList();
  187. string[,] arr = ObjectToString(uC_EmbedExcelIntoWinFormNoDLL1.GetRangeArray_Value(
  188. "A" + startRow, ExcelHelper.SeqToXlsCol[colNum + 1] + endRow));
  189. if (arr == null)
  190. {
  191. return;
  192. }
  193. WaitFromOpen();
  194. DataTable tableBaseInfo = ServerHelper.GetData("com.steering.pss.plnsaleord.order.CorePlnSaleOrder.queryBaseinfoAll",new object[] { }, this.ob);
  195. for (int i = 0; i < arr.GetLength(0); i++)
  196. {
  197. ArrayList param = new ArrayList();
  198. PlnSaleordSetEntity entity = new PlnSaleordSetEntity();
  199. string orderPk = arr[i, colOrderPk].Trim();
  200. string ordLnDlyPk = "";
  201. string plnDivideId = "";
  202. if (orderPk.Equals(""))
  203. {
  204. messageErr.Add("第" + (i + startRow).ToString() + "条数据PK码为空");
  205. continue;
  206. }
  207. if (orderPk.Contains('-'))
  208. {
  209. int lenPk = orderPk.LastIndexOf('-');
  210. ordLnDlyPk = orderPk.Substring(0, lenPk);
  211. plnDivideId = orderPk.Substring(lenPk + 1, orderPk.Length - lenPk - 1);
  212. }
  213. else
  214. {
  215. ordLnDlyPk = orderPk;
  216. }
  217. if (ordLnDlyPk.Equals(""))
  218. {
  219. messageErr.Add("第" + (i + startRow).ToString() + "条数据PK码有误。");
  220. continue;
  221. }
  222. if (colRollMonth != -1)
  223. {
  224. DateTime date = new DateTime();
  225. string rollMonth = arr[i, colRollMonth].ToString();
  226. if (DateTime.TryParseExact(rollMonth, "yyyyMM", null, DateTimeStyles.None, out date))
  227. {
  228. entity.RollMonth = date.ToString("yyyy-MM");
  229. }
  230. }
  231. if(colCheckMoth != -1)
  232. {
  233. entity.CheckMoth = arr[i, colCheckMoth].Trim();
  234. }
  235. if (colPriority != -1)
  236. {
  237. tableBaseInfo.DefaultView.RowFilter = "SORTCODE='2006' and BASENAME='" + arr[i, colPriority].Trim() + "'";
  238. DataTable dtPrior = tableBaseInfo.DefaultView.ToTable();
  239. if (dtPrior != null)
  240. {
  241. entity.Priority = dtPrior.Rows[0]["BASECODE"].ToString2();
  242. }
  243. }
  244. if (colPriorityMemo != -1)
  245. {
  246. entity.PriorityMemo = arr[i, colPriorityMemo].Trim();
  247. }
  248. entity.OrdLnDlyPk = ordLnDlyPk;
  249. entity.PlnDivideId = plnDivideId;
  250. list.Add(entity);
  251. }
  252. int succed = ServerHelper.SetData("com.steering.pss.plnsaleord.order.CoreOrderStatusSet.saveOrderSetlog",
  253. new object[] { list }, this.ob);
  254. WaitFromColse();
  255. if (succed > 0)
  256. {
  257. if (messageErr.Count == 0)
  258. {
  259. MessageUtil.ShowTips("导入成功,共" + list.Count + "条。");
  260. }
  261. else
  262. {
  263. MessageUtil.ShowTips(list.Count + "条导入成功," + messageErr.Count + "条导入失败。\n" + messageErr[0]);
  264. }
  265. }
  266. else
  267. {
  268. MessageUtil.ShowTips("导入失败,共" + list.Count + "条。");
  269. }
  270. }
  271. catch (Exception ex)
  272. {
  273. WaitFromColse();
  274. if (!(ex is MESException))
  275. {
  276. MessageUtil.ShowError(ex.Message);
  277. }
  278. }
  279. }
  280. /// <summary>
  281. /// 打开excel文件
  282. /// </summary>
  283. private void doOpen()
  284. {
  285. try
  286. {
  287. OpenFileDialog dialog = new OpenFileDialog();
  288. uC_EmbedExcelIntoWinFormNoDLL1.AppExcel_Exit();
  289. if (dialog.ShowDialog() == DialogResult.OK)
  290. {
  291. ModelPatch = dialog.FileName;
  292. if (!System.IO.File.Exists(ModelPatch))//检察文件是否存在
  293. {
  294. return;
  295. }
  296. try
  297. {
  298. System.IO.File.Move(ModelPatch, ModelPatch);
  299. }
  300. catch
  301. {
  302. MessageUtil.ShowTips("文件已经被打开,请先关闭!");
  303. return;
  304. }
  305. uC_EmbedExcelIntoWinFormNoDLL1.AppExcel_Open(ModelPatch, true);
  306. this.ultraNumRowEnd.Value = getExcelRowsCount();
  307. }
  308. }
  309. catch (Exception ex)
  310. {
  311. MessageBox.Show(ex.Message);
  312. }
  313. }
  314. /// <summary>
  315. /// 关闭
  316. /// </summary>
  317. private void doClose()
  318. {
  319. uC_EmbedExcelIntoWinFormNoDLL1.AppExcel_Exit();
  320. }
  321. /// <summary>
  322. /// object二维数组转string二维数组
  323. /// </summary>
  324. /// <param name="obj"></param>
  325. /// <returns></returns>
  326. private string[,] ObjectToString(object[,] obj)
  327. {
  328. int rows = obj.GetLength(0); //获取m_objRangeArrayValue的行数
  329. int columns = obj.GetLength(1); //获取m_objRangeArrayValue的列数
  330. object[,] param = new object[rows, columns]; //转化为起始为0的数组
  331. Array.Copy(obj, param, rows * columns); //临时结果,学习用
  332. string[,] str = new string[param.GetLength(0), param.GetLength(1)];
  333. for (int i = 0; i < str.GetLength(0); i++)
  334. {
  335. for (int j = 0; j < str.GetLength(1); j++)
  336. {
  337. if (param[i, j] == null)
  338. {
  339. str[i, j] = "";
  340. }
  341. else
  342. {
  343. str[i, j] = param[i, j].ToString();
  344. }
  345. }
  346. }
  347. return str;
  348. }
  349. /// <summary>
  350. /// 等待窗口
  351. /// </summary>
  352. private void WaitFromOpen()
  353. {
  354. this.Cursor = Cursors.WaitCursor; //控制鼠标的样式为等待
  355. if (Constant.WaitingForm == null)
  356. {
  357. Constant.WaitingForm = new WaitingForm();
  358. }
  359. Constant.WaitingForm.ShowToUser = true;
  360. Constant.WaitingForm.Show();
  361. Constant.WaitingForm.Update();
  362. }
  363. /// <summary>
  364. /// 关闭等待
  365. /// </summary>
  366. private void WaitFromColse()
  367. {
  368. this.Cursor = Cursors.Default;
  369. Constant.WaitingForm.ShowToUser = false;
  370. Constant.WaitingForm.Close();
  371. Constant.WaitingForm = null;
  372. }
  373. private void FrmImportSetOrder_FormClosed(object sender, FormClosedEventArgs e)
  374. {
  375. uC_EmbedExcelIntoWinFormNoDLL1.AppExcel_Exit();
  376. }
  377. }
  378. }