private void btnShow_Click(object sender, EventArgs e)
        {
            try
            {
                if (cmbDealerName.SelectedIndex == 0)
                {
                    MessageBox.Show("Please selet dealer name");
                    cmbDealerName.Focus();
                    return;
                }
                else
                {
                    DataTable dtChallaneList = TempPurchaseDetailsController.getChallenList(Convert.ToInt64(cmbDealerName.SelectedValue), Convert.ToDateTime(dtpFromChallanDate.Value.ToShortDateString()), Convert.ToDateTime(dtpToChallanDate.Value.ToShortDateString()), Utility.FinancilaYearId);
                    dgvSaleChallan.DataSource = dtChallaneList;

                    dgvSaleChallan.ReadOnly            = false;
                    dgvSaleChallan.Columns[0].ReadOnly = true;
                    dgvSaleChallan.Columns[1].ReadOnly = true;
                    dgvSaleChallan.Columns[2].ReadOnly = true;
                    dgvSaleChallan.Columns[3].ReadOnly = true;
                }
            }
            catch (Exception ae)
            {
                MessageBox.Show(ae.ToString());
            }
        }
 private void btnnew_Click(object sender, EventArgs e)
 {
     try
     {
         dgvPurchaseBook.DataSource = null;
         string opration = "";
         if (rdbAll.Checked == true)
         {
             opration = "All";
         }
         if (rbtnCash.Checked == true)
         {
             opration = "Cash";
         }
         if (rbtnCredit.Checked == true)
         {
             opration = "Credit";
         }
         DataTable lstSaleBill = TempPurchaseDetailsController.PurchaseDayBook(Convert.ToDateTime(dtpFromDate.Value.ToShortDateString()), Convert.ToDateTime(dtpToDate.Value.ToShortDateString()), opration, Utility.FinancilaYearId);
         if (lstSaleBill.Rows.Count > 0)
         {
             AddAutoIncrementColumn(lstSaleBill);
             //  DataTable dtSaleBook = SubTot(lstSaleBill);
             DataRow dr = lstSaleBill.NewRow();
             dr["Bill Amount"]       = billAMt;
             dr["Total Taxable Amt"] = Math.Round(TotalTaxableAmt, 2);
             dr["Total Tax Amt"]     = Math.Round(billAMt - TotalTaxableAmt);
             dr["grossAmount"]       = Math.Round(grossAmount);
             lstSaleBill.Rows.Add(dr);
             BindNewData(lstSaleBill);
             dgvPurchaseItems.Rows.Clear();
             dgvPurchaseItems.Visible = true;
         }
         else
         {
             dgvPurchaseItems.Rows.Clear();
             dgvPurchaseItems.Visible = false;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
        private void dgvPurchaseBook_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                long purchaseId = 0;
                if (e.RowIndex >= 0)
                {
                    purchaseId = Convert.ToInt64(dgvPurchaseBook.CurrentRow.Cells["purchaseId"].Value);
                }
                DataTable dtSaleChallen = TempPurchaseDetailsController.getPurchaseIvoiceDetails(purchaseId, Utility.FinancilaYearId);
                dgvPurchaseItems.Rows.Clear();
                dgvPurchaseItems.Rows.Add();
                foreach (DataRow dr in dtSaleChallen.Rows)
                {
                    dgvPurchaseItems.CurrentRow.Cells["itemId"].Value               = Convert.ToInt64(dr["itemId"]);
                    dgvPurchaseItems.CurrentRow.Cells["StockId"].Value              = Convert.ToInt64(0);
                    dgvPurchaseItems.CurrentRow.Cells["categoryId"].Value           = Convert.ToInt32(dr["categoryId"]);
                    dgvPurchaseItems.CurrentRow.Cells["companyId"].Value            = Convert.ToInt32(dr["companyId"]);
                    dgvPurchaseItems.CurrentRow.Cells["purchaseItemDetailId"].Value = Convert.ToInt32(dr["purchaseItemDetailId"]);
                    dgvPurchaseItems.CurrentRow.Cells["purchaseChalanId"].Value     = 0;
                    dgvPurchaseItems.CurrentRow.Cells["batchNo"].Value              = Convert.ToString(dr["batchNo"]);
                    dgvPurchaseItems.CurrentRow.Cells["itemName"].Value             = dr["itemName"].ToString();
                    dgvPurchaseItems.CurrentRow.Cells["HSNCode"].Value              = dr["HNSCode"].ToString();
                    dgvPurchaseItems.CurrentRow.Cells["rackNo"].Value               = dr["rackNo"].ToString();
                    dgvPurchaseItems.CurrentRow.Cells["productCode"].Value          = dr["productCode"].ToString();
                    //dgvPurchaseItems.CurrentRow.Cells["HSNCode"].Value = dr["HNSCode"].ToString();
                    dgvPurchaseItems.CurrentRow.Cells["MRP"].Value                 = dr["MRP"].ToString();
                    dgvPurchaseItems.CurrentRow.Cells["Quantity"].Value            = dr["Quantity"].ToString();
                    dgvPurchaseItems.CurrentRow.Cells["unitBy"].Value              = dr["unitBy"].ToString();
                    dgvPurchaseItems.CurrentRow.Cells["mfgDate"].Value             = dr["MFD_Date"].ToString();
                    dgvPurchaseItems.CurrentRow.Cells["expireDate"].Value          = dr["expireDate"].ToString();
                    dgvPurchaseItems.CurrentRow.Cells["discount"].Value            = dr["discount"].ToString();
                    dgvPurchaseItems.CurrentRow.Cells["discountPer"].Value         = dr["discountPer"].ToString();
                    dgvPurchaseItems.CurrentRow.Cells["freeQuantity"].Value        = Utility.ParseValue(dr["freeQuantity"].ToString());
                    dgvPurchaseItems.CurrentRow.Cells["salesCashRate"].Value       = Utility.ParseValue(dr["salesCashRate"].ToString());
                    dgvPurchaseItems.CurrentRow.Cells["purchaseRateWithGST"].Value = Math.Round(Utility.ParseValue(dr["purchaseRate"].ToString()) + ((Utility.ParseValue(dr["purchaseRate"].ToString()) * Utility.ParseValue(dr["IGST"].ToString())) / 100), 2);
                    dgvPurchaseItems.CurrentRow.Cells["purchaseRate"].Value        = Utility.ParseValue(dr["purchaseRate"].ToString());
                    double Discount = ((Utility.ParseValue(dgvPurchaseItems.CurrentRow.Cells["purchaseRate"].Value.ToString()) * Utility.ParseValue(dgvPurchaseItems.CurrentRow.Cells["discountPer"].Value.ToString()) / 100)) + Utility.ParseValue(dgvPurchaseItems.CurrentRow.Cells["discount"].Value.ToString());
                    if (Discount > 0)
                    {
                        dgvPurchaseItems.CurrentRow.Cells["ActualPurchaseRate"].Value = Utility.ParseValue(dgvPurchaseItems.CurrentRow.Cells["purchaseRate"].Value.ToString()) - Discount;
                    }
                    else
                    {
                        dgvPurchaseItems.CurrentRow.Cells["ActualPurchaseRate"].Value = Utility.ParseValue(dgvPurchaseItems.CurrentRow.Cells["purchaseRate"].Value.ToString());
                    } dgvPurchaseItems.CurrentRow.Cells["TaxableAmount"].Value = Math.Round((Utility.ParseValue(dgvPurchaseItems.CurrentRow.Cells["Quantity"].Value.ToString()) - Utility.ParseValue(dgvPurchaseItems.CurrentRow.Cells["freeQuantity"].Value.ToString())) * Utility.ParseValue(dgvPurchaseItems.CurrentRow.Cells["ActualPurchaseRate"].Value.ToString()), 2);
                    //  dgvPurchaseItems.CurrentRow.Cells["totalAmount"].Value = Utility.ParseValue(dgvPurchaseItems.CurrentRow.Cells["Quantity"].Value.ToString()) * Convert.ToDouble(dgvPurchaseItems.CurrentRow.Cells["purchaseRate"].Value.ToString());

                    //double discount = (Utility.ParseValue(dgvPurchaseItems.CurrentRow.Cells["discount"].Value.ToString()) * (Convert.ToDouble(dgvPurchaseItems.CurrentRow.Cells["purchaseRate"].Value)) / 100);
                    double purRate = (Convert.ToDouble(Utility.ParseValue(dgvPurchaseItems.CurrentRow.Cells["Quantity"].Value.ToString()) * Utility.ParseValue(dgvPurchaseItems.CurrentRow.Cells["ActualPurchaseRate"].Value.ToString())));

                    dgvPurchaseItems.CurrentRow.Cells["totalAmount"].Value = Convert.ToDouble(purRate + Utility.ParseValue(dgvPurchaseItems.CurrentRow.Cells["IGSTAmt"].Value.ToString())).ToString();

                    //  dgvPurchaseItems.Focus();
                    //   dgvPurchaseItems.CurrentCell = dgvPurchaseItems.CurrentRow.Cells["Quantity"];
                    dgvPurchaseItems.BeginEdit(true);
                    int col = dgvPurchaseItems.CurrentCell.ColumnIndex;
                    int row = dgvPurchaseItems.CurrentCell.RowIndex;
                    col = 0;
                    row++;
                    if (dgvPurchaseItems.Rows.Count < dtSaleChallen.Rows.Count)
                    {
                        if (row == dgvPurchaseItems.RowCount)
                        {
                            dgvPurchaseItems.Rows.Add();
                            dgvPurchaseItems.CurrentCell = dgvPurchaseItems[col + 7, row];
                        }
                    }
                }
                dgvPurchaseItems.ClearSelection();
            }
            catch (Exception ae)
            {
                MessageBox.Show(ae.Message);
            }
        }