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 Core.Mes.Client.Comm.Server;
using Core.Mes.Client.Comm.Control;
using Core.Mes.Client.Comm.Tool;
using Infragistics.Win.UltraWinGrid;
using Infragistics.Win;
using System.Threading;
using System.Net;
using System.Collections;
using CoreFS.SA06;
namespace Core.StlMes.Client.BuyBillet
{
public partial class frmRptDaySCKB : FrmBase
{
public frmRptDaySCKB()
{
InitializeComponent();
this.updator = new UpdateProgress(UIUpdateProgress);
}
private void frmRptDaySCKB_Load(object sender, EventArgs e)
{
//this.startDate.Value = DateTime.Now.AddDays(-7);
//this.endDate.Value = DateTime.Now;
this.startDate.Value = this.endDate.Value.AddDays(-6);
ultraExpandableGroupBox1.Expanded = false;
ForbidSort(ug);
ForbidSort1(ug1);
}
public override void ToolBar_Click(object sender, string ToolbarKey)
{
base.ToolBar_Click(sender, ToolbarKey);
switch (ToolbarKey)
{
case "Query":
Query();
break;
case "Export":
Export();
break;
case "ExportDetails":
ExportDetails();
break;
case "Close":
this.Close();
break;
}
}
private void Query()
{
int flag = DateTime.Compare(this.startDate.Value, this.endDate.Value);
string startDate = this.startDate.Value.ToString("yyyyMMdd");
string endDate = this.endDate.Value.ToString("yyyyMMdd");
if (Convert.ToInt32(startDate) > Convert.ToInt32(endDate))
{
MessageUtil.ShowWarning("起始日期不能大于截止日期!");
return;
}
string selectedDay = this.endDate.Value.ToString("yyyyMMdd");
//TimeSpan sp = this.endDate.Value.Subtract(this.startDate.Value);
//int days = sp.Days;
//System.DateTime f = this.startDate.Value;
//System.DateTime g = this.endDate.Value;
//System.TimeSpan diff = g.Subtract(f);
//int days = diff.Days;
DateTime d1 = this.startDate.Value;
DateTime d2 = this.endDate.Value;
DateTime d3 = Convert.ToDateTime(string.Format("{0}-{1}-{2}", d1.Year, d1.Month, d1.Day));
DateTime d4 = Convert.ToDateTime(string.Format("{0}-{1}-{2}", d2.Year, d2.Month, d2.Day));
int days = (d4 - d3).Days;
DataTable dt = ServerHelper.GetData("com.steering.pss.buybillet.Buybillet.get_Rpt_DaySCKB", new object[] { startDate,endDate,days }, this.ob);
DataTable dt3 = ds.Tables[0];
GridHelper.CopyDataToDatatable(dt, dt3, true);
//if(dt.Columns.Contains("PLINEORDER")){
//dt.Columns["PLINEORDER"].ColumnMapping = MappingType.Hidden;
//}
ug.DisplayLayout.Bands[0].Columns["DEPT"].CellAppearance.BackColor = Color.Wheat;
ug.DisplayLayout.Bands[0].Columns["DEPT"].MergedCellStyle = MergedCellStyle.Always;
//ug.DisplayLayout.Bands[0].Columns["DEPARTMENT_DESC_P"].MergedCellStyle = MergedCellStyle.Always;
ug.DisplayLayout.Bands[0].Columns["DEPT"].CellAppearance.TextHAlign = HAlign.Center;
ug.DisplayLayout.Bands[0].Columns["DEPT"].MinWidth = 100;
ug.DisplayLayout.Bands[0].Columns["DAYZYL"].CellAppearance.TextHAlign = HAlign.Right;
ug.DisplayLayout.Bands[0].Columns["YXNB"].CellAppearance.TextHAlign = HAlign.Right;
ug.DisplayLayout.Bands[0].Columns["YXZH"].CellAppearance.TextHAlign = HAlign.Right;
ug.DisplayLayout.Bands[0].Columns["DAYZYLDAY"].CellAppearance.TextHAlign = HAlign.Right;
ug.DisplayLayout.Bands[0].Columns["YXNBDAY"].CellAppearance.TextHAlign = HAlign.Right;
ug.DisplayLayout.Bands[0].Columns["YXZHDAY"].CellAppearance.TextHAlign = HAlign.Right;
ug.DisplayLayout.Bands[0].Columns["PLINECODE"].Hidden = true;
//ug.DisplayLayout.Bands[0].PerformAutoResizeColumns(true, PerformAutoSizeType.VisibleRows);
//ug.DisplayLayout.AutoFitStyle = AutoFitStyle.ResizeAllColumns;
ug.DisplayLayout.Bands[0].Columns["DEPT"].PerformAutoResize();
UltraGridBand band = this.ug.DisplayLayout.Bands[0];
foreach (UltraGridRow row in band.GetRowEnumerator(GridRowType.DataRow))
{
if (row.Cells["PLINENAME"].Value.ToString() == "合计" ||
row.Cells["PLINENAME"].Value.ToString() == "管加工热处理(炉)合计" ||
row.Cells["PLINENAME"].Value.ToString() == "管加工热处理(探伤)合计" ||
row.Cells["PLINENAME"].Value.ToString() == "管加工加工线合计")
{
Color cellColor = Color.Yellow;
row.Cells["PLINENAME"].Appearance.BackColor = cellColor;
row.Cells["ZCNB"].Appearance.BackColor = cellColor;
row.Cells["ZCWB"].Appearance.BackColor = cellColor;
row.Cells["YCNB"].Appearance.BackColor = cellColor;
row.Cells["YCWB"].Appearance.BackColor = cellColor;
row.Cells["TJTIMETOTAL"].Appearance.BackColor = cellColor;
row.Cells["YXNB"].Appearance.BackColor = cellColor;
row.Cells["YXZH"].Appearance.BackColor = cellColor;
row.Cells["DAYZYL"].Appearance.BackColor = cellColor;
row.Cells["ZCNBDAY"].Appearance.BackColor = cellColor;
row.Cells["ZCWBDAY"].Appearance.BackColor = cellColor;
row.Cells["YCNBDAY"].Appearance.BackColor = cellColor;
row.Cells["YCWBDAY"].Appearance.BackColor = cellColor;
row.Cells["TJTIMETOTALDAY"].Appearance.BackColor = cellColor;
row.Cells["YXNBDAY"].Appearance.BackColor = cellColor;
row.Cells["YXZHDAY"].Appearance.BackColor = cellColor;
row.Cells["DAYZYLDAY"].Appearance.BackColor = cellColor;
}
if (row.Cells["PLINENAME"].Value.ToString() == "本部热处理(炉)合计" ||
row.Cells["PLINENAME"].Value.ToString() == "元通热处理(炉)合计" ||
row.Cells["PLINENAME"].Value.ToString() == "深加工热处理(炉)合计" ||
row.Cells["PLINENAME"].Value.ToString() == "本部热处理(探伤)合计" ||
row.Cells["PLINENAME"].Value.ToString() == "元通热处理(探伤)合计" ||
row.Cells["PLINENAME"].Value.ToString() == "深加工热处理(探伤)合计" ||
row.Cells["PLINENAME"].Value.ToString() == "本部加工线合计" ||
row.Cells["PLINENAME"].Value.ToString() == "元通加工线合计" ||
row.Cells["PLINENAME"].Value.ToString() == "深加工加工线合计"
)
{
Color cellColor = Color.SkyBlue;
row.Cells["PLINENAME"].Appearance.BackColor = cellColor;
row.Cells["ZCNB"].Appearance.BackColor = cellColor;
row.Cells["ZCWB"].Appearance.BackColor = cellColor;
row.Cells["YCNB"].Appearance.BackColor = cellColor;
row.Cells["YCWB"].Appearance.BackColor = cellColor;
row.Cells["TJTIMETOTAL"].Appearance.BackColor = cellColor;
row.Cells["YXNB"].Appearance.BackColor = cellColor;
row.Cells["YXZH"].Appearance.BackColor = cellColor;
row.Cells["DAYZYL"].Appearance.BackColor = cellColor;
row.Cells["ZCNBDAY"].Appearance.BackColor = cellColor;
row.Cells["ZCWBDAY"].Appearance.BackColor = cellColor;
row.Cells["YCNBDAY"].Appearance.BackColor = cellColor;
row.Cells["YCWBDAY"].Appearance.BackColor = cellColor;
row.Cells["TJTIMETOTALDAY"].Appearance.BackColor = cellColor;
row.Cells["YXNBDAY"].Appearance.BackColor = cellColor;
row.Cells["YXZHDAY"].Appearance.BackColor = cellColor;
row.Cells["DAYZYLDAY"].Appearance.BackColor = cellColor;
}
}
foreach (var col in ug.DisplayLayout.Bands[0].Columns)
{
col.CellAppearance.TextHAlign = HAlign.Right;
}
ug.DisplayLayout.Bands[0].Columns["DEPT"].CellAppearance.TextHAlign = HAlign.Left;
ug.DisplayLayout.Bands[0].Columns["PLINENAME"].CellAppearance.TextHAlign = HAlign.Left;
}
private void Export()
{
if (ug.Rows.Count == 0)
{
MessageUtil.ShowWarning("查询数据为空,无法导出!");
}
else
{
GridHelper.ulGridToExcel(ug, "日生产运行快报");
}
}
private void ExportDetails()
{
if (ug1.Rows.Count == 0)
{
MessageUtil.ShowWarning("查询数据为空,无法导出!");
}
else
{
GridHelper.ulGridToExcel(ug1, "停机详情");
}
}
///
/// 禁止排序及筛选
///
///
public void ForbidSort(UltraGrid ugr)
{
foreach (UltraGridColumn ugc in ugr.DisplayLayout.Bands[0].Columns)
{
ugc.SortIndicator = SortIndicator.Disabled;
ugc.AllowRowFiltering = DefaultableBoolean.False;
}
}
///
/// 禁止排序
///
///
public void ForbidSort1(UltraGrid ugr)
{
foreach (UltraGridColumn ugc in ugr.DisplayLayout.Bands[0].Columns)
{
ugc.SortIndicator = SortIndicator.Disabled;
//ugc.AllowRowFiltering = DefaultableBoolean.False;
}
}
private void ug_ClickCell(object sender, ClickCellEventArgs e)
{
e.Cell.Selected = true;
string plinecode = e.Cell.Row.Cells["PLINECODE"].Value.ToString();
if (string.IsNullOrEmpty(plinecode))
{
//ug1.DataSource;
ThreadPool.QueueUserWorkItem(new WaitCallback(DoInBackgroundThread));
return;
}
string date = endDate.Value.ToString("yyyyMMdd");
string date1 = startDate.Value.ToString("yyyyMMdd");
DataTable dt = ServerHelper.GetData("com.steering.pss.buybillet.Buybillet.get_FrmddTJ_data", new object[] { plinecode, date,date1 }, this.ob);
DataTable dt1 = ds1.Tables[0];
GridHelper.CopyDataToDatatable(dt, dt1, true);
if (dt == null || dt.Rows.Count == 0)
{
//ultraExpandableGroupBox1.Expanded = true;
//WaitingForm2 wf = new WaitingForm2("无停机数据....");
//System.Threading.Thread.Sleep(3000);
//wf.Close();
ThreadPool.QueueUserWorkItem(new WaitCallback(DoInBackgroundThread));
//ultraExpandableGroupBox1.Expanded = false;
return;
}
ug1.DisplayLayout.Bands[0].Columns["PLINE_NAME"].CellAppearance.BackColor = Color.Wheat;
ug1.DisplayLayout.Bands[0].Columns["PLINE_NAME"].MergedCellStyle = MergedCellStyle.Always;
ug1.DisplayLayout.Bands[0].Columns["TJHOURS"].MergedCellStyle = MergedCellStyle.Always;
ug1.DisplayLayout.Bands[0].Columns["TJHOURS"].CellAppearance.TextHAlign = HAlign.Right;
//ug1.DisplayLayout.Bands[0].Columns["TJHOURS"].PerformAutoResize();
ug1.DisplayLayout.Bands[0].Columns["LOGS_BEG"].MinWidth = 100;
ug1.DisplayLayout.Bands[0].Columns["LOGS_END"].MinWidth = 100;
ug1.DisplayLayout.Bands[0].Columns["CONFIRM_TIME"].MinWidth = 100;
ug1.DisplayLayout.Bands[0].Columns["TJ_DATE"].MinWidth = 60;
ug1.DisplayLayout.Bands[0].Columns["FLAG"].Hidden = true;
UltraGridBand band = this.ug1.DisplayLayout.Bands[0];
foreach (UltraGridRow row in band.GetRowEnumerator(GridRowType.DataRow))
{
if (row.Cells["FLAG"].Value.ToString() == "1")
{
row.Cells["TJ_DATE"].Value = "小计";
row.Cells["TJ_DATE"].Appearance.BackColor = Color.Yellow;
}
if (row.Cells["FLAG"].Value.ToString() == "2")
{
row.Cells["TJ_DATE"].Value = "合计";
row.Cells["TJ_DATE"].Appearance.BackColor = Color.Green;
}
row.Activation = Activation.NoEdit;
if (plinecode.Length == 5)
{
if (plinecode.EndsWith("0"))
{
row.Cells["PLINE_NAME"].Value = row.Cells["PLINE_NAME"].Value + "(热处理)";
}
if (plinecode.EndsWith("1"))
{
row.Cells["PLINE_NAME"].Value = row.Cells["PLINE_NAME"].Value + "(探伤)";
}
}
}
ultraExpandableGroupBox1.Expanded = true;
//ug1.DisplayLayout.Bands[0].PerformAutoResizeColumns(true, PerformAutoSizeType.VisibleRows);
//foreach (UltraGridColumn ugc in ug1.DisplayLayout.Bands[0].Columns)
// ugc.PerformAutoResize();
}
private void DoInBackgroundThread(object state)
{
this.BeginInvoke(updator,true);
WaitingForm2 wf = new WaitingForm2("无停机数据....");
System.Threading.Thread.Sleep(3000);
wf.Close();
this.BeginInvoke(updator,false);
}
//定义一个更新UI的委托类
public delegate void UpdateProgress(bool flag);
//定义一个委托实例
private UpdateProgress updator;
private void UIUpdateProgress(bool flag)
{
this.ultraExpandableGroupBox1.Expanded = flag;
}
private void ultraExpandableGroupBox1_ExpandedStateChanging(object sender, CancelEventArgs e)
{
ulBoxExpanded = !ulBoxExpanded;
spcPanel2_Resize();
}
private void spcPanel2_Resize()
{
if (ulBoxExpanded)
{
setSpcSize();
}
else
{
setSpcCollapse();
}
}
bool ulBoxExpanded = true;
private void setSpcSize()
{
this.spc.SplitterDistance = Convert.ToInt32(spc.Size.Height * 0.7);
}
private void setSpcCollapse()
{
this.spc.SplitterDistance = this.spc.Size.Height - 10;
}
private void frmRptDaySCKB_Resize(object sender, EventArgs e)
{
spcPanel2_Resize();
}
private void spc_SizeChanged(object sender, EventArgs e)
{
//WaitingForm2 wf = new WaitingForm2("无停机数据....");
//System.Threading.Thread.Sleep(3000);
//wf.Close();
}
private void btn_week_Click(object sender, EventArgs e)
{
this.startDate.Value = this.endDate.Value.AddDays(-6);
}
private void btn_month_Click(object sender, EventArgs e)
{
this.startDate.Value = this.endDate.Value.AddMonths(-1);
}
}
}