public void RemoveModel(ModbusTableModel model = null, int index = -1)
 {
     _ArguemntsTranslate(ref model, ref index);
     models.Remove(model);
     if (model == Current)
     {
         if (currentindex < models.Count)
         {
             Current = models[currentindex];
         }
         else if (models.Count > 0)
         {
             Current = models[models.Count - 1];
         }
         else
         {
             Current = null;
         }
     }
     else
     {
         Current = model;
     }
     ModelChanged(this, new RoutedEventArgs());
     IsModify = true;
 }
 public void AddModel(ModbusTableModel model = null, int index = -1)
 {
     if (model == null)
     {
         if (dialog == null)
         {
             InitializeDialog();
             DialogType             = DIALOG_CREATE;
             dialog.TB_Name.Text    = String.Empty;
             dialog.TB_Comment.Text = String.Empty;
             dialog.ShowDialog();
         }
         return;
     }
     if (index < 0 && Current != null)
     {
         index = currentindex + 1;
     }
     if (index < 0)
     {
         models.Add(model);
     }
     else
     {
         models.Insert(index, model);
     }
     ModelChanged(this, new RoutedEventArgs());
     IsModify = true;
     Current  = model;
 }
 public void RenameModel(ModbusTableModel model = null, int index = -1)
 {
     _ArguemntsTranslate(ref model, ref index);
     Current = model;
     if (dialog == null)
     {
         InitializeDialog();
         DialogType             = DIALOG_RENAME;
         dialog.TB_Name.Text    = Current.Name;
         dialog.TB_Comment.Text = Current.Comment;
         dialog.ShowDialog();
     }
 }
        public void Load(XElement xele)
        {
            models.Clear();
            IEnumerable <XElement> xeles_model = xele.Elements("ModbusTableModel");

            foreach (XElement xele_model in xeles_model)
            {
                ModbusTableModel model = new ModbusTableModel();
                model.Load(xele_model);
                models.Add(model);
            }
            Current = models.FirstOrDefault();
            ModelChanged(this, new RoutedEventArgs());
        }
Example #5
0
        static private void Read(ModbusTableViewModel mtvmodel)
        {
            int sz = ReadE16();

            sz += eid;
            while (eid < sz)
            {
                int mid = (int)edata[eid++];
                ModbusTableModel mtmodel = new ModbusTableModel();
                mtmodel.Name = ReadTextE8();
                if ((option & OPTION_COMMENT) != 0)
                {
                    mtmodel.Comment = ReadTextE8();
                }
            }
        }
        private void OnDialogEnsureClick(object sender, RoutedEventArgs e)
        {
            string name    = dialog.TB_Name.Text;
            string comment = dialog.TB_Comment.Text;

            if (name.Equals(String.Empty))
            {
                LocalizedMessageBox.Show(Properties.Resources.Message_Name_Needed, LocalizedMessageIcon.Information);
                return;
            }
            IEnumerable <ModbusTableModel> fit = models.Where(
                (ModbusTableModel model) => { return(model.Name.Equals(name)); });

            switch (DialogType)
            {
            case DIALOG_CREATE:
                if (fit.Count() > 0)
                {
                    LocalizedMessageBox.Show(Properties.Resources.Message_Table_Exist, LocalizedMessageIcon.Warning);
                }
                else
                {
                    ModbusTableModel model = new ModbusTableModel();
                    model.Name    = name;
                    model.Comment = comment;
                    AddModel(model, currentindex);
                    dialog.Close();
                }
                break;

            case DIALOG_RENAME:
                if (fit.Count() > 0 && fit.First() != Current)
                {
                    LocalizedMessageBox.Show(Properties.Resources.Message_Table_Exist, LocalizedMessageIcon.Warning);
                }
                else
                {
                    Current.Name    = name;
                    Current.Comment = comment;
                    ModelChanged(this, e);
                    IsModify = true;
                    dialog.Close();
                }
                break;
            }
        }
 private void _ArguemntsTranslate(ref ModbusTableModel model, ref int index)
 {
     if (model == null && index >= 0 && index < models.Count)
     {
         model = models[index];
     }
     else if (model != null && models.Contains(model))
     {
         index = models.IndexOf(model);
     }
     else if (index < 0 && currentmodel != null)
     {
         model = currentmodel;
         index = currentindex;
     }
     else
     {
         throw new ArgumentException();
     }
 }
        public void MoveModel(ModbusTableModel model = null, int index = -1, MOVE_DIRECTION direct = MOVE_DIRECTION.UP)
        {
            _ArguemntsTranslate(ref model, ref index);
            switch (direct)
            {
            case MOVE_DIRECTION.UP:
                if (index > 0)
                {
                    RemoveModel(model);
                    AddModel(model, index - 1);
                }
                break;

            case MOVE_DIRECTION.DOWN:
                if (index < Models.Count() - 1)
                {
                    RemoveModel(model);
                    AddModel(model, index + 1);
                }
                break;
            }
        }