Пример #1
0
 // add nes product button
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         // prodcutname
         var productName = UtilityClass.CheckIfEmpty(textBox1.Text);
         // price
         var productPrice = UtilityClass.CheckIfEmpty(textBox2.Text);
         // date
         var date = dateTimePicker1.Value;
         // added by
         var addedBy = UtilityClass.CheckIfEmpty(textBox3.Text);
         // get only date value tostring
         var dateValue = date.Date.ToShortDateString();
         database.DataBaseConnection();
         // sql string
         var sql = $"INSERT INTO Product(product_Name, cost_Price, Added_By, Date_Added)" + $" VALUES ('{productName}', '{productPrice}', '{addedBy}', '{dateValue}')";
         // query database
         var conn = database.QueryDatabase(sql);
         conn.ExecuteNonQuery();
         MessageBox.Show("Product Added");
         // set text box empty
         textBox1.Text = "";
         textBox2.Text = "";
         textBox3.Text = "";
     }
     catch (Exception)
     {
         MessageBox.Show("Invalid Operation");
     }
 }
Пример #2
0
        private void button8_Click(object sender, EventArgs e)
        {
            // clear display result
            dataGridView1.Rows.Clear();
            string word = "";

            // check if string is empty
            UtilityClass.CheckIfEmpty(textBox2.Text);
            // radio button product name is checked
            if (radioButton1.Checked)
            {
                word = textBox2.Text.Trim();
                var sqlquery = $"SELECT * FROM Product WHERE Product_Name = '{word}'";
                QueryDataClass.QueryAllData(dataGridView1, sqlquery);
            }

            // if radio button price is checked
            if (radioButton2.Checked)
            {
                word = textBox2.Text;
                var price    = Convert.ToDecimal(word);
                var sqlquery = $"SELECT * FROM Product WHERE Cost_Price = '{price}'";
                QueryDataClass.QueryAllData(dataGridView1, sqlquery);
            }
        }
Пример #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            database.DataBaseConnection();

            var productName  = UtilityClass.CheckIfEmpty(textBox3.Text);
            var productPrice = Convert.ToDecimal(textBox1.Text);
            var addedBy      = UtilityClass.CheckIfEmpty(textBox2.Text);
            // query string
            var sql    = $"UPDATE Product SET Product_Name = '{productName}', Cost_Price = '{productPrice}', Added_by= '{addedBy}' WHERE Id = '{page_id}' ";
            var conn   = database.QueryDatabase(sql);
            var result = conn.ExecuteReader();

            MessageBox.Show("Item Edited");
        }