public void display()
        {
            this.clMaNhom.DataPropertyName     = nameof(Nhom.MaNhom);
            this.clTenNhom.DataPropertyName    = nameof(Nhom.TenNhom);
            this.clNhomTruong.DataPropertyName = nameof(Nhom.NhomTruong);
            cbxListCongViec.DataSource         = CongViecControllers.getListCongViecfromDB();
            cbxListCongViec.DisplayMember      = "TenCongViec";


            List <Nhom>   lstNhom = NhomControllers.getListNhomfromDB();
            BindingSource src     = new BindingSource();

            src.DataSource           = lstNhom;
            dataGridView1.DataSource = src;
            if (qh == 0)
            {
                btnThemNhom.Visible = false;
                btnSuaNhom.Visible  = false;
                btnXoaNhom.Visible  = false;
            }
            else if (qh == 1)
            {
            }

            dataGridView1.Columns[3].Visible = false;
            dataGridView1.Columns[4].Visible = false;
            dataGridView1.Columns[5].Visible = false;
            dataGridView1.Columns[6].Visible = false;
        }
        private void btnXoaNhom_Click(object sender, EventArgs e)
        {
            if (this.dataGridView1.CurrentCell.Value == null)
            {
                return;
            }
            CongViec      cv    = lcv[cbxListCongViec.SelectedIndex];
            List <string> lstcv = cv.ListNhomPhuTrach.Split(',').ToList();

            foreach (var item in lstcv)
            {
                if (dataGridView1.CurrentRow.Cells[0].Value.ToString().Trim() == item.Trim())
                {
                    lstcv.Remove(item);
                    break;
                }
            }
            if (lstcv[0] != null)
            {
                cv.ListNhomPhuTrach = lstcv[0];
            }
            else
            {
                cv.ListNhomPhuTrach = "";
            }
            for (int i = 1; i < lstcv.Count; i++)
            {
                cv.ListNhomPhuTrach = cv.ListNhomPhuTrach + "," + lstcv[i];
            }
            CongViecControllers.updateCongViec(cv);
            List <NhanVien> listnv = NhanVienControllers.getListNhanVienfromDB();

            foreach (var item in listnv)
            {
                if (item.Nhom.Trim() == dataGridView1.CurrentRow.Cells[0].Value.ToString().Trim())
                {
                    NhanVienControllers.DeleteNhanVien(item);
                }
            }
            NhomControllers.DeleteNhom(dataGridView1.CurrentRow.Cells[0].Value.ToString().Trim());
            BindingSource src = new BindingSource();

            src.DataSource = NhomControllers.getListNhomfromDB();
            this.dataGridView1.DataSource = src;
        }
        private void btnSuaNhom_Click(object sender, EventArgs e)
        {
            if (this.txtNhom.Text.Trim().Length <= 0)
            {
                this.errorProvider1.SetError(this.txtNhom, "nhap ten ma nhom");
                return;
            }
            else
            {
                this.errorProvider1.Clear();
            }

            if (this.txtTenNhom.Text.Trim().Length <= 0)
            {
                this.errorProvider1.SetError(this.txtTenNhom, "nhap ten nhom");
                return;
            }
            else
            {
                this.errorProvider1.Clear();
            }
            if (this.txtNhomTruong.Text.Trim().Length <= 0)
            {
                this.errorProvider1.SetError(this.txtNhomTruong, "nhap ma nhan vien nhom truong");
                return;
            }
            else
            {
                this.errorProvider1.Clear();
            }
            Nhom nh = new Nhom();

            nh.MaNhom     = txtNhom.Text.Trim();
            nh.TenNhom    = txtTenNhom.Text.Trim();
            nh.NhomTruong = txtNhomTruong.Text.Trim();

            NhomControllers.updateNhom(nh);
            BindingSource source = new BindingSource();

            source.DataSource             = NhomControllers.getListNhomfromDB();
            this.dataGridView1.DataSource = source;
        }
