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 CoreFS.CA06;
using System.Collections;
using Infragistics.Win.UltraWinGrid;
namespace Core.LgMes.Client.lgIntegrationQuery
{
public partial class FrmCLReport : FrmBase
{
public FrmCLReport()
{
InitializeComponent();
}
private void FrmCLReport_Load(object sender, EventArgs e)
{
this.ultraComboEditor1.SelectedIndex = 0;
this.ultraComboEditor3.SelectedIndex = 0;
this.ultraComboEditor2.SelectedIndex = 0;
}
///
/// 操作方法 查询
///
private void DoQuery()
{
try
{
if (this.DelToDateTo.DateTime.Date.Subtract(this.DelToDateFrom.DateTime.Date).Days > 180)
{
MessageBox.Show("查询时间不可超过6个月。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (this.DelToDateFrom.DateTime > this.DelToDateTo.DateTime)
{
MessageBox.Show("查询起始时间不能大于结束时间!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
string strErr = "";
this.dataSet1.Tables[0].Clear();
string DelToDateFrom = Convert.ToString(this.DelToDateFrom.DateTime.ToString("yyyyMMdd"));
string DelToDateTo = Convert.ToString(this.DelToDateTo.DateTime.ToString("yyyyMMdd"));
string prcd = this.ultraComboEditor4.Text.ToString();
DateTime t1 = DateTime.ParseExact(DelToDateFrom, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture);
DateTime t2 = DateTime.ParseExact(DelToDateTo, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture);
System.TimeSpan t3 = t2 - t1; //两个时间相减 。默认得到的是 两个时间之间的天数 得到:365.00:00:00
double getDay = t3.TotalDays; //将这个天数转换成天数, 返回值是double类型的(其实不必转换,因为t3默认就是天数) 得到:
if (getDay > 30)
{
MessageBox.Show("查询周期过长,是否继续查询?");
}
string sqlCondition = "1=1 AND (T1.MATRL_END_CAUSE_CD IS NULL OR T1.MATRL_END_CAUSE_CD != '4')";
if (this.ultraComboEditor1.Text.ToString() == "已申报") //是否申报
{
sqlCondition += " AND T1.REPORT_TIME IS NOT NULL ";
}
else if (this.ultraComboEditor1.Text.ToString() == "未申报")
{
sqlCondition += " AND T1.REPORT_TIME IS NULL ";
}
if (this.ultraComboEditor2.Text.ToString() == "切割时间")
{
sqlCondition += " AND T1.SLAB_CUT_DTIME BETWEEN " + DelToDateFrom + "000000" + " AND " + DelToDateTo + "999999" + "";
}
else if (this.ultraComboEditor2.Text.ToString() == "申报时间")
{
sqlCondition += " AND T1.REPORT_REGTIME BETWEEN " + DelToDateFrom + "000000" + " AND " + DelToDateTo + "999999" + "";
}
else //出库时间
{
sqlCondition += " AND T1.SMS_YARD_EXT_DTIME BETWEEN " + DelToDateFrom + "000000" + " AND " + DelToDateTo + "999999" + "";
}
if (!string.IsNullOrEmpty(this.textOrdNO.Text))
{
sqlCondition += " AND T1.SLAB_NO LIKE '%" + Convert.ToString(this.textOrdNO.Text) + "%' ";
}
if (!string.IsNullOrEmpty(this.ultraComboEditor4.Text.Trim()) && this.ultraComboEditor4.Text.Trim() != "全部")
{
sqlCondition += " AND T1.PROC_CD = '" + this.ultraComboEditor4.Text.Trim() + "'";
}
ArrayList arry1 = new ArrayList();
ArrayList sqlList = new ArrayList();
arry1.Add("FrmCLReport.Select");//此ID为XML文件ID
sqlList.Add(sqlCondition);
//调用服务端方法
CoreClientParam CCP_JJBQuery = new CoreClientParam();
DataTable dt = new DataTable();
CCP_JJBQuery.ServerName = "Core.LgMes.Server.Common.ComDBQuery";
CCP_JJBQuery.MethodName = "doQuery";
CCP_JJBQuery.ServerParams = new object[] { arry1, sqlList };
CCP_JJBQuery.SourceDataTable = dt;//dataSet1.Tables[0];
this.ExecuteQueryToDataTable(CCP_JJBQuery, CoreInvokeType.Internal);
if (dt != null && dt.Rows.Count > 0)
{
this.dataTable1.Rows.Clear();
DataRow dr;
for (int iRow = 0; iRow < dt.Rows.Count; iRow++)
{
dr = this.dataTable1.NewRow();
for (int jCol = 0; jCol < dt.Columns.Count; jCol++)
{
if (this.dataTable1.Columns.Contains(dt.Columns[jCol].ColumnName))
{
dr[dt.Columns[jCol].ColumnName] = dt.Rows[iRow][jCol];
}
}
this.dataTable1.Rows.Add(dr);
}
}
//this.dataSet1.data = dt;
//System.Diagnostics.Debug.WriteLine(this.dataSet1.Tables[0].ToString());
this.Docount();
}
catch (Exception EX)
{
MessageBox.Show(EX.ToString());
}
}
private void Docount()
{
int coilCount = 0;
double actWgtSum = 0;
double thrWgtSum = 0;
string status = "", zl2 = "", zl3 = "";
foreach (Infragistics.Win.UltraWinGrid.UltraGridRow ugr in ultraGrid1.Rows)
{
double actWgt = 0;
double thrWgt = 0;
bool ifhide = ugr.HiddenResolved;
if (ifhide == false)
{
try
{
Color color = Color.SandyBrown;
status = ugr.Cells["REPORTFLAG"].Value.ToString().Trim();
if ("未申报".Equals(status))
{
color = Color.White;
}
else if ("已申报".Equals(status))
{
color = Color.FromArgb(255, 128, 128);
}
ugr.Appearance.BackColor = color;
zl2 = Convert.ToString(ugr.Cells["THR_WGT"].Text.ToString());
if (zl2 == "") zl2 = "0";
zl3 = Convert.ToString(ugr.Cells["SLAB_WGT"].Text.ToString());
if (zl3 == "") zl3 = "0";
thrWgt = double.Parse(zl2);
actWgt = double.Parse(zl3);
thrWgtSum += thrWgt;
actWgtSum += actWgt;
coilCount = coilCount + 1;
}
catch (Exception e)
{
}
}
}
this.textBox1.Text = coilCount.ToString();
this.textBox2.Text = (Math.Round(thrWgtSum, 3)).ToString();
this.textBox3.Text = (Math.Round(actWgtSum, 3)).ToString();
// this.ultraGrid1.DisplayLayout.Bands[0].Summaries.
}
private void DoSave()
{
try
{
string strQueryFlag = "Y";
this.ultraGrid1.UpdateData();
ArrayList list = new ArrayList();
string[] param = null;
CoreClientParam ccp = new CoreClientParam();
ccp.ServerName = "Core.LgMes.Server.lgIntegrationQuery.PerformanceLog";
string regid = this.UserInfo.GetUserName();
string bc = this.UserInfo.GetUserOrderText();
string reporttime = Convert.ToString(this.ultraDateTimeEditor1.DateTime.ToString("yyyyMM"));
DataRow[] selectedRows = dataSet1.Tables[0].Select("CHK ='True'");
for (int i = 0; i < selectedRows.Length; i++)
{
param = new string[3];
string slab_no = Convert.ToString(selectedRows[i]["SLAB_NO"]);
param[0] = slab_no;//板坯号
param[1] = reporttime;//申报时间
param[2] = bc;//班次
list.Add(param);
}
if (MessageBox.Show("确定将所选定板坯申报至" + reporttime + "?", "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
return;
ccp.MethodName = "reportslab";
ccp.ServerParams = new Object[] { regid, list };
this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
if (strQueryFlag == "Y")
{
this.DoQuery();
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
}
private void DoCancel()
{
try
{
string strQueryFlag = "Y";
this.ultraGrid1.UpdateData();
ArrayList list = new ArrayList();
string[] param = null;
CoreClientParam ccp = new CoreClientParam();
ccp.ServerName = "Core.LgMes.Server.lgIntegrationQuery.PerformanceLog";
string regid = this.UserInfo.GetUserID();
string reporttime = Convert.ToString(this.ultraDateTimeEditor1.DateTime.ToString("yyyyMM"));
DataRow[] selectedRows = dataSet1.Tables[0].Select("CHK ='True'");
for (int i = 0; i < selectedRows.Length; i++)
{
param = new string[1];
string slab_no = Convert.ToString(selectedRows[i]["SLAB_NO"]);
param[0] = slab_no;//板坯号
list.Add(param);
}
if (MessageBox.Show("确定取消所选板坯申报?", "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
return;
ccp.MethodName = "cancelreportslab";
ccp.ServerParams = new Object[] { regid, list };
this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
if (strQueryFlag == "Y")
{
this.DoQuery();
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
}
private void DoExport()
{
try
{
if (this.saveFileDialog1.ShowDialog(this) == DialogResult.OK)
{
string fileName = this.saveFileDialog1.FileName;
ultraGridExcelExporter1.Export(ultraGrid1, fileName);
//System.Diagnostics.Process.Start(fileName);
}
}
catch (Exception EX)
{
MessageBox.Show(EX.ToString());
}
}
///
/// 事件方法:
///
///
///
#region "EVENT 事件"
private void UIN060310_Load(object sender, EventArgs e)
{
// init();
}
public override void ToolBar_Click(object sender, string ToolbarKey)
{
switch (ToolbarKey)
{
case "Query":
this.DoQuery();
break;
case "Save":
this.DoSave();
break;
case "Export":
this.DoExport();
break;
case "cancel":
this.DoCancel();
break;
case "Exit":
this.Close();
break;
}
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
try
{
foreach (UltraGridRow ugr in this.ultraGrid1.Rows)
{
if (ugr.HiddenResolved == false)//只处理过滤之后的数据
{
ugr.Cells["CHK"].Value = this.checkBox1.Checked;
ugr.Update();
}
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
}
#endregion
private void ultraComboEditor3_ValueChanged(object sender, EventArgs e)
{
try
{
this.ultraGrid1.DisplayLayout.Bands[0].ColumnFilters.ClearAllFilters();
if (ultraComboEditor3.Text == "在库")
ultraGrid1.DisplayLayout.Bands[0].ColumnFilters["SLAB_STAT"].FilterConditions.Add(Infragistics.Win.UltraWinGrid.FilterComparisionOperator.Like, "在*");
else if (ultraComboEditor3.Text == "出库")
ultraGrid1.DisplayLayout.Bands[0].ColumnFilters["SLAB_STAT"].FilterConditions.Add(Infragistics.Win.UltraWinGrid.FilterComparisionOperator.Like, "出*");
this.Docount();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void ultraGrid1_FilterRow(object sender, Infragistics.Win.UltraWinGrid.FilterRowEventArgs e)
{
//this.Docount();
//List rows = this.ultraGrid1.Rows.Where(p => p.IsFilteredOut == false).ToList();//选择过滤后数据的代码
}
private void ultraGrid1_AfterRowFilterChanged(object sender, Infragistics.Win.UltraWinGrid.AfterRowFilterChangedEventArgs e)
{
this.Docount();
}
}
}