using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Infragistics.Win.UltraWinEditors;
using Common;
namespace MeterModuleLibrary
{
public partial class ucStorageWeightKg : UserControl
{
public ucStorageWeightKg()
{
InitializeComponent();
}
#region 线程中赋值的控件需使用委托
private delegate void UpdateUIEventHander(object sender, UpdateUIArgs args); //自定义事件用来从线程中更新控件的值
public class UpdateUIArgs : EventArgs
{
public string textValue { get; private set; }
public UpdateUIArgs(string textValue)
{
this.textValue = textValue;
}
}
private void UpdateUI_Method(object sender, UpdateUIArgs args)
{
if (sender is UltraTextEditor)
{
if (args.textValue == "" || args.textValue == null)
{
((UltraTextEditor)sender).Text = "0";
}
else
{
((UltraTextEditor)sender).Text = args.textValue;
}
}
else if (sender is Button)
{
if (args.textValue == "red")
{
((Button)sender).BackColor = Color.Red;
((Button)sender).ForeColor = Color.White;
}
else if (args.textValue == "green")
{
((Button)sender).BackColor = Color.White;
((Button)sender).ForeColor = Color.Black;
}
else
{
((Label)sender).Text = args.textValue;
}
}
else if (sender is PictureBox)
{
if (args.textValue == "red")
{
((PictureBox)sender).Load(PbCache.path + "\\image\\icon\\red.gif");
}
else
{
((PictureBox)sender).Load(PbCache.path + "\\image\\icon\\green.gif");
}
}
}
///
/// 记录当前的颜色,在线程中窑调用下面的setControl方法前
/// 可先判断当前的颜色与显示颜色是否一致
/// 若一致则可不调用setControl,不一致再调用
///
public bool isGreen = true;
///
/// 重量稳定
///
///
public void setStable(bool bGreen)
{
//if (!PbCache.isLockWgt)
{
isGreen = bGreen;
string sValue = isGreen ? "green" : "red";
picStable.Invoke(new UpdateUIEventHander(UpdateUI_Method), picStable, new UpdateUIArgs(sValue));
btnStable.Invoke(new UpdateUIEventHander(UpdateUI_Method), btnStable, new UpdateUIArgs(sValue));
}
}
public double getWgt()
{
if (txtWeight.Text.Trim() != "")
{
return Math.Round(Convert.ToDouble(txtWeight.Text.Trim()), 1);
}
else
{
return 0;
}
}
///
/// 实时写入重量
/// PbCache.isLockWgt 重量未锁定则可写入,否则调用了也不会写入
///
/// 重量信息
public void setWgt(double db)
{
//if (!PbCache.isLockWgt)
{
txtWeight.Invoke(new UpdateUIEventHander(UpdateUI_Method), txtWeight, new UpdateUIArgs(Math.Round(db, 1) + ""));
}
}
#endregion
}
}