Ejemplo n.º 1
0
        protected void btnSua_Command(object sender, CommandEventArgs e)
        {
            txtID.Enabled = false;
            string id_admin = e.CommandArgument.ToString();

            Models.Quan_Ly_Nhan_SuEntities db = new Models.Quan_Ly_Nhan_SuEntities();
            Models.Admin obj = db.Admin.FirstOrDefault(x => x.id_admin == id_admin);
            txtID.Text                = obj.id_admin;
            txtTenAdm.Text            = obj.ten_admin;
            txtUser.Text              = obj.username;
            txtPass.Text              = obj.password;
            txtPhanquyen.Text         = obj.phan_quyen;
            txtNgaysinh.Text          = obj.ngay_sinh.ToString();
            txtSex.Text               = obj.gioi_tinh;
            txtSdt.Text               = obj.sdt;
            txtEmail.Text             = obj.email;
            txtQue.Text               = obj.que;
            cmdChucvu.SelectedValue   = obj.id_chucvu;
            cmbPhongban.SelectedValue = obj.id_phongban;
            txtCre.Text               = obj.create_at.ToString();
            txtUpd.Text               = obj.update_at.ToString();
            pnInfo.Visible            = true;
            btnLuu.Visible            = true;
            txtID.ReadOnly            = true;
        }
Ejemplo n.º 2
0
 public string getAnhDaiDien(string MaSP)
 {
     Models.Quan_Ly_Nhan_SuEntities db = new Models.Quan_Ly_Nhan_SuEntities();
     Models.Admin obj = db.Admin.FirstOrDefault(x => x.id_admin == MaSP);
     if (obj == null)
     {
         return("");
     }
     else
     {
         return(obj.image_admin);
     }
 }
Ejemplo n.º 3
0
        protected void btnXoa_Command(object sender, CommandEventArgs e)
        {
            string MaAdmin = e.CommandArgument.ToString();

            Models.Quan_Ly_Nhan_SuEntities db = new Models.Quan_Ly_Nhan_SuEntities();
            Models.Admin obj = db.Admin.FirstOrDefault(x => x.id_admin == MaAdmin);
            if (obj != null)
            {
                db.Admin.Remove(obj);
                db.SaveChanges();
                getData();
            }
        }
Ejemplo n.º 4
0
        protected void btnSua_Command(object sender, CommandEventArgs e)
        {
            txtID.Enabled     = false;
            txtUser.Enabled   = false;
            txtTenAdm.Enabled = false;
            string id_admin = e.CommandArgument.ToString();

            Models.Quan_Ly_Nhan_SuEntities db = new Models.Quan_Ly_Nhan_SuEntities();
            Models.Admin obj = db.Admin.FirstOrDefault(x => x.id_admin == id_admin);
            txtID.Text        = obj.id_admin;
            txtTenAdm.Text    = obj.ten_admin;
            txtUser.Text      = obj.username;
            txtPass.Text      = obj.password;
            txtPhanquyen.Text = obj.phan_quyen;
            pnInfo.Visible    = true;
            btnLuu.Visible    = true;
            txtID.ReadOnly    = true;
        }
Ejemplo n.º 5
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         getChucVu();
         getPhongban();
         getData();
         if (Request.QueryString["id_admin"] == null || Request.QueryString["id_admin"].ToString() == "")
         {
             btnLuu.Visible     = false;
             btnThemmoi.Visible = true;
             txtID.Enabled      = true;
         }
         else
         {
             // Đây là trường hợp sửa
             btnLuu.Visible     = true;
             btnThemmoi.Visible = false;
             txtID.Enabled      = false;
             // Đổ dữ liệu lên form
             string MaAdmin = Request.QueryString["id_admin"].ToString();
             Models.Quan_Ly_Nhan_SuEntities db = new Models.Quan_Ly_Nhan_SuEntities();
             Models.Admin obj = db.Admin.FirstOrDefault(x => x.id_admin == MaAdmin);
             if (obj != null)
             {
                 txtID.Text                = obj.id_admin;
                 txtTenAdm.Text            = obj.ten_admin;
                 txtUser.Text              = obj.username;
                 txtPass.Text              = obj.password;
                 txtPhanquyen.Text         = obj.phan_quyen;
                 txtNgaysinh.Text          = obj.ngay_sinh.ToString();
                 txtSex.Text               = obj.gioi_tinh;
                 txtSdt.Text               = obj.sdt;
                 txtEmail.Text             = obj.email;
                 txtQue.Text               = obj.que;
                 cmdChucvu.SelectedValue   = obj.id_chucvu;
                 cmbPhongban.SelectedValue = obj.id_phongban;
                 txtCre.Text               = obj.create_at.ToString();
                 txtUpd.Text               = obj.update_at.ToString();
             }
         }
     }
 }
