private void bSave_Click(object sender, EventArgs e) { var messagebox = System.Windows.Forms.MessageBox.Show("Are you sure you want to save your changes?", "Save Information", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (messagebox == DialogResult.Yes) { var controller = new CommunicatorController(); UpdateCommunicatorObject(); controller.SaveCommunicator(_communicator); } }
private void add_bSaveSource_Click(object sender, EventArgs e) { if (_communicator is DatabaseCommunicator) { _communicator = new DatabaseCommunicator() { DbType = (DatabaseType) add_cbDatabaseType.SelectedItem, ValueType = (Models.ValueType) add_cbValueType.SelectedItem, ConnectionString = add_tConnectionString.Text, Query = add_tQuery.Text, StartChar = GetStartChar(), EndChar = GetEndChar(), Device = _device, //Id = GetNextIdNumber(), Inbound = add_rbCommInbound.Checked, Type = CommunicatorType.Database, Action = null }; } else if (_communicator is SerialCommunicator) { _communicator = new SerialCommunicator() { StartChar = GetStartChar(), EndChar = GetEndChar(), ValueType = (Models.ValueType) add_cbValueType.SelectedItem, BaudRate = Convert.ToInt32(add_tBaudRate.Text), ComPort = add_cbComPort.SelectedItem.ToString(), DataBits = Convert.ToByte(add_tDataBits.Text), IsDTR = add_cbDtr.Checked, IsRTS = add_cbRts.Checked, Device = _device, Inbound = add_rbCommInbound.Checked, Type = CommunicatorType.Serial, Action = null //Id = GetNextIdNumber() }; } else if (_communicator is FileCommunicator) { _communicator = new FileCommunicator() { FilePath = add_tFilePath.Text, ValueType = (Models.ValueType) add_cbValueType.SelectedItem, StartChar = GetStartChar(), EndChar = GetEndChar(), Device = _device, Type = CommunicatorType.FlatFile, Inbound = add_rbCommInbound.Checked, Action = null //Id = GetNextIdNumber() }; } _communicator.Device = _device; var _controller = new CommunicatorController(); var Id = _controller.SaveCommunicator(_communicator); if (Id != null) _communicator.Id = (int) Id; DebugOutput.Print($"a new Communicator was created with ID {_communicator.Id.ToString()}"); this.Close(); }
private void modcomms_bSaveComm_Click(object sender, EventArgs e) { //Collect the selected item and store globally _communicator = (Communicator)modcomms_lbComms.SelectedItem; /* * Preparing all of the standard (abstract) Communicator fields */ //Id does not update _communicator.StartChar = Convert.ToInt32(modcomms_tStart.Text); _communicator.EndChar = Convert.ToInt32(modcomms_tEnd.Text); _communicator.LastReadTime = Convert.ToDateTime(modcomms_tLastReadTime.Text); //CommType does not update _communicator.ValueType = (Models.ValueType)modcomms_cbValueType.SelectedItem; _communicator.Inbound = modcomms_rbInbound.Checked; /* * Preparing FileCommunicator fields */ if (_communicator is FileCommunicator) { var temp = (FileCommunicator)_communicator; temp.FilePath = modcomms_tFilePath.Text; //Store this in the global variable. _communicator = temp; } else if (_communicator is SerialCommunicator) { var temp = (SerialCommunicator)_communicator; temp.ComPort = modcomms_cbComPort.SelectedItem.ToString(); temp.BaudRate = Convert.ToInt32(modcomms_tBaudRate.Text); temp.DataBits = Convert.ToByte(modcomms_tDataBits.Text); temp.IsDTR = modcomms_cbDtr.Checked; temp.IsRTS = modcomms_cbRts.Checked; //Store this in the global variable. _communicator = temp; } else if (_communicator is DatabaseCommunicator) { var temp = (DatabaseCommunicator)_communicator; temp.ConnectionString = modcomms_tConnectionString.Text; temp.Query = modcomms_tQuery.Text; temp.DbType = (Models.DatabaseType)modcomms_cbDatabaseType.SelectedItem; //Store this in the global variable. _communicator = temp; } //Save the Communicator var controller = new CommunicatorController(); controller.SaveCommunicator(_communicator); //Inform user. DebugOutput.Print("Successfully updated Communicator settings for ", _communicator.ToString()); }