/// <summary>
 /// On cellvaluechange of dgvServiceVoucher
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void dgvServiceVoucher_CellValueChanged(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         ServicesBll BllService = new ServicesBll();
         ServiceInfo infoService = new ServiceInfo();
         decimal decRate = 0;
         if (e.RowIndex != -1 && e.ColumnIndex != -1)
         {
             SerialNo();
             if (e.ColumnIndex == dgvServiceVoucher.Columns["dgvcmbParticulars"].Index)
             {
                 if (dgvServiceVoucher.Rows[e.RowIndex].Cells["dgvcmbParticulars"].Value != null && dgvServiceVoucher.Rows[e.RowIndex].Cells["dgvcmbParticulars"].Value.ToString() != string.Empty)
                 {
                     infoService = BllService.ServiceViewForRate(Convert.ToDecimal(dgvServiceVoucher.Rows[e.RowIndex].Cells["dgvcmbParticulars"].Value.ToString()));
                     decRate = infoService.Rate;
                     string strAmount = decRate.ToString();
                     if (strAmount != string.Empty)
                     {
                         dgvServiceVoucher.Rows[e.RowIndex].Cells["dgvtxtAmount"].Value = strAmount;
                     }
                 }
             }
             AmountCalculation();
         }
         CheckColumnMissing(e);
     }
     catch (Exception ex)
     {
         MessageBox.Show("SV 45 : " + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// Function to reset the form to make new service voucher
        /// </summary>
        public void Clear()
        {
            try
            {
                /*Automatic invoice number generation*/
                TransactionsGeneralFillBll obj = new TransactionsGeneralFillBll();
                VoucherDate();
                if (isAutomatic)    //  Checking voucher number generation is automatic or not
                {
                    ServicesBll BllService = new ServicesBll();
                    ContraVoucherDetailsBll bllContraVoucherDetails = new ContraVoucherDetailsBll();
                    if (strVoucherNo == string.Empty)
                    {
                        strVoucherNo = "0";
                    }
                    strVoucherNo = obj.VoucherNumberAutomaicGeneration(DecServicetVoucherTypeId, Convert.ToDecimal(strVoucherNo), dtpVoucherDate.Value, tableName);
                    if (Convert.ToDecimal(strVoucherNo) != (BllService.ServiceMasterGetMax(DecServicetVoucherTypeId)) + 1)
                    {
                        strVoucherNo = BllService.ServiceMasterGetMax(DecServicetVoucherTypeId).ToString();
                        strVoucherNo = obj.VoucherNumberAutomaicGeneration(DecServicetVoucherTypeId, Convert.ToDecimal(strVoucherNo), dtpVoucherDate.Value, tableName);
                        if (BllService.ServiceMasterGetMax(DecServicetVoucherTypeId) == 0)
                        {
                            strVoucherNo = "0";
                            strVoucherNo = obj.VoucherNumberAutomaicGeneration(DecServicetVoucherTypeId, Convert.ToDecimal(strVoucherNo), dtpVoucherDate.Value, tableName);
                        }
                    }
                    SuffixPrefixSettingsBll BllSuffixPrefixSettings = new SuffixPrefixSettingsBll();

                    SuffixPrefixInfo infoSuffixPrefix = new SuffixPrefixInfo();
                    infoSuffixPrefix = BllSuffixPrefixSettings.GetSuffixPrefixDetails(DecServicetVoucherTypeId, dtpVoucherDate.Value);   //  Getting suffix-prefix settings
                    strPrefix = infoSuffixPrefix.Prefix;
                    strSuffix = infoSuffixPrefix.Suffix;
                    decServiceSuffixPrefixId = infoSuffixPrefix.SuffixprefixId;
                    strInvoiceNo = strPrefix + strVoucherNo + strSuffix;    // Generating invoice number with suffix and prefix
                    txtInvoiceNumber.Text = strInvoiceNo;
                    txtInvoiceNumber.ReadOnly = true;
                    txtVoucherDate.Select();
                }
                else
                {
                    txtInvoiceNumber.Text = string.Empty;
                    txtInvoiceNumber.ReadOnly = false;
                }
                ServiceAcoountComboFill();
                GridParticularComboFill();
                SalesmanComboFill();
                CashOrPartyComboFill();
                isEditMode = false;
                txtDiscount.Text = "0";
                txtTotalAmount.Text = "0";
                txtGrandTotal.Text = "0";
                txtCreditPeriod.Text = "0";
                txtCustomer.Text = string.Empty;
                txtNarration.Text = string.Empty;
                PrintCheck();
                int inCount = dgvServiceVoucher.RowCount;
                for (int i = 0; i < inCount; i++)
                {
                    dgvServiceVoucher.Rows[i].Cells["dgvcmbParticulars"].Value = null;
                    dgvServiceVoucher.Rows[i].Cells["dgvtxtMeasure"].Value = null;
                    dgvServiceVoucher.Rows[i].Cells["dgvtxtAmount"].Value = null;
                }
                dgvServiceVoucher.ClearSelection();
                btnDelete.Enabled = false;
                btnSave.Text = "Save";
                dgvServiceVoucher.Rows.Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show("SV 04 : " + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// Function to save the service voucher
 /// </summary>
 public void SaveFunction()
 {
     try
     {
         ServiceMasterInfo infoServiceMaster = new ServiceMasterInfo();
         ServiceDetailsInfo infoServiceDetails = new ServiceDetailsInfo();
         ServicesBll BllService = new ServicesBll();
         LedgerPostingBll BllLedgerPosting = new LedgerPostingBll();
         LedgerPostingInfo infoLedgerPosting = new LedgerPostingInfo();
         ExchangeRateBll BllExchangeRate = new ExchangeRateBll();
         int inRowCount = dgvServiceVoucher.RowCount;
         int inValue = 0;
         for (int ini = 0; ini < inRowCount - 1; ini++)
         {
             if (dgvServiceVoucher.Rows[ini].Cells["dgvcmbParticulars"].Value != null && dgvServiceVoucher.Rows[ini].Cells["dgvcmbParticulars"].Value.ToString() != string.Empty)
             {
                 inValue++;
             }
         }
         if (inValue > 0)
         {
             txtDiscount.Enabled = true;
             infoServiceMaster.InvoiceNo = txtInvoiceNumber.Text;
             if (isAutomatic)
             {
                 infoServiceMaster.VoucherNo = strVoucherNo;
             }
             else
             {
                 infoServiceMaster.VoucherNo = Convert.ToString(BllService.ServiceMasterGetMax(DecServicetVoucherTypeId) + 1);
             }
             infoServiceMaster.SuffixPrefixId = decServiceSuffixPrefixId;
             infoServiceMaster.Date = Convert.ToDateTime(txtVoucherDate.Text);
             infoServiceMaster.LedgerId = Convert.ToDecimal(cmbCashParty.SelectedValue.ToString());
             infoServiceMaster.TotalAmount = Convert.ToDecimal(txtTotalAmount.Text);
             infoServiceMaster.Narration = txtNarration.Text.Trim();
             infoServiceMaster.UserId = PublicVariables._decCurrentUserId;
             infoServiceMaster.CreditPeriod = Convert.ToInt32(txtCreditPeriod.Text);
             infoServiceMaster.ServiceAccount = Convert.ToDecimal(cmbServiceAC.SelectedValue.ToString());
             decimal decExchangeRateId = Convert.ToDecimal(cmbCurrency.SelectedValue.ToString());//spExchangeRate.GetExchangeRateByCurrencyId(Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()));
             infoServiceMaster.ExchangeRateId = decExchangeRateId;
             infoServiceMaster.EmployeeId = Convert.ToDecimal(cmbSalesman.SelectedValue.ToString());
             infoServiceMaster.Customer = txtCustomer.Text.Trim();
             infoServiceMaster.Discount = Convert.ToDecimal(txtDiscount.Text.Trim());
             infoServiceMaster.GrandTotal = Convert.ToDecimal(txtGrandTotal.Text);
             infoServiceMaster.VoucherTypeId = DecServicetVoucherTypeId;
             infoServiceMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
             infoServiceMaster.ExtraDate = PublicVariables._dtCurrentDate;
             infoServiceMaster.Extra1 = string.Empty;
             infoServiceMaster.Extra2 = string.Empty;
             decServiceMasterId = BllService.ServiceMasterAddReturnWithIdentity(infoServiceMaster);
             infoServiceDetails.ServiceMasterId = decServiceMasterId;
             infoServiceDetails.Extra1 = string.Empty;
             infoServiceDetails.Extra2 = string.Empty;
             infoServiceDetails.ExtraDate = PublicVariables._dtCurrentDate;
             for (int i = 0; i < inRowCount - 1; i++)
             {
                 if (dgvServiceVoucher.Rows[i].Cells["dgvcmbParticulars"].Value != null && dgvServiceVoucher.Rows[i].Cells["dgvcmbParticulars"].Value.ToString() != string.Empty)
                 {
                     infoServiceDetails.ServiceId = Convert.ToDecimal(dgvServiceVoucher.Rows[i].Cells["dgvcmbParticulars"].Value.ToString());
                 }
                 if (dgvServiceVoucher.Rows[i].Cells["dgvtxtMeasure"].Value != null && dgvServiceVoucher.Rows[i].Cells["dgvtxtMeasure"].Value.ToString() != string.Empty)
                 {
                     infoServiceDetails.Measure = dgvServiceVoucher.Rows[i].Cells["dgvtxtMeasure"].Value.ToString();
                 }
                 if (dgvServiceVoucher.Rows[i].Cells["dgvtxtAmount"].Value != null && dgvServiceVoucher.Rows[i].Cells["dgvtxtAmount"].Value.ToString() != string.Empty)
                 {
                     infoServiceDetails.Amount = Convert.ToDecimal(dgvServiceVoucher.Rows[i].Cells["dgvtxtAmount"].Value.ToString());
                     decAmount += Convert.ToDecimal(dgvServiceVoucher.Rows[i].Cells["dgvtxtAmount"].Value);
                 }
                 decServiceDetailsId = BllService.ServiceDetailsAddReturnWithIdentity(infoServiceDetails);
             }
             decSelectedCurrencyRate = BllExchangeRate.GetExchangeRateByExchangeRateId(infoServiceMaster.ExchangeRateId);
             decConvertRate = decAmount * decSelectedCurrencyRate;
             decCredit = 0;
             decDebit = decConvertRate;
             decLedgerId = Convert.ToDecimal(cmbCashParty.SelectedValue.ToString());
             LedgerPosting(decLedgerId, decCredit, decDebit, decServiceDetailsId, infoServiceMaster.VoucherNo);
             AccountLedgerBll bllAccountLedger = new AccountLedgerBll();
             decimal decI = Convert.ToDecimal(bllAccountLedger.AccountGroupIdCheck(cmbCashParty.Text));
             if (decI > 0)
             {
                 PartyBalanceInfo infoPartyBalance = new PartyBalanceInfo();
                 PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
                 infoPartyBalance.Date = Convert.ToDateTime(txtVoucherDate.Text);
                 infoPartyBalance.LedgerId = Convert.ToDecimal(cmbCashParty.SelectedValue.ToString());
                 infoPartyBalance.VoucherTypeId = DecServicetVoucherTypeId;
                 infoPartyBalance.VoucherNo = strVoucherNo;
                 infoPartyBalance.AgainstVoucherTypeId = 0;
                 infoPartyBalance.AgainstVoucherNo = "0";
                 infoPartyBalance.InvoiceNo = strInvoiceNo;
                 infoPartyBalance.AgainstInvoiceNo = "0";
                 infoPartyBalance.ReferenceType = "New";
                 infoPartyBalance.Debit = decAmount;
                 infoPartyBalance.Credit = 0;
                 infoPartyBalance.CreditPeriod = Convert.ToInt32(txtCreditPeriod.Text);
                 infoPartyBalance.ExchangeRateId = decExchangeRateId;
                 infoPartyBalance.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                 infoPartyBalance.Extra1 = string.Empty;
                 infoPartyBalance.Extra2 = string.Empty;
                 BllPartyBalance.PartyBalanceAdd(infoPartyBalance);
             }
             Messages.SavedMessage();
             if (cbxPrintAfterSave.Checked)
             {
                 if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                 {
                     PrintForDotMatrix(decServiceMasterId);
                 }
                 else
                 {
                     Print(decServiceMasterId, infoServiceMaster.ExchangeRateId);
                 }
             }
             Clear();
         }
         else
         {
             Messages.InformationMessage("Can't save Service Voucher without atleast one ledger with complete details");
             dgvServiceVoucher.ClearSelection();
             dgvServiceVoucher.CurrentCell = dgvServiceVoucher.Rows[0].Cells["dgvcmbParticulars"];
             dgvServiceVoucher.Rows[0].Cells["dgvcmbParticulars"].Selected = true;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("SV 19 : " + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to call save or edit function  
 /// </summary>
 public void SaveOrEditFuction()
 {
     try
     {
         ServicesBll BllService = new ServicesBll();
         if (txtDiscount.Text.Trim() == string.Empty)
         {
             txtDiscount.Text = "0";
         }
         if (txtInvoiceNumber.Text == string.Empty)
         {
             Messages.InformationMessage("Enter invoice number");
             txtInvoiceNumber.Focus();
         }
         else if (cmbCashParty.SelectedIndex == -1)
         {
             Messages.InformationMessage("Select cash or party's account");
             cmbCashParty.Focus();
         }
         else if (cmbServiceAC.SelectedIndex == -1)
         {
             Messages.InformationMessage("Select service");
             cmbServiceAC.Focus();
         }
         else if (cmbSalesman.SelectedIndex == -1)
         {
             Messages.InformationMessage("Select salesman");
             cmbSalesman.Focus();
         }
         else if (cmbCurrency.SelectedIndex == -1)
         {
             Messages.InformationMessage("Select currency");
             cmbCurrency.Focus();
         }
         else if (Convert.ToDecimal(txtDiscount.Text.Trim()) > Convert.ToDecimal(txtTotalAmount.Text.Trim()))
         {
             Messages.InformationMessage("Discount is greater than total amount");
             txtDiscount.Focus();
         }
         else
         {
             if (RemoveIncompleteRowsFromGrid())
             {
                 if (dtpVoucherDate.Value.ToString() != string.Empty)
                 {
                     if (!isEditMode)
                     {
                         if (PublicVariables.isMessageAdd)
                         {
                             if (Messages.SaveMessage())
                             {
                                 if (!isAutomatic)
                                 {
                                     strInvoiceNo = txtInvoiceNumber.Text;
                                     if (!BllService.ServiceVoucherCheckExistence(strInvoiceNo, DecServicetVoucherTypeId, 0))
                                     {
                                         SaveFunction();
                                     }
                                     else
                                     {
                                         Messages.InformationMessage("Invoice number already exist");
                                     }
                                 }
                                 else
                                 {
                                     SaveFunction();
                                 }
                             }
                         }
                         else
                         {
                             if (!isAutomatic)
                             {
                                 if (!BllService.ServiceVoucherCheckExistence(strVoucherNo, DecServicetVoucherTypeId, 0))
                                 {
                                     SaveFunction();
                                 }
                                 else
                                 {
                                     Messages.InformationMessage("Invoice number already exist");
                                 }
                             }
                             else
                             {
                                 SaveFunction();
                             }
                         }
                     }
                     else if (isEditMode)
                     {
                         if (PublicVariables.isMessageEdit)
                         {
                             if (Messages.UpdateMessage())
                             {
                                 if (!isAutomatic)
                                 {
                                     if (!BllService.ServiceVoucherCheckExistence(strVoucherNo, DecServicetVoucherTypeId, decServiceMasterId))
                                     {
                                         EditFunction(decServiceMasterId);
                                     }
                                     else
                                     {
                                         Messages.InformationMessage("Invoice number already exist");
                                     }
                                 }
                                 else
                                 {
                                     EditFunction(decServiceMasterId);
                                 }
                             }
                         }
                         else
                         {
                             if (!isAutomatic)
                             {
                                 if (!BllService.ServiceVoucherCheckExistence(strVoucherNo, DecServicetVoucherTypeId, decServiceMasterId))
                                 {
                                     EditFunction(decServiceMasterId);
                                 }
                                 else
                                 {
                                     Messages.InformationMessage("Invoice number already exist");
                                 }
                             }
                             else
                             {
                                 EditFunction(decServiceMasterId);
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("SV 20 : " + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Delete function and reference exists checking
 /// </summary>
 public void DeleteFunction()
 {
     try
     {
         ServicesBll BllService = new ServicesBll();
         if (BllService.ServiceDeleteReferenceCheck(decServiceId) == -1)
         {
             Messages.ReferenceExistsMessage();
         }
         else
         {
             Clear();
             btnSave.Text = "Save";
             Messages.DeletedMessage();
             GridFill();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Ser8:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 public void Print(decimal decServiceMasterId, decimal decExchangeRateId)
 {
     try
     {
         ServicesBll BllService = new ServicesBll();
         DataSet dsServiceVoucher = BllService.ServiceVoucherPrinting(decServiceMasterId, 1, decExchangeRateId);
         frmReport frmReport = new frmReport();
         frmReport.MdiParent = formMDI.MDIObj;
         frmReport.ServiceVoucherPrinting(dsServiceVoucher);
     }
     catch (Exception ex)
     {
         MessageBox.Show("SV 25 : " + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to fill Datagridview
 /// </summary>
 public void GridFill()
 {
     try
     {
         ServicesBll BllService = new ServicesBll();
         List<DataTable> listObj = new List<DataTable>();
         listObj = BllService.ServiceReportSearch(Convert.ToDateTime(dtpFromDate.Value.ToString()), Convert.ToDateTime(dtpToDate.Value.ToString()), cmbVoucherType.Text.Trim(), cmbCashOrParty.Text.ToString(), cmbSalesman.Text.ToString());
         dgvServiceReport.DataSource = listObj[0];
     }
     catch (Exception ex)
     {
         MessageBox.Show("SVRT 9 : " + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to fill the fields for edit or delete
 /// </summary>
 public void FillFunction()
 {
     try
     {
         ServicesBll BllService = new ServicesBll();
         //ServiceMasterSP spServiceMaster = new ServiceMasterSP();
         ServiceMasterInfo infoServiceMaster = new ServiceMasterInfo();
         LedgerPostingBll BllLedgerPosting = new LedgerPostingBll();
         VoucherTypeBll BllVoucherType = new VoucherTypeBll();
         VoucherTypeInfo infoVoucherType = new VoucherTypeInfo();
         PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
         PartyBalanceInfo infoPartyBalance = new PartyBalanceInfo();
         decServiceMasterId = decMasterId;
         infoServiceMaster = BllService.ServiceMasterView(decServiceMasterId);
         infoVoucherType = BllVoucherType.VoucherTypeView(infoServiceMaster.VoucherTypeId);
         this.Text = infoVoucherType.VoucherTypeName;
         isAutomatic = BllVoucherType.CheckMethodOfVoucherNumbering(infoServiceMaster.VoucherTypeId);
         txtInvoiceNumber.ReadOnly = true;
         strVoucherNo = infoServiceMaster.VoucherNo.ToString();
         txtInvoiceNumber.Text = infoServiceMaster.InvoiceNo;
         txtCreditPeriod.Text = infoServiceMaster.CreditPeriod.ToString();
         strInvoiceNo = infoServiceMaster.InvoiceNo.ToString();
         decServiceSuffixPrefixId = Convert.ToDecimal(infoServiceMaster.SuffixPrefixId.ToString());
         DecServicetVoucherTypeId = Convert.ToDecimal(infoServiceMaster.VoucherTypeId.ToString());
         int inDecimalPlace = PublicVariables._inNoOfDecimalPlaces;
         txtVoucherDate.Text = infoServiceMaster.Date.ToString("dd-MMM-yyyy");
         dtpVoucherDate.Value = Convert.ToDateTime(infoServiceMaster.Date);
         cmbCashParty.SelectedValue = infoServiceMaster.LedgerId;
         cmbServiceAC.SelectedValue = infoServiceMaster.ServiceAccount;
         cmbSalesman.SelectedValue = infoServiceMaster.EmployeeId;
         txtCustomer.Text = infoServiceMaster.Customer;
         txtNarration.Text = infoServiceMaster.Narration;
         List<DataTable> listObjServiceDetails = new List<DataTable>();
         listObjServiceDetails = BllService.ServiceDetailsViewWithMasterId(decServiceMasterId);
         for (int i = 0; i < listObjServiceDetails[0].Rows.Count; i++)
         {
             dgvServiceVoucher.Rows.Add();
             dgvServiceVoucher.Rows[i].Cells["dgvtxtDetailsId"].Value = Convert.ToDecimal(listObjServiceDetails[0].Rows[i]["serviceDetailsId"].ToString());
             dgvServiceVoucher.Rows[i].Cells["dgvtxtServiceMasterId"].Value = Convert.ToDecimal(listObjServiceDetails[0].Rows[i]["serviceMasterId"].ToString());
             dgvServiceVoucher.Rows[i].Cells["dgvcmbParticulars"].Value = Convert.ToDecimal(listObjServiceDetails[0].Rows[i]["serviceId"].ToString());
             dgvServiceVoucher.Rows[i].Cells["dgvtxtMeasure"].Value = listObjServiceDetails[0].Rows[i]["measure"].ToString();
             dgvServiceVoucher.Rows[i].Cells["dgvtxtAmount"].Value = listObjServiceDetails[0].Rows[i]["amount"].ToString();
             decimal decDetailsId1 = Convert.ToDecimal(listObjServiceDetails[0].Rows[i]["serviceDetailsId"].ToString());
             decimal decLedgerPostingId = BllLedgerPosting.LedgerPostingIdFromDetailsId(decDetailsId1, strVoucherNo, DecServicetVoucherTypeId);
             dgvServiceVoucher.Rows[i].Cells["dgvtxtLedgerPostingId"].Value = decLedgerPostingId.ToString();
         }
         cmbCurrency.SelectedValue = infoServiceMaster.ExchangeRateId;
         txtTotalAmount.Text = infoServiceMaster.TotalAmount.ToString();
         txtDiscount.Text = infoServiceMaster.Discount.ToString();
         txtGrandTotal.Text = infoServiceMaster.GrandTotal.ToString();
         infoPartyBalance = BllPartyBalance.PartyBalanceViewByVoucherNoAndVoucherTypeId(DecServicetVoucherTypeId, strVoucherNo, infoServiceMaster.Date);
         decPartyBalanceId = infoPartyBalance.PartyBalanceId;
     }
     catch (Exception ex)
     {
         MessageBox.Show("SV 32 : " + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Service Search function
 /// </summary>
 /// <param name="strBrandName"></param>
 /// <param name="strCategoryname"></param>
 public void ServiceSearch(string strBrandName, string strCategoryname)
 {
     try
     {
         ServicesBll BllService = new ServicesBll();
         ServiceInfo infoService = new ServiceInfo();
         List<DataTable> listObjService = new List<DataTable>();
         listObjService = BllService.ServiceSearch(strBrandName, strCategoryname);
         dgvService.DataSource = listObjService[0];
     }
     catch (Exception ex)
     {
         MessageBox.Show("Ser9:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Fill controls for Update or delete
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void dgvService_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         if (e.RowIndex != -1)
         {
             ServicesBll BllService = new ServicesBll();
             ServiceInfo infoService = new ServiceInfo();
             decServiceId = Convert.ToDecimal(dgvService.Rows[e.RowIndex].Cells["dgvtxtServiceId"].Value.ToString());
             infoService = BllService.ServiceView(decServiceId);
             txtServiceName.Text = infoService.ServiceName;
             cmbCategory.SelectedValue = infoService.ServiceCategoryId.ToString();
             txtRate.Text = infoService.Rate.ToString();
             txtNarration.Text = infoService.Narration;
             txtServiceNameSearch.Text = string.Empty;
             cmbCategorySearch.SelectedIndex = 0;
             btnSave.Text = "Update";
             btnDelete.Enabled = true;
             strServiceName = infoService.ServiceName;
             txtServiceName.Focus();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Ser17:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Save Function
 /// </summary>
 public void SaveFunction()
 {
     try
     {
         ServicesBll BllService = new ServicesBll();
         ServiceInfo infoService = new ServiceInfo();
         infoService.ServiceName = txtServiceName.Text.Trim();
         infoService.ServiceCategoryId = Convert.ToDecimal(cmbCategory.SelectedValue.ToString());
         infoService.Rate = Convert.ToDecimal(txtRate.Text.ToString());
         infoService.Narration = txtNarration.Text.Trim();
         infoService.ExtraDate = PublicVariables._dtCurrentDate;
         infoService.Extra1 = string.Empty;
         infoService.Extra2 = string.Empty;
         if (BllService.ServiceCheckExistence(txtServiceName.Text.Trim(), 0) == false)
         {
             decIdForOtherForms = BllService.ServiceAddWithReturnIdentity(infoService);
             Messages.SavedMessage();
             Clear();
             GridFill();
         }
         else
         {
             Messages.InformationMessage("Service name already exist");
             txtServiceName.Focus();
         }
         if (frmServiceVoucherObj != null)
         {
             this.Close();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Ser11 : " + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Gridfill function
 /// </summary>
 public void GridFill()
 {
     try
     {
         ServicesBll BllService = new ServicesBll();
         List<DataTable> listObjService = new List<DataTable>();
         listObjService = BllService.ServiceGridFill();
         dgvService.DataSource = listObjService[0];
     }
     catch (Exception ex)
     {
         MessageBox.Show("Ser4:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Edit Function
 /// </summary>
 public void EditFunction()
 {
     try
     {
         ServicesBll BllService = new ServicesBll();
         ServiceInfo infoService = new ServiceInfo();
         infoService.ServiceId = Convert.ToDecimal(dgvService.CurrentRow.Cells["dgvtxtServiceId"].Value.ToString());
         infoService.ServiceName = txtServiceName.Text.Trim();
         infoService.ServiceCategoryId = Convert.ToDecimal(cmbCategory.SelectedValue.ToString());
         infoService.Rate = Convert.ToDecimal(txtRate.Text.ToString());
         infoService.Narration = txtNarration.Text.Trim();
         infoService.Extra1 = string.Empty;
         infoService.Extra2 = string.Empty;
         if (CheckExistenceOfServiceName() == false)
         {
             if (BllService.ServiceEdit(infoService))
             {
                 Messages.UpdatedMessage();
                 Clear();
                 txtServiceName.Focus();
             }
         }
         else
         {
             Messages.InformationMessage("Already exists");
             txtServiceName.Focus();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Ser12:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to delete service voucher
 /// </summary>
 /// <param name="decServiceMasterId"></param>
 public void DeleteFunction(decimal decServiceMasterId)
 {
     try
     {
         ServicesBll BllService = new ServicesBll();
         BllService.ServiceVoucherDelete(decPartyBalanceId, DecServicetVoucherTypeId, strVoucherNo, decServiceMasterId);
         Messages.DeletedMessage();
         this.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show("SV 23 : " + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// on "print'  button click for print
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnPrint_Click(object sender, EventArgs e)
 {
     try
     {
         if (dgvServiceReport.RowCount > 0)
         {
             DataSet dsServiceVoucherReport = new DataSet();
             //CompanySP spCompany = new CompanySP();
             CompanyCreationBll bllCompanyCreation = new CompanyCreationBll();
             frmReport reportobj = new frmReport();
             ServicesBll BllService = new ServicesBll();
             List<DataTable> listObjCompany = bllCompanyCreation.CompanyViewDataTable(1);
             List<DataTable> listServiceVoucherReport = BllService.ServiceReport(Convert.ToDateTime(dtpFromDate.Value.ToString()), Convert.ToDateTime(dtpToDate.Value.ToString()), cmbVoucherType.Text, cmbCashOrParty.Text, cmbSalesman.Text);
             dsServiceVoucherReport.Tables.Add(listObjCompany[0]);
             dsServiceVoucherReport.Tables.Add(listServiceVoucherReport[0]);
             reportobj.MdiParent = formMDI.MDIObj;
             reportobj.ServiceVoucherReport(dsServiceVoucherReport);
         }
         else
         {
             Messages.InformationMessage("No data found");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("SVRT 15 : " + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to edit the service voucher
 /// </summary>
 /// <param name="decServiceMasterId"></param>
 public void EditFunction(decimal decServiceMasterId)
 {
     try
     {
         ServiceMasterInfo infoServiceMaster = new ServiceMasterInfo();
         ServiceDetailsInfo infoServiceDetails = new ServiceDetailsInfo();
         ServicesBll BllService = new ServicesBll();
         LedgerPostingBll BllLedgerPosting = new LedgerPostingBll();
         LedgerPostingInfo infoLedgerPosting = new LedgerPostingInfo();
         ExchangeRateBll BllExchangeRate = new ExchangeRateBll();
         int inRowCount = dgvServiceVoucher.RowCount;
         int inValue = 0;
         decimal decLedgerPostingId1 = 0;
         decimal decLedgerPostingId2 = 0;
         List<DataTable> listObjLedgerPostingId = new List<DataTable>();
         listObjLedgerPostingId = BllService.LedgerPostingIdByServiceMaasterId(decServiceMasterId);
         decLedgerPostingId1 = Convert.ToDecimal(listObjLedgerPostingId[0].Rows[0]["ledgerPostingId"].ToString());
         decLedgerPostingId2 = Convert.ToDecimal(listObjLedgerPostingId[0].Rows[1]["ledgerPostingId"].ToString());
         for (int ini = 0; ini < inRowCount - 1; ini++)
         {
             if (dgvServiceVoucher.Rows[ini].Cells["dgvcmbParticulars"].Value != null && dgvServiceVoucher.Rows[ini].Cells["dgvcmbParticulars"].Value.ToString() != string.Empty)
             {
                 inValue++;
             }
         }
         if (inValue > 0)
         {
             infoServiceMaster.ServiceMasterId = decServiceMasterId;
             infoServiceMaster.SuffixPrefixId = decServiceSuffixPrefixId;
             infoServiceMaster.Date = Convert.ToDateTime(txtVoucherDate.Text);
             infoServiceMaster.LedgerId = Convert.ToDecimal(cmbCashParty.SelectedValue.ToString());
             infoServiceMaster.TotalAmount = Convert.ToDecimal(txtTotalAmount.Text);
             infoServiceMaster.Narration = txtNarration.Text.Trim();
             infoServiceMaster.UserId = PublicVariables._decCurrentUserId;
             infoServiceMaster.CreditPeriod = Convert.ToInt32(txtCreditPeriod.Text);
             infoServiceMaster.ServiceAccount = Convert.ToDecimal(cmbServiceAC.SelectedValue.ToString());
             decimal decExchangeRateId = Convert.ToDecimal(cmbCurrency.SelectedValue.ToString());//spExchangeRate.GetExchangeRateByCurrencyId(Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()));
             infoServiceMaster.ExchangeRateId = decExchangeRateId;
             infoServiceMaster.EmployeeId = Convert.ToDecimal(cmbSalesman.SelectedValue.ToString());
             infoServiceMaster.Customer = txtCustomer.Text.Trim();
             infoServiceMaster.Discount = Convert.ToDecimal(txtDiscount.Text);
             infoServiceMaster.GrandTotal = Convert.ToDecimal(txtGrandTotal.Text);
             infoServiceMaster.VoucherTypeId = DecServicetVoucherTypeId;
             infoServiceMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
             infoServiceMaster.ExtraDate = PublicVariables._dtCurrentDate;
             infoServiceMaster.Extra1 = string.Empty;
             infoServiceMaster.Extra2 = string.Empty;
             //------------------deleting removed rows----------------------------------------//
             BankReconciliationBll BllBankReconciliation = new BankReconciliationBll();
             foreach (object obj in strArrOfRemove)
             {
                 string str = Convert.ToString(obj);
                 BllService.ServiceDetailsDelete(Convert.ToDecimal(str));
             }
             BllService.ServiceMasterEdit(infoServiceMaster);
             infoServiceDetails.ServiceMasterId = decServiceMasterId;
             infoServiceDetails.Extra1 = string.Empty;
             infoServiceDetails.Extra2 = string.Empty;
             infoServiceDetails.ExtraDate = PublicVariables._dtCurrentDate;
             for (int i = 0; i < inRowCount - 1; i++)
             {
                 if (dgvServiceVoucher.Rows[i].Cells["dgvcmbParticulars"].Value != null && dgvServiceVoucher.Rows[i].Cells["dgvcmbParticulars"].Value.ToString() != string.Empty)
                 {
                     infoServiceDetails.ServiceId = Convert.ToDecimal(dgvServiceVoucher.Rows[i].Cells["dgvcmbParticulars"].Value.ToString());
                 }
                 if (dgvServiceVoucher.Rows[i].Cells["dgvtxtMeasure"].Value != null && dgvServiceVoucher.Rows[i].Cells["dgvtxtMeasure"].Value.ToString() != string.Empty)
                 {
                     infoServiceDetails.Measure = dgvServiceVoucher.Rows[i].Cells["dgvtxtMeasure"].Value.ToString();
                 }
                 if (dgvServiceVoucher.Rows[i].Cells["dgvtxtAmount"].Value != null && dgvServiceVoucher.Rows[i].Cells["dgvtxtAmount"].Value.ToString() != string.Empty)
                 {
                     infoServiceDetails.Amount = Convert.ToDecimal(dgvServiceVoucher.Rows[i].Cells["dgvtxtAmount"].Value.ToString());
                     if (dgvServiceVoucher.Rows[i].Cells["dgvtxtDetailsId"].Value != null && dgvServiceVoucher.Rows[i].Cells["dgvtxtDetailsId"].Value.ToString() != string.Empty)
                     {
                         infoServiceDetails.ServiceDetailsId = Convert.ToDecimal(dgvServiceVoucher.Rows[i].Cells["dgvtxtDetailsId"].Value.ToString());
                         infoServiceDetails.ExchangeRateId = Convert.ToDecimal(cmbCurrency.SelectedValue.ToString());
                         BllService.ServiceDetailsEdit(infoServiceDetails);
                     }
                     else
                     {
                         infoServiceDetails.ExchangeRateId = Convert.ToDecimal(cmbCurrency.SelectedValue.ToString());
                         decServiceDetailsId = BllService.ServiceDetailsAddReturnWithIdentity(infoServiceDetails);
                     }
                     decSelectedCurrencyRate = BllExchangeRate.GetExchangeRateByExchangeRateId(Convert.ToDecimal(cmbCurrency.SelectedValue.ToString()));
                     decAmount = Convert.ToDecimal(dgvServiceVoucher.Rows[i].Cells["dgvtxtAmount"].Value);
                     decConvertRate += decAmount * decSelectedCurrencyRate;
                 }
             }
             decCredit = 0;
             decDebit = decConvertRate;
             decLedgerId = Convert.ToDecimal(cmbCashParty.SelectedValue.ToString());
             LedgerPostingEdit(decLedgerPostingId1, decLedgerId, decCredit, decDebit);
             decCredit = decConvertRate;
             decDebit = 0;
             decLedgerId = Convert.ToDecimal(cmbServiceAC.SelectedValue.ToString());
             LedgerPostingEdit(decLedgerPostingId2, decLedgerId, decCredit, decDebit);
             AccountLedgerBll bllAccountLedger = new AccountLedgerBll();
             decimal decI = Convert.ToDecimal(bllAccountLedger.AccountGroupIdCheck(cmbCashParty.Text));
             if (decI > 0)
             {
                 PartyBalanceInfo infoPartyBalance = new PartyBalanceInfo();
                 PartyBalanceBll BllPartyBalance = new PartyBalanceBll();
                 infoPartyBalance.PartyBalanceId = decPartyBalanceId;
                 infoPartyBalance.Date = Convert.ToDateTime(txtVoucherDate.Text);
                 infoPartyBalance.LedgerId = Convert.ToDecimal(cmbCashParty.SelectedValue.ToString());
                 infoPartyBalance.VoucherTypeId = DecServicetVoucherTypeId;
                 infoPartyBalance.VoucherNo = strVoucherNo;
                 infoPartyBalance.AgainstVoucherTypeId = 0;
                 infoPartyBalance.AgainstVoucherNo = "0";
                 infoPartyBalance.InvoiceNo = strInvoiceNo;
                 infoPartyBalance.AgainstInvoiceNo = "0";
                 infoPartyBalance.ReferenceType = "New";
                 infoPartyBalance.Debit = decAmount;
                 infoPartyBalance.Credit = 0;
                 infoPartyBalance.CreditPeriod = Convert.ToInt32(txtCreditPeriod.Text);
                 infoPartyBalance.ExchangeRateId = decExchangeRateId;
                 infoPartyBalance.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                 infoPartyBalance.Extra1 = string.Empty;
                 infoPartyBalance.Extra2 = string.Empty;
                 BllPartyBalance.PartyBalanceEdit(infoPartyBalance);
             }
             Messages.UpdatedMessage();
             if (cbxPrintAfterSave.Checked)
             {
                 if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                 {
                     PrintForDotMatrix(decServiceMasterId);
                 }
                 else
                 {
                     Print(decServiceMasterId, infoServiceMaster.ExchangeRateId);
                 }
             }
             this.Close();
             if (frmServiceVoucherRegisterObj != null)
             {
                 frmServiceVoucherRegisterObj.Show();
                 frmServiceVoucherRegisterObj.GridFill();
             }
             else if (frmServiceReportObj != null)
             {
                 frmServiceReportObj.Show();
                 frmServiceReportObj.GridFill();
             }
         }
         else
         {
             Messages.InformationMessage("Can't save Service Voucher without atleast one ledger with complete details");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("SV 24 : " + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Fills Datagridview
 /// </summary>
 public void GridFill()
 {
     try
     {
         if (cmbCashOrParty.Text.Trim() == string.Empty)
         {
             cmbCashOrParty.Text = "All";
         }
         ServicesBll BllService = new ServicesBll();
         List<DataTable> listObj = new List<DataTable>();
         listObj = BllService.ServiceVoucherRegisterSearch(Convert.ToDateTime(dtpFromDate.Value.ToString()), Convert.ToDateTime(dtpToDate.Value.ToString()), txtVoucherNo.Text.Trim(), cmbCashOrParty.Text.ToString());
         dgvServiceVoucherRegister.DataSource = listObj[0];
         if (cmbCashOrParty.Text == "All")
         {
             cmbCashOrParty.Text = string.Empty;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("SVR 2 : " + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to fill the perticular combobox in grid
 /// </summary>
 public void GridParticularComboFill()
 {
     try
     {
         List<DataTable> listObj = new List<DataTable>();
         ServicesBll BllService = new ServicesBll();
         listObj = BllService.ServiceViewAll();
         dgvcmbParticulars.DataSource = listObj[0];
         dgvcmbParticulars.DisplayMember = "serviceName";
         dgvcmbParticulars.ValueMember = "serviceId";
     }
     catch (Exception ex)
     {
         MessageBox.Show("SV 10 : " + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// ServiceName Checking Existance
        /// </summary>
        /// <returns></returns>
        public bool CheckExistenceOfServiceName()
        {
            bool isExist = false;

            try
            {
                ServicesBll BllService = new ServicesBll();
                isExist = BllService.ServiceCheckExistence(txtServiceName.Text.Trim(), 0);
                if (isExist)
                {
                    string strServiceNames = txtServiceName.Text.Trim();
                    if (strServiceNames.ToLower() == strServiceName.ToLower())
                    {
                        isExist = false;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ser10:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            return isExist;
        }