Example #1
0
        private void AssertDayAndMonth(UkCensusYears censusYear, DayOfWeek day, MonthNames monthOfYear)
        {
            var date = UkCensus.DateFromCensusYear(censusYear);

            Assert.Equal(date.DayOfWeek, day);
            Assert.Equal(date.Month, (int)monthOfYear);
        }
Example #2
0
        private void buttonMonthLeft_Click_1(object sender, EventArgs e)
        {
            Button btn = sender as Button;

            if (btn != null && (int)currentMonth > 1)
            {
                currentMonth -= 1;
                loadMonth(currentMonth);
            }
            // January to December decrement year
            else if (btn != null && (int)currentMonth == 1)
            {
                currentMonth = currentMonth + 11;
                //decrement year
                currentYear -= 1;

                //reinit calendar
                cal.initCalendar(currentYear);

                //reload month GUI
                loadMonth(currentMonth);

                //update year label
                YearLabel.Text = currentYear.ToString();
            }
        }
Example #3
0
        public Agenda(int d, MonthNames m, int y, Calendar c)
        {
            InitializeComponent();

            day   = d;
            month = m;
            year  = y;
            cal   = c;

            loadTaskList();
        }
Example #4
0
        public bool HasTask(int d, MonthNames m, int year)
        {
            foreach (Task t in tasks)
            {
                if (t.taskYear == year && t.taskMonth == m && t.taskDay == d)
                {
                    return(true);
                }
            }

            return(false);
        }
Example #5
0
        private void CreateMonth(DateTime date)
        {
            ClearGrids();
            label_MonthName.Content = string.Format("{0} {1}", MonthNames.GetMonthName(date.Month), date.Year);
            var days = User.Calendar.GetMonthlyFinances(date);
            int y    = 0;

            foreach (var day in days)
            {
                DailyCalendarEntity dailyCalendar = new DailyCalendarEntity(day.Key, day.Value);
                Frame frame = new Frame()
                {
                    Margin = new Thickness(0, y, 0, 0), VerticalAlignment = VerticalAlignment.Top, Width = 100, Height = 100, Content = dailyCalendar
                };
                switch (day.Key.DayOfWeek)
                {
                case DayOfWeek.Sunday:
                    Grid_Sunday.Children.Add(frame);
                    y += 100;
                    break;

                case DayOfWeek.Monday:
                    Grid_Monday.Children.Add(frame);
                    break;

                case DayOfWeek.Tuesday:
                    Grid_Tuesday.Children.Add(frame);
                    break;

                case DayOfWeek.Wednesday:
                    Grid_Wednesday.Children.Add(frame);
                    break;

                case DayOfWeek.Thursday:
                    Grid_Thursday.Children.Add(frame);
                    break;

                case DayOfWeek.Friday:
                    Grid_Friday.Children.Add(frame);
                    break;

                case DayOfWeek.Saturday:
                    Grid_Saturday.Children.Add(frame);
                    break;

                default:
                    break;
                }
            }
        }
Example #6
0
        public List <Task> GetTasks(int d, MonthNames m, int year)
        {
            List <Task> tempTasks = new List <Task>();

            foreach (Task t in tasks)
            {
                if (t.taskYear == year && t.taskMonth == m && t.taskDay == d)
                {
                    tempTasks.Add(t);
                }
            }

            return(tempTasks);
        }
Example #7
0
        public int NumTask(int d, MonthNames m, int year)
        {
            int numTasks = 0;

            foreach (Task t in tasks)
            {
                if (t.taskYear == year && t.taskMonth == m && t.taskDay == d)
                {
                    numTasks++;
                }
            }

            return(numTasks);
        }
        public void AsSerializableObject_MonthNamesIsBuilded_ObjectIsCorrectlySerialized()
        {
            MonthNames monthNames = new MonthNames
            {
                November = "No",
                December = ""
            };
            object target = monthNames.AsSerializableObject();

            target.ShouldBeEquivalentTo(new List <string>
            {
                "undefined", "undefined", "undefined", "undefined",
                "undefined", "undefined", "undefined", "undefined",
                "undefined", "undefined", "No", ""
            });
        }
Example #9
0
        static private int GetDaysInMonth(MonthNames name)
        {
            int result = 0;

            //Здесь всего 3 варианта ответа 31/30/28 дней. Так что я решил
            //использовать if c 3-1=2 вариантами, а не switch/case с 12-1=11 вариантами
            if (name == MonthNames.January || name == MonthNames.March || name == MonthNames.May ||
                name == MonthNames.July || name == MonthNames.August || name == MonthNames.October ||
                name == MonthNames.December)
            {
                result = 31;
            }
            else
            {
                if (name != MonthNames.February)
                {
                    result = 30;
                }
            }
            return(result);
        }
