Example #1
0
 private void InitDay()
 {
     this.ProgramActivities.Clear();
     DateTime programActivityTime = this.StartTime;
     do
     {
         ProgramActivity programActivity = new ProgramActivity(this, programActivityTime);
         ApplyPrograms(programActivity);
         this.ProgramActivities.Add(programActivity);
         programActivityTime = programActivityTime.AddMinutes(30);
     }
     while (!(programActivityTime.Hour == 5 && programActivityTime.Minute == 0));
 }
Example #2
0
 private void ApplyPrograms(ProgramActivity programActivity)
 {
     foreach (Program program in this.Station.Programs)
         if (program.ContainsGivenTime(programActivity.Time))
         {
             programActivity.Program = program.Name;
             programActivity.ProgramLink = program.Id;
             programActivity.Type = program.Type;
             programActivity.FCC = program.FCC;
             programActivity.HouseNumber = program.HouseNumber;
             programActivity.MovieTitle = program.MovieTitle;
             programActivity.Distributor = program.Distributor;
             programActivity.ContractLength = program.ContractLength;
             programActivity.CustomNote = program.CustomNote;
         }
 }
		public void GenerateActivityListReport(ProgramActivity[] activities, bool convertToPDF)
		{
			if (!Directory.Exists(OutputFolder))
				Directory.CreateDirectory(OutputFolder);
			var destinationPath = Path.Combine(OutputFolder, String.Format("{0}.{1}", DateTime.Now.ToString("MMddyy-hhmmtt"), convertToPDF ? "pdf" : "xls"));
			ProgramScheduleReportHelper.GenerateActivityList(
				ReporActivityListTemplatePath,
				activities,
				destinationPath,
				convertToPDF);
			if (File.Exists(destinationPath))
				Utils.OpenFile(destinationPath);
		}
Example #4
0
        private void Load()
        {
            this.ProgramActivities.Clear();
            if (File.Exists(this.DataFilePath))
            {
                XmlDocument document = new XmlDocument();

                document.Load(this.DataFilePath);

                XmlNode node = document.SelectSingleNode(@"/Programs");
                if (node != null)
                {
                    foreach (XmlNode childNode in node.ChildNodes)
                    {
                        ProgramActivity programActivity = new ProgramActivity(this);
                        programActivity.Deserialize(childNode);
                        if (this.Station.Programs.Where(x => x.Id.Equals(programActivity.ProgramLink)).Count() == 0 && !programActivity.ProgramLink.Equals(Guid.Empty))
                            programActivity.Clear();
                        ApplyPrograms(programActivity);
                        this.ProgramActivities.Add(programActivity);
                    }
                }
                if (this.ProgramActivities.Count == 0)
                {
                    InitDay();
                    Save();
                }
            }
            else
            {
                InitDay();
                Save();
            }
            this.ProgramActivities.Sort((x, y) => x.Time.CompareTo(y.Time));
            this.DataNotSaved = false;
        }
Example #5
0
 public void AddProgramActivity(ProgramActivity programActivity)
 {
     ProgramActivity existedProgramActivity = this.ProgramActivities.Where(x => x.Time.Year.Equals(programActivity.Time.Year) && x.Time.Month.Equals(programActivity.Time.Month) && x.Time.Day.Equals(programActivity.Time.Day) && x.Time.Hour.Equals(programActivity.Time.Hour) && x.Time.Minute.Equals(programActivity.Time.Minute)).FirstOrDefault();
     if (existedProgramActivity != null)
     {
         existedProgramActivity.Program = programActivity.Program;
         existedProgramActivity.ProgramLink = programActivity.ProgramLink;
         existedProgramActivity.Episode = programActivity.Episode;
         existedProgramActivity.Type = programActivity.Type;
         existedProgramActivity.FCC = programActivity.FCC;
         existedProgramActivity.HouseNumber = programActivity.HouseNumber;
         existedProgramActivity.MovieTitle = programActivity.MovieTitle;
         existedProgramActivity.Distributor = programActivity.Distributor;
         existedProgramActivity.ContractLength = programActivity.ContractLength;
         existedProgramActivity.CustomNote = programActivity.CustomNote;
     }
     else
     {
         this.ProgramActivities.Add(programActivity);
         this.ProgramActivities.Sort((x, y) => x.Time.CompareTo(y.Time));
     }
     this.DataNotSaved = true;
 }
