Пример #1
0
        public static ScalesChannelViewModel LoadFromDb(int id)
        {
            ScalesChannelViewModel result = null;

            using (LiteDatabase dba = new LiteDatabase(string.Format("filename={0};", Program.dbPath)))
            {
                ScalesDescriptor sd = dba.GetCollection <ScalesDescriptor>("scales").FindById(id);
                if (sd != null)
                {
                    ScalesChannelViewModel tmp = new ScalesChannelViewModel();
                    tmp.Load(sd);
                    result = tmp;
                }
            }

            return(result);
        }
Пример #2
0
        protected void Setup(int id)
        {
            source.Add(ScalesChannelViewModel.LoadFromDb(id));

            reg_stop_bits.Properties.Items.AddEnum <System.IO.Ports.StopBits>();
            reg_parity.Properties.Items.AddEnum <System.IO.Ports.Parity>();

            reg_code.DataBindings.Add(new System.Windows.Forms.Binding("EditValue", source, "Code", true, DataSourceUpdateMode.OnValidation));
            reg_name.DataBindings.Add(new System.Windows.Forms.Binding("EditValue", source, "Name", true, DataSourceUpdateMode.OnValidation));
            reg_decoder.DataBindings.Add(new System.Windows.Forms.Binding("EditValue", source, "Decoder", true, DataSourceUpdateMode.OnValidation));
            reg_active.DataBindings.Add(new System.Windows.Forms.Binding("EditValue", source, "Active", true, DataSourceUpdateMode.OnValidation));
            reg_description.DataBindings.Add(new System.Windows.Forms.Binding("EditValue", source, "Description", true, DataSourceUpdateMode.OnValidation));
            reg_trigger_empty.DataBindings.Add(new System.Windows.Forms.Binding("EditValue", source, "TriggerEmpty", true, DataSourceUpdateMode.OnValidation));
            reg_exposure.DataBindings.Add(new System.Windows.Forms.Binding("EditValue", source, "ExposureMilliseconds", true, DataSourceUpdateMode.OnValidation));
            reg_timeout.DataBindings.Add(new System.Windows.Forms.Binding("EditValue", source, "TimeoutMilliseconds", true, DataSourceUpdateMode.OnValidation));

            reg_address.DataBindings.Add(new System.Windows.Forms.Binding("EditValue", source, "Address", true, DataSourceUpdateMode.OnValidation));
            reg_port_name.DataBindings.Add(new System.Windows.Forms.Binding("EditValue", source, "PortName", true, DataSourceUpdateMode.OnValidation));
            reg_baud_rate.DataBindings.Add(new System.Windows.Forms.Binding("EditValue", source, "BaudRate", true, DataSourceUpdateMode.OnValidation));
            reg_data_bits.DataBindings.Add(new System.Windows.Forms.Binding("EditValue", source, "DataBits", true, DataSourceUpdateMode.OnValidation));
            reg_parity.DataBindings.Add(new System.Windows.Forms.Binding("EditValue", source, "Parity", true, DataSourceUpdateMode.OnValidation));
            reg_stop_bits.DataBindings.Add(new System.Windows.Forms.Binding("EditValue", source, "StopBits", true, DataSourceUpdateMode.OnValidation));

            reg_type.EditValueChanging += (sender, e) => SetupSettings(Convert.ToString(e.NewValue));
            reg_type.DataBindings.Add(new System.Windows.Forms.Binding("EditValue", source, "SettingsType", true, DataSourceUpdateMode.OnPropertyChanged));

            SetupSettings(source[0].SettingsType);

            btnOk.Click += (sender, e) =>
            {
                var vr = ViewModel.Validate();
                if (vr.Count() != 0)
                {
                    String errors = String.Concat((from tmp in vr select tmp.Message + "\r\n"));
                    XtraMessageBox.Show(string.Format("Данные содержат ошибки:\r\n{0}", errors), Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                ViewModel.Update();
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            };
        }