Example #10
0
        public Form1()
        {
            InitializeComponent();

            // get current system day month and year
            currentDay   = System.DateTime.Now.Day;
            currentMonth = (MonthNames)System.DateTime.Now.Month;
            currentYear  = System.DateTime.Now.Year;


            // instantiate calender class
            cal = new Calendar();

            // initilize calendar
            cal.initCalendar(currentYear);

            //load month in GUI
            loadMonth(currentMonth);

            FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
        }
Example #11
0
        static void Main(string[] args)
        {
            // declarations
            Employee[] employees = new Employee[5];
            Date       tempDate;

            // construct employees
            employees[0] = new SalariedEmployee("John", "Smith", "111-11-1111", "5/1/1970", 800.00M);
            employees[1] = new HourlyEmployee("Karen", "Price", "222-22-2222", "10/2/1980", 16.75M, 40.0M);
            employees[2] = new CommissionEmployee("Sue", "Jones", "333-33-3333", "6/3/1990", 10000.00M, .06M);
            employees[3] = new BasePlusCommissionEmployee("Bob", "Lewis", "444-44-4444", "1/4/1965", 5000.00M, .04M, 300.00M);
            employees[4] = new HourlyEmployee("Michael", "DeSanto", "555-55-5555", "7/9/1985", 20.00M, 45.0M);

            // display payroll
            for (MonthNames month = MonthNames.January; month <= MonthNames.December; ++month)
            {
                Console.WriteLine("{0} payroll:", month);
                foreach (Employee selectedEmployee in employees)
                {
                    tempDate = (Date)selectedEmployee.BirthDate;
                    if (tempDate.Month == (int)month) // eligible for birth month bonus
                    {
                        Console.WriteLine("{0}, {1} earned {2:C}.", selectedEmployee.LastName, selectedEmployee.FirstName, selectedEmployee.Earnings() + 100.00M);
                    }
                    else // regular pay
                    {
                        Console.WriteLine("{0}, {1} earned {2:C}.", selectedEmployee.LastName, selectedEmployee.FirstName, selectedEmployee.Earnings());
                    }
                }
                Console.WriteLine();
            }

            // hold console
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
Example #12
0
        private void buttonMonthRight_Click(object sender, EventArgs e)
        {
            Button btn = sender as Button;

            if (btn != null && (int)currentMonth < 12)
            {
                currentMonth += 1;
                loadMonth(currentMonth);
            }
            // December to January increment year
            else if (btn != null && (int)currentMonth == 12)
            {
                currentMonth = currentMonth - 11;
                currentYear += 1;
                //reinit calendar
                cal.initCalendar(currentYear);

                //reload month GUI
                loadMonth(currentMonth);

                //update year label
                YearLabel.Text = currentYear.ToString();
            }
        }
Example #13
0
 public Day(DayNames d, int number, MonthNames m)
 {
     dow       = d;
     dayNum    = number;
     monthName = m;
 }
Example #14
0
 internal void Check_census_dates_are_on_correct_days(UkCensusYears censusYear, DayOfWeek expectedDay, MonthNames expectedMonth)
 {
     AssertDayAndMonth(censusYear, expectedDay, expectedMonth);
 }
Example #15
0
        void loadMonth(MonthNames m)
        {
            // if buttons in temp button array, delete them
            if (buttons.Count > 0)
            {
                foreach (Button b in buttons)
                {
                    //this.buttons.Remove(b);
                    this.Controls.Remove(b);
                    //buttons.Clear();
                }
            }

            // if labels in temp label array, delete them
            if (labels.Count > 0)
            {
                foreach (Label l in labels)
                {
                    this.Controls.Remove(l);
                }
            }

            //set current month
            currentMonth = m;

            //calculate day and shift value, Sun = 0, Sat = 6
            int dayShift = ((int)(cal.year.months[(int)currentMonth - 1].days[0].dow));

            // for every day in month add button in form1
            for (
                int d = 0 + dayShift;                                           //get starting day and shift appropriately
                d < cal.year.months[(int)currentMonth - 1].numDays + dayShift;  // total days + shift value
                d++
                )
            {
                Button btn = new Button();

                btn.Text = cal.year.months[(int)currentMonth - 1].days[d - dayShift].dayNum.ToString();

                btn.Width  = daySize - 4;
                btn.Height = daySize - 4;

                btn.TextAlign = ContentAlignment.TopLeft;

                btn.Location = new Point(
                    daySize * (d % 7) + boarder,    // x position value
                    daySize * (d / 7) + boarder * 3 // y position value
                    );

                //get rid of boarder and change color
                btn.BackColor = System.Drawing.Color.Ivory;

                btn.FlatStyle = FlatStyle.Flat;
                btn.FlatAppearance.BorderSize = 0;
                btn.Font = new Font("Microsoft Sans serif", 16);

                // highlight current day in a green color
                if (System.DateTime.Now.Day == d + 1 - dayShift && System.DateTime.Now.Month == (int)currentMonth && System.DateTime.Now.Year == currentYear)
                {
                    btn.BackColor = System.Drawing.Color.LightGreen;
                }


                // check if day has a task
                int numTasks = cal.NumTask(d + 1 - dayShift, currentMonth, currentYear);

                if (numTasks > 0)
                {
                    // Add indicator for task at this day
                    Button taskLabel = new Button();

                    taskLabel.Location = new Point(
                        daySize * (d % 7) + boarder + (daySize / 2),    // x position value
                        daySize * (d / 7) + boarder * 3 + (daySize / 2) // y position value
                        );

                    taskLabel.Text = numTasks.ToString();

                    taskLabel.Width  = daySize / 2 - 3;
                    taskLabel.Height = daySize / 2 - 3;

                    //get rid of boarder and change color
                    taskLabel.BackColor = System.Drawing.Color.SeaGreen;
                    taskLabel.FlatStyle = FlatStyle.Flat;
                    taskLabel.FlatAppearance.BorderSize = 0;
                    taskLabel.ForeColor = System.Drawing.Color.White;
                    taskLabel.Font      = new Font("Microsoft Sans serif", 12);

                    taskLabel.Name = (d + 1 - dayShift).ToString();

                    this.Controls.Add(taskLabel);
                    this.buttons.Add(taskLabel);

                    taskLabel.Click += new EventHandler(this.buttonTasks_Click);
                }

                btn.Click += new EventHandler(this.buttonDay_Click);


                this.Controls.Add(btn);

                //add day buttons to holder list
                buttons.Add(btn);
            }

            //Update labels
            MonthLabel.Text = currentMonth.ToString();
            YearLabel.Text  = currentYear.ToString();

            //Display Days of week
            for (int i = 0; i < 7; i++)
            {
                Label lbl = new Label();
                lbl.Text      = ((DayNames)i).ToString();
                lbl.Width     = daySize;
                lbl.TextAlign = ContentAlignment.TopCenter;


                lbl.Location = new Point(
                    daySize * i + boarder,
                    2 * boarder
                    );

                lbl.BackColor = System.Drawing.Color.Transparent;

                this.Controls.Add(lbl);
            }
        }
Example #16
0
 public Month(MonthNames n, int d)
 {
     monthName = n;
     numDays   = d;
 }
Example #17
0
        static void Main(string[] args)
        {
            double[] numbers = new double[2];
            for (int i = 0; i < 2; i++)
            {
                Console.WriteLine($"Вводите {i + 1} из 2 чисел");
                numbers[i] = ReadWithCheckDouble();
            }

            Console.WriteLine("Выберите операцию:\n" +
                              "нажмите 1 для сложения\n" +
                              "нажмите 2 для разности (первое - второе)\n" +
                              "нажмите 3 для умножения\n" +
                              "нажмите 4 для деления (первое/второе)\n" +
                              "нажмите 5 для возведения в степень (первое^второе)");
            int        ans = ReadWithCheckInt(limit1, limit5);
            Operations op  = (Operations)ans;

            Console.WriteLine($"Результат мат. операции {op} = {DoOperation(numbers[0], numbers[1], op):f2}");

            Console.WriteLine("Вводите номер или название месяца по английски полностью или сокращенно " +
                              "- 3 буквы с которых начинается месяц (типа Dec, Nov, Sep)");
            bool   check = false;
            string str   = null;

            ans = 0;
            while (!check)
            {
                str   = Console.ReadLine();
                check = int.TryParse(str, out ans);
                if (!check || ans < limit1 || ans > limit12)
                {
                    check = false;
                    if (str.Length >= 3)
                    {
                        check = GetMonthName(str, out ans);
                    }
                    if (!check)
                    {
                        Console.WriteLine("Что-то пошло не так, еще раз");
                    }
                }
            }

            Console.WriteLine("\nВисокосный год? Вводите y/n");
            check = false;
            str   = null;
            while (!check)
            {
                //Т.к. я проверяю знач. ans, я решил, что могу использовать именно строковую ans
                //и не заменять её на булевую переменную (ошибки не будет)
                str = Console.ReadLine();
                if (str == "y" || str == "n")
                {
                    check = true;
                }
                else
                {
                    Console.WriteLine("Некорректно, еще раз");
                }
            }
            MonthNames month = (MonthNames)ans;

            Console.WriteLine($"В месяце {month} дней " +
                              $"{((str == "y" && ans == 2) ? GetDaysInMonth(month) + 1 : GetDaysInMonth(month))}.");
        }