Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Working, with separate source date.

  • Loading branch information...
commit 3b2dd9135e2d35a024039082e879120d494c1df9 0 parents
@BDizzle BDizzle authored
Showing with 376 additions and 0 deletions.
  1. +83 −0 Default.aspx
  2. +253 −0 Default.aspx.cs
  3. +40 −0 Web.Config
83 Default.aspx
@@ -0,0 +1,83 @@
+<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" >
+<head runat="server">
+ <title>Untitled Page</title>
+</head>
+<body>
+ <form id="form1" runat="server">
+ <div>
+ <asp:Wizard ID="SuperCopyWizard" runat="server" ActiveStepIndex="0" Height="508px" Width="655px" OnNextButtonClick="SuperCopyWizard_NextButtonClick">
+ <WizardSteps>
+ <asp:WizardStep runat="server" Title="Step 1" ID="Step1">
+ Please select a Channel<br />
+ <asp:DropDownList ID="uxChannel" runat="server">
+ </asp:DropDownList>
+ </asp:WizardStep>
+ <asp:WizardStep runat="server" Title="Step 2" ID="Step2">
+ Current Channel:<br />
+ <asp:Label ID="uxCurrentChannel" runat="server" Text="None"></asp:Label>
+ <br />
+ <br />
+ Please select the source day:<br />
+ <asp:Calendar ID="uxSourceDate" runat="server" OnSelectionChanged="uxSourceDate_SelectionChanged">
+ <SelectedDayStyle BackColor="Navy" />
+ </asp:Calendar>
+ <br />
+ <asp:Label ID="uxNumberOfSourceRuns" runat="server" Text="Please select a source day to continue."></asp:Label>
+ </asp:WizardStep>
+ <asp:WizardStep runat="server" Title="Step 3" ID="Step3">
+ Please select destination dates<br />
+ <br />
+ Start:<br />
+ <asp:Calendar ID="uxStartDate" runat="server" OnSelectionChanged="uxStartDate_SelectionChanged">
+ <TodayDayStyle BackColor="Silver" />
+ <SelectedDayStyle BackColor="Navy" />
+ </asp:Calendar>
+ <asp:Label ID="uxStartDateError" runat="server" ForeColor="Red"></asp:Label>
+ <br />
+ <br />
+ <br />
+ End:<asp:Calendar ID="uxEndDate" runat="server" OnSelectionChanged="uxEndDate_SelectionChanged">
+ <TodayDayStyle BackColor="Silver" />
+ <SelectedDayStyle BackColor="Navy" />
+ </asp:Calendar>
+ <asp:Label ID="uxEndDateError" runat="server" ForeColor="Red"></asp:Label>
+ <br />
+ <br />
+ <asp:Label ID="uxDateCount" runat="server"></asp:Label>
+ <br />
+ </asp:WizardStep>
+ <asp:WizardStep ID="Step4" runat="server" Title="Step 4">
+ SuperCopy is ready to run.<br />
+ <br />
+ You are about to copy the programing on
+ <asp:Label ID="uxSourceDateName" runat="server"></asp:Label>
+ on
+ <asp:Label ID="uxChannelName1" runat="server"></asp:Label>
+ .<br />
+ <br />
+ The programing on
+ <asp:Label ID="uxChannelName2" runat="server"></asp:Label>
+ &nbsp;will be deleted, and replaced, from
+ <asp:Label ID="uxDestStartDate" runat="server"></asp:Label>
+ &nbsp;to
+ <asp:Label ID="uxDestEndDate" runat="server"></asp:Label>
+ .<br />
+ <br />
+ If you are sure you want to do this, press Next</asp:WizardStep>
+ <asp:WizardStep ID="Step5" runat="server" Title="Confirm">
+ Removed
+ <asp:Label ID="uxRemovedRunCount" runat="server"></asp:Label>
+ &nbsp;runs from the schedule.</asp:WizardStep>
+ </WizardSteps>
+ <HeaderTemplate>
+ Welcome to SuperCopy
+ </HeaderTemplate>
+ </asp:Wizard>
+ &nbsp;</div>
+ </form>
+</body>
+</html>
253 Default.aspx.cs
@@ -0,0 +1,253 @@
+using System;
+using System.Data;
+using System.Configuration;
+using System.Web;
+using System.Web.Security;
+using System.Web.UI;
+using System.Web.UI.WebControls;
+using System.Web.UI.WebControls.WebParts;
+using System.Web.UI.HtmlControls;
+
+public partial class _Default : System.Web.UI.Page
+{
+ private bool m_SuppressDateChangeEvent = false;
+
+ protected void Page_Load(object sender, EventArgs e)
+ {
+ PopulateChannelList();
+ }
+
+ private void PopulateChannelList()
+ {
+ System.Data.SqlClient.SqlConnection SqlConn = new System.Data.SqlClient.SqlConnection();
+ System.Data.SqlClient.SqlDataReader SqlDr = null;
+
+ try
+ {
+ SqlConn.ConnectionString = "Data Source=(local);Initial Catalog=Cablecast40;Integrated Security=SSPI;Persist Security Info=False;Packet Size=4096";
+ SqlConn.Open();
+
+ //Get the channels from the database
+ System.Data.SqlClient.SqlCommand SqlCmd
+ = new System.Data.SqlClient.SqlCommand(
+ "SELECT * FROM stChannels;", SqlConn);
+
+ //set data reader
+ SqlDr = SqlCmd.ExecuteReader();
+
+ uxChannel.Items.Clear();
+
+ while (SqlDr.Read())
+ {
+ ListItem Item = new ListItem((string)SqlDr["ChannelName"], (SqlDr["ChannelID"]).ToString());
+ uxChannel.Items.Add(Item);
+ }
+ }
+ catch(Exception exc)
+ {
+ }
+ }
+
+ protected void SuperCopyWizard_NextButtonClick(object sender, WizardNavigationEventArgs e)
+ {
+ if(SuperCopyWizard.ActiveStepIndex == 0)
+ uxCurrentChannel.Text = uxChannel.SelectedItem.Text;
+
+ if (SuperCopyWizard.ActiveStepIndex == 2)
+ {
+ uxChannelName1.Text = uxChannel.SelectedItem.Text;
+ uxChannelName2.Text = uxChannel.SelectedItem.Text;
+ uxSourceDateName.Text = uxSourceDate.SelectedDate.ToShortDateString();
+ uxDestStartDate.Text = uxStartDate.SelectedDate.ToShortDateString();
+ uxDestEndDate.Text = uxEndDate.SelectedDate.ToShortDateString();
+ }
+
+ if (SuperCopyWizard.ActiveStepIndex == 3)
+ {
+ int RemovedRuns =
+ ClearSchedule(
+ int.Parse(uxChannel.SelectedValue),
+ uxStartDate.SelectedDate,
+ uxEndDate.SelectedDate);
+
+ uxRemovedRunCount.Text = RemovedRuns.ToString();
+
+ int AddedRuns =
+ CopySchedule(
+ int.Parse(uxChannel.SelectedValue),
+ uxSourceDate.SelectedDate,
+ uxStartDate.SelectedDate,
+ uxEndDate.SelectedDate);
+ }
+ }
+
+
+
+ private int ClearSchedule(int channelID, DateTime startDate, DateTime endDate)
+ {
+ int result = 0;
+
+ using(System.Data.SqlClient.SqlConnection SqlConn = new System.Data.SqlClient.SqlConnection())
+ {
+ SqlConn.ConnectionString = "Data Source=(local);Initial Catalog=Cablecast40;Integrated Security=SSPI;Persist Security Info=False;Packet Size=4096";
+ SqlConn.Open();
+
+ string sql = @"
+ DELETE FROM schedule
+ WHERE channelID = " + channelID + @"
+ AND runDateTime >= DATEADD(dd,0, datediff(dd,0,'" + startDate.ToShortDateString() + @"'))
+ AND runDateTime <= DATEADD([day],1, dateadd(dd,0, datediff(dd,0,'" + endDate.ToShortDateString() + @"')))";
+
+ System.Data.SqlClient.SqlCommand sqlCmd = new System.Data.SqlClient.SqlCommand(sql, SqlConn);
+
+ result = sqlCmd.ExecuteNonQuery();
+ }
+
+ return result;
+ }
+
+ private int CopySchedule(int channelID, DateTime sourceDay, DateTime startDate, DateTime endDate)
+ {
+ int result = 0;
+
+ using (System.Data.SqlClient.SqlConnection SqlConn = new System.Data.SqlClient.SqlConnection())
+ {
+ SqlConn.ConnectionString = "Data Source=(local);Initial Catalog=Cablecast40;Integrated Security=SSPI;Persist Security Info=False;Packet Size=4096";
+ SqlConn.Open();
+
+ int numberOfDays = (int)((endDate - startDate).TotalDays + 1);
+
+ for (int i = 1; i <= numberOfDays; i++)
+ {
+ string sql = @"
+ INSERT INTO schedule (ChannelID, ShowID, RunDateTime, RunBump, RunLock, CGExempt, IDType)
+ SELECT ChannelID, ShowID, DATEADD([day], " + i + @", RunDateTime), RunBump, RunLock, CGExempt, IDType
+ FROM Schedule
+ WHERE (Schedule.ChannelID = " + channelID + @")
+ AND runDateTime >= DATEADD(dd,0, datediff(dd,0,'" + sourceDay.ToShortDateString() + @"'))
+ AND runDateTime <= DATEADD([day],1, dateadd(dd,0, datediff(dd,0,'" + sourceDay.ToShortDateString() + @"')))
+ AND (IDType = 1);";
+
+ System.Data.SqlClient.SqlCommand sqlCmd = new System.Data.SqlClient.SqlCommand(sql, SqlConn);
+
+ result += sqlCmd.ExecuteNonQuery();
+ }
+ }
+
+ return result;
+ }
+
+ protected void uxSourceDate_SelectionChanged(object sender, EventArgs e)
+ {
+ uxNumberOfSourceRuns.Text = NumberOfRunsDescriptions(GetNumberOfRuns(uxSourceDate.SelectedDate));
+ }
+
+ private int GetNumberOfRuns(DateTime Date)
+ {
+ System.Data.SqlClient.SqlConnection SqlConn = new System.Data.SqlClient.SqlConnection();
+ System.Data.SqlClient.SqlDataReader SqlDr = null;
+
+ try
+ {
+ SqlConn.ConnectionString = "Data Source=(local);Initial Catalog=Cablecast40;Integrated Security=SSPI;Persist Security Info=False;Packet Size=4096";
+ SqlConn.Open();
+
+
+ string sql = @"
+SELECT Count(*)
+FROM Schedule
+WHERE (DATEADD([second], Schedule.RunBump, Schedule.RunDateTime) >= dateadd(dd,0, datediff(dd,0,'" + Date.ToShortDateString() + @"')))
+AND (DATEADD([second], Schedule.RunBump, Schedule.RunDateTime) <= DATEADD([day],1, dateadd(dd,0, datediff(dd,0,'" + Date.ToShortDateString() + @"'))))
+AND (Schedule.ChannelID = " + int.Parse(uxChannel.SelectedValue) + @") ";
+
+ //Get the channels from the database
+ System.Data.SqlClient.SqlCommand SqlCmd = new System.Data.SqlClient.SqlCommand(sql, SqlConn);
+
+ //set data reader
+ SqlDr = SqlCmd.ExecuteReader();
+
+ if (SqlDr.Read())
+ {
+ return (int)SqlDr[0];
+ }
+ }
+ catch (Exception exc)
+ {
+ }
+
+ return 0;
+ }
+
+ private string NumberOfRunsDescriptions(int NumberOfRuns)
+ {
+ string result = string.Empty;
+
+ if (NumberOfRuns <= 0)
+ result = "There are no runs on the selected day.";
+ if (NumberOfRuns == 1)
+ result = "There is one run on the selected day.";
+ if (NumberOfRuns > 1)
+ result = string.Format("There are {0} runs on the selected day.", NumberOfRuns);
+
+ return result;
+ }
+
+ protected void uxStartDate_SelectionChanged(object sender, EventArgs e)
+ {
+ ValidateDateRange();
+ }
+
+ protected void uxEndDate_SelectionChanged(object sender, EventArgs e)
+ {
+ ValidateDateRange();
+ }
+
+ private void ValidateDateRange()
+ {
+ if (m_SuppressDateChangeEvent == false) //If we don't do this check, it will clear the message out right away.
+ {
+ if (uxStartDate.SelectedDates.Count == 0)
+ {
+ uxStartDateError.Text = "You must select a start date.";
+ uxDateCount.Text = string.Empty;
+ }
+ else if (uxEndDate.SelectedDates.Count == 0)
+ {
+ uxEndDateError.Text = "You must select an end date.";
+ uxDateCount.Text = string.Empty;
+ }
+ else if (uxEndDate.SelectedDate < uxStartDate.SelectedDate)
+ {
+ m_SuppressDateChangeEvent = true;
+ uxEndDateError.Text = "End date must be on or after the start date.";
+ uxEndDate.SelectedDates.Clear();
+ m_SuppressDateChangeEvent = false;
+ }
+ else if (uxEndDate.SelectedDate >= uxStartDate.SelectedDate)
+ {
+ uxEndDateError.Text = string.Empty;
+ uxStartDateError.Text = string.Empty;
+
+ uxDateCount.Text = GetDateSelectionDescription();
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Provides a description of the number of days selected in the form
+ /// "There are 'n' days selected"
+ /// </summary>
+ /// <returns>Empty string if there are no days selected</returns>
+ private string GetDateSelectionDescription()
+ {
+ if ((uxEndDate.SelectedDate - uxStartDate.SelectedDate).TotalDays < 1)
+ return string.Empty;
+
+ if ((uxEndDate.SelectedDate - uxStartDate.SelectedDate).TotalDays == 0)
+ return "There is one day selected.";
+
+ return string.Format("There are {0} days selected.", (uxEndDate.SelectedDate - uxStartDate.SelectedDate).TotalDays + 1);
+ }
+}
+
40 Web.Config
@@ -0,0 +1,40 @@
+<?xml version="1.0"?>
+<!--
+ Note: As an alternative to hand editing this file you can use the
+ web admin tool to configure settings for your application. Use
+ the Website->Asp.Net Configuration option in Visual Studio.
+ A full list of settings and comments can be found in
+ machine.config.comments usually located in
+ \Windows\Microsoft.Net\Framework\v2.x\Config
+-->
+<configuration>
+ <appSettings/>
+ <connectionStrings/>
+ <system.web>
+ <!--
+ Set compilation debug="true" to insert debugging
+ symbols into the compiled page. Because this
+ affects performance, set this value to true only
+ during development.
+ -->
+ <compilation debug="true"/>
+ <!--
+ The <authentication> section enables configuration
+ of the security authentication mode used by
+ ASP.NET to identify an incoming user.
+ -->
+ <authentication mode="Windows"/>
+ <!--
+ The <customErrors> section enables configuration
+ of what to do if/when an unhandled error occurs
+ during the execution of a request. Specifically,
+ it enables developers to configure html error pages
+ to be displayed in place of a error stack trace.
+
+ <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
+ <error statusCode="403" redirect="NoAccess.htm" />
+ <error statusCode="404" redirect="FileNotFound.htm" />
+ </customErrors>
+ -->
+ </system.web>
+</configuration>
Please sign in to comment.
Something went wrong with that request. Please try again.