| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Collections;
- using CoreFS.CA06;
- using Core.Mes.Client.Comm.Tool;
- using Core.Mes.Client.Comm.Server;
- using com.steering.pss.plnsaleord.order.model;
- using System.Globalization;
- using Core.Mes.Client.Comm;
- namespace Core.StlMes.Client.PlnSaleOrd.PopupWindow
- {
- public partial class FrmImportSetOrder : FrmBase
- {
- /// <summary>
- /// 模板路径
- /// </summary>
- string modelPatch = "";
- /// <summary>
- /// 模板路径
- /// </summary>
- public string ModelPatch
- {
- get { return modelPatch; }
- set { modelPatch = value; }
- }
- public FrmImportSetOrder()
- {
- InitializeComponent();
- }
- public FrmImportSetOrder(OpeBase openbase)
- {
- this.ob = openbase;
- InitializeComponent();
- }
- private void FrmImportSetOrder_Load(object sender, EventArgs e)
- {
- Init();
- }
- /// <summary>
- /// 初始化
- /// </summary>
- private void Init()
- {
- ultraNumRowStart.Value = 2;
- ultraNumRowEnd.Value = 2;
- if (!System.IO.File.Exists(ModelPatch))//检察文件是否存在
- {
- return;
- }
- try
- {
- System.IO.File.Move(ModelPatch, ModelPatch);
- }
- catch
- {
- MessageUtil.ShowTips("文件已经被打开,请先关闭!");
- return;
- }
- uC_EmbedExcelIntoWinFormNoDLL1.AppExcel_Open(ModelPatch, true);
- this.ultraNumRowEnd.Value = getExcelRowsCount();
- }
- /// <summary>
- /// 获取excl的行数
- /// </summary>
- private int getExcelRowsCount()
- {
- //获取行数(上限5000)
- int colOrderNo = 0;
- int j = 4999;
- string[,] arr = null;
- string[,] head = ObjectToString(uC_EmbedExcelIntoWinFormNoDLL1.GetRangeArray_Value("A" + 1, "BZ" + 1));
- if (head == null)
- {
- return 1;
- }
- for (int i = 0; i < head.GetLength(1); i++)
- {
- if (head[0, i].Trim().Equals("合同号"))
- {
- colOrderNo = i;
- break;
- }
- }
- arr = ObjectToString(uC_EmbedExcelIntoWinFormNoDLL1.GetRangeArray_Value(
- ExcelHelper.SeqToXlsCol[colOrderNo + 1] + 2,
- ExcelHelper.SeqToXlsCol[colOrderNo + 1] + 5001));
- if (arr == null)
- {
- return 1;
- }
- for (j = 4999; j >= 0; j--)
- {
- if (!arr[j, 0].Equals(""))
- {
- break;
- }
- }
- return j + 2;
- }
- private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
- {
- switch (e.Tool.Key)
- {
- case "Save":
- doSave();
- break;
- case "Open":
- doOpen();
- break;
- case "Close":
- doClose();
- break;
- }
- }
- /// <summary>
- /// 保存
- /// </summary>
- private void doSave()
- {
- try
- {
- ArrayList messageErr = new ArrayList();
- int startRow = (int)ultraNumRowStart.Value;
- int endRow = (int)ultraNumRowEnd.Value;
- if (endRow - startRow < 0)
- {
- MessageUtil.ShowTips("没有任何行数据!");
- return;
- }
- string[,] head = ObjectToString(uC_EmbedExcelIntoWinFormNoDLL1.GetRangeArray_Value("A" + 1, "BZ" + 1));
- if (head == null)
- {
- return;
- }
- string[] colhead = new string[head.GetLength(1)];
- for (int i = 0; i < colhead.Length; i++)
- {
- colhead[i] = head[0, i];
- }
- #region 获取合同号等所在列
- int colNum = 0;
- int colRollMonth = -1;
- int colOrderPk = -1;
- int colCheckMoth = -1;
- int colPriority = -1;
- int colPriorityMemo = -1;
- for (int i = head.GetLength(1) - 1; i >= 0; i--)
- {
- if (!head[0, i].Equals("") && colNum == 0)
- {
- colNum = i;
- }
- if (head[0, i].Trim().Equals("轧制月份"))
- {
- colRollMonth = i;
- }
- if (head[0, i].Trim().Equals("交货编码PK"))
- {
- colOrderPk = i;
- }
- if (head[0, i].Trim().Equals("考核年月"))
- {
- colCheckMoth = i;
- }
- if (head[0, i].Trim().Equals("合同紧急度"))
- {
- colPriority = i;
- }
- if (head[0, i].Trim().Equals("紧急度备注"))
- {
- colPriorityMemo = i;
- }
- }
- if (colOrderPk == -1)
- {
- MessageUtil.ShowError("未找到交货编码PK的列");
- return;
- }
- #endregion
- ArrayList list = new ArrayList();
- string[,] arr = ObjectToString(uC_EmbedExcelIntoWinFormNoDLL1.GetRangeArray_Value(
- "A" + startRow, ExcelHelper.SeqToXlsCol[colNum + 1] + endRow));
- if (arr == null)
- {
- return;
- }
- WaitFromOpen();
- DataTable tableBaseInfo = ServerHelper.GetData("com.steering.pss.plnsaleord.order.CorePlnSaleOrder.queryBaseinfoAll",new object[] { }, this.ob);
- for (int i = 0; i < arr.GetLength(0); i++)
- {
- ArrayList param = new ArrayList();
- PlnSaleordSetEntity entity = new PlnSaleordSetEntity();
- string orderPk = arr[i, colOrderPk].Trim();
- string ordLnDlyPk = "";
- string plnDivideId = "";
- if (orderPk.Equals(""))
- {
- messageErr.Add("第" + (i + startRow).ToString() + "条数据PK码为空");
- continue;
- }
- if (orderPk.Contains('-'))
- {
- int lenPk = orderPk.LastIndexOf('-');
- ordLnDlyPk = orderPk.Substring(0, lenPk);
- plnDivideId = orderPk.Substring(lenPk + 1, orderPk.Length - lenPk - 1);
- }
- else
- {
- ordLnDlyPk = orderPk;
- }
- if (ordLnDlyPk.Equals(""))
- {
- messageErr.Add("第" + (i + startRow).ToString() + "条数据PK码有误。");
- continue;
- }
- if (colRollMonth != -1)
- {
- DateTime date = new DateTime();
- string rollMonth = arr[i, colRollMonth].ToString();
- if (DateTime.TryParseExact(rollMonth, "yyyyMM", null, DateTimeStyles.None, out date))
- {
- entity.RollMonth = date.ToString("yyyy-MM");
- }
- }
- if(colCheckMoth != -1)
- {
- entity.CheckMoth = arr[i, colCheckMoth].Trim();
- }
- if (colPriority != -1)
- {
- tableBaseInfo.DefaultView.RowFilter = "SORTCODE='2006' and BASENAME='" + arr[i, colPriority].Trim() + "'";
- DataTable dtPrior = tableBaseInfo.DefaultView.ToTable();
- if (dtPrior != null)
- {
- entity.Priority = dtPrior.Rows[0]["BASECODE"].ToString2();
- }
- }
- if (colPriorityMemo != -1)
- {
- entity.PriorityMemo = arr[i, colPriorityMemo].Trim();
- }
- entity.OrdLnDlyPk = ordLnDlyPk;
- entity.PlnDivideId = plnDivideId;
- list.Add(entity);
- }
- int succed = ServerHelper.SetData("com.steering.pss.plnsaleord.order.CoreOrderStatusSet.saveOrderSetlog",
- new object[] { list }, this.ob);
- WaitFromColse();
- if (succed > 0)
- {
- if (messageErr.Count == 0)
- {
- MessageUtil.ShowTips("导入成功,共" + list.Count + "条。");
- }
- else
- {
- MessageUtil.ShowTips(list.Count + "条导入成功," + messageErr.Count + "条导入失败。\n" + messageErr[0]);
- }
- }
- else
- {
- MessageUtil.ShowTips("导入失败,共" + list.Count + "条。");
- }
- }
- catch (Exception ex)
- {
- WaitFromColse();
- if (!(ex is MESException))
- {
- MessageUtil.ShowError(ex.Message);
- }
- }
- }
- /// <summary>
- /// 打开excel文件
- /// </summary>
- private void doOpen()
- {
- try
- {
- OpenFileDialog dialog = new OpenFileDialog();
- uC_EmbedExcelIntoWinFormNoDLL1.AppExcel_Exit();
- if (dialog.ShowDialog() == DialogResult.OK)
- {
- ModelPatch = dialog.FileName;
- if (!System.IO.File.Exists(ModelPatch))//检察文件是否存在
- {
- return;
- }
- try
- {
- System.IO.File.Move(ModelPatch, ModelPatch);
- }
- catch
- {
- MessageUtil.ShowTips("文件已经被打开,请先关闭!");
- return;
- }
- uC_EmbedExcelIntoWinFormNoDLL1.AppExcel_Open(ModelPatch, true);
- this.ultraNumRowEnd.Value = getExcelRowsCount();
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- /// <summary>
- /// 关闭
- /// </summary>
- private void doClose()
- {
- uC_EmbedExcelIntoWinFormNoDLL1.AppExcel_Exit();
- }
- /// <summary>
- /// object二维数组转string二维数组
- /// </summary>
- /// <param name="obj"></param>
- /// <returns></returns>
- private string[,] ObjectToString(object[,] obj)
- {
- int rows = obj.GetLength(0); //获取m_objRangeArrayValue的行数
- int columns = obj.GetLength(1); //获取m_objRangeArrayValue的列数
- object[,] param = new object[rows, columns]; //转化为起始为0的数组
- Array.Copy(obj, param, rows * columns); //临时结果,学习用
- string[,] str = new string[param.GetLength(0), param.GetLength(1)];
- for (int i = 0; i < str.GetLength(0); i++)
- {
- for (int j = 0; j < str.GetLength(1); j++)
- {
- if (param[i, j] == null)
- {
- str[i, j] = "";
- }
- else
- {
- str[i, j] = param[i, j].ToString();
- }
- }
- }
- return str;
- }
- /// <summary>
- /// 等待窗口
- /// </summary>
- private void WaitFromOpen()
- {
- this.Cursor = Cursors.WaitCursor; //控制鼠标的样式为等待
- if (Constant.WaitingForm == null)
- {
- Constant.WaitingForm = new WaitingForm();
- }
- Constant.WaitingForm.ShowToUser = true;
- Constant.WaitingForm.Show();
- Constant.WaitingForm.Update();
- }
- /// <summary>
- /// 关闭等待
- /// </summary>
- private void WaitFromColse()
- {
- this.Cursor = Cursors.Default;
- Constant.WaitingForm.ShowToUser = false;
- Constant.WaitingForm.Close();
- Constant.WaitingForm = null;
- }
- private void FrmImportSetOrder_FormClosed(object sender, FormClosedEventArgs e)
- {
- uC_EmbedExcelIntoWinFormNoDLL1.AppExcel_Exit();
- }
- }
- }
|