public string AddSub(EditDepartmentModel model)
        {
#if DEBUG
            UserModel user = UserModel.SingleOrDefault(14);
            SysConfig.CurrentUser = user;
#endif

            if (ModelState.IsValid)
            {
                DepartmentModel department = new DepartmentModel();
                department.Name = model.Name;                                                               //部门名称
                department.No = model.No;                                                                   //部门编号

                department.DocDepartment = model.DocDepartment.ToInt();                                     //是否业务部门
                department.Pid = model.Id;                                                                  //上级部门
                department.FullPid = model.FullPid + "-" + model.Id;                                        //所有上级部门

                department.FullName = CommonMethod.GetDepFullName(department.FullPid) + department.Name;    //部门全称
                department.Sortno = model.Sortno;                                                           //排序编号
                department.DepLevel = model.DepLevel + 1;                                                   //部门层级

                department.CreateMan = SysConfig.CurrentUser.Id;                                            //创建人
                department.CreateTime = DateTime.Now;                                                       //创建时间

                int result = (int)department.Insert();

                if (result > 0)
                {
                    //记录操作日志
                    CommonMethod.Log(SysConfig.CurrentUser.Id, "Insert", "Sys_Department");

                    return "1";
                }
            }

            return "0";
        }
        public string Edit(EditDepartmentModel model)
        {
#if DEBUG
            UserModel user = UserModel.SingleOrDefault(14);
            SysConfig.CurrentUser = user;
#endif

            if (ModelState.IsValid)
            {
                DepartmentModel department = DepartmentModel.SingleOrDefault(model.Id.ToInt());
                if (null == department)
                {
                    return "0";
                }

                department.Name = model.Name;                                 //部门名称
                department.No = model.No;                                     //部门编号
                department.FullName = CommonMethod.GetDepFullName(department.FullPid) + department.Name;    //部门全称

                department.DocDepartment = model.DocDepartment.ToInt();       //是否单据所属部门
                department.Sortno = model.Sortno;                             //排序编号
                department.ModifyMan = SysConfig.CurrentUser.Id;              //修改人
                department.ModifyTime = DateTime.Now;                         //修改时间

                int result = department.Update();

                if (result > 0)
                {
                    //记录操作日志
                    CommonMethod.Log(SysConfig.CurrentUser.Id, "Update", "Sys_Department");

                    return "1";
                }
            }

            return "0";
        }