using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CoreFS.CA06;
namespace Core.LZMes.Client.UIM
{
public partial class UIM010210 : FrmBase
{
private string opTime = "";
private string shift = "";
private string group = "";
private string stockNo = "";
int queryType = 0;
public UIM010210()
{
InitializeComponent();
}
private void UIM010210_Load(object sender, EventArgs e)
{
//默认查询入库记录
this.ddlQueryType.Value = 0;
this.QueryCustomers();//查询并显示收货单位
this.ExportColumnsInit();//初始化导出字段设定
}
///
/// 导出时不需要显示的字段
///
string[] ExportColumns;
///
/// 不需要导出的字段的名字组初始化
///
private void ExportColumnsInit()
{
this.ExportColumns = new string[]{
"YARD_ENTRY_DTIME",
"TRNF_DTIME",
"PRODNM_CD",
"CZSJ",
"SHIFT",
"WKGROUP",
"CZR",
"ZPH",
"TOT_DEC_GRD",
"INGR_DEC_GRD",
"MATLQLTY_DEC_GRD",
"SIZE_DEC_RST",
"EXTSHAPE_DEC_GRD",
"WGT_DEC_RST",
"ORD_NO",
"ORD_SEQ",
"DLIV_TP",
"ORDCUST_CD",
"CHARGE_NO",
"OP_TYPE",
"DLIV_DIRNO",
"ORD_DEVLMT_DATE",
"SMP_NO",
"LC_YSREL",
"LC_YSRP",
"LC_EL50",
"LC_EL80"
};
}
public override void ToolBar_Click(object sender, string ToolbarKey)
{
switch (ToolbarKey)
{
case "Query":
this.label1.Focus();
this.DoQuery();
break;
case "Save":
this.DoSave();
break;
case "Exit":
this.Close();
break;
case "":
break;
}
}
///
/// 查询原料库钢卷出入库记录
///
private void DoQuery()
{
try
{
this.dataSet1.Tables[0].Clear();
string startTime =this.dteStartDate.DateTime.ToString("yyyyMMdd");//开始时间 1
opTime = this.dteStartDate.DateTime.ToString("yyyy年MM月dd日");
string endTime =this.dteEndDate.DateTime.ToString("yyyyMMdd");//结束时间 2
string specStlGrd = this.txtSPEC_STL_GRD.Text;//牌号 3
string coilWthMin = this.txtWidth_1.Text;//宽度最小值 4
string coilWthMax = this.txtWidth_2.Text;//宽度最大值 5
string coilThkMin = this.txtThick_1.Text;//厚度最小值 6
string coilThkMax = this.txtThick_2.Text;//厚度最大值 7
string curLoadLoc = this.txtCUR_LOAD_LOC.Text;//垛位 8
string coilNo = this.txtOLD_SAMPL_NO.Text;//钢卷号 9
shift = (-1 >= this.ddlShift.SelectedIndex ) ? "" : this.ddlShift.Value.ToString();//班次 10
group = (-1 >= this.ddlWKGroup.SelectedIndex ) ? "" : this.ddlWKGroup.Value.ToString();//班组 11
string regId = this.txtCZR.Text;//作业人12
string custCd = (-1 == this.ddlDLIV_tp.SelectedIndex) ? "" : this.ddlDLIV_tp.Value.ToString();//客户编号13
string ordNo = this.txtORD_NO.Text;//订单号14
string ordSeq = this.txtORD_SQE.Text;//合同号15
string ordFl = (-1 >= this.ddlSEQType.SelectedIndex || this.ddlSEQType.Value == null) ? "" : this.ddlSEQType.Value.ToString();//订单区分16
//string prodnmCd = -1 == this.ddlProductType.SelectedIndex ? "" : this.ddlProductType.Value.ToString();//产品类型17
stockNo = 0 > this.ultraComboEditor1.SelectedIndex ? "" : this.ultraComboEditor1.Value.ToString();
//string deldatefr = this.ultraDateTimeEditor4.DateTime.ToString("yyyyMMdd");//交货期开始时间
//string deldateto = this.ultraDateTimeEditor3.DateTime.ToString("yyyyMMdd");//结束时间
string deldatefr = this.ultraDateTimeEditor4.Value != null ? ultraDateTimeEditor4.DateTime.ToString("yyyyMMdd") : "";//入库开始时间
string deldateto = this.ultraDateTimeEditor3.Value != null ? ultraDateTimeEditor3.DateTime.ToString("yyyyMMdd") : "";//入库结束时间
queryType = int.Parse(this.ddlQueryType.Value.ToString());//查询类型 0 入库记录 1 出库记录
string[] queryParams = new string[] { startTime, endTime, specStlGrd, coilWthMin, coilWthMax,
coilThkMin, coilThkMax, curLoadLoc, coilNo, shift, group, regId, custCd, ordNo, ordSeq,
ordFl, "",stockNo,deldatefr,deldateto};
for(int i = 0;i < queryParams.Length;i++)
{
if (queryParams[i] == null)
{
queryParams[i] = "";
}
}
List list = new List();
list.Add(queryParams);
CoreClientParam ccp = new CoreClientParam();
ccp.ServerName = "UIM.UIM010210";
ccp.MethodName = "queryYardList";
ccp.ServerParams = new object[] { queryType, list };
ccp.SourceDataTable = this.dataSet1.Tables[0];
this.ExecuteQueryToDataTable(ccp, CoreInvokeType.Internal);
DataRowCollection drs = this.dataSet1.Tables[0].Rows;
int coilCount = 0;
double wgtCount = 0;
int drsSize = drs.Count;
coilCount = drsSize;
for (int i = 0; i < drsSize; i++)
{
double actWgt = 0;
try
{
actWgt = double.Parse(drs[i]["ACT_WGT"].ToString());
}
catch (Exception e)
{
}
wgtCount += actWgt;
}
if (coilCount == 0)
{
this.textBox1.Text = "";
this.textBox2.Text = "";
}
else
{
this.textBox1.Text = coilCount.ToString();
this.textBox2.Text = (wgtCount / 1000).ToString();
}
}
catch (Exception EX)
{
MessageBox.Show(EX.ToString());
}
}
///
/// 查询并显示收货单位
///
private void QueryCustomers()
{
CoreClientParam ccp = new CoreClientParam();
ccp.ServerName = "UIM.UIM010060";
ccp.MethodName = "queryCustomers";
ccp = this.ExecuteQuery(ccp, CoreInvokeType.Internal);
ArrayList custList = (ArrayList)ccp.ReturnObject;
int listSize = custList.Count;
Infragistics.Win.ValueListItem[] valueListItems = new Infragistics.Win.ValueListItem[listSize];
for (int i = 0; i < listSize; i++)
{
Infragistics.Win.ValueListItem item = new Infragistics.Win.ValueListItem();
Hashtable ht = (Hashtable)custList[i];
item.DataValue = ht["VALUE"].ToString();
object obj = ht["LABEL"];
if (obj != null)
{
item.DisplayText = ht["LABEL"].ToString();
}
else
{
item.DisplayText = "";
}
valueListItems[i] = item;
}
this.ddlDLIV_tp.Items.AddRange(valueListItems);
}
///
/// 导出
///
private void DoSave()
{
try
{
if (this.saveFileDialog1.ShowDialog() != DialogResult.OK)
{
return;
}
this.dataSet1.Tables[0].Columns["ACT_WGT"].Caption = "卷重(吨)";
foreach (string columnStr in ExportColumns)
{
this.ultraGrid1.DisplayLayout.Bands[0].Columns[columnStr].Hidden = true;
}
if(this.ddlQueryType.SelectedIndex == 1)
{
this.ultraGrid1.DisplayLayout.Bands[0].Columns["CUR_LOAD_LOC"].Hidden = true;
}
// 如果加单位会导致统计数据出错
for (int i = 0; i < this.ultraGrid1.Rows.Count; i++)
{
Infragistics.Win.UltraWinGrid.UltraGridRow row = this.ultraGrid1.Rows[i];
double tempWGT;
double.TryParse(row.Cells["ACT_WGT"].Value.ToString(), out tempWGT);
tempWGT = tempWGT * 0.001;
row.Cells["ACT_WGT"].Value = (tempWGT.ToString());
}
string title = "成品库";
if (stockNo == "3")
{
title = "连退库";
}
else if(stockNo == "4")
{
title = "连退库";
}
else if (stockNo == "5")
{
title = "重卷库";
}
if (queryType == 0)
{
title += "入库单";
}
else
{
title += "出库单";
}
string operation = "";
if (opTime != "")
{
operation += opTime + " ";
}
operation += tools.UserInfoExt.Get_UserOrder(UserInfo) + "/" + tools.UserInfoExt.Get_UserGroup(UserInfo);
this.ultraGrid1.DisplayLayout.AutoFitStyle = Infragistics.Win.UltraWinGrid.AutoFitStyle.None;
string filepath = this.saveFileDialog1.FileName;
ultraGridExcelExporter1.Export(ultraGrid1, filepath);
Microsoft.Office.Interop.Excel.Application excel;
Microsoft.Office.Interop.Excel._Workbook objBook;
Microsoft.Office.Interop.Excel.Workbooks objBooks;//接口 workbooks
Microsoft.Office.Interop.Excel.Sheets objSheets;// 接口 sheets
Microsoft.Office.Interop.Excel.Worksheet objSheet;//接口 worksheet
Microsoft.Office.Interop.Excel.Range range = null;
try
{
excel = new Microsoft.Office.Interop.Excel.Application();
objBooks = excel.Workbooks;
//Object miss = System.Reflection.Missing.Value;
objBook = objBooks.Add(filepath);
objSheets = objBook.Sheets;
objSheet = (Microsoft.Office.Interop.Excel.Worksheet)objSheets[1];
excel.Visible = false; //让后台执行设置为不可见,为true的话会看到打开一个Excel,然后数据在往里写
Microsoft.Office.Interop.Excel.Range tmpRange = (Microsoft.Office.Interop.Excel.Range)objSheet.Rows[1, System.Reflection.Missing.Value];
tmpRange.Insert(Microsoft.Office.Interop.Excel.XlInsertShiftDirection.xlShiftDown, System.Reflection.Missing.Value);
tmpRange.Insert(Microsoft.Office.Interop.Excel.XlInsertShiftDirection.xlShiftDown, System.Reflection.Missing.Value);
objSheet.get_Range("A1", queryType == 0 ? "G1" : "F1").Merge(objSheet.get_Range("A1", queryType == 0 ? "G1" : "F1").MergeCells);
objSheet.get_Range("A2", queryType == 0 ? "G2" : "F2").Merge(objSheet.get_Range("A2", queryType == 0 ? "G2" : "F2").MergeCells);
objSheet.get_Range("A1", queryType == 0 ? "G1" : "F1").VerticalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter;
objSheet.get_Range("A2", queryType == 0 ? "G2" : "F2").VerticalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter;
objSheet.get_Range("A1", queryType == 0 ? "G1" : "F1").HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
objSheet.get_Range("A2", queryType == 0 ? "G2" : "F2").HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft;
((Microsoft.Office.Interop.Excel.Range)objSheet.UsedRange.Cells[1, 1]).Font.Size = 24;
((Microsoft.Office.Interop.Excel.Range)objSheet.UsedRange.Cells[1, 1]).RowHeight = 45;
((Microsoft.Office.Interop.Excel.Range)objSheet.UsedRange.Cells[1, 1]).Font.Bold = true;
((Microsoft.Office.Interop.Excel.Range)objSheet.UsedRange.Cells[1, 1]).Interior.Color = ((Microsoft.Office.Interop.Excel.Range)objSheet.UsedRange.Cells[4, 1]).Interior.Color;
((Microsoft.Office.Interop.Excel.Range)objSheet.UsedRange.Cells[2, 1]).Interior.Color = ((Microsoft.Office.Interop.Excel.Range)objSheet.UsedRange.Cells[4, 1]).Interior.Color;
excel.Cells[1, 1] = title;
excel.Cells[2, 1] = operation;
int iRowCnt = objSheet.UsedRange.Cells.Rows.Count;
int iBgnRow = (objSheet.UsedRange.Cells.Row > 3 ? objSheet.UsedRange.Cells.Row : objSheet.UsedRange.Cells.Row + 1) + 1;
int insertIdx = iRowCnt - 1, insertIdx1 = iRowCnt - 1;
string befStlStr = ((Microsoft.Office.Interop.Excel.Range)objSheet.UsedRange.Cells[insertIdx - 1, queryType == 0 ? 2 : 2]).Text.ToString();
string befThkStr = GetThickBySize(((Microsoft.Office.Interop.Excel.Range)objSheet.UsedRange.Cells[insertIdx - 1, queryType == 0 ? 3 : 3]).Text.ToString());
string curStlStr = string.Empty, curThkStr = string.Empty;
int coilCount = 0, coilCount1 = 0;
double weightSum = 0, weightSum1 = 0;
for (int i = iRowCnt - 2; i >= iBgnRow; i--)
{
curStlStr = ((Microsoft.Office.Interop.Excel.Range)objSheet.UsedRange.Cells[i, queryType == 0 ? 2 : 2]).Text.ToString();
curThkStr = GetThickBySize(((Microsoft.Office.Interop.Excel.Range)objSheet.UsedRange.Cells[i, queryType == 0 ? 3 : 3]).Text.ToString());
if (!befStlStr.Equals(curStlStr) || !befThkStr.Equals(curThkStr))
{
if (!befStlStr.Equals(curStlStr))
{
tmpRange = (Microsoft.Office.Interop.Excel.Range)objSheet.Rows[insertIdx1, System.Reflection.Missing.Value];
tmpRange.Insert(Microsoft.Office.Interop.Excel.XlInsertShiftDirection.xlShiftDown, System.Reflection.Missing.Value);
excel.Cells[insertIdx1, queryType == 0 ? 1 : 1] = coilCount1.ToString();
excel.Cells[insertIdx1, queryType == 0 ? 5 : 5] = weightSum1.ToString();
coilCount1 = 0;
weightSum1 = 0;
insertIdx1 = i;
}
tmpRange = (Microsoft.Office.Interop.Excel.Range)objSheet.Rows[insertIdx, System.Reflection.Missing.Value];
tmpRange.Insert(Microsoft.Office.Interop.Excel.XlInsertShiftDirection.xlShiftDown, System.Reflection.Missing.Value);
excel.Cells[insertIdx, queryType == 0 ? 1 : 1] = coilCount.ToString();
excel.Cells[insertIdx, queryType == 0 ? 5 : 5] = weightSum.ToString();
coilCount = 0;
weightSum = 0;
insertIdx = i + 1;
insertIdx1++;
}
if (i > iBgnRow)
{
coilCount++;
weightSum += Convert.ToDouble(((Microsoft.Office.Interop.Excel.Range)objSheet.UsedRange.Cells[i, queryType == 0 ? 5 : 5]).Text);
coilCount1++;
weightSum1 += Convert.ToDouble(((Microsoft.Office.Interop.Excel.Range)objSheet.UsedRange.Cells[i, queryType == 0 ? 5 : 5]).Text);
}
befStlStr = curStlStr;
befThkStr = curThkStr;
}
objBook.SaveCopyAs(filepath);
//设置禁止弹出保存和覆盖的询问提示框
excel.DisplayAlerts = false;
excel.AlertBeforeOverwriting = false;
//确保Excel进程关闭
objBooks.Close();
excel.Workbooks.Close();
excel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(objBook);
System.Runtime.InteropServices.Marshal.ReleaseComObject(objBooks);
System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);
GC.Collect();
System.GC.WaitForPendingFinalizers();
//MessageBox.Show("数据导出完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
if (System.IO.File.Exists(filepath))
System.Diagnostics.Process.Start(filepath); //保存成功后打开此文件
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "错误提示");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void ultraGridExcelExporter1_EndExport(object sender, Infragistics.Win.UltraWinGrid.ExcelExport.EndExportEventArgs e)
{
this.ultraGrid1.BeginUpdate();
this.dataSet1.Tables[0].Columns["ACT_WGT"].Caption = "卷重";
//保险
try
{
for (int i = 0; i < this.ultraGrid1.Rows.Count; i++)
{
Infragistics.Win.UltraWinGrid.UltraGridRow row = this.ultraGrid1.Rows[i];
double tempWGT;
double.TryParse(row.Cells["ACT_WGT"].Value.ToString(), out tempWGT);
tempWGT = tempWGT * 1000;
row.Cells["ACT_WGT"].Value = tempWGT.ToString();
}
}
catch
{
this.DoQuery();
}
foreach (string columnStr in ExportColumns)
{
this.ultraGrid1.DisplayLayout.Bands[0].Columns[columnStr].Hidden = false;
}
this.ultraGrid1.DisplayLayout.Bands[0].Columns["CUR_LOAD_LOC"].Hidden = false;
this.ultraGrid1.DisplayLayout.AutoFitStyle = Infragistics.Win.UltraWinGrid.AutoFitStyle.ExtendLastColumn;
this.ultraGrid1.EndUpdate();
}
private string GetThickBySize(string coilSize)
{
string thick = string.Empty;
if (!string.IsNullOrEmpty(coilSize) && coilSize.Contains("*"))
{
thick = coilSize.Substring(0, coilSize.IndexOf("*"));
}
return thick;
}
private void txtThick_1_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
try
{
if (this.saveFileDialog1.ShowDialog(this) == DialogResult.OK)
{
string fileName = this.saveFileDialog1.FileName;
this.ultraGridExcelExporter1.Export(ultraGrid1, fileName);
System.Diagnostics.Process.Start(fileName);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}