Exemplo n.º 1
0
        private void BuildCalendar(int year)
        {
            //variables
            int height = 0;

            ShowPanel.FlowDirection = FlowDirection.TopDown;
            int math = 1;
            //pannel for year select
            Panel yearSelect = new Panel();

            yearSelect.AutoSize = false;


            //labeo year
            Label lbYear = new Label();

            lbYear.AutoSize = true;
            //button left
            Button btLeftYear = new Button();

            btLeftYear.Size = new Size(16, 16);
            //read image for button
            var fs  = new FileStream(@"Imagens\leftarrow.png", FileMode.Open, FileAccess.Read);
            var img = Image.FromStream(fs);

            btLeftYear.Image     = img;
            btLeftYear.Name      = "btLeftYear";
            btLeftYear.Padding   = new Padding(0);
            btLeftYear.FlatStyle = FlatStyle.Flat;
            //button right
            Button btRightArrow = new Button();;

            btRightArrow.Name      = "btRightArrow";
            btRightArrow.Image     = img;
            btRightArrow.Padding   = new Padding(0);
            btRightArrow.FlatStyle = FlatStyle.Flat;

            btRightArrow.Size = new Size(16, 16);
            FileStream fs2  = new FileStream(@"Imagens\rightarrow.png", FileMode.Open, FileAccess.Read);
            Image      img2 = Image.FromStream(fs2);

            btRightArrow.Image = img2;
            var auxmargin = lbYear.Margin;

            auxmargin.All     = 0;
            btLeftYear.Margin = auxmargin;
            //deal with space
            var margin = lbYear.Margin;



            btLeftYear.Padding = new Padding(0);
            lbYear.Text        = year.ToString();
            lbYear.Font        = new Font("Times New Roman", 10.0f, FontStyle.Bold);
            lbYear.ForeColor   = Color.Black;


            yearSelect.Margin    = auxmargin;
            yearSelect.Padding   = new Padding(0);
            yearSelect.BackColor = ColorTranslator.FromHtml("#CF6766");


            yearSelect.Controls.Add(btLeftYear);

            yearSelect.Controls.Add(lbYear);

            yearSelect.Controls.Add(btRightArrow);
            yearSelect.Controls.SetChildIndex(btLeftYear, 2);

            yearSelect.Controls.SetChildIndex(lbYear, 1);
            //YearSelect.Controls.SetChildIndex(btRightArrow, 2);



            ShowPanel.Controls.Add(yearSelect);
            //divide months into panels for stacking horizontally and vertically
            //4 panels with 3 calendars or 3 with 4 dunno yet
            for (int c = 1; c <= 3; c++)
            {
                //panel colum
                FlowLayoutPanel rowMonthPanel = new FlowLayoutPanel();

                rowMonthPanel.FlowDirection = FlowDirection.LeftToRight;
                rowMonthPanel.Tag           = $"Row{c + 1}";
                //add 4 months to row panel

                for (int i = 1; i <= 4; i++)
                {
                    MonthCalendar calendar = new MonthCalendar();

                    calendar.Tag  = $"month{math}";
                    calendar.Name = math.ToString();
                    //add date value to calendar
                    //shows calendar month as well
                    //sets all settings of calendars
                    calendar.ActiveMonth.Year      = year;
                    calendar.ActiveMonth.Month     = math;
                    calendar.Header.ShowMonth      = false;
                    calendar.Header.Text           = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(math);
                    calendar.Footer.ShowToday      = false;
                    calendar.Header.MonthSelectors = false;
                    calendar.Header.BackColor1     = ColorTranslator.FromHtml("#CF6766");
                    calendar.Weekdays.TextColor    = ColorTranslator.FromHtml("#0E1116");
                    calendar.KeyboardEnabled       = false;


                    calendar.Weekdays.Font = new Font("Arial", 7);
                    DateItem[] d = new DateItem[5];
                    d.Initialize();
                    for (int k = 0; k < 5; k++)
                    {
                        d[k] = new DateItem();
                    }
                    height = calendar.Height;
                    rowMonthPanel.Controls.Add(calendar);
                    math++;
                }

                //RowMonthPanel.BackColor = ColorTranslator.FromHtml("#D8DBE2");


                yearSelect.Dock    = DockStyle.Top;
                rowMonthPanel.Size = new Size(ShowPanel.Width, height + 3);
                //year top panel settings
                yearSelect.MaximumSize = new Size(rowMonthPanel.Width - 45, 16);

                btLeftYear.Dock = DockStyle.Left;
                //last part of dealing with label position
                lbYear.Dock       = DockStyle.Fill;
                lbYear.AutoSize   = false;
                lbYear.TextAlign  = ContentAlignment.MiddleCenter;
                btRightArrow.Dock = DockStyle.Right;
                //btRightArrow.Click += new EventHandler(this.YearChange);
                //btLeftYear.Click += new EventHandler(this.YearChange);



                ShowPanel.BackColor = ColorTranslator.FromHtml("#D8DBE2");
                ShowPanel.Controls.Add(rowMonthPanel);
            }
            btLeftYear.Click += delegate
            {
                YearChange(-1);
            };
            btRightArrow.Click += delegate
            {
                YearChange(1);
            };
        }
        public void TextOfDay(int intNam, MonthCalendar monthCa)
        {
            int i;

            if (intNam % 4 == 0)
            {
                i = 1;
            }
            else
            {
                i = 0;
            }
            int Thang1  = 31;
            int Thang2  = Thang1 + 28 + i;
            int Thang3  = Thang2 + 31;
            int Thang4  = Thang3 + 30;
            int Thang5  = Thang4 + 31;
            int Thang6  = Thang5 + 30;
            int Thang7  = Thang6 + 31;
            int Thang8  = Thang7 + 31;
            int Thang9  = Thang8 + 30;
            int Thang10 = Thang9 + 31;
            int Thang11 = Thang10 + 30;
            int Thang12 = Thang11 + 31;

            DateItem[] d = new DateItem[365 + i];
            d.Initialize();
            for (int k = 0; k < 365 + i; k++)
            {
                d[k] = new DateItem();
            }
            //for (int k = intNumberYear; k < intDieuKien; k++)
            //    d[k] = new DateItem();
            for (int j = 0; j < 365 + i; j++)
            {
                if (j < Thang1)
                {
                    d[j].Date = new DateTime(intNam, 1, j + 1);
                    string strNgayAm = chuyendoingay.convertSolar2Lunar(j + 1, 1, intNam);
                    if (strNgayAm.Substring(0, 2) == "1/")
                    {
                        d[j].Text = strNgayAm;
                        strNgayAm = chuyendoingay.convertSolar2Lunar(j, 1, intNam);
                        try
                        {
                            d[j - 1].Text = strNgayAm;
                        }
                        catch
                        {
                            DateItem[] date = new DateItem[1];
                            date.Initialize();
                            date[0]      = new DateItem();
                            date[0].Date = new DateTime(intNam - 1, 12, 31);
                            string strDateAm = chuyendoingay.convertSolar2Lunar(31, 12, intNam - 1);
                            date[0].Text = strDateAm;
                        }
                    }
                    else
                    {
                        int a = strNgayAm.IndexOf("/");
                        d[j].Text = strNgayAm.Substring(0, a);
                    }
                    //Chủ Nhật Màu Đỏ
                    int intTinhThu = tinhThu.ThuTrongThang(intNam, 1, j + 1);
                    if (intTinhThu % 7 == 1)
                    {
                        //d[j].TextColor = Color.Red;
                        d[j].DateColor = Color.Red;
                    }
                }
                if (j >= Thang1 && j < Thang2)
                {
                    d[j].Date = new DateTime(intNam, 2, ((j + 1) - Thang1));
                    string strNgayAm = chuyendoingay.convertSolar2Lunar((j + 1) - Thang1, 2, intNam);
                    if (strNgayAm.Substring(0, 2) == "1/")
                    {
                        d[j].Text     = strNgayAm;
                        strNgayAm     = chuyendoingay.convertSolar2Lunar(j - Thang1, 2, intNam);
                        d[j - 1].Text = strNgayAm;
                    }
                    else
                    {
                        int a = strNgayAm.IndexOf("/");
                        d[j].Text = strNgayAm.Substring(0, a);
                    }
                    //Chủ Nhật Màu Đỏ
                    int intTinhThu = tinhThu.ThuTrongThang(intNam, 2, ((j + 1) - Thang1));
                    if (intTinhThu % 7 == 1)
                    {
                        //d[j].TextColor = Color.Red;
                        d[j].DateColor = Color.Red;
                    }
                }
                if (j >= Thang2 && j < Thang3)
                {
                    d[j].Date = new DateTime(intNam, 3, (j + 1) - Thang2);
                    string strNgayAm = chuyendoingay.convertSolar2Lunar((j + 1) - Thang2, 3, intNam);
                    if (strNgayAm.Substring(0, 2) == "1/")
                    {
                        d[j].Text     = strNgayAm;
                        strNgayAm     = chuyendoingay.convertSolar2Lunar(j - Thang2, 3, intNam);
                        d[j - 1].Text = strNgayAm;
                    }
                    else
                    {
                        int a = strNgayAm.IndexOf("/");
                        d[j].Text = strNgayAm.Substring(0, a);
                    }
                    //Chủ Nhật Màu Đỏ
                    int intTinhThu = tinhThu.ThuTrongThang(intNam, 3, (j + 1) - Thang2);
                    if (intTinhThu % 7 == 1)
                    {
                        //d[j].TextColor = Color.Red;
                        d[j].DateColor = Color.Red;
                    }
                }
                if (j >= Thang3 && j < Thang4)
                {
                    d[j].Date = new DateTime(intNam, 4, (j + 1) - Thang3);
                    string strNgayAm = chuyendoingay.convertSolar2Lunar((j + 1) - Thang4, 4, intNam);
                    if (strNgayAm.Substring(0, 2) == "1/")
                    {
                        d[j].Text     = strNgayAm;
                        strNgayAm     = chuyendoingay.convertSolar2Lunar(j - Thang3, 4, intNam);
                        d[j - 1].Text = strNgayAm;
                    }
                    else
                    {
                        int a = strNgayAm.IndexOf("/");
                        d[j].Text = strNgayAm.Substring(0, a);
                    }
                    //Chủ Nhật Màu Đỏ
                    int intTinhThu = tinhThu.ThuTrongThang(intNam, 4, (j + 1) - Thang3);
                    if (intTinhThu % 7 == 1)
                    {
                        //d[j].TextColor = Color.Red;
                        d[j].DateColor = Color.Red;
                    }
                }
                if (j >= Thang4 && j < Thang5)
                {
                    d[j].Date = new DateTime(intNam, 5, (j + 1) - Thang4);
                    string strNgayAm = chuyendoingay.convertSolar2Lunar((j + 1) - Thang4, 5, intNam);
                    if (strNgayAm.Substring(0, 2) == "1/")
                    {
                        d[j].Text     = strNgayAm;
                        strNgayAm     = chuyendoingay.convertSolar2Lunar(j - Thang4, 5, intNam);
                        d[j - 1].Text = strNgayAm;
                    }
                    else
                    {
                        int a = strNgayAm.IndexOf("/");
                        d[j].Text = strNgayAm.Substring(0, a);
                    }
                    //Chủ Nhật Màu Đỏ
                    int intTinhThu = tinhThu.ThuTrongThang(intNam, 5, (j + 1) - Thang4);
                    if (intTinhThu % 7 == 1)
                    {
                        //d[j].TextColor = Color.Red;
                        d[j].DateColor = Color.Red;
                    }
                }
                if (j >= Thang5 && j < Thang6)
                {
                    d[j].Date = new DateTime(intNam, 6, (j + 1) - Thang5);
                    string strNgayAm = chuyendoingay.convertSolar2Lunar((j + 1) - Thang5, 6, intNam);
                    if (strNgayAm.Substring(0, 2) == "1/")
                    {
                        d[j].Text     = strNgayAm;
                        strNgayAm     = chuyendoingay.convertSolar2Lunar(j - Thang5, 6, intNam);
                        d[j - 1].Text = strNgayAm;
                    }
                    else
                    {
                        int a = strNgayAm.IndexOf("/");
                        d[j].Text = strNgayAm.Substring(0, a);
                    }
                    //Chủ Nhật Màu Đỏ
                    int intTinhThu = tinhThu.ThuTrongThang(intNam, 6, (j + 1) - Thang5);
                    if (intTinhThu % 7 == 1)
                    {
                        //d[j].TextColor = Color.Red;
                        d[j].DateColor = Color.Red;
                    }
                }
                if (j >= Thang6 && j < Thang7)
                {
                    d[j].Date = new DateTime(intNam, 7, (j + 1) - Thang6);
                    string strNgayAm = chuyendoingay.convertSolar2Lunar((j + 1) - Thang6, 7, intNam);
                    if (strNgayAm.Substring(0, 2) == "1/")
                    {
                        d[j].Text     = strNgayAm;
                        strNgayAm     = chuyendoingay.convertSolar2Lunar(j - Thang6, 7, intNam);
                        d[j - 1].Text = strNgayAm;
                    }
                    else
                    {
                        int a = strNgayAm.IndexOf("/");
                        d[j].Text = strNgayAm.Substring(0, a);
                    }
                    //Chủ Nhật Màu Đỏ
                    int intTinhThu = tinhThu.ThuTrongThang(intNam, 7, (j + 1) - Thang6);
                    if (intTinhThu % 7 == 1)
                    {
                        //d[j].TextColor = Color.Red;
                        d[j].DateColor = Color.Red;
                    }
                }
                if (j >= Thang7 && j < Thang8)
                {
                    d[j].Date = new DateTime(intNam, 8, (j + 1) - Thang7);
                    string strNgayAm = chuyendoingay.convertSolar2Lunar((j + 1) - Thang7, 8, intNam);
                    if (strNgayAm.Substring(0, 2) == "1/")
                    {
                        d[j].Text     = strNgayAm;
                        strNgayAm     = chuyendoingay.convertSolar2Lunar(j - Thang7, 8, intNam);
                        d[j - 1].Text = strNgayAm;
                    }
                    else
                    {
                        int a = strNgayAm.IndexOf("/");
                        d[j].Text = strNgayAm.Substring(0, a);
                    }
                    //Chủ Nhật Màu Đỏ
                    int intTinhThu = tinhThu.ThuTrongThang(intNam, 8, (j + 1) - Thang7);
                    if (intTinhThu % 7 == 1)
                    {
                        //d[j].TextColor = Color.Red;
                        d[j].DateColor = Color.Red;
                    }
                }
                if (j >= Thang8 && j < Thang9)
                {
                    d[j].Date = new DateTime(intNam, 9, (j + 1) - Thang8);
                    string strNgayAm = chuyendoingay.convertSolar2Lunar((j + 1) - Thang8, 9, intNam);
                    if (strNgayAm.Substring(0, 2) == "1/")
                    {
                        d[j].Text     = strNgayAm;
                        strNgayAm     = chuyendoingay.convertSolar2Lunar(j - Thang8, 9, intNam);
                        d[j - 1].Text = strNgayAm;
                    }
                    else
                    {
                        int a = strNgayAm.IndexOf("/");
                        d[j].Text = strNgayAm.Substring(0, a);
                    }
                    //Chủ Nhật Màu Đỏ
                    int intTinhThu = tinhThu.ThuTrongThang(intNam, 9, (j + 1) - Thang8);
                    if (intTinhThu % 7 == 1)
                    {
                        //d[j].TextColor = Color.Red;
                        d[j].DateColor = Color.Red;
                    }
                }
                if (j >= Thang9 && j < Thang10)
                {
                    d[j].Date = new DateTime(intNam, 10, (j + 1) - Thang9);
                    string strNgayAm = chuyendoingay.convertSolar2Lunar((j + 1) - Thang9, 10, intNam);
                    if (strNgayAm.Substring(0, 2) == "1/")
                    {
                        d[j].Text     = strNgayAm;
                        strNgayAm     = chuyendoingay.convertSolar2Lunar(j - Thang9, 10, intNam);
                        d[j - 1].Text = strNgayAm;
                    }
                    else
                    {
                        int a = strNgayAm.IndexOf("/");
                        d[j].Text = strNgayAm.Substring(0, a);
                    }
                    //Chủ Nhật Màu Đỏ
                    int intTinhThu = tinhThu.ThuTrongThang(intNam, 10, (j + 1) - Thang9);
                    if (intTinhThu % 7 == 1)
                    {
                        //d[j].TextColor = Color.Red;
                        d[j].DateColor = Color.Red;
                    }
                }
                if (j >= Thang10 && j < Thang11)
                {
                    d[j].Date = new DateTime(intNam, 11, (j + 1) - Thang10);
                    string strNgayAm = chuyendoingay.convertSolar2Lunar((j + 1) - Thang10, 11, intNam);
                    if (strNgayAm.Substring(0, 2) == "1/")
                    {
                        d[j].Text     = strNgayAm;
                        strNgayAm     = chuyendoingay.convertSolar2Lunar(j - Thang10, 11, intNam);
                        d[j - 1].Text = strNgayAm;
                    }
                    else
                    {
                        int a = strNgayAm.IndexOf("/");
                        d[j].Text = strNgayAm.Substring(0, a);
                    }
                    //Chủ Nhật Màu Đỏ
                    int intTinhThu = tinhThu.ThuTrongThang(intNam, 11, (j + 1) - Thang10);
                    if (intTinhThu % 7 == 1)
                    {
                        //d[j].TextColor = Color.Red;
                        d[j].DateColor = Color.Red;
                    }
                }
                if (j >= Thang11 && j < Thang12)
                {
                    d[j].Date = new DateTime(intNam, 12, (j + 1) - Thang11);
                    string strNgayAm = chuyendoingay.convertSolar2Lunar((j + 1) - Thang11, 12, intNam);
                    if (strNgayAm.Substring(0, 2) == "1/")
                    {
                        d[j].Text     = strNgayAm;
                        strNgayAm     = chuyendoingay.convertSolar2Lunar(j - Thang11, 12, intNam);
                        d[j - 1].Text = strNgayAm;
                    }
                    else
                    {
                        int a = strNgayAm.IndexOf("/");
                        d[j].Text = strNgayAm.Substring(0, a);
                    }
                    //Chủ Nhật Màu Đỏ
                    int intTinhThu = tinhThu.ThuTrongThang(intNam, 12, (j + 1) - Thang11);
                    if (intTinhThu % 7 == 1)
                    {
                        //d[j].TextColor = Color.Red;
                        d[j].DateColor = Color.Red;
                    }
                }

                //Ngày Tết Thì Màu Đỏ
                if (d[j].Text == "1/1")
                {
                    d[j].TextColor     = Color.Red;
                    d[j].DateColor     = Color.Red;
                    d[j - 1].TextColor = Color.Red;
                    d[j - 1].DateColor = Color.Red;
                    d[j + 1].TextColor = Color.Red;
                    d[j + 1].DateColor = Color.Red;
                    d[j + 2].TextColor = Color.Red;
                    d[j + 2].DateColor = Color.Red;
                }
            }
            monthCa.AddDateInfo(d);
        }
