/// <summary>
        /// This is the constructor for the Schedule Stats generator.
        ///
        /// This class determines if today is the last working day of the week, month,
        /// or first working day of the year and send out a report via email automatically.
        /// </summary>
        /// <param name="MainForm"></param>
        /// <param name="detailFrom"></param>
        public ScheduleStatsGen(LogCreator MainForm, DetailForm detailFrom)
        {
            //Check if today is either the end of the week, end of the month, or end of the year.
            //End of the week == Monday(of next week)
            //End of the month == Last business day of the month
            //End of the year == One week into the new year. (Send out on the second Monday of the year)

            today = DateTime.Today;

            //If today is the end of the week we generate end of week statistics
            if (isEndOfWeek())
            {
                //Get the start date
                DateTime startDate = this.getFirstDayOfWeek();
                DateTime endDate   = today;

                while (endDate.DayOfWeek != DayOfWeek.Friday)
                {
                    endDate = endDate.AddDays(-1);
                }
                //generate the stats
                detailFrom.updateDetail("Generating weekly statistics.");
                statGenerator = new StatsGen(MainForm, startDate, endDate, "Weekly");
                //Get the file path
                string filePath = MainForm.STATS_LOCATION + statGenerator.getfileName();
                //Send the email
                detailFrom.updateDetail("Sending Email.");
                EmailSender ES = new EmailSender(filePath, "Weekly CSCO PT Stats");
            }

            //If we are at the end of the month we auto generate statistics
            if (isEndOfMonth())
            {
                //Get the start date
                DateTime starteDate = this.getFirstDayOfMonth();
                //generate the stats
                detailFrom.updateDetail("Generating monthly statistics.");
                statGenerator = new StatsGen(MainForm, starteDate, today, "Monthly");
                //Get the file path
                string filePath = MainForm.STATS_LOCATION + statGenerator.getfileName();
                //Send the email
                detailFrom.updateDetail("Sending Email.");
                EmailSender ES = new EmailSender(filePath, "Monthly CSCO PT Stats for " + today.Month);
            }

            //If we are at the end of the year we end
            if (isEndOfYear())
            {
                //Get the start date
                DateTime starteDate = this.getFirstDayOfYear();
                //generate the stats
                detailFrom.updateDetail("Generating yearly statistics.");
                statGenerator = new StatsGen(MainForm, starteDate, today, "Yearly");
                //Get the file path
                string filePath = MainForm.STATS_LOCATION + statGenerator.getfileName();
                //Send the email
                detailFrom.updateDetail("Sending Email.");
                EmailSender ES = new EmailSender(filePath, "Yearly CSCO PT stats for " + (today.Year - 1));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Create the statistics given the start and end date.
        /// </summary>
        /// <param name="MainForm"></param>
        /// <param name="StartDate"></param>
        /// <param name="EndDate"></param>
        /// <param name="pdfName"></param>
        public StatsGen(LogCreator MainForm, DateTime StartDate, DateTime EndDate, string pdfName)
        {
            this.mainForm  = MainForm;
            this.startDate = StartDate;
            this.endDate   = EndDate;

            this.PDFName = pdfName;

            this.generateStats();
        }
Beispiel #3
0
        /// <summary>
        /// This Class will import all the zone supervisor logs and assist with
        /// modification and find operations.
        /// </summary>
        public ZoneSuperLogImporter(LogCreator form1, string StartTime, string EndTime, ref string[,] arrayClassRooms)
        {
            //Assigning the variables
            this.Form1           = form1;
            this.startTime       = StartTime;
            this.endTime         = EndTime;
            this.ArrayClassRooms = arrayClassRooms;

            //Get the buildings and rooms
            buildingAndRooms = this.getBuildingsAndRoom();

            //Open the Excel Work books
            JeannineLog         = new Excel.Application();
            RaulLog             = new Excel.Application();
            DerekLog            = new Excel.Application();
            JeannineLog.Visible = false;
            RaulLog.Visible     = false;
            DerekLog.Visible    = false;

            try
            {
                //This should look for the file
                JeannineWorkBook = JeannineLog.Workbooks.Open(Form1.JEANNINE_LOG);
                RaulWorkBook     = RaulLog.Workbooks.Open(form1.RAUL_LOG);
                DerekWorkBook    = DerekLog.Workbooks.Open(Form1.DEREK_LOG);

                //Work in worksheet number 1
                JeannineSheet1 = (Excel.Worksheet)JeannineWorkBook.Sheets[1];
                RaulSheet1     = (Excel.Worksheet)RaulWorkBook.Sheets[1];
                DerekSheet1    = (Excel.Worksheet)DerekWorkBook.Sheets[1];
            }
            catch (Exception)
            {
                //File not found...
                Quit();
                throw new System.FieldAccessException("File not found!");
            }

            // Get the last date and create the 2D array for each log.
            lastDate         = this.dateFromLogs(JeannineSheet1);
            JeannineLogArray = this.ConvertToStringArray2D(JeannineSheet1);
            DerekLogArray    = this.ConvertToStringArray2D(DerekSheet1);
            RaulLogArray     = this.ConvertToStringArray2D(RaulSheet1);

            //Special case were we account for R N102 being in the building list already and doesn't have the description.
            if (buildingAndRooms.Contains("R N102") && arrayClassRooms[buildingAndRooms.IndexOf("R N102"), 3].ToString() == "")
            {
                this.ArrayClassRooms[buildingAndRooms.IndexOf("R N102"), 3] = @" Lock upper cinema doors (2) with allen key by releasing the crash bar.Pull side stage door shut from the inside.Make sure the stage lights at the front are off.Make sure the projector room is not open.Make sure the cinema lights are off, switched across from the projector room. Make sure the keyboard is on top of all the equipment in the drawer.";
            }

            this.Quit();
        }
        /// <summary>
        /// Constructor
        /// </summary>
        public SettingForm(LogCreator MainForm)
        {
            InitializeComponent();

            this.mainForm = MainForm;

            //Add event handlers
            this.emailLoginTab.SelectedIndexChanged += MetroTabControl1_SelectedIndexChanged;
            this.weeklyRadio.CheckedChanged         += new EventHandler(weeklyRadio_CheckedChanged);
            this.monthlyRadio.CheckedChanged        += new EventHandler(monthlyRadio_CheckedChanged);
            this.yearlyRadio.CheckedChanged         += new EventHandler(yearlyRadio_CheckedChanged);


            //Get last weeks start and end date.
            DateTime date = DateTime.Now.AddDays(-7);

            while (date.DayOfWeek != DayOfWeek.Sunday)
            {
                date = date.AddDays(-1);
            }
            DateTime startDateNow = date;
            DateTime endOfWeek    = date.AddDays(6);

            //Set the min and max date for the picker
            dateTimePicker.MinDate = new DateTime(2016, 9, 1);
            dateTimePicker.MaxDate = endOfWeek;

            //Fill the combo boxes
            for (int i = 1; i <= 12; i++)
            {
                //Select 1
                this.startHour1.Items.Add(new TimeItem {
                    Hour = i.ToString(), Minute = "00"
                });
                this.endHour1.Items.Add(new TimeItem {
                    Hour = i.ToString(), Minute = "00"
                });
                //15 minute intervals
                for (int k = 15; k <= 45; k += 15)
                {
                    //Select 1
                    this.startHour1.Items.Add(new TimeItem {
                        Hour = i.ToString(), Minute = k.ToString()
                    });
                    this.endHour1.Items.Add(new TimeItem {
                        Hour = i.ToString(), Minute = k.ToString()
                    });
                }
            }

            //Fill the am/pm selector
            this.am_pmCombo1_1.Items.Add("AM");
            this.am_pmCombo1_1.Items.Add("PM");
            this.am_pmCombo1_2.Items.Add("AM");
            this.am_pmCombo1_2.Items.Add("PM");

            //set the default view for the combo for tab 1
            this.startHour1.SelectedIndex    = -1;
            this.endHour1.SelectedIndex      = -1;
            this.am_pmCombo1_1.SelectedIndex = 1;
            this.am_pmCombo1_2.SelectedIndex = 1;

            //Set the version number
            this.versionLabel.Text += Application.ProductVersion;

            //Fill the password and user name field if we already have a user name and password saved.
            if (!Properties.Settings.Default.UserName.Equals("") || !Properties.Settings.Default.Password.Equals(""))
            {
                this.usernameTextBox.Text = Properties.Settings.Default.UserName;
                this.passwordTextBox.Text = Properties.Settings.Default.Password;
            }

            //Fill in the gmail and box
            this.gmailUsernameTextBox.Text = Properties.Settings.Default.gmailUserName;
            this.gmailPasswordTextBox.Text = Properties.Settings.Default.gmailPassword;
        }
        /// <summary>
        /// Constructor that will create the arrays for the main UI to use
        /// </summary>
        /// <param name="Form1"></param>
        /// <param name="StartTime"></param>
        /// <param name="EndTime"></param>
        /// <param name="classInfo"></param>
        public LogoutLogImporter(LogCreator Form1, string StartTime, string EndTime, ClassInfo classInfo)
        {
            this.form1     = Form1;
            this.startTime = StartTime;
            this.endTime   = EndTime;
            this.classList = classInfo;

            //Open the room excel file
            roomSched         = new Excel.Application();
            roomSched.Visible = false;

            try
            {
                //This should look for the file
                roomWorkBook = roomSched.Workbooks.Open(form1.ROOM_SCHED);
                //Work in worksheet number 1
                roomSheet1 = (Excel.Worksheet)roomWorkBook.Sheets[1];
            }
            catch (Exception)
            {
                //File not found...

                Quit();
                throw new System.FieldAccessException("File not found!");
            }


            //Get the range we are working within. (A1, A.LastRow)
            Excel.Range last       = roomSheet1.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell, Type.Missing);
            Excel.Range classRange = roomSheet1.get_Range("A5", "A" + last.Row);
            Excel.Range timeRange  = roomSheet1.get_Range("C5", "C" + last.Row);
            Excel.Range eventRange = roomSheet1.get_Range("D5", "D" + last.Row);

            //Delete any invalid rows in the clo
            deleteInValidRows();

            //Lets export the whole range of raw data into an array. (Cell.Value2 is a fast and accurate operation to use)
            System.Array classArray = (System.Array)classRange.Cells.Value2;
            System.Array timeArray  = (System.Array)timeRange.Cells.Value2;
            System.Array eventArray = (System.Array)eventRange.Cells.Value2;

            //Now we extract all the raw data to strings
            arrayClassRooms = this.ConvertToStringArray(classArray, 0);
            arrayTimes      = this.ConvertToStringArray(timeArray, 1);
            arrayEvent      = this.ConvertToStringArray(eventArray, 1);
            arrayLastTimes  = this.extract_last_time(arrayTimes, arrayEvent);

            //Remove the sql entry in the array if they exist
            if (arrayClassRooms[arrayClassRooms.GetUpperBound(0)].Contains("SQL"))
            {
                arrayClassRooms = arrayClassRooms.Take(arrayClassRooms.Count() - 1).ToArray();
            }

            //Check if the arrayLastTimes and the class array are the same length, if so then we get correct results.
            if (arrayLastTimes.GetUpperBound(0) != arrayClassRooms.GetUpperBound(0))
            {
                Quit();
                throw new System.IO.FileLoadException("Error: While parsing clo.xlsx we ran into a problem:" + Environment.NewLine +
                                                      "The file is not formatted correctly, please ensure all rows have a corresponding classroom");
            }
            else
            {
                masterArray = this.convertToString2DArray(arrayClassRooms, arrayLastTimes);
                masterArray = RemoveEmptyRows(masterArray);
            }


            last       = null;
            classRange = null;
            timeRange  = null;
            eventRange = null;
            //Close all open processes
            Quit();
        }