Beispiel #1
0
 // helper
 private void AddColumn(string name, Type type)
 {
     C1.Win.C1FlexGrid.Column col = _flex.Cols.Add();
     col.Name     = name;
     col.Caption  = name;
     col.DataType = type;
 }
Beispiel #2
0
 private static void ShowColumnWithHeader(C1.Win.C1FlexGrid.C1FlexGrid grd, string originalColName, string newColName)
 {
     C1.Win.C1FlexGrid.Column col = grd.Cols[originalColName];
     col.Caption      = newColName;
     col.Visible      = true;
     col.AllowEditing = false;
 }
Beispiel #3
0
        private void frmLich_Load(object sender, EventArgs e)
        {
            height             = (Screen.PrimaryScreen.WorkingArea.Height - 300);
            width              = (Screen.PrimaryScreen.WorkingArea.Width - 400) / 7;
            dtNow              = DateTime.Now;
            cheDoXem           = 3;
            fg.Cols[0].Caption = "Chủ nhật";
            fg.Cols[0].Width   = width;

            fg.Cols[0].Style = csNghi;
            for (int c = 0; c < 6; ++c)
            {
                C1.Win.C1FlexGrid.Column col = fg.Cols.Add();
                col.Width   = width;
                col.Caption = "Thứ " + (c + 2);
                col.Name    = c.ToString();
            }
            fg.Styles.Normal.ImageAlign = ImageAlignEnum.Stretch;
            LoadCombobox();
            LoadView(cheDoXem);
        }
Beispiel #4
0
        private void LoadView(int cheDo)
        {
            InstalCsStyle();

            fg.BeginUpdate();

            fg.ClearRows();
            if (cheDo == 1)
            {
            }
            if (cheDo == 2)
            {
                fg.Cols[1].Caption = "Chủ nhật";
                fg.Cols[1].Width   = 205;
                fg.Cols[1].Style   = csNghi;
                for (int c = 0; c < 7; ++c)
                {
                    C1.Win.C1FlexGrid.Column col = fg.Cols.Add();
                    col.Width   = 200;
                    col.Caption = "Thứ " + (c + 2);
                    col.Name    = c.ToString();
                }
                for (int r = 1; r <= 30; ++r)
                {
                    C1.Win.C1FlexGrid.Row row = fg.Rows.Add();
                    for (int c = fg.Cols.Fixed; c < fg.Cols.Count; ++c)
                    {
                        if (r % 6 == 0)
                        {
                            this.fg.SetCellStyle(r, c, "b");
                        }
                    }
                }
                for (int c = fg.Cols.Fixed + 1; c < fg.Cols.Count; ++c)
                {
                    fg.Cols[c].Style = csNgayThuong;
                }
                fg.Cols[fg.Cols.Fixed].Style = csNghi;
                DateTime d = firstDayCalendar;
                for (int r = fg.Rows.Fixed; r < fg.Rows.Count; r += 6)
                {
                    for (int c = fg.Cols.Fixed; c < fg.Cols.Count; ++c)
                    {
                        if (d.Day == 1)
                        {
                            fg[r, c] = d.Day + " tháng " + d.Month;
                        }
                        else
                        {
                            fg[r, c] = d.Day;
                        }
                        d = d.AddDays(1);
                    }
                }
            }
            if (cheDo == 3)
            {
                DateTime date = monthCalendar.SelectionRange.Start;
                int      totalCalendarDays = 42; // matrix 7 x 5

                // set the first month day
                DateTime firstDayMonth = new DateTime(date.Year, date.Month, 1);

                // set the lastmonth day
                DateTime lastDayMonth = new DateTime(date.Year, date.Month, DateTime.DaysInMonth(date.Year, date.Month));

                // now get the first day week of the first day month (0-6 Sun-Sat)
                byte firstDayWeek = (byte)firstDayMonth.DayOfWeek;

                // now get the first day week of the last day month (0-6 Sun-Sat)
                byte lastDayWeek = (byte)lastDayMonth.DayOfWeek;

                // now the first day show in calendar is the first day month minus the days to 0 (sunday)
                firstDayCalendar = firstDayMonth.Subtract(TimeSpan.FromDays(firstDayWeek));
                int tempDays = (lastDayMonth - firstDayCalendar).Days;

                lastDayCalendar = lastDayMonth.Add(TimeSpan.FromDays(totalCalendarDays - tempDays - 1));

                for (int r = 1; r <= 36; ++r)
                {
                    C1.Win.C1FlexGrid.Row row = fg.Rows.Add();
                    for (int c = fg.Cols.Fixed; c < fg.Cols.Count; ++c)
                    {
                        if (r % 6 == 0)
                        {
                            this.fg.SetCellStyle(r, c, "b");
                        }
                    }
                }
                for (int c = fg.Cols.Fixed + 1; c < fg.Cols.Count; ++c)
                {
                    fg.Cols[c].Style = csNgayThuong;
                }
                DateTime    d             = firstDayCalendar;
                clsCongViec cls           = new clsCongViec();
                DataTable   dt_DsNgayNghi = cls.DS_NgayNghi(firstDayCalendar, lastDayCalendar);

                for (int r = fg.Rows.Fixed; r < fg.Rows.Count; r += 6)
                {
                    for (int c = fg.Cols.Fixed; c < fg.Cols.Count; ++c)
                    {
                        if (d.Day == 1)
                        {
                            fg[r, c] = d.Day + "/" + d.Month;
                        }
                        else
                        {
                            fg[r, c] = d.Day + "/" + d.Month;
                        }
                        if (d.Date == dtNow.Date)
                        {
                            for (int i = 0; i < 1; ++i)
                            {
                                CellRange range = fg.GetCellRange(r + i, c);
                                range.Style = csNgayHomNay;
                            }
                        }
                        if (Trong_DsNgayNghi(dt_DsNgayNghi, d))
                        {
                            for (int i = 0; i < 1; ++i)
                            {
                                CellRange range = fg.GetCellRange(r + i, c);
                                range.Style = csNghi;
                            }
                        }
                        d = d.AddDays(1);
                    }
                }

                LoadCalendar(cheDo, firstDayCalendar);

                fg.AllowMerging = AllowMergingEnum.Custom;
                for (int i = fg.Rows.Fixed; i < fg.Rows.Count; ++i)
                {
                    fg.Rows[i].AllowMerging = true;
                }
            }

            fg.EndUpdate();
            fg.AllowMerging = AllowMergingEnum.Free;
        }