예제 #1
0
        public EditHours()
        {
            InitializeComponent();

            ParseHours hours = new ParseHours();

            hours.HoursWorked();

            // We're auto-populating all the textboxes with the values in the .txt file. It'll either be
            // zero, or something that the user has filled in previously.
            textBoxMonStart.Text    = hours.mondayStart.Trim();
            textBoxMonEnd.Text      = hours.mondayEnd.Trim();
            textBoxMonLunchIn.Text  = hours.mondayBreakEnd.Trim();
            textBoxMonLunchOut.Text = hours.mondayBreakStart.Trim();
            textBoxMonTotal.Text    = hours.mondayTotal.Trim();

            textBoxTueStart.Text    = hours.tuesdayStart.Trim();
            textBoxTueEnd.Text      = hours.tuesdayEnd.Trim();
            textBoxTueLunchIn.Text  = hours.tuesdayBreakEnd.Trim();
            textBoxTueLunchOut.Text = hours.tuesdayBreakStart.Trim();
            textBoxTueTotal.Text    = hours.tuesdayTotal.Trim();

            textBoxWedStart.Text    = hours.wednesdayStart.Trim();
            textBoxWedEnd.Text      = hours.wednesdayEnd.Trim();
            textBoxWedLunchIn.Text  = hours.wednesdayBreakEnd.Trim();
            textBoxWedLunchOut.Text = hours.wednesdayBreakStart.Trim();
            textBoxWedTotal.Text    = hours.wednesdayTotal.Trim();

            textBoxThurStart.Text    = hours.thursdayStart.Trim();
            textBoxThurEnd.Text      = hours.thursdayEnd.Trim();
            textBoxThurLunchIn.Text  = hours.thursdayBreakEnd.Trim();
            textBoxThurLunchOut.Text = hours.thursdayBreakStart.Trim();
            textBoxThurTotal.Text    = hours.thursdayTotal.Trim();

            textBoxFriStart.Text    = hours.fridayStart.Trim();
            textBoxFriEnd.Text      = hours.fridayEnd.Trim();
            textBoxFriLunchIn.Text  = hours.fridayBreakEnd.Trim();
            textBoxFriLunchOut.Text = hours.fridayBreakStart.Trim();
            textBoxFriTotal.Text    = hours.fridayTotal.Trim();
        }
        public bool checkValid(string dayOfWeek)
        {
            ParseHours hours = new ParseHours();

            hours.HoursWorked();
            bool valid = true;

            // This whole thing is fucky
            // We're taking the day of the week, checking if it's a working day (has no 0 in the first field for the day)
            // If it's a working day, both mondayStart and end should include ':'
            // if they don't it's not a valid time
            // This is for both a bit of standardization as well as ensuring that the time works with the calendar update
            if (dayOfWeek == "Monday")
            {
                if (hours.mondayStart != "0" || hours.mondayStart != " 0")
                {
                    if (hours.mondayStart.Contains(":") == false || hours.mondayEnd.Contains(":") == false)
                    {
                        valid = false;
                    }
                }
                else if (hours.mondayStart == "0" || hours.mondayStart == " 0")
                {
                    valid = true;
                }
            }
            if (dayOfWeek == "Tuesday")
            {
                if (hours.tuesdayStart != "0" || hours.tuesdayStart != " 0")
                {
                    if (hours.tuesdayStart.Contains(":") == false || hours.tuesdayEnd.Contains(":") == false)
                    {
                        valid = false;
                    }
                }
                else if (hours.tuesdayStart == "0" || hours.tuesdayStart == " 0")
                {
                    valid = true;
                }
            }
            if (dayOfWeek == "Wednesday")
            {
                if (hours.wednesdayStart != "0" || hours.wednesdayStart != " 0")
                {
                    if (hours.wednesdayStart.Contains(":") == false || hours.wednesdayEnd.Contains(":") == false)
                    {
                        valid = false;
                    }
                }
                else if (hours.wednesdayStart == "0" || hours.wednesdayStart == " 0")
                {
                    valid = true;
                }
            }
            if (dayOfWeek == "Thursday")
            {
                if (hours.thursdayStart != "0" || hours.thursdayStart != " 0")
                {
                    if (hours.thursdayStart.Contains(":") == false || hours.thursdayEnd.Contains(":") == false)
                    {
                        valid = false;
                    }
                }
                else if (hours.thursdayStart == "0" || hours.thursdayStart == " 0")
                {
                    valid = true;
                }
            }
            if (dayOfWeek == "Friday")
            {
                if (hours.fridayStart != "0" || hours.fridayStart != " 0")
                {
                    if (hours.fridayStart.Contains(":") == false || hours.fridayEnd.Contains(":") == false)
                    {
                        valid = false;
                    }
                }
                else if (hours.fridayStart == "0" || hours.fridayStart == " 0")
                {
                    valid = true;
                }
            }

            return(valid);
        }
