public void LoadSearchResult(string Customername)
        {
            ICreditNoteListRepository SalesRepository = new CreditNoteListRepository();

            this.ShowAllCount   = SalesRepository.GetAllSalesCredit().Count();
            this.CreditNoteList = SalesRepository.GetAllSalesCredit().Where(x => x.CustomerName == Customername).OrderBy(x => x.CustomerName).ToList();
        }
        private void RefreshData()
        {
            ICreditNoteListRepository SalesRepository = new CreditNoteListRepository();

            // this.DateFormat = SalesRepository.GetDateFormat();
            this.ShowAllCount = SalesRepository.GetAllSalesCredit().Count();
            GetOptionsandTaxValues();
            this.JsonData                = SalesRepository.GetLastSelectionData(Convert.ToInt32(ScreenId.CreditNoteList));
            this.CreditNoteList          = SalesRepository.GetAllSalesCreditJson(this.JsonData, this.IncludingGSTTrue).OrderBy(x => x.CustomerName).ToList();
            this.CreditNoteListcmb       = SalesRepository.GetAllSalesCredit().OrderBy(x => x.CustomerName).ToList();
            this.ShowSelectedCount       = this.CreditNoteList.Count();
            this.CreditNoteListcmbCredit = this.CreditNoteListcmb.GroupBy(x => x.CashCreditNo).Select(g => g.First()).Where(y => y.CashCreditNo != null).OrderBy(x => x.CreditCashNO).ToList();
            this.CreditNoteListcmbCus    = this.CreditNoteList.GroupBy(x => x.CustomerName).Select(y => y.First()).Distinct().OrderBy(x => x.CustomerName).ToList();
            this.CreditNoteListcmbCus    = this.CreditNoteList.GroupBy(x => x.CustomerName).Select(y => y.First()).Distinct().OrderBy(x => x.CustomerName).ToList();
            this.CreditNoteListcmbInv    = this.CreditNoteList.GroupBy(x => x.CreditNo).Select(y => y.First()).Distinct().OrderBy(x => x.SortCreditNoteNo).ToList();
            this.YearRange               = SalesRepository.GetYearRange().ToList();

            changeNumberformat(this.CreditNoteList);
            changeNumberformat(this.CreditNoteListcmb);
            DefaultList = this.CreditNoteList;
            FullPQList  = this.CreditNoteListcmb;
            //this.ShowAllCount = this.CreditNoteListcmb.Count();
            SetDefaultSearchSelection(this.JsonData);
            var    Updateddate = this.CreditNoteListcmb.Max(x => x.CreatedDate);
            string date        = this.DateFormat as string;

            this.LastUpdateDate = Convert.ToDateTime(Updateddate).ToString(date);

            this.CreditAmount = Convert.ToString(CreditNoteList.Sum(e => e.CreditAmountValue));
            //this.GetData(this.SelectedSearchCustomer);
        }
        void showexcGST(object param)
        {
            Mouse.OverrideCursor = Cursors.Wait;
            int decimalpoints = Convert.ToInt32(this.DecimalPlaces);

            ICreditNoteListRepository SalesRepository = new CreditNoteListRepository();

            this.CreditNoteList = SalesRepository.GetAllSalesCreditJson(this.JsonData, this.IncludingGSTTrue).OrderBy(x => x.CustomerName).ToList();
            if (this.ShowAllTrue == false)
            {
                this.ShowSelectedCount = this.CreditNoteList.Count();
            }
            else
            {
                this.ShowSelectedCount = 0;
            }
            this.CreditNoteListcmb       = this.CreditNoteList.OrderBy(x => x.CustomerName).OrderBy(x => x.CustomerName).ToList();
            this.CreditNoteListcmbCredit = this.CreditNoteListcmb.GroupBy(x => x.CashCreditNo).Select(g => g.First()).Where(y => y.CashCreditNo != null).OrderBy(x => x.CreditCashNO).OrderBy(x => x.CustomerName).ToList();
            this.CreditNoteListcmbCus    = this.CreditNoteList.GroupBy(x => x.CustomerName).Select(y => y.First()).Distinct().OrderBy(x => x.CustomerName).OrderBy(x => x.CustomerName).ToList();
            this.CreditNoteListcmbInv    = this.CreditNoteList.GroupBy(x => x.CreditNo).Select(y => y.First()).Distinct().OrderBy(x => x.SortCreditNoteNo).OrderBy(x => x.CustomerName).ToList();
            DefaultList = this.CreditNoteListcmb;

            changeNumberformat(this.CreditNoteList);
            Mouse.OverrideCursor = null;
        }
        }//end

        void showincGST(object param)
        {
            Mouse.OverrideCursor = Cursors.Wait;
            int decimalpoints = Convert.ToInt32(this.DecimalPlaces);
            //foreach (var item in this.CreditNoteList)
            //{
            //    //item.CreditAmount = item.CreditAmountIncGST;
            //    item.CreditAmount = Math.Round(Convert.ToDouble(item.CreditAmountIncGST), decimalpoints).ToString();
            //}
            //if (this.ShowAllTrue == false)
            //    this.CreditNoteList = DefaultList.Where(x => x.ExcIncGST == true).ToList();
            //else
            //    this.CreditNoteList = FullPQList.Where(x => x.ExcIncGST == true).ToList();
            ICreditNoteListRepository SalesRepository = new CreditNoteListRepository();

            this.CreditNoteList = SalesRepository.GetAllSalesCreditJson(this.JsonData, this.IncludingGSTTrue).OrderBy(x => x.CustomerName).ToList();
            if (this.ShowAllTrue == false)
            {
                this.ShowSelectedCount = this.CreditNoteList.Count();
            }
            else
            {
                this.ShowSelectedCount = 0;
            }
            this.CreditNoteListcmb       = this.CreditNoteList.OrderBy(x => x.CustomerName).ToList();
            this.CreditNoteListcmbCredit = this.CreditNoteListcmb.GroupBy(x => x.CashCreditNo).Select(g => g.First()).Where(y => y.CashCreditNo != null).OrderBy(x => x.CustomerName).ToList();
            this.CreditNoteListcmbCus    = this.CreditNoteList.GroupBy(x => x.CustomerName).Select(y => y.First()).Distinct().OrderBy(x => x.CustomerName).ToList();
            this.CreditNoteListcmbInv    = this.CreditNoteList.GroupBy(x => x.CreditNo).Select(y => y.First()).Distinct().OrderBy(x => x.SortCreditNoteNo).ToList();
            DefaultList = this.CreditNoteListcmb;
            //changedateformat(this.CreditNoteList);
            changeNumberformat(this.CreditNoteList);
            Mouse.OverrideCursor = null;
        }
        void GetOptionsandTaxValues()
        {
            OptionsEntity             oData           = new OptionsEntity();
            ICreditNoteListRepository SalesRepository = new CreditNoteListRepository();

            oData = SalesRepository.GetOptionSettings();
            if (oData != null)
            {
                this.CurrencyName   = oData.CurrencyCode;   //there is no currency name field in database
                this.CurrencyCode   = oData.CurrencyCode;
                this.CurrencyFormat = oData.NumberFormat;
                this.DateFormat     = oData.DateFormat;
                this.DecimalPlaces  = oData.DecimalPlaces;
                if (oData.ShowAmountIncGST == true)
                {
                    this.IncludingGSTTrue  = true;
                    this.IncludingGSTFalse = false;
                }
                else
                {
                    this.IncludingGSTTrue  = false;
                    this.IncludingGSTFalse = true;
                    int decimalpoints = Convert.ToInt32(DecimalPlaces);

                    if (this.CreditNoteList != null)
                    {
                        this.CreditNoteList = this.CreditNoteList.OrderBy(x => x.CustomerName).ToList();
                    }
                }
            }
            else
            {
                this.CurrencyName   = "USD";
                this.CurrencyCode   = "USD";
                this.CurrencyFormat = "en-US";
                this.DateFormat     = "dd/MM/yyyy";
            }

            TaxModel objDefaultTax = new TaxModel();

            objDefaultTax = SalesRepository.GetDefaultTaxes();
            if (objDefaultTax != null)
            {
                this.TaxName = objDefaultTax.TaxName;
                //this.TaxName = objDefaultTax.TaxRate;
            }
            else
            {
                this.TaxName = "GST Free";
                //this.TaxRate = 0;
            }
        }
        void showexcGST(object param)
        {
            Mouse.OverrideCursor = Cursors.Wait;
            int decimalpoints = Convert.ToInt32(this.DecimalPlaces);

            ICreditNoteListRepository SalesRepository = new CreditNoteListRepository();

            this.CreditNoteList = SalesRepository.GetAllSalesCreditJson(this.JsonData, this.IncludingGSTTrue).OrderBy(x => x.CustomerName).ToList();
            //if (this.ShowAllTrue == false)
            //    this.ShowSelectedCount = this.CreditNoteList.Count();
            //else
            //    this.ShowSelectedCount = 0;
            this.CreditNoteListcmb       = this.CreditNoteList.OrderBy(x => x.CustomerName).OrderBy(x => x.CustomerName).ToList();
            this.CreditNoteListcmbCredit = this.CreditNoteList.GroupBy(x => x.InvoiceNoCashChequeNo).Select(g => g.First()).Where(y => !string.IsNullOrEmpty(y.InvoiceNoCashChequeNo) || !string.IsNullOrWhiteSpace(y.InvoiceNoCashChequeNo)).OrderBy(x => x.InvoiceNoCashChequeNo).ToList();
            this.CreditNoteListcmbCus    = this.CreditNoteList.GroupBy(x => x.CustomerName).Select(y => y.First()).Distinct().OrderBy(x => x.CustomerName).OrderBy(x => x.CustomerName).ToList();
            this.CreditNoteListcmbInv    = this.CreditNoteList.GroupBy(x => x.CreditNo).Select(y => y.First()).Distinct().OrderBy(x => x.SortCreditNoteNo).OrderBy(x => x.CustomerName).ToList();
            DefaultList = this.CreditNoteList;

            // changeNumberformat(this.CreditNoteList);
            Mouse.OverrideCursor = null;
        }
        void Search(object param)
        {
            if (Count != 0)
            {
                SearchValues = new List <SearchEntity>();
                //this.ShowSelectedTrue = true;
                //this.ShowAllTrue = false;
                if (this.SelectedSearchYear != null || this.SelectedSearchYear == string.Empty)
                {
                    SearchEntity value = new SearchEntity();
                    value.FieldName  = "Year";
                    value.FieldValue = this.SelectedSearchYear;
                    SearchValues.Add(value);
                    var year = Convert.ToInt32(this.SelectedSearchYear);
                    //DefaultList = FullPQList.Where(x => x.CreatedDate.Value.Year == year).ToList();
                    //if (this.IncludingGSTTrue == true)
                    //    this.CreditNoteListInternal = DefaultList.Where(x => x.ExcIncGST == true).ToList();
                    //else
                    //    this.CreditNoteListInternal = DefaultList.Where(x => x.ExcIncGST == false).ToList();
                    //this.CreditNoteListcmb = DefaultList;
                }
                if (this.SelectedSearchQuarter != null || this.SelectedSearchQuarter == string.Empty)
                {
                    SearchEntity value = new SearchEntity();
                    value.FieldName  = "Quarter";
                    value.FieldValue = this.SelectedSearchQuarter;
                    int month1;
                    int month2;
                    int month3;
                    if (Convert.ToInt32(this.SelectedSearchQuarter) == 1)
                    {
                        month1 = 1;
                        month2 = 2;
                        month3 = 3;
                    }
                    else if (Convert.ToInt32(this.SelectedSearchQuarter) == 2)
                    {
                        month1 = 4;
                        month2 = 5;
                        month3 = 6;
                    }
                    else if (Convert.ToInt32(this.SelectedSearchQuarter) == 3)
                    {
                        month1 = 7;
                        month2 = 8;
                        month3 = 9;
                    }
                    else
                    {
                        month1 = 10;
                        month2 = 11;
                        month3 = 12;
                    }
                    //DefaultList = FullPQList.Where(x => x.CreatedDate.Value.Month == month1 || x.CreatedDate.Value.Month == month2 || x.CreatedDate.Value.Month == month3).ToList();
                    //if (this.IncludingGSTTrue == true)
                    //    this.CreditNoteListInternal = DefaultList.Where(x => x.ExcIncGST == true).ToList();
                    //else
                    //    this.CreditNoteListInternal = DefaultList.Where(x => x.ExcIncGST == false).ToList();
                    //this.CreditNoteListcmb = DefaultList;
                    SearchValues.Add(value);
                }
                if (this.SelectedSearchMonth != null || this.SelectedSearchMonth == string.Empty)
                {
                    SearchEntity value = new SearchEntity();
                    value.FieldName  = "Month";
                    value.FieldValue = this.SelectedSearchMonth;
                    SearchValues.Add(value);
                    var month = Convert.ToInt32(this.SelectedSearchMonth);
                    //DefaultList = FullPQList.Where(x => x.CreatedDate.Value.Month == month).ToList();
                    //if (this.IncludingGSTTrue == true)
                    //    this.CreditNoteListInternal = DefaultList.Where(x => x.ExcIncGST == true).ToList();
                    //else
                    //    this.CreditNoteListInternal = DefaultList.Where(x => x.ExcIncGST == false).ToList();
                    //this.CreditNoteListcmb = DefaultList;
                }
                if (this.SelectedSearchStartDate != null && this.SelectedSearchEndDate != null)
                {
                    SearchEntity value = new SearchEntity();
                    value.FieldName = "StartDate";
                    //value.FieldValue = this.SelectedSearchStartDate.ToString();
                    value.FieldValue = string.Format("{0:MMM/dd/yyyy}", this.SelectedSearchStartDate);
                    SearchValues.Add(value);
                    //string[] value = new string[2];
                    SearchEntity value1 = new SearchEntity();
                    value1.FieldName = "EndDate";
                    //value1.FieldValue = this.SelectedSearchEndDate.ToString();
                    value1.FieldValue = string.Format("{0:MMM/dd/yyyy}", this.SelectedSearchEndDate);

                    SearchValues.Add(value);
                    SearchValues.Add(value1);
                }

                jsonSearch    = JsonConvert.SerializeObject(SearchValues);
                this.JsonData = jsonSearch;

                ICreditNoteListRepository SalesRepository = new CreditNoteListRepository();
                var results = SalesRepository.SaveSearchJson(jsonSearch, Convert.ToInt32(ScreenId.CreditNoteList), "Credit_Note_List");
                if (Count != 0)
                {
                    this.CreditNoteList = SalesRepository.GetAllSalesCreditJson(jsonSearch, this.IncludingGSTTrue).OrderBy(x => x.CustomerName).ToList();

                    changeNumberformat(this.CreditNoteList);
                }

                this.CreditNoteListcmb       = this.CreditNoteList.OrderBy(x => x.CustomerName).ToList();
                this.CreditNoteListcmbCredit = this.CreditNoteListcmb.GroupBy(x => x.CashCreditNo).Select(g => g.First()).Where(y => y.CashCreditNo != null).OrderBy(x => x.CreditCashNO).ToList();
                this.CreditNoteListcmbCus    = this.CreditNoteList.GroupBy(x => x.CustomerName).Select(y => y.First()).Distinct().OrderBy(x => x.CustomerName).ToList();
                this.CreditNoteListcmbInv    = this.CreditNoteList.GroupBy(x => x.CreditNo).Select(y => y.First()).Distinct().OrderBy(x => x.SortCreditNoteNo).ToList();
                if (this.ShowAllTrue == true)
                {
                    this.ShowSelectedCount = 0;
                }
                else
                {
                    this.ShowSelectedCount = this.CreditNoteList.Count();
                }
                DefaultList = this.CreditNoteListcmb;

                this.TotalCreditAmount = Convert.ToString(CreditNoteList.Sum(e => e.CreditAmountValue));
            }
        }
 //void ShowSelected(object param)
 //{
 //    Search(null);
 //}
 void Search(object param)
 {
     if (Count != 0)
     {
         //this.ShowAllTrue = false;
         SearchValues = new List <SearchEntity>();
         if (this.SelectedSearchYear != null || this.SelectedSearchYear == string.Empty)
         {
             SearchEntity value = new SearchEntity();
             value.FieldName  = "Year";
             value.FieldValue = this.SelectedSearchYear;
             SearchValues.Add(value);
             var year = Convert.ToInt32(this.SelectedSearchYear);
         }
         else
         {
             SearchEntity value = new SearchEntity();
             value.FieldName  = "Year";
             value.FieldValue = "0";
             SearchValues.Add(value);
             var year = Convert.ToInt32(this.SelectedSearchYear);
         }
         if (this.SelectedSearchQuarter != null || this.SelectedSearchQuarter == string.Empty)
         {
             SearchEntity value = new SearchEntity();
             value.FieldName  = "Quarter";
             value.FieldValue = this.SelectedSearchQuarter;
             int month1;
             int month2;
             int month3;
             if (Convert.ToInt32(this.SelectedSearchQuarter) == 1)
             {
                 month1 = 1;
                 month2 = 2;
                 month3 = 3;
             }
             else if (Convert.ToInt32(this.SelectedSearchQuarter) == 2)
             {
                 month1 = 4;
                 month2 = 5;
                 month3 = 6;
             }
             else if (Convert.ToInt32(this.SelectedSearchQuarter) == 3)
             {
                 month1 = 7;
                 month2 = 8;
                 month3 = 9;
             }
             else
             {
                 month1 = 10;
                 month2 = 11;
                 month3 = 12;
             }
             SearchValues.Add(value);
         }
         else
         {
             SearchEntity value = new SearchEntity();
             value.FieldName  = "Quarter";
             value.FieldValue = "0";
             SearchValues.Add(value);
         }
         if (this.SelectedSearchMonth != null || this.SelectedSearchMonth == string.Empty)
         {
             SearchEntity value = new SearchEntity();
             value.FieldName  = "Month";
             value.FieldValue = this.SelectedSearchMonth;
             SearchValues.Add(value);
             var month = Convert.ToInt32(this.SelectedSearchMonth);
         }
         else
         {
             SearchEntity value = new SearchEntity();
             value.FieldName  = "Month";
             value.FieldValue = "0";
             SearchValues.Add(value);
         }
         if (this.ShowAllTrue == true)
         {
             SearchEntity value = new SearchEntity();
             value.FieldName  = "ShowAll";
             value.FieldValue = this.ShowAllTrue.ToString();
             SearchValues.Add(value);
         }
         else
         {
             SearchEntity value = new SearchEntity();
             value.FieldName  = "ShowAll";
             value.FieldValue = "false";
             SearchValues.Add(value);
         }
         if (this.SelectedSearchStartDate != null && this.SelectedSearchEndDate != null)
         {
             SearchEntity value = new SearchEntity();
             value.FieldName  = "StartDate";
             value.FieldValue = string.Format("{0:MMM/dd/yyyy}", this.SelectedSearchStartDate);
             //SearchValues.Add(value);
             SearchEntity value1 = new SearchEntity();
             value1.FieldName  = "EndDate";
             value1.FieldValue = string.Format("{0:MMM/dd/yyyy}", this.SelectedSearchEndDate);
             SearchValues.Add(value);
             SearchValues.Add(value1);
         }
         else
         {
             SearchEntity value = new SearchEntity();
             value.FieldName  = "StartDate";
             value.FieldValue = "0";
             //SearchValues.Add(value);
             SearchEntity value1 = new SearchEntity();
             value1.FieldName  = "EndDate";
             value1.FieldValue = "0";
             SearchValues.Add(value);
             SearchValues.Add(value1);
         }
         jsonSearch    = JsonConvert.SerializeObject(SearchValues);
         this.JsonData = jsonSearch;
         ICreditNoteListRepository SalesRepository = new CreditNoteListRepository();
         var results = SalesRepository.SaveSearchJson(jsonSearch, Convert.ToInt32(ScreenId.CreditNoteList), "Credit_Note_List");
         if (Count != 0)
         {
             this.CreditNoteList = SalesRepository.GetAllSalesCreditJson(jsonSearch, this.IncludingGSTTrue).OrderBy(x => x.CustomerName).ToList();
             // changeNumberformat(this.CreditNoteList);
         }
         this.CreditNoteListcmb       = this.CreditNoteList.OrderBy(x => x.CustomerName).ToList();
         this.CreditNoteListcmbCredit = this.CreditNoteList.GroupBy(x => x.InvoiceNoCashChequeNo).Select(g => g.First()).Where(y => !string.IsNullOrEmpty(y.InvoiceNoCashChequeNo) || !string.IsNullOrWhiteSpace(y.InvoiceNoCashChequeNo)).OrderBy(x => x.InvoiceNoCashChequeNo).ToList();
         this.CreditNoteListcmbCus    = this.CreditNoteList.GroupBy(x => x.CustomerName).Select(y => y.First()).Distinct().OrderBy(x => x.CustomerName).ToList();
         this.CreditNoteListcmbInv    = this.CreditNoteList.GroupBy(x => x.CreditNo).Select(y => y.First()).Distinct().OrderBy(x => x.SortCreditNoteNo).ToList();
         if (this.ShowAllTrue == true)
         {
             this.ShowSelectedCount = this.CreditNoteList.Count();
         }
         else
         {
             this.ShowSelectedCount = this.CreditNoteList.Count();
         }
         DefaultList                       = this.CreditNoteList;
         this.TotalCreditAmount            = Convert.ToString(CreditNoteList.Sum(e => e.CreditNoteAmount));
         this.TotalInvoiceCashChequeAmount = Convert.ToString(CreditNoteListcmbCredit.Sum(e => e.InvoiceCashChequeAmount));
     }
 }