FrmImportSetOrder.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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.plan.order.model;
  14. using System.Globalization;
  15. using Core.Mes.Client.Comm;
  16. namespace Core.StlMes.Client.Plan.Order.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. int startRow = (int)ultraNumRowStart.Value;
  129. int endRow = (int)ultraNumRowEnd.Value;
  130. if (endRow - startRow < 0)
  131. {
  132. MessageUtil.ShowTips("没有任何行数据!");
  133. return;
  134. }
  135. string[,] head = ObjectToString(uC_EmbedExcelIntoWinFormNoDLL1.GetRangeArray_Value("A" + 1, "BZ" + 1));
  136. if (head == null)
  137. {
  138. return;
  139. }
  140. string[] colhead = new string[head.GetLength(1)];
  141. for (int i = 0; i < colhead.Length; i++)
  142. {
  143. colhead[i] = head[0, i];
  144. }
  145. #region 获取合同号等所在列
  146. int colNum = 0;
  147. int colOrderNo = -1;
  148. int colRollMonth = -1;
  149. int colOrderPk = -1;
  150. int colOrderfrom = -1;
  151. int colProduceSort = -1;
  152. if (!((IList)colhead).Contains("合同号"))
  153. {
  154. MessageUtil.ShowWarning("列“合同号”不存在!");
  155. return;
  156. }
  157. for (int i = head.GetLength(1) - 1; i >= 0; i--)
  158. {
  159. if (!head[0, i].Equals("") && colNum == 0)
  160. {
  161. colNum = i;
  162. }
  163. if (head[0, i].Trim().Equals("合同号"))
  164. {
  165. colOrderNo = i;
  166. }
  167. if (head[0, i].Trim().Equals("轧制月份"))
  168. {
  169. colRollMonth = i;
  170. }
  171. if (head[0, i].Trim().Equals("交货编码PK"))
  172. {
  173. colOrderPk = i;
  174. }
  175. if (head[0, i].Trim().Equals("来源"))
  176. {
  177. colOrderfrom = i;
  178. }
  179. if (head[0, i].Trim().Equals("项目"))
  180. {
  181. colProduceSort = i;
  182. }
  183. }
  184. #endregion
  185. ArrayList list = new ArrayList();
  186. string[,] arr = ObjectToString(uC_EmbedExcelIntoWinFormNoDLL1.GetRangeArray_Value(
  187. "A" + startRow, ExcelHelper.SeqToXlsCol[colNum + 1] + endRow));
  188. if (arr == null)
  189. {
  190. return;
  191. }
  192. for (int i = 0; i <= endRow - startRow; i++)
  193. {
  194. if (arr[i, colOrderNo].Equals(""))
  195. {
  196. MessageUtil.ShowTips("第" + (i + startRow).ToString() + "行,合同号为空!");
  197. return;
  198. }
  199. }
  200. WaitFromOpen();
  201. for (int i = 0; i < arr.GetLength(0); i++)
  202. {
  203. string orderNoseq = arr[i, colOrderNo].ToString();
  204. ArrayList param = new ArrayList();
  205. PlnSaleorderSetEntity entity = new PlnSaleorderSetEntity();
  206. if (!orderNoseq.Contains('/'))
  207. {
  208. WaitFromColse();
  209. MessageUtil.ShowTips("第" + (i + startRow).ToString() + "行,合同行号为空!");
  210. return;
  211. }
  212. if (colRollMonth != -1)
  213. {
  214. DateTime date = new DateTime();
  215. string rollMonth = arr[i, colRollMonth].ToString();
  216. if (DateTime.TryParseExact(rollMonth, "yyyyMM", null, DateTimeStyles.None, out date))
  217. {
  218. entity.RollMonth = date.ToString("yyyy-MM");
  219. }
  220. }
  221. entity.IfSetMonth = "0";
  222. entity.OrderNoSeq = orderNoseq;
  223. if (colOrderPk != -1)
  224. {
  225. entity.OrdLnDlyPk = arr[i, colOrderPk].ToString();
  226. }
  227. if (colOrderfrom != -1)
  228. {
  229. entity.Orderfrom = arr[i, colOrderfrom].ToString();
  230. }
  231. if (colProduceSort != -1)
  232. {
  233. entity.ProduceSort = arr[i, colProduceSort].ToString();
  234. }
  235. list.Add(entity);
  236. }
  237. int succed = ServerHelper.SetData("com.steering.pss.plan.order.CoreOrderStatusSet.saveOrderSetlog",
  238. new object[] { list }, this.ob);
  239. WaitFromColse();
  240. if (succed > 0)
  241. {
  242. MessageUtil.ShowTips("导入成功!");
  243. }
  244. else
  245. {
  246. MessageUtil.ShowTips("导入失败!");
  247. }
  248. }
  249. catch (Exception ex)
  250. {
  251. WaitFromColse();
  252. if (ex is MESException)
  253. {
  254. }
  255. else
  256. {
  257. MessageBox.Show(ex.Message);
  258. }
  259. }
  260. }
  261. /// <summary>
  262. /// 打开excel文件
  263. /// </summary>
  264. private void doOpen()
  265. {
  266. try
  267. {
  268. OpenFileDialog dialog = new OpenFileDialog();
  269. uC_EmbedExcelIntoWinFormNoDLL1.AppExcel_Exit();
  270. if (dialog.ShowDialog() == DialogResult.OK)
  271. {
  272. ModelPatch = dialog.FileName;
  273. if (!System.IO.File.Exists(ModelPatch))//检察文件是否存在
  274. {
  275. return;
  276. }
  277. try
  278. {
  279. System.IO.File.Move(ModelPatch, ModelPatch);
  280. }
  281. catch
  282. {
  283. MessageUtil.ShowTips("文件已经被打开,请先关闭!");
  284. return;
  285. }
  286. uC_EmbedExcelIntoWinFormNoDLL1.AppExcel_Open(ModelPatch, true);
  287. this.ultraNumRowEnd.Value = getExcelRowsCount();
  288. }
  289. }
  290. catch (Exception ex)
  291. {
  292. MessageBox.Show(ex.Message);
  293. }
  294. }
  295. /// <summary>
  296. /// 关闭
  297. /// </summary>
  298. private void doClose()
  299. {
  300. uC_EmbedExcelIntoWinFormNoDLL1.AppExcel_Exit();
  301. }
  302. /// <summary>
  303. /// object二维数组转string二维数组
  304. /// </summary>
  305. /// <param name="obj"></param>
  306. /// <returns></returns>
  307. private string[,] ObjectToString(object[,] obj)
  308. {
  309. int rows = obj.GetLength(0); //获取m_objRangeArrayValue的行数
  310. int columns = obj.GetLength(1); //获取m_objRangeArrayValue的列数
  311. object[,] param = new object[rows, columns]; //转化为起始为0的数组
  312. Array.Copy(obj, param, rows * columns); //临时结果,学习用
  313. string[,] str = new string[param.GetLength(0), param.GetLength(1)];
  314. for (int i = 0; i < str.GetLength(0); i++)
  315. {
  316. for (int j = 0; j < str.GetLength(1); j++)
  317. {
  318. if (param[i, j] == null)
  319. {
  320. str[i, j] = "";
  321. }
  322. else
  323. {
  324. str[i, j] = param[i, j].ToString();
  325. }
  326. }
  327. }
  328. return str;
  329. }
  330. /// <summary>
  331. /// 等待窗口
  332. /// </summary>
  333. private void WaitFromOpen()
  334. {
  335. this.Cursor = Cursors.WaitCursor; //控制鼠标的样式为等待
  336. if (Constant.WaitingForm == null)
  337. {
  338. Constant.WaitingForm = new WaitingForm();
  339. }
  340. Constant.WaitingForm.ShowToUser = true;
  341. Constant.WaitingForm.Show();
  342. Constant.WaitingForm.Update();
  343. }
  344. /// <summary>
  345. /// 关闭等待
  346. /// </summary>
  347. private void WaitFromColse()
  348. {
  349. this.Cursor = Cursors.Default;
  350. Constant.WaitingForm.ShowToUser = false;
  351. Constant.WaitingForm.Close();
  352. Constant.WaitingForm = null;
  353. }
  354. private void FrmImportSetOrder_FormClosed(object sender, FormClosedEventArgs e)
  355. {
  356. uC_EmbedExcelIntoWinFormNoDLL1.AppExcel_Exit();
  357. }
  358. }
  359. }