private void SetDeviceCommunicators_Load(object sender, EventArgs e) { var _controller = new CommunicatorController(); IEnumerable<Communicator> commsList = _controller.GetAllFileCommunicators(); foreach (var comm in commsList) { cbReader.Items.Add(comm); cbWriter.Items.Add(comm); } }
public AddAction(Models.Rule rule) { //Initialise InitializeComponent(); _rule = rule; //If Action already created, load the info. _action = rule.Action; //If Communicator already created, load the info. if (_action != null) { var controller = new CommunicatorController(); _comm = controller.GetAllCommunicators().FirstOrDefault(c => c.Id == rule.Action.CommunicatorId); } }
private void bDelete_Click(object sender, EventArgs e) { var messagebox = System.Windows.Forms.MessageBox.Show("Are you sure you wish to delete Communicator ID " + _communicator.Id + "?","Delete Communicator",MessageBoxButtons.YesNo,MessageBoxIcon.Exclamation); if (messagebox == DialogResult.Yes) { var controller = new CommunicatorController(); // TODO delete the comms in the controller...... System.Windows.Forms.MessageBox.Show("Deleted the Communicator successfully."); } else { System.Windows.Forms.MessageBox.Show("Phew - nothing was deleted..."); } }
/// <summary> /// Returns a list of Communicator objects for the given Device via the /// parametised Device ID. /// </summary> /// <param name="id"></param> /// <returns></returns> public IEnumerable<Communicator> GetCommunicatorsForDevice(int id) { CommunicatorController commCont = new CommunicatorController(); return commCont.GetAllCommunicators().Where(comm=>comm.Id==id); }
private void DataBoard_Load(object sender, EventArgs e) { add_cbCommType.DataSource = Enum.GetValues(typeof (Models.CommunicatorType)); add_cbValueType.DataSource = Enum.GetValues(typeof (Models.ValueType)); add_cbDatabaseType.DataSource = Enum.GetValues(typeof (Models.DatabaseType)); add_cbComPort.DataSource = SerialPort.GetPortNames(); add_cbRuleCheckValue.DataSource = Enum.GetValues(typeof (Models.ValueType)); //add_cbRuleType.DataSource = Enum.GetValues(typeof (Models.RuleType)); //Adds known rules for the device to the list box. var controller = new RuleController(); add_cbRule.Items.Clear(); foreach (Models.Rule rule in controller.RetrieveRulesForDevice(_device.Id)) add_cbRule.Items.Add(rule); //Adds outbound comms to the Action list box. var commController = new CommunicatorController(); add_cbCommunicatorDestination.Items.Clear(); List<Communicator> allComms = commController.GetAllCommunicators().Where(c => c.Device.Id == _device.Id && c.Inbound == false).ToList(); add_cbCommunicatorDestination.Items.AddRange(allComms.ToArray()); }
private void add_cbRule_SelectedIndexChanged(object sender, EventArgs e) { var devController = new DeviceController(); var commController = new CommunicatorController(); _rule = (Models.Rule)add_cbRule.SelectedItem; _rule.Device = devController.RetrieveDevice(_rule.DeviceId); _device = _rule.Device; //add_cbCommunicatorDestination.Items.AddRange(commController.GetAllCommunicators().Where(com=>com.Device.Id==_rule.DeviceId && com.Inbound==false).ToArray()); }
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 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 modrules_bSetAction_Click(object sender, EventArgs e) { //Save the Rule as it stands. modrules_tSave.PerformClick(); var controller = new ActionController(); if (controller.RetrieveActionsForRule(_rule.Id).Any()) { //Get the actual Action. var action = controller.RetrieveActionsForRule(_rule.Id).FirstOrDefault(); _action = action; //Load the values required. modact_cEnabled.Checked = action.Enabled; modact_tValue.Text = action.OutputValue; modact_tRule.Text = _rule.ToString(); //Download the required communicator var commController = new CommunicatorController(); var comm = commController.GetAllCommunicators().FirstOrDefault(c => c.Id == action.CommunicatorId); if (comm != null) { _communicator = comm; _action.Communicator = comm; modact_tComm.Text = comm.ToString(); } else { modact_tComm.Text = ""; } //Actions exist. pTabPanel.SelectedTab = pModifyActions; } else { var db = new DataBoard(_communicator,_selectedDevice); db.GoToActionPage(_rule); db.ShowDialog(); _action = db.GetAction(); DebugOutput.Print("Changes made in the Data Manager are saved."); } }
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()); }
private void modify_bComms_Click(object sender, EventArgs e) { try { //Loads the relevant communicators. var controller = new CommunicatorController(); modcomms_lbComms.Items.Clear(); modcomms_lbComms.Items.AddRange( controller.GetAllCommunicators().Where(c => c.Device.Id == _selectedDevice.Id).ToArray()); if (modcomms_lbComms.Items.Count > 0) { //Select the first element modcomms_lbComms.SelectedItem = modcomms_lbComms.Items[0]; //Shows the modify tab. pTabPanel.SelectedTab = pModifyCommunicators; } else { var msg = System.Windows.Forms.MessageBox.Show( "There are no Communicators for this Device.", "No Communicators Available", MessageBoxButtons.OK, MessageBoxIcon.Hand); // -------- Create new communicator ---------- //Create and display the DataBoard form. var window = new DataBoard(null, _selectedDevice); window.GoToCommunicatorPage(); window.ShowDialog(); //Get the Comm object created. _communicator = window.GetCommunicator(); } } catch (Exception ex) { DebugOutput.Print("Could not load/store/update information for selected Device", ex.Message); } }
private void UpdateStartLabels() { var comm_controller = new CommunicatorController(); var rule_controller = new RuleController(); var acti_controller = new ActionController(); try { //Update labels. add_lSource.Text = $"{comm_controller.CountCommunicatorsForDevice(_communicator.Device.Id)} Sources..."; add_lRules.Text = $"{rule_controller.RetrieveRulesForDevice(_selectedDevice.Id).Count()} Rules..."; } catch { //Update labels. add_lSource.Text = $"0 Sources..."; add_lRules.Text = $"0 Rules..."; } }
private void start_bStart_Click(object sender, EventArgs e) { try { var controller = new CommunicatorController(); var commList = controller.GetAllCommunicators().Where(comm => comm.Device.Id == _selectedDevice.Id); foreach (var comm in commList) new Inbound(comm); //Once started, stops allowing a second start. start_bStart.Enabled = false; } catch { DebugOutput.Print("Unable to start the selected device!"); } }
private void WriteData(Rule rule, Value value) { var controller = new CommunicatorController(); var comm = controller.GetAllCommunicators().FirstOrDefault(com => com.Id == rule.Action.CommunicatorId); if (comm == null) return; DataHandler handler = null; switch (comm.Type) { case CommunicatorType.FlatFile: handler = new FlatFileHandler((FileCommunicator)comm,rule,value); break; case CommunicatorType.Serial: handler = new SerialDataHandler((SerialCommunicator)comm,rule,value); break; case CommunicatorType.Database: handler = new DatabaseHandler((DatabaseCommunicator)comm,rule,value); break; default: throw new ArgumentOutOfRangeException(); } }
private void button6_Click(object sender, EventArgs e) { var cont = new CommunicatorController(); CommunicatorModifier cm = new CommunicatorModifier(cont.GetAllCommunicators().First()); cm.Show(); }