Esempio n. 1
0
        private void btn_save_Click(object sender, EventArgs e)
        {
            try
            {
                ModCommonClasses.con = new SqlConnection(ModCS.cs);
                ModCommonClasses.con.Open();
                string ct = "select Invoiceno from tbl_salemaster where Invoiceno=@d1";
                ModCommonClasses.cmd = new SqlCommand(ct);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d1", txt_invoice_no.Text);
                ModCommonClasses.cmd.Connection = ModCommonClasses.con;
                ModCommonClasses.rdr            = ModCommonClasses.cmd.ExecuteReader();
                if (ModCommonClasses.rdr.Read())
                {
                    MessageBox.Show("Invoice No. Already Exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txt_invoice_no.Text = "";
                    txt_invoice_no.Focus();
                    if ((ModCommonClasses.rdr != null))
                    {
                        ModCommonClasses.rdr.Close();
                    }
                    return;
                }
                ModCommonClasses.con.Close();


                ModCommonClasses.con = new SqlConnection(ModCS.cs);
                ModCommonClasses.con.Open();
                string cb = "insert into tbl_salemaster(Inv_ID,Invoiceno,Date,Salesman,Saletype,CustomerID,Customer,Grandtotal,Discount,Discountvalue,Tax,Taxvalue,Netamount,Oldbalance,Newbalance,Receivedamount,Balance,Comments) VALUES (@d1,@d2,@d3,@d4,@d5,@d6,@d7,@d8,@d9,@d10,@d11,@d12,@d13,@d14,@d15,@d16,@d17,@d18)";
                ModCommonClasses.cmd = new SqlCommand(cb);

                ModCommonClasses.cmd.Parameters.AddWithValue("@d1", txtinvoice.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d2", txt_invoice_no.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d3", dateTimePicker1.Value.ToString("MM/dd/yyyy"));
                ModCommonClasses.cmd.Parameters.AddWithValue("@d4", combo_salesman.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d5", combo_bil_type.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d6", txtCus_ID.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d7", txtCustomerName.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d8", txt_total_amount.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d9", combo_DiscountType.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d10", txt_dis_amount.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d11", combo_TaxType.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d12", txt_tax_amount.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d13", txt_Total.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d14", txt_old_bal.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d15", txt_new_bal.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d16", txt_rec_amount.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d17", txt_dues.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d18", txt_comment.Text);


                ModCommonClasses.cmd.Connection = ModCommonClasses.con;
                ModCommonClasses.cmd.ExecuteNonQuery();
                ModCommonClasses.con.Close();



                ModCommonClasses.con = new SqlConnection(ModCS.cs);
                ModCommonClasses.con.Open();
                string cb1 = "insert into tbl_Temp_sale_product(InvoiceID,Productcode,Barcode,Invoiceno,Date,Customer,Productname,Price,Qty,Typeofunit,Total) VALUES (@sId,@d1,@d2,@d3,@d4,@d5,@d6,@d7,@d8,@d9,@d10)";
                ModCommonClasses.cmd            = new SqlCommand(cb1);
                ModCommonClasses.cmd.Connection = ModCommonClasses.con;
                // Prepare command for repeated execution
                ModCommonClasses.cmd.Prepare();
                // Data to be inserted
                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    if (!row.IsNewRow)
                    {
                        ModCommonClasses.cmd.Parameters.AddWithValue("@sId", txtinvoice.Text);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d1", row.Cells[0].Value);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d2", row.Cells[1].Value);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d3", txt_invoice_no.Text);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d4", dateTimePicker1.Value.ToString("MM/dd/yyyy"));
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d5", txtCustomerName.Text);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d6", row.Cells[2].Value);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d7", row.Cells[3].Value);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d8", row.Cells[4].Value);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d9", row.Cells[5].Value);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d10", row.Cells[6].Value);

                        ModCommonClasses.cmd.ExecuteNonQuery();
                        ModCommonClasses.cmd.Parameters.Clear();
                    }
                }
                ModCommonClasses.con.Close();



                ModCommonClasses.con = new SqlConnection(ModCS.cs);
                ModCommonClasses.con.Open();
                string cb2 = "insert into tbl_sale_pro(InvoiceID,Productcode,Barcode,Invoiceno,Date,Customer,Productname,Price,Qty,Typeofunit,Total) VALUES (@sId,@d1,@d2,@d3,@d4,@d5,@d6,@d7,@d8,@d9,@d10)";
                ModCommonClasses.cmd            = new SqlCommand(cb2);
                ModCommonClasses.cmd.Connection = ModCommonClasses.con;
                // Prepare command for repeated execution
                ModCommonClasses.cmd.Prepare();
                // Data to be inserted
                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    if (!row.IsNewRow)
                    {
                        ModCommonClasses.cmd.Parameters.AddWithValue("@sId", txtinvoice.Text);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d1", row.Cells[0].Value);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d2", row.Cells[1].Value);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d3", txt_invoice_no.Text);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d4", dateTimePicker1.Value.ToString("MM/dd/yyyy"));
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d5", txtCustomerName.Text);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d6", row.Cells[2].Value);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d7", row.Cells[3].Value);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d8", row.Cells[4].Value);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d9", row.Cells[5].Value);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d10", row.Cells[6].Value);

                        ModCommonClasses.cmd.ExecuteNonQuery();
                        ModCommonClasses.cmd.Parameters.Clear();
                    }
                }
                ModCommonClasses.con.Close();
                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    if (!row.IsNewRow)
                    {
                        ModCommonClasses.con = new SqlConnection(ModCS.cs);
                        ModCommonClasses.con.Open();
                        string ctx = "select Productcode from Temp_Stock where Productcode=@d1 and Barcodeno=@d2";
                        ModCommonClasses.cmd            = new SqlCommand(ctx);
                        ModCommonClasses.cmd.Connection = ModCommonClasses.con;
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d1", row.Cells[0].Value);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d2", row.Cells[1].Value);
                        ModCommonClasses.rdr = ModCommonClasses.cmd.ExecuteReader();
                        if ((ModCommonClasses.rdr.Read()))
                        {
                            ModCommonClasses.con = new SqlConnection(ModCS.cs);
                            ModCommonClasses.con.Open();
                            string cb3 = "Update Temp_Stock set Quantity = Quantity - " + row.Cells[4].Value + " where Productcode=@d1 and Barcodeno=@d2";
                            ModCommonClasses.cmd            = new SqlCommand(cb3);
                            ModCommonClasses.cmd.Connection = ModCommonClasses.con;
                            ModCommonClasses.cmd.Parameters.AddWithValue("@d1", row.Cells[0].Value);
                            ModCommonClasses.cmd.Parameters.AddWithValue("@d2", row.Cells[1].Value);
                            ModCommonClasses.cmd.ExecuteReader();
                            ModCommonClasses.con.Close();
                        }
                    }
                }



                if (combo_bil_type.SelectedIndex == 1)
                {
                    ModFunc.CustomerLedgerSave(dateTimePicker1.Text, txtCustomerID.Text, txtCustomerName.Text, "Sale Credit", 0, Convert.ToDecimal(txt_new_bal.Text) - Convert.ToDecimal(txt_old_bal.Text), txt_cus_mob.Text);
                }

                if (combo_bil_type.SelectedIndex == 0)
                {
                    ModFunc.CustomerLedgerSave(dateTimePicker1.Text, txtCustomerID.Text, txtCustomerName.Text, "Sale Credit", 0, Convert.ToDecimal(txt_new_bal.Text) - Convert.ToDecimal(txt_old_bal.Text), txt_cus_mob.Text);
                    ModFunc.CustomerLedgerSave(dateTimePicker1.Text, txtCustomerID.Text, "Cash Account", "Payment", Convert.ToDecimal(txt_rec_amount.Text), 0, txt_cus_mob.Text);
                }


                if (combo_bil_type.SelectedIndex == 1)
                {
                    ModFunc.LedgerSaveInvoice(dateTimePicker1.Text, txtCustomerID.Text, txtCustomerName.Text, "Sale Credit", 0, Convert.ToDecimal(txt_new_bal.Text) - Convert.ToDecimal(txt_old_bal.Text), txt_cus_mob.Text);
                }


                if (combo_bil_type.SelectedIndex == 0)
                {
                    ModFunc.LedgerSaveInvoice(dateTimePicker1.Text, txtCustomerID.Text, txtCustomerName.Text, "Sale Credit", 0, Convert.ToDecimal(txt_new_bal.Text) - Convert.ToDecimal(txt_old_bal.Text), txt_cus_mob.Text);
                    ModFunc.LedgerSaveInvoice(dateTimePicker1.Text, txtCustomerID.Text, "Cash Account", "Payment", Convert.ToDecimal(txt_rec_amount.Text), 0, txt_cus_mob.Text);
                }



                printDocument1.Print();
                ModFunc.LogFunc(lblUser.Text, "Added the New Sale Having Invoice No. '" + txt_invoice_no.Text + "'");
                MessageBox.Show("Successfully Saved", "Stock", MessageBoxButtons.OK, MessageBoxIcon.Information);

                stockid();
                this.ActiveControl = txt_pro_name;
                txt_pro_name.Focus();

                btn_save.Enabled = false;
                btnnew.Enabled   = true;



                ModCommonClasses.con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                ModCommonClasses.con = new SqlConnection(ModCS.cs);
                ModCommonClasses.con.Open();
                string ct = "select Invoiceno from tbl_purchase where Invoiceno=@d1";
                ModCommonClasses.cmd = new SqlCommand(ct);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d1", txt_invoice.Text);
                ModCommonClasses.cmd.Connection = ModCommonClasses.con;
                ModCommonClasses.rdr            = ModCommonClasses.cmd.ExecuteReader();
                if (ModCommonClasses.rdr.Read())
                {
                    MessageBox.Show("Invoice No. Already Exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txt_invoice.Text = "";
                    txt_invoice.Focus();
                    if ((ModCommonClasses.rdr != null))
                    {
                        ModCommonClasses.rdr.Close();
                    }
                    return;
                }
                ModCommonClasses.con.Close();


                ModCommonClasses.con = new SqlConnection(ModCS.cs);
                ModCommonClasses.con.Open();
                string cb = "insert into tbl_purchase(ST_ID,Invoiceno,Invoicedate,Venderinvoice,Venderinvoicedate,PurchaseType,SupplierID,Suppliercode,Suppliername,Grandtotal,Discount,Discountvalue,Tax,Taxvalue,Netamount,Oldbalance,Newbalance,Paidamount,Duesamount,Comments) VALUES (@d1,@d2,@d3,@d4,@d5,@d6,@d7,@d8,@d9,@d10,@d11,@d12,@d13,@d14,@d15,@d16,@d17,@d18,@d19,@d20)";
                ModCommonClasses.cmd = new SqlCommand(cb);

                ModCommonClasses.cmd.Parameters.AddWithValue("@d1", txtST_ID.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d2", txt_invoice.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d3", dateTimePicker1.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d4", txt_ven_invoice.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d5", dateTimePicker2.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d6", combo_pur_type.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d7", txtSup_ID.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d8", txtSupplierID.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d9", txtSupplierName.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d10", txt_total_amount.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d11", txt_discount.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d12", txt_dis_amount.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d13", txt_tax.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d14", txt_tax_amount.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d15", txt_net_amount.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d16", txt_old_bal.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d17", txt_new_bal.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d18", txt_paid_amount.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d19", txt_dues.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d20", txt_comments.Text);


                ModCommonClasses.cmd.Connection = ModCommonClasses.con;
                ModCommonClasses.cmd.ExecuteNonQuery();
                ModCommonClasses.con.Close();



                ModCommonClasses.con = new SqlConnection(ModCS.cs);
                ModCommonClasses.con.Open();
                string cb1 = "insert into tbl_Temp_pur_product(StockID,Productcode,Barcode,Invoiceno,Date,Suppliername,Productname,Typeofunit,Description,Purchaseprice,Qty,Total,Mfd,Expdate) VALUES (@sId,@d1,@d2,@d3,@d4,@d5,@d6,@d7,@d8,@d9,@d10,@d11,@d12,@d13)";
                ModCommonClasses.cmd            = new SqlCommand(cb1);
                ModCommonClasses.cmd.Connection = ModCommonClasses.con;
                // Prepare command for repeated execution
                ModCommonClasses.cmd.Prepare();
                // Data to be inserted
                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    if (!row.IsNewRow)
                    {
                        ModCommonClasses.cmd.Parameters.AddWithValue("@sId", txtST_ID.Text);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d1", row.Cells[0].Value);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d2", row.Cells[1].Value);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d3", txt_invoice.Text);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d4", dateTimePicker1.Text);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d5", txtSupplierName.Text);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d6", row.Cells[2].Value);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d7", row.Cells[3].Value);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d8", row.Cells[4].Value);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d9", row.Cells[5].Value);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d10", row.Cells[6].Value);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d11", row.Cells[7].Value);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d12", row.Cells[8].Value);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d13", row.Cells[9].Value);

                        ModCommonClasses.cmd.ExecuteNonQuery();
                        ModCommonClasses.cmd.Parameters.Clear();
                    }
                }
                ModCommonClasses.con.Close();



                ModCommonClasses.con = new SqlConnection(ModCS.cs);
                ModCommonClasses.con.Open();
                string cb4 = "insert into tbl_pur_product(StockID,Productcode,Barcode,Invoiceno,Date,Suppliername,Productname,Typeofunit,Description,Purchaseprice,Qty,Total,Mfd,Expdate) VALUES (@sId,@d1,@d2,@d3,@d4,@d5,@d6,@d7,@d8,@d9,@d10,@d11,@d12,@d13)";
                ModCommonClasses.cmd            = new SqlCommand(cb4);
                ModCommonClasses.cmd.Connection = ModCommonClasses.con;
                // Prepare command for repeated execution
                ModCommonClasses.cmd.Prepare();
                // Data to be inserted
                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    if (!row.IsNewRow)
                    {
                        ModCommonClasses.cmd.Parameters.AddWithValue("@sId", txtST_ID.Text);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d1", row.Cells[0].Value);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d2", row.Cells[1].Value);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d3", txt_invoice.Text);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d4", dateTimePicker1.Text);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d5", txtSupplierName.Text);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d6", row.Cells[2].Value);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d7", row.Cells[3].Value);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d8", row.Cells[4].Value);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d9", row.Cells[5].Value);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d10", row.Cells[6].Value);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d11", row.Cells[7].Value);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d12", row.Cells[8].Value);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d13", row.Cells[9].Value);

                        ModCommonClasses.cmd.ExecuteNonQuery();
                        ModCommonClasses.cmd.Parameters.Clear();
                    }
                }
                ModCommonClasses.con.Close();
                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    if (!row.IsNewRow)
                    {
                        ModCommonClasses.con = new SqlConnection(ModCS.cs);
                        ModCommonClasses.con.Open();
                        string ctx = "select Productcode from Temp_Stock where Productcode=@d1 and Barcodeno=@d2";
                        ModCommonClasses.cmd            = new SqlCommand(ctx);
                        ModCommonClasses.cmd.Connection = ModCommonClasses.con;
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d1", row.Cells[0].Value);
                        ModCommonClasses.cmd.Parameters.AddWithValue("@d2", row.Cells[1].Value);
                        ModCommonClasses.rdr = ModCommonClasses.cmd.ExecuteReader();
                        if ((ModCommonClasses.rdr.Read()))
                        {
                            ModCommonClasses.con = new SqlConnection(ModCS.cs);
                            ModCommonClasses.con.Open();
                            string cb2 = "Update Temp_Stock set Quantity = Quantity + " + row.Cells[6].Value + " where Productcode=@d1 and Barcodeno=@d2";
                            ModCommonClasses.cmd            = new SqlCommand(cb2);
                            ModCommonClasses.cmd.Connection = ModCommonClasses.con;
                            ModCommonClasses.cmd.Parameters.AddWithValue("@d1", row.Cells[0].Value);
                            ModCommonClasses.cmd.Parameters.AddWithValue("@d2", row.Cells[1].Value);
                            ModCommonClasses.cmd.ExecuteReader();
                            ModCommonClasses.con.Close();
                        }
                        else
                        {
                            ModCommonClasses.con = new SqlConnection(ModCS.cs);
                            ModCommonClasses.con.Open();
                            string cb3 = "insert into Temp_Stock(ProductCode,Barcodeno,Product,Typeofunit,Description,Purchaseprice,Quantity,Mfd,Expdate) VALUES (@d1,@d2,@d3,@d4,@d5,@d6,@d7,@d8,@d9)";
                            ModCommonClasses.cmd            = new SqlCommand(cb3);
                            ModCommonClasses.cmd.Connection = ModCommonClasses.con;
                            ModCommonClasses.cmd.Parameters.AddWithValue("@d1", row.Cells[0].Value);
                            ModCommonClasses.cmd.Parameters.AddWithValue("@d2", row.Cells[1].Value);

                            ModCommonClasses.cmd.Parameters.AddWithValue("@d3", row.Cells[2].Value);
                            ModCommonClasses.cmd.Parameters.AddWithValue("@d4", row.Cells[3].Value);

                            ModCommonClasses.cmd.Parameters.AddWithValue("@d5", row.Cells[4].Value);
                            ModCommonClasses.cmd.Parameters.AddWithValue("@d6", row.Cells[5].Value);
                            ModCommonClasses.cmd.Parameters.AddWithValue("@d7", row.Cells[6].Value);
                            ModCommonClasses.cmd.Parameters.AddWithValue("@d8", row.Cells[7].Value);

                            ModCommonClasses.cmd.Parameters.AddWithValue("@d9", row.Cells[8].Value);


                            ModCommonClasses.cmd.ExecuteReader();
                            ModCommonClasses.con.Close();
                        }
                    }
                }



                if (combo_pur_type.SelectedIndex == 1)
                {
                    ModFunc.SupplierLedgerSaveInvoice(dateTimePicker1.Text, txtSupplierID.Text, txtSupplierName.Text, "Purchase", 0, Convert.ToDecimal(txt_new_bal.Text) - Convert.ToDecimal(txt_old_bal.Text), txtContactNo.Text);
                }


                if (combo_pur_type.SelectedIndex == 0)
                {
                    ModFunc.SupplierLedgerSaveInvoice(dateTimePicker1.Text, txtSupplierID.Text, txtSupplierName.Text, "Purchase", 0, Convert.ToDecimal(txt_new_bal.Text) - Convert.ToDecimal(txt_old_bal.Text), txtContactNo.Text);
                    ModFunc.SupplierLedgerSaveInvoice(dateTimePicker1.Text, txtSupplierID.Text, "Cash Account", "Payment", Convert.ToDecimal(txt_paid_amount.Text), 0, txtContactNo.Text);
                }



                if (combo_pur_type.SelectedIndex == 1)
                {
                    ModFunc.LedgerSaveInvoice(dateTimePicker1.Text, txtSupplierID.Text, txtSupplierName.Text, "Purchase", 0, Convert.ToDecimal(txt_new_bal.Text) - Convert.ToDecimal(txt_old_bal.Text), txtContactNo.Text);
                }


                if (combo_pur_type.SelectedIndex == 0)
                {
                    ModFunc.LedgerSaveInvoice(dateTimePicker1.Text, txtSupplierID.Text, txtSupplierName.Text, "Purchase", 0, Convert.ToDecimal(txt_new_bal.Text) - Convert.ToDecimal(txt_old_bal.Text), txtContactNo.Text);
                    ModFunc.LedgerSaveInvoice(dateTimePicker1.Text, txtSupplierID.Text, "Cash Account", "Payment", Convert.ToDecimal(txt_paid_amount.Text), 0, txtContactNo.Text);
                }



                ModFunc.LogFunc(lblUser.Text, "Added the New Purchase Having Invoice No. '" + txt_invoice.Text + "'");
                MessageBox.Show("Successfully Saved", "Stock", MessageBoxButtons.OK, MessageBoxIcon.Information);

                this.ActiveControl = txt_product;
                txt_product.Focus();

                btnSave.Enabled = false;
                btnNew.Enabled  = true;

                ModCommonClasses.con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }