/// <summary>
 /// Function to use to fill details to updation when comes register or report
 /// </summary>
 public void FillRegisterOrReport()
 {
     try
     {
         SalesQuotationMasterInfo infoSalesQuotationMaster = new SalesQuotationMasterInfo();
         SalesOrderMasterInfo infoSalesOrderMaster = new SalesOrderMasterInfo();
         SalesOrderBll bllSalesOrder = new SalesOrderBll();
         isValueChange = false;
         btnSave.Text = "Update";
         btnDelete.Enabled = true;
         txtOrderNo.ReadOnly = true;
         infoSalesOrderMaster = bllSalesOrder.SalesOrderMasterView(decSalesOrderMasterId);
         txtOrderNo.Text = infoSalesOrderMaster.InvoiceNo;
         strVoucherNo = infoSalesOrderMaster.VoucherNo.ToString();
         decSalesSuffixPrefixId = Convert.ToDecimal(infoSalesOrderMaster.SuffixPrefixId);
         decSalesVoucherId = Convert.ToDecimal(infoSalesOrderMaster.VoucherTypeId);
         isAutomatic = new VoucherTypeBll().CheckMethodOfVoucherNumbering(decSalesVoucherId);
         decSalesOrderTypeId = decSalesVoucherId;
         txtDate.Text = infoSalesOrderMaster.Date.ToString("dd-MMM-yyyy");
         cmbCashOrParty.SelectedValue = infoSalesOrderMaster.LedgerId;
         decSalesOrderVoucherTypeId = infoSalesOrderMaster.VoucherTypeId;
         VoucherTypeInfo infoVoucherType = new VoucherTypeInfo();
         VoucherTypeBll BllVoucherType = new VoucherTypeBll();
         infoVoucherType = BllVoucherType.VoucherTypeView(decSalesOrderVoucherTypeId);
         string strVoucherTypeName = infoVoucherType.VoucherTypeName;
         this.Text = strVoucherTypeName;
         if (infoSalesOrderMaster.QuotationMasterId == 0)
         {
             cmbType.SelectedItem = "NA";
         }
         else if (infoSalesOrderMaster.QuotationMasterId != 0)
         {
             infoSalesQuotationMaster = new SalesQuotationBll().SalesQuotationMasterView(infoSalesOrderMaster.QuotationMasterId);
             cmbType.SelectedValue = infoSalesQuotationMaster.VoucherTypeId;
             AgainstQuotationComboFill();
             cmbQuotationNo.SelectedValue = infoSalesOrderMaster.QuotationMasterId;
         }
         txtDueDate.Text = infoSalesOrderMaster.DueDate.ToString("dd-MMM-yyyy");
         TimeSpan objTs = Convert.ToDateTime(txtDueDate.Text).Subtract(Convert.ToDateTime(txtDate.Text));
         txtDueDays.Text = objTs.Days.ToString();
         txtNarration.Text = infoSalesOrderMaster.Narration;
         cmbCurrency.SelectedValue = infoSalesOrderMaster.ExchangeRateId;
         cmbPricingLevel.SelectedValue = infoSalesOrderMaster.PricinglevelId;
         SalesManComboFill();
         cmbSalesMan.SelectedValue = infoSalesOrderMaster.EmployeeId;
         txtTotalAmount.Text = infoSalesOrderMaster.TotalAmount.ToString();
         List<DataTable> ListObj = new List<DataTable>();
         ListObj = bllSalesOrder.SalesOrderDetailsViewByMasterId(decSalesOrderMasterId);
         if (CheckCancelStatus(decSalesOrderMasterId))
         {
             isCheck = true;
             cbxCancelled.Checked = true;
             cbxCancelled.Enabled = false;
             btnSave.Enabled = false;
             isCheck = false;
         }
         else
         {
             isCheck = true;
             cbxCancelled.Enabled = true;
             cbxCancelled.Checked = false;
             isCheck = false;
         }
         if (isAutomatic)
         {
             txtOrderNo.ReadOnly = true;
             txtDate.Focus();
         }
         else
         {
             txtOrderNo.ReadOnly = false;
             txtOrderNo.Focus();
         }
         for (int i = 0; i < ListObj[0].Rows.Count; i++)
         {
             isAmountcalc = false;
             isValueChange = false;
             dgvSalesOrder.Rows.Add();
             dgvSalesOrder.Rows[i].HeaderCell.Value = string.Empty;
             dgvSalesOrder.Rows[i].Cells["dgvtxtSalesOrderDetailsId"].Value = Convert.ToDecimal(ListObj[0].Rows[i]["salesOrderDetailsId"].ToString());
             dgvSalesOrder.Rows[i].Cells["dgvtxtProductId"].Value = ListObj[0].Rows[i]["productId"].ToString();
             dgvSalesOrder.Rows[i].Cells["dgvtxtProductCode"].Value = ListObj[0].Rows[i]["productCode"].ToString();
             dgvSalesOrder.Rows[i].Cells["dgvtxtProductName"].Value = ListObj[0].Rows[i]["productName"].ToString();
             dgvSalesOrder.Rows[i].Cells["dgvtxtQty"].Value = ListObj[0].Rows[i]["qty"].ToString();
             UnitComboFill(Convert.ToDecimal(dgvSalesOrder.Rows[i].Cells["dgvtxtProductId"].Value.ToString()), i, dgvSalesOrder.Rows[i].Cells["dgvcmbUnit"].ColumnIndex);
             dgvSalesOrder.Rows[i].Cells["dgvcmbUnit"].Value = Convert.ToDecimal(ListObj[0].Rows[i]["unitId"].ToString());
             dgvSalesOrder.Rows[i].Cells["dgvtxtRate"].Value = ListObj[0].Rows[i]["rate"].ToString();
             BatchComboFill(Convert.ToDecimal(dgvSalesOrder.Rows[i].Cells["dgvtxtProductId"].Value.ToString()), i, dgvSalesOrder.Rows[i].Cells["dgvcmbBatch"].ColumnIndex);
             dgvSalesOrder.Rows[i].Cells["dgvcmbBatch"].Value = Convert.ToDecimal(ListObj[0].Rows[i]["batchId"].ToString());
             dgvSalesOrder.Rows[i].Cells["dgvtxtBarcode"].Value = ListObj[0].Rows[i]["barcode"].ToString();
             dgvSalesOrder.Rows[i].Cells["dgvtxtAmount"].Value = ListObj[0].Rows[i]["amount"].ToString();
             dgvSalesOrder.Rows[i].Cells["dgvtxtUnitConversionId"].Value = ListObj[0].Rows[i]["unitConversionId"].ToString();
             dgvSalesOrder.Rows[i].Cells["dgvtxtConversionRate"].Value = ListObj[0].Rows[i]["conversionRate"].ToString();
             dgvSalesOrder.Rows[i].Cells["dgvtxtSalesQuotationDetailsId"].Value = ListObj[0].Rows[i]["quotationDetailsId"].ToString();
             if (Convert.ToDecimal(ListObj[0].Rows[i]["quotationDetailsId"].ToString()) != 0)
             {
                 dgvSalesOrder.Rows[i].Cells["dgvtxtProductCode"].ReadOnly = true;
                 dgvSalesOrder.Rows[i].Cells["dgvtxtProductName"].ReadOnly = true;
                 dgvSalesOrder.Rows[i].Cells["dgvtxtBarcode"].ReadOnly = true;
             }
             if (cmbQuotationNo.Visible == true)
             {
                 dgvSalesOrder.Rows[i].Cells["dgvcmbUnit"].ReadOnly = true;
             }
         }
         isAmountcalc = true;
         isEditFill = false;
         isValueChange = true;
         isDoAfterGridFill = true;
     }
     catch (Exception ex)
     {
         MessageBox.Show("SO30:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }