/// <summary>
 /// On print button click
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnPrint_Click(object sender, EventArgs e)
 {
     try
     {
         //frmReport crptReport = new frmReport();
         DataSet   ds          = new DataSet();
         DataTable dtblFormat2 = new DataTable();
         DataTable dtblTotal   = new DataTable();
         CompanySP spCompany   = new CompanySP();
         DataTable dtblCompany = new DataTable();
         dtblCompany = spCompany.CompanyViewAll();
         if (dgvVatreturn.Rows.Count > 0)
         {
             if (dtblFill.Rows.Count > 0)
             {
                 DataTable dtblReportFill = new DataTable();
                 dtblReportFill.Columns.Add("SlNO");
                 dtblReportFill.Columns.Add("Invoice No");
                 dtblReportFill.Columns.Add("Date");
                 dtblReportFill.Columns.Add("Party Name");
                 dtblReportFill.Columns.Add("Mailing Name");
                 dtblReportFill.Columns.Add("Tin No");
                 dtblReportFill.Columns.Add("qt");
                 dtblReportFill.Columns.Add("Sales Amound");
                 dtblReportFill.Columns.Add("Tax Amount");
                 dtblReportFill.Columns.Add("Cess");
                 dtblReportFill.Columns.Add("Net Amount");
                 dtblReportFill.Columns.Add("billDiscount");
                 dtblReportFill.Columns.Add("grandtotal");
                 for (int i = 0; i < dgvVatreturn.Rows.Count; i++)
                 {
                     DataRow drow = dtblReportFill.NewRow();
                     if (dgvVatreturn.Rows[i].Cells["dgvtxtSlno"].Value != null)
                     {
                         drow["SlNO"] = dgvVatreturn.Rows[i].Cells["dgvtxtSlno"].Value.ToString();
                     }
                     if (dgvVatreturn.Rows[i].Cells["dgvtxtInvoiceNo"].Value != null)
                     {
                         drow["Invoice No"] = dgvVatreturn.Rows[i].Cells["dgvtxtInvoiceNo"].Value.ToString();
                     }
                     if (dgvVatreturn.Rows[i].Cells["dgvtxtDate"].Value != null)
                     {
                         drow["Date"] = dgvVatreturn.Rows[i].Cells["dgvtxtDate"].Value.ToString();
                     }
                     if (dgvVatreturn.Rows[i].Cells["dgvtxtPartyName"].Value != null)
                     {
                         drow["Party Name"] = dgvVatreturn.Rows[i].Cells["dgvtxtPartyName"].Value.ToString();
                     }
                     if (dgvVatreturn.Rows[i].Cells["dgvtxtMailingName"].Value.ToString() != string.Empty)
                     {
                         drow["Mailing Name"] = dgvVatreturn.Rows[i].Cells["dgvtxtMailingName"].Value.ToString();
                     }
                     if (dgvVatreturn.Rows[i].Cells["dgvtxtTinNo"].Value != null)
                     {
                         drow["Tin No"] = dgvVatreturn.Rows[i].Cells["dgvtxtTinNo"].Value.ToString();
                     }
                     if (dgvVatreturn.Rows[i].Cells["dgvtxtQty"].Value != null)
                     {
                         drow["qt"] = dgvVatreturn.Rows[i].Cells["dgvtxtQty"].Value.ToString();
                     }
                     if (dgvVatreturn.Rows[i].Cells["dgvtxtSalesAmount"].Value != null)
                     {
                         drow["Sales Amound"] = dgvVatreturn.Rows[i].Cells["dgvtxtSalesAmount"].Value.ToString();
                     }
                     if (dgvVatreturn.Rows[i].Cells["dgvtxtTaxAmount"].Value != null)
                     {
                         drow["Tax Amount"] = dgvVatreturn.Rows[i].Cells["dgvtxtTaxAmount"].Value.ToString();
                     }
                     if (dgvVatreturn.Rows[i].Cells["dgvtxtCess"].Value != null)
                     {
                         drow["Cess"] = dgvVatreturn.Rows[i].Cells["dgvtxtCess"].Value.ToString();
                     }
                     if (dgvVatreturn.Rows[i].Cells["dgvtxtNetAmount"].Value != null)
                     {
                         drow["Net Amount"] = dgvVatreturn.Rows[i].Cells["dgvtxtNetAmount"].Value.ToString();
                     }
                     if (dgvVatreturn.Rows[i].Cells["dgvtxtbillDiscount"].Value != null)
                     {
                         drow["billDiscount"] = dgvVatreturn.Rows[i].Cells["dgvtxtbillDiscount"].Value.ToString();
                     }
                     if (dgvVatreturn.Rows[i].Cells["dgvtxtGrandTotal"].Value != null)
                     {
                         drow["grandtotal"] = dgvVatreturn.Rows[i].Cells["dgvtxtGrandTotal"].Value.ToString();
                     }
                     dtblReportFill.Rows.Add(drow);
                 }
                 ds.Tables.Add(dtblReportFill);
                 ds.Tables.Add(dtblCompany);
                 //crptReport.vatreturnReport(ds);
             }
             else
             {
                 VoucherTypeSP spVoucher = new VoucherTypeSP();
                 dtblFormat2 = spVoucher.VatGridFill(DateTime.Parse(dtpFrmDate.Text), DateTime.Parse(dtpToDate.Text), cmbTypeofVoucher.Text, Convert.ToDecimal(cmbVouchertype.SelectedValue.ToString()), strformat, cmbTax.Text);
                 if (dgvVatreturn.Rows.Count > 1)
                 {
                     dtblTotal.Columns.Add("taxableamt");
                     dtblTotal.Columns.Add("taxAmount");
                     DataRow dr1 = dtblTotal.NewRow();
                     dr1["taxableamt"] = dgvVatreturn.Rows[dgvVatreturn.Rows.Count - 2].Cells["dgvtxtTaxableAmount"].Value.ToString();
                     dr1["taxAmount"]  = dgvVatreturn.Rows[dgvVatreturn.Rows.Count - 2].Cells["dgvtxttax"].Value.ToString();
                     dtblTotal.Rows.Add(dr1);
                     ds.Tables.Add(dtblCompany);
                     ds.Tables.Add(dtblFormat2);
                     ds.Tables.Add(dtblTotal);
                     //crptReport.vatreturnReportFormat(ds);
                 }
             }
         }
         else
         {
             MessageBox.Show("No data found", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("VRR:14" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// Function to fill the grid
        /// </summary>
        public void GridFill()
        {
            try
            {
                dgvVatreturn.Rows.Clear();
                DataTable dt = new DataTable();
                string    strVoucherTypeName = string.Empty;
                decimal   decVoucherTypeId;
                if (rbtnFormat1.Checked)
                {
                    strformat = "type1";
                }
                else
                {
                    strformat = "type2";
                }
                if (cmbVouchertype.Enabled)
                {
                    decVoucherTypeId = Convert.ToDecimal(cmbVouchertype.SelectedValue.ToString());
                }
                else
                {
                    decVoucherTypeId = 0;
                }
                strVoucherTypeName = Convert.ToString(cmbTypeofVoucher.Text);
                VoucherTypeSP spVoucher = new VoucherTypeSP();
                dt       = spVoucher.VatGridFill(Convert.ToDateTime(dtpFrmDate.Text), Convert.ToDateTime(dtpToDate.Text), strVoucherTypeName, decVoucherTypeId, strformat, cmbTax.Text);
                dtblFill = dt;
                DataTable dtblTaxName = new DataTable();
                dtblTaxName = spVoucher.VatViewTaxNames();
                if (rbtnFormat1.Checked)
                {
                    dgvVatreturn.Columns["dgvtxtTaxName"].Visible       = false;
                    dgvVatreturn.Columns["dgvtxtTaxableAmount"].Visible = false;
                    dgvVatreturn.Columns["dgvtxttax"].Visible           = false;
                    dgvVatreturn.Columns["dgvtxtQty"].Visible           = true;
                    dgvVatreturn.Columns["dgvtxtSalesAmount"].Visible   = true;
                    dgvVatreturn.Columns["dgvtxtTaxAmount"].Visible     = true;
                    dgvVatreturn.Columns["dgvtxtNetAmount"].Visible     = true;
                    dgvVatreturn.Columns["dgvtxtbillDiscount"].Visible  = true;
                    foreach (DataRow drowDetails in dt.Rows)
                    {
                        dgvVatreturn.Rows.Add();
                        dgvVatreturn.Rows[dgvVatreturn.Rows.Count - 1].Cells["dgvtxtInvoiceNo"].Value     = drowDetails["Invoice No"].ToString();
                        dgvVatreturn.Rows[dgvVatreturn.Rows.Count - 1].Cells["dgvtxtDate"].Value          = drowDetails["Date"].ToString();
                        dgvVatreturn.Rows[dgvVatreturn.Rows.Count - 1].Cells["dgvtxtPartyName"].Value     = drowDetails["Party Name"].ToString();
                        dgvVatreturn.Rows[dgvVatreturn.Rows.Count - 1].Cells["dgvtxtMailingName"].Value   = drowDetails["Mailing Name"].ToString();
                        dgvVatreturn.Rows[dgvVatreturn.Rows.Count - 1].Cells["dgvtxtsalesmasterid"].Value = drowDetails["SalesMasterId"].ToString();
                        dgvVatreturn.Rows[dgvVatreturn.Rows.Count - 1].Cells["dgvtxtvoucherName"].Value   = drowDetails["voucherName"].ToString();

                        dgvVatreturn.Rows[dgvVatreturn.Rows.Count - 1].Cells["dgvtxtVoucherType"].Value = drowDetails["voucherType"].ToString();

                        decimal dSaleId        = Convert.ToDecimal(dgvVatreturn.Rows[dgvVatreturn.Rows.Count - 1].Cells["dgvtxtsalesmasterid"].Value.ToString());
                        string  strVoucherType = Convert.ToString(dgvVatreturn.Rows[dgvVatreturn.Rows.Count - 1].Cells["dgvtxtVoucherType"].Value);
                        string  qt             = spVoucher.VoucherreportsumQty(dSaleId, strVoucherType);

                        dgvVatreturn.Rows[dgvVatreturn.Rows.Count - 1].Cells["dgvtxtTinNo"].Value        = drowDetails["Tin No"].ToString();
                        dgvVatreturn.Rows[dgvVatreturn.Rows.Count - 1].Cells["dgvtxtQty"].Value          = qt;
                        dgvVatreturn.Rows[dgvVatreturn.Rows.Count - 1].Cells["dgvtxtSalesAmount"].Value  = drowDetails["Sales Amound"].ToString();
                        dgvVatreturn.Rows[dgvVatreturn.Rows.Count - 1].Cells["dgvtxtTaxAmount"].Value    = Math.Round(Convert.ToDecimal(drowDetails["Tax Amount"].ToString()), PublicVariables._inNoOfDecimalPlaces).ToString();
                        dgvVatreturn.Rows[dgvVatreturn.Rows.Count - 1].Cells["dgvtxtCess"].Value         = drowDetails["Cess"].ToString();
                        dgvVatreturn.Rows[dgvVatreturn.Rows.Count - 1].Cells["dgvtxtNetAmount"].Value    = Math.Round(Convert.ToDecimal(drowDetails["Net Amount"].ToString()), PublicVariables._inNoOfDecimalPlaces).ToString();
                        dgvVatreturn.Rows[dgvVatreturn.Rows.Count - 1].Cells["dgvtxtbillDiscount"].Value = Math.Round(Convert.ToDecimal(drowDetails["billDiscount"].ToString()), PublicVariables._inNoOfDecimalPlaces).ToString();
                        dgvVatreturn.Rows[dgvVatreturn.Rows.Count - 1].Cells["dgvtxtGrandTotal"].Value   = Math.Round(Convert.ToDecimal(drowDetails["grandtotal"].ToString()), PublicVariables._inNoOfDecimalPlaces).ToString();;
                    }
                    if (dgvVatreturn.Rows.Count > 0)
                    {
                        SerialNo();
                    }
                }
                else
                {
                    dgvVatreturn.Rows.Clear();
                    dgvVatreturn.Columns["dgvtxtTaxName"].Visible       = true;
                    dgvVatreturn.Columns["dgvtxtTaxableAmount"].Visible = true;
                    dgvVatreturn.Columns["dgvtxttax"].Visible           = true;
                    dgvVatreturn.Columns["dgvtxtQty"].Visible           = false;
                    dgvVatreturn.Columns["dgvtxtSalesAmount"].Visible   = false;
                    dgvVatreturn.Columns["dgvtxtTaxAmount"].Visible     = false;
                    dgvVatreturn.Columns["dgvtxtNetAmount"].Visible     = false;
                    dgvVatreturn.Columns["dgvtxtbillDiscount"].Visible  = false;
                    foreach (DataRow drowDetails in dt.Rows)
                    {
                        dgvVatreturn.Rows.Add();

                        dgvVatreturn.Rows[dgvVatreturn.Rows.Count - 1].Cells["dgvtxtInvoiceNo"].Value     = drowDetails["Invoice No"].ToString();
                        dgvVatreturn.Rows[dgvVatreturn.Rows.Count - 1].Cells["dgvtxtDate"].Value          = drowDetails["Date"].ToString();
                        dgvVatreturn.Rows[dgvVatreturn.Rows.Count - 1].Cells["dgvtxtPartyName"].Value     = drowDetails["Party Name"].ToString();
                        dgvVatreturn.Rows[dgvVatreturn.Rows.Count - 1].Cells["dgvtxtMailingName"].Value   = drowDetails["Mailing Name"].ToString();
                        dgvVatreturn.Rows[dgvVatreturn.Rows.Count - 1].Cells["dgvtxtsalesmasterid"].Value = drowDetails["SalesMasterId"].ToString();
                        dgvVatreturn.Rows[dgvVatreturn.Rows.Count - 1].Cells["dgvtxtTinNo"].Value         = drowDetails["Tin No"].ToString();
                        dgvVatreturn.Rows[dgvVatreturn.Rows.Count - 1].Cells["dgvtxtGrandTotal"].Value    = drowDetails["grandtotal"].ToString();
                        dgvVatreturn.Rows[dgvVatreturn.Rows.Count - 1].Cells["dgvtxtTaxName"].Value       = drowDetails["taxName"].ToString();
                        dgvVatreturn.Rows[dgvVatreturn.Rows.Count - 1].Cells["dgvtxtTaxableAmount"].Value = drowDetails["rate"].ToString();
                        dgvVatreturn.Rows[dgvVatreturn.Rows.Count - 1].Cells["dgvtxttax"].Value           = drowDetails["taxamount"].ToString();
                        dgvVatreturn.Rows[dgvVatreturn.Rows.Count - 1].Cells["dgvtxtvoucherName"].Value   = drowDetails["voucherName"].ToString();
                        dgvVatreturn.Rows[dgvVatreturn.Rows.Count - 1].Cells["dgvtxtVoucherType"].Value   = drowDetails["voucherType"].ToString();
                    }
                    if (dgvVatreturn.Rows.Count > 0)
                    {
                        SerialNo();
                        dgvVatreturn.Rows.Add();
                        CalculateTotal();
                    }
                    dtblFill.Clear();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("VRR:06" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }