| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 | using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Windows.Media;using System.Windows;using System.ComponentModel;using System.Windows.Input;using Aitex.UI.RecipeEditor.View;namespace Aitex.UI.RecipeEditor{    /// <summary>    /// cell type enum    /// </summary>    public enum CellType    {        ReadOnly,        TextInput,        EditableSelection,        TimeInput,        ReadOnlySelection,        NumInput,        CheckBox,        EndPointSetting,    }    /// <summary>    /// reicpe variable definition    /// </summary>    public class RecipeVariableDefine    {        public CellType CellType { get; set; }        public string CatalogName { get; set; }        public string GroupName { get; set; }        public string FriendlyName { get; set; }        public string TechnicalName { get; set; }        public string DeviceType { get; set; }        public string Description { get; set; }        public double MinValue { get; set; }        public double MaxValue { get; set; }        public List<Tuple<string, string>> DropdownItemList { get; set; }    }    /// <summary>    /// cell data definition    /// </summary>    public class SmartCellData : INotifyPropertyChanged    {        public RecipeVariableDefine RecipeVariableDefine { get; set; }        public int RowIndex { get; set; }        public int ColIndex { get; set; }        public bool IsRunning { get; set; }        public bool IsHidden { get; set; }        public bool IsMasked { get; set; }                public Brush Foreground { get; set; }        public Brush Background { get; set; }        public FontWeight FontWeight { get; set; }        public string Value { get; set; }        public string ErrInfo { get; set; }        public object Tag { get; set; }        public string AdditionalInfo { get; set; }        //public bool IsJump { get; set; }        //public bool ShowsJumpControl { get; set; }        public ICommand EndPointCommand { get; set; }        //public EndPointConfigItem EndPointConfig { get; set; }        //public SmartCellData()        //{        //    EndPointCommand = new DelegatedCommand((o) => true, (o) => EndPointAction(o));        //    EndPointConfig = new EndPointConfigItem();        //}        //private void EndPointAction(object obj)        //{        //    EndPointDlg dlg = new EndPointDlg(){ Owner = Application.Current.MainWindow };        //    EndPointConfig.SetValue(Value);        //    dlg.ConfigItem = EndPointConfig;                     //    var result = dlg.ShowDialog();        //    if (result.HasValue && result.Value)        //    {        //        Value = dlg.ConfigItem.ToValue();        //    }         //}        public override string ToString()        {            return Display;        }        public string ToolTip        {            get            {                string str = "n/a";                switch (RecipeVariableDefine.CellType)                {                    case CellType.NumInput:                        str = string.Format("{0}\r\nMax:{1}\r\nValue:{2}", RecipeVariableDefine.FriendlyName, RecipeVariableDefine.MaxValue.ToString("N2").TrimEnd('0').TrimEnd('.').Replace(',', '\''), Display);                        break;                    default:                        str = string.Format("{0}\r\nValue:{1}", RecipeVariableDefine.FriendlyName, string.IsNullOrEmpty(Display) ? "Empty" : Display);                        break;                }                if (!string.IsNullOrEmpty(AdditionalInfo))                    str += "\r\n" + AdditionalInfo;                 if (!string.IsNullOrEmpty(ErrInfo))                   str = str + "\r\n\r\nError:" + ErrInfo;                return str;            }        }        public string Display        {            get            {                try                {                    if (IsHidden)                        return "";                    if (IsMasked)                        return "*";                    if (RecipeVariableDefine.CellType == CellType.ReadOnlySelection && RecipeVariableDefine.DropdownItemList != null)                    {                        var v = RecipeVariableDefine.DropdownItemList.Find((o) => o.Item1 == Value);                        if (v != null) return v.Item2;                    }                    else if (RecipeVariableDefine.CellType == CellType.CheckBox)                    {                        if (Tag != null && Tag is int)                        {                            if (bool.Parse(Value))                                return "【√】 " + Tag.ToString();                            else                                return "       " + Tag.ToString();                        }                        if (bool.Parse(Value))                            return "【√】";                        return "      ";                    }                    else if (RecipeVariableDefine.CellType == CellType.EndPointSetting)                    {                        if (!string.IsNullOrEmpty(Value) && Value != "n/a")                        {                            return "【√】";                        }                        return "【...】";                    }                    else if (RecipeVariableDefine.CellType == CellType.NumInput)                    {                        double d;                        if (double.TryParse(Value.ToString(), out d))                        {                            return d.ToString("N2").TrimEnd('0').TrimEnd('.').Replace(',', '\'');                        }                    }                }                catch (Exception ex)                {                    System.Diagnostics.Debug.WriteLine(ex.Message);                }                return Value;            }        }        #region INotifyPropertyChanged        public event PropertyChangedEventHandler PropertyChanged;        public void InvokePropertyChanged()        {            if (PropertyChanged != null)            {                foreach (var pro in this.GetType().GetProperties())                {                    PropertyChanged.Invoke(this, new PropertyChangedEventArgs(pro.Name));                }            }        }        public void InvokePropertyChanged(string proName)        {            if (PropertyChanged != null)            {                PropertyChanged.Invoke(this, new PropertyChangedEventArgs(proName));            }        }        #endregion    }}
 |