Exemple #1
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < parentForm.GetMessagesCount(msgType); i++)
            {
                if ((Byte.Parse(txtID1.Text, System.Globalization.NumberStyles.HexNumber) == parentForm.GetMessageHighByte(i, msgType)) && (Byte.Parse(txtID2.Text, System.Globalization.NumberStyles.HexNumber) == parentForm.GetMessageLowByte(i, msgType)))
                {
                    MessageBox.Show("Message ID already exists", "Duplicate ID", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                    return;
                }
                if (txtName.Text == parentForm.GetMessageName(i, msgType))
                {
                    MessageBox.Show("Message name already exists", "Duplicate name", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                    return;
                }
            }

            if (cmbFormatType.SelectedIndex == 0)
            {
                txtFormat.Text += "g * " + cmbUniformGroup.Text + " " + Format.getTokenString(cmbUniformFormat.Text);

                if (txtFormat.Text == "g * 1 h")
                {
                    txtFormat.Text = "%"; //slight optimization, the parser will skip some extra work
                }
            }
            else if (cmbFormatType.SelectedIndex == 1)
            {
                foreach (FormatLine f in lstFormats.Items)
                {
                    txtFormat.Text += f.ToFormatString();
                }
            }
            else if (cmbFormatType.SelectedIndex == 2)
            {
                txtFormat.Text = "call " + txtExternalFile.Text;
            }

            parentForm.PrintStatusMessage("Format string: " + txtFormat.Text);
            MessageFormat message = new MessageFormat(
                Byte.Parse(txtVersion1.Text, System.Globalization.NumberStyles.HexNumber),
                Byte.Parse(txtVersion2.Text, System.Globalization.NumberStyles.HexNumber),
                Byte.Parse(txtID1.Text, System.Globalization.NumberStyles.HexNumber),
                Byte.Parse(txtID2.Text, System.Globalization.NumberStyles.HexNumber),
                Byte.Parse(txtLength.Text, System.Globalization.NumberStyles.HexNumber),
                txtName.Text,
                txtFormat.Text);

            if (msgType == MessageType.Company)
            {
                if (cmbConnections.SelectedIndex < 0)
                {
                    MessageBox.Show("Please select a database connection.", "Company message failed", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                    return;
                }
                Connection           c   = (Connection)cmbConnections.Items[cmbConnections.SelectedIndex];
                SqlMessageConnection sql = new SqlMessageConnection(c.connection);
                if (sql.Write(message) == false)
                {
                    MessageBox.Show("Company message failed", "Company message failed", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                    return;
                }
                MessageBox.Show("Company message created", "Company message created", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
            }
            else
            {
                MessageBox.Show("Local message created", "Local message created", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
            }
            parentForm.AddMessageFormat(message, msgType);
            this.Visible = false;
            reset();
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < parentForm.GetMessagesCount(msgType); i++)
            {
                if ((Byte.Parse(txtID1.Text, System.Globalization.NumberStyles.HexNumber) == parentForm.GetMessageHighByte(i, msgType)) && (Byte.Parse(txtID2.Text, System.Globalization.NumberStyles.HexNumber) == parentForm.GetMessageLowByte(i, msgType)))
                {
                    MessageBox.Show("Message ID already exists", "Duplicate ID", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                    return;
                }
             if (txtName.Text == parentForm.GetMessageName(i, msgType))
                {
                    MessageBox.Show("Message name already exists", "Duplicate name", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                    return;
                }
            }

            if (cmbFormatType.SelectedIndex == 0)
            {
                txtFormat.Text += "g * " + cmbUniformGroup.Text + " " + Format.getTokenString(cmbUniformFormat.Text);

                if (txtFormat.Text == "g * 1 h")
                    txtFormat.Text = "%"; //slight optimization, the parser will skip some extra work
            }
            else if (cmbFormatType.SelectedIndex == 1)
            {
                foreach (FormatLine f in lstFormats.Items)
                    txtFormat.Text += f.ToFormatString();
            }
            else if (cmbFormatType.SelectedIndex == 2)
            {
                txtFormat.Text = "call " + txtExternalFile.Text;
            }

            parentForm.PrintStatusMessage("Format string: " + txtFormat.Text);
            MessageFormat message = new MessageFormat(
                Byte.Parse(txtVersion1.Text, System.Globalization.NumberStyles.HexNumber),
                Byte.Parse(txtVersion2.Text, System.Globalization.NumberStyles.HexNumber),
                Byte.Parse(txtID1.Text, System.Globalization.NumberStyles.HexNumber),
                Byte.Parse(txtID2.Text, System.Globalization.NumberStyles.HexNumber),
                Byte.Parse(txtLength.Text, System.Globalization.NumberStyles.HexNumber),
                txtName.Text,
                txtFormat.Text);

            if (msgType == MessageType.Company)
            {
                if (cmbConnections.SelectedIndex < 0)
                {
                    MessageBox.Show("Please select a database connection.", "Company message failed", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                    return;
                }
                Connection c = (Connection)cmbConnections.Items[cmbConnections.SelectedIndex];
                SqlMessageConnection sql = new SqlMessageConnection(c.connection);
                if (sql.Write(message) == false)
                {
                    MessageBox.Show("Company message failed", "Company message failed", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                    return;
                }
                MessageBox.Show("Company message created", "Company message created", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
            }
            else
            {
                MessageBox.Show("Local message created", "Local message created", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
            }
            parentForm.AddMessageFormat(message, msgType);
            this.Visible = false;
            reset();
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            lblNameError2.Visible = false;
            lblIdError3.Visible = false;
            error = false;
            txtName_check(sender, e);
            txtID_check(sender, e);
            txtLength_check(sender, e);
            if (error == true)
                return;
            ID = ushort.Parse(txtID.Text, System.Globalization.NumberStyles.HexNumber);
            byte[] versionBytes = BitConverter.GetBytes(MainForm.SOFTWARE_VERSION);
            byte[] IdBytes = BitConverter.GetBytes(ID);

            for (int i = 0; i < parentForm.GetMessagesCount(msgType); i++)
            {
                if (i == editIndex)
                    continue;

                if ((IdBytes[1] == parentForm.GetMessageHighByte(i, msgType)) && (IdBytes[0] == parentForm.GetMessageLowByte(i, msgType)))
                {
                    lblIdError3.Visible = true;
                    error = true;
                }
                if (txtName.Text.Trim() == parentForm.GetMessageName(i, msgType))
                {
                    lblNameError2.Visible = true;
                    error = true;
                }
            }
            if (error == true)
                return;

            if (cmbFormatType.SelectedIndex == 0)
            {
                txtFormat.Text = "* " + cmbUniformGroup.Text + " " + Format.getTokenString(cmbUniformFormat.Text);
                if (cmbUniformFormat.Text == "decimal")
                    if (cmbUniformSigned.Text == "unsigned")
                        txtFormat.Text = "* " + cmbUniformGroup.Text + " " + Format.getTokenString("unsigned");

                if (txtFormat.Text == "* 1 h")
                    txtFormat.Text = "%"; //slight optimization, the parser will skip some extra work
            }
            else if (cmbFormatType.SelectedIndex == 1)
            {
                if ((bytes - bytes_used) < 0)
                {
                    lblCustomError.Visible = true;
                    return;
                }
                else
                    lblCustomError.Visible = false;
                foreach (FormatLine f in lstFormats.Items)
                    txtFormat.Text += f.ToFormatString();
            }
            else if (cmbFormatType.SelectedIndex == 2)
            {
                txtFormat.Text = "call " + txtExternalFile.Text;
            }

            MessageFormat message = new MessageFormat(
                versionBytes[1],
                versionBytes[0],
                IdBytes[1],
                IdBytes[0],
                Byte.Parse(txtLength.Text, System.Globalization.NumberStyles.HexNumber),
                txtName.Text.Trim(),
                txtFormat.Text);

            if (msgType == MessageType.Company)
            {
                if (cmbConnections.SelectedIndex < 0)
                {
                    lblCompanyError1.Visible = true;
                    return;
                }
                else
                    lblCompanyError1.Visible = false;
                Connection c = (Connection)cmbConnections.Items[cmbConnections.SelectedIndex];
                SqlMessageConnection sql = new SqlMessageConnection(c.connection);
                if (sql.Write(message) == false)
                {
                    lblCompanyError2.Visible = true;
                    return;
                }
                else
                    lblCompanyError2.Visible = false;
            }
            if (editIndex > -1)
                parentForm.RemoveMessageFormat(editIndex);
            parentForm.AddMessageFormat(message, msgType);
            this.Visible = false;
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            lblNameError2.Visible = false;
            lblIdError3.Visible   = false;
            error = false;
            txtName_check(sender, e);
            txtID_check(sender, e);
            txtLength_check(sender, e);
            if (error == true)
            {
                return;
            }
            ID = ushort.Parse(txtID.Text, System.Globalization.NumberStyles.HexNumber);
            byte[] versionBytes = BitConverter.GetBytes(MainForm.SOFTWARE_VERSION);
            byte[] IdBytes      = BitConverter.GetBytes(ID);

            for (int i = 0; i < parentForm.GetMessagesCount(msgType); i++)
            {
                if (i == editIndex)
                {
                    continue;
                }

                if ((IdBytes[1] == parentForm.GetMessageHighByte(i, msgType)) && (IdBytes[0] == parentForm.GetMessageLowByte(i, msgType)))
                {
                    lblIdError3.Visible = true;
                    error = true;
                }
                if (txtName.Text.Trim() == parentForm.GetMessageName(i, msgType))
                {
                    lblNameError2.Visible = true;
                    error = true;
                }
            }
            if (error == true)
            {
                return;
            }

            if (cmbFormatType.SelectedIndex == 0)
            {
                txtFormat.Text = "* " + cmbUniformGroup.Text + " " + Format.getTokenString(cmbUniformFormat.Text);
                if (cmbUniformFormat.Text == "decimal")
                {
                    if (cmbUniformSigned.Text == "unsigned")
                    {
                        txtFormat.Text = "* " + cmbUniformGroup.Text + " " + Format.getTokenString("unsigned");
                    }
                }


                if (txtFormat.Text == "* 1 h")
                {
                    txtFormat.Text = "%"; //slight optimization, the parser will skip some extra work
                }
            }
            else if (cmbFormatType.SelectedIndex == 1)
            {
                if ((bytes - bytes_used) < 0)
                {
                    lblCustomError.Visible = true;
                    return;
                }
                else
                {
                    lblCustomError.Visible = false;
                }
                foreach (FormatLine f in lstFormats.Items)
                {
                    txtFormat.Text += f.ToFormatString();
                }
            }
            else if (cmbFormatType.SelectedIndex == 2)
            {
                txtFormat.Text = "call " + txtExternalFile.Text;
            }

            MessageFormat message = new MessageFormat(
                versionBytes[1],
                versionBytes[0],
                IdBytes[1],
                IdBytes[0],
                Byte.Parse(txtLength.Text, System.Globalization.NumberStyles.HexNumber),
                txtName.Text.Trim(),
                txtFormat.Text);

            if (msgType == MessageType.Company)
            {
                if (cmbConnections.SelectedIndex < 0)
                {
                    lblCompanyError1.Visible = true;
                    return;
                }
                else
                {
                    lblCompanyError1.Visible = false;
                }
                Connection           c   = (Connection)cmbConnections.Items[cmbConnections.SelectedIndex];
                SqlMessageConnection sql = new SqlMessageConnection(c.connection);
                if (sql.Write(message) == false)
                {
                    lblCompanyError2.Visible = true;
                    return;
                }
                else
                {
                    lblCompanyError2.Visible = false;
                }
            }
            if (editIndex > -1)
            {
                parentForm.RemoveMessageFormat(editIndex);
            }
            parentForm.AddMessageFormat(message, msgType);
            this.Visible = false;
        }