public static SysData_ProjectCaseCount GetById(long id, DataClass _db = null)
        {
            DataClass db = new DataClass(_db);
            SysData_ProjectCaseCount obj = null;

            obj = db.DB.SysData_ProjectCaseCount.FirstOrDefault(p => p.ID == id);
            db.Connection_Close();
            db.Dispose();
            return(obj);
        }
        public static SysData_ProjectCaseCount GetProjectCaseCountByProjectAndAreaId(long projectId, long areaId, DataClass _db = null)
        {
            DataClass db = new DataClass(_db);
            SysData_ProjectCaseCount obj = null;

            obj = db.DB.SysData_ProjectCaseCount.FirstOrDefault(p => p.ProjectId == projectId && p.AreaId == areaId);
            db.Connection_Close();
            db.Dispose();
            return(obj);
        }
        public static SysData_ProjectCaseCount InsertProjectCaseCount(long projectId, long areaId, int notImportCaseCount, DataClass _db = null)
        {
            DataClass db = new DataClass(_db);
            SysData_ProjectCaseCount obj = null;

            obj = GetProjectCaseCountByProjectAndAreaId(projectId, areaId, db);
            if (obj == null)
            {
                obj                    = new SysData_ProjectCaseCount();
                obj.ProjectId          = projectId;
                obj.AreaId             = areaId;
                obj.NotImportCaseCount = notImportCaseCount;
                db.DB.SysData_ProjectCaseCount.InsertOnSubmit(obj);
                db.DB.SubmitChanges();
            }
            db.Connection_Close();
            db.Dispose();
            return(obj);
        }
        public static bool UpdateNotImportCaseCount(long projectId, long areaId, int count, DataClass _db = null)
        {
            DataClass db = new DataClass(_db);
            SysData_ProjectCaseCount obj = GetProjectCaseCountByProjectAndAreaId(projectId, areaId, db);
            bool result = false;

            if (obj != null)
            {
                obj.NotImportCaseCount = obj.NotImportCaseCount + count;
                db.DB.SubmitChanges();
                result = true;
            }
            else
            {
                InsertProjectCaseCount(projectId, areaId, count, db);
                result = true;
            }
            db.Connection_Close();
            db.Dispose();
            return(result);
        }
        /// <summary>
        /// 导入案例后统计未入库案例个数
        /// </summary>
        /// <param name="importCaseList">准备导入的案例</param>
        /// <param name="notImportCase">导入失败的案例</param>
        /// <param name="message"></param>
        /// <param name="_db"></param>
        /// <returns></returns>
        public static bool UpdateNotImportCaseCount(List <案例信息> importCaseList, List <案例库上传信息过滤表> notImportCase, out string message, DataClass _db = null)
        {
            message = "";
            DataClass db = new DataClass(_db);

            try
            {
                //设置案例楼盘ID,行政区ID,片区ID
                importCaseList = ProjectManager.SetProjectId(importCaseList, _dc: db);
                List <SysData_ProjectCaseCount> addCount    = new List <SysData_ProjectCaseCount>();
                List <SysData_ProjectCaseCount> updateCount = GetSysData_ProjectCaseCountByCase(importCaseList, _db: db);
                foreach (案例信息 caseObj in importCaseList)
                {
                    if (caseObj.fxtId != null)
                    {
                        continue;
                    }
                    bool nowObj = false;//true:新实体,false:存在实体
                    SysData_ProjectCaseCount countObj = updateCount.Where(tbl => tbl.ProjectId == Convert.ToInt64(caseObj.ProjectId) && tbl.AreaId == Convert.ToInt64(caseObj.AreaId)).FirstOrDefault();
                    //个数记录不存在
                    if (countObj == null)
                    {
                        countObj = addCount.Where(tbl => tbl.ProjectId == Convert.ToInt64(caseObj.ProjectId) && tbl.AreaId == Convert.ToInt64(caseObj.AreaId)).FirstOrDefault();
                        if (countObj == null)
                        {
                            nowObj   = true;
                            countObj = new SysData_ProjectCaseCount {
                                ProjectId = Convert.ToInt64(caseObj.ProjectId), AreaId = Convert.ToInt64(caseObj.AreaId), NotImportCaseCount = 0
                            };
                        }
                    }
                    案例库上传信息过滤表 notImport = notImportCase.Where(tbl => tbl.案例ID == caseObj.ID).FirstOrDefault();
                    //当前为导入成功的
                    if (notImport == null)
                    {
                        //当前案例为曾经导入失败的案例
                        if (caseObj.是否已进行入库整理 == 1 && countObj.NotImportCaseCount > 0)
                        {
                            countObj.NotImportCaseCount = countObj.NotImportCaseCount - 1;
                        }
                    }
                    else//当前为导入失败的
                    {
                        //当前案例为曾经导入失败的案例
                        if (caseObj.是否已进行入库整理 != 1)
                        {
                            countObj.NotImportCaseCount = countObj.NotImportCaseCount + 1;
                        }
                    }
                    if (nowObj)
                    {
                        addCount.Add(countObj);
                    }
                }
                db.DB.SysData_ProjectCaseCount.InsertAllOnSubmit(addCount);
                db.DB.SubmitChanges();
            }
            catch (Exception ex)
            {
                db.Connection_Close();
                db.Dispose();
                message = "导入案例后统计未入库案例个数_系统异常";
                log.Error("UpdateNotImportCaseCount(List<VIEW_案例信息_城市表_网站表> importCaseList, List<案例库上传信息过滤表> notImportCase,out string message, DataClass _db = null)", ex);

                return(false);
            }
            db.Connection_Close();
            db.Dispose();
            return(true);
        }