diff --git a/ad-automation/Form1.cs b/ad-automation/Form1.cs index 8674e61..c4f5251 100644 --- a/ad-automation/Form1.cs +++ b/ad-automation/Form1.cs @@ -21,16 +21,16 @@ public partial class adForm : Form string advertPath = ""; string promoPath = ""; string targetPath = ""; - DateTime nextMonday; public static List allAdverts = new List(); public static List adsToPlayPerDay = new List(); // List of adverts by number of plays needed public static List allPromos = new List(); + public static List allPromosWeighted = new List(); List allBreaksList = new List(); public static List thisBreak = new List(); public static List lastBreak = new List(); public static List thisBreakKeywords = new List(); public bool advertDateHasBeenSet = false; - + public static string jingleStudioPathValue { get; private set; } public adForm() @@ -38,6 +38,7 @@ public adForm() InitializeComponent(); DateTime tomorrow = DateTime.Today.AddDays(1); createBreaksForPicker.Value = tomorrow; + loadAdvertBreaksFromDate(); } private void button1_Click(object sender, EventArgs e) @@ -107,7 +108,7 @@ private void canGenerateButtonBeDisabled() private void generateBreaksButton_Click(object sender, EventArgs e) { - createTargetDirectory(); + createTargetDirectory(createBreaksForPicker.Value); createBreaks(); jingleStudioPathValue = jinglesStudioPath.Text; progressBar1.Minimum = 0; @@ -124,6 +125,7 @@ private void generateBreaksButton_Click(object sender, EventArgs e) outputLog(); fileBeingGeneratedLabel.Text = "Done"; Process.Start(targetPath); // Opens Windows Explorer to output directory + Application.Exit(); } private void outputLog() @@ -188,8 +190,8 @@ public static promo selectPromo(DateTime breakTargetTime) private static promo choosePromoAtRandom() { Random rnd = new Random(); - int numericRnd = rnd.Next(0, allPromos.Count); - return allPromos[numericRnd]; + int numericRnd = rnd.Next(0, allPromosWeighted.Count); + return allPromosWeighted[numericRnd]; } private static advert chooseAdvertAtRandom() @@ -201,13 +203,11 @@ private static advert chooseAdvertAtRandom() } - private void createTargetDirectory() + private void createTargetDirectory(DateTime breakDate) { - string dateTime = DateTime.Now.ToString(); - dateTime = dateTime.Replace("/", ""); - dateTime = dateTime.Replace(" ", ""); - dateTime = dateTime.Replace(":", ""); - targetPath = targetPath + "\\" + dateTime; + string dateTime = DateTime.Now.ToString("yyyyMMddHHmmss"); + string breakDateStr = breakDate.ToString("dd-MMM-yyyy"); + targetPath = targetPath + "\\Adverts for " + breakDateStr + " - Created " + dateTime; Directory.CreateDirectory(targetPath); } @@ -252,16 +252,22 @@ private void getPromosInFolder(string folderPath) tmpPromo.addToPromoTablePanel(promoTableLayoutPanel); // Add promo mulitple times depending on priorities to weight the probabilityu of it being chosen allPromos.Add(tmpPromo); + allPromosWeighted.Add(tmpPromo); if (tmpPromo.priority < 3) { - allPromos.Add(tmpPromo); - allPromos.Add(tmpPromo); + allPromosWeighted.Add(tmpPromo); + allPromosWeighted.Add(tmpPromo); + allPromosWeighted.Add(tmpPromo); } if (tmpPromo.priority < 2) { - allPromos.Add(tmpPromo); - allPromos.Add(tmpPromo); - allPromos.Add(tmpPromo); + allPromosWeighted.Add(tmpPromo); + allPromosWeighted.Add(tmpPromo); + allPromosWeighted.Add(tmpPromo); + allPromosWeighted.Add(tmpPromo); + allPromosWeighted.Add(tmpPromo); + allPromosWeighted.Add(tmpPromo); + allPromosWeighted.Add(tmpPromo); } } } @@ -275,6 +281,12 @@ private void adForm_Load(object sender, EventArgs e) } private void createBreaksForPicker_ValueChanged(object sender, EventArgs e) + { + loadAdvertBreaksFromDate(); + } + + + private void loadAdvertBreaksFromDate() { DateTime breakDate = createBreaksForPicker.Value.Date; string[] breaksOnDay = new string[] { "Select the day to set advert times" }; @@ -292,6 +304,7 @@ private void createBreaksForPicker_ValueChanged(object sender, EventArgs e) advertDateHasBeenSet = true; canGenerateButtonBeDisabled(); } + } }