private bool checkFields(out byte addr, out byte data, out byte repeat, out typeClass pgm_class, out typeId pgm_id, out byte[] pgm_data) { addr = 0; data = 0; repeat = 0; pgm_class = new typeClass(""); pgm_id = new typeId(""); pgm_data = new byte[irCommand.PGM_DATA_LENGTH]; if (!byte.TryParse(txtIrAddr.Text, System.Globalization.NumberStyles.HexNumber, null, out addr)) { MessageBox.Show("IR address field does not contains a hex value between 0 and FF.", "Input error", MessageBoxButtons.OK, MessageBoxIcon.Information); return false; } if (!byte.TryParse(txtIrData.Text, System.Globalization.NumberStyles.HexNumber, null, out data)) { MessageBox.Show("IR data field does not contains a hex value between 0 and FF.", "Input error", MessageBoxButtons.OK, MessageBoxIcon.Information); return false; } if (!byte.TryParse(txtIrRepeat.Text, System.Globalization.NumberStyles.HexNumber, null, out repeat)) { MessageBox.Show("IR repeat field does not contains a hex value between 0 and FF.", "Input error", MessageBoxButtons.OK, MessageBoxIcon.Information); return false; } pgm_class = (typeClass)cmbClass.SelectedItem; if (pgm_class == null) { MessageBox.Show("You need to select a class.", "Input error", MessageBoxButtons.OK, MessageBoxIcon.Information); return false; } pgm_id = (typeId)cmbId.SelectedItem; if (pgm_id == null) { MessageBox.Show("You need to select a ID.", "Input error", MessageBoxButtons.OK, MessageBoxIcon.Information); return false; } if (!byte.TryParse(txtData1.Text, System.Globalization.NumberStyles.HexNumber, null, out pgm_data[1])) { MessageBox.Show("Data1 field does not contains a hex value between 0 and FF.", "Input error", MessageBoxButtons.OK, MessageBoxIcon.Information); return false; } if (!byte.TryParse(txtData0.Text, System.Globalization.NumberStyles.HexNumber, null, out pgm_data[0])) { MessageBox.Show("Data1 field does not contains a hex value between 0 and FF.", "Input error", MessageBoxButtons.OK, MessageBoxIcon.Information); return false; } return true; }
private bool checkIdField(string name, string comment, string oldName) { Regex rgxIsValidChars = new Regex("[^A-Za-z0-9_\\-]"); if (name.Length == 0) { MessageBox.Show("Name field is empty.", "Emtpy field", MessageBoxButtons.OK, MessageBoxIcon.Information); return false; } if (rgxIsValidChars.IsMatch(name)) { MessageBox.Show("Name has invalid characters.", "Invalid chars", MessageBoxButtons.OK, MessageBoxIcon.Information); return false; } typeId typeid = new typeId(name, comment); if (oldName != name && currentClass.getIds().Contains(typeid)) { MessageBox.Show("A id for this class with that name alredy exists.", "Dupes", MessageBoxButtons.OK, MessageBoxIcon.Information); return false; } return true; }
public bool addId(typeId id) { typeIds.Add(id); return true; }
private void cmdIdAdd_Click(object sender, EventArgs e) { if (currentClass == null) { MessageBox.Show("You need to select a class first.", "Missing class", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string name = txtIdName.Text.Trim().ToUpper(); string comment = txtIdComment.Text.Trim(); if (!checkIdField(name, comment)) return; if (currentClass.getIds().Count >= MAX_IDS) { MessageBox.Show("You cannot add more ids. Maximum of " + MAX_IDS.ToString() + " classes reached.", "Limit", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } typeId typeid = new typeId(name, comment); // Get first free value bool[] takenvalues = new bool[MAX_IDS]; foreach (typeId ti in currentClass.getIds()) { takenvalues[ti.value] = true; } for (int i = 0; i < MAX_IDS; i++) { if (!takenvalues[i]) { typeid.value = i; break; } } currentClass.getIds().Add(typeid); lstIds.Items.Add(typeid); }
public irCommand(byte repeat, byte addr, byte data, typeClass pgm_class, typeId pgm_id, byte[] pgm_data) { this.repeat = repeat; this.addr = addr; this.data = data; this.pgm_class = pgm_class; this.pgm_id = pgm_id; for (int i = 0; i < this.pgm_data.Length; i++) this.pgm_data[i] = pgm_data[i]; }