/// <summary>
        /// 保存
        /// </summary>
        /// <returns></returns>
        public string Save2()
        {
            string Orgcode = System.Web.HttpContext.Current.Request.Params["Orgcode"];
            string data    = System.Web.HttpContext.Current.Request.Params["data"];

            Dictionary <string, object> dicWhere = new Dictionary <string, object>();

            new CreateCriteria(dicWhere).Add(ORMRestrictions <string> .Eq("Orgcode", Orgcode));
            IList <ProjectThresholdModel> projectThresholdModels = ProjectThresholdService.Find(dicWhere).Data;
            List <long> phidList = projectThresholdModels.ToList().Select(x => x.PhId).ToList();
            List <ProjectThresholdModel> SaveData = new List <ProjectThresholdModel>();

            if (data.EndsWith("|"))
            {
                data = data.Substring(0, data.Length - 1);
            }
            String[] Items = data.Split('|');
            foreach (String item in Items)
            {
                //取到item,即序列化对象
                String[] attrs = item.Split(':');
                if (string.IsNullOrEmpty(attrs[0]) || attrs[0] == "0")
                {
                    var p1 = new ProjectThresholdModel();
                    p1.Orgcode         = attrs[1];
                    p1.FThreshold      = attrs[2];
                    p1.ProjTypeId      = attrs[3];
                    p1.ProjTypeName    = attrs[4];
                    p1.Orgid           = long.Parse(attrs[5]);
                    p1.PersistentState = PersistentState.Added;
                    SaveData.Add(p1);
                }
                else
                {
                    if (phidList.Contains(long.Parse(attrs[0])))
                    {
                        phidList.Remove(long.Parse(attrs[0]));
                    }
                    var p1 = projectThresholdModels.ToList().Find(x => x.PhId == long.Parse(attrs[0]));
                    p1.FThreshold      = attrs[2];
                    p1.ProjTypeId      = attrs[3];
                    p1.ProjTypeName    = attrs[4];
                    p1.PersistentState = PersistentState.Modified;
                    SaveData.Add(p1);
                }
            }
            if (phidList.Count > 0)
            {
                foreach (var phid in phidList)
                {
                    var p1 = projectThresholdModels.ToList().Find(x => x.PhId == phid);
                    p1.PersistentState = PersistentState.Deleted;
                    SaveData.Add(p1);
                }
            }

            SavedResult <Int64> savedresult = ProjectThresholdService.Save <Int64>(SaveData, "");

            return(DataConverterHelper.SerializeObject(savedresult));
        }
        public ActionResult SaveOrUpdate(String data)
        {
            DataStoreParam dataStoreParam = this.GetDataStoreParam();
            var            result         = CorrespondenceSettingsService.LoadWithPageOrg(dataStoreParam);
            //Dictionary<string, object> dicWhere = DataConverterHelper.ConvertToDic("");
            IList <OrganizeModel> organizes = result.Results as List <OrganizeModel>;

            Dictionary <string, object> dicWhere = new Dictionary <string, object>();

            new CreateCriteria(dicWhere).Add(ORMRestrictions <Int64> .NotEq("PhId", 0));
            IList <CorrespondenceSettings2Model> correspondenceSettings2s = CorrespondenceSettings2Service.Find(dicWhere).Data as List <CorrespondenceSettings2Model>;

            //IList<CorrespondenceSettings2Model> correspondenceSettings2s = CorrespondenceSettings2Service.LoadWithPage(dataStoreParam.PageIndex, dataStoreParam.PageSize, dicWhere).Results as List<CorrespondenceSettings2Model>;
            organizes = ProjectThresholdService.GetSBOrganizes(organizes, correspondenceSettings2s);
            //IList<ProjectThresholdModel> projectThresholds = (ProjectThresholdService.LoadWithPage(dataStoreParam.PageIndex, dataStoreParam.PageSize, dicWhere)).Results as List<ProjectThresholdModel>;
            IList <ProjectThresholdModel> projectThresholds = ProjectThresholdService.Find(dicWhere).Data as List <ProjectThresholdModel>;

            if (this.ProjectThresholdService.SaveOrUpdate(data, organizes, projectThresholds, dataStoreParam))
            {
                return(Content("{\"result\":\"success\"}"));
            }
            else
            {
                return(Content("{\"result\":\"fail\"}"));
            }
        }
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <returns>返回Json串</returns>
        public string Delete()
        {
            long id = Convert.ToInt64(System.Web.HttpContext.Current.Request.Params["id"]);              //主表主键

            var deletedresult = ProjectThresholdService.Delete <System.Int64>(id);

            return(DataConverterHelper.SerializeObject(deletedresult));
        }
        /// <summary>
        /// 根据主键获取数据
        /// </summary>
        /// <returns>返回Json串</returns>
        public string GetProjectThresholdInfo()
        {
            long   id           = Convert.ToInt64(System.Web.HttpContext.Current.Request.Params["id"]); //主表主键
            string tabtype      = System.Web.HttpContext.Current.Request.Params["tabtype"];             //Tab类型
            var    findedresult = ProjectThresholdService.Find(id);

            return(DataConverterHelper.ResponseResultToJson(findedresult));
        }
        /// <summary>
        /// 取列表数据
        /// </summary>
        /// <returns>返回Json串</returns>
        public string GetProjectThresholdList()
        {
            string clientJsonQuery = System.Web.HttpContext.Current.Request.Params["queryfilter"];    //查询条件
            Dictionary <string, object> dicWhere = DataConverterHelper.ConvertToDic(clientJsonQuery); //查询条件转Dictionary

            DataStoreParam storeparam = this.GetDataStoreParam();
            var            result     = ProjectThresholdService.LoadWithPage(storeparam.PageIndex, storeparam.PageSize, dicWhere);

            return(DataConverterHelper.EntityListToJson <ProjectThresholdModel>(result.Results, (Int32)result.TotalItems));
        }
        /// <summary>
        /// 根据主键获取数据
        /// </summary>
        /// <returns>返回Json串</returns>
        public string GetProjectThresholdInfoToOrgcode()
        {
            string orgcode = System.Web.HttpContext.Current.Request.Params["orgcode"];  //组织号
            Dictionary <string, object> dicWhere = new Dictionary <string, object>();

            new CreateCriteria(dicWhere)
            .Add(ORMRestrictions <string> .Eq("Orgcode", orgcode));


            var findedresult = ProjectThresholdService.Find(dicWhere);

            return(DataConverterHelper.ResponseResultToJson(findedresult));
        }
        /// <summary>
        /// 取列表数据
        /// </summary>
        /// <returns>返回对象集合</returns>
        public IList <ProjectThresholdModel> GetPTMList()
        {
            string clientJsonQuery = System.Web.HttpContext.Current.Request.Params["queryfilter"];    //查询条件
            Dictionary <string, object> dicWhere = DataConverterHelper.ConvertToDic(clientJsonQuery); //查询条件转Dictionary

            new CreateCriteria(dicWhere).Add(ORMRestrictions <Int64> .NotEq("PhId", 0));
            DataStoreParam storeparam = this.GetDataStoreParam();
            var            result     = ProjectThresholdService.Find(dicWhere).Data;

            //ProjectThresholdService.LoadWithPage(storeparam.PageIndex, storeparam.PageSize, dicWhere);

            return(result);
        }
        /// <summary>
        /// 根据申报单位组装数据发送给前台
        /// </summary>
        /// <returns>返回Json串</returns>

        /**
         * 需要借用orange组件
         *
         *
         * */
        public string GetProjectThresholdListByUserPower()
        {
            DataStoreParam        dataStoreParam = this.GetDataStoreParam();
            var                   result         = CorrespondenceSettingsService.LoadWithPageOrg(dataStoreParam);
            IList <OrganizeModel> organizes      = result.Results as List <OrganizeModel>;
            //Dictionary<string, object> dicWhere = DataConverterHelper.ConvertToDic("");//查询条件转Dictionary
            Dictionary <string, object> dicWhere = new Dictionary <string, object>();

            new CreateCriteria(dicWhere).Add(ORMRestrictions <Int64> .NotEq("PhId", 0));
            IList <CorrespondenceSettings2Model> correspondenceSettings2s = CorrespondenceSettings2Service.Find(dicWhere).Data as List <CorrespondenceSettings2Model>;

            organizes = ProjectThresholdService.GetSBOrganizes(organizes, correspondenceSettings2s);
            IList <ProjectThresholdModel> projectThresholds = ProjectThresholdService.Find(dicWhere).Data as List <ProjectThresholdModel>;

            IList <VProjectThresholdModel> vprojectThresholds = new List <VProjectThresholdModel>();

            foreach (OrganizeModel organize in organizes)
            {
                var q1 = from dt1 in projectThresholds
                         where dt1.Orgid == organize.PhId
                         select dt1;
                VProjectThresholdModel pt1 = new VProjectThresholdModel();
                if (q1.Count() == 0)
                {
                    pt1.Orgcode    = organize.OCode;
                    pt1.Orgid      = organize.PhId;
                    pt1.FThreshold = "未设置";
                }
                if (q1.Count() == 1)
                {
                    var pm = q1.ToList()[0];
                    pt1.PhId         = pm.PhId;
                    pt1.Orgid        = pm.Orgid;
                    pt1.Orgcode      = pm.Orgcode;
                    pt1.FThreshold   = pm.FThreshold;
                    pt1.ProjTypeId   = pm.ProjTypeId;
                    pt1.ProjTypeName = pm.ProjTypeName;
                }


                pt1.Orgname = organize.OName;
                vprojectThresholds.Add(pt1);
            }

            return(DataConverterHelper.EntityListToJson <VProjectThresholdModel>(vprojectThresholds, (Int32)vprojectThresholds.Count()));


            //return DataConverterHelper.EntityListToJson<ProjectThresholdModel>(result.Results, (Int32)result.TotalItems);
        }
        /// <summary>
        /// 右边的已选项目类型
        /// </summary>
        /// <returns></returns>
        public String GetRightExpenseCategoryModel()
        {
            string Orgcode = System.Web.HttpContext.Current.Request.Params["Orgcode"];
            string PhId    = System.Web.HttpContext.Current.Request.Params["PhId"];
            List <ExpenseCategoryModel> expenseCategoryModels = new List <ExpenseCategoryModel>();

            if (!string.IsNullOrEmpty(PhId))
            {
                ProjectThresholdModel projectThreshold = ProjectThresholdService.Find(long.Parse(PhId)).Data;
                expenseCategoryModels = this.GetAllExpenseCategoryModel(Orgcode).ToList();
                IList <String> useCodeList = (projectThreshold.ProjTypeId ?? "").Split(',').ToList <String>();
                expenseCategoryModels = expenseCategoryModels.Where(x => useCodeList.Contains(x.Dm)).ToList();
                expenseCategoryModels.Sort((ExpenseCategoryModel a, ExpenseCategoryModel b) => a.Dm.CompareTo(b.Dm));
            }

            return(DataConverterHelper.EntityListToJson <ExpenseCategoryModel>(expenseCategoryModels, (Int32)expenseCategoryModels.Count));
        }
        /// <summary>
        /// 根据组织取数
        /// </summary>
        /// <returns></returns>
        public string GetProjectThresholdListByOrg()
        {
            string Orgcode = System.Web.HttpContext.Current.Request.Params["Orgcode"];
            Dictionary <string, object> dicWhere = new Dictionary <string, object>();

            if (!string.IsNullOrEmpty(Orgcode))
            {
                new CreateCriteria(dicWhere).Add(ORMRestrictions <string> .Eq("Orgcode", Orgcode));
            }
            else
            {
                new CreateCriteria(dicWhere).Add(ORMRestrictions <Int64> .NotEq("PhId", 0));
            }
            IList <ProjectThresholdModel> projectThresholds = ProjectThresholdService.Find(dicWhere).Data;

            return(DataConverterHelper.EntityListToJson <ProjectThresholdModel>(projectThresholds, (Int32)projectThresholds.Count()));
        }
        /// <summary>
        /// 保存数据
        /// </summary>
        /// <returns>返回Json串</returns>
        public string Save()
        {
            string projectthresholdformData = System.Web.HttpContext.Current.Request.Form["projectthresholdformData"];

            var projectthresholdforminfo = DataConverterHelper.JsonToEntity <ProjectThresholdModel>(projectthresholdformData);

            SavedResult <Int64> savedresult = new SavedResult <Int64>();

            try
            {
                savedresult = ProjectThresholdService.Save <Int64>(projectthresholdforminfo.AllRow, "");
            }
            catch (Exception ex)
            {
                savedresult.Status = ResponseStatus.Error;
                savedresult.Msg    = ex.Message.ToString();
            }
            return(DataConverterHelper.SerializeObject(savedresult));
        }
        /// <summary>
        /// 根据组织和项目类型取阈值
        /// </summary>
        /// <returns></returns>
        public string GetProjectThresholdByOrgAndZCLB()
        {
            string Orgcode = System.Web.HttpContext.Current.Request.Params["Orgcode"];
            string FExpenseCategoryCode          = System.Web.HttpContext.Current.Request.Params["FExpenseCategoryCode"];
            Dictionary <string, object> dicWhere = new Dictionary <string, object>();

            new CreateCriteria(dicWhere).Add(ORMRestrictions <string> .Eq("Orgcode", Orgcode));
            IList <ProjectThresholdModel> projectThresholds = ProjectThresholdService.Find(dicWhere).Data;

            if (projectThresholds.Count > 0)
            {
                foreach (var projectThreshold in projectThresholds)
                {
                    IList <String> useCodeList = (projectThreshold.ProjTypeId ?? "").Split(',').ToList <String>();
                    if (useCodeList.Contains(FExpenseCategoryCode))
                    {
                        return(DataConverterHelper.ResponseResultToJson(projectThreshold));
                    }
                }
            }
            return(DataConverterHelper.ResponseResultToJson(new ProjectThresholdModel()));
        }
        /// <summary>
        /// 左边的可选项目类型
        /// </summary>
        /// <returns></returns>
        public String GetLeftExpenseCategoryModel()
        {
            string Orgcode = System.Web.HttpContext.Current.Request.Params["Orgcode"];
            Dictionary <string, object> dicWhere = new Dictionary <string, object>();

            new CreateCriteria(dicWhere).Add(ORMRestrictions <string> .Eq("Orgcode", Orgcode));
            List <ExpenseCategoryModel> ALLData = this.GetAllExpenseCategoryModel(Orgcode).ToList();

            if (ALLData.Count > 0)
            {
                List <String> useCodeList = new List <string>();
                IList <ProjectThresholdModel> projectThresholdModels = ProjectThresholdService.Find(dicWhere).Data;
                if (projectThresholdModels.Count > 0)
                {
                    foreach (var projectThresholdModel in projectThresholdModels)
                    {
                        useCodeList = useCodeList.Union((projectThresholdModel.ProjTypeId ?? "").Split(',').ToList()).ToList();
                    }
                }
                ALLData = ALLData.Where(x => !useCodeList.Contains(x.Dm)).ToList();
                ALLData.Sort((ExpenseCategoryModel a, ExpenseCategoryModel b) => a.Dm.CompareTo(b.Dm));
            }
            return(DataConverterHelper.EntityListToJson <ExpenseCategoryModel>(ALLData, (Int32)ALLData.Count));
        }