using CallCenter.Utility;
using CallCenterApi.Common;
using CallCenterApi.DB;
using CallCenterApi.Interface.Controllers.Base;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace CallCenterApi.Interface.Controllers
{
    
    public class DepartmentController : BaseController
    {
        private BLL.T_Sys_Department departmentBLL = new BLL.T_Sys_Department();

        #region 部门
        /// <summary>
        /// 获取部门列表
        /// </summary>
        /// <returns></returns>
        public ActionResult GetDeptList(string deptname,int iscbdw=0)
        {
            DataTable dt = new DataTable();
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);
            Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
            string sql = "";
            if (!string.IsNullOrEmpty(deptname))
            {
                sql += " and F_DeptName like '%" + deptname.Trim() + "%'";
            }
            if (userModel.F_RoleCode == "GLY" || userModel.F_RoleCode == "ZXLD" || userModel.F_RoleCode == "ZXHWY")
            {

                if (iscbdw == 0)
                {
                    dt = departmentBLL.GetList(0, "F_State=0", " F_Sort").Tables[0];
                }
                else
                {
                    dt = departmentBLL.GetList(0, "F_State=0 and  ISNULL(F_IsDealDept, '0') ='1'", " F_Sort").Tables[0];
                }
            }
            else
            {
                if (iscbdw == 0)
                {
                    dt = departmentBLL.GetList(0, "F_State=0  and ( F_DeptId='" + userModel.F_DeptId + "'  or  F_PartentId='" + userModel.F_DeptId + "')" + sql, " F_Sort").Tables[0];
                }
                else
                {
                    dt = departmentBLL.GetList(0, "F_State=0 and  ISNULL(F_IsDept, '0') ='1' and F_PartentId='" + userModel.F_DeptId + "'" + sql, " F_Sort").Tables[0];
                }
            }
           
            return Success("加载成功", dt);
        }
        public ActionResult GetDeptListByDept(string dept,int iscbdw = 0)
        {
            string depts = RequestString.FilterSql(dept, 1);
            DataTable dt = new DataTable();
            var sql = " F_State=0   and F_PartentId>0 ";
                   
            if (iscbdw == 0)
                sql += " and  ISNULL(F_IsDealDept, '0') ='1' ";
            if (!string.IsNullOrEmpty(depts))
            {
                sql += " and F_DeptName like '%" + depts.Trim() + "%'";

                dt = departmentBLL.GetList(0, sql, "F_Sort").Tables[0];
            }
            return Success("加载成功", dt);
        }

        /// <summary>
        /// 获取二级部门列表
        /// </summary>
        /// <returns></returns>
        [Authority]
        public ActionResult GetSecondDeptList()
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);
            Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);

            DataTable dt = new DataTable();
            if (userModel.F_RoleCode == "GLY")
            {
                dt = departmentBLL.GetList(0, "F_State=0 and  ISNULL(F_IsDept, '0') ='2' " , " F_Sort").Tables[0];
            }
            if (userModel.F_RoleCode == "WLDW")
            {
                dt = departmentBLL.GetList(0, "F_State=0 and  ISNULL(F_IsDept, '0') ='2'  and F_PartentId='" + userModel.F_DeptId + "'", " F_Sort").Tables[0];
            }

            return Success("加载成功", dt);
        }

        /// <summary>
        /// 获取部门列表
        /// </summary>
        /// <returns></returns>
        [Authority]
        public ActionResult GetDeptListtree(int pId = 0)
        {
            DataTable dt = new DataTable();
            dt = new BLL.T_Sys_Department().GetList(" F_State=0 and ISNULL(F_IsDealDept, '0') ='1' and F_PartentId=" + pId).Tables[0];
            List<Model.TreeModel> modelList = BindTree(dt, "0");

            if (modelList != null)
            {
                if (modelList.Count > 0)
                    return Success("加载成功", modelList);
            }
            return Error("加载失败");

        }
        /// <summary>
        /// 获取部门总父级
        /// </summary>
        /// <returns></returns>
        public ActionResult GetDeptLiallparid()
        {
            DataTable dt = new DataTable();
            dt = DbHelperSQL.Query("select * from T_Sys_Department where  F_PartentId=0").Tables[0];
            return Success("加载成功", dt);
        }
        /// <summary>
        /// tree  树形部门
        /// </summary>
        /// <param name="tab"></param>
        /// <param name="parentid"></param>
        /// <returns></returns>
        [Authority]
        private List<Model.TreeModel> BindTree(DataTable tab, string parentid)
        {
            DataTable tab2 = new DataTable();

            if (tab != null && tab.Rows.Count > 0)
            {
                List<Model.T_Sys_Department> categorylist = new BLL.T_Sys_Department().DataTableToList(tab);
                List<Model.TreeModel> modelList = new List<Model.TreeModel>(categorylist.Count);
                for (int i = 0; i < categorylist.Count; i++)
                {
                    Model.TreeModel model = new Model.TreeModel();
                    string currentID = categorylist[i].F_DeptId.ToString();//当前功能ID
                    model.id = currentID;
                    model.IconCls = "";//图标
                    model.text = categorylist[i].F_DeptName;
                    tab2 = new BLL.T_Sys_Department().GetList("F_PartentId=" + currentID + " and F_State=0 and ISNULL(F_IsDealDept, '0') ='1' order by f_sort").Tables[0];
                    if (tab2 != null && tab2.Rows.Count > 0)
                    {
                        model.children = BindTree(tab2, currentID);
                    }
                    modelList.Add(model);
                }
                return modelList;

            }
            else
            {
                return null;
            }

        }

        /// <summary>
        /// 获取部门
        /// </summary>
        /// <param name="deptId"></param>
        /// <returns></returns>
        [Authority]
        public ActionResult GetDept()
        {
            int id = RequestString.GetInt("id", 0);
            Model.T_Sys_Department dModel = departmentBLL.GetModel(id);
            if (dModel != null)
            {

                string value = "";
                if (dModel.F_Valueid  != null)
                {
                    var dicvalue = new BLL.T_Sys_DictionaryValue ().GetModel((int)dModel.F_Valueid);
                    if (dicvalue != null)
                        value = dicvalue.F_Value ;
                }
                var obj = new
                {
                    F_Address = dModel.F_Address,
                    F_CreateDate = dModel.F_CreateDate,
                    F_CreateUser = dModel.F_CreateUser,
                    F_DeptId = dModel.F_DeptId,
                    F_DeptName = dModel.F_DeptName,
                    F_DeptNameSpell = dModel.F_DeptNameSpell,
                    F_DeptNameSpells = dModel.F_DeptNameSpells,
                    F_DeptPhone = dModel.F_DeptPhone,
                    F_DeptPhone2 = dModel.F_DeptPhone2,
                    F_DeptTelphone = dModel.F_DeptTelphone,
                    F_IsDealDept = dModel.F_IsDealDept,
                    F_IsDept = dModel.F_IsDept,
                    F_LeaderUser = dModel.F_LeaderUser,
                    F_LeaderUserName = dModel.F_LeaderUserName,
                    F_PartentId = dModel.F_PartentId,
                    F_Remark = dModel.F_Remark,
                    F_Sort = dModel.F_Sort,
                    F_State = dModel.F_State,
                    F_TopLeaderUser = dModel.F_TopLeaderUser,
                    F_TopLeaderUserName = dModel.F_TopLeaderUserName,
                    F_TopSplitUser = dModel.F_TopSplitUser,
                    F_TopSplitUserName = dModel.F_TopSplitUserName,
                    F_Type = dModel.F_Type,
                    F_layer = dModel.F_layer,
                    F_Valueid = dModel.F_Valueid,
                    F_Value = value,
                };
                return Success("获取信息成功", dModel);
            }
                
            return Error("获取信息失败");

        }

        /// <summary>
        /// 添加部门
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [Authority]
        [HttpPost]
        public ActionResult AddDept()
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);
            Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
            int id = RequestString.GetInt("id", 0);
            int did = RequestString.GetInt("did", 0);
            int sort = RequestString.GetInt("sort", 0);
            int isdept = RequestString.GetInt("isdept", 0);
            int isdealdept = RequestString.GetInt("isdealdept", 0);
            int valueid = RequestString.GetInt("valueid", 0);
            string name = RequestString.GetFormString("name");
            string phone = RequestString.GetFormString("phone");
            string leader = RequestString.GetFormString("leader");
            string split = RequestString.GetFormString("split");
            string topleader = RequestString.GetFormString("topleader");
            string remark = RequestString.GetFormString("remark");

            Model.T_Sys_Department dModel = new Model.T_Sys_Department();
            if (id == 0)
            {
                var list = departmentBLL.GetModelList(" F_State=0 and F_PartentId='" + did + "' and F_DeptName='" + name + "' ");
                if (list.Count > 0)
                {
                    return Error("已经存在此部门");
                }
                else
                {
                    dModel.F_PartentId = did;
                    dModel.F_Sort = sort;
                    dModel.F_DeptName = name;
                    dModel.F_DeptPhone = phone;
                    dModel.F_layer = did > 0 ? 1 : 0;
                    dModel.F_Type = 0;
                    dModel.F_LeaderUser = leader;
                    dModel.F_TopSplitUser = split;
                    dModel.F_TopLeaderUser = topleader;
                    dModel.F_State = 0;
                    dModel.F_IsDept = isdept;
                    dModel.F_IsDealDept = isdealdept;
                    dModel.F_CreateDate = DateTime.Now;
                    dModel.F_CreateUser = userModel.F_UserCode;
                    dModel.F_Valueid  = valueid;
                    
                    int n = departmentBLL.Add(dModel);
                    if (n > 0)
                    {
                        if (valueid > 0)
                        {
                            var value = new BLL.T_Sys_DictionaryValue ().GetModel(valueid);
                            if (value != null)
                            {
                                value.F_Deptid  = n;
                            }
                            var b = new BLL.T_Sys_DictionaryValue().Update(value);
                        }
                        return Success("添加成功", n);
                    }
                       
                    else
                        return Error("添加失败");
                }
            }
            else
            {
                dModel = departmentBLL.GetModel(id);
                if (dModel != null)
                {
                    var list = departmentBLL.GetModelList(" F_State=0 and F_PartentId='" + did + "' and F_DeptName='" + name + "' and F_DeptId!='" + id + "' ");
                    if (list.Count > 0)
                    {
                        return Error("已经存在此部门");
                    }
                    else
                    {
                        dModel.F_PartentId = did;
                        dModel.F_Sort = sort;
                        dModel.F_DeptName = name;
                        dModel.F_DeptPhone = phone;
                        dModel.F_LeaderUser = leader;
                        dModel.F_TopSplitUser = split;
                        dModel.F_TopLeaderUser = topleader;
                        dModel.F_IsDept = isdept;
                        dModel.F_IsDealDept = isdealdept;
                        dModel.F_Valueid = valueid;
                        if (departmentBLL.Update(dModel))
                        {
                            if (valueid > 0)
                            {
                                var value = new BLL.T_Sys_DictionaryValue().GetModel(valueid);
                                if (value != null)
                                {
                                    value.F_Deptid = dModel.F_DeptId ;
                                }
                                var b = new BLL.T_Sys_DictionaryValue().Update(value);
                            }
                            return Success("修改成功");
                        }
                        else
                            return Error("修改失败");
                    }
                }
                else
                {
                    return Error("修改失败");
                }
            }
        }
        [Authority]
        [HttpPost]
        public ActionResult UpdateDeptRemark()
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);
            if (userId <= 0)
                return Error("权限不足");
            Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
            if(userModel==null)
                return Error("权限不足!");
            int id = RequestString.GetInt("id", 0);
            string remark = RequestString.GetFormString("remark");
            if (id <= 0)
                return Error("参数错误");
            Model.T_Sys_Department dModel = departmentBLL.GetModel(id);
            if(dModel==null)
                return Error("参数错误!");
            dModel.F_Remark = remark;
            if (departmentBLL.Update(dModel))
                return Success("修改成功");
            else
                return Error("修改失败");

        }
        public ActionResult UpdateSMSList(string ids,int state)
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);
            if (userId <= 0)
                return Error("权限不足");
            Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
            if (userModel == null)
                return Error("权限不足!");
            if (string .IsNullOrEmpty (ids) )
                return Error("请选择部门");
            if (departmentBLL.UpdateSMS(0))
            {
                if (departmentBLL.UpdateSMSList(ids, state))
                    return Success("修改成功");
            }
            return Error("修改失败");
        }
        /// <summary>
        /// 综合考评
        /// </summary>
        /// <param name="deptid"></param>
        /// <param name="Score"></param>
        /// <returns></returns>
        public ActionResult Comprehensive(int  deptid=0, int Score=0,string Remarks="")
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);
            Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
            if (userId <= 0)
                return Error("权限不足");
             if (deptid<=0)
                return Error("请选择部门");
            if(Score > 5)
                        return Error("当月累计分值不可大于5分");
            if (Score>5|| Score<0)
                return Error("请输入正确的分值");
            if (userModel.F_RoleCode != "ZXLD" && userModel.F_RoleCode != "GLY")
                return Error("权限不足");
            var deptment = departmentBLL.GetModel(deptid);
            if (deptment == null)
                return Error("部门不存在");
            Model.T_Sys_Comprehensive t_Sys_Comprehensive = new Model.T_Sys_Comprehensive();
            t_Sys_Comprehensive.F_Score = Score;
            t_Sys_Comprehensive.F_ScoreRemarks = Remarks;
            t_Sys_Comprehensive.F_ScoreTime = DateTime.Now;
            t_Sys_Comprehensive.F_CreatTime = DateTime.Now;
            t_Sys_Comprehensive.F_CreatUser = userModel.F_UserCode;
            t_Sys_Comprehensive.F_Deprid = deptid;
            if (new BLL.T_Sys_Comprehensive().Add(t_Sys_Comprehensive) > 0)
                return Success("加分成功");
            return Error("加分失败");
        }


        /// <summary>
        /// 综合考评
        /// </summary>
        /// <param name="deptid"></param>
        /// <param name="Score"></param>
        /// <returns></returns>
        public ActionResult NewComprehensive(int deptid = 0, int Score = 0, string Remarks = "", DateTime? ScoreTime = null)
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);
            Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
            if (userId <= 0)
                return Error("权限不足");
            if (deptid <= 0)
                return Error("请选择部门");
            if (userModel.F_RoleCode != "ZXLD" && userModel.F_RoleCode != "GLY")
                return Error("权限不足");
            var deptment = departmentBLL.GetModel(deptid);
            if (deptment == null)
                return Error("部门不存在");
            Model.T_Sys_Comprehensive t_Sys_Comprehensive = new Model.T_Sys_Comprehensive();
            t_Sys_Comprehensive.F_NewScore = Score;
            t_Sys_Comprehensive.F_NewScoreRemarks = Remarks;
            if (ScoreTime!=null )
            {
                t_Sys_Comprehensive.F_NewScoreTime = ScoreTime;
            }
            else 
            t_Sys_Comprehensive.F_NewScoreTime = DateTime.Now;
            t_Sys_Comprehensive.F_CreatTime = DateTime.Now;
            t_Sys_Comprehensive.F_CreatUser = userModel.F_UserCode;
            t_Sys_Comprehensive.F_Deprid = deptid;
            if (new BLL.T_Sys_Comprehensive().Add(t_Sys_Comprehensive) > 0)
                return Success("成功");
            return Error("失败");
        }


        /// <summary>
        /// 综合考评
        /// </summary>
        /// <param name="deptid"></param>
        /// <param name="Score"></param>
        /// <param name="type"></param>0信息宣传1优秀案件2即办事项
        /// <returns></returns>
        public ActionResult Evaluation(int deptid = 0, float  Score = 0, string Remarks = "", DateTime? ScoreTime = null
            ,int type=0)
        {

            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);
            Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
            if (userId <= 0)
                return Error("权限不足");
            if (deptid <= 0)
                return Error("请选择部门");
            if (userModel.F_RoleCode != "ZXLD" && userModel.F_RoleCode != "GLY")
                return Error("权限不足");
            var deptment = departmentBLL.GetModel(deptid);
            if (deptment == null)
                return Error("部门不存在");
            if(Score<0)
                return Error("请输入正确的分值");
            Model.T_Sys_Comprehensive t_Sys_Comprehensive = new Model.T_Sys_Comprehensive();
            if (type==0)
            {
                if (Score >5)
                    return Error("请输入正确的分值");
                t_Sys_Comprehensive.Information = Score;
                t_Sys_Comprehensive.InformationRemarks = Remarks;
                if (ScoreTime != null)
                {
                    t_Sys_Comprehensive.InformationTime = ScoreTime;
                }
                else
                    t_Sys_Comprehensive.InformationTime = DateTime.Now;
                t_Sys_Comprehensive.F_CreatTime = DateTime.Now;
                t_Sys_Comprehensive.F_CreatUser = userModel.F_UserCode;
                t_Sys_Comprehensive.F_Deprid = deptid;
            }
            else if (type == 1)
            {
                if (Score > 10)
                    return Error("请输入正确的分值");
                t_Sys_Comprehensive.Excellent = Score;
                t_Sys_Comprehensive.ExcellentRemarks = Remarks;
                if (ScoreTime != null)
                {
                    t_Sys_Comprehensive.ExcellentTime = ScoreTime;
                }
                else
                    t_Sys_Comprehensive.ExcellentTime = DateTime.Now;
                t_Sys_Comprehensive.F_CreatTime = DateTime.Now;
                t_Sys_Comprehensive.F_CreatUser = userModel.F_UserCode;
                t_Sys_Comprehensive.F_Deprid = deptid;
            }
            else 
            {
                if (Score > 5)
                    return Error("请输入正确的分值");
                t_Sys_Comprehensive.Immediate = Score;
                t_Sys_Comprehensive.ImmediateRemarks = Remarks;
                if (ScoreTime != null)
                {
                    t_Sys_Comprehensive.ImmediateTime = ScoreTime;
                }
                else
                    t_Sys_Comprehensive.ImmediateTime = DateTime.Now;
                t_Sys_Comprehensive.F_CreatTime = DateTime.Now;
                t_Sys_Comprehensive.F_CreatUser = userModel.F_UserCode;
                t_Sys_Comprehensive.F_Deprid = deptid;
            }

            if (new BLL.T_Sys_Comprehensive().Add(t_Sys_Comprehensive) > 0)
                return Success("成功");
            return Error("失败");
        }
        /// <summary>
        /// 综合考评
        /// </summary>
        /// <param name="deptid"></param>
        /// <param name="Score"></param>
        /// <returns></returns>
        public ActionResult GetComprehensiveList(int deptid = 0 )
        {
            Dictionary<string, string> paras = new Dictionary<string, string>();
            paras.Add("@deptid", deptid.ToString ());
            var obj = DbHelperSQL.RunProcedure("P_DeptComprehensiveList", paras, "DeptComprehensiveList");
            return Success("成功",obj);
        }

        /// <summary>
        /// 综合考评
        /// </summary>
        /// <param name="deptid"></param>
        /// <param name="Score"></param>
        /// <returns></returns>
        public ActionResult UpdateComprehensive(int id = 0, float ? Comprehensive =null , string Remarks = "")
        {
            if (Comprehensive!=null )
            {
                Dictionary<string, string> paras = new Dictionary<string, string>();
                paras.Add("@ID", id.ToString());
                paras.Add("@source", Comprehensive.ToString());
                paras.Add("@sourceremaks", Remarks);
                var obj = DbHelperSQL.RunProcedure("P_UpdateAchievements", paras, "UpdateAchievements");
            }
            return Success("成功");
        }
        /// <summary>
        /// 监督检查
        /// </summary>
        /// <param name="deptid"></param>
        /// <param name="Score"></param>
        /// <returns></returns>
        public ActionResult Supervision(int deptid = 0, int Score = 0, string Remarks = "", DateTime? ScoreTime = null)
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);
            Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
            if (userId <= 0)
                return Error("权限不足");
            if (deptid <= 0)
                return Error("请选择部门");
            if (Score < -10)
                return Error("当月累计减分不可低于十分");
            if (userModel.F_RoleCode != "ZXLD" && userModel.F_RoleCode != "GLY")
                return Error("权限不足");

            var deptment = departmentBLL.GetModel(deptid);
            if (deptment == null)
                return Error("部门不存在");
            Model.T_Sys_Comprehensive t_Sys_Comprehensive = new Model.T_Sys_Comprehensive();
            t_Sys_Comprehensive.F_SupervisionScore = Score;
            t_Sys_Comprehensive.F_ScoreSupervision = Remarks;
            if (ScoreTime != null)
            {
                t_Sys_Comprehensive.F_SupervisionTime = ScoreTime;
            }
            else
                t_Sys_Comprehensive.F_SupervisionTime = DateTime.Now;
            t_Sys_Comprehensive.F_CreatTime = DateTime.Now;
            t_Sys_Comprehensive.F_CreatUser = userModel.F_UserCode;
            t_Sys_Comprehensive.F_Deprid = deptid;
            if (new BLL .T_Sys_Comprehensive().Add (t_Sys_Comprehensive)>0)
                return Success("减分成功");
            return Error("减分失败");
        }
        /// <summary>
        /// 获取部门
        /// </summary>
        /// <param name="deptId"></param>
        /// <returns></returns>
        [Authority]
        public ActionResult GetDeptSocre(DateTime? time)
        {
            int id = RequestString.GetInt("id", 0);
            Model.T_Sys_Department dModel = departmentBLL.GetModel(id);
           
            if (time == null)
            {
                time = DateTime.Now;
            }
            if (dModel != null)
            {
                if (((DateTime)dModel.F_SupervisionTime).Month ==((DateTime) time).Month
                   && ((DateTime)dModel.F_SupervisionTime).Year == ((DateTime)time).Year)
                {
                   
                }
                else
                {
                    dModel.F_ScoreSupervision = "";
                }
                if (((DateTime)dModel.F_ScoreTime).Month == ((DateTime)time).Month
                 && ((DateTime)dModel.F_ScoreTime).Year == ((DateTime)time).Year)
                {
                }
                else
                {
                    dModel.F_ScoreRemarks = "";
                }
                var obj = new
                {
                    F_ScoreSupervision= dModel.F_ScoreSupervision,
                    F_ScoreRemarks = dModel.F_ScoreRemarks,

                };
                return Success("获取信息成功", dModel);
            }

            return Error("获取信息失败");

        }
        /// <summary>
        /// 删除部门
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [Authority]
        public ActionResult DelDept(string[] ids)
        {
            if (ids == null || ids.Length <= 0)
                return Error("请选择要删除的部门");

            var idStr = string.Join(",", ids);
            if (string.IsNullOrEmpty(idStr.Trim()))
                return Error("请选择要删除的部门");

            if (departmentBLL.DeleteList(idStr))
                return Success("删除成功");
            return Error("删除失败");

        }

        /// <summary>
        /// 删除部门和其下级部门
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [Authority]
        public ActionResult DelDepts(int id)
        {
            if (id > 0)
            {
                var model = new BLL.T_Sys_Department().GetModel(id);
                if (DelDeptsByPId(id))
                {
                    new BLL.T_Sys_Department().Delete(id);
                }
                return Success("删除成功");
            }
            else
            {
                return Error("删除失败");
            }

        }
        [Authority]
        public bool DelDeptsByPId(int id)
        {
            bool bl = true;

            var list = new BLL.T_Sys_Department().GetModelList(" F_PartentId ='" + id + "'");
            foreach (var l in list)
            {
                if (DelDeptsByPId(l.F_DeptId))
                {
                    new BLL.T_Sys_Department().Delete(l.F_DeptId);
                }
            }

            return bl;
        }

        #endregion

    }
}