Ejemplo n.º 6
0
        protected void btnLuu_Command(object sender, CommandEventArgs e)
        {
            try
            {
                Models.Quan_Ly_Nhan_SuEntities db = new Models.Quan_Ly_Nhan_SuEntities();
                string       id_admin             = txtID.Text;
                Models.Admin obj = db.Admin.FirstOrDefault(x => x.id_admin == id_admin);
                obj.id_admin   = txtID.Text;
                obj.ten_admin  = txtTenAdm.Text;
                obj.username   = txtUser.Text;
                obj.password   = txtPass.Text;
                obj.phan_quyen = txtPhanquyen.Text;


                db.SaveChanges();
                Response.Redirect("User.aspx");
            }
            catch
            {
            }
        }
Ejemplo n.º 7
0
        protected void btnLuu_Command(object sender, CommandEventArgs e)
        {
            if (btnLuu.Text == "Thêm")
            {
                // Kiểm tra mã có tồn tại chưa?
                Models.Quan_Ly_Nhan_SuEntities db = new Models.Quan_Ly_Nhan_SuEntities();
                string       id_admin             = txtID.Text;
                Models.Admin obj = db.Admin.FirstOrDefault(x => x.id_admin == id_admin);
                if (obj != null)
                {
                    pnError.Visible     = true;
                    lbError.Text        = "Mã Admin bị trùng, xem chi tiết tại ";
                    hpError.Text        = id_admin;
                    hpError.NavigateUrl = "Admin.aspx?id_admin=" + id_admin;
                }
                else
                {
                    obj             = new Models.Admin();
                    obj.id_admin    = txtID.Text;
                    obj.ten_admin   = txtTenAdm.Text;
                    obj.username    = txtUser.Text;
                    obj.password    = txtPass.Text;
                    obj.phan_quyen  = txtPhanquyen.Text;
                    obj.ngay_sinh   = Convert.ToDateTime(txtNgaysinh.Text);
                    obj.gioi_tinh   = txtSex.Text;
                    obj.sdt         = txtSdt.Text;
                    obj.email       = txtEmail.Text;
                    obj.que         = txtQue.Text;
                    obj.id_chucvu   = cmdChucvu.SelectedValue;
                    obj.id_phongban = cmbPhongban.SelectedValue;
                    obj.create_at   = Convert.ToDateTime(txtCre.Text);
                    obj.update_at   = Convert.ToDateTime(txtUpd.Text);
                    if (fuImg.HasFile == true)
                    {
                        // Bước 1: Tải file về server
                        // Sinh tên file
                        string   filename = DateTime.Now.ToString("yyyyMMddHHmmssffff");
                        string[] arr      = fuImg.FileName.Split('.');
                        string   file_ext = arr[arr.Length - 1];
                        filename += '.' + file_ext;
                        string folder = Server.MapPath("/Uploads/Image/");
                        fuImg.SaveAs(folder + filename);

                        // Bước 2: Thêm dữ liệu vào Database
                        obj.image_admin = filename;
                    }

                    db.Admin.Add(obj);
                    db.SaveChanges();
                    getData();
                    Response.Redirect("Admin.aspx");
                }
            }
            else
            {
                try
                {
                    Models.Quan_Ly_Nhan_SuEntities db = new Models.Quan_Ly_Nhan_SuEntities();
                    string       id_admin             = txtID.Text;
                    Models.Admin obj = db.Admin.FirstOrDefault(x => x.id_admin == id_admin);
                    obj.id_admin    = txtID.Text;
                    obj.ten_admin   = txtTenAdm.Text;
                    obj.username    = txtUser.Text;
                    obj.password    = txtPass.Text;
                    obj.phan_quyen  = txtPhanquyen.Text;
                    obj.ngay_sinh   = DateTime.Parse(txtNgaysinh.Text);
                    obj.gioi_tinh   = txtSex.Text;
                    obj.sdt         = txtSdt.Text;
                    obj.email       = txtEmail.Text;
                    obj.que         = txtQue.Text;
                    obj.id_chucvu   = cmdChucvu.SelectedValue;
                    obj.id_phongban = cmbPhongban.SelectedValue;
                    obj.create_at   = DateTime.Parse(txtCre.Text);
                    obj.update_at   = DateTime.Parse(txtUpd.Text);
                    if (fuImg.HasFile == true)
                    {
                        // Bước 1: Tải file về server
                        // Sinh tên file
                        string   filename = DateTime.Now.ToString("yyyyMMddHHmmssffff");
                        string[] arr      = fuImg.FileName.Split('.');
                        string   file_ext = arr[arr.Length - 1];
                        filename += '.' + file_ext;
                        string folder = Server.MapPath("/Uploads/Image/");
                        fuImg.SaveAs(folder + filename);
                        // Bước 2: Thêm dữ liệu vào Database
                        obj.image_admin = filename;
                    }
                    db.SaveChanges();
                    Response.Redirect("Admin.aspx");
                }
                catch
                {
                    pnError.Visible = true;
                    lbError.Text    = "Lỗi, không lưu lại được!";
                }
            }
        }