private void RefreshGrid2(string MaLichTrinh)
        {
            dataGridView2.Columns.Clear();
            ATINChamCongEntities context = new ATINChamCongEntities();

            switch (WorkCalendarShowType)
            {
            case "week":
                dataGridView2.Columns.Add("", "Ngày");
                dataGridView2.Rows.Add("Chủ Nhật");
                for (int i = 2; i < 8; i++)
                {
                    if (i % 2 == 0)
                    {
                        dataGridView2.Rows.Add("Thứ " + i);
                        dataGridView2.Rows[i - 1].DefaultCellStyle.BackColor = SystemColors.Control;
                        continue;
                    }
                    dataGridView2.Rows.Add("Thứ " + i);
                }
                dataGridView2.Rows.Add("Ngày Lễ");
                dataGridView2.Rows[7].DefaultCellStyle.BackColor = SystemColors.Control;
                dataGridView2.Rows[0].DefaultCellStyle.ForeColor = Color.Red;
                dataGridView2.Rows[7].DefaultCellStyle.ForeColor = Color.Blue;
                List <LichTrinhTuan> lichTrinhTuans = context.spGetLichTrinhTuanByLichTrinh(MaLichTrinh).OrderBy(c => c.DateInWeek).ToList();
                int maxcol = context.spGetAllCaLamViec().ToList().Count;
                for (int i = 1; i <= maxcol; i++)
                {
                    dataGridView2.Columns.Add("", "Ca Thứ " + i);
                }
                int count = 0;
                int tmp   = 0;
                foreach (var lictrinhtuan in lichTrinhTuans)
                {
                    if (tmp != lictrinhtuan.DateInWeek)
                    {
                        tmp = lictrinhtuan.DateInWeek;
                        dataGridView2.Rows[lictrinhtuan.DateInWeek - 1].Cells[1].Value = lictrinhtuan.MaCaLamViec;
                        count = 1;
                        continue;
                    }
                    count++;
                    dataGridView2.Rows[lictrinhtuan.DateInWeek - 1].Cells[count].Value = lictrinhtuan.MaCaLamViec;
                }
                break;

            case "month":
                dataGridView2.Columns.Add("", "Ngày");
                for (int i = 1; i < 32; i++)
                {
                    if (i % 2 == 0)
                    {
                        dataGridView2.Rows.Add("Ngày " + i);
                        dataGridView2.Rows[i - 1].DefaultCellStyle.BackColor = SystemColors.Control;
                        continue;
                    }
                    dataGridView2.Rows.Add("Ngày " + i);
                }
                dataGridView2.Rows.Add("Ngày Lễ");
                dataGridView2.Rows[31].DefaultCellStyle.BackColor = SystemColors.Control;
                dataGridView2.Rows[31].DefaultCellStyle.ForeColor = Color.Blue;
                List <LichTrinhThang> lichTrinhThangs = context.spGetLichTrinhThangByLichTrinh(MaLichTrinh).OrderBy(c => c.Date).ToList();;
                int maxcol2 = context.spGetAllCaLamViec().ToList().Count;
                for (int i = 1; i <= maxcol2; i++)
                {
                    dataGridView2.Columns.Add("", "Ca Thứ " + i);
                }
                int count2 = 0;
                int tmp2   = 0;
                foreach (var lichTrinhThang in lichTrinhThangs)
                {
                    if (tmp2 != lichTrinhThang.Date)
                    {
                        tmp2 = lichTrinhThang.Date;
                        dataGridView2.Rows[lichTrinhThang.Date - 1].Cells[1].Value = lichTrinhThang.MaCaLamViec;
                        count2 = 1;
                        continue;
                    }
                    count2++;
                    dataGridView2.Rows[lichTrinhThang.Date - 1].Cells[count2].Value = lichTrinhThang.MaCaLamViec;
                }
                break;

            case "year":
                dataGridView2.Columns.Add("", "Tháng");
                for (int i = 1; i < 13; i++)
                {
                    if (i % 2 == 0)
                    {
                        dataGridView2.Rows.Add("Tháng " + i);
                        dataGridView2.Rows[i - 1].DefaultCellStyle.BackColor = SystemColors.Control;
                        continue;
                    }
                    dataGridView2.Rows.Add("Tháng " + i);
                }
                List <LichTrinhNam> lichTrinhNams = context.spGetLichTrinhNamByLichTrinh(MaLichTrinh).OrderBy(c => c.Month).ThenBy(c => c.Date).ToList();;
                for (int i = 1; i <= 31; i++)
                {
                    dataGridView2.Columns.Add("", "Ngày " + i);
                }
                dataGridView2.Columns.Add("", "Ngày Lễ");
                dataGridView2.Columns[32].DefaultCellStyle.ForeColor = Color.Blue;
                int Date  = 0;
                int Month = 0;
                int Count = 0;     //grid cell count

                string Ca = "";
                foreach (var lichTrinhNam in lichTrinhNams)
                {
                    if (Month != lichTrinhNam.Month && Date != lichTrinhNam.Date)
                    {
                        Month = lichTrinhNam.Month;
                        Date  = lichTrinhNam.Date;
                        foreach (var obj in lichTrinhNams)
                        {
                            if (obj.Month == lichTrinhNam.Month && obj.Date == Date)
                            {
                                Ca += obj.MaCaLamViec + @"/";
                            }
                        }
                        dataGridView2.Rows[lichTrinhNam.Month - 1].Cells[Date].Value = Ca;
                        Ca = "";
                        Count++;
                        continue;
                    }
                    if (Month == lichTrinhNam.Month && Date != lichTrinhNam.Date)
                    {
                        Date = lichTrinhNam.Date;
                        foreach (var obj in lichTrinhNams)
                        {
                            if (obj.Month == lichTrinhNam.Month && obj.Date == Date)
                            {
                                Ca += obj.MaCaLamViec + @"/";
                            }
                        }
                        dataGridView2.Rows[lichTrinhNam.Month - 1].Cells[Date].Value = Ca;
                        Ca = "";
                        Count++;
                    }
                }

                break;
            }
        }