예제 #4
0
        private void dataGridViewDuAn_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            chlbCongViec.Items.Clear();
            tinhChiPhiDA();
            tinhTienDoDA();
            dahoanthanh();

            cbxNhom.DataSource = null;
            if (true)
            {
                if (this.dataGridViewDuAn.Columns[e.ColumnIndex].DataPropertyName != nameof(DuAn.MaDuAn))
                {
                    if (this.dataGridViewDuAn.CurrentRow.Cells[0].Value == null)
                    {
                        MessageBox.Show("Chua nhap Ma Du An");
                        return;
                    }
                }
                if (dataGridViewDuAn.CurrentRow.Cells[3].Value == null)
                {
                    txtChiPhiDuAn.Text = "0";
                }
                else
                {
                    txtChiPhiDuAn.Text = dataGridViewDuAn.CurrentRow.Cells[3].Value.ToString();
                }
                txtMaDuAn.Text                = dataGridViewDuAn.CurrentRow.Cells[0].Value.ToString();
                txtTenDuAn.Text               = dataGridViewDuAn.CurrentRow.Cells[1].Value.ToString();
                dateTimeBatDauDuAn.Value      = DateTime.Parse(dataGridViewDuAn.CurrentRow.Cells[7].Value.ToString());
                dateNgayDuKienHoanThanh.Value = DateTime.Parse(dataGridViewDuAn.CurrentRow.Cells[6].Value.ToString());
                if (dataGridViewDuAn.CurrentRow.Cells[9].Value == null)
                {
                    dateTimeNgayHoanThanh.Value = DateTime.Parse("01/01/2000 12:00:00 AM");
                }
                else
                {
                    dateTimeNgayHoanThanh.Value = DateTime.Parse(dataGridViewDuAn.CurrentRow.Cells[9].Value.ToString());
                }

                if (dataGridViewDuAn.CurrentRow.Cells[2].Value != null)
                {
                    rtxtMucTieu.Text = dataGridViewDuAn.CurrentRow.Cells[2].Value.ToString();
                }
                if (dataGridViewDuAn.CurrentRow.Cells[8].Value == null || int.Parse(dataGridViewDuAn.CurrentRow.Cells[8].Value.ToString()) == -2147483648)
                {
                    pgbTienDoDuAn.Value = 0;
                }
                else
                {
                    pgbTienDoDuAn.Value = int.Parse(dataGridViewDuAn.CurrentRow.Cells[8].Value.ToString());
                }
                //cho ma cong viec vao => list cong viec setitemchecked
                List <DuAn> da = DuAnControllers.getListDuAnfromDB();
                if (da[dataGridViewDuAn.CurrentRow.Index].CongViecDuAn == null)
                {
                    return;
                }

                string macongviec = da[dataGridViewDuAn.CurrentRow.Index].CongViecDuAn;
                macongviec = macongviec.Trim();
                string[]        listtencongviec = macongviec.Trim().Split(',');
                List <CongViec> lcv             = CongViecControllers.getListCongViecfromDB(listtencongviec);

                foreach (var item in listtencongviec)
                {
                    chlbCongViec.Items.Add(item.Trim());
                }
                foreach (var item in lcv)
                {
                    if (item.TienDo == 100)
                    {
                        for (int i = 0; i < chlbCongViec.Items.Count; i++)
                        {
                            if (chlbCongViec.Items[i].ToString() == item.MaCongViec.ToString().Trim())
                            {
                                chlbCongViec.SetItemChecked(i, true);
                            }
                        }
                    }
                }
                List <string> listnhom = new List <string>();

                foreach (var item in listtencongviec)
                {
                    if (NhomControllers.getListNhomfromDB(item) != null)
                    {
                        string[] lstnhom = NhomControllers.getListNhomfromDB(item).Split(',');
                        foreach (var nhom in lstnhom)
                        {
                            listnhom.Add(nhom);
                        }
                    }
                }
                cbxNhom.DataSource = listnhom;
            }
            else
            {
                return;
            }
        }
        private void btnThemNhom_Click(object sender, EventArgs e)
        {
            if (this.txtNhom.Text.Trim().Length <= 0)
            {
                this.errorProvider1.SetError(this.txtNhom, "nhap ten ma nhom");
                return;
            }
            else
            {
                this.errorProvider1.Clear();
            }
            if (NhomControllers.getNhomfromDB(this.txtNhom.Text.Trim()) != "")
            {
                this.errorProvider1.SetError(this.txtNhom, "Ma nhom da ton tai");
                return;
            }
            this.errorProvider1.Clear();
            if (this.txtTenNhom.Text.Trim().Length <= 0)
            {
                this.errorProvider1.SetError(this.txtTenNhom, "nhap ten nhom");
                return;
            }
            else
            {
                this.errorProvider1.Clear();
            }
            if (this.txtNhomTruong.Text.Trim().Length <= 0)
            {
                this.errorProvider1.SetError(this.txtNhomTruong, "nhap ma nhan vien nhom truong");
                return;
            }
            else
            {
                this.errorProvider1.Clear();
            }
            if (NhanVienControllers.getNhanVienfromDB(this.txtNhomTruong.Text.Trim()) == null)
            {
                this.errorProvider1.SetError(this.txtNhom, "khong tim thay nhom truong");
                return;
            }
            this.errorProvider1.Clear();
            Nhom nh = new Nhom();

            nh.MaNhom     = txtNhom.Text.Trim();
            nh.TenNhom    = txtTenNhom.Text.Trim();
            nh.NhomTruong = txtNhomTruong.Text.Trim();

            NhomControllers.AddNhom(nh);
            BindingSource source = new BindingSource();

            source.DataSource             = NhomControllers.getListNhomfromDB();
            this.dataGridView1.DataSource = source;
            CongViec cv = CongViecControllers.getCongViecfromDB(lcv[(cbxListCongViec.SelectedIndex)].MaCongViec.Trim());

            if (cv.ListNhomPhuTrach == "" || cv.ListNhomPhuTrach == null)
            {
                cv.ListNhomPhuTrach = txtNhom.Text.Trim();
            }
            else
            {
                cv.ListNhomPhuTrach = cv.ListNhomPhuTrach.Trim() + "," + txtNhom.Text.Trim();
            }
            CongViecControllers.updateCongViec(cv);
        }