예제 #3
0
        public void AddToCalendar(bool update)
        {
            // Making this a boolean for reasons. Dont remember what they are right now, but I remember thinking this was better for some reason.
            if (update == true)
            {
                UserCredential credential;

                using (var stream =
                           new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
                {
                    string credPath = System.Environment.GetFolderPath(
                        System.Environment.SpecialFolder.Personal);
                    credPath = Path.Combine(credPath, ".credentials/calendar-dotnet-quickstart.json");

                    credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                        GoogleClientSecrets.Load(stream).Secrets,
                        Scopes,
                        "user",
                        CancellationToken.None,
                        new FileDataStore(credPath, true)).Result;
                    //Console.WriteLine("Credential file saved to: " + credPath);
                }

                // Create Google Calendar API service.
                var service = new CalendarService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName       = ApplicationName,
                });

                // Grabbing the hours
                ParseHours hours = new ParseHours();
                hours.HoursWorked();
                DateTime dateValue = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
                MainForm listbox   = new MainForm();

                string calendarDate = "1/1/2017 ";

                // Making one event with 'default' settings. So if something goes wrong it posts it to your current day between 8 and 10 AM
                Event newEvent = new Event()
                {
                    Summary     = "Working",
                    Location    = "7000 Dandini BLVD Reno NV 89512",
                    Description = "Working during this time",
                    Start       = new EventDateTime()
                    {
                        DateTime = DateTime.Parse(calendarDate + "8:00 AM"),
                        TimeZone = "America/Los_Angeles",
                    },
                    End = new EventDateTime()
                    {
                        DateTime = DateTime.Parse(calendarDate + "10:00 AM"),
                        TimeZone = "America/Los_Angeles",
                    },
                    Recurrence = new String[] {
                        "RRULE:FREQ=WEEKLY;COUNT=2"
                    },
                    Reminders = new Event.RemindersData()
                    {
                        UseDefault = true,
                    }
                };

                String calendarId = "primary";
                EventsResource.InsertRequest request = service.Events.Insert(newEvent, calendarId);
                string dateText;

                // We're adding dates for the first five days of the week, and then we're letting google handle the second repeat of the event
                // We're running the loop ~7 times, but only posting on Mon-Fri
                int i = 0;
                int x = 0;

                if (dateRange == "1st - 15th")
                {
                    i = 1;
                    x = i + 7;
                }
                else if (dateRange == "16th - 30th")
                {
                    i = 16;
                    x = i + 7;
                }
                else if (dateRange == "16th - 31st")
                {
                    i = 16;
                    x = i + 8;
                }

                while (i < x)
                {
                    if (dateValue.AddDays(i - 1).ToString("ddd") == "Mon" && hours.mondayStart != " 0")
                    {
                        dateText = string.Format("{0}/{1}/{2} ", DateTime.Now.Month, i, DateTime.Now.Year);
                        newEvent.Start.DateTime = DateTime.Parse(dateText + hours.mondayStart);
                        newEvent.End.DateTime   = DateTime.Parse(dateText + hours.mondayEnd);
                        Event createdEvent = request.Execute();
                    }
                    else if (dateValue.AddDays(i - 1).ToString("ddd") == "Tue" && hours.tuesdayStart != " 0")
                    {
                        dateText = string.Format("{0}/{1}/{2} ", DateTime.Now.Month, i, DateTime.Now.Year);
                        newEvent.Start.DateTime = DateTime.Parse(dateText + hours.tuesdayStart);
                        newEvent.End.DateTime   = DateTime.Parse(dateText + hours.tuesdayEnd);
                        Event createdEvent = request.Execute();
                    }
                    else if (dateValue.AddDays(i - 1).ToString("ddd") == "Wed" && hours.wednesdayStart != " 0")
                    {
                        dateText = string.Format("{0}/{1}/{2} ", DateTime.Now.Month, i, DateTime.Now.Year);
                        newEvent.Start.DateTime = DateTime.Parse(dateText + hours.wednesdayStart);
                        newEvent.End.DateTime   = DateTime.Parse(dateText + hours.wednesdayEnd);
                        Event createdEvent = request.Execute();
                    }
                    else if (dateValue.AddDays(i - 1).ToString("ddd") == "Thu" && hours.thursdayStart != " 0")
                    {
                        dateText = string.Format("{0}/{1}/{2} ", DateTime.Now.Month, i, DateTime.Now.Year);
                        newEvent.Start.DateTime = DateTime.Parse(dateText + hours.thursdayStart);
                        newEvent.End.DateTime   = DateTime.Parse(dateText + hours.thursdayEnd);
                        Event createdEvent = request.Execute();
                    }
                    else if (dateValue.AddDays(i - 1).ToString("ddd") == "Fri" && hours.fridayStart != " 0")
                    {
                        dateText = string.Format("{0}/{1}/{2} ", DateTime.Now.Month, i, DateTime.Now.Year);
                        newEvent.Start.DateTime = DateTime.Parse(dateText + hours.fridayStart);
                        newEvent.End.DateTime   = DateTime.Parse(dateText + hours.fridayEnd);
                        Event createdEvent = request.Execute();
                    }

                    ++i;
                }


                //Console.WriteLine("Event created: {0}", createdEvent.HtmlLink);
            }
        }
