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.plan.order.model;
using System.Globalization;
using Core.Mes.Client.Comm;
namespace Core.StlMes.Client.Plan.Order.PopupWindow
{
public partial class FrmImportSetOrder : FrmBase
{
///
/// 模板路径
///
string modelPatch = "";
///
/// 模板路径
///
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();
}
///
/// 初始化
///
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();
}
///
/// 获取excl的行数
///
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;
}
}
///
/// 保存
///
private void doSave()
{
try
{
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 colOrderNo = -1;
int colRollMonth = -1;
int colOrderPk = -1;
int colOrderfrom = -1;
int colProduceSort = -1;
if (!((IList)colhead).Contains("合同号"))
{
MessageUtil.ShowWarning("列“合同号”不存在!");
return;
}
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("合同号"))
{
colOrderNo = i;
}
if (head[0, i].Trim().Equals("轧制月份"))
{
colRollMonth = i;
}
if (head[0, i].Trim().Equals("交货编码PK"))
{
colOrderPk = i;
}
if (head[0, i].Trim().Equals("来源"))
{
colOrderfrom = i;
}
if (head[0, i].Trim().Equals("项目"))
{
colProduceSort = i;
}
}
#endregion
ArrayList list = new ArrayList();
string[,] arr = ObjectToString(uC_EmbedExcelIntoWinFormNoDLL1.GetRangeArray_Value(
"A" + startRow, ExcelHelper.SeqToXlsCol[colNum + 1] + endRow));
if (arr == null)
{
return;
}
for (int i = 0; i <= endRow - startRow; i++)
{
if (arr[i, colOrderNo].Equals(""))
{
MessageUtil.ShowTips("第" + (i + startRow).ToString() + "行,合同号为空!");
return;
}
}
WaitFromOpen();
for (int i = 0; i < arr.GetLength(0); i++)
{
string orderNoseq = arr[i, colOrderNo].ToString();
ArrayList param = new ArrayList();
PlnSaleorderSetEntity entity = new PlnSaleorderSetEntity();
if (!orderNoseq.Contains('/'))
{
WaitFromColse();
MessageUtil.ShowTips("第" + (i + startRow).ToString() + "行,合同行号为空!");
return;
}
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");
}
}
entity.IfSetMonth = "0";
entity.OrderNoSeq = orderNoseq;
if (colOrderPk != -1)
{
entity.OrdLnDlyPk = arr[i, colOrderPk].ToString();
}
if (colOrderfrom != -1)
{
entity.Orderfrom = arr[i, colOrderfrom].ToString();
}
if (colProduceSort != -1)
{
entity.ProduceSort = arr[i, colProduceSort].ToString();
}
list.Add(entity);
}
int succed = ServerHelper.SetData("com.steering.pss.plan.order.CoreOrderStatusSet.saveOrderSetlog",
new object[] { list }, this.ob);
WaitFromColse();
if (succed > 0)
{
MessageUtil.ShowTips("导入成功!");
}
else
{
MessageUtil.ShowTips("导入失败!");
}
}
catch (Exception ex)
{
WaitFromColse();
if (ex is MESException)
{
}
else
{
MessageBox.Show(ex.Message);
}
}
}
///
/// 打开excel文件
///
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);
}
}
///
/// 关闭
///
private void doClose()
{
uC_EmbedExcelIntoWinFormNoDLL1.AppExcel_Exit();
}
///
/// object二维数组转string二维数组
///
///
///
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;
}
///
/// 等待窗口
///
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();
}
///
/// 关闭等待
///
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();
}
}
}