/// <summary> /// Add By Nishant Sheth /// #2496 : Set the cache of currency exchange rate for users's preferd currency /// </summary> /// <param name="clientId"></param> /// <param name="userId"></param> public void SetUserCurrencyCache(int clientId, int userId) { try { BDSService.BDSServiceClient objBDSServiceClient = new BDSService.BDSServiceClient(); BDSService.Currency objUserCurrency = new BDSService.Currency(); DateTime now = DateTime.Now; DateTime CurrentMonthStartDate = GetFirstDayOfMonth(now.Month, now.Year); DateTime CurrentMonthEndDate = GetLastDayOfMonth(now.Month, now.Year); objUserCurrency = objBDSServiceClient.GetCurrencyExchangeRateEx(clientId, userId); // Call the BDS Sevice for get exchange rate if (objUserCurrency.UserCurrency != null) { var Currency = objUserCurrency.UserCurrency; // Get Planning Exchange rate // With Current Start Date and end date RevenuePlanner.Models.CurrencyModel.PlanCurrency UserPlanCurrency = Currency.CurrencyExchangeRate .Where(curr => curr.CurrencyCode == Currency.UserPreferredCurrencyCode && curr.Component == Enums.CurrencyComponent.Plan.ToString().ToLower() && (curr.StartDate >= CurrentMonthStartDate && curr.EndDate <= CurrentMonthEndDate)) .Select(curr => new RevenuePlanner.Models.CurrencyModel.PlanCurrency { CurrencyCode = curr.CurrencyCode, CurrencySymbol = curr.CurrencySymbol, ExchangeRate = curr.ExchangeRate }).FirstOrDefault(); if (UserPlanCurrency != null) { objCache.AddCache(Convert.ToString(Enums.CacheObject.UserPlanCurrency), UserPlanCurrency); Sessions.PlanExchangeRate = UserPlanCurrency.ExchangeRate; } else { Sessions.PlanExchangeRate = 1; } // Get Reporting Exchange rate List <RevenuePlanner.Models.CurrencyModel.ClientCurrency> UserReportCurrency = Currency.CurrencyExchangeRate .Where(curr => curr.CurrencyCode == Currency.UserPreferredCurrencyCode && curr.Component == Enums.CurrencyComponent.Report.ToString().ToLower()) .Select(curr => new RevenuePlanner.Models.CurrencyModel.ClientCurrency { ClientId = curr.CID, Component = curr.Component, CurrencyCode = curr.CurrencyCode, CurrencySymbol = curr.CurrencySymbol, EndDate = curr.EndDate, ExchangeRate = curr.ExchangeRate, StartDate = curr.StartDate }).ToList(); if (UserReportCurrency != null) { objCache.AddCache(Enums.CacheObject.ListUserReportCurrency.ToString(), UserReportCurrency); } Sessions.PlanCurrencySymbol = Currency.UserPreferredCurrencySymbol; } else { Sessions.PlanExchangeRate = 1; Sessions.PlanCurrencySymbol = Convert.ToString(Enums.CurrencySymbolsValues[Enums.CurrencySymbols.USD.ToString()]); } } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); } }
private Plangrid GenerateGrid(string year, string component) { // string mode = InsepectMode; Plangrid objplangrid = new Plangrid(); List <PlanHead> headobjlist = new List <PlanHead>(); List <PlanDHTMLXGridDataModel> lineitemrowsobjlist = new List <PlanDHTMLXGridDataModel>(); PlanDHTMLXGridDataModel lineitemrowsobj = new PlanDHTMLXGridDataModel(); PlanController objPlanController = new PlanController(); string customFieldEntityValue = string.Empty; string DropdowList = Enums.CustomFieldType.DropDownList.ToString(); PlanMainDHTMLXGrid objPlanMainDHTMLXGrid = new PlanMainDHTMLXGrid(); try { string Gridheder = string.Empty; string coltype = string.Empty; headobjlist = GenerateHeader(); IEnumerable <BDSService.Currency> lstClientCurrency = objBDSServiceClient.GetClientCurrencyEx(Sessions.User.CID); BDSService.Currency lstConversionRate = objBDSServiceClient.GetCurrencyExchangeRateEx(Sessions.User.CID, Sessions.User.ID); for (int i = 0; i < lstClientCurrency.Count(); i++) { string RowID = lstClientCurrency.ElementAt(i).ISOCurrencyCode; if (RowID.ToLower() != Enums.CurrencyCode.USD.ToString().ToLower()) { lineitemrowsobj = new PlanDHTMLXGridDataModel(); List <Plandataobj> lineitemdataobjlist = new List <Plandataobj>(); lineitemrowsobj.id = RowID; Plandataobj lineitemdataobj = new Plandataobj(); lineitemdataobj = new Plandataobj(); lineitemdataobj.value = "<span><strong>$ USD -> " + lstClientCurrency.ElementAt(i).CurrencySymbol + "</strong></span>" + " <strong>" + lstClientCurrency.ElementAt(i).ISOCurrencyCode + " </strong>(" + lstClientCurrency.ElementAt(i).CurrencyDetail + ")"; lineitemdataobjlist.Add(lineitemdataobj); for (int j = 1; j < headobjlist.Count(); j++) { int month = 0; #region MonthNo if (headobjlist.ElementAt(j).id == Convert.ToString(Enums.ReportMonthDisplayValues[Enums.ReportMonthDisplay.Jan.ToString()])) { month = (int)Enums.ReportMonthDisplay.Jan + 1; } if (headobjlist.ElementAt(j).id == Convert.ToString(Enums.ReportMonthDisplayValues[Enums.ReportMonthDisplay.Feb.ToString()])) { month = (int)Enums.ReportMonthDisplay.Feb + 1; } if (headobjlist.ElementAt(j).id == Convert.ToString(Enums.ReportMonthDisplayValues[Enums.ReportMonthDisplay.Mar.ToString()])) { month = (int)Enums.ReportMonthDisplay.Mar + 1; } if (headobjlist.ElementAt(j).id == Convert.ToString(Enums.ReportMonthDisplayValues[Enums.ReportMonthDisplay.April.ToString()])) { month = (int)Enums.ReportMonthDisplay.April + 1; } if (headobjlist.ElementAt(j).id == Convert.ToString(Enums.ReportMonthDisplayValues[Enums.ReportMonthDisplay.May.ToString()])) { month = (int)Enums.ReportMonthDisplay.May + 1; } if (headobjlist.ElementAt(j).id == Enums.ReportMonthDisplayValues[Enums.ReportMonthDisplay.Jun.ToString()].ToString()) { month = (int)Enums.ReportMonthDisplay.Jun + 1; } if (headobjlist.ElementAt(j).id == Convert.ToString(Enums.ReportMonthDisplayValues[Enums.ReportMonthDisplay.July.ToString()])) { month = (int)Enums.ReportMonthDisplay.July + 1; } if (headobjlist.ElementAt(j).id == Convert.ToString(Enums.ReportMonthDisplayValues[Enums.ReportMonthDisplay.Aug.ToString()])) { month = (int)Enums.ReportMonthDisplay.Aug + 1; } if (headobjlist.ElementAt(j).id == Convert.ToString(Enums.ReportMonthDisplayValues[Enums.ReportMonthDisplay.Sep.ToString()])) { month = (int)Enums.ReportMonthDisplay.Sep + 1; } if (headobjlist.ElementAt(j).id == Convert.ToString(Enums.ReportMonthDisplayValues[Enums.ReportMonthDisplay.Oct.ToString()])) { month = (int)Enums.ReportMonthDisplay.Oct + 1; } if (headobjlist.ElementAt(j).id == Convert.ToString(Enums.ReportMonthDisplayValues[Enums.ReportMonthDisplay.Nov.ToString()])) { month = (int)Enums.ReportMonthDisplay.Nov + 1; } if (headobjlist.ElementAt(j).id == Convert.ToString(Enums.ReportMonthDisplayValues[Enums.ReportMonthDisplay.Dec.ToString()])) { month = (int)Enums.ReportMonthDisplay.Dec + 1; } #endregion var startDate = new DateTime(Convert.ToInt32(year), month, 1); var endDate = startDate.AddMonths(1).AddDays(-1); var data = lstConversionRate.UserCurrency.CurrencyExchangeRate.Where(w => w.StartDate == startDate && w.EndDate == endDate && w.Component.ToLower() == component.ToLower() && w.CurrencyCode.ToLower() == lstClientCurrency.ElementAt(i).ISOCurrencyCode.ToLower()).FirstOrDefault(); lineitemdataobj = new Plandataobj(); if (data != null) { lineitemdataobj.value = Convert.ToString(data.ExchangeRate); } else { lineitemdataobj.value = "1"; } //lineitemdataobj.actval = month.ToString(); lineitemdataobj.actval = month.ToString(); lineitemdataobj.style = "allownumericwithdecimal"; lineitemdataobjlist.Add(lineitemdataobj); } lineitemrowsobj.data = lineitemdataobjlist; lineitemrowsobjlist.Add(lineitemrowsobj); } } objPlanMainDHTMLXGrid.head = headobjlist; objPlanMainDHTMLXGrid.rows = lineitemrowsobjlist; } catch (Exception objException) { ErrorSignal.FromCurrentContext().Raise(objException); } objplangrid.PlanDHTMLXGrid = objPlanMainDHTMLXGrid; return(objplangrid); }