private void button1_Click(object sender, EventArgs e) { //Checking if text boxes are empty or null if (Validation()) { //Gettting Data FRom UI u.product_name = txtproductname.Text; u.colour_code = txtcolourcode.Text; u.supplier = txtsupplier.Text; u.catagory = txtcatagory.Text; u.purchase_price = txtpurchaseprice.Text; u.retail_price = txtretailprice.Text; u.type = txtmaxdiscount.Text; u.quantity = txtquantity.Text; //u.added_by = 1; u.added_date = DateTime.Now; //Getting Username of the logged in user string loggedUser = Login.loggedIn; usersbll usr = da.GetIDFromUsername(loggedUser); u.added_by = usr.id; //Inserting Data into DAtabase bool check1 = dal.exist(u); //Checking if Product Already Exist if (check1 == true) { //Showing MessageBox DialogResult = MessageBox.Show("Product already exist do you want to update", "Message", MessageBoxButtons.YesNo); if (DialogResult == DialogResult.Yes) { u.id = Convert.ToInt32(txtproductid.Text); //Update Data in DataBase bool check = dal.update_(u); if (check == true) { MessageBox.Show("Record updated successfully"); clear(); } else { MessageBox.Show("error"); } //Refreshing Data Grid View DataTable dt1 = dal.select(); dgvmanageproducts.DataSource = dt1; } } else { //Inserting data in DataBase bool check = dal.insert(u); if (check == true) { MessageBox.Show("Record added successfully"); clear(); } else { MessageBox.Show("error"); } } //Refreshing Data Grid View DataTable dt = dal.select(); dgvmanageproducts.DataSource = dt; } }
private void btncomplete_Click(object sender, EventArgs e) { if (Validation1()) { //printPreviewDialog1.Document = printDocument1; //printPreviewDialog1.ShowDialog(); //Gettting Data FRom UI inbll.inv_no = Convert.ToInt32(lblinvoiceno.Text); inbll.customer_name = cmbcustomer.Text; inbll.total_payable = txtsubtotal.Text; inbll.paid_amount = txtpaidamount.Text; inbll.discount = txtdiscount.Text; inbll.due_amount = txtdueamount.Text; inbll.change_amount = txtchangeamount.Text; inbll.sales_date = DateTime.Now; //Getting Username of the logged in user string loggedUser = Login.loggedIn; usersbll usr = user.GetIDFromUsername(loggedUser); inbll.added_by = usr.id; //Inserting Data into DAtabase bool w = indal.insert(inbll); bool sucess = false; for (int i = 0; i < table.Rows.Count; i++) { bool x = false; //Get the Product name and convert it to id string ProductName = table.Rows[i][0].ToString(); string type1 = table.Rows[i][2].ToString(); string ccode = table.Rows[i][1].ToString(); Manage_Productsbll p = dal.GetProductIDFromName(ProductName, type1, ccode); prbll.product_id = p.id; prbll.product_name = table.Rows[i][0].ToString(); prbll.type = table.Rows[i][2].ToString(); prbll.price = table.Rows[i][3].ToString(); prbll.quantity = table.Rows[i][4].ToString(); prbll.code = Convert.ToInt32(table.Rows[i][1]); prbll.discount = txtdiscount.Text; //prbll.total = table.Rows[i][3].ToString(); //Getting total value by calculating discount t1 = Convert.ToDouble(txtdiscount.Text); t2 = Convert.ToDouble(table.Rows[i][5]); prbll.total = (t2 - (t2 * t1) / 100).ToString(); //Method to get purchase price an multiply it with quantity Manage_Productsbll pr = dal.GetProductpriceFromId(p.id.ToString()); purchaseprice = Convert.ToDouble(pr.purchase_price); prbll.purchase_price = ((Convert.ToDouble(table.Rows[i][4])) * purchaseprice).ToString(); prbll.inv_no = lblinvoiceno.Text; prbll.added_by = usr.id; prbll.added_date = DateTime.Now; quantity1 = Convert.ToDecimal(prbll.quantity); // Decreasing product quantity in DAtabase bool y = false; y = dal.DecreaseProduct(prbll.product_id, quantity1); // Inserting Data into DAtabase x = prdal.insert(prbll); sucess = w && x && y; } if (sucess == true) { //code to print Bill DGVPrinter printer = new DGVPrinter(); printer.Title = "\r \r Time Paint & Hardware Store"; printer.SubTitle = "Khokhar Plaza, Near Alied Bank, Main Behria Enclave Road \r \n Phone: 031659007044 \r \r \r \r \r \r Invoice #:" + lblinvoiceno.Text + "\r"; printer.SubTitleFormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.NoClip; printer.PageNumbers = true; printer.PageNumberInHeader = false; printer.PorportionalColumns = true; printer.HeaderCellAlignment = StringAlignment.Near; printer.Footer = "Grand Total: " + txtsubtotal.Text + " \r \r \r \r \r \r \r \r \r \r \r \r" + "Total Paid:" + txtpaidamount.Text + " \r \n" + "Thank You, for doing business with us. \n"; //printer.PageText = "Developed By: \r \r \r Engr. Azhar Mir \r \r \r \r \r \r \r \r \r Mailing Contact: \r \r \r [email protected] \n"; printer.FooterSpacing = 15; printer.PrintDataGridView(dgvinvoice); MessageBox.Show("Transaction Completed Sucessfully"); //Celar the Data Grid View and Clear all the TExtboxes dgvinvoice.DataSource = null; dgvinvoice.Rows.Clear(); txttotal.Text = ""; txtdiscount.Text = ""; txtsubtotal.Text = ""; txtpaidamount.Text = ""; txtdueamount.Text = ""; txtchangeamount.Text = ""; cmbcustomer.Text = ""; txtcomment.Text = "0"; //To refresh stock in Data grid view DataTable dt = dal.select(); dgvstock.DataSource = dt; ToGetInvoiceID(); } else { //Transaction Failed MessageBox.Show("Transaction Failed"); } } }
private void button1_Click(object sender, EventArgs e) { //Checking if text boxes are empty or null if (Validation()) { //Gettting Data FRom UI u.user_name = txtusername.Text; u.user_type = txtusertype.Text; u.password = txtpassword.Text; u.email = txtemail.Text; u.cnic = txtcnic.Text; u.adress = txtaddress.Text; u.phone_no = txtphoneno.Text; //u.added_by = 1; u.added_date = DateTime.Now; //Getting Username of the logged in user string loggedUser = Login.loggedIn; usersbll usr = dal.GetIDFromUsername(loggedUser); u.added_by = usr.id; //Inserting Data into DAtabase bool check1 = dal.exist(u); //Checking if Product Already Exist if (check1 == true) { //Showing MessageBox DialogResult = MessageBox.Show("Product already exist do you want to update", "Message", MessageBoxButtons.YesNo); if (DialogResult == DialogResult.Yes) { u.id = Convert.ToInt32(txtid.Text); //Update Data in DataBase bool check = dal.update(u); if (check == true) { MessageBox.Show("Record updated successfully"); clear(); } else { MessageBox.Show("error"); } //Refreshing Data Grid View DataTable dt1 = dal.select(); dgvusers.DataSource = dt1; } } else { //Inserting data in DataBase bool check = dal.insert(u); if (check == true) { MessageBox.Show("user data added successfully"); clear(); } else { MessageBox.Show("error"); } } //Refreshing Data Grid View DataTable dt = dal.select(); dgvusers.DataSource = dt; } }