Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            bool errorsFound = false;
            //start check of cashpay and cardpay
            float cashPaid, cardPaid;

            //if cashpaid wrongly entered
            if (textBox4.Enabled && !textBox5.Enabled)
            {
                if (System.Text.RegularExpressions.Regex.IsMatch(textBox4.Text, @"^[1-9][0-9]*(?:(,[0-9]{2}$)|(\b$))"))
                {
                    cashPaid = Convert.ToSingle(textBox4.Text);
                }
                else
                {
                    errorsFound   = true;
                    textBox4.Text = "0";
                    MessageBox.Show("Incorrect CASH value entered. Try again.");
                }
            }
            //if cardpay wrongly entered
            if (!textBox4.Enabled && textBox5.Enabled)
            {
                if (System.Text.RegularExpressions.Regex.IsMatch(textBox5.Text, @"^[1-9][0-9]*(?:(,[0-9]{2}$)|(\b$))"))
                {
                    cardPaid = Convert.ToSingle(textBox5.Text);
                }
                else
                {
                    errorsFound   = true;
                    textBox5.Text = "0";
                    MessageBox.Show("Incorrect CARD value entered. Try again.");
                }
            }
            // check both
            if (textBox4.Enabled && textBox5.Enabled)
            {
                if ((!System.Text.RegularExpressions.Regex.IsMatch(textBox4.Text, @"^[1-9][0-9]*(?:(,[0-9]{2}$)|(\b$))") && System.Text.RegularExpressions.Regex.IsMatch(textBox5.Text, @"^[1-9][0-9]*(?:(,[0-9]{2}$)|(\b$))")) || ((System.Text.RegularExpressions.Regex.IsMatch(textBox4.Text, @"^[1-9][0-9]*(?:(,[0-9]{2}$)|(\b$))") && !System.Text.RegularExpressions.Regex.IsMatch(textBox5.Text, @"^[1-9][0-9]*(?:(,[0-9]{2}$)|(\b$))"))))
                {
                    //only cashpay wrongly entered
                    if (System.Text.RegularExpressions.Regex.IsMatch(textBox4.Text, @"^[1-9][0-9]*(?:(,[0-9]{2}$)|(\b$))"))
                    {
                        cashPaid = Convert.ToSingle(textBox4.Text);
                    }
                    else
                    {
                        errorsFound = true;
                        MessageBox.Show("Incorrect CASH value entered. Try again.");
                        textBox4.Text = "0";
                    }

                    //only cardpay wrongly entered
                    if (System.Text.RegularExpressions.Regex.IsMatch(textBox5.Text, @"^[1-9][0-9]*(?:(,[0-9]{2}$)|(\b$))"))
                    {
                        cardPaid = Convert.ToSingle(textBox5.Text);
                    }
                    else
                    {
                        errorsFound = true;
                        MessageBox.Show("Incorrect CARD value entered. Try again.");
                        textBox5.Text = "0";
                    }
                }
                //both wrong entered
                if (!System.Text.RegularExpressions.Regex.IsMatch(textBox4.Text, @"^[1-9][0-9]*(?:(,[0-9]{2}$)|(\b$))") && !System.Text.RegularExpressions.Regex.IsMatch(textBox5.Text, @"^[1-9][0-9]*(?:(,[0-9]{2}$)|(\b$))"))
                {
                    errorsFound   = true;
                    textBox4.Text = "0";
                    textBox5.Text = "0";
                    MessageBox.Show("Icorrect CASH and CARD value. Try again.");
                }
            }
            //end of check cashpay and cardpay

            //service order checking
            if (!System.Text.RegularExpressions.Regex.IsMatch(textBox3.Text, @"^[0-9]*$") && !errorsFound)
            {
                DialogResult result = MessageBox.Show(
                    String.Format("Are you sure you want to add a job with S/O number like: {0}", textBox3.Text),
                    "Are you sure?",
                    MessageBoxButtons.OKCancel,
                    MessageBoxIcon.Information,
                    MessageBoxDefaultButton.Button1);
                if (result == DialogResult.OK)
                {
                    Insert();
                    shouldIBeClosed = false;
                    m_form.Select();
                    this.Close();
                }
            }

            if (System.Text.RegularExpressions.Regex.IsMatch(textBox3.Text, @"^[0-9]*$") && !errorsFound)
            {
                Insert();
                shouldIBeClosed = false;
                m_form.Select();
                this.Close();
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            Wrong = "Wrong values entered in: ";
            if (System.Text.RegularExpressions.Regex.IsMatch(textBox4.Text, @"^(?:0\b$|[1-9][0-9]*(?:(,[0-9]{2}$)|(\b$)))"))
            {
                cashPayValid = true;
            }
            else
            {
                cashPayValid = false;
                howManyWrong++;
                Wrong += "cash pay";
            }


            if (System.Text.RegularExpressions.Regex.IsMatch(textBox5.Text, @"^(?:0\b$|[1-9][0-9]*(?:(,[0-9]{2}$)|(\b$)))"))
            {
                cardPayValid = true;
            }
            else
            {
                cardPayValid = false;
                if (cashPayValid)
                {
                    Wrong += "card pay";
                }
                if (!cashPayValid)
                {
                    Wrong += ", card pay";
                }
                howManyWrong++;
            }


            if (System.Text.RegularExpressions.Regex.IsMatch(textBox7.Text, @"^(?:0\b$|[1-9][0-9]*(?:(,[0-9]{2}$)|(\b$)))"))
            {
                cashRefundValid = true;
            }
            else
            {
                cashRefundValid = false;
                if (cashPayValid && cardPayValid)
                {
                    Wrong += "cash refund";
                }
                if (!cashPayValid || !cardPayValid)
                {
                    Wrong += ", cash refund";
                }
                howManyWrong++;
            }


            if (System.Text.RegularExpressions.Regex.IsMatch(textBox8.Text, @"^(?:0\b$|[1-9][0-9]*(?:(,[0-9]{2}$)|(\b$)))"))
            {
                cardRefundValid = true;
            }
            else
            {
                cardRefundValid = false;
                if (cashPayValid && cardPayValid && cashRefundValid)
                {
                    Wrong += "card refund";
                }

                if (!cashPayValid || !cardPayValid || !cashRefundValid)
                {
                    Wrong += ", card refund";
                }
                howManyWrong++;
            }

            if (cashPayValid && cardPayValid && cashRefundValid && cardRefundValid)
            {
                UpdateSQL();
                MessageBox.Show("Updated successfully!");
                shouldIBeClosed = false;
                m_form.Select();
                this.Close();
            }
            else
            {
                MessageBox.Show(Wrong + ".");
            }
        }