예제 #1
0
        private void btnaddsale_Click(object sender, EventArgs e)
        {
            this.Hide();
            addsales display = new addsales();

            display.ShowDialog();

            /*
             * if (txtcustid.Text == "" || txtprodcode.Text == "" || txtdiscount.Text == "" || txtprice.Text == "" || txtquantity.Text == "")
             * {
             *  MessageBox.Show("All fields cannot be EMPTY!","Error");
             *  return;
             * }
             * int left = Convert.ToInt32(txtleftitem.Text);
             * if(left == 0)
             * {
             *  MessageBox.Show("Please be warned! \nthe product you selected maybe out numbered Please contact Supplier", "Warning!");
             *  return;
             * }
             * if (left < 0)
             * {
             *  MessageBox.Show("There is no Item Left", "Warning!");
             *  return;
             *
             * }
             *
             * try
             * {
             *
             *  conn.dbcon();
             *  SqlCommand cm = new SqlCommand("INSERT INTO Sales (Sale_Date, Customer_ID) " + "Values ('" + txtsalesdate.Text + "', '" + txtcustid.Text + "' )");
             *  cm.Connection = Connectionclass.con;
             *  cm.ExecuteNonQuery();
             *  cmd = new SqlCommand("INSERT INTO SalesDetails (Product_ID, Price, Quantity) " + "Values ( '" + txtprodcode.Text + "','" + txtprice.Text + "', '" +txtquantity.Text +"')");
             *  cmd.Connection = Connectionclass.con;
             *  cmd.ExecuteNonQuery();
             *  int lefta = Convert.ToInt32(txtleftitem.Text);
             *  if (lefta <= 10)
             *  {
             *      MessageBox.Show("Please be warned! \nthe product you selected maybe out numbered \nPlease contact Supplier!", "Warning!");
             *
             *  }
             *  MessageBox.Show("Saved Successfully", "Saving");
             *
             *
             *  txtquantity.Text = "";
             *  txtprodcode.SelectedIndex = -1;
             *  txtcustid.SelectedIndex = -1;
             *  txtinfocustname.Clear();
             *  txtleftitem.Clear();
             *  txtquantity.Clear();
             *  txtinfoprod.Clear();
             *  txtdiscount.Clear();
             *  txtprice.Clear();
             *  txtTotal.Text = "0.00";
             *
             *
             *
             *  //refresh
             *
             *  cmd = new SqlCommand("SELECT * from SalesDetails");
             *  cmd.Connection = Connectionclass.con;
             *  sda = new SqlDataAdapter(cmd);
             *  cmb = new SqlCommandBuilder(sda);
             *  ds = new DataSet();
             *  sda.Fill(ds, "Sales");
             *  dt = ds.Tables["Sales"];
             *
             *  data.DataSource = ds.Tables["Sales"];
             *  data.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
             *  DateTime dta = DateTime.Now;
             *  txtsalesdate.Text = DateTime.Now.ToString();
             *
             *
             * }
             * catch (Exception ex)
             * {
             *  MessageBox.Show(ex.ToString(), "Error");
             * }
             * finally
             * {
             *  conn.Closecon();
             * }*/
        }
