internal void SetDateChanged(DateTime date) { this.Cursor = Cursors.WaitCursor; CurrentDateTime = DateFunctions.GetStartDateTime(date); Update_ShiftsControls(); this.Cursor = Cursors.Default; }
public async Task <IActionResult> SaveNote(string date, string note) { var _date = DateFunctions.GetDate(date); await noteRepository.SaveNote(_date, note); return(RedirectToAction("Index", new { date })); }
/// <summary>Outputs where Date Part function is used includes the array builder. /// <para>jparameters = JSON congifurations relating to this function</para> /// <para>jCategory = the whole configuration which is required to do the variable replace</para> /// <para>GroupID = current Group ID</para> /// <para>ItemID = current row ID</para> /// </summary> public string Output(string jparameters, List <CategoryViewModel> jCategory, int GroupID, int ItemID) { JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); CalculationCSharp.Areas.Configuration.Models.ConfigFunctions Config = new CalculationCSharp.Areas.Configuration.Models.ConfigFunctions(); DateFunctions DatesFunctions = new DateFunctions(); ArrayBuildingFunctions ArrayBuilder = new ArrayBuildingFunctions(); DatePart parameters = (DatePart)javaScriptSerializer.Deserialize(jparameters, typeof(DatePart)); string[] Date1parts = null; //Returns Array Date1parts = ArrayBuilder.InputArrayBuilder(parameters.Date1, jCategory, GroupID, ItemID); string Output = null; //Loop through the array to calculate each value in array foreach (string part in Date1parts) { dynamic InputA = Config.VariableReplace(jCategory, part, GroupID, ItemID); DateTime Date1; DateTime.TryParse(InputA, out Date1); int DatePart = DatesFunctions.GetDatePart(parameters.Part, Date1); Output = Output + Convert.ToString(DatePart) + "~"; } Output = Output.Remove(Output.Length - 1); return(Convert.ToString(Output)); }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { //Date HF from which all dates are derived HF_Date.Value = DateFunctions.GetDateForMond(DateTime.Today).ToShortDateString(); DefineSelectParam(); } }
//Change period (-) protected void lkbtnPrevious_Click(object sender, EventArgs e) { //Remove 7 days to HF_Date on each click until week 4 is reach (showing weeks 1-4) if (DateFunctions.GetWeekNumber(Convert.ToDateTime(HF_Date.Value)) > 4) { HF_Date.Value = Convert.ToDateTime(HF_Date.Value).AddDays(-7).ToShortDateString(); DefineSelectParam(); } }
//Change period (+) protected void lkbtnNext_Click(object sender, EventArgs e) { //Add 7 days to HF_Date on each click until latest week is reach) if (DateFunctions.GetWeekNumber(Convert.ToDateTime(HF_Date.Value)) < DateFunctions.GetWeekNumber(DateTime.Today)) { HF_Date.Value = Convert.ToDateTime(HF_Date.Value).AddDays(+7).ToShortDateString(); DefineSelectParam(); } }
public void CalculateExpressionTest() { string expression = "LastMonthendDate"; // TODO: Initialize to an appropriate value List <ExpressionCondition> expected = null; // TODO: Initialize to an appropriate value List <ExpressionCondition> actual; actual = DateFunctions.CalculateExpression(expression); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
public async Task <IActionResult> Index(string date = "") { var _date = DateFunctions.GetDate(date); var days = await dayRepository.GetDays(_date, _date.AddDays(1).AddMinutes(-1)); ViewBag.Date = _date; ViewBag.Note = await noteRepository.GetNote(_date); return(View(days)); }
public async Task <IActionResult> Index(string from = "", string to = "") { var _from = DateFunctions.GetDate(from, DateTime.Now.Date.AddDays(-7)); var _to = DateFunctions.GetDate(to, DateTime.Now.Date); var notes = await noteRepository.GetBetween(_from, _to); ViewBag.From = _from; ViewBag.To = _to; return(View(notes)); }
private string GetValueFromExpression(QvVariable item) { if (item.HasExpression) { return(DateFunctions.GetValueFromExpression(item.Expression).ToString("yyyy/MM/dd")); } else { return(item.Value); } }
public void GetValueFromExpressionTest() { string p = "LastWeekendDate"; // TODO: Initialize to an appropriate value string expected = "2012/03/11"; // TODO: Initialize to an appropriate value string actual; actual = DateFunctions.GetValueFromExpression(p).ToString("yyyy/MM/dd"); Assert.AreEqual(expected, actual); actual = DateFunctions.GetValueFromExpression(p).ToString("yyyy/MM/dd 00:00:00"); Assert.AreEqual("2012/03/11 00:00:00", actual); //Assert.Inconclusive("Verify the correctness of this test method."); }
public DateTime GetSingleDatetime() { try { int serialDate = (int)GetNumber(); return(DateFunctions.FromExcelSerialDate(serialDate)); } catch (Exception e) { Console.WriteLine(e); throw new ExcelReadException(_prefix + " DateTime", e); } }
public ActionResult Information(string Layer = "_", string networkMode = "", string FilePath = "", string File = "") { Response res = new Response(); try { List <L3TempModel> Messages = new List <L3TempModel>(); if (Directory.Exists(FilePath)) { string fileName = "*.xml"; if (File != "All") { fileName = File; } var fileList = new DirectoryInfo(FilePath).GetFiles(fileName, SearchOption.AllDirectories); int count = 0; foreach (var file in fileList) { myFile mf = new myFile(); XmlDocument doc = new XmlDocument(); doc.Load(fileList[count].FullName); string jsonText = JsonConvert.SerializeXmlNode(doc); JObject json = JObject.Parse(jsonText); DateFunctions df = new DateFunctions(); networkMode = (networkMode == "All") ? "" : networkMode; var rssTitle = json["Drive"]["message-body"]; if (rssTitle != null) { var Chennellst = from p in json["Drive"]["message-body"] select new L3TempModel { rat = (string)p["rat"], RadioBearerID = (string)p["RadioBearerID"], Freq = (string)p["Freq"], PCI = (string)p["PCI"], time = (string)p["time"], channel = (string)p["channel"], Event = (string)p["event"], Ticket = (string)p["time"] }; Messages.AddRange(Chennellst); } count++; } return(Json(Messages.Where(a => a.rat.ToLower().Contains(networkMode.ToLower())), JsonRequestBehavior.AllowGet)); } else { res.Status = "error"; res.Message = "file path not found."; } } catch (Exception ex) { res.Status = "error"; res.Message = ex.Message; } return(Json(res, JsonRequestBehavior.AllowGet)); }
public void TestDateFunctions() { DateTime today = DateTime.Parse("2010-03-26"); Assert.AreEqual(DateFunctions.GetStartDateOfLastWeek(today), DateTime.Parse("2010-03-14")); Assert.AreEqual(DateFunctions.GetStartDateOfLast2Weeks(today), DateTime.Parse("2010-03-07")); Assert.AreEqual(DateFunctions.GetStartDateOfLastMonth(today), DateTime.Parse("2010-02-01")); Assert.AreEqual(DateFunctions.GetStartDateOfLast3Months(today), DateTime.Parse("2009-12-01")); Assert.AreEqual(DateFunctions.GetStartDateOfLast6Months(today), DateTime.Parse("2009-09-01")); }
protected async Task <IEnumerable <ScheduleUI> > LoadSchedules() { //Load the schedules from the database DateTime dt = DateFunctions.GetFirstDayOfWeek(DateTime.Now); dt = dt.AddDays(DayOfWeek); Day = Day + ":" + dt.ToShortDateString(); DateTime d; DateTime.TryParse(dt.ToShortDateString(), out d); Date = d; Schedules = await ScheduleService.GetAll(dt); return(Schedules); }
public async Task <IActionResult> History(int id, string from = "", string to = "") { var location = await locationRepository.GetByIdWithHistory(id); var _from = DateFunctions.GetDate(from, DateTime.Now.Date.AddDays(-7)); var _to = DateFunctions.GetDate(to, DateTime.Now.Date); _to = _to.AddHours(23.99); ViewBag.From = _from; ViewBag.To = _to; if (!(location is Location)) { return(RedirectToAction("Index", "Home")); } return(View(location)); }
/// <summary> /// Crea una entrada en log.xml /// </summary> /// <param name="msg"></param> /// <param name="eventType"></param> public static void Audit(Event ev) { if (!logOnFile) { return; } lock (lookFile)//Evita concurencia en hilos de la app { try { StaticLogger.Log(TargetType.File, ev, string.Format(logFileFullName, DateFunctions.Get_Year_Mont_Day_String(DateTime.Now, '-')) , string.Empty); } catch (System.IO.IOException)//Hilos externos a la app. EJ Notepad { //"The requested operation cannot be performed on a file with a user-mapped section open." //throw ex; } } }
/// <summary>Outputs where Date Part function is used includes the array builder. /// <para>jparameters = JSON congifurations relating to this function</para> /// <para>jCategory = the whole configuration which is required to do the variable replace</para> /// <para>GroupID = current Group ID</para> /// <para>ItemID = current row ID</para> /// </summary> public string Output(string jparameters, List<CategoryViewModel> jCategory, int GroupID, int ItemID) { JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); CalculationCSharp.Areas.Configuration.Models.ConfigFunctions Config = new CalculationCSharp.Areas.Configuration.Models.ConfigFunctions(); DateFunctions DatesFunctions = new DateFunctions(); ArrayBuildingFunctions ArrayBuilder = new ArrayBuildingFunctions(); DatePart parameters = (DatePart)javaScriptSerializer.Deserialize(jparameters, typeof(DatePart)); string[] Date1parts = null; //Returns Array Date1parts = ArrayBuilder.InputArrayBuilder(parameters.Date1, jCategory, GroupID, ItemID); string Output = null; //Loop through the array to calculate each value in array foreach (string part in Date1parts) { dynamic InputA = Config.VariableReplace(jCategory, part, GroupID, ItemID); DateTime Date1; DateTime.TryParse(InputA, out Date1); int DatePart = DatesFunctions.GetDatePart(parameters.Part, Date1); Output = Output + Convert.ToString(DatePart) + "~"; } Output = Output.Remove(Output.Length - 1); return Convert.ToString(Output); }
private void btnSaveResult_Click(object sender, EventArgs e) { if (_SearchSalesOrderDetailRes == null) { return; } if (!Directory.Exists("Logs")) { Directory.CreateDirectory("Logs"); } TestRes wTestRes = new TestRes(); wTestRes.Times = _SearchSalesOrderDetailRes.BusinessData.Times; wTestRes.Sizes = _Sizes; string name = string.Concat(@"Logs\R_", DateFunctions.Get_Year_Mont_Day_Hour_Min_Sec_String(_SearchSalesOrderDetailRes.ContextInformation.HostTime, '_'), ".xml"); Fwk.HelperFunctions.FileFunctions.SaveTextFile(name, wTestRes.GetXml(), false); MessageBox.Show("Test saved successfully"); }
protected void GV_PreRender(object sender, EventArgs e) { MergeRows(GV); if (GV.Rows.Count > 0) { //Get week number for each of the 4 col int col4WeekNb = DateFunctions.GetWeekNumber(Convert.ToDateTime(HF_Date.Value)); int col3WeekNb = col4WeekNb - 1; int col2WeekNb = col4WeekNb - 2; int col1WeekNb = col4WeekNb - 3; //Set gv headers as W + weekNb GV.HeaderRow.Cells[6].Text = $"W{col4WeekNb}"; GV.HeaderRow.Cells[5].Text = $"W{col3WeekNb}"; GV.HeaderRow.Cells[4].Text = $"W{col2WeekNb}"; GV.HeaderRow.Cells[3].Text = $"W{col1WeekNb}"; GV.HeaderRow.Cells[10].Text = $"W{col4WeekNb}"; GV.HeaderRow.Cells[9].Text = $"W{col3WeekNb}"; GV.HeaderRow.Cells[8].Text = $"W{col2WeekNb}"; GV.HeaderRow.Cells[7].Text = $"W{col1WeekNb}"; } }
private ObservableCollection <FieldValue> GetValuesFromExpression(QVField item) { ObservableCollection <FieldValue> values = new ObservableCollection <FieldValue>(); if (item.Name == "TheYear" || item.Name == "MonthOfYear" || item.Name == "DayOfMonth") { var valuelist = Functions.GetDateValueFromExpression(item.Expression); foreach (var value in valuelist) { values.Add(new FieldValue() { IsNumeric = true, Number = value, Value = value.ToString() }); } } else if (item.Name == "YearMonth" && item.Expression.Contains("CurrentFiscalYearMonthEx")) { values = Functions.GetValuesFromCurrentFiscalYearMonthEx(); } else if (item.Name == "YearMonth" && item.Expression.Contains("CurrentFiscalYearMonth")) { values = Functions.GetValuesFromCurrentFiscalYearMonth(); } else if (item.Name == "YearMonth" && item.Expression.Contains("LatestTwoFiscalYearMonth")) { values = Functions.GetValuesFromLatestTwoFiscalYearMonth(); } else if (item.Name == "YearMonth" && item.Expression.Contains("CurrentYearMonthNumeric")) { values = Functions.GetValuesFromCurrentYearMonthNumeric(); } else if (item.Name == "YearMonth" && item.Expression.Contains("CurrentYearMonth")) { values = Functions.GetValuesFromCurrentYearMonth(); } else if (item.Name == "FiscalYearName" && item.Expression == "CurrentFiscalYearName") { values = Functions.GetCurrentFiscalYearName(); } else if (item.Name == "FiscalYearName" && item.Expression == "PreviousFiscalYearName") { values = Functions.GetPreviousFiscalYearName(); } else if (item.Name == "UsageYearMonth" && item.Expression.Contains("LastMonthFiscalYearMonth")) { values = Functions.GetValuesFromLastMonthFiscalYearMonth(); var field = this.GetQVFieldByName(item.Name); foreach (var value in values) { value.IsNumeric = field.Values.First(x => x.Value == value.Value).IsNumeric; value.Number = field.Values.First(x => x.Value == value.Value).Number; } } else { var field = this.GetQVFieldByName(item.Name); List <ExpressionCondition> conditions = DateFunctions.CalculateExpression(item.Expression); foreach (var value in field.Values) { DateTime date = DateTime.Parse(value.Value).Date; bool isChecked = true; foreach (var condition in conditions) { if (!condition.IsChecked(date)) { isChecked = false; break; } } if (isChecked) { values.Add(value); } } } return(values); }
/// <summary>Outputs where Period function is used, includes the array builder. /// <para>jparameters = JSON congifurations relating to this function</para> /// <para>jCategory = the whole configuration which is required to do the variable replace</para> /// <para>GroupID = current Group ID</para> /// <para>ItemID = current row ID</para> /// </summary> public string Output(string jparameters, List <CategoryViewModel> jCategory, int GroupID, int ItemID) { JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); DateFunctions DateFunctions = new DateFunctions(); ArrayBuildingFunctions ArrayBuilder = new ArrayBuildingFunctions(); Period Dates = new Period(); Period parameters = (Period)javaScriptSerializer.Deserialize(jparameters, typeof(Period)); string[] Date1parts = null; string[] Date2parts = null; //Returns array Date1parts = ArrayBuilder.InputArrayBuilder(parameters.Date1, jCategory, GroupID, ItemID); Date2parts = ArrayBuilder.InputArrayBuilder(parameters.Date2, jCategory, GroupID, ItemID); string OutputValue = null; string Output = null; int Counter = 0; //Gets Max Length of array so loops through all values int MaxLength = ArrayBuilder.GetMaxLength(Date1parts, Date2parts); //Loop through the array to calculate each value in array for (int i = 0; i < MaxLength; i++) { dynamic InputA = null; dynamic InputB = null; InputA = ArrayBuilder.GetArrayPart(Date1parts, Counter); InputB = ArrayBuilder.GetArrayPart(Date2parts, Counter); Counter = Counter + 1; //Checks if Inputs are OK to proceed in using the calculation if (InputA != "" && InputB != "" && InputA != "01/01/0001" && InputB != "01/01/0001") { DateTime Date1; DateTime Date2; if (InputA != null) { DateTime.TryParse(InputA, out Date1); } else { Date1 = Convert.ToDateTime("01/01/0001"); } if (InputB != null) { DateTime.TryParse(InputB, out Date2); } else { Date2 = Convert.ToDateTime("01/01/0001"); } String DateAdjustmentType = parameters.DateAdjustmentType; Boolean Inclusive = parameters.Inclusive; Double DaysinYear = parameters.DaysinYear; //Calcuates the relevant period if (Date1 <= Date2) { if (DateAdjustmentType == "YearsDays") { OutputValue = Convert.ToString(DateFunctions.YearsDaysBetween(Date1, Date2, Inclusive, DaysinYear)); } else if (DateAdjustmentType == "YearsMonths") { OutputValue = Convert.ToString(DateFunctions.YearsMonthsBetween(Date1, Date2, Inclusive, DaysinYear)); } else if (DateAdjustmentType == "Years") { OutputValue = Convert.ToString(DateFunctions.YearsBetween(Date1, Date2, Inclusive, DaysinYear)); } else if (DateAdjustmentType == "Months") { OutputValue = Convert.ToString(DateFunctions.GetMonthsBetween(Date1, Date2, Inclusive)); } else if (DateAdjustmentType == "Days") { OutputValue = Convert.ToString(DateFunctions.DaysBetween(Date1, Date2, Inclusive, DaysinYear)); } else { OutputValue = "0"; } } else { OutputValue = Convert.ToString(0); } Output = Output + OutputValue + "~"; } else { OutputValue = Convert.ToString(0); Output = Output + OutputValue + "~"; } } if (Output != null) { Output = Output.Remove(Output.Length - 1); } return(Output); }
/// <summary>Outputs Date Adjustment function is used, includes the array builder. /// <para>jparameters = JSON congifurations relating to this function</para> /// <para>jCategory = the whole configuration which is required to do the variable replace</para> /// <para>GroupID = current Group ID</para> /// <para>ItemID = current row ID</para> /// </summary> public string Output(string jparameters, List<CategoryViewModel> jCategory, int GroupID, int ItemID) { JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); CalculationCSharp.Areas.Configuration.Models.ConfigFunctions Config = new CalculationCSharp.Areas.Configuration.Models.ConfigFunctions(); DateFunctions DatesFunctions = new DateFunctions(); ArrayBuildingFunctions ArrayBuilder = new ArrayBuildingFunctions(); Dates parameters = (Dates)javaScriptSerializer.Deserialize(jparameters, typeof(Dates)); if(parameters.Type == "Today") { return DateTime.Now.ToShortDateString(); } string[] Date1parts = null; string[] Date2parts = null; //Returns array Date1parts = ArrayBuilder.InputArrayBuilder(parameters.Date1, jCategory, GroupID, ItemID); Date2parts = ArrayBuilder.InputArrayBuilder(parameters.Date2, jCategory, GroupID, ItemID); string Output = null; int Counter = 0; //Gets Max Length of array so loops through all values int MaxLength = ArrayBuilder.GetMaxLength(Date1parts, Date2parts); //Loop through the array to calculate each value in array for (int i = 0; i < MaxLength; i++) { dynamic InputA = null; dynamic InputB = null; //Gets the current array to use in the loop InputA = ArrayBuilder.GetArrayPart(Date1parts, Counter); InputB = ArrayBuilder.GetArrayPart(Date2parts, Counter); dynamic InputC = Config.VariableReplace(jCategory, parameters.Period, GroupID, ItemID); DateTime Date1; DateTime Date2; Decimal Period; //Data output checker if (InputA != null) { DateTime.TryParse(InputA, out Date1); } else { Date1 = Convert.ToDateTime("01/01/0001"); } if (InputB != null) { DateTime.TryParse(InputB, out Date2); } else { Date2 = Convert.ToDateTime("01/01/0001"); } Decimal.TryParse(InputC, out Period); string date = DatesFunctions.DateAdjustment(parameters.Type, Convert.ToString(Date1), Convert.ToString(Date2), parameters.PeriodType, Period, parameters.Adjustment, parameters.Day, parameters.Month); Output = Output + date + "~"; Counter = Counter + 1; } if(Output != null) { Output = Output.Remove(Output.Length - 1); } return Convert.ToString(Output); }
public void DateFromStringMDDTest() { Assert.AreEqual(new DateTime(2008, 9, 17), DateFunctions.DateFromStringMDD("9172008")); Assert.AreEqual(new DateTime(2008, 9, 13), DateFunctions.DateFromStringMDD("9132008")); }
protected void GV_DataBound(object sender, EventArgs e) { #region Compute KPI //Because some KPIs are computed from other KPIs, a new column is needed to hold this mix of dependant and precendent KPIs //Precedent KPIs = initial; //Dependent KPIs = function of some precedent KPIs; foreach (GridViewRow row in GV.Rows) { if (row.RowType == DataControlRowType.DataRow) { //Look up values of Precedent KPI Label lblW1Adj = (Label)row.FindControl("lblW1Adj"); decimal KPIVal; decimal KPI20Val = (decimal.TryParse(LabelFinder(GetRowIndexByKPI("VA Sales (thousands"), "lblW1").Text, out KPIVal)) ? 0 : KPIVal; decimal KPI21Val = (decimal.TryParse(LabelFinder(GetRowIndexByKPI("NVA Sales (thousands)"), "lblW1").Text, out KPIVal)) ? 0 : KPIVal; decimal KPI36Val = (decimal.TryParse(LabelFinder(GetRowIndexByKPI("MOD OT hours"), "lblW1").Text, out KPIVal)) ? 0 : KPIVal; decimal KPI37Val = (decimal.TryParse(LabelFinder(GetRowIndexByKPI("MOD total hours"), "lblW1").Text, out KPIVal)) ? 0 : KPIVal; decimal KPI39Val = (decimal.TryParse(LabelFinder(GetRowIndexByKPI("MOI total hours"), "lblW1").Text, out KPIVal)) ? 0 : KPIVal; decimal KPI40Val = (decimal.TryParse(LabelFinder(GetRowIndexByKPI("Scrap Cost"), "lblW1").Text, out KPIVal)) ? 0 : KPIVal; decimal KPI41Val = (decimal.TryParse(LabelFinder(GetRowIndexByKPI("MOD Earned hours"), "lblW1").Text, out KPIVal)) ? 0 : KPIVal; decimal KPI42Val = (decimal.TryParse(LabelFinder(GetRowIndexByKPI("MRO Costs"), "lblW1").Text, out KPIVal)) ? 0 : KPIVal; if (lblW1Adj != null) { switch (row.Cells[2].Text) { case "Scrap as % of Total Sales": lblW1Adj.Text = (KPI40Val == 0 || KPI21Val == 0) ? "0" : (KPI39Val / KPI21Val).ToString(); break; case "Manufacturing Costs (% of VASales)": lblW1Adj.Text = (KPI20Val == 0) ? "0" : (KPI42Val / KPI20Val).ToString(); break; case "Total Sales (thousands)": lblW1Adj.Text = (KPI20Val + KPI21Val).ToString(); break; case "DLE %": lblW1Adj.Text = (KPI37Val == 0) ? "0" : (KPI41Val / KPI37Val).ToString(); break; case "MOD HC Equivalent": lblW1Adj.Text = (1 + KPI37Val / (8 * 4)).ToString(); break; case "MOD OT %": lblW1Adj.Text = (KPI36Val == 0 || KPI37Val == 0) ? "0" : (KPI36Val / KPI37Val).ToString(); break; default: lblW1Adj.Text = ((Label)row.FindControl("lblW1")).Text; break; } } } //W2 if (row.RowType == DataControlRowType.DataRow) { //Look up values of Precedent KPI Label lblW2Adj = (Label)row.FindControl("lblW2Adj"); decimal KPIVal; decimal KPI20Val = (decimal.TryParse(LabelFinder(GetRowIndexByKPI("VA Sales (thousands"), "lblW2").Text, out KPIVal)) ? 0 : KPIVal; decimal KPI21Val = (decimal.TryParse(LabelFinder(GetRowIndexByKPI("NVA Sales (thousands)"), "lblW2").Text, out KPIVal)) ? 0 : KPIVal; decimal KPI36Val = (decimal.TryParse(LabelFinder(GetRowIndexByKPI("MOD OT hours"), "lblW2").Text, out KPIVal)) ? 0 : KPIVal; decimal KPI37Val = (decimal.TryParse(LabelFinder(GetRowIndexByKPI("MOD total hours"), "lblW2").Text, out KPIVal)) ? 0 : KPIVal; decimal KPI39Val = (decimal.TryParse(LabelFinder(GetRowIndexByKPI("MOI total hours"), "lblW2").Text, out KPIVal)) ? 0 : KPIVal; decimal KPI40Val = (decimal.TryParse(LabelFinder(GetRowIndexByKPI("Scrap Cost"), "lblW2").Text, out KPIVal)) ? 0 : KPIVal; decimal KPI41Val = (decimal.TryParse(LabelFinder(GetRowIndexByKPI("MOD Earned hours"), "lblW2").Text, out KPIVal)) ? 0 : KPIVal; decimal KPI42Val = (decimal.TryParse(LabelFinder(GetRowIndexByKPI("MRO Costs"), "lblW2").Text, out KPIVal)) ? 0 : KPIVal; if (lblW2Adj != null) { switch (row.Cells[2].Text) { case "Scrap as % of Total Sales": lblW2Adj.Text = (KPI40Val == 0 || KPI21Val == 0) ? "0" : (KPI39Val / KPI21Val).ToString(); break; case "Manufacturing Costs (% of VASales)": lblW2Adj.Text = (KPI20Val == 0) ? "0" : (KPI42Val / KPI20Val).ToString(); break; case "Total Sales (thousands)": lblW2Adj.Text = (KPI20Val + KPI21Val).ToString(); break; case "DLE %": lblW2Adj.Text = (KPI37Val == 0) ? "0" : (KPI41Val / KPI37Val).ToString(); break; case "MOD HC Equivalent": lblW2Adj.Text = (1 + KPI37Val / (8 * 4)).ToString(); break; case "MOD OT %": lblW2Adj.Text = (KPI36Val == 0 || KPI37Val == 0) ? "0" : (KPI36Val / KPI37Val).ToString(); break; default: lblW2Adj.Text = ((Label)row.FindControl("lblW2")).Text; break; } } } //W3 if (row.RowType == DataControlRowType.DataRow) { //Look up values of Precedent KPI Label lblW3Adj = (Label)row.FindControl("lblW3Adj"); decimal KPIVal; decimal KPI20Val = (decimal.TryParse(LabelFinder(GetRowIndexByKPI("VA Sales (thousands"), "lblW3").Text, out KPIVal)) ? 0 : KPIVal; decimal KPI21Val = (decimal.TryParse(LabelFinder(GetRowIndexByKPI("NVA Sales (thousands)"), "lblW3").Text, out KPIVal)) ? 0 : KPIVal; decimal KPI36Val = (decimal.TryParse(LabelFinder(GetRowIndexByKPI("MOD OT hours"), "lblW3").Text, out KPIVal)) ? 0 : KPIVal; decimal KPI37Val = (decimal.TryParse(LabelFinder(GetRowIndexByKPI("MOD total hours"), "lblW3").Text, out KPIVal)) ? 0 : KPIVal; decimal KPI39Val = (decimal.TryParse(LabelFinder(GetRowIndexByKPI("MOI total hours"), "lblW3").Text, out KPIVal)) ? 0 : KPIVal; decimal KPI40Val = (decimal.TryParse(LabelFinder(GetRowIndexByKPI("Scrap Cost"), "lblW3").Text, out KPIVal)) ? 0 : KPIVal; decimal KPI41Val = (decimal.TryParse(LabelFinder(GetRowIndexByKPI("MOD Earned hours"), "lblW3").Text, out KPIVal)) ? 0 : KPIVal; decimal KPI42Val = (decimal.TryParse(LabelFinder(GetRowIndexByKPI("MRO Costs"), "lblW3").Text, out KPIVal)) ? 0 : KPIVal; if (lblW3Adj != null) { switch (row.Cells[2].Text) { case "Scrap as % of Total Sales": lblW3Adj.Text = (KPI40Val == 0 || KPI21Val == 0) ? "0" : (KPI39Val / KPI21Val).ToString(); break; case "Manufacturing Costs (% of VASales)": lblW3Adj.Text = (KPI20Val == 0) ? "0" : (KPI42Val / KPI20Val).ToString(); break; case "Total Sales (thousands)": lblW3Adj.Text = (KPI20Val + KPI21Val).ToString(); break; case "DLE %": lblW3Adj.Text = (KPI37Val == 0) ? "0" : (KPI41Val / KPI37Val).ToString(); break; case "MOD HC Equivalent": lblW3Adj.Text = (1 + KPI37Val / (8 * 4)).ToString(); break; case "MOD OT %": lblW3Adj.Text = (KPI36Val == 0 || KPI37Val == 0) ? "0" : (KPI36Val / KPI37Val).ToString(); break; default: lblW3Adj.Text = ((Label)row.FindControl("lblW3")).Text; break; } } } //W4 if (row.RowType == DataControlRowType.DataRow) { //Look up values of Precedent KPI Label lblW4Adj = (Label)row.FindControl("lblW4Adj"); decimal KPIVal; decimal KPI20Val = (decimal.TryParse(LabelFinder(GetRowIndexByKPI("VA Sales (thousands"), "lblW4").Text, out KPIVal)) ? 0 : KPIVal; decimal KPI21Val = (decimal.TryParse(LabelFinder(GetRowIndexByKPI("NVA Sales (thousands)"), "lblW4").Text, out KPIVal)) ?0: KPIVal; decimal KPI36Val = (decimal.TryParse(LabelFinder(GetRowIndexByKPI("MOD OT hours"), "lblW4").Text, out KPIVal))?0: KPIVal; decimal KPI37Val = (decimal.TryParse(LabelFinder(GetRowIndexByKPI("MOD total hours"), "lblW4").Text, out KPIVal))?0:KPIVal; decimal KPI39Val = (decimal.TryParse(LabelFinder(GetRowIndexByKPI("MOI total hours"), "lblW4").Text, out KPIVal))?0:KPIVal; decimal KPI40Val = (decimal.TryParse(LabelFinder(GetRowIndexByKPI("Scrap Cost"), "lblW4").Text, out KPIVal)) ? 0 : KPIVal; decimal KPI41Val = (decimal.TryParse(LabelFinder(GetRowIndexByKPI("MOD Earned hours"), "lblW4").Text, out KPIVal)) ? 0 : KPIVal; decimal KPI42Val = (decimal.TryParse(LabelFinder(GetRowIndexByKPI("MRO Costs"), "lblW4").Text, out KPIVal)) ? 0 : KPIVal; if (lblW4Adj != null) { switch (row.Cells[2].Text) { case "Scrap as % of Total Sales": lblW4Adj.Text = (KPI40Val == 0 || KPI21Val == 0) ? "0" : (KPI39Val / KPI21Val).ToString(); break; case "Manufacturing Costs (% of VASales)": lblW4Adj.Text = (KPI20Val == 0)?"0": (KPI42Val / KPI20Val).ToString(); break; case "Total Sales (thousands)": lblW4Adj.Text = (KPI20Val + KPI21Val).ToString(); break; case "DLE %": lblW4Adj.Text = (KPI37Val == 0) ? "0" : (KPI41Val / KPI37Val).ToString(); break; case "MOD HC Equivalent": lblW4Adj.Text = (1 + KPI37Val / (8 * 4)).ToString(); break; case "MOD OT %": lblW4Adj.Text = (KPI36Val == 0 || KPI37Val == 0) ? "0" : (KPI36Val / KPI37Val).ToString(); break; default: lblW4Adj.Text = ((Label)row.FindControl("lblW4")).Text; break; } } } } #endregion ComputeMTD(); #region Function to set format based on type //Style KPI based on their data type foreach (GridViewRow row in GV.Rows) { if (row.RowType == DataControlRowType.DataRow) { Label lblW1Adj = ((Label)row.FindControl("lblW1Adj")); Label lblW2Adj = ((Label)row.FindControl("lblW2Adj")); Label lblW3Adj = ((Label)row.FindControl("lblW3Adj")); Label lblW4Adj = ((Label)row.FindControl("lblW4Adj")); Label lblMTD = ((Label)row.FindControl("lblMTD")); Label lblBudget = ((Label)row.FindControl("lblBudget")); List <Label> lblWAdj = new List <Label>(); lblWAdj.Add(lblW1Adj); lblWAdj.Add(lblW2Adj); lblWAdj.Add(lblW3Adj); lblWAdj.Add(lblW4Adj); lblWAdj.Add(lblMTD); lblWAdj.Add(lblBudget); string type = GV.DataKeys[row.RowIndex].Values[0].ToString(); decimal colVal; foreach (Label lbl in lblWAdj) { if (lbl != null) { switch (type) { case "p0": if (lbl != null) { if (Decimal.TryParse(lbl.Text, out colVal)) { lbl.Text = colVal.ToString("p0"); } } break; case "p1": if (lbl != null) { if (Decimal.TryParse(lbl.Text, out colVal)) { lbl.Text = colVal.ToString("p1"); } } break; case "p2": if (lbl != null) { if (Decimal.TryParse(lbl.Text, out colVal)) { lbl.Text = colVal.ToString("p2"); } } break; case "c0": if (lbl != null) { if (Decimal.TryParse(lbl.Text, out colVal)) { lbl.Text = colVal.ToString("c0"); } } break; case "n0": if (lbl != null) { if (Decimal.TryParse(lbl.Text, out colVal)) { lbl.Text = colVal.ToString("n0"); } } break; case "n2": if (lbl != null) { if (Decimal.TryParse(lbl.Text, out colVal)) { lbl.Text = colVal.ToString("n2"); } } break; default: break; } } } } } #endregion #region Random content for comment column //Create default comments foreach (GridViewRow row in GV.Rows) { if (row.RowType == DataControlRowType.DataRow) { int col4WeekNb = DateFunctions.GetWeekNumber(Convert.ToDateTime(HF_Date.Value)); Label comments = ((Label)row.FindControl("lblComments")); if (comments.Text == "") { comments.Text = $"This is a default comment for {HF_Plant.Value} for the week W{col4WeekNb}, This is a default comment for {HF_Plant.Value} for the week W{col4WeekNb}, This is a default comment for {HF_Plant.Value} for the week W{col4WeekNb}, This is a default comment for {HF_Plant.Value} for the week W{col4WeekNb},This is a default comment for {HF_Plant.Value} for the week W{col4WeekNb}"; } } } #endregion }
public void DateFromStringTest() { Assert.AreEqual(new DateTime(2007, 12, 5), DateFunctions.DateFromString("5122007")); Assert.AreEqual(new DateTime(1995, 10, 25), DateFunctions.DateFromString("25101995")); }
//Calcuation Controller Action public void CalculateAction(List <CategoryViewModel> jCategory) { foreach (var group in jCategory) { foreach (var item in group.Functions) { if (item.Function == "Input") { item.Output = InputFunctions.Output(item.Type, item.Output); OutputList.Add(new OutputList { ID = Convert.ToString(item.ID), Field = item.Name, Value = item.Output, Group = group.Name }); } else { //Logic check at Column Level string colLogic = null; bool colLogicParse = true; if (group.Logic != null) { foreach (var bit in group.Logic) { var grouplastLogic = group.Logic.Last(); string grouplastLogicOperator = grouplastLogic.Operator; Logic Logic = new Logic(); colLogic = Logic.Output(jCategory, bit, group.ID, 0); Expression ex = new Expression(colLogic); try { colLogicParse = Convert.ToBoolean(ex.Evaluate()); } catch (Exception exception) { logger.Error(exception); throw new HttpException(exception.ToString()); } if (grouplastLogicOperator == "AND" && colLogicParse == false) { break; } else if (grouplastLogicOperator == "OR" && colLogicParse == true) { colLogicParse = true; break; } } } if (item.Parameter.Count > 0) { string logic = null; bool logicparse = true; string MathString = null; bool PowOpen = false; //Logic check at column level if (colLogicParse == true) { foreach (var bit in item.Logic) { var lastLogic = item.Logic.Last(); string lastLogicOperator = lastLogic.Operator; Logic Logic = new Logic(); logic = Logic.Output(jCategory, bit, group.ID, item.ID); Expression ex = new Expression(logic); try { logicparse = Convert.ToBoolean(ex.Evaluate()); } catch (Exception exception) { logger.Error(exception); throw new HttpException(exception.ToString()); } if (lastLogicOperator == "AND" && logicparse == false) { break; } else if (lastLogicOperator == "OR" && logicparse == true) { logicparse = true; break; } } } else { logicparse = false; } //Run code if logic if met at column and row level if (logicparse == true) { int paramCount = 1; foreach (var param in item.Parameter) { string jparameters = Newtonsoft.Json.JsonConvert.SerializeObject(param); logger.Debug("Column Name(" + group.ID + ") - " + group.Name + " || Row Name(" + item.ID + ") - " + item.Name); if (item.Function == "Maths") { Maths Maths = new Maths(); Maths parameters = (Maths)javaScriptSerializer.Deserialize(jparameters, typeof(Maths)); MathString = Maths.Output(jparameters, jCategory, group.ID, item.ID, MathString, PowOpen); PowOpen = Maths.PowOpen(jparameters, PowOpen); if (paramCount == item.Parameter.Count) { Expression e = new Expression(MathString); var Calculation = e.Evaluate(); bool DeciParse; decimal CalculationDeci; string Rounding; DeciParse = decimal.TryParse(Convert.ToString(Calculation), out CalculationDeci); Rounding = Convert.ToString(parameters.Rounding); if (Rounding == null || Rounding == "") { Rounding = "2"; } if (DeciParse == true) { decimal Output = CalculationDeci; MathematicalFunctions MathematicalFunctions = new MathematicalFunctions(); try { Output = MathematicalFunctions.Rounding(Convert.ToString(parameters.RoundingType), Rounding, Output); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } item.Output = Convert.ToString(Output); } else { item.Output = "0"; } } paramCount = paramCount + 1; } else if (item.Function == "ErrorsWarnings") { ErrorsWarnings Errors = new ErrorsWarnings(); ErrorsWarnings parameters = (ErrorsWarnings)javaScriptSerializer.Deserialize(jparameters, typeof(ErrorsWarnings)); item.Name = parameters.Type; item.Output = parameters.String1; } else if (item.Function == "Comments") { Comments Errors = new Comments(); Comments parameters = (Comments)javaScriptSerializer.Deserialize(jparameters, typeof(Comments)); item.Output = parameters.String1; } else if (item.Function == "Period") { DateFunctions DateFunctions = new DateFunctions(); Period Periods = new Period(); try { item.Output = Periods.Output(jparameters, jCategory, group.ID, item.ID); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } } else if (item.Function == "Factors") { Factors Factors = new Factors(); Factors parameters = (Factors)javaScriptSerializer.Deserialize(jparameters, typeof(Factors)); try { item.Output = Factors.Output(jparameters, jCategory, group.ID, item.ID); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } item.Type = parameters.OutputType; } else if (item.Function == "DateAdjustment") { Dates Dates = new Dates(); try { item.Output = Dates.Output(jparameters, jCategory, group.ID, item.ID); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } } else if (item.Function == "DatePart") { DatePart DateParts = new DatePart(); try { item.Output = DateParts.Output(jparameters, jCategory, group.ID, item.ID); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } } else if (item.Function == "Return") { Return Return = new Return(); try { item.Output = Return.Output(jparameters, jCategory, group.ID, item.ID); OutputList.Add(new OutputList { ID = Convert.ToString(item.ID), Field = item.Name, Value = item.Output, Group = group.Name }); return; } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } } else if (item.Function == "MathsFunctions") { MathsFunctions MathsFunctions = new MathsFunctions(); try { item.Output = MathsFunctions.Output(jparameters, jCategory, group.ID, item.ID, group); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } } else if (item.Function == "ArrayFunctions") { ArrayFunctions ArrayFunctions = new ArrayFunctions(); ArrayFunctions parameters = (ArrayFunctions)javaScriptSerializer.Deserialize(jparameters, typeof(ArrayFunctions)); try { item.Output = ArrayFunctions.Output(jparameters, jCategory, group.ID, item.ID); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } if (parameters.Function == "Count") { item.Type = "Decimal"; } else { item.Type = parameters.LookupType; } } else if (item.Function == "StringFunctions") { StringFunctions StringFunctions = new StringFunctions(); StringFunctions parameters = (StringFunctions)javaScriptSerializer.Deserialize(jparameters, typeof(StringFunctions)); try { item.Output = StringFunctions.Output(jparameters, jCategory, group.ID, item.ID); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } if (parameters.Type == "Len") { item.Type = "Decimal"; } else { item.Type = "String"; } } else if (item.Function == "Function") { Function Functions = new Function(); Function parameters = (Function)javaScriptSerializer.Deserialize(jparameters, typeof(Function)); FunctionConfiguration calcFunction = db.FunctionConfiguration.Find(Convert.ToInt32(parameters.ID)); List <CategoryViewModel> calcFunctionConfig = (List <CategoryViewModel>)javaScriptSerializer.Deserialize(calcFunction.Configuration, typeof(List <CategoryViewModel>)); //replace inputs from main configuration to function foreach (var row in calcFunctionConfig[0].Functions) { int index = parameters.Input.FindIndex(a => a.Name == row.Name); if (index >= 0) { row.Output = parameters.Input[index].Output; } else { row.Output = null; } } foreach (var input in calcFunctionConfig[0].Functions) { if (input.Output != null) { input.Output = Convert.ToString(Functions.Output(jparameters, jCategory, group.ID, item.ID, input.Output, input.Type)); } } //run the function with the new inputs Calculate Calculate = new Calculate(); calcFunctionConfig = Calculate.DebugResults(calcFunctionConfig); item.SubOutput = Calculate.OutputResults(calcFunctionConfig); foreach (var col in calcFunctionConfig) { int index = col.Functions.FindIndex(a => a.Function == "Return"); if (index >= 0) { item.Output = col.Functions[index].Output; foreach (var thing in col.Functions[index].Parameter) { foreach (var test in thing) { if (test.Key == "Datatype") { item.Type = test.Value; } } } } } } } //Expected results on the builder this sets the required ones if (item.ExpectedResult == null || item.ExpectedResult == "") { item.Pass = "******"; } else if (item.ExpectedResult == item.Output) { item.Pass = "******"; } else { item.Pass = "******"; } OutputList.Add(new OutputList { ID = Convert.ToString(item.ID), Field = item.Name, Value = item.Output, Group = group.Name, SubOutput = item.SubOutput }); } else { //Ignores the row if logic is not met dynamic LogicReplace = Config.VariableReplace(jCategory, item.Name, group.ID, item.ID); if (Convert.ToString(LogicReplace) == Convert.ToString(item.Name)) { item.Output = null; } else { item.Output = Convert.ToString(LogicReplace); } item.Pass = "******"; OutputList.Add(new OutputList { ID = Convert.ToString(item.ID), Field = item.Name, Value = item.Output, Group = group.Name, SubOutput = item.SubOutput }); } } } } } }
public override void Refresh() { if (this.DesignMode) { return; } this.Date = Fwk.HelperFunctions.DateFunctions.GetStartDateTime(this.Date); _TimespamViewList = Get_ArrayOfTimes(); TimespamView wTimespamView = null; if (AppointmentList != null) { //Recorrer todos los turnos a partir de Date foreach (AppointmentBE a in AppointmentList.Where <AppointmentBE>(p => DateFunctions.GetStartDateTime(p.Start.Value).Equals(this.Date) && !p.IsExceptional)) { TimeSpan t = a.TimeStart_timesp; //Este cilo permite pintar Varios appointments como uno solo //El caso se da cuando el usuario selecciona varios concecutivos y los asigna a un TURNO. Por lo tanto se crea un //solo Appoiment en la bace de datos donde TimeStart_timesp y TimeEnd_timesp incluira todos los turnos seleccionados while (true) { //Creo ej: 10:15 para buscarlo dentro de los TimesView de la Grilla string wTimeStart = String.Concat(t.ToString("hh"), ":", t.ToString("mm")); wTimespamView = _TimespamViewList.Where <TimespamView>(p => p.TimeString.Equals(wTimeStart)).FirstOrDefault <TimespamView>(); if (wTimespamView != null) { wTimespamView.Appointment = a; } t = t.Add(TimeSpan.FromMinutes(a.Duration.Value)); //Revisar que pasa si t > a.TimeEnd_timesp if (t >= a.TimeEnd_timesp) { break; } } } } #region sobreturnos //Si existen sobreturnos agregarlos al la lista de timelines var sobreturnos = AppointmentList.Where <AppointmentBE>(p => p.IsExceptional); Insert_Sobreturnos(sobreturnos.ToList()); #endregion _TimespamViewList.Sort(new TimeSpanComparer()); //_TimespamViewList = _TimespamViewList.OrderBy(p => p.Time).ToList<TimespamView>(); timespamViewBindingSource.DataSource = _TimespamViewList; gridControl2.RefreshDataSource(); gridView2.RefreshData(); base.Refresh(); }
//Calcuation Controller Action public void CalculateAction(List<CategoryViewModel> jCategory) { foreach (var group in jCategory) { foreach (var item in group.Functions) { if (item.Function == "Input") { item.Output = InputFunctions.Output(item.Type, item.Output); OutputList.Add(new OutputList { ID = Convert.ToString(item.ID), Field = item.Name, Value = item.Output, Group = group.Name }); } else { //Logic check at Column Level string colLogic = null; bool colLogicParse = true; if(group.Logic != null) { foreach (var bit in group.Logic) { var grouplastLogic = group.Logic.Last(); string grouplastLogicOperator = grouplastLogic.Operator; Logic Logic = new Logic(); colLogic = Logic.Output(jCategory, bit, group.ID, 0); Expression ex = new Expression(colLogic); try { colLogicParse = Convert.ToBoolean(ex.Evaluate()); } catch (Exception exception) { logger.Error(exception); throw new HttpException(exception.ToString()); } if (grouplastLogicOperator == "AND" && colLogicParse == false) { break; } else if (grouplastLogicOperator == "OR" && colLogicParse == true) { colLogicParse = true; break; } } } if (item.Parameter.Count > 0) { string logic = null; bool logicparse = true; string MathString = null; bool PowOpen = false; //Logic check at column level if (colLogicParse == true) { foreach (var bit in item.Logic) { var lastLogic = item.Logic.Last(); string lastLogicOperator = lastLogic.Operator; Logic Logic = new Logic(); logic = Logic.Output(jCategory, bit, group.ID, item.ID); Expression ex = new Expression(logic); try { logicparse = Convert.ToBoolean(ex.Evaluate()); } catch (Exception exception) { logger.Error(exception); throw new HttpException(exception.ToString()); } if (lastLogicOperator == "AND" && logicparse == false) { break; } else if (lastLogicOperator == "OR" && logicparse == true) { logicparse = true; break; } } } else { logicparse = false; } //Run code if logic if met at column and row level if (logicparse == true) { int paramCount = 1; foreach (var param in item.Parameter) { string jparameters = Newtonsoft.Json.JsonConvert.SerializeObject(param); logger.Debug("Column Name(" + group.ID + ") - " + group.Name + " || Row Name(" + item.ID +") - " + item.Name); if (item.Function == "Maths") { Maths Maths = new Maths(); Maths parameters = (Maths)javaScriptSerializer.Deserialize(jparameters, typeof(Maths)); MathString = Maths.Output(jparameters,jCategory,group.ID,item.ID,MathString,PowOpen); PowOpen = Maths.PowOpen(jparameters, PowOpen); if (paramCount == item.Parameter.Count) { Expression e = new Expression(MathString); var Calculation = e.Evaluate(); bool DeciParse; decimal CalculationDeci; string Rounding; DeciParse = decimal.TryParse(Convert.ToString(Calculation), out CalculationDeci); Rounding = Convert.ToString(parameters.Rounding); if (Rounding == null || Rounding == "") { Rounding = "2"; } if (DeciParse == true) { decimal Output = CalculationDeci; MathematicalFunctions MathematicalFunctions = new MathematicalFunctions(); try { Output = MathematicalFunctions.Rounding(Convert.ToString(parameters.RoundingType), Rounding, Output); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } item.Output = Convert.ToString(Output); } else { item.Output = "0"; } } paramCount = paramCount + 1; } else if (item.Function == "ErrorsWarnings") { ErrorsWarnings Errors = new ErrorsWarnings(); ErrorsWarnings parameters = (ErrorsWarnings)javaScriptSerializer.Deserialize(jparameters, typeof(ErrorsWarnings)); item.Name = parameters.Type; item.Output = parameters.String1; } else if (item.Function == "Comments") { Comments Errors = new Comments(); Comments parameters = (Comments)javaScriptSerializer.Deserialize(jparameters, typeof(Comments)); item.Output = parameters.String1; } else if (item.Function == "Period") { DateFunctions DateFunctions = new DateFunctions(); Period Periods = new Period(); try { item.Output = Periods.Output(jparameters, jCategory, group.ID, item.ID); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } } else if (item.Function == "Factors") { Factors Factors = new Factors(); Factors parameters = (Factors)javaScriptSerializer.Deserialize(jparameters, typeof(Factors)); try { item.Output = Factors.Output(jparameters, jCategory, group.ID, item.ID); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } item.Type = parameters.OutputType; } else if (item.Function == "DateAdjustment") { Dates Dates = new Dates(); try { item.Output = Dates.Output(jparameters, jCategory, group.ID, item.ID); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } } else if (item.Function == "DatePart") { DatePart DateParts = new DatePart(); try { item.Output = DateParts.Output(jparameters, jCategory, group.ID, item.ID); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } } else if (item.Function == "MathsFunctions") { MathsFunctions MathsFunctions = new MathsFunctions(); try { item.Output = MathsFunctions.Output(jparameters, jCategory, group.ID, item.ID); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } } else if (item.Function == "ArrayFunctions") { ArrayFunctions ArrayFunctions = new ArrayFunctions(); ArrayFunctions parameters = (ArrayFunctions)javaScriptSerializer.Deserialize(jparameters, typeof(ArrayFunctions)); try { item.Output = ArrayFunctions.Output(jparameters, jCategory, group.ID, item.ID); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } if(parameters.Function == "Count") { item.Type = "Decimal"; } else { item.Type = parameters.LookupType; } } else if (item.Function == "StringFunctions") { StringFunctions StringFunctions = new StringFunctions(); StringFunctions parameters = (StringFunctions)javaScriptSerializer.Deserialize(jparameters, typeof(StringFunctions)); try { item.Output = StringFunctions.Output(jparameters, jCategory, group.ID, item.ID); } catch (Exception ex) { logger.Error(ex); throw new HttpException(ex.ToString()); } if(parameters.Type == "Len") { item.Type = "Decimal"; } else { item.Type = "String"; } } } //Expected results on the builder this sets the required ones if (item.ExpectedResult == null || item.ExpectedResult == "") { item.Pass = "******"; } else if (item.ExpectedResult == item.Output) { item.Pass = "******"; } else { item.Pass = "******"; } OutputList.Add(new OutputList { ID = Convert.ToString(item.ID), Field = item.Name, Value = item.Output, Group = group.Name }); } else { //Ignores the row if logic is not met dynamic LogicReplace = Config.VariableReplace(jCategory, item.Name, group.ID, item.ID); if(Convert.ToString(LogicReplace) == Convert.ToString(item.Name)) { item.Output = null; } else { item.Output = Convert.ToString(LogicReplace); } item.Pass = "******"; OutputList.Add(new OutputList { ID = Convert.ToString(item.ID), Field = item.Name, Value = item.Output, Group = group.Name }); } } } } } }
public async Task SplitRide(int rideId, long timestamp) { var ride = await GetByIdFull(rideId); if (!(ride is Ride)) { throw new ArgumentException("Invalid ride"); } var timeFrom = DateFunctions.UnixTimeToDateTime(timestamp); var pingsAfterSplit = ride.Pings.Where(p => p.Time > timeFrom).OrderBy(p => p.Time); // New ride var newRide = new Ride() { TimeFrom = timeFrom, TimeTo = ride.TimeTo, }; Insert(newRide); await db.SaveChangesAsync(); // New day var newDay = new Day() { TimeFrom = timeFrom, TimeTo = ride.Day.TimeTo, RideId = newRide.Id }; db.Add(newDay); await db.SaveChangesAsync(); // Cut off old day & ride ride.Day.TimeTo = timeFrom.AddSeconds(-1); ride.TimeTo = timeFrom.AddSeconds(-1); Update(ride); db.Attach(ride.Day); await db.SaveChangesAsync(); // Move pings to new day & ride foreach (var ping in pingsAfterSplit) { ping.RideId = newRide.Id; ping.DayId = newDay.Id; db.Attach(ping); } await db.SaveChangesAsync(); // Get rides from DB to reset distance. ride = await GetByIdFull(ride.Id); newRide = await GetByIdFull(newRide.Id); ride.ResetDistance(); newRide.ResetDistance(); Update(ride); Update(newRide); await db.SaveChangesAsync(); }
/// <summary>Outputs Date Adjustment function is used, includes the array builder. /// <para>jparameters = JSON congifurations relating to this function</para> /// <para>jCategory = the whole configuration which is required to do the variable replace</para> /// <para>GroupID = current Group ID</para> /// <para>ItemID = current row ID</para> /// </summary> public string Output(string jparameters, List <CategoryViewModel> jCategory, int GroupID, int ItemID) { JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); CalculationCSharp.Areas.Configuration.Models.ConfigFunctions Config = new CalculationCSharp.Areas.Configuration.Models.ConfigFunctions(); DateFunctions DatesFunctions = new DateFunctions(); ArrayBuildingFunctions ArrayBuilder = new ArrayBuildingFunctions(); Dates parameters = (Dates)javaScriptSerializer.Deserialize(jparameters, typeof(Dates)); if (parameters.Type == "Today") { return(DateTime.Now.ToShortDateString()); } string[] Date1parts = null; string[] Date2parts = null; //Returns array Date1parts = ArrayBuilder.InputArrayBuilder(parameters.Date1, jCategory, GroupID, ItemID); Date2parts = ArrayBuilder.InputArrayBuilder(parameters.Date2, jCategory, GroupID, ItemID); string Output = null; int Counter = 0; //Gets Max Length of array so loops through all values int MaxLength = ArrayBuilder.GetMaxLength(Date1parts, Date2parts); //Loop through the array to calculate each value in array for (int i = 0; i < MaxLength; i++) { dynamic InputA = null; dynamic InputB = null; //Gets the current array to use in the loop InputA = ArrayBuilder.GetArrayPart(Date1parts, Counter); InputB = ArrayBuilder.GetArrayPart(Date2parts, Counter); dynamic InputC = Config.VariableReplace(jCategory, parameters.Period, GroupID, ItemID); DateTime Date1; DateTime Date2; Decimal Period; //Data output checker if (InputA != null) { DateTime.TryParse(InputA, out Date1); } else { Date1 = Convert.ToDateTime("01/01/0001"); } if (InputB != null) { DateTime.TryParse(InputB, out Date2); } else { Date2 = Convert.ToDateTime("01/01/0001"); } Decimal.TryParse(InputC, out Period); string date = DatesFunctions.DateAdjustment(parameters.Type, Convert.ToString(Date1), Convert.ToString(Date2), parameters.PeriodType, Period, parameters.Adjustment, parameters.Day, parameters.Month); Output = Output + date + "~"; Counter = Counter + 1; } if (Output != null) { Output = Output.Remove(Output.Length - 1); } return(Convert.ToString(Output)); }
/// <summary>Outputs where Period function is used, includes the array builder. /// <para>jparameters = JSON congifurations relating to this function</para> /// <para>jCategory = the whole configuration which is required to do the variable replace</para> /// <para>GroupID = current Group ID</para> /// <para>ItemID = current row ID</para> /// </summary> public string Output(string jparameters, List<CategoryViewModel> jCategory, int GroupID, int ItemID) { JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); DateFunctions DateFunctions = new DateFunctions(); ArrayBuildingFunctions ArrayBuilder = new ArrayBuildingFunctions(); Period Dates = new Period(); Period parameters = (Period)javaScriptSerializer.Deserialize(jparameters, typeof(Period)); string[] Date1parts = null; string[] Date2parts = null; //Returns array Date1parts = ArrayBuilder.InputArrayBuilder(parameters.Date1, jCategory, GroupID, ItemID); Date2parts = ArrayBuilder.InputArrayBuilder(parameters.Date2, jCategory, GroupID, ItemID); string OutputValue = null; string Output = null; int Counter = 0; //Gets Max Length of array so loops through all values int MaxLength = ArrayBuilder.GetMaxLength(Date1parts, Date2parts); //Loop through the array to calculate each value in array for (int i = 0; i < MaxLength; i++) { dynamic InputA = null; dynamic InputB = null; InputA = ArrayBuilder.GetArrayPart(Date1parts, Counter); InputB = ArrayBuilder.GetArrayPart(Date2parts, Counter); Counter = Counter + 1; //Checks if Inputs are OK to proceed in using the calculation if (InputA != "" && InputB != "" && InputA != "01/01/0001" && InputB != "01/01/0001") { DateTime Date1; DateTime Date2; if (InputA != null) { DateTime.TryParse(InputA, out Date1); } else { Date1 = Convert.ToDateTime("01/01/0001"); } if (InputB != null) { DateTime.TryParse(InputB, out Date2); } else { Date2 = Convert.ToDateTime("01/01/0001"); } String DateAdjustmentType = parameters.DateAdjustmentType; Boolean Inclusive = parameters.Inclusive; Double DaysinYear = parameters.DaysinYear; //Calcuates the relevant period if (Date1 <= Date2) { if (DateAdjustmentType == "YearsDays") { OutputValue = Convert.ToString(DateFunctions.YearsDaysBetween(Date1, Date2, Inclusive, DaysinYear)); } else if (DateAdjustmentType == "YearsMonths") { OutputValue = Convert.ToString(DateFunctions.YearsMonthsBetween(Date1, Date2, Inclusive, DaysinYear)); } else if (DateAdjustmentType == "Years") { OutputValue = Convert.ToString(DateFunctions.YearsBetween(Date1, Date2, Inclusive, DaysinYear)); } else if (DateAdjustmentType == "Months") { OutputValue = Convert.ToString(DateFunctions.GetMonthsBetween(Date1, Date2, Inclusive)); } else if (DateAdjustmentType == "Days") { OutputValue = Convert.ToString(DateFunctions.DaysBetween(Date1, Date2, Inclusive, DaysinYear)); } else { OutputValue = "0"; } } else { OutputValue = Convert.ToString(0); } Output = Output + OutputValue + "~"; } else { OutputValue = Convert.ToString(0); Output = Output + OutputValue + "~"; } } if (Output != null) { Output = Output.Remove(Output.Length - 1); } return Output; }