예제 #4
0
        public void ReplacePdfForm()
        {
            DateTime dateValue        = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
            string   fileNameExisting = "time.pdf";
            string   fileNameNew      = "TimeSheet" + dateValue.Month + dateValue.Year + ".pdf";

            double hoursTotalInt = 0;

            ParseHours hours = new ParseHours();

            hours.HoursWorked();

            // Employee Info Variables
            string empFirst = File.ReadLines("EmployeeInfo.txt").Skip(0).Take(1).First();

            empFirst = empFirst.Split(')').Last();
            string empLast = File.ReadLines("EmployeeInfo.txt").Skip(1).Take(1).First();

            empLast = empLast.Split(')').Last();
            string empNSHE = File.ReadLines("EmployeeInfo.txt").Skip(2).Take(1).First();

            empNSHE = empNSHE.Split(')').Last();

            using (var existingFileStream = new FileStream(fileNameExisting, FileMode.Open))
                using (var newFileStream = new FileStream(fileNameNew, FileMode.Create))
                {
                    // Open existing PDF
                    var pdfReader = new PdfReader(existingFileStream);

                    // PdfStamper, which will create
                    var stamper = new PdfStamper(pdfReader, newFileStream, '\0', true);

                    var form      = stamper.AcroFields;
                    var fieldKeys = form.Fields.Keys;

                    if (radioButton15th.Checked)
                    {
                        for (int i = 1; i < 16; ++i)
                        {
                            // We're building a date: DD/MM/YYYY
                            // fieldKey is the name of the textbox where the date is being entered
                            // Then we set it
                            string dateText = string.Format("{0}/{1}/{2}", DateTime.Now.Month, i, DateTime.Now.Year);
                            string fieldKey = string.Format("DateRow{0}", i);
                            form.SetField(fieldKey, dateText);
                        }
                    }
                    else if (radioButton30th.Checked)
                    {
                        for (int i = 1; i < 16; ++i)
                        {
                            string dateText = string.Format("{0}/{1}/{2}", DateTime.Now.Month, i + 15, DateTime.Now.Year);
                            string fieldKey = string.Format("DateRow{0}", i);
                            form.SetField(fieldKey, dateText);
                        }
                    }
                    else if (radioButton31st.Checked)
                    {
                        for (int i = 1; i < 16; ++i)
                        {
                            string dateText = string.Format("{0}/{1}/{2}", DateTime.Now.Month, i + 15, DateTime.Now.Year);
                            string fieldKey = string.Format("DateRow{0}", i);
                            form.SetField(fieldKey, dateText);
                        }
                        string extraDateText = string.Format("{0}/31/{1}", DateTime.Now.Month, DateTime.Now.Year);
                        form.SetField("DateRow16", extraDateText);
                    }

                    int x = 16;
                    // Adding working in hours
                    try
                    {
                        foreach (string fieldKey in fieldKeys)
                        {
                            for (int i = 1; i < x; ++i)
                            {
                                // 1st - 15th
                                if (radioButton15th.Checked)
                                {
                                    if (fieldKey.Equals("Work StartRow" + i))
                                    {
                                        switch (dateValue.AddDays(i - 1).ToString("ddd"))
                                        {
                                        case "Mon":
                                            form.SetField(fieldKey, hours.mondayStart);
                                            form.SetField("Work EndRow" + i, hours.mondayEnd);
                                            form.SetField("Break OutRow" + i, hours.mondayBreakStart);
                                            form.SetField("Break InRow" + i, hours.mondayBreakEnd);
                                            form.SetField("HoursRow" + i, hours.mondayTotal);
                                            hoursTotalInt = hoursTotalInt + Double.Parse(hours.mondayTotal);
                                            break;

                                        case "Tue":
                                            form.SetField(fieldKey, hours.tuesdayStart);
                                            form.SetField("Work EndRow" + i, hours.tuesdayEnd);
                                            form.SetField("Break OutRow" + i, hours.tuesdayBreakStart);
                                            form.SetField("Break InRow" + i, hours.tuesdayBreakEnd);
                                            form.SetField("HoursRow" + i, hours.tuesdayTotal);
                                            hoursTotalInt = hoursTotalInt + Double.Parse(hours.tuesdayTotal);
                                            break;

                                        case "Wed":
                                            form.SetField(fieldKey, hours.wednesdayStart);
                                            form.SetField("Work EndRow" + i, hours.wednesdayEnd);
                                            form.SetField("Break OutRow" + i, hours.wednesdayBreakStart);
                                            form.SetField("Break InRow" + i, hours.wednesdayBreakEnd);
                                            form.SetField("HoursRow" + i, hours.wednesdayTotal);
                                            hoursTotalInt = hoursTotalInt + Double.Parse(hours.wednesdayTotal);
                                            break;

                                        case "Thu":
                                            form.SetField(fieldKey, hours.thursdayStart);
                                            form.SetField("Work EndRow" + i, hours.thursdayEnd);
                                            form.SetField("Break OutRow" + i, hours.thursdayBreakStart);
                                            form.SetField("Break InRow" + i, hours.thursdayBreakEnd);
                                            form.SetField("HoursRow" + i, hours.thursdayTotal);
                                            hoursTotalInt = hoursTotalInt + Double.Parse(hours.thursdayTotal);
                                            break;

                                        case "Fri":
                                            form.SetField(fieldKey, hours.fridayStart);
                                            form.SetField("Work EndRow" + i, hours.fridayEnd);
                                            form.SetField("Break OutRow" + i, hours.fridayBreakStart);
                                            form.SetField("Break InRow" + i, hours.fridayBreakEnd);
                                            form.SetField("HoursRow" + i, hours.fridayTotal);
                                            hoursTotalInt = hoursTotalInt + Double.Parse(hours.fridayTotal);
                                            break;

                                        default:

                                            break;
                                        } // Switch
                                    }
                                }         // if 1st - 15th

                                //16th - 30th
                                else if (radioButton30th.Checked)
                                {
                                    if (fieldKey.Equals("Work StartRow" + i))
                                    {
                                        switch (dateValue.AddDays(i + 15 - 1).ToString("ddd"))
                                        {
                                        case "Mon":
                                            form.SetField(fieldKey, hours.mondayStart);
                                            form.SetField("Work EndRow" + i, hours.mondayEnd);
                                            form.SetField("Break OutRow" + i, hours.mondayBreakStart);
                                            form.SetField("Break InRow" + i, hours.mondayBreakEnd);
                                            form.SetField("HoursRow" + i, hours.mondayTotal);
                                            hoursTotalInt = hoursTotalInt + Double.Parse(hours.mondayTotal);
                                            break;

                                        case "Tue":
                                            form.SetField(fieldKey, hours.tuesdayStart);
                                            form.SetField("Work EndRow" + i, hours.tuesdayEnd);
                                            form.SetField("Break OutRow" + i, hours.tuesdayBreakStart);
                                            form.SetField("Break InRow" + i, hours.tuesdayBreakEnd);
                                            form.SetField("HoursRow" + i, hours.tuesdayTotal);
                                            hoursTotalInt = hoursTotalInt + Double.Parse(hours.tuesdayTotal);
                                            break;

                                        case "Wed":
                                            form.SetField(fieldKey, hours.wednesdayStart);
                                            form.SetField("Work EndRow" + i, hours.wednesdayEnd);
                                            form.SetField("Break OutRow" + i, hours.wednesdayBreakStart);
                                            form.SetField("Break InRow" + i, hours.wednesdayBreakEnd);
                                            form.SetField("HoursRow" + i, hours.wednesdayTotal);
                                            hoursTotalInt = hoursTotalInt + Double.Parse(hours.wednesdayTotal);
                                            break;

                                        case "Thu":
                                            form.SetField(fieldKey, hours.thursdayStart);
                                            form.SetField("Work EndRow" + i, hours.thursdayEnd);
                                            form.SetField("Break OutRow" + i, hours.thursdayBreakStart);
                                            form.SetField("Break InRow" + i, hours.thursdayBreakEnd);
                                            form.SetField("HoursRow" + i, hours.thursdayTotal);
                                            hoursTotalInt = hoursTotalInt + Double.Parse(hours.thursdayTotal);
                                            break;

                                        case "Fri":
                                            form.SetField(fieldKey, hours.fridayStart);
                                            form.SetField("Work EndRow" + i, hours.fridayEnd);
                                            form.SetField("Break OutRow" + i, hours.fridayBreakStart);
                                            form.SetField("Break InRow" + i, hours.fridayBreakEnd);
                                            form.SetField("HoursRow" + i, hours.fridayTotal);
                                            hoursTotalInt = hoursTotalInt + Double.Parse(hours.fridayTotal);
                                            break;

                                        default:

                                            break;
                                        } // switch
                                    }
                                }         // if 16th - 30th

                                //16th - 31st
                                if (radioButton31st.Checked)
                                {
                                    x = 17;
                                    if (fieldKey.Equals("Work StartRow" + i))
                                    {
                                        switch (dateValue.AddDays(i + 15 - 1).ToString("ddd"))
                                        {
                                        case "Mon":
                                            form.SetField(fieldKey, hours.mondayStart);
                                            form.SetField("Work EndRow" + i, hours.mondayEnd);
                                            form.SetField("Break OutRow" + i, hours.mondayBreakStart);
                                            form.SetField("Break InRow" + i, hours.mondayBreakEnd);
                                            form.SetField("HoursRow" + i, hours.mondayTotal);
                                            hoursTotalInt = hoursTotalInt + Double.Parse(hours.mondayTotal);
                                            break;

                                        case "Tue":
                                            form.SetField(fieldKey, hours.tuesdayStart);
                                            form.SetField("Work EndRow" + i, hours.tuesdayEnd);
                                            form.SetField("Break OutRow" + i, hours.tuesdayBreakStart);
                                            form.SetField("Break InRow" + i, hours.tuesdayBreakEnd);
                                            form.SetField("HoursRow" + i, hours.tuesdayTotal);
                                            hoursTotalInt = hoursTotalInt + Double.Parse(hours.tuesdayTotal);
                                            break;

                                        case "Wed":
                                            form.SetField(fieldKey, hours.wednesdayStart);
                                            form.SetField("Work EndRow" + i, hours.wednesdayEnd);
                                            form.SetField("Break OutRow" + i, hours.wednesdayBreakStart);
                                            form.SetField("Break InRow" + i, hours.wednesdayBreakEnd);
                                            form.SetField("HoursRow" + i, hours.wednesdayTotal);
                                            hoursTotalInt = hoursTotalInt + Double.Parse(hours.wednesdayTotal);
                                            break;

                                        case "Thu":
                                            form.SetField(fieldKey, hours.thursdayStart);
                                            form.SetField("Work EndRow" + i, hours.thursdayEnd);
                                            form.SetField("Break OutRow" + i, hours.thursdayBreakStart);
                                            form.SetField("Break InRow" + i, hours.thursdayBreakEnd);
                                            form.SetField("HoursRow" + i, hours.thursdayTotal);
                                            hoursTotalInt = hoursTotalInt + Double.Parse(hours.thursdayTotal);
                                            break;

                                        case "Fri":
                                            form.SetField(fieldKey, hours.fridayStart);
                                            form.SetField("Work EndRow" + i, hours.fridayEnd);
                                            form.SetField("Break OutRow" + i, hours.fridayBreakStart);
                                            form.SetField("Break InRow" + i, hours.fridayBreakEnd);
                                            form.SetField("HoursRow" + i, hours.fridayTotal);
                                            hoursTotalInt = hoursTotalInt + Double.Parse(hours.fridayTotal);
                                            break;

                                        default:

                                            break;
                                        } // switch
                                    }
                                }         // if 16th - 31st
                            }
                        }                 // foreach field
                    }                     // try

                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }

                    // Adding employee info into the PDF
                    form.SetField("Last Name", empLast);
                    form.SetField("First Name", empFirst);
                    form.SetField("Employee ID", empNSHE);
                    form.SetField("HoursTotal Hours", Convert.ToString(hoursTotalInt));

                    if (radioButton15th.Checked)
                    {
                        string fromDate = DateTime.Now.Month + "/01/" + DateTime.Now.Year;
                        string toDate   = DateTime.Now.Month + "/15/" + DateTime.Now.Year;
                        form.SetField("Pay Period From To", fromDate);
                        form.SetField("Pay Period To", toDate);
                    }
                    if (radioButton30th.Checked)
                    {
                        string fromDate = DateTime.Now.Month + "/16/" + DateTime.Now.Year;
                        string toDate   = DateTime.Now.Month + "/30/" + DateTime.Now.Year;
                        form.SetField("Pay Period From To", fromDate);
                        form.SetField("Pay Period To", toDate);
                    }
                    else if (radioButton31st.Checked)
                    {
                        string fromDate = DateTime.Now.Month + "/16/" + DateTime.Now.Year;
                        string toDate   = DateTime.Now.Month + "/31/" + DateTime.Now.Year;
                        form.SetField("Pay Period From To", fromDate);
                        form.SetField("Pay Period To", toDate);
                    }

                    stamper.Close();
                    pdfReader.Close();
                }
        }
