using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace Supermarket { public partial class SellingForm : Form { public SellingForm() { InitializeComponent(); } SqlConnection Con = new SqlConnection(@"[Your Data Location]"); private void populate() { Con.Open(); string query = "SELECT ProductName, ProductQuantity FROM ProductData"; SqlDataAdapter sda = new SqlDataAdapter(query, Con); SqlCommandBuilder builder = new SqlCommandBuilder(sda); var ds = new DataSet(); sda.Fill(ds); SellinglistproductDatagrid.DataSource = ds.Tables[0]; Con.Close(); } private void SellingForm_Load(object sender, EventArgs e) { populate(); SellingDate.Text = DateTime.Today.Day.ToString() + "/" + DateTime.Today.Month.ToString() + "/" + DateTime.Today.Year.ToString(); populatebill(); SellingSellername.Text = Login.Sellername; } private void Logout1_Click(object sender, EventArgs e) { this.Hide(); Login log = new Login(); log.Show(); } private void SellinglistproductDatagrid_CellContentClick_1(object sender, DataGridViewCellEventArgs e) { SellingProductname.Text = SellinglistproductDatagrid.SelectedRows[0].Cells[0].Value.ToString(); SellingPrice.Text = "12000"; } int Grdtotal = 0; int n = 0; private void SellingAddproduct_Click_1(object sender, EventArgs e) { int total = Convert.ToInt32(SellingPrice.Text) * Convert.ToInt32(SellingQuantity.Text); DataGridViewRow data = new DataGridViewRow(); data.CreateCells(SellingproductDatagrid); data.Cells[0].Value = n + 1; data.Cells[1].Value = SellingProductname.Text; data.Cells[2].Value = SellingQuantity.Text; data.Cells[3].Value = Convert.ToInt32(SellingPrice.Text) * Convert.ToInt32(SellingQuantity.Text); SellingproductDatagrid.Rows.Add(data); Grdtotal = Grdtotal + total; SellingAmount.Text = " "+ Grdtotal; label6.Text = "Total Amount : " + "Rp "; n++; } private void populatebill() { Con.Open(); string query = "SELECT * FROM BillData"; SqlDataAdapter sda = new SqlDataAdapter(query, Con); SqlCommandBuilder builder = new SqlCommandBuilder(sda); var ds = new DataSet(); sda.Fill(ds); SellingselllistDatagrid.DataSource = ds.Tables[0]; Con.Close(); } private void ListaddButton_Click(object sender, EventArgs e) { try { Con.Open(); string query = "INSERT INTO BillData VALUES("+SellingBillId.Text+",'"+SellingSellername.Text+"','"+SellingDate.Text+"','"+SellingAmount.Text+"')"; SqlCommand cmd = new SqlCommand(query, Con); cmd.ExecuteNonQuery(); MessageBox.Show("Bill Data Added Successfully"); Con.Close(); populatebill(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void ListdeleteButton_Click(object sender, EventArgs e) { try { Con.Open(); string query = "DELETE FROM BillData WHERE BillId = " + SellingselllistDatagrid.SelectedRows[0].Cells[0].Value+""; SqlCommand cmd = new SqlCommand(query, Con); cmd.ExecuteNonQuery(); MessageBox.Show("Bill Deleted Successfully"); Con.Close(); populatebill(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void outbutton4_Click(object sender, EventArgs e) { Application.Exit(); } } }