Example #2
0
        private void TreeView1Config(ListView listView)
        {
            treeView1.Nodes.Clear();
            ATINChamCongEntities context = new ATINChamCongEntities();

            foreach (ListViewItem item in listView.Items)
            {
                TreeNode node = new TreeNode(item.Text);
                node.Tag = item.Tag;
                treeView1.Nodes.Add(node);
            }
            switch (WorkCalendarShowType)
            {
            case "week":
                List <LichTrinhTuan> lichTrinhTuans = context.spGetLichTrinhTuanByLichTrinh(lichTrinh.MaLichTrinh).OrderBy(x => x.DateInWeek).ToList();
                foreach (TreeNode node in treeView1.Nodes)
                {
                    int?x = node.Tag as int?;
                    foreach (LichTrinhTuan lic in lichTrinhTuans)
                    {
                        if (x == lic.DateInWeek)
                        {
                            TreeNode childNode = new TreeNode(lic.MaCaLamViec);
                            childNode.Tag = lic;
                            node.Nodes.Add(childNode);
                        }
                    }
                }
                break;

            case "month":
                List <LichTrinhThang> lichTrinhThangs = context.spGetLichTrinhThangByLichTrinh(lichTrinh.MaLichTrinh).OrderBy(x => x.Date).ToList();
                foreach (TreeNode node in treeView1.Nodes)
                {
                    int?x = node.Tag as int?;
                    foreach (LichTrinhThang lic in lichTrinhThangs)
                    {
                        if (x == lic.Date)
                        {
                            TreeNode childNode = new TreeNode(lic.MaCaLamViec);
                            childNode.Tag = lic;
                            node.Nodes.Add(childNode);
                        }
                    }
                }
                break;

            case "year":
                List <LichTrinhNam> lichTrinhNams = context.spGetLichTrinhNamByLichTrinh(lichTrinh.MaLichTrinh).OrderBy(x => x.Month).ToList();
                foreach (TreeNode node in treeView1.Nodes)
                {
                    int?x = node.Tag as int?;
                    foreach (LichTrinhNam lic in lichTrinhNams)
                    {
                        if (x == lic.Date && (comboBox1.SelectedIndex + 1) == lic.Month)
                        {
                            TreeNode childNode = new TreeNode(lic.MaCaLamViec);
                            childNode.Tag = lic;
                            node.Nodes.Add(childNode);
                        }
                    }
                }
                break;
            }
            treeView1.ExpandAll();
        }