예제 #5
0
        // Calendar update
        private void buttonAddToCalendar_Click(object sender, EventArgs e)
        {
            CalendarUpdate calendar = new CalendarUpdate();

            if (File.Exists("client_secret.json") == false) // File needed to access google api
            {
                WebClient client = new WebClient();
                client.DownloadFile("http://uraqt.xyz/uselessprograms/client_secret.json", "client_secret.json"); // same
            }

            if (radioButton15th.Checked)
            {
                calendar.dateRange = "1st - 15th";
            }

            else if (radioButton30th.Checked)
            {
                calendar.dateRange = "16th - 30th";
            }
            else if (radioButton31st.Checked)
            {
                calendar.dateRange = "16th - 31st";
            }
            else
            {
                MessageBox.Show("Please select a date range before trying to update your calendar", "Error", MessageBoxButtons.OK);
            }

            ParseHours hours = new ParseHours();

            hours.HoursWorked();
            CheckIfValidTime check = new CheckIfValidTime();
            int count = 0;

            // k. so. whats going on here is we're checking if you're working
            // then we're checking if the way the time has been entered is valid
            // if it's not valid we're adding one to the count
            // if at the end the count is > 0 we display an error
            // this was my quick way of making sure we don't display an error one million times
            if (hours.mondayStart != " 0")
            {
                if (check.checkValid("Monday") == false)
                {
                    ++count;
                }
            }
            if (hours.tuesdayStart != " 0")
            {
                if (check.checkValid("Tuesday") == false)
                {
                    ++count;
                }
            }
            if (hours.wednesdayStart != " 0")
            {
                if (check.checkValid("Wednesday") == false)
                {
                    ++count;
                }
            }
            if (hours.thursdayStart != " 0")
            {
                if (check.checkValid("Thursday") == false)
                {
                    ++count;
                }
            }
            if (hours.fridayStart != " 0")
            {
                if (check.checkValid("Friday") == false)
                {
                    ++count;
                }
            }
            if (count > 0)
            {
                MessageBox.Show("Please make sure your times are in the correct format (<HH>:<MM>), and/or have '0' in empty spaces", "Error", MessageBoxButtons.OK);
            }
            else if (count == 0)
            {
                MessageBox.Show("Added to calendar!", "Success", MessageBoxButtons.OK);
                calendar.AddToCalendar(true);
            }
        }
