private void ListAccessoryDecoders() { try { grdAcc.BeginUpdate(); grdAccView.OptionsBehavior.AutoPopulateColumns = false; grdAccView.Columns.Clear(); grdAccView.Columns.Add(new GridColumn() { Caption = "Device", Visible = true, FieldName = "Name" }); grdAccView.Columns.Add(new GridColumn() { Caption = "Connections", Visible = true, FieldName = "ConnectionsCount", Width = 45 }); grdAccView.Columns["ConnectionsCount"].AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; grdAccView.Columns["ConnectionsCount"].AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; grdAcc.DataSource = AccessoryDecoder.FindAll(); grdAcc.EndUpdate(); } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void CmdOk_Click(object sender, EventArgs e) { if (!this.MapViewToModel()) { return; } try { Cursor.Current = Cursors.WaitCursor; AccessoryDecoder.Save(this.Decoder); // Add the decoder into the project if (!OTCContext.Project.AccessoryDecoders.Contains(this.Decoder)) { OTCContext.Project.AccessoryDecoders.Add(this.Decoder); } this.DialogResult = DialogResult.OK; this.Close(); } catch (Exception ex) { Cursor.Current = Cursors.Default; MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { Cursor.Current = Cursors.Default; } }
private void ListComboLists() { ImageComboBoxItem item; List <string> models = new List <string>(); List <string> modules = new List <string>(); // Fill manufacturers list foreach (Manufacturer manufacturer in Manufacturer.FindAll()) { item = new ImageComboBoxItem(); item.Value = manufacturer; item.Description = manufacturer.Name; item.ImageIndex = 1; cboManufacturer.Properties.Items.Add(item); } // Fill models list foreach (AccessoryDecoder decoder in AccessoryDecoder.FindAll()) { if (!string.IsNullOrEmpty(decoder.Model) && !models.Contains(decoder.Model)) { item = new ImageComboBoxItem(); item.Value = decoder.Model; item.Description = decoder.Model; item.ImageIndex = 2; cboModel.Properties.Items.Add(item); } } }
private void SetModelList(string selected) { ImageComboBoxItem item; List <string> models = new List <string>(); // Fill models list cboModel.Properties.Items.Clear(); foreach (AccessoryDecoder decoder in AccessoryDecoder.FindAll()) { if (!string.IsNullOrEmpty(decoder.Model) && !models.Contains(decoder.Model)) { item = new ImageComboBoxItem(); item.Value = decoder.Model; item.Description = decoder.Model; item.ImageIndex = 2; cboModel.Properties.Items.Add(item); models.Add(decoder.Model); } } if (selected != null) { cboModel.Text = selected; } }
private void DigitalReport_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) { this.ReportData = AccessoryDecoder.FindByConnection(); this.DataSource = ReportData; this.DataMember = "Switchboards"; }
public override void Refresh() { try { grdModule.BeginUpdate(); grdModuleView.Columns.Clear(); grdModuleView.Columns.Add(new GridColumn() { Caption = "Device", Visible = true, FieldName = "Name" }); grdModuleView.Columns.Add(new GridColumn() { Caption = "Connections", Visible = true, FieldName = "ConnectionsCount", Width = 45 }); grdModuleView.Columns["ConnectionsCount"].AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; grdModuleView.Columns["ConnectionsCount"].AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; grdModule.DataSource = AccessoryDecoder.FindAll(); grdModule.EndUpdate(); } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } base.Refresh(); }
public void DeleteDecoder() { if (grdModuleView.SelectedRowsCount <= 0) { MessageBox.Show("You must select the control device you want to delete.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (!(grdModuleView.GetRow(grdModuleView.GetSelectedRows()[0]) is AccessoryDecoder decoder)) { return; } if (MessageBox.Show("Are you sure you want to delete the module " + decoder.Name + " and all its related data and configurations?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.No) { return; } try { AccessoryDecoder.Delete(decoder.ID); // Also remove the module in current project OTCContext.Project.AccessoryDecoders.Remove(decoder); this.Refresh(); } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void CmdCancel_Click(object sender, EventArgs e) { this.SelectedDecoder = null; this.SelectedConnection = null; this.DialogResult = DialogResult.Cancel; this.Close(); }
internal void EditItem() { if (tlsDecoders.Selection.Count <= 0) { MessageBox.Show("No items selected.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } TreeListNode node = tlsDecoders.Selection[0]; if (node == null) { return; } if (node.Tag is AccessoryDecoder) { AccessoryDecoder decoder = node.Tag as AccessoryDecoder; if (decoder == null) { return; } AccessoryDecoderEditorView form = new AccessoryDecoderEditorView(decoder); if (form.ShowDialog(this) == DialogResult.OK) { this.RefreshTreeList(); } } else if (node.Tag is FeedbackEncoder) { FeedbackEncoder encoder = node.Tag as FeedbackEncoder; if (encoder == null) { return; } FeedbackEncoderEditorView form = new FeedbackEncoderEditorView(encoder); if (form.ShowDialog(this) == DialogResult.OK) { this.RefreshTreeList(); } } else if (node.Tag is Module) { Module module = node.Tag as Module; if (module == null) { return; } ModuleEditorView form = new ModuleEditorView(module); if (form.ShowDialog(this) == DialogResult.OK) { this.RefreshTreeList(); } } }
private void DigitalConnectionsReport_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) { int i = NumericUtils.ToInteger(lblSwitchboardId.Text); // DigitalConnectionsGroup.GroupFields.Add(new GroupField("Name")); DigitalConnectionsReport.DataSource = AccessoryDecoder.FindBySwitchboard(i); DigitalConnectionsReport.DataMember = "AccessoryConnections"; }
private void GrdDecodersView_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e) { this.SelectedDecoder = grdDecodersView.GetRow(e.RowHandle) as AccessoryDecoder; this.RefreshDecoderOutputs(); this.SelectedDecoder = null; txtAddress.EditValue = String.Empty; txtSwitchTime.EditValue = String.Empty; cmdOK.Enabled = false; grpDigital.Enabled = false; }
private void RefreshListDecoders() { grdDecoders.BeginUpdate(); grdDecodersView.OptionsBehavior.AutoPopulateColumns = false; grdDecoders.DataSource = null; if (grdDecodersView.Columns.Count <= 0) { grdDecodersView.Columns.Clear(); grdDecodersView.OptionsBehavior.AutoPopulateColumns = false; grdDecodersView.Columns.Add(new GridColumn() { Caption = "ID", Visible = false, FieldName = "ID" }); grdDecodersView.Columns.Add(new GridColumn() { Caption = "Name", Visible = true, FieldName = "Name" }); grdDecodersView.Columns.Add(new GridColumn() { Caption = "Outputs", Visible = true, FieldName = "Outputs", Width = 30 }); grdDecodersView.Columns.Add(new GridColumn() { Caption = "Used", Visible = true, FieldName = "ConnectionsCount", Width = 30 }); grdDecodersView.Columns["Outputs"].AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; grdDecodersView.Columns["Outputs"].AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; grdDecodersView.Columns["ConnectionsCount"].AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; grdDecodersView.Columns["ConnectionsCount"].AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; } grdDecoders.DataSource = OTCContext.Project.AccessoryDecoders; grdDecoders.EndUpdate(); // Preselect a decoder if connection is selected if (this.SelectedConnection != null) { int rowHandle = grdDecodersView.LocateByValue("ID", this.SelectedConnection.Decoder.ID); if (rowHandle != DevExpress.XtraGrid.GridControl.InvalidRowHandle) { this.SelectedDecoder = this.SelectedConnection.Decoder; grdDecodersView.FocusedRowHandle = rowHandle; } } else { grdDecodersView.ClearSelection(); } }
internal void DecoderProgram() { if (tlsDecoders.Selection.Count <= 0) { MessageBox.Show("No items selected.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } TreeListNode node = tlsDecoders.Selection[0]; if (node == null) { return; } try { if (node.Tag is AccessoryDecoder) { AccessoryDecoder decoder = node.Tag as AccessoryDecoder; if (decoder != null) { if (decoder.Manufacturer.ID != 0) { MessageBox.Show("Only Railwaymania accessory decoders can be programmed by this command.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { DecoderSketch sketch = new DecoderSketch(decoder); sketch.Create(false); sketch.Build(StudioContext.UI.LogConsoleControl); } } } else if (node.Tag is EmotionModule) { EmotionModule module = node.Tag as EmotionModule; if (module != null) { EMotionSketch sketch = new EMotionSketch(module); sketch.Create(false); sketch.Build(StudioContext.UI.LogConsoleControl); } } } catch (Exception ex) { Logger.LogError(this, ex); MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void CmdOk_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(txtName.Text)) { MessageBox.Show("You must provide a valid name for the decoder.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); txtName.Focus(); return; } else if (int.Parse(txtOutputs.Text) <= 0) { MessageBox.Show("Invalid number of decoder digital outputs.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); txtOutputs.SelectAll(); txtOutputs.Focus(); return; } Cursor.Current = Cursors.WaitCursor; this.Decoder.Project = OTCContext.Project; this.Decoder.Name = txtName.Text.Trim(); this.Decoder.Manufacturer = cboManufacturer.EditValue as Manufacturer; this.Decoder.Model = cboModel.Text.Trim(); this.Decoder.Section = cboSection.SelectedSection; this.Decoder.StartAddress = (int)nudAddress.Value; this.Decoder.Outputs = int.Parse(txtOutputs.Text); this.Decoder.Notes = txtNotes.Text.Trim(); try { AccessoryDecoder.Save(this.Decoder); // Add the decoder into the project if (!OTCContext.Project.AccessoryDecoders.Contains(this.Decoder)) { OTCContext.Project.AccessoryDecoders.Add(this.Decoder); } this.DialogResult = DialogResult.OK; this.Close(); } catch (Exception ex) { Cursor.Current = Cursors.Default; MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { Cursor.Current = Cursors.Default; } }
private void MapModelToView(AccessoryDecoder decoder) { this.Decoder = decoder; txtName.Text = this.Decoder.Name; cboManufacturer.SetSelectedElement(this.Decoder.Manufacturer); cboSection.SetSelectedElement(this.Decoder.Module); lblOutputsCount.Text = this.Decoder.Outputs.Count.ToString(); txtNotes.Text = this.Decoder.Notes; this.SetModelList(this.Decoder.Model); this.ListOutputs(); }
/// <summary> /// Returns a new instance of <see cref="AccessoryDecoderEditorView"/>. /// </summary> /// <param name="settings">Current application settings.</param> /// <param name="decoder">The decoder to edit in the editor dialogue.</param> public AccessoryDecoderEditorView(AccessoryDecoder decoder) { InitializeComponent(); this.Decoder = decoder; ListComboLists(); ListOutputs(); txtName.Text = this.Decoder.Name; cboModel.Text = this.Decoder.Model; cboManufacturer.EditValue = this.Decoder.Manufacturer; cboSection.SetSelectedElement(this.Decoder.Section); nudAddress.EditValue = this.Decoder.StartAddress; txtOutputs.EditValue = this.Decoder.Outputs; txtNotes.Text = this.Decoder.Notes; txtOutputs.Enabled = false; }
private void WizardControl_FinishClick(object sender, System.ComponentModel.CancelEventArgs e) { this.Decoder = new AccessoryDecoder(this.DecoderOutputs); for (int i = 0; i < this.DecoderOutputs; i++) { if (this.StartAddress > 0) { this.Decoder.Outputs[i].Address = this.StartAddress + i; } else { this.Decoder.Outputs[i].Address = 0; } this.Decoder.Outputs[i].Mode = this.OutputMode; this.Decoder.Outputs[i].DurationB = 500; } this.DialogResult = DialogResult.OK; this.Close(); }
private void MapModelToView(AccessoryDecoder decoder) { AccessoryDecoderOutput output; this.Decoder = decoder; txtName.Text = this.Decoder.Name; cboModel.Text = "Railwaymania EasyConnect Decoder"; // cboManufacturer.Text = "Railwaymania"; // TODO: Use created manufacturer cboSection.SetSelectedElement(this.Decoder.Module); txtNotes.Text = this.Decoder.Notes; output = this.Decoder.GetOutputByIndex(1); if (output != null) { chkOutput1.Checked = true; spnAddress1.Value = output.Address; } cboModel.Enabled = false; cboManufacturer.Enabled = false; }
private void CmdDecoderDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { try { if (tabDecoder.SelectedTabPage == tabDecoderAcc) { if (!(this.GetSelectedResource() is AccessoryDecoder accDecoder)) { return; } if (MessageBox.Show("Are you sure you want to remove the selected decoder?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { AccessoryDecoder.Delete(accDecoder); this.ListAccessoryDecoders(); } } else { if (!(this.GetSelectedResource() is FeedbackEncoder fbEncoder)) { return; } if (MessageBox.Show("Are you sure you want to remove the selected decoder?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { FeedbackEncoder.Delete(fbEncoder); this.ListFeedbackEncoders(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Returns a new instance of <see cref="DecoderSketch"/>. /// </summary> /// <param name="accessoryDecoder">The decoder of accessories for which the sketch is generated.</param> public DecoderSketch(AccessoryDecoder accessoryDecoder) { this.AccessoryDecoder = accessoryDecoder; }
/// <summary> /// Returns a new instance of <see cref="AccessoryDecoderEditorView"/>. /// </summary> /// <param name="decoder">The decoder to edit in the editor dialogue.</param> public AccessoryDecoderEditorView(AccessoryDecoder decoder) { InitializeComponent(); MapModelToView(decoder); }
internal void DeleteItem() { if (tlsDecoders.Selection.Count <= 0) { MessageBox.Show("No items selected.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } TreeListNode node = tlsDecoders.Selection[0]; if (node == null) { return; } try { if (node.Tag is AccessoryDecoder) { AccessoryDecoder decoder = node.Tag as AccessoryDecoder; if (decoder == null) { return; } if (MessageBox.Show("Are you sure you want to delete the accessory decoder " + decoder.Name + "?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { AccessoryDecoder.Delete(decoder); this.RefreshTreeList(); } } else if (node.Tag is FeedbackEncoder) { FeedbackEncoder encoder = node.Tag as FeedbackEncoder; if (encoder == null) { return; } if (MessageBox.Show("Are you sure you want to delete the feedback encoder " + encoder.Name + "?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { FeedbackEncoder.Delete(encoder); this.RefreshTreeList(); } } else if (node.Tag is Module) { Module module = node.Tag as Module; if (module == null) { return; } if (MessageBox.Show("Are you sure you want to remove the layout module " + module.Name + "?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { Module.Delete(module); this.RefreshTreeList(); } } } catch (Exception ex) { MessageBox.Show(Logger.LogError(this, ex), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }