Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            id = Request.QueryString["id"] ?? "0";

            if (IsPostBack)
            {
                return;
            }

            List <Option> options = BuildProductCategorySelection(5);

            foreach (Option option in options)
            {
                Nodes = string.Concat(Nodes, string.Format(lblNodeFormat.Text, option.ID, option.Name));
            }

            if (id != "0")
            {
                Sys_DanhMucDonViRepository repository = new Sys_DanhMucDonViRepository();
                Sys_DanhMucDonVi           department = repository.GetById(int.Parse(id));
                txtCode.Text = department.MaHieuDonVi;
                txtName.Text = department.TenDonVi;
                txtNote.Text = department.GhiChu;
                parentID     = department.MaDonViCapTren;
            }
        }
Пример #2
0
        public List <PositionViewModel> GetPositionByStaff(int staffId)
        {
            List <PositionViewModel> vm = new List <PositionViewModel>();

            List <Sys_DanhMucDonVi>  departments = departmentRepository.GetAll().ToList();
            List <Sys_DanhMucChucVu> positions   = positionRepository.GetAll().ToList();

            //Sys_CanBo staff = staffRepository.GetById(staffId);
            Sys_DanhMucDonVi  donvi  = new Sys_DanhMucDonVi();
            Sys_DanhMucChucVu chucvu = new Sys_DanhMucChucVu();

            //List<Sys_CanBo_Department_ChucVu> maps = staffRepository.GetMappingByStaff(staffId);
            //foreach (Sys_CanBo_Department_ChucVu map in maps)
            //{
            //    PositionViewModel pvm = new PositionViewModel();
            //    donvi = departments.FirstOrDefault(x => x.ID == map.DepartmentID);
            //    chucvu = positions.FirstOrDefault(x => x.ID == map.ChucVuID);

            //    if (donvi != null && chucvu != null)
            //    {
            //        pvm.Department = donvi;
            //        pvm.Position = chucvu;
            //    }
            //    vm.Add(pvm);
            //}

            return(vm);
        }
Пример #3
0
        private List <string> BuildTreeNode(Sys_DanhMucDonVi department, int level, string format, List <string> nodes)
        {
            string temp = string.Empty;

            temp = string.Format(format, department.TenDonVi, level, department.ID);
            nodes.Add(temp);
            ++level;
            department.Childs.ForEach(x => nodes = BuildTreeNode(x, level, format, nodes));
            return(nodes);
        }
Пример #4
0
        private List <DepartmentTreeNode> BuildTreeNode(Sys_DanhMucDonVi department, int level, List <DepartmentTreeNode> nodes)
        {
            DepartmentTreeNode node = new DepartmentTreeNode();

            node.Name  = department.TenDonVi;
            node.Level = level;
            node.ID    = department.ID;
            nodes.Add(node);
            ++level;
            department.Childs.ForEach(x => nodes = BuildTreeNode(x, level, nodes));
            return(nodes);
        }
Пример #5
0
        private void BuildOption(Sys_DanhMucDonVi department, int level, int seperator, ref List <Option> nodes, ref List <Sys_DanhMucDonVi> departments)
        {
            string prefix = string.Empty;
            string name   = string.Empty;

            for (int i = 0; i < level; i++)
            {
                prefix = string.Concat(prefix, "&nbsp;");
            }
            name = string.Concat(prefix, department.TenDonVi);
            Option node = new Option();

            node.Name = name;
            node.ID   = department.ID;
            nodes.Add(node);
            level = level + seperator;
            foreach (Sys_DanhMucDonVi c in departments.FindAll(p => p.MaDonViCapTren == department.ID))
            {
                BuildOption(c, level, seperator, ref nodes, ref departments);
            }
        }
Пример #6
0
        public static string AddDepartment(string name, string code, string note)
        {
            AjaxResponse response = new AjaxResponse();

            try
            {
                Sys_DanhMucDonViRepository repository = new Sys_DanhMucDonViRepository();


                bool isExistCode = repository.IsExistDepartmentCode(code);
                if (isExistCode)
                {
                    response.IsSuccess = false;
                    response.Message   = "Mã đơn vị đã tồn tại, vui lòng chọn mã khác.";
                }
                else
                {
                    Sys_DanhMucDonVi department = new Sys_DanhMucDonVi();
                    department.TenDonVi       = name;
                    department.MaHieuDonVi    = code;
                    department.MaDonViCapTren = 0;
                    department.KichHoat       = true;
                    department.NgayTao        = DateTime.Now;
                    department.NgayThayDoi    = DateTime.Now;
                    department.CapDo          = 0;
                    repository.Add(department);
                    repository.SubmitChanges();
                    response.IsSuccess = true;
                    response.Message   = "Cập nhật thành công";
                }
            }
            catch (Exception ex)
            {
                response.IsSuccess = false;
                response.Message   = (ex.Message + ex.StackTrace).EncodeJsString();
            }
            return(JsonConvert.SerializeObject(response));
        }
Пример #7
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                int    groupdID    = 0;
                string name        = txtCode.Text;
                string role        = string.Empty;
                bool   isExistName = false;//


                Sys_DanhMucDonVi           entity     = new Sys_DanhMucDonVi();
                Sys_DanhMucDonViRepository repository = new Sys_DanhMucDonViRepository();

                if (id != "0")
                {
                    entity = repository.GetById(int.Parse(id));
                    if (entity.MaHieuDonVi != txtCode.Text)
                    {
                        isExistName = repository.IsExistDepartmentCode(name);
                    }
                }
                else
                {
                    isExistName = repository.IsExistDepartmentCode(name);
                }

                if (isExistName)
                {
                    ClientScriptManager cs = Page.ClientScript;
                    String cstext1         = "alert('Tên nhóm đã tồn tại, vui lòng chọn tên khác');";
                    cs.RegisterStartupScript(this.GetType(), "alert", cstext1, true);


                    return;
                }
                entity.MaHieuDonVi = txtCode.Text;
                entity.NgayThayDoi = DateTime.Now;
                entity.NgayTao     = DateTime.Now;
                entity.TenDonVi    = txtName.Text;
                entity.GhiChu      = txtNote.Text;

                int temp = 0;
                int.TryParse(Request.Form["ddlDepartment"], out temp);
                entity.MaDonViCapTren = temp;

                if (id == "0")
                {
                    repository.Add(entity);
                }

                repository.SubmitChanges();
                groupdID = entity.ID;

                Response.Redirect("default.aspx?page=department");
            }
            catch (Exception ex)
            {
                //lblMessage.CssClass = "error";
                //lblMessage.Visible = true;
                //lblMessage.Text = "Lỗi trong quá trình cập nhật, lỗi: " + ex.Message;

                string message = "Lỗi trong quá trình cập nhật, lỗi: " + ex.Message;
                String cstext2 = "alert('" + message + "');";
                Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", cstext2, true);
            }
        }