예제 #6
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            foreach (Control c in this.Controls)
            {
                if (c is TextBox)
                {
                    TextBox textBox = c as TextBox;
                    if (string.IsNullOrWhiteSpace(textBox.Text) == true)
                    {
                        textBox.Text = "0";
                    }
                    // If not a total
                    if (textBox.TabIndex != 5 && textBox.TabIndex != 10 && textBox.TabIndex != 15 && textBox.TabIndex != 20 && textBox.TabIndex != 25)
                    {
                        // If user enters a time that isn't formatted correctly (ex: 8 AM instead of 8:00 AM) this will adjust the format
                        // Doing this so it's a little more standard, and it'll work properly with the calendar update
                        // which is understandably picky with the time formatting

                        // If not a day that you're not working
                        if (textBox.Text != "0")
                        {
                            // if the textbox is only missing AM/PM (ex: 8:00)
                            if (textBox.Text.Contains("AM") == false && textBox.Text.Contains("PM") == false)
                            {
                                if (textBox.Text.Contains(':') == true)
                                {
                                    if (Convert.ToInt32(textBox.Text.Split(':').First().Trim()) > 6 && Convert.ToInt32(textBox.Text.Split(':').First().Trim()) <= 11)
                                    {
                                        textBox.Text  = textBox.Text.Trim();
                                        textBox.Text += " AM";
                                    }
                                    if (Convert.ToInt32(textBox.Text.Split(':').First().Trim()) <= 5 || Convert.ToInt32(textBox.Text.Split(':').First().Trim()) == 12)
                                    {
                                        textBox.Text  = textBox.Text.Trim();
                                        textBox.Text += " PM";
                                    }
                                }
                                // If it's only a number (ex: 8)
                                else
                                {
                                    if (Convert.ToInt32(textBox.Text.Trim()) > 6 && Convert.ToInt32(textBox.Text.Trim()) <= 11)
                                    {
                                        textBox.Text  = textBox.Text.Trim();
                                        textBox.Text += ":00 AM";
                                    }
                                    else if (Convert.ToInt32(textBox.Text.Trim()) <= 5 || Convert.ToInt32(textBox.Text.Trim()) == 12)
                                    {
                                        textBox.Text  = textBox.Text.Trim();
                                        textBox.Text += ":00 PM";
                                    }
                                }
                            }
                        }
                    }
                }
            }

            ParseHours hours = new ParseHours();

            // Adding it to the hours.txt file
            string hoursFile =
                "Day, Work Start, Lunch Out, Lunch In, Work End, Total Hours" + Environment.NewLine + Environment.NewLine +
                String.Format("Mon) {0}, {1}, {2}, {3}, {4}", textBoxMonStart.Text, textBoxMonLunchOut.Text, textBoxMonLunchIn.Text, textBoxMonEnd.Text, textBoxMonTotal.Text) + Environment.NewLine +
                String.Format("Tue) {0}, {1}, {2}, {3}, {4}", textBoxTueStart.Text, textBoxTueLunchOut.Text, textBoxTueLunchIn.Text, textBoxTueEnd.Text, textBoxTueTotal.Text) + Environment.NewLine +
                String.Format("Wed) {0}, {1}, {2}, {3}, {4}", textBoxWedStart.Text, textBoxWedLunchOut.Text, textBoxWedLunchIn.Text, textBoxWedEnd.Text, textBoxWedTotal.Text) + Environment.NewLine +
                String.Format("Thu) {0}, {1}, {2}, {3}, {4}", textBoxThurStart.Text, textBoxThurLunchOut.Text, textBoxThurLunchIn.Text, textBoxThurEnd.Text, textBoxThurTotal.Text) + Environment.NewLine +
                String.Format("Fri) {0}, {1}, {2}, {3}, {4}", textBoxFriStart.Text, textBoxFriLunchOut.Text, textBoxFriLunchIn.Text, textBoxFriEnd.Text, textBoxFriTotal.Text) + Environment.NewLine;

            File.WriteAllText("hours.txt", hoursFile);

            this.Close();
        }