Example #6
0
        private void LoadDataFromOldFormat()
        {
            DateTime tempDate;
            int tempInt;

            string filePath = Path.Combine(this.RootFolderPath, "olddata.xml");
            Day fakeDay = new Day(this, DateTime.Now);
            List<ProgramActivity> programActivities = new List<ProgramActivity>();

            if (File.Exists(filePath))
            {
                XmlDocument document = new XmlDocument();

                document.Load(filePath);

                XmlNode node = document.SelectSingleNode(@"/RECORDS");
                if (node != null)
                {
                    foreach (XmlNode recordNode in node.ChildNodes)
                    {
                        ProgramActivity programActivity = new ProgramActivity(fakeDay);
                        foreach (XmlNode rowNode in recordNode.ChildNodes)
                        {
                            foreach (XmlAttribute attribute in rowNode.Attributes)
                            {
                                switch (attribute.Name)
                                {
                                    case "PROG_DATE":
                                        if (DateTime.TryParseExact(attribute.Value, "yyyyMMdd", new System.Globalization.CultureInfo("en-us"), System.Globalization.DateTimeStyles.None, out tempDate))
                                            programActivity.Time = tempDate;
                                        break;
                                    case "PROG_SO":
                                        if (int.TryParse(attribute.Value, out tempInt))
                                            programActivity.Time = new DateTime(programActivity.Time.Year, programActivity.Time.Month, programActivity.Time.Day, 5, 0, 0).AddMinutes(30 * (tempInt - 1));
                                        break;
                                    case "PROG_PROG":
                                        programActivity.Program = attribute.Value;
                                        break;
                                    case "PROG_LSN":
                                        programActivity.Type = attribute.Value;
                                        break;
                                    case "PROG_EPI":
                                        programActivity.Episode = attribute.Value;
                                        break;
                                }
                            }
                        }
                        if (programActivity.Time.Year >= 2012 && programActivity.Time.Year <= 2015)
                            programActivities.Add(programActivity);
                    }
                }
                if (programActivities.Count > 1)
                {
                    string programName = string.Empty;
                    foreach (ProgramActivity programActivity in programActivities)
                    {
                        if (!string.IsNullOrEmpty(programActivity.Program))
                            programName = programActivity.Program;
                        else if (!string.IsNullOrEmpty(programActivity.Type))
                            programActivity.Program = programName;
                    }

                    DateTime minDate = programActivities.Select(x => x.Time).Min();
                    DateTime maxDate = programActivities.Select(x => x.Time).Max();
                    while (minDate < maxDate)
                    {
                        Day day = new Day(this, minDate);
                        day.AddProgramActivityRange(programActivities.Where(x => x.Time >= day.StartTime && x.Time < day.EndTime).ToArray());
                        day.Save();
                        minDate = minDate.AddDays(1);
                    }
                }
            }
        }
