public void MoveTable(ModbusTable table = null, int index = -1, MOVE_DIRECTION direct = MOVE_DIRECTION.UP) { if (Current != null) { int _currentindex = Current.Current; Current.Move(table, index, direct); switch (direct) { case MOVE_DIRECTION.UP: if (--_currentindex >= 0) { DG_Table.SelectedIndex = _currentindex; } break; case MOVE_DIRECTION.DOWN: if (++_currentindex < Tables.Count()) { DG_Table.SelectedIndex = _currentindex; } break; } Current = Current; IsModify = true; } }
public void AddTable(ModbusTable table = null, int index = -1) { if (Current != null) { Current.Add(table, index); Current = Current; IsModify = true; } }
public void RemoveTable(ModbusTable table = null, int index = -1) { if (Current != null) { Current.Remove(table, index); IsModify = true; Current = Current; } }
private void Update(DataGridCell dgcell, bool?isselected = null) { ModbusTable mtable = (ModbusTable)(dgcell.DataContext); DataGridColumn dgcolumn = dgcell.Column; bool isvalid = false; if (dgcolumn.Header.ToString() == Properties.Resources.Modbus_Slave_Station_Number) { isvalid = mtable.SlaveID_IsValid; } else if (dgcolumn.Header.ToString() == Properties.Resources.Modbus_Function_Code) { isvalid = mtable.HandleCode_IsValid; } else if (dgcolumn.Header.ToString() == Properties.Resources.Modbus_Slave_Register) { isvalid = mtable.SlaveRegister_IsValid; } else if (dgcolumn.Header.ToString() == Properties.Resources.Modbus_Slave_Length) { isvalid = mtable.SlaveCount_IsValid; } else if (dgcolumn.Header.ToString() == Properties.Resources.Modbus_Master_Register) { isvalid = mtable.MasterRegister_IsValid; } if (isselected == null) { isselected = dgcell.IsSelected; } if (isselected == true && isvalid) { dgcell.Background = Brushes.Blue; dgcell.Foreground = Brushes.White; dgcell.FontWeight = FontWeights.Heavy; } else if (isselected == true && !isvalid) { dgcell.Background = Brushes.Blue; dgcell.Foreground = Brushes.OrangeRed; dgcell.FontWeight = FontWeights.Heavy; } else if (isselected == false && isvalid) { dgcell.Background = Brushes.White; dgcell.Foreground = Brushes.Black; dgcell.FontWeight = FontWeights.Light; } else if (isselected == false && !isvalid) { dgcell.Background = Brushes.Red; dgcell.Foreground = Brushes.Black; dgcell.FontWeight = FontWeights.Light; } }
private void Update(DataGridRow dgrow, bool?isselected = null) { ModbusTable mtable = (ModbusTable)(dgrow.DataContext); foreach (DataGridColumn dgcol in DG_Table.Columns) { FrameworkElement fele = dgcol.GetCellContent(dgrow); if (fele.Parent is DataGridCell) { DataGridCell dgcell = (DataGridCell)(fele.Parent); Update(dgcell, isselected); } } }
public void Load(XElement xele) { Name = xele.Attribute("Name").Value; Comment = xele.Attribute("Comment").Value; tables.Clear(); IEnumerable <XElement> xeles_table = xele.Elements("ModbusTable"); foreach (XElement xele_table in xeles_table) { ModbusTable table = new ModbusTable(); table.SlaveID = xele_table.Attribute("SlaveID").Value; table.HandleCode = xele_table.Attribute("HandleCode").Value; table.SlaveRegister = xele_table.Attribute("SlaveRegister").Value; table.SlaveCount = xele_table.Attribute("SlaveCount").Value; table.MasteRegister = xele_table.Attribute("MasteRegister").Value; tables.Add(table); } }
private void _ArguemntsTranslate(ref ModbusTable table, ref int index) { if (table == null && index >= 0 && index < tables.Count) { table = tables[index]; } else if (table != null && tables.Contains(table)) { index = tables.IndexOf(table); } else if (index < 0 && currenttable != null) { table = currenttable; index = currentindex; } else { throw new ArgumentException(); } }
private void DataGridCell_LostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) { DataGridCell dgcell = (DataGridCell)sender; ModbusTable mtable = (ModbusTable)(dgcell.DataContext); DataGridColumn dgcolumn = dgcell.Column; string text = String.Empty; if (dgcell.Content is TextBox) { text = ((TextBox)(dgcell.Content)).Text; } if (dgcell.Content is TextBlock) { text = ((TextBlock)(dgcell.Content)).Text; } if (dgcell.Content is ComboBox) { text = ((ComboBox)(dgcell.Content)).Text; } if (dgcolumn.Header.ToString() == Properties.Resources.Modbus_Slave_Station_Number) { mtable.SlaveID = text; } else if (dgcolumn.Header.ToString() == Properties.Resources.Modbus_Function_Code) { mtable.HandleCode = text; } else if (dgcolumn.Header.ToString() == Properties.Resources.Modbus_Slave_Register) { mtable.SlaveRegister = text; } else if (dgcolumn.Header.ToString() == Properties.Resources.Modbus_Slave_Length) { mtable.SlaveCount = text; } else if (dgcolumn.Header.ToString() == Properties.Resources.Modbus_Master_Register) { mtable.MasteRegister = text; } Update(dgcell); }
public void Add(ModbusTable table = null, int index = -1) { if (index < 0) { index = Current; } if (table == null) { table = new ModbusTable(); } if (index < 0) { tables.Add(table); index = tables.Count - 1; } else { tables.Insert(index, table); } Current = index; }
public void Move(ModbusTable table = null, int index = -1, MOVE_DIRECTION direct = MOVE_DIRECTION.UP) { _ArguemntsTranslate(ref table, ref index); switch (direct) { case MOVE_DIRECTION.UP: if (index > 0) { tables.Remove(table); tables.Insert(index - 1, table); Current = index - 1; } break; case MOVE_DIRECTION.DOWN: if (index < tables.Count - 1) { tables.Remove(table); tables.Insert(index + 1, table); Current = index + 1; } break; } }
public void Remove(ModbusTable table = null, int index = -1) { _ArguemntsTranslate(ref table, ref index); tables.Remove(table); Current = Math.Max(0, Math.Min(Current, tables.Count - 1)); }