public void SetEndDate(DateTime date) { if (numberOfCrops == 0) { if (date != endDate) { if (NotSavedEvent != null) { NotSavedEvent(); } } if (BeginDate.AddMonths(3) < date) { date = date.AddMonths(3); } endDate = date; totalWeeks = GetNumberOfWeeks(); dateChanged(); } }
public PromotionQueryModel() { BeginDate = DateTime.Now.Date; EndDate = BeginDate.AddMonths(1); PromotionStatusType = -1; }
string GetChartXMLFile(string unit) { string filename = "chart_" + unit + "_" + BeginDate.ToString("yyyyMMdd") + "_" + EndDate.ToString("yyyyMMdd") + ".xml"; string path = Server.MapPath("~/_temp/chart"); string fileUrl = ""; if (File.Exists(Path.Combine(path, filename))) { fileUrl = "/_temp/chart/" + filename; } else { if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string strHead = @"<graph xaxisname=""{0}"" yaxisname=""访问量"" hovercapbg=""DEDEBE"" hovercapborder=""889E6D"" baseFontSize='12' rotateNames=""0"" numdivlines=""9"" divLineColor=""CCCCCC"" divLineAlpha=""80"" decimalPrecision=""0"" showAlternateHGridColor=""1"" AlternateHGridAlpha=""30"" AlternateHGridColor=""CCCCCC"" bgcolor='fbfbfb' caption=""{1}"" subcaption=""{2}"">"; switch (unit) { case "hour": using (FileStream fs = File.Open(Path.Combine(path, filename), FileMode.CreateNew, FileAccess.Write)) { using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8)) { sw.WriteLine(string.Format(strHead, "小时", BeginDate.ToString("yyyy-MM-dd") + " 24小时流量图", "")); sw.WriteLine("<categories font=\"Arial\" fontSize=\"12\" fontColor=\"000000\">"); for (int i = 0; i <= 24; i++) { sw.WriteLine(string.Format("<category name=\"{0}\" hoverText=\"{0}点\"/>", i)); } sw.WriteLine("</categories>"); sw.WriteLine("<dataset seriesname=\"访客数\" color=\"FDC12E\">"); for (int i = 0; i <= 24; i++) { DateTime startTime = BeginDate.AddDays(-1).AddHours(i); DateTime endTime = startTime.AddHours(1); sw.WriteLine(string.Format("<set value=\"{0}\"/>", PageVisitorHelper.GetPVCountByTime(startTime, endTime))); } sw.WriteLine("</dataset>"); sw.WriteLine("<dataset seriesname=\"访客数\" color=\"56B9F9\">"); for (int i = 0; i <= 24; i++) { DateTime startTime = BeginDate.AddDays(-1).AddHours(i); DateTime endTime = startTime.AddHours(1); sw.WriteLine(string.Format("<set value=\"{0}\"/>", PageVisitorHelper.GetVisitorCountByTime(startTime, endTime))); } sw.WriteLine("</dataset>"); sw.WriteLine("</graph>"); sw.Flush(); } } fileUrl = "/_temp/chart/" + filename; break; case "day": using (FileStream fs = File.Open(Path.Combine(path, filename), FileMode.CreateNew, FileAccess.Write)) { using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8)) { sw.WriteLine(string.Format(strHead, "天", "流量曲线图", BeginDate.ToString("yyyy-MM-dd") + " 到 " + EndDate.ToString("yyyy-MM-dd"))); sw.WriteLine("<categories font=\"Arial\" fontSize=\"11\" fontColor=\"000000\">"); TimeSpan ts = EndDate - BeginDate; int days = ts.Days; for (int i = 0; i <= days; i++) { sw.WriteLine(string.Format("<category name=\"{0}\" />", BeginDate.AddDays(i).Day)); } sw.WriteLine("</categories>"); sw.WriteLine("<dataset seriesname=\"访客数\" color=\"FDC12E\">"); for (int i = 0; i <= days; i++) { DateTime startTime = BeginDate.AddDays(i); DateTime endTime = startTime.AddDays(1); sw.WriteLine(string.Format("<set value=\"{0}\"/>", PageVisitorHelper.GetPVCountByTime(startTime, endTime))); } sw.WriteLine("</dataset>"); sw.WriteLine("<dataset seriesname=\"访客数\" color=\"56B9F9\">"); for (int i = 0; i <= days; i++) { DateTime startTime = BeginDate.AddDays(i); DateTime endTime = startTime.AddDays(1); sw.WriteLine(string.Format("<set value=\"{0}\"/>", PageVisitorHelper.GetVisitorCountByTime(startTime, endTime))); } sw.WriteLine("</dataset>"); sw.WriteLine("</graph>"); sw.Flush(); } } fileUrl = "/_temp/chart/" + filename; break; case "month": using (FileStream fs = File.Open(Path.Combine(path, filename), FileMode.CreateNew, FileAccess.Write)) { using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8)) { sw.WriteLine(string.Format(strHead, "月", "流量曲线图", BeginDate.ToString("yyyy-MM") + " 到 " + EndDate.ToString("yyyy-MM"))); sw.WriteLine("<categories font=\"Arial\" fontSize=\"11\" fontColor=\"000000\">"); TimeSpan ts = EndDate - BeginDate; int months = (int)(ts.TotalDays / 30); for (int i = 0; i <= months; i++) { sw.WriteLine(string.Format("<category name=\"{0}\" hoverText=\"{0}月\"/>", BeginDate.AddMonths(i).Month)); } sw.WriteLine("</categories>"); sw.WriteLine("<dataset seriesname=\"访客数\" color=\"FDC12E\">"); for (int i = 0; i <= months; i++) { DateTime startTime = BeginDate.AddMonths(i); DateTime endTime = startTime.AddMonths(1); sw.WriteLine(string.Format("<set value=\"{0}\"/>", PageVisitorHelper.GetPVCountByTime(startTime, endTime))); } sw.WriteLine("</dataset>"); sw.WriteLine("<dataset seriesname=\"访客数\" color=\"56B9F9\">"); for (int i = 0; i <= months; i++) { DateTime startTime = BeginDate.AddMonths(i); DateTime endTime = startTime.AddMonths(1); sw.WriteLine(string.Format("<set value=\"{0}\"/>", PageVisitorHelper.GetVisitorCountByTime(startTime, endTime))); } sw.WriteLine("</dataset>"); sw.WriteLine("</graph>"); sw.Flush(); } } fileUrl = "/_temp/chart/" + filename; break; } } return(fileUrl); }