예제 #2
0
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            //ADD SALES
            if (e.KeyData == Keys.F1)
            {
                this.Hide();
                addsales display = new addsales();
                display.ShowDialog();

                /*if (txtcustid.Text == "" || txtprodcode.Text == "" || txtdiscount.Text == "" || txtprice.Text == "" || txtquantity.Text == "")
                 * {
                 *  MessageBox.Show("All fields cannot be EMPTY!", "Error");
                 *  return;
                 * }
                 * int left = Convert.ToInt32(txtleftitem.Text);
                 * if (left == 0)
                 * {
                 *  MessageBox.Show("Please be warned! \nthe product you selected maybe out numbered Please contact Supplier", "Warning!");
                 *  return;
                 * }
                 * if (left < 0)
                 * {
                 *  MessageBox.Show("There is no Item Left", "Warning!");
                 *  return;
                 *
                 * }
                 *
                 * try
                 * {
                 *  conn.dbcon();
                 *  SqlCommand cm = new SqlCommand("INSERT INTO Sales (Sale_Date, Customer_ID) " + "Values ('" + txtsalesdate.Text + "', '" + txtcustid.Text + "' )");
                 *  cm.Connection = Connectionclass.con;
                 *  cm.ExecuteNonQuery();
                 *  cmd = new SqlCommand("INSERT INTO SalesDetails (Product_ID, Price, Quantity) " + "Values ( '" + txtprodcode.Text + "','" + txtprice.Text + "', '" + txtquantity.Text + "')");
                 *  cmd.Connection = Connectionclass.con;
                 *  cmd.ExecuteNonQuery();
                 *  int lefta = Convert.ToInt32(txtleftitem.Text);
                 *  if (lefta <= 10)
                 *  {
                 *      MessageBox.Show("Please be warned! \nthe product you selected maybe out numbered \nPlease contact Supplier!", "Warning!");
                 *
                 *  }
                 *  MessageBox.Show("Saved Successfully", "Saving");
                 *
                 *
                 *  txtquantity.Text = "";
                 *  txtprodcode.SelectedIndex = -1;
                 *  txtcustid.SelectedIndex = -1;
                 *  txtinfocustname.Clear();
                 *  txtleftitem.Clear();
                 *  txtquantity.Clear();
                 *  txtinfoprod.Clear();
                 *  txtdiscount.Clear();
                 *  txtprice.Clear();
                 *  txtTotal.Text = "0.00";
                 *
                 *
                 *
                 *  //refresh
                 *
                 *  cmd = new SqlCommand("SELECT * from SalesDetails");
                 *  cmd.Connection = Connectionclass.con;
                 *  sda = new SqlDataAdapter(cmd);
                 *  cmb = new SqlCommandBuilder(sda);
                 *  ds = new DataSet();
                 *  sda.Fill(ds, "Sales");
                 *  dt = ds.Tables["Sales"];
                 *
                 *  data.DataSource = ds.Tables["Sales"];
                 *  data.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
                 *  DateTime dta = DateTime.Now;
                 *  txtsalesdate.Text = DateTime.Now.ToString();
                 *
                 *
                 * }
                 * catch (Exception ex)
                 * {
                 *  MessageBox.Show(ex.ToString(), "Error");
                 * }
                 * finally
                 * {
                 *  conn.Closecon();
                 * }*/
            }
            //UPDATE SALES
            if (e.KeyData == Keys.F2)
            {
                ////UPDATE
                bool   error  = true;
                bool   error1 = true;
                bool   error2 = true;
                string id     = txtcustid.Text;
                string pcode  = txtprodcode.Text;
                string qty    = txtquantity.Text;
                //Start TXTCustid Constraints
                foreach (char c in id)
                {
                    if (!Char.IsNumber(c))
                    {
                        error = false;
                        break;
                    }
                }

                if (error == false)
                {
                    MessageBox.Show("The Customer ID you entered does'nt 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'nt 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 (txtprodcode.Text == "" || txtdiscount.Text == "" || txtprice.Text == "" || txtquantity.Text == "")
                {
                    MessageBox.Show("No Such Record To Update", "Error");
                    return;
                }

                try
                {
                    conn.dbcon();
                    cmb = new SqlCommandBuilder(sda);
                    sda.Update(ds, "Sales");
                    cmd            = new SqlCommand("Update SalesDetails set Product_ID  = '" + txtprodcode.Text + "' , Price = '" + txtprice.Text + "',Quantity = '" + txtquantity.Text + "', Discount = '" + txtdiscount.Text + "'  where Sale_No = '" + txtsaleno.Text + "'");
                    cmd.Connection = Connectionclass.con;
                    cmd.ExecuteNonQuery();
                    cmd            = new SqlCommand("Update Sales set Customer_ID  = '" + txtcustid.Text + "' where Sale_No = '" + txtsaleno.Text + "'");
                    cmd.Connection = Connectionclass.con;
                    cmd.ExecuteNonQuery();
                    MessageBox.Show("Successfully Updated", "Update");

                    txtcustid.Enabled = true;
                    ////clear

                    txtquantity.Text          = "";
                    txtprodcode.SelectedIndex = -1;
                    txtcustid.SelectedIndex   = -1;
                    txtinfocustname.Clear();

                    txtquantity.Clear();
                    txtinfoprod.Clear();
                    txtdiscount.Clear();
                    txtprice.Clear();
                    txtTotal.Text        = "0.00";
                    txtquantity.ReadOnly = true;
                    txtdiscount.ReadOnly = true;
                    //refresh

                    cmd            = new SqlCommand("select SD.Sale_No, S.Customer_ID, SD.Product_ID, SD.Price, SD.Quantity , SD.Discount from Sales S inner join SalesDetails SD on S.Sale_No = SD.Sale_No order by SD.Sale_No DESC");
                    cmd.Connection = Connectionclass.con;
                    sda            = new SqlDataAdapter(cmd);
                    cmb            = new SqlCommandBuilder(sda);
                    ds             = new DataSet();
                    sda.Fill(ds, "Sales");
                    dt = ds.Tables["Sales"];
                    data.DataSource    = ds.Tables["Sales"];
                    data.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
                    DateTime dta = DateTime.Now;
                    txtsalesdate.Text = DateTime.Now.ToString();
                }
                catch
                {
                }
                finally
                {
                    conn.Closecon();
                    txtcustid.Enabled   = false;
                    txtprodcode.Enabled = false;
                }

                ///product Left
                try
                {
                    conn.dbcon();
                    SqlCommand tot = new SqlCommand("Select sum(Quantity) from stockcard where Product_ID like '" + txtprodcode.Text + "%'");
                    tot.Connection = Connectionclass.con;
                    SqlDataReader DR1 = tot.ExecuteReader();
                    if (DR1.Read())
                    {
                        txtleftitem.Text = DR1.GetValue(0).ToString();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Error");
                }
                finally
                {
                    conn.Closecon();
                    txtleftitem.Clear();
                }
            }

            //BACK
            if (e.KeyData == Keys.Escape)
            {
                this.Hide();
                Main display = new Main();
                display.ShowDialog();
                this.Close();
            }
        }