示例#1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            trang = Request.QueryString["trang"] != null ? Request.QueryString["trang"].ToString() : "1";
            lblNameError.Visible = false;
            lblMessage.Visible   = false;

            itemFormat = lblDeparmentRowFormat.Text;

            id = Request.QueryString["id"] ?? "0";


            if (!IsPostBack)
            {
                List <string> userNames = staffRepository.GetAvailableUserName();

                if (id != "0")
                {
                    staff = staffRepository.GetById(int.Parse(id));
                    ckKichHoat.Checked  = staff.KichHoat;
                    txtName.Text        = staff.TenCanBo;
                    txtEmail.Text       = staff.Email;
                    txtSoDienThoai.Text = staff.SoDienThoai;
                    StaffName           = staff.TenCanBo;

                    if (!string.IsNullOrEmpty(staff.UserName))
                    {
                        userNames.Add(staff.UserName);
                    }

                    mappings = staffRepository.GetMappingByStaff(int.Parse(id));
                }

                ddlAccount.DataSource = userNames;
                ddlAccount.Items.Add(new ListItem {
                    Text = "[Bạn hãy chọn]", Value = "0"
                });
                ddlAccount.DataBind();

                if (id != "0")
                {
                    ddlAccount.SelectedValue = staff.UserName;
                }


                Sys_DanhMucChucVuRepository positionRepository = new Sys_DanhMucChucVuRepository();
                positions = positionRepository.GetAll().ToList();

                ///Phong ban, don vi
                Sys_DanhMucDonViRepository repository  = new Sys_DanhMucDonViRepository();
                List <DepartmentTreeNode>  nodes       = new List <DepartmentTreeNode>();
                List <Sys_DanhMucDonVi>    departments = repository.GetDepartmentStructure();
                int level = 0;
                departments.ForEach(x => nodes = BuildTreeNode(x, level, nodes));

                rptDepartment.DataSource = nodes;
                rptDepartment.DataBind();
            }
        }
示例#2
0
 public bool UpdateStaff(int id, string Name, string Mobile)
 {
     try
     {
         Sys_CanBo staff = staffRepository.GetById(id);
         if (staff != null)
         {
             staff.TenCanBo    = Name;
             staff.SoDienThoai = Mobile;
             staffRepository.SubmitChanges();
             return(true);
         }
     }
     catch { }
     return(false);
 }
示例#3
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Sys_CanBoRepository repository = new Sys_CanBoRepository();
            Sys_CanBo           staff      = new Sys_CanBo();

            if (!string.IsNullOrEmpty(id) && id != "0")
            {
                staff = repository.GetById(int.Parse(id));
            }

            //Update thông tin cơ bản
            bool isExistEmail = false;

            if (id == "0")
            {
                if (repository.IsEmailExist(txtEmail.Text))
                {
                    lblEmailError.Visible = true;
                    lblEmailError.Text    = "Email đã tồn tại, vui lòng chọn email khác";
                    return;
                }
            }
            else
            {
                if (staff.Email.ToLower() != txtEmail.Text.ToLower())
                {
                    if (repository.IsEmailExist(txtEmail.Text))
                    {
                        lblEmailError.Visible = true;
                        lblEmailError.Text    = "Email đã tồn tại, vui lòng chọn email khác";
                        return;
                    }
                }
            }

            staff.UserName       = ddlAccount.SelectedValue;
            staff.NgayThayDoi    = DateTime.Now;
            staff.Email          = txtEmail.Text;
            staff.MaNguoiTao     = new Guid(Membership.GetUser(HttpContext.Current.User.Identity.Name).ProviderUserKey.ToString());
            staff.MaNguoiThayDoi = new Guid(Membership.GetUser(HttpContext.Current.User.Identity.Name).ProviderUserKey.ToString());
            staff.NgayTao        = DateTime.Now;
            staff.SoDienThoai    = txtSoDienThoai.Text;
            staff.TenCanBo       = txtName.Text;
            staff.KichHoat       = ckKichHoat.Checked;
            if (id == "0")
            {
                repository.Add(staff);
            }
            repository.SubmitChanges();
            ///Update thông tin chức vụ phòng ban.
            int temp = 0;

            List <Sys_CanBo_Department_ChucVu> mappings = new List <Sys_CanBo_Department_ChucVu>();

            foreach (RepeaterItem item in rptDepartment.Items)
            {
                CheckBox     chkCheck    = (CheckBox)item.FindControl("chkCheck");
                DropDownList ddlPosition = (DropDownList)item.FindControl("ddlPosition");
                HiddenField  hdfID       = (HiddenField)item.FindControl("hdfID");
                int.TryParse(ddlPosition.SelectedValue, out temp);

                if (chkCheck.Checked && temp > 0)
                {
                    Sys_CanBo_Department_ChucVu map = new Sys_CanBo_Department_ChucVu();
                    map.CanBoID      = staff.ID;
                    map.ChucVuID     = temp;
                    map.DepartmentID = int.Parse(hdfID.Value);
                    mappings.Add(map);
                }
            }
            repository.UpdateDepartmentPosition(staff.ID, mappings);

            Page.Response.Redirect("default.aspx?page=staff&trang=" + trang);
        }