Ejemplo n.º 1
0
        private bool checkClassField(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;
            }

            typeClass typeclass = new typeClass(name, comment);

            if (oldName != name && lstClasses.Items.Contains(typeclass))
            {
                MessageBox.Show("A class with that name alredy exists.", "Dupes", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }

            return true;
        }
Ejemplo n.º 2
0
        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;
        }
Ejemplo n.º 3
0
 private void lstClasses_SelectedIndexChanged(object sender, EventArgs e)
 {
     typeClass typeclass = (typeClass)lstClasses.SelectedItem;
     if (typeclass != null)
     {
         txtClassName.Text = typeclass.name;
         txtClassComment.Text = typeclass.comment;
         txtIdComment.Text = "";
         txtIdName.Text = "";
         currentClass = typeclass;
         lstIds.Items.Clear();
         foreach (typeId ti in typeclass.getIds())
         {
             lstIds.Items.Add(ti);
         }
     }
 }
Ejemplo n.º 4
0
        private void cmdClassDelete_Click(object sender, EventArgs e)
        {
            typeClass typeclass = (typeClass)lstClasses.SelectedItem;
            if (typeclass == null)
            {
                MessageBox.Show("You need to select a class to delete.", "Missing class", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            currentClass = null;
            lstClasses.Items.Remove(typeclass);
            txtClassName.Text = "";
            txtClassComment.Text = "";
        }
Ejemplo n.º 5
0
        private void cmdClassAdd_Click(object sender, EventArgs e)
        {
            string name = txtClassName.Text.Trim().ToUpper();
            string comment = txtClassComment.Text.Trim();

            if (!checkClassField(name, comment)) return;

            if (lstClasses.Items.Count >= MAX_CLASSES)
            {
                MessageBox.Show("You cannot add more classes. Maximum of " + MAX_CLASSES.ToString() + " classes reached.", "Limit", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            typeClass typeclass = new typeClass(name, comment);

            // Get first free value
            bool[] takenvalues = new bool[MAX_CLASSES];
            foreach (typeClass tp in lstClasses.Items)
            {
                takenvalues[tp.value] = true;
            }
            for (int i = 0; i < MAX_CLASSES; i++)
            {
                if (!takenvalues[i])
                {
                    typeclass.value = i;
                    break;
                }
            }

            lstClasses.Items.Add(typeclass);
        }
Ejemplo n.º 6
0
 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];
 }