Example #7
0
 public void ApplyProgram(Program program)
 {
     Day lastCreatedDay = this.Days.LastOrDefault();
     DateTime[] programProgramActivityDates = program.GetUsedTimes(lastCreatedDay.Date.AddDays(1));
     foreach (Day day in this.Days)
     {
         foreach (DateTime time in programProgramActivityDates.Where(x => x >= day.StartTime && x <= day.EndTime))
         {
             ProgramActivity programActivity = new ProgramActivity(day, time);
             programActivity.ProgramLink = program.Id;
             programActivity.Program = program.Name;
             programActivity.Type = program.Type;
             programActivity.FCC = program.FCC;
             programActivity.HouseNumber = program.HouseNumber;
             programActivity.MovieTitle = program.MovieTitle;
             programActivity.Distributor = program.Distributor;
             programActivity.ContractLength = program.ContractLength;
             programActivity.CustomNote = program.CustomNote;
             day.AddProgramActivity(programActivity);
         }
     }
 }
		public static void GenerateActivityList(
			string templatePath,
			ProgramActivity[] activities,
			string destinationFilePath,
			bool convertToPDF)
		{
			if (!File.Exists(templatePath) || !ExcelHelper.Instance.Connect()) return;
			try
			{
				var sourceWorkBook = ExcelHelper.Instance.ExcelObject.Workbooks.Open(templatePath);
				Worksheet workSheet = sourceWorkBook.Worksheets["Program Activities"];

				var start = activities.First().Time;
				var end = activities.Last().Time;
				var title = string.Format("Program Activity For {0}", activities.First().Day.Station.Name);
				var dateRange = string.Format("Between {0} and {1} from {2} to {3}", start.ToString("MM/dd/yyyy"), end.ToString("MM/dd/yyyy"), start.ToString("hh:mmtt"), end.ToString("hh:mmtt"));
				workSheet.PageSetup.CenterHeader = "&12&B" + title + (char)13 + dateRange;

				var sheduleGenrated = DateTime.Now;
				workSheet.PageSetup.CenterFooter = "&11Generated" + (char)13 + sheduleGenrated.ToString("MM/dd/yy h:mm tt");

				var range = workSheet.Range["Date"];
				var firstRow = range.Row + 1;
				var lastRow = firstRow;
				var firstColumn = range.Column;
				range = workSheet.Range["Type"];
				var lastColumn = range.Column;

				var rows = new List<object[]>();
				foreach (var activity in activities)
				{
					var cells = new List<object>();
					cells.Add(activity.Date.ToString("MM/dd/yyyy"));
					cells.Add(activity.Date.ToString("ddd"));
					cells.Add(activity.Time.ToString("hh:mmtt"));
					cells.Add(activity.Program);
					cells.Add(activity.HouseNumber);
					cells.Add(activity.Episode);
					cells.Add(activity.Type);
					rows.Add(cells.ToArray());
					lastRow++;
				}
				if (lastRow > firstRow)
					lastRow--;

				if (rows.Count > 0)
				{
					var values = new object[rows.Count, rows[0].Length];
					for (var i = 0; i < rows.Count; i++)
						for (int j = 0; j < rows[0].Length; j++)
							values[i, j] = rows[i][j];

					range = workSheet.Range[GetColumnLetterByIndex(firstColumn) + firstRow + ":" + GetColumnLetterByIndex(lastColumn) + lastRow];
					range.Value2 = values;
					range.Rows.AutoFit();
					range.Borders[XlBordersIndex.xlEdgeBottom].LineStyle = XlLineStyle.xlContinuous;
					range.Borders[XlBordersIndex.xlEdgeLeft].LineStyle = XlLineStyle.xlContinuous;
					range.Borders[XlBordersIndex.xlEdgeRight].LineStyle = XlLineStyle.xlContinuous;
					range.Borders[XlBordersIndex.xlEdgeTop].LineStyle = XlLineStyle.xlContinuous;
					range.Borders[XlBordersIndex.xlInsideHorizontal].LineStyle = XlLineStyle.xlContinuous;
					range.Borders[XlBordersIndex.xlInsideVertical].LineStyle = XlLineStyle.xlContinuous;

					if (convertToPDF)
						sourceWorkBook.ExportAsFixedFormat(Filename: destinationFilePath, Type: XlFixedFormatType.xlTypePDF);
					else
						sourceWorkBook.SaveAs(destinationFilePath, XlFileFormat.xlWorkbookNormal);
				}

				sourceWorkBook.Close();
			}
			catch { }
			finally
			{
				ExcelHelper.Instance.Disconnect();
			}
		}