Exemplo n.º 3
0
        private void LoadFuncFerias(FeriasColletionItem feriasCol)
        {
            int     auxMonthS = 0;
            int     auxMonthE = 0;
            Control tagFound  = new Control();

            Control row1 = ShowPanel.Controls[1];
            Control row2 = ShowPanel.Controls[2];
            Control row3 = ShowPanel.Controls[3];

            foreach (FeriasItem feriasItem in feriasCol.ListaFerias)
            {
                //auxiliary variables

                DateTime currentDate = new DateTime();
                //get first and last vacation days
                auxMonthS = feriasItem.InicioFerias.Month;
                auxMonthE = feriasItem.FimFerias.Month;
                //calculates the number of days
                int numberOfDaysFerias = Math.Abs((feriasItem.InicioFerias - feriasItem.FimFerias).Days);
                //calculates number of months
                int numberOfMonths = auxMonthE - auxMonthS + 1;

                //inicialize dateitems for calendar
                //DateItem[] d = new DateItem[NumberOfDaysFerias];
                //d.Initialize();
                //for (int j = 0; j < NumberOfDaysFerias; j++)
                //    d[j] = new DateItem();
                int auxCounter = 0;


                List <DateItem> listD = new List <DateItem>();

                //repeat if more then 1 month
                for (int m = 1; m <= numberOfMonths; m++)
                {
                    Control calendarControl = new Control();
                    if (auxMonthS != 0)
                    {
                        if (auxMonthS > 0 && auxMonthS < 5)
                        {
                            calendarControl = HelperClass.FindTag(row1.Controls, $"month{auxMonthS}");
                        }
                        else if (auxMonthS > 4 && auxMonthS < 9)
                        {
                            calendarControl = HelperClass.FindTag(row2.Controls, $"month{auxMonthS}");
                        }
                        else
                        {
                            calendarControl = HelperClass.FindTag(row3.Controls, $"month{auxMonthS}");
                        }
                    }

                    MonthCalendar calendarToAdd = (MonthCalendar)calendarControl ?? throw new Exception("Algo deu ruim no calendario");


                    //cast dates to dateitems
                    for (int i = auxCounter; i <= numberOfDaysFerias; i++)
                    {
                        //compare current months
                        currentDate = feriasItem.InicioFerias.AddDays(i);


                        //make sure same month
                        if (auxMonthS == currentDate.Month)
                        {
                            DateItem d = new DateItem();
                            //add date to dateitem
                            d.Date = currentDate;
                            FileStream fs        = new FileStream(@"Imagens\sunny.png", FileMode.Open, FileAccess.Read);
                            Image      img       = Image.FromStream(fs);
                            Bitmap     objBitmap = new Bitmap(img, new Size(10, 10));
                            ImageList  list      = new ImageList();



                            d.Image = objBitmap;

                            fs.Close();
                            d.BackColor1 = Color.Red;
                            listD.Add(d);
                        }
                        else
                        {
                            auxMonthS += 1;
                            break;
                        }

                        auxCounter++;
                    }
                    DateItem[] e = new DateItem[listD.Count()];
                    e.Initialize();
                    for (int i = 0; i < listD.Count(); i++)
                    {
                        e[i] = listD[i];
                    }
                    calendarToAdd.AddDateInfo(e);
                }
            }
        }