Пример #1
0
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            //add orders
            if (e.KeyData == Keys.F1)
            {
                bool   error  = true;
                bool   error1 = true;
                bool   error2 = true;
                string id     = combosupid.Text;
                string pcode  = txtprodid.Text;
                string qty    = txtqty.Text;
                //Start TXTCustid Constraints
                foreach (char c in id)
                {
                    if (!Char.IsNumber(c))
                    {
                        error = false;
                        break;
                    }
                }

                if (error == false)
                {
                    MessageBox.Show("The Supplier ID you entered does not exist in the RECORD", "Error");
                    return;
                }
                ///end of txtCUSTID Constraints
                ///
                ///Start of txtprodcode Constraints
                foreach (char c in pcode)
                {
                    if (!Char.IsNumber(c))
                    {
                        error1 = false;
                        break;
                    }
                }

                if (error1 == false)
                {
                    MessageBox.Show("The Product Code you entered does not exist in the RECORD", "Error");
                    return;
                }
                ///end of txtprodcode Constraints
                ///
                ///Start of txtquantity Constraints
                foreach (char c in qty)
                {
                    if (!Char.IsNumber(c))
                    {
                        error2 = false;
                        break;
                    }
                }
                if (error2 == false)
                {
                    MessageBox.Show("Invalid Input Please Checked Quantity Field for INCORRECT input", "Error");
                    return;
                }
                ///end of txtquantity Constraints



                if (combosupid.Text == "" || txtprodid.Text == "" || txtqty.Text == "" || txtTotal.Text == "")
                {
                    MessageBox.Show("All fields cannot be empty", "Error");
                    return;
                }

                try
                {
                    conn.dbcon();
                    SqlCommand cm = new SqlCommand("INSERT INTO Orders (Order_Date, Supplier_ID) " + "Values ('" + txtordersdate.Text + "', '" + combosupid.Text + "' )");
                    cm.Connection = Connectionclass.con;
                    cm.ExecuteNonQuery();
                    cmd            = new SqlCommand("INSERT INTO OrderDetails (Product_ID, Cost, Quantity) " + "Values ('" + txtprodid.Text + "', '" + txtcost.Text + "' , '" + txtqty.Text + "')");
                    cmd.Connection = Connectionclass.con;
                    cmd.ExecuteNonQuery();

                    MessageBox.Show("Saved Successfully", "Saving");
                    ///clear

                    txtqty.Clear();
                    txtprodid.SelectedIndex  = -1;
                    combosupid.SelectedIndex = -1;
                    txtsupname.Clear();
                    txtprodname.Clear();
                    txtunitmeas.Clear();
                    txtcost.Clear();
                    txtTotal.Text = "0.00";
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Error");
                }
                finally
                {
                    conn.Closecon();
                }
            }

            if (e.KeyData == Keys.Escape)
            {
                this.Hide();
                Orders display = new Orders();
                display.ShowDialog();
            }
        }