| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- 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<StlTempsamplingEntity> 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<StlTempsamplingEntity>(
- "Core.LgMes.Server.LgDeviceManager.StlTemperature.GetStlTemperature",
- new[]
- {
- _stove,
- _station,
- _disposalTime
- }, _ob) ?? new DataSourceList<StlTempsamplingEntity>();
- 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;
- }
- }
- }
- }
- }
|