using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; 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.UltraWinGrid; namespace Core.StlMes.Client.LgCommon.公共自定义控件.温度 { public partial class ucNewTemperature : UserControl { public ucNewTemperature() { InitializeComponent(); } private string _stove = ""; private string _station = ""; private string _disposalTime = ""; private bool _changed = false; private OpeBase _ob; public bool Changed { get { return _changed ? _changed : datas != null && datas.Any() && datas.Any(p => p.NewRow); } } public bool CanSave { get { return datas.All(p => p.Valid); } } private List datas; public bool SaveDate() { if (_ob == null) return false; if (!Changed || datas ==null) return true; if (!CanSave) { MessageBox.Show("温度数据不正确,无法保存温度数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return true; } try { ServerHelper.SetData("Core.LgMes.Server.LgDeviceManager.StlTemperature.SaveStlTemperature", new object[] { datas, _stove, _station,_disposalTime }, _ob); Refresh(); return true; } catch (Exception ex) { return false; } } public void SetData(string Stove, string station, string disposalTime, OpeBase ob) { _stove = Stove; _station = station; _disposalTime = disposalTime; if (_ob==null) _ob = ob; Refresh(); } private void Refresh() { if (_ob == null) return; datas = EntityHelper.GetData( "Core.LgMes.Server.LgDeviceManager.StlTemperature.GetStlTemperature", new[] { _stove, _station, _disposalTime }, _ob) ?? new DataSourceList(); ugTem.DataBindings.Clear(); ugTem.DataSource = datas; if (datas.Count >= 0) { ClsControlPack.RefreshAndAutoSize(ugTem); } _changed = false; } private void tsmAdd_Click(object sender, EventArgs e) { if (datas == null) return; datas.Add(new StlTempsamplingEntity() {NewRow = true,Valid = false,Startdate = DateTime.Now,Enddate = DateTime.Now}); ugTem.DataBind(); ugTem.Rows[ugTem.Rows.Count - 1].Appearance.BackColor = Color.Orange; if (ugTem.Rows.Count <= 1) { ClsControlPack.RefreshAndAutoSize(ugTem); } } private void tsmDelete_Click(object sender, EventArgs e) { if (ugTem.ActiveRow == null) { MessageBox.Show("请选中一行再进行删除"); return; } StlTempsamplingEntity StlTempsamplingEntity = ugTem.ActiveRow.ListObject as StlTempsamplingEntity; if (StlTempsamplingEntity != null && !StlTempsamplingEntity.NewRow) { _changed = true; } datas.RemoveAt(ugTem.ActiveRow.Index); } private void ugTem_KeyPress(object sender, KeyPressEventArgs e) { try { ugTem.UpdateData(); } catch (Exception) { } } private void ugTem_AfterRowInsert(object sender, Infragistics.Win.UltraWinGrid.RowEventArgs e) { e.Row.Appearance.BackColor = Color.Orange; } private void ugTem_BeforeRowsDeleted(object sender, Infragistics.Win.UltraWinGrid.BeforeRowsDeletedEventArgs e) { if (e.Rows != null) { StlTempsamplingEntity StlTempsamplingEntity = e.Rows[0].ListObject as StlTempsamplingEntity; if (StlTempsamplingEntity != null && !StlTempsamplingEntity.NewRow) { _changed = true; } } } private void ugTem_ClickCellButton(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e) { e.Cell.Value = DateTime.Now; } private void ugTem_AfterCellUpdate(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e) { StlTempsamplingEntity StlTempsamplingEntity = ugTem.ActiveRow.ListObject as StlTempsamplingEntity; if (StlTempsamplingEntity != null) { if (StlTempsamplingEntity.Startdate == null || StlTempsamplingEntity.Enddate == null || StlTempsamplingEntity.Startdate > StlTempsamplingEntity.Enddate || StlTempsamplingEntity.Samplingname == "" || StlTempsamplingEntity.Samplingvalue == null ) { ugTem.Rows[ugTem.ActiveRow.Index].Appearance.BackColor = Color.Orange; StlTempsamplingEntity.Valid = false; } else { ugTem.Rows[ugTem.ActiveRow.Index].Appearance.BackColor = Color.LightGreen; StlTempsamplingEntity.Valid = true; } } else { ugTem.Rows[ugTem.ActiveRow.Index].Appearance.BackColor = Color.Orange; StlTempsamplingEntity.Valid = false; _changed = true; } } private void ugTem_CellChange(object sender, CellEventArgs e) { try { ugTem.UpdateData(); } catch (Exception) { } } private void ugTem_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { var uieOver = ugTem.DisplayLayout.UIElement.ElementFromPoint(new Point(e.X, e.Y)); if (uieOver != null) { UltraGridRow ugrOver = uieOver.GetContext(typeof(UltraGridRow), true) as UltraGridRow; ugTem.ActiveRow = ugrOver; } } } } }