using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Windows.Forms;
using Core.Mes.Client.Comm.Server;
using Core.Mes.Client.Comm.Tool;
using Core.StlMes.Client.LgClassModel;
using CoreFS.CA06;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
namespace Core.StlMes.Client.LgCommon
{
///
/// 实绩管理响应炉号选中事件
///
public delegate void OperationOver();
public delegate void OperationBegin();
public partial class ucNewResBase : UserControl
{
public ucNewResBase()
{
InitializeComponent();
ClsControlPack.SetUltraGridStyle(ugData, 1);
}
public event OperationOver OperationOver;
public event OperationBegin OperationBegin;
public bool bOperationOver;
protected OpeBase Ob;
protected string _operator = "";
protected string _shiftCode = "";
protected string _stove = "";
protected string _station = "";
protected LG_PROCESS _process;
private List allowSave = new List() { true, true, true, true }; //是否允许修改实绩
public bool AllowSave
{
get { return allowSave.All(p=>p); }
}
private object _htValueInitial = null; //初始值
private Hashtable _htValueChanged = null; //修改后的值
private Hashtable _htDatatypeChanged = null; //修改字段数据类型
private Hashtable _htCaptionChanged = null; //修改字段中文名
public void SetBase(OpeBase ob, string Operator, string ShifCode, LG_PROCESS Process)
{
Ob = ob;
_operator = Operator;
_shiftCode = ShifCode;
_process = Process;
}
///
/// 初始值
///
public object htValueInitial
{
get { return _htValueInitial; }
}
///
/// 值发生变化列表
///
public Hashtable htValueChanged
{
get
{
ugData.UpdateData();
return _htValueChanged;
}
}
///
/// 修改字段数据类型
///
public Hashtable htDatatypeChanged
{
get
{
ugData.UpdateData();
return _htDatatypeChanged;
}
}
///
/// 值发生变化的字段名
///
public Hashtable htCaptionChanged
{
get
{
ugData.UpdateData();
return _htCaptionChanged;
}
}
///
/// 有值发生变化
///
public bool HasChanged
{
get
{
ugData.UpdateData();
return (_htValueChanged != null && _htValueChanged.Count > 0);
}
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
SetControlDelegate();
InitValuelist();
ResetData();
}
protected virtual void InitValuelist()
{
try
{
if (ClsControlPack.GridContainsColumn(ugData, "SHIFTCODE"))
{
ValueList vlist = ClsBusinessPack.GetValuelistShift();
ClsControlPack.SetGridValuelist(ref ugData, "SHIFTCODE", ref vlist);
}
if (ClsControlPack.GridContainsColumn(ugData, "POTDISTINCTION"))
{
ValueList vlist1 = ClsBusinessPack.GetValuelistPotLevel();
ClsControlPack.SetGridValuelist(ref ugData, "POTDISTINCTION", ref vlist1);
}
if (ClsControlPack.GridContainsColumn(ugData, "POTWRAPSTATE"))
{
ValueList vlist2 = ClsBusinessPack.GetValuelistPotStatus();
ClsControlPack.SetGridValuelist(ref ugData, "POTWRAPSTATE", ref vlist2);
}
if (ClsControlPack.GridContainsColumn(ugData, "BILLETSECTION"))
{
ValueList vlist3 = ClsBusinessPack.GetValuelistBilletSection();
ClsControlPack.SetGridValuelist(ref ugData, "BILLETSECTION", ref vlist3);
}
if (ClsControlPack.GridContainsColumn(ugData, "MOLIRNTYPE"))
{
ValueList vlist3 = ClsBusinessPack.GetValuelistIronSourceForBOF();
ClsControlPack.SetGridValuelist(ref ugData, "MOLIRNTYPE", ref vlist3);
}
}
catch { }
}
public void SetValuelistSteel(OpeBase ob)
{
try
{
ValueList vlist = ClsBusinessPack.GetValuelistSteel(ob);
ClsControlPack.SetGridValuelist(ref ugData, "GRADECODE", ref vlist);
}
catch { }
}
protected virtual void SetControlDelegate()
{
ugData.ClickCellButton += new CellEventHandler(ugData_ClickCellButton);
ugData.KeyDown += new KeyEventHandler(ugData_KeyDown);
ugData.CellListSelect += new CellEventHandler(ugData_CellListSelect);
ugData.AfterCellUpdate += new CellEventHandler(ugData_AfterCellUpdate);
ugData.CellChange += new CellEventHandler(ugData_CellChange);
ugData.KeyPress +=ugData_KeyPress;
ugData.CellDataError +=ugData_CellDataError;
}
private void ugData_CellDataError(object sender, CellDataErrorEventArgs e)
{
e.RestoreOriginalValue = true;
e.RaiseErrorEvent = false;
}
private void ugData_KeyPress(object sender, KeyPressEventArgs e)
{
if(this.ugData.ActiveCell==null) return;
string strKey = this.ugData.ActiveCell.Column.ToString();
if (strKey == "POTNO" || strKey == "POTAGE")
{
if (!(Char.IsNumber(e.KeyChar) && ugData.ActiveRow.Cells[strKey].Value.ToString().Length <= 3) && e.KeyChar != '\b')
{
e.Handled = true;
}
}
if (strKey == "OGGNUMID" || strKey == "GAGE" || strKey == "SAGE" ||
strKey == "BLOWO2TIMES" || strKey == "EMOLSTLTIME" || strKey == "IRONPOTID")
{
if (!(Char.IsNumber(e.KeyChar) && ugData.ActiveRow.Cells[strKey].Value.ToString().Length <= 6) && e.KeyChar != '\b')
{
e.Handled = true;
}
}
if (strKey == "RSSTOVENO")
{
if (!(Char.IsNumber(e.KeyChar) && ugData.ActiveRow.Cells[strKey].Value.ToString().Length <= 8) && e.KeyChar != '\b')
{
e.Handled = true;
}
}
if (strKey == "IRONPOTWGT" || strKey == "IRONTEMPERATURE" || strKey == "WSTEELWGT" ||
strKey == "PIGIRONWGT" || strKey == "O2CONSUME" || strKey == "TOPN2CONSUME" ||
strKey == "TERMINUSC" || strKey == "TERMINUSO2" || strKey == "TERMINUSTEPT" ||
strKey == "RSWGT")
{
if (!(e.KeyChar == '\b') && ugData.ActiveRow.Cells[strKey].Value.ToString().Length >= 6)
{
e.Handled = true;
}
if (!(Char.IsNumber(e.KeyChar) || e.KeyChar == '\b' || e.KeyChar == '.'))
{
e.Handled = true;
}
if (e.KeyChar == '.')
{
char[] arrary = ugData.ActiveRow.Cells[strKey].Text.ToCharArray();
if (arrary.Length == 0)
{
ugData.ActiveRow.Cells[strKey].Value = "0.";
ugData.ActiveRow.Cells[strKey].SelStart = ugData.ActiveRow.Cells[strKey].Value.ToString().Length;
e.Handled = true;
}
else
{
for (int i = 0; i < arrary.Length; i++)
{
if (arrary[i] == '.')
e.Handled = true;
}
}
}
}
if (strKey == "MEMO")
{
char[] arrary = ugData.ActiveRow.Cells[strKey].Text.ToCharArray();
if (!(e.KeyChar == '\b') && arrary.Length >= 40)
{
// MessageBox.Show("生产记事不能超过40个字!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
e.Handled = true;
}
}
if (strKey == "PROTECTDTEG")
{
char[] arrary = ugData.ActiveRow.Cells[strKey].Text.ToCharArray();
if (!(e.KeyChar == '\b') && arrary.Length >= 10)
{
// MessageBox.Show("保护渣名称不能超过10个字!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
e.Handled = true;
}
}
}
protected virtual void ugData_ClickCellButton(object sender, CellEventArgs e)
{
try
{
if (e.Cell.Column.DataType == typeof(DateTime) || e.Cell.Column.DataType == typeof(DateTime?) )
{
/* frmSetTime frm = new frmSetTime(e.Cell.Value);
frm.Location = ClsControlPack.GetChildWindowLocation(frm.Size);
if (frm.ShowDialog() == DialogResult.OK)
{
e.Cell.Value = frm.SelectDate;
ugData.UpdateData();
}*/
//e.Cell.Value = DateTime.Now;
DateTime dataValue = ClsBusinessPack.GetServerDateTime(Ob);
if (ugData.Rows[0].Cells.Exists("OPTDATE"))
{
var vaule = ugData.Rows[0].Cells["OPTDATE"].Value;
DateTime? OpdateDate = null;
if (vaule != null)
{
OpdateDate = (DateTime?) vaule;
}
if (OpdateDate != null)
{
dataValue =
DateTime.ParseExact(
((DateTime) OpdateDate).ToString("yyyy-MM-dd ") + dataValue.ToString("HH:mm:ss"),
"yyyy-MM-dd HH:mm:ss", null);
}
}
e.Cell.Value = dataValue;
}
else if (e.Cell.Column.DataType == typeof(Decimal) || e.Cell.Column.DataType == typeof(Decimal?))
{
frmInputDecimal frm = new frmInputDecimal(Convert.ToString(e.Cell.Text));
frm.Location = ClsControlPack.GetChildWindowLocation(frm.Size);
if (frm.ShowDialog() == DialogResult.OK)
{
if (!frm.ValueChanged) return;
e.Cell.Value = frm.Value;
ugData.UpdateData();
}
}
else if (e.Cell.Column.Key.Equals("Potno", StringComparison.OrdinalIgnoreCase) || e.Cell.Column.Key.Equals("Vacgrooveid", StringComparison.OrdinalIgnoreCase)
||e.Cell.Column.Key.Equals("Basketetno1", StringComparison.OrdinalIgnoreCase)
||e.Cell.Column.Key.Equals("Basketetno2", StringComparison.OrdinalIgnoreCase)
||e.Cell.Column.Key.Equals("Basketetno3", StringComparison.OrdinalIgnoreCase)
|| e.Cell.Column.Key.Equals("Basketetno4", StringComparison.OrdinalIgnoreCase)
|| e.Cell.Column.Key.Equals("BasketetNum", StringComparison.OrdinalIgnoreCase)
|| e.Cell.Column.Key.Equals("PotNum", StringComparison.OrdinalIgnoreCase)
|| e.Cell.Column.Key.Equals("Pot1Wgt", StringComparison.OrdinalIgnoreCase)
|| e.Cell.Column.Key.Equals("Pot2Wgt", StringComparison.OrdinalIgnoreCase)
|| e.Cell.Column.Key.Equals("Pot3Wgt", StringComparison.OrdinalIgnoreCase)
)
{
frmHeatNoEditor frm = new frmHeatNoEditor();
frm.InputText = Convert.ToString(e.Cell.Text);
frm.Location = ClsControlPack.GetChildWindowLocation(frm.Size);
if (frm.ShowDialog() == DialogResult.OK)
{
e.Cell.Value = frm.InputText;
ugData.UpdateData();
}
}
}
catch { }
}
protected virtual void ugData_CellChange(object sender, CellEventArgs e)
{
try
{
if (!e.Cell.Column.Hidden && e.Cell.Column.CellActivation == Activation.AllowEdit)
{
if (e.Cell.Column.DataType == typeof(DateTime) ||
e.Cell.Column.DataType == typeof(DateTime?) && Convert.ToString(e.Cell.Text).Contains("_"))
{
return;
}
ugData.UpdateData();
if (e.Cell.Column.Key.ToUpper() == "REPOSEBEGINTIME" && ugData.Rows[0].Cells["REPOSEBEGINTIME"].Value != null)
{
/* DateTime now = ClsBusinessPack.GetServerDateTime(Ob);
DateTime dt1 = (DateTime)ugData.Rows[0].Cells["REPOSEBEGINTIME"].Value;
if (dt1.Hour >= 20 && now.Hour <= 9)
{
now= now.AddDays(-1);
ugData.Rows[0].Cells["OPTDATE"].Value = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second);
ugData.Rows[0].Cells["REPOSEBEGINTIME"].Value = new DateTime(now.Year, now.Month, now.Day, dt1.Hour, dt1.Minute, dt1.Second);
}*/
}
if (e.Cell.Column.Key.ToUpper() == "OPTDATE")
{
try
{
if (ugData.Rows[0].Cells.Exists("REPOSEBEGINTIME") &&
ugData.Rows[0].Cells["REPOSEBEGINTIME"].Value != null)
{
DateTime opdt = (DateTime) ugData.Rows[0].Cells["OPTDATE"].Value;
DateTime dt1 = (DateTime)ugData.Rows[0].Cells["REPOSEBEGINTIME"].Value;
ugData.Rows[0].Cells["REPOSEBEGINTIME"].Value = new DateTime(opdt.Year,opdt.Month,opdt.Day, dt1.Hour,dt1.Minute,dt1.Second);
}
}
catch (Exception)
{
}
try
{
if (ugData.Rows[0].Cells.Exists("REPOSEENDTIME") &&
ugData.Rows[0].Cells["REPOSEENDTIME"].Value != null)
{
DateTime opdt = (DateTime)ugData.Rows[0].Cells["OPTDATE"].Value;
DateTime dt1 = (DateTime)ugData.Rows[0].Cells["REPOSEENDTIME"].Value;
ugData.Rows[0].Cells["REPOSEENDTIME"].Value = new DateTime(opdt.Year, opdt.Month, opdt.Day, dt1.Hour, dt1.Minute, dt1.Second);
}
}
catch (Exception)
{
}
ugData.UpdateData();
}
/* try
{
if (ugData.Rows[0].Cells.Exists("REPOSEBEGINTIME") &&
ugData.Rows[0].Cells["REPOSEBEGINTIME"].Value != null && ugData.Rows[0].Cells.Exists("REPOSEENDTIME") &&
ugData.Rows[0].Cells["REPOSEENDTIME"].Value != null)
{
DateTime dt1 = (DateTime)ugData.Rows[0].Cells["REPOSEBEGINTIME"].Value;
DateTime dt2 = (DateTime)ugData.Rows[0].Cells["REPOSEENDTIME"].Value;
if (DateTime.Compare(dt1, dt2) > 0) dt2= dt2.AddDays(1);
ugData.Rows[0].Cells["REPOSEENDTIME"].Value = dt2;
ugData.UpdateData();
}
}
catch (Exception)
{
}*/
if (string.IsNullOrEmpty(Convert.ToString(e.Cell.Text)))
{
ugData.PerformAction(UltraGridAction.ExitEditMode);
ugData.PerformAction(UltraGridAction.EnterEditMode);
}
}
}
catch { }
}
protected virtual void ugData_KeyDown(object sender, KeyEventArgs e)
{
try
{
UltraGridCell cell = ugData.ActiveCell;
if (e.KeyCode != Keys.Enter || cell.Column.CellActivation != Activation.AllowEdit) return;
ugData.UpdateData();
}
catch { }
}
protected virtual void ugData_CellListSelect(object sender, CellEventArgs e)
{
try
{
if (!e.Cell.Column.Hidden && e.Cell.Column.CellActivation == Activation.AllowEdit)
ugData.UpdateData();
}
catch { }
}
protected virtual void ugData_AfterCellUpdate(object sender, CellEventArgs e)
{
try
{
if (!e.Cell.Column.Hidden && e.Cell.Column.CellActivation == Activation.AllowEdit)
{
InitHashtable(ref _htValueChanged);
InitHashtable(ref _htDatatypeChanged);
InitHashtable(ref _htCaptionChanged);
string strKey = e.Cell.Column.Key.ToUpper();
string strCaption = e.Cell.Column.Header.Caption;
Type type = e.Cell.Column.DataType;
object value = e.Cell.Value;
object valueInitial = null;
var vaule = _htValueInitial.GetType().GetProperties().Where(p => p.Name.ToUpper() == strKey).ToList();
if (vaule.Any())
{
var firstOrDefault = vaule.FirstOrDefault();
if (firstOrDefault != null)
valueInitial = firstOrDefault.GetValue(_htValueInitial,null);
}
;
if ((value==null && valueInitial==null) || (value!=null && value.Equals(valueInitial)))
{
if (_htValueChanged.Contains(strKey)) _htValueChanged.Remove(strKey);
if (_htDatatypeChanged.Contains(strKey)) _htDatatypeChanged.Remove(strKey);
if (_htCaptionChanged.Contains(strKey)) _htCaptionChanged.Remove(strKey);
try
{
e.Cell.Appearance.ResetBackColor();
}
catch { }
return;
}
try
{
e.Cell.Appearance.BackColor = Color.Orange;
}
catch { }
if (!_htValueChanged.Contains(strKey))
_htValueChanged.Add(strKey, value);
else _htValueChanged[strKey] = value;
if (!_htDatatypeChanged.Contains(strKey))
_htDatatypeChanged.Add(strKey, type);
else _htDatatypeChanged[strKey] = type;
if (!_htCaptionChanged.Contains(strKey))
_htCaptionChanged.Add(strKey, strCaption);
else _htCaptionChanged[strKey] = strCaption;
if (!e.Cell.Column.Hidden && e.Cell.Column.CellActivation == Activation.AllowEdit)
{
UltraGridRow row = e.Cell.Row;
if (strKey.Equals("REPOSEBEGINTIME", StringComparison.OrdinalIgnoreCase) ||
strKey.Equals("REPOSEENDTIME", StringComparison.OrdinalIgnoreCase))
{
ugData.ActiveRow.Cells["REPOSETIME"].Value = null;
if (row.Cells["REPOSEBEGINTIME"].Value == null && row.Cells["REPOSEENDTIME"].Value != null)
{
ugData.Rows[0].Cells["REPOSEBEGINTIME"].Value = ClsBusinessPack.GetLastOptionTime(Ob, _process);
/* e.Cell.Appearance.BackColor = Color.Red;
MessageBox.Show("不能没有处理开始时间", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
allowSave[1] = false;*/
}
/*
if (row.Cells["REPOSEBEGINTIME"].Value == null) return;
DateTime Start = (DateTime) ugData.ActiveRow.Cells["REPOSEBEGINTIME"].Value;
if (strKey.Equals("REPOSEBEGINTIME", StringComparison.OrdinalIgnoreCase) && valueInitial==null )
{
if (!bOperationOver)
{
bOperationOver = true;
saveDate();
if (OperationBegin != null) OperationBegin();
bOperationOver = false;
return;
}
}
if (row.Cells["REPOSEENDTIME"].Value == null) return;
DateTime End = (DateTime) ugData.ActiveRow.Cells["REPOSEENDTIME"].Value;
if (Start > End)
{
e.Cell.Appearance.BackColor = Color.Red;
MessageBox.Show("处理结束时间不能早于开始时间", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
allowSave[1] = false;
}
else
{
if (ugData.ActiveRow.Cells["REPOSEBEGINTIME"].Appearance.BackColor == Color.Red)
{
ugData.ActiveRow.Cells["REPOSEBEGINTIME"].Appearance.BackColor = Color.Orange;
}
if (ugData.ActiveRow.Cells["REPOSEENDTIME"].Appearance.BackColor == Color.Red)
{
ugData.ActiveRow.Cells["REPOSEENDTIME"].Appearance.BackColor = Color.Orange;
}
allowSave[1] = true;
ugData.ActiveRow.Cells["REPOSETIME"].Value =
decimal.Parse(End.Subtract(Start)
.TotalSeconds.ToString(CultureInfo.InvariantCulture));
}
if (allowSave.All(p=>p) && strKey.Equals("REPOSEENDTIME", StringComparison.OrdinalIgnoreCase) && valueInitial == null)
{
if (bOperationOver) return;
bOperationOver = true;
saveDate();
if (OperationOver != null)
{
if (MessageBox.Show(@"该炉已经结束,是否切至下一炉", @"提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
OperationOver();
}
bOperationOver = false;
}*/
}
else if (strKey.Equals("BALEPFTIME", StringComparison.OrdinalIgnoreCase) ||
strKey.Equals("BALELEAVETIME", StringComparison.OrdinalIgnoreCase))
{
// ugData.ActiveRow.Cells["REPOSETIME"].Value = null;
if (row.Cells["BALEPFTIME"].Value == null && row.Cells["BALELEAVETIME"].Value != null)
{
ugData.Rows[0].Cells["BALEPFTIME"].Value = ClsBusinessPack.GetLastOptionTime(Ob, _process);
/* e.Cell.Appearance.BackColor = Color.Red;
MessageBox.Show("不能没有到站时间", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
allowSave[1] = false;*/
}
/*
if (row.Cells["BALEPFTIME"].Value == null) return;
DateTime Start = (DateTime)ugData.ActiveRow.Cells["BALEPFTIME"].Value;
if (strKey.Equals("BALEPFTIME", StringComparison.OrdinalIgnoreCase) && valueInitial == null)
{
if (!bOperationOver)
{
bOperationOver = true;
saveDate();
if (OperationBegin != null) OperationBegin();
bOperationOver = false;
return;
}
}
if (row.Cells["BALELEAVETIME"].Value == null) return;
DateTime End = (DateTime)ugData.ActiveRow.Cells["BALELEAVETIME"].Value;
if (Start > End)
{
e.Cell.Appearance.BackColor = Color.Red;
MessageBox.Show("离站时间不能早于到站时间", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
allowSave[1] = false;
}
else
{
if (ugData.ActiveRow.Cells["BALEPFTIME"].Appearance.BackColor == Color.Red)
{
ugData.ActiveRow.Cells["BALEPFTIME"].Appearance.BackColor = Color.Orange;
}
if (ugData.ActiveRow.Cells["BALELEAVETIME"].Appearance.BackColor == Color.Red)
{
ugData.ActiveRow.Cells["BALELEAVETIME"].Appearance.BackColor = Color.Orange;
}
allowSave[1] = true;
}
if (allowSave.All(p => p) && strKey.Equals("BALELEAVETIME", StringComparison.OrdinalIgnoreCase) && valueInitial == null && allowSave[1])
{
if (bOperationOver) return;
bOperationOver = true;
saveDate();
if (OperationOver != null)
{
if (MessageBox.Show(@"该炉已经结束,是否切至下一炉", @"提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
OperationOver();
}
bOperationOver = false;
}*/
}
}
}
}
catch { }
}
protected void SetUltraGridActiveCell(string ColumnName)
{
try
{
if (ugData.Rows.Count > 0)
{
ugData.Rows[0].Cells[ColumnName].Activated = true;
ugData.PerformAction(UltraGridAction.EnterEditMode);
}
}
catch { }
}
public virtual void ResetData()
{
DatabindingSource.Clear();
try
{
//string strKey = "";
//object Value = null;
//for (int i = 0; i < ugData.DisplayLayout.Bands[0].Columns.Count; i++)
//{
// try
// {
// ugData.Rows[0].Cells[strKey].Appearance.ResetBackColor();
// }
// catch { }
//}
}
catch { }
finally
{
if (_htValueChanged != null) _htValueChanged.Clear();
if (_htDatatypeChanged != null) _htDatatypeChanged.Clear();
if (_htCaptionChanged != null) _htCaptionChanged.Clear();
}
}
public virtual void SetData(List