Ejemplo n.º 1
0
        private void LoadPhong()
        {
            DateTime s  = dtpkNgayBD.Value.Date;
            TimeSpan ts = dtpkGioDB.Value.TimeOfDay;

            s = s.Date + ts;

            DateTime f  = dtpkNgayKT.Value.Date;
            TimeSpan tf = dtpkGioKT.Value.TimeOfDay;

            f = f.Date + tf;

            int loaiphong = 1;

            if (rdbPhongdoi.Checked == true)
            {
                loaiphong = 2;
            }

            PhongBUS phongBUS = new PhongBUS();

            dt1 = phongBUS.LayDanhSachPhongTrong(s.ToString("yyyy-MM-dd HH:mm:ss"), f.ToString("yyyy-MM-dd HH:mm:ss"), loaiphong);
            DataTable dtgrid = new DataTable();

            dtgrid.Columns.Add("1");
            dtgrid.Columns.Add("2");
            dtgrid.Columns.Add("3");
            dtgrid.Columns.Add("4");
            dtgrid.Columns.Add("5");

            for (int i = 0; i < 3; i++)
            {
                DataRow r = dtgrid.NewRow();
                r[0] = (i + 1) + "0" + 1;
                r[1] = (i + 1) + "0" + 2;
                r[2] = (i + 1) + "0" + 3;
                r[3] = (i + 1) + "0" + 4;
                r[4] = (i + 1) + "0" + 5;
                dtgrid.Rows.Add(r);
            }

            gridviewPhong.DataSource = dtgrid;
            foreach (DataGridViewRow row in gridviewPhong.Rows)
            {
                row.Height = 40;
            }

            for (int i = 0; i < 5; i++)
            {
                DataGridViewButtonColumn c = (DataGridViewButtonColumn)gridviewPhong.Columns[i];
                c.FlatStyle = FlatStyle.Flat;
                c.DefaultCellStyle.ForeColor = Color.White;
                c.DefaultCellStyle.BackColor = Color.FromArgb(229, 57, 53);
            }
            gridviewPhong.AllowUserToResizeColumns = false;
            gridviewPhong.AllowUserToResizeRows    = false;
            gridviewPhong.CurrentCell = null;

            if (dt1 != null)
            {
                foreach (DataRow r in dt1.Rows)
                {
                    int maP = Convert.ToInt32(r["Ma"]);
                    if (maP % 5 == 0)
                    {
                        DataGridViewButtonCell c = (DataGridViewButtonCell)gridviewPhong.Rows[maP / 5 - 1].Cells[4];
                        c.Style.BackColor = Color.FromArgb(124, 179, 66);
                    }
                    else
                    {
                        DataGridViewButtonCell c = (DataGridViewButtonCell)gridviewPhong.Rows[maP / 5].Cells[maP % 5 - 1];
                        c.Style.BackColor = Color.FromArgb(124, 179, 66);
                    }
                }
            }
        }