Ejemplo n.º 1
0
        public bool Add(CongTacDang item)
        {
            try
            {
                db.CongTacDangs.Add(item);
                db.SaveChanges();

                HocVien_CongTacDang temp = new HocVien_CongTacDang();
                temp.Diem          = 0;
                temp.CongTacDangID = item.ID;
                List <HocVien> hv  = db.HocViens.ToList();
                HocVienDAO     dao = new HocVienDAO();
                foreach (var x in hv)
                {
                    temp.HocVienID = x.ID;
                    dao.Add_HocVien_CongTacDang(temp);
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        private void btn_Them_Click(object sender, EventArgs e)
        {
            if (Common.Acc_type == "Root" || Common.Acc_type == "Admin")
            {
                if (btn_Them.Text == "Thêm")
                {
                    btn_Sua.Enabled = false;
                    btn_Them.Text   = "Lưu";
                    btn_Xoa.Text    = "Hủy";
                    UnLockControl();
                    Empty();
                }
                else
                {
                    CongTacDang item = new CongTacDang();

                    item.Ten = txbTen.Text;
                    try
                    {
                        item.Nam = Convert.ToInt16(txbNam.Text);
                        if (item.Nam < 1 || item.Nam > 5)
                        {
                            MessageBox.Show("Bạn đã nhập sai năm ", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Bạn đã nhập sai năm ", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                    item.Dat  = Convert.ToDouble(txbDat.Text);
                    item.Kha  = Convert.ToDouble(txbKha.Text);
                    item.Gioi = Convert.ToDouble(txbGioi.Text);

                    if (new CongTacDangDAO().Add(item))
                    {
                        LoadCongTacDang();
                        MessageBox.Show("Thêm thành công");
                    }
                    else
                    {
                        MessageBox.Show("Không thành công");
                    }
                    LockControl();
                }
            }
            else
            {
                MessageBox.Show("Bạn không có quyền thực hiện tác vụ này");
            }
        }
Ejemplo n.º 3
0
        public bool Edit(CongTacDang item)
        {
            try
            {
                CongTacDang temp = db.CongTacDangs.Find(item.ID);

                temp.Nam  = item.Nam;
                temp.Ten  = item.Ten;
                temp.Dat  = item.Dat;
                temp.Kha  = item.Kha;
                temp.Gioi = item.Gioi;

                db.SaveChanges();
                return(true);
            }
            catch
            {
                return(false);
            }
        }