コード例 #1
0
        private string GetList(HttpContext context)
        {
            int    pageIndex = ObjectConvertHelper.ConvertToInt(context.Request["page"]);
            int    pageSize  = ObjectConvertHelper.ConvertToInt(context.Request["limit"]);
            string name      = ObjectConvertHelper.ConvertToString(context.Request["txtName"]);

            string strWhere = "";

            if (!string.IsNullOrEmpty(name))
            {
                strWhere += " and (UserName like '%" + name + "%' or StaffName like '%" + name + "%' )";
            }

            StaffsBLL     bll  = new StaffsBLL();
            List <Staffs> list = bll.GetList(strWhere, pageIndex, pageSize);

            int count = bll.GetCount(strWhere);

            var iso = new IsoDateTimeConverter();

            iso.DateTimeFormat = "yyyy-MM-dd";
            return(JsonConvert.SerializeObject(new
            {
                code = "0",
                msg = "",
                count = count,
                data = list
            }, iso));
        }
コード例 #2
0
        private string AddData(HttpContext context)
        {
            string    data    = context.Request["model"];
            Staffs    model   = JsonConvert.DeserializeObject <Staffs>(data);
            StaffsBLL bll     = new StaffsBLL();
            int       success = 1;
            string    msg     = "";

            if (model.Id == 0)
            {
                if (bll.GetCount(" and UserName='******' ") > 0)
                {
                    msg = "账号已存在!";
                }
                else
                {
                    model.UserPwd = "888888";
                    if (bll.Add(model))
                    {
                        success = 0;
                        msg     = "添加成功";
                    }
                    else
                    {
                        msg = "添加失败";
                    }
                }
            }
            else
            {
                if (bll.Update(model))
                {
                    success = 0;
                    msg     = "Success";
                }
                else
                {
                    msg = "修改失败";
                }
            }

            return(JsonConvert.SerializeObject(new
            {
                success = success,
                msg = msg
            }));
        }
コード例 #3
0
        private string DeleteData(HttpContext context)
        {
            int    id   = ObjectConvertHelper.ConvertToInt(context.Request["id"]);
            string name = context.Request["name"];

            SysDepartBLL bll     = new SysDepartBLL();
            var          dept    = bll.GetModel(id);
            StaffsBLL    userBll = new StaffsBLL();

            if (bll.GetCount(" and ParentId=" + id) > 1)
            {
                return(JsonConvert.SerializeObject(new
                {
                    success = 1,
                    msg = "该部门下面子级部门,不能删除!"
                }));
            }
            if (userBll.GetCount(" and DepartId='" + id + "' ") > 0)
            {
                return(JsonConvert.SerializeObject(new
                {
                    success = 1,
                    msg = "该部门下面有用户,不能删除!"
                }));
            }
            if (bll.Delete(id))
            {
                return(JsonConvert.SerializeObject(new
                {
                    success = 0,
                    msg = "Success"
                }));
            }
            else
            {
                return(JsonConvert.SerializeObject(new
                {
                    success = 1,
                    msg = "删除失败"
                }));
            }
        }