private void btn_chnge_Click(object sender, EventArgs e) { errorProvider2.SetError(txt_paid, ""); errorProvider3.SetError(txt_balnce, ""); errorProvider1.SetError(cbx_payMethord, ""); //-------------------------------------------Auto Invoice Number--------------------------------------------------------// string rNo = Invo.InvoiceNo(); if (rNo.Equals("") || rNo == null) { iNo = 001000; } else { iNo = Convert.ToInt32(rNo); iNo = iNo + 1; } //MessageBox.Show(iNo.ToString()); //---------------------------------------------------------------------------------------------------------------------// //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++check tablen is Null++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// String emty = "SELECT*FROM tbl_Invoice_Item"; SqlDataAdapter iigemty = new SqlDataAdapter(emty, ConnectionDB.Connection()); DataTable iemty = new DataTable(); iigemty.Fill(iemty); if (0 != iemty.Rows.Count) // does not exist { //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// if (cbx_payMethord.Text != "" && txt_paid.Text != "") { if (txt_balnce.Text != "Invalaid payment..!") { SqlDataReader cdr = wrty.select_cusNo(Warranty_Details.dgvw.CurrentRow.Cells["Invoice_No"].Value.ToString()); if (cdr.Read()) { ccno = cdr["Coustomer_No"].ToString(); InvDt = Convert.ToDateTime(cdr["Invoice_Date"]); } //====================================================================================================================================// String iisql = "SELECT*FROM tbl_Invoice_Item"; SqlDataAdapter iiget = new SqlDataAdapter(iisql, ConnectionDB.Connection()); DataTable iins = new DataTable(); iiget.Fill(iins); for (int ii = 0; ii < iins.Rows.Count; ii++) { inom = iins.Rows[ii]["Item_No"].ToString(); inme = iins.Rows[ii]["Item_Name"].ToString(); iserial = iins.Rows[ii]["Serial_No"].ToString(); iselpiz = iins.Rows[ii]["Sales_Price"].ToString(); ipurpiz = iins.Rows[ii]["Purchase_Price"].ToString(); ictgry = iins.Rows[ii]["Catogory"].ToString(); isubctgry = iins.Rows[ii]["Sub_Catogory"].ToString(); ibrnd = iins.Rows[ii]["Brande"].ToString(); ibcode = iins.Rows[ii]["Barcode"].ToString(); iwrrty = iins.Rows[ii]["Warranty"].ToString(); isuppl = iins.Rows[ii]["Supplier"].ToString(); itpe = iins.Rows[ii]["Item_Type"].ToString(); descri = iins.Rows[ii]["Discription"].ToString(); decimal pfit = (Convert.ToDecimal(iselpiz)) - (Convert.ToDecimal(ipurpiz)); try { Invo.insert_Invoice_detalis(iNo.ToString(), InvDt, inom, iserial, inme, Convert.ToDecimal(iselpiz), Convert.ToDecimal(ipurpiz), ibcode, ictgry, isubctgry, ibrnd, iwrrty, isuppl, itpe, descri, pfit, "Ok", "1"); // MessageBox.Show("new itttttttttmss changgggg"); wrty.addWary_foundItm(Warranty_Details.dgvw.CurrentRow.Cells["Warranty_No"].Value.ToString(), Warranty_Details.dgvw.CurrentRow.Cells["Invoice_No"].Value.ToString(), inom, inme, iserial, ibcode, ictgry, isubctgry, ibrnd, itpe, descri); //MessageBox.Show("warranty found item"); } catch (Exception ee) { MessageBox.Show(ee.Message); } } //===================================================================================================================================// //-----------------------------------------------for description-------------------------------------------------------------// String sql = "SELECT DISTINCT Catogory FROM tbl_Invoice_Item"; SqlDataAdapter get = new SqlDataAdapter(sql, ConnectionDB.Connection()); DataTable ns = new DataTable(); get.Fill(ns); for (int i = 0; i < ns.Rows.Count; i++) { iqqqty = 0; icty = ns.Rows[i]["Catogory"].ToString(); String idsql = "SELECT Quntity FROM tbl_Invoice_Item WHERE Catogory='" + icty + "'"; SqlDataAdapter idget = new SqlDataAdapter(idsql, ConnectionDB.Connection()); DataTable idns = new DataTable(); idget.Fill(idns); for (int idi = 0; idi < idns.Rows.Count; idi++) { decimal qttt = Convert.ToDecimal(idns.Rows[idi]["Quntity"].ToString()); iqqqty += qttt; } ides += icty + iqqqty.ToString() + " "; } //---------------------------------------------------------------------------------------------------------------------------// //===============================================================================================================================// if (txt_balnce.Text == "0.00") { pymnt = "Ok"; } else { pymnt = "Not Complete"; } //================================================================================================================================// try { Invo.insert_Invoice(iNo.ToString(), InvDt, Convert.ToDecimal(txt_Total.Text), (Convert.ToDecimal(txt_paid.Text)) + (Convert.ToDecimal(lbl_CurrentMoney.Text)), Convert.ToDecimal(txt_balnce.Text), cbx_payMethord.Text, ides, New_invoice.sref.Text, ccno, Convert.ToDecimal(txt_granTotal.Text), Convert.ToDecimal(txt_discount.Text), Convert.ToDecimal(txt_tax.Text), pymnt); // MessageBox.Show("ADd new invo"); wrty.update_item_status(Warranty_Details.dgvw.CurrentRow.Cells["Invoice_No"].Value.ToString(), Warranty_Details.dgvw.CurrentRow.Cells["Item_No"].Value.ToString(), "Return"); // MessageBox.Show("update oled invo"); } catch (Exception eee) { MessageBox.Show(eee.Message); } //--------------------------------------------------Remove Invoiced items From tbl_Add_Items Table---------------------------------// String dsql = "SELECT*FROM tbl_Invoice_Item"; SqlDataAdapter dget = new SqlDataAdapter(dsql, ConnectionDB.Connection()); DataTable dns = new DataTable(); dget.Fill(dns); for (int di = 0; di < dns.Rows.Count; di++) { SqlDataReader drm = itemdb.select_to_Qntity(dns.Rows[di]["Catogory"].ToString(), dns.Rows[di]["Sub_Catogory"].ToString(), dns.Rows[di]["Brande"].ToString()); if (drm.Read()) { string qqt = drm["Quntity"].ToString(); int qq1 = int.Parse(qqt); int qq2 = qq1 - 1; string qty = qq2.ToString(); itemdb.update_Quntity(qty, dns.Rows[di]["Catogory"].ToString(), dns.Rows[di]["Sub_Catogory"].ToString(), dns.Rows[di]["Brande"].ToString()); itemdb.delete_item(dns.Rows[di]["Item_No"].ToString()); // MessageBox.Show("Quntity Updated"); } } //---------------------------------------------------------------------------------------------------------------------------------// //========================================Add old item to return_item table & qty updated================================================// try { SqlDataReader bdr = wrty.select_invo_backI(Warranty_Details.dgvw.CurrentRow.Cells["Item_No"].Value.ToString(), Warranty_Details.dgvw.CurrentRow.Cells["Invoice_No"].Value.ToString()); if (bdr.Read()) { iinme = bdr["Item_Name"].ToString(); iiserial = bdr["Serial_No"].ToString(); iiselpiz = bdr["Sales_Price"].ToString(); iipurpiz = bdr["Purchase_Price"].ToString(); iictgry = bdr["Catogory"].ToString(); iisubctgry = bdr["Sub_Catogory"].ToString(); iibrnd = bdr["Brande"].ToString(); iibcode = bdr["Barcode"].ToString(); iiwrrty = bdr["Warranty"].ToString(); iisuppl = bdr["Supplier"].ToString(); iitpe = bdr["Item_Type"].ToString(); iidescri = bdr["Discription"].ToString(); ////// wrty.insert_retn_itm(Warranty_Details.dgvw.CurrentRow.Cells["Item_No"].Value.ToString(), iiserial, iinme, Convert.ToDecimal(iiselpiz), Convert.ToDecimal(iipurpiz), Convert.ToDecimal("0"), iibcode, iictgry, iisubctgry, iibrnd, iitpe, iisuppl, iiwrrty, iidescri); // MessageBox.Show("add to return item"); } } catch (Exception ee) { MessageBox.Show(ee.Message); } //=========================================================================================================================================// wty_dtail_inconplete.newItm = true; if (MessageBox.Show("Retun By Stock Item", "Sharp Creation", MessageBoxButtons.OK, MessageBoxIcon.Information) == DialogResult.OK) { if (cb_printi.Checked == true) { //========================================================================================================================== SqlDataReader ziddr = Invo.select_invoNo(iNo.ToString()); if (ziddr.Read()) { invodate = Convert.ToDateTime(ziddr["Invoice_Date"].ToString()); total = ziddr["Total_Price"].ToString(); paid = ziddr["Paid_Price"].ToString(); blnc = ziddr["Balance"].ToString(); cusnom = ziddr["Coustomer_No"].ToString(); paymethd = ziddr["Payment_Method"].ToString(); grantota = ziddr["Grande_total"].ToString(); disc = ziddr["Discount"].ToString(); tax = ziddr["Tax"].ToString(); } SqlDataReader zdrcus = Invo.select_incus(cusnom); if (zdrcus.Read()) { fname = zdrcus["First_Name"].ToString(); lnme = zdrcus["Last_Name"].ToString(); add1 = zdrcus["Address_Line1"].ToString(); add2 = zdrcus["Address_Line2"].ToString(); mobl = zdrcus["Mobile"].ToString(); } else { fname = "N/A"; lnme = "N/A"; add1 = "N/A"; add2 = "N/A"; mobl = "N/A"; } String ibsql = "SELECT*FROM tbl_Invoice_details WHERE Invoice_No='" + iNo + "'"; SqlDataAdapter ibget = new SqlDataAdapter(ibsql, ConnectionDB.Connection()); DataTable ibns = new DataTable(); ibget.Fill(ibns); for (int ib = 0; ib < ibns.Rows.Count; ib++) { itmno = ibns.Rows[ib]["Item_No"].ToString(); itmNme = ibns.Rows[ib]["Item_Name"].ToString(); itmseril = ibns.Rows[ib]["Serial_No"].ToString(); itsalepriz = ibns.Rows[ib]["Sales_Price"].ToString(); itmctgy = ibns.Rows[ib]["Catogory"].ToString(); itmsbctgy = ibns.Rows[ib]["Sub_Catogory"].ToString(); itmbrnd = ibns.Rows[ib]["Brande"].ToString(); itmwarrty = ibns.Rows[ib]["Warranty"].ToString(); iqty = ibns.Rows[ib]["Quntity"].ToString(); //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ check- is bill table Null...? ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// String emty_ibl = "SELECT*FROM tbl_Invoice_bill"; SqlDataAdapter iigemty_bil = new SqlDataAdapter(emty_ibl, ConnectionDB.Connection()); DataTable iemty_bil = new DataTable(); iigemty_bil.Fill(iemty_bil); if (0 != iemty_bil.Rows.Count) // does not exist { //___________________________________________________________________________________________________________________________ SqlDataReader slct_billDR = Invo.select_invtmp_bil(itmctgy, itmsbctgy, itmbrnd); if (slct_billDR.Read()) { string bsril, bqtyy, u_piz; decimal n_qty; bsril = slct_billDR["Serial_No"].ToString(); bqtyy = slct_billDR["Quantity"].ToString(); u_piz = slct_billDR["Unit_Price"].ToString(); n_qty = Convert.ToDecimal(bqtyy) + Convert.ToDecimal(iqty); Invo.Updte_invc_bill(itmctgy, itmsbctgy, itmbrnd, n_qty, (Convert.ToDecimal(u_piz) * n_qty), bsril + "," + itmseril); //MessageBox.Show("update_Dtail"); } else { try { Invo.insert_Invoice_Bill(iNo.ToString(), invodate, fname + " " + lnme, add1 + " " + add2, mobl, Convert.ToDecimal(grantota), Convert.ToDecimal(disc), Convert.ToDecimal(tax), Convert.ToDecimal(total), Convert.ToDecimal(paid), paymethd, Convert.ToDecimal(blnc), itmseril, itmctgy, itmsbctgy, itmbrnd, itmbrnd + " " + itmNme + " " + itmctgy + " " + itmsbctgy + " \nWarranty- " + itmwarrty, Convert.ToDecimal(Convert.ToDecimal(itsalepriz) / Convert.ToDecimal(iqty)), Convert.ToDecimal(iqty), Convert.ToDecimal(itsalepriz)); //MessageBox.Show("Invoice bill add"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } //___________________________________________________________________________________________________________________________ } else { try { Invo.insert_Invoice_Bill(iNo.ToString(), invodate, fname + " " + lnme, add1 + " " + add2, mobl, Convert.ToDecimal(grantota), Convert.ToDecimal(disc), Convert.ToDecimal(tax), Convert.ToDecimal(total), Convert.ToDecimal(paid), paymethd, Convert.ToDecimal(blnc), itmseril, itmctgy, itmsbctgy, itmbrnd, itmbrnd + " " + itmNme + " " + itmctgy + " " + itmsbctgy + " \nWarranty- " + itmwarrty, Convert.ToDecimal(Convert.ToDecimal(itsalepriz) / Convert.ToDecimal(iqty)), Convert.ToDecimal(iqty), Convert.ToDecimal(itsalepriz)); //MessageBox.Show("Invoice bill add"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } Bill invoBil = new Bill(); invoBil.ShowDialog(); //============================================================================================================================ //============================================================================================================================ } btn_warrtySave = true; wty_dtail_inconplete.bt_save = true; this.Close(); } //=========================================================================================================================================// } else { errorProvider2.SetError(txt_paid, "Invalid payment"); errorProvider3.SetError(txt_balnce, "Invalid payment"); } } else { if (cbx_payMethord.Text == "") { errorProvider1.SetError(cbx_payMethord, "Complete warranty"); } if (txt_paid.Text == "") { toolTipselect.Show("No Payment Enter", txt_paid, 1000); } } } else { toolTipselect.Show("Select items to Change", button_SearchItem, 0, 75, 2500); } }
private void btn_print_Click(object sender, EventArgs e) { try { invoNo = dgv_Invoice.CurrentRow.Cells["Invoice_No"].Value.ToString(); SqlDataReader iddr = Invo.select_invoNo(invoNo); if (iddr.Read()) { invodate = Convert.ToDateTime(iddr["Invoice_Date"].ToString()); total = iddr["Total_Price"].ToString(); paid = iddr["Paid_Price"].ToString(); blnc = iddr["Balance"].ToString(); cusnom = iddr["Coustomer_No"].ToString(); paymethd = iddr["Payment_Method"].ToString(); grantota = iddr["Grande_total"].ToString(); disc = iddr["Discount"].ToString(); tax = iddr["Tax"].ToString(); } SqlDataReader drcus = Invo.select_incus(cusnom); if (drcus.Read()) { fname = drcus["First_Name"].ToString(); lnme = drcus["Last_Name"].ToString(); add1 = drcus["Address_Line1"].ToString(); add2 = drcus["Address_Line2"].ToString(); mobl = drcus["Mobile"].ToString(); } else { fname = "N/A"; lnme = "N/A"; add1 = "N/A"; add2 = "N/A"; mobl = "N/A"; } String ibsql = "SELECT*FROM tbl_Invoice_details WHERE Invoice_No='" + invoNo + "'"; SqlDataAdapter ibget = new SqlDataAdapter(ibsql, ConnectionDB.Connection()); DataTable ibns = new DataTable(); ibget.Fill(ibns); for (int ib = 0; ib < ibns.Rows.Count; ib++) { itmno = ibns.Rows[ib]["Item_No"].ToString(); itmNme = ibns.Rows[ib]["Item_Name"].ToString(); itmseril = ibns.Rows[ib]["Serial_No"].ToString(); itsalepriz = ibns.Rows[ib]["Sales_Price"].ToString(); itmctgy = ibns.Rows[ib]["Catogory"].ToString(); itmsbctgy = ibns.Rows[ib]["Sub_Catogory"].ToString(); itmbrnd = ibns.Rows[ib]["Brande"].ToString(); itmwarrty = ibns.Rows[ib]["Warranty"].ToString(); iqty = ibns.Rows[ib]["Quntity"].ToString(); //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ check- is bill table Null...? ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// String emty_ibl = "SELECT*FROM tbl_Invoice_bill"; SqlDataAdapter iigemty_bil = new SqlDataAdapter(emty_ibl, ConnectionDB.Connection()); DataTable iemty_bil = new DataTable(); iigemty_bil.Fill(iemty_bil); if (0 != iemty_bil.Rows.Count) // does not exist { //___________________________________________________________________________________________________________________________ SqlDataReader slct_billDR = Invo.select_invtmp_bil(itmctgy, itmsbctgy, itmbrnd); if (slct_billDR.Read()) { string bsril, bqtyy, u_piz; decimal n_qty; bsril = slct_billDR["Serial_No"].ToString(); bqtyy = slct_billDR["Quantity"].ToString(); u_piz = slct_billDR["Unit_Price"].ToString(); n_qty = Convert.ToDecimal(bqtyy) + Convert.ToDecimal(iqty); Invo.Updte_invc_bill(itmctgy, itmsbctgy, itmbrnd, n_qty, (Convert.ToDecimal(u_piz) * n_qty), bsril + "," + itmseril); //MessageBox.Show("update_Dtail"); } else { try { Invo.insert_Invoice_Bill(invoNo, invodate, fname + " " + lnme, add1 + " " + add2, mobl, Convert.ToDecimal(grantota), Convert.ToDecimal(disc), Convert.ToDecimal(tax), Convert.ToDecimal(total), Convert.ToDecimal(paid), paymethd, Convert.ToDecimal(blnc), itmseril, itmctgy, itmsbctgy, itmbrnd, itmbrnd + " " + itmNme + " " + itmctgy + " " + itmsbctgy + " \nWarranty- " + itmwarrty, Convert.ToDecimal(Convert.ToDecimal(itsalepriz) / Convert.ToDecimal(iqty)), Convert.ToDecimal(iqty), Convert.ToDecimal(itsalepriz)); //MessageBox.Show("Invoice bill add"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } //___________________________________________________________________________________________________________________________ } else { try { Invo.insert_Invoice_Bill(invoNo, invodate, fname + " " + lnme, add1 + " " + add2, mobl, Convert.ToDecimal(grantota), Convert.ToDecimal(disc), Convert.ToDecimal(tax), Convert.ToDecimal(total), Convert.ToDecimal(paid), paymethd, Convert.ToDecimal(blnc), itmseril, itmctgy, itmsbctgy, itmbrnd, itmbrnd + " " + itmNme + " " + itmctgy + " " + itmsbctgy + " \nWarranty- " + itmwarrty, Convert.ToDecimal(Convert.ToDecimal(itsalepriz) / Convert.ToDecimal(iqty)), Convert.ToDecimal(iqty), Convert.ToDecimal(itsalepriz)); //MessageBox.Show("Invoice bill add"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } Bill invoBil = new Bill(); invoBil.Show(); } catch (Exception) { } // else { toolTip_Invoice.Show("Plese Select Invoice For Print", dgv_Invoice, 1500); } }