Beispiel #1
0
        /// <summary>
        /// Thêm mới, xóa, sửa mapping
        /// </summary>
        /// <param name="staffId"></param>
        /// <param name="mappings"></param>
        public void UpdateDepartmentPosition(int staffId, List <Sys_CanBo_Department_ChucVu> mappings)
        {
            var currentMappings = GetMappingByStaff(staffId);
            List <Sys_CanBo_Department_ChucVu> addMappings    = new List <Sys_CanBo_Department_ChucVu>();
            List <Sys_CanBo_Department_ChucVu> updateMappings = new List <Sys_CanBo_Department_ChucVu>();
            List <Sys_CanBo_Department_ChucVu> deleteMappings = new List <Sys_CanBo_Department_ChucVu>();

            ///Xác định chức vụ nào là thêm mới, hoặc update
            foreach (Sys_CanBo_Department_ChucVu map in mappings)
            {
                Sys_CanBo_Department_ChucVu m = currentMappings.FirstOrDefault(x => x.DepartmentID == map.DepartmentID);
                if (m == null)
                {
                    addMappings.Add(map);
                }
                else
                {
                    if (m.ChucVuID != map.ChucVuID)
                    {
                        m.ChucVuID = map.ChucVuID;
                        //updateMappings.Add(map);
                    }
                }
            }

            foreach (Sys_CanBo_Department_ChucVu map in currentMappings)
            {
                Sys_CanBo_Department_ChucVu m = mappings.FirstOrDefault(x => x.DepartmentID == map.DepartmentID);
                if (m == null)
                {
                    deleteMappings.Add(map);
                }
            }

            //foreach (Sys_CanBo_Department_ChucVu map in updateMappings)
            //{
            //    Sys_CanBo_Department_ChucVu m =currentMappings.fin dataContext.Sys_CanBo_Department_ChucVus.FirstOrDefault(x => x.ID == map.ID);
            //    m.ChucVuID = map.ChucVuID;
            //}

            deleteMappings.ForEach(x => dataContext.Sys_CanBo_Department_ChucVus.DeleteOnSubmit(x));
            addMappings.ForEach(x => dataContext.Sys_CanBo_Department_ChucVus.InsertOnSubmit(x));
            dataContext.SubmitChanges();
        }
Beispiel #2
0
        protected void rptDepartment_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                DepartmentTreeNode node        = (DepartmentTreeNode)e.Item.DataItem;
                DropDownList       ddlPosition = (DropDownList)e.Item.FindControl("ddlPosition");
                CheckBox           chkCheck    = (CheckBox)e.Item.FindControl("chkCheck");
                ddlPosition.DataSource = positions;
                ddlPosition.DataBind();

                if (mappings.Count > 0)
                {
                    Sys_CanBo_Department_ChucVu map = mappings.FirstOrDefault(x => x.DepartmentID == node.ID);
                    if (map != null)
                    {
                        ddlPosition.Enabled       = true;
                        chkCheck.Checked          = true;
                        ddlPosition.SelectedValue = map.ChucVuID.ToString();
                    }
                }
            }
        }
Beispiel #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);
        }