Beispiel #1
0
 private void BtnDelete_Click(object sender, EventArgs e)
 {
     try
     {
         int delete = dataGridView1.CurrentCell.RowIndex;
         dataGridView1.Rows.RemoveAt(delete);
         double a, b, c = 0;
         a = double.Parse(Txtcurrentstock.Text);
         b = double.Parse(Txtquant.Text);
         c = a - b;
         con.Open();
         SqlCommand cmd = new SqlCommand();
         cmd             = con.CreateCommand();
         cmd.CommandType = CommandType.Text;
         cmd.CommandText = "UPDATE CProductMaster SET TUnit='" + c + "' where [ProCode]='" + Txtproductid.Text + "'";
         cmd.ExecuteNonQuery();
         MessageBox.Show("Product " + Txtproductname.Text + " Deleted From List.", "Congratulation", MessageBoxButtons.OK, MessageBoxIcon.Information);
         con.Close();
     }
     catch (Exception ex)
     {
     }
     finally
     {
         Txtproductname.Text = "";
         Txtcategory.Text    = "";
         Txtunitname.Text    = "";
         Txtproductid.Text   = "";
         Txtquantity.Text    = "";
         Txtprice.Text       = "";
         Txtmrp.Text         = "";
         Txtpurchage.Text    = "";
         Txtsale.Text        = "";
         Txtcurrentstock.Clear();
     }
 }
Beispiel #2
0
        private void Btnadd_Click(object sender, EventArgs e)
        {
            try
            {
                //add text item in datagridview
                int row1 = 0;
                dataGridView1.Rows.Add();
                row1 = dataGridView1.Rows.Count - 1;
                dataGridView1["Purchase_ID", row1].Value   = TxtpurchageID.Text;
                dataGridView1["Product_Name", row1].Value  = Txtproductname.Text;
                dataGridView1["Category_Name", row1].Value = Txtcategory.Text;
                dataGridView1["Unit_Name", row1].Value     = Txtunitname.Text;
                dataGridView1["Purchase_Rate", row1].Value = Txtpurchage.Text;
                dataGridView1["MRP_Rate", row1].Value      = Txtmrp.Text;
                dataGridView1["Sale_Rate", row1].Value     = Txtsale.Text;
                dataGridView1["Quantity", row1].Value      = Txtquantity.Text;
                dataGridView1["Price", row1].Value         = Txtprice.Text;
                dataGridView1["CurrentStock", row1].Value  = Txtcurrentstock.Text;
                dataGridView1["ProductID", row1].Value     = Txtproductid.Text;

                Txttottal.Text = "0.00";
                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    Txttottal.Text = Convert.ToString(double.Parse(Txttottal.Text) + double.Parse(dataGridView1.Rows[i].Cells[9].Value.ToString()));
                }
                double x;
                double.TryParse(Txttottal.Text, out x);
                Txttottal.Text = x.ToString("0.00");

                long a, b, c = 0;
                a = long.Parse(Txtcurstock.Text);    //Quantity of Total items
                b = long.Parse(Txtquantity.Text);    //Quantity of Purchase items

                c = a + b;
                con.Open();
                SqlCommand cmd = new SqlCommand();
                cmd             = con.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "UPDATE CProductMaster SET [TUnit]='" + c + "' where [ID]='" + Txtproductid.Text + "'";
                cmd.ExecuteNonQuery();
                MessageBox.Show("Product " + Txtproductname.Text + " Added To Cart!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);

                con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Problem Found");
            }
            finally
            {
                Txtproductname.Text  = "";
                Txtcategory.Text     = "";
                Txtunitname.Text     = "";
                Txtcurrentstock.Text = "";
                Txtproductid.Text    = "";
                Txtquantity.Text     = "";
                Txtprice.Text        = "";
                Txtmrp.Text          = "";
                Txtpurchage.Text     = "";
                Txtsale.Text         = "";
                Txtcurrentstock.Clear();
                Txtquant.Text    = "";
                Txtcurstock.Text = "";
            }
        }