protected CellMonitor AddToMonitoring(string primaryValue, int columnIndex)
        {
            var data = this.DataTable;

            if (data == null || columnIndex < 0 || data.Columns.Count <= columnIndex)
            {
                return(null);
            }
            if (data.Columns.Contains(PrimaryKey))
            {
                //Get values
                string columnName = data.Columns[columnIndex].ColumnName;
                for (int i = 0; i < data.Rows.Count; i++)
                {
                    if (data.Rows[i][PrimaryKey].ToString() == primaryValue)
                    {
                        string orgin = data.Rows[i][columnIndex].ToString();
                        //Add
                        var item = new CellMonitor(primaryValue, columnIndex, columnName, orgin);
                        MonitorItems.Add(item);
                        return(item);
                    }
                }
            }
            return(null);
        }
Beispiel #2
0
 // OnNavigatedTo后调用
 public void OnLoaded(ListView monitorlist)
 {
     this.monitorlist = monitorlist;
     for (int i = 0; i < monitorlist.Items.Count; i++)
     {
         ((ListViewItem)monitorlist.ContainerFromIndex(i)).IsSelected = MonitorItems.ToList()[i].Is_Monitor;
     }
 }
        private void SaveChangesTo(CellMonitor src, CellMonitor changed)
        {
            int index = MonitorItems.IndexOf(src);

            if (index >= 0)
            {
                MonitorItems[index] = changed;
            }
        }
 private CellMonitor AddToMonitoring(DataTable data, int rowIndex, int columnIndex)
 {
     //Validate
     if (data == null || rowIndex < 0 || columnIndex < 0)
     {
         return(null);
     }
     if (data.Rows.Count <= rowIndex || data.Columns.Count <= columnIndex)
     {
         return(null);
     }
     if (data.Columns.Contains(PrimaryKey))
     {
         //Get values
         string primary    = data.Rows[rowIndex][PrimaryKey].ToString();
         string columnName = data.Columns[columnIndex].ColumnName;
         string orgin      = data.Rows[rowIndex][columnIndex].ToString();
         //Add
         var item = new CellMonitor(primary, columnIndex, columnName, orgin);
         MonitorItems.Add(item);
         return(item);
     }
     return(null);
 }
        protected override void OnInitCommands()
        {
            base.OnInitCommands();
            AddMonitorCommand         = new DelegateCommand();
            RemoveMonitorCommand      = new DelegateCommand();
            SaveMonitorCommand        = new DelegateCommand();
            LoadMonitorCommand        = new DelegateCommand();
            SaveMonitorChangesCommand = new DelegateCommand();
            CallEditMonitorCommand    = new DelegateCommand();

            AddMonitorCommand.ExecuteCommand += o =>
            {
                object[] values = o as object[];
                if (values != null && values.Length == 2)
                {
                    int col, row;
                    if (int.TryParse(values[0].ToString(), out col) &&
                        int.TryParse(values[1].ToString(), out row))
                    {
                        AddToMonitoring(row, col);
                    }
                }
            };
            RemoveMonitorCommand.ExecuteCommand += o =>
            {
                if (o is CellMonitor)
                {
                    CellMonitor item = (CellMonitor)o;
                    if (MonitorItems.Contains(item))
                    {
                        MonitorItems.Remove(item);
                    }
                }
            };
            LoadMonitorCommand.ExecuteCommand += o =>
            {
                object obj = SerializeHelper.DeserializeDefault(saveName);
                if (obj != null)
                {
                    BindingList <CellMonitor> items = obj as BindingList <CellMonitor>;
                    if (items != null)
                    {
                        this.MonitorItems = items;
                    }
                }
            };
            SaveMonitorCommand.ExecuteCommand += o =>
            {
                SerializeHelper.SerializeDefault(saveName, MonitorItems);
            };
            SaveMonitorChangesCommand.ExecuteCommand += o =>
            {
                object        obj    = o;
                CellMonitor[] values = obj as CellMonitor[];
                if (values != null && values.Length == 2)
                {
                    SaveChangesTo(values[0], values[1]);
                }
            };
            CallEditMonitorCommand.ExecuteCommand += o =>
            {
                if (null != o)
                {
                    CellMonitor item = o as CellMonitor;
                    if (null != item)
                    {
                        ExecutableContent <CellMonitor> executeable = new ExecutableContent <CellMonitor>()
                        {
                            Value   = item,
                            Command = SaveMonitorChangesCommand
                        };
                        Messenger.Default.Send(executeable, Token);
                    }
                }
            };
        }