void AfterLoad(MyData res, DateTime?start = null, DateTime?end = null) { Projects = res.Projects; settings = res.settings ?? new Settings(); user = res.user ?? new User(); if (start != null || end != null) { end = end ?? DateTime.Now.AddYears(5000); start = start ?? DateTime.Now.AddYears(-5000); foreach (var p in Projects) { for (int i = 0; i < p.Times.Count; i++) { if (p.Times[i].Start > end || p.Times[i].End < start) { p.Times.RemoveAt(i--); } } } } {// re-link foreach (var p in Projects) { if (p.LastBackup.Year < 1900) { p.LastBackup = new DateTime(1900, 1, 1); } if (p.LastBackup.Year > 3000) { p.LastBackup = new DateTime(1900, 1, 1); } foreach (var t in p.Times) { t.project = p; } } try { if (res.project != null) { project = GetByName(res.project.Name); } } catch { project = null; } try { resume_project_at_startup = GetByName(res.resume_project_at_startup?.Name ?? ""); } catch { resume_project_at_startup = null; } } var all_deactive = true; foreach (var p in Projects) { if (p.Active) { all_deactive = false; break; } } if (all_deactive) { foreach (var p in Projects) { p.Active = true; } } if (MyData.db == this && GetByType(hozoor: true) == null) { Projects.Add(new Project() { Name = "ورود-خروج" }); } #pragma warning disable 0612 /// for old versions ~3.3.2.22 //user.name = settings.real_name + ""; // if (settings.Server == "smalavi-pc") // settings.host = "192.168.1.1:90"; #pragma warning restore 0612 try { var coms = Environment.GetCommandLineArgs(); if (coms.Length > 2) { if (coms[1].ToLower() == "/host") { res.settings.host = coms[2]; } } } catch { } }
public string GetValue(MyData db, bool debug = false) { var str = ""; foreach (var c in Conditions) { var sum = 0; foreach (var p in db.Projects) { if (p.Active) { foreach (var t in p.Times) { if (c.Satisfy(t)) { sum += t.Duration.sec; } } } } str += "double " + c.Name + "=" + sum + ";//" + c.project + "\r\n"; } str += "double day=" + Utils.PersianDay(DateTime.Now) + ";\r\n"; if (output.Contains("return ")) { str += output + ";"; } else { str += "return " + output + ";"; } str = str.Replace("Round(", "Math.Round("); str = str.Replace("Floor(", "Math.Floor("); str = str.Replace("Ceiling(", "Math.Ceiling("); str = str.Replace("Abs(", "Math.Abs("); str = str.Replace("Sin(", "Math.Sin("); str = str.Replace("Cos(", "Math.Cos("); str = str.Replace("Tan(", "Math.Tan("); str = str.Replace("Min(", "Math.Min("); str = str.Replace("Max(", "Math.Max("); str = str.Replace("round(", "Math.Round("); str = str.Replace("floor(", "Math.Floor("); str = str.Replace("ceiling(", "Math.Ceiling("); str = str.Replace("abs(", "Math.Abs("); str = str.Replace("sin(", "Math.Sin("); str = str.Replace("cos(", "Math.Cos("); str = str.Replace("tan(", "Math.Tan("); str = str.Replace("min(", "Math.Min("); str = str.Replace("max(", "Math.Max("); str = str.Replace(".str()", ".ToString(\"0.##\")"); str = str.Replace("Math.Math.", "Math."); if (debug) { MessageBox.Show(str); } var v = RunCompiler(str); if (v is double || v is int) { if (type == Type.ساعت) { return(new TSpan(Convert.ToInt32(v)) + ""); } else if (type == Type.درصد) { return((100 * Convert.ToDouble(v)).ToString("0.0#") + " %"); } else { return(Convert.ToDouble(v).ToString("0.00#")); } } else { return(v.ToString()); } }