BuildingsInfoServices.cs 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using System.Text;
  6. using System.Text.RegularExpressions;
  7. using System.Transactions;
  8. using Bowin.Common.Linq;
  9. using Bowin.Common.Linq.Entity;
  10. using Bowin.Common.Utility;
  11. using EMIS.Entities;
  12. using EMIS.Utility;
  13. using EMIS.ViewModel;
  14. using EMIS.ViewModel.CacheManage;
  15. using EMIS.ViewModel.UniversityManage.ClassroomManage;
  16. using EMIS.DataLogic.UniversityManage.ClassroomManage;
  17. namespace EMIS.CommonLogic.UniversityManage.ClassroomManage
  18. {
  19. public class BuildingsInfoServices : BaseServices, IBuildingsInfoServices
  20. {
  21. public BuildingsInfoDAL BuildingsInfoDAL { get; set; }
  22. /// <summary>
  23. /// 查询对应的建筑信息View
  24. /// </summary>
  25. /// <param name="configuretView"></param>
  26. /// <param name="campusID"></param>
  27. /// <param name="collegeID"></param>
  28. /// <param name="buildingsTypeID"></param>
  29. /// <param name="isSpecial"></param>
  30. /// <param name="pageIndex"></param>
  31. /// <param name="pageSize"></param>
  32. /// <returns></returns>
  33. public IGridResultSet<BuildingsInfoView> GetBuildingsInfoViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? buildingsTypeID, int? isSpecial, int pageIndex, int pageSize)
  34. {
  35. Expression<Func<CF_BuildingsInfo, bool>> expBuildingsInfo = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  36. if (campusID.HasValue)
  37. {
  38. //校区
  39. expBuildingsInfo = expBuildingsInfo.And(x => x.CampusID == campusID);
  40. }
  41. if (collegeID.HasValue)
  42. {
  43. //所属院系所
  44. expBuildingsInfo = expBuildingsInfo.And(x => x.CollegeID == collegeID);
  45. }
  46. if (buildingsTypeID.HasValue)
  47. {
  48. //建筑类型
  49. expBuildingsInfo = expBuildingsInfo.And(x => x.BuildingsTypeID == buildingsTypeID);
  50. }
  51. if (isSpecial.HasValue)
  52. {
  53. //是否启用
  54. if (isSpecial.Value == (int)CF_GeneralPurpose.IsYes)
  55. {
  56. expBuildingsInfo = expBuildingsInfo.And(x => x.IsSpecial == true);
  57. }
  58. if (isSpecial.Value == (int)CF_GeneralPurpose.IsNo)
  59. {
  60. expBuildingsInfo = expBuildingsInfo.And(x => x.IsSpecial != true);
  61. }
  62. }
  63. var query = BuildingsInfoDAL.GetBuildingsInfoViewQueryable(expBuildingsInfo);
  64. //查询条件
  65. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  66. {
  67. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  68. }
  69. return this.GetQueryByDataRangeByCampus(query).OrderBy(x => x.CampusCode.Length).ThenBy(x => x.CampusCode).ThenBy(x => x.Code.Length)
  70. .ThenBy(x => x.Code).ThenBy(x => x.BuildingsTypeID).ThenBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode).ToGridResultSet<BuildingsInfoView>(pageIndex, pageSize);
  71. }
  72. /// <summary>
  73. /// 查询对应的建筑信息List
  74. /// </summary>
  75. /// <param name="configuretView"></param>
  76. /// <param name="campusID"></param>
  77. /// <param name="collegeID"></param>
  78. /// <param name="buildingsTypeID"></param>
  79. /// <param name="isSpecial"></param>
  80. /// <returns></returns>
  81. public IList<BuildingsInfoView> GetBuildingsInfoViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? buildingsTypeID, int? isSpecial)
  82. {
  83. Expression<Func<CF_BuildingsInfo, bool>> expBuildingsInfo = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  84. if (campusID.HasValue)
  85. {
  86. //校区
  87. expBuildingsInfo = expBuildingsInfo.And(x => x.CampusID == campusID);
  88. }
  89. if (collegeID.HasValue)
  90. {
  91. //所属院系所
  92. expBuildingsInfo = expBuildingsInfo.And(x => x.CollegeID == collegeID);
  93. }
  94. if (buildingsTypeID.HasValue)
  95. {
  96. //建筑类型
  97. expBuildingsInfo = expBuildingsInfo.And(x => x.BuildingsTypeID == buildingsTypeID);
  98. }
  99. if (isSpecial.HasValue)
  100. {
  101. //是否启用
  102. if (isSpecial.Value == (int)CF_GeneralPurpose.IsYes)
  103. {
  104. expBuildingsInfo = expBuildingsInfo.And(x => x.IsSpecial == true);
  105. }
  106. if (isSpecial.Value == (int)CF_GeneralPurpose.IsNo)
  107. {
  108. expBuildingsInfo = expBuildingsInfo.And(x => x.IsSpecial != true);
  109. }
  110. }
  111. var query = BuildingsInfoDAL.GetBuildingsInfoViewQueryable(expBuildingsInfo);
  112. //查询条件
  113. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  114. {
  115. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  116. }
  117. return this.GetQueryByDataRangeByCampus(query).OrderBy(x => x.CampusCode.Length).ThenBy(x => x.CampusCode).ThenBy(x => x.Code.Length)
  118. .ThenBy(x => x.Code).ThenBy(x => x.BuildingsTypeID).ThenBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode).ToList();
  119. }
  120. /// <summary>
  121. /// 查询对应的建筑信息CF_BuildingsInfo
  122. /// </summary>
  123. /// <param name="buildingsInfoID"></param>
  124. /// <returns></returns>
  125. public CF_BuildingsInfo GetBuildingsInfo(Guid? buildingsInfoID)
  126. {
  127. try
  128. {
  129. var query = BuildingsInfoDAL.BuildingsInfoRepository.GetList(x => x.BuildingsInfoID == buildingsInfoID).SingleOrDefault();
  130. return query;
  131. }
  132. catch (Exception ex)
  133. {
  134. throw new Exception(ex.Message);
  135. }
  136. }
  137. /// <summary>
  138. /// 查询对应的建筑信息BuildingsInfoView
  139. /// </summary>
  140. /// <param name="buildingsInfoID"></param>
  141. /// <returns></returns>
  142. public BuildingsInfoView GetBuildingsInfoView(Guid? buildingsInfoID)
  143. {
  144. try
  145. {
  146. var query = BuildingsInfoDAL.GetBuildingsInfoViewQueryable(x => x.BuildingsInfoID == buildingsInfoID).SingleOrDefault();
  147. return query;
  148. }
  149. catch (Exception ex)
  150. {
  151. throw new Exception(ex.Message);
  152. }
  153. }
  154. /// <summary>
  155. /// 编辑(新增、修改,业务主键:建筑编号唯一)
  156. /// </summary>
  157. /// <param name="buildingsInfoView"></param>
  158. public void BuildingsInfoEdit(BuildingsInfoView buildingsInfoView)
  159. {
  160. try
  161. {
  162. //查询数据库进行验证
  163. var buildingsInfoVerify = BuildingsInfoDAL.BuildingsInfoRepository.GetList(x => x.BuildingsInfoID != buildingsInfoView.BuildingsInfoID && x.Code == buildingsInfoView.Code).FirstOrDefault();
  164. if (buildingsInfoVerify == null)
  165. {
  166. //数据有误验证
  167. if (buildingsInfoView.BuildingsInfoID != Guid.Empty)
  168. {
  169. var buildingsInfo = BuildingsInfoDAL.BuildingsInfoRepository.GetList(x => x.BuildingsInfoID == buildingsInfoView.BuildingsInfoID).SingleOrDefault();
  170. if (buildingsInfo == null)
  171. {
  172. throw new Exception("数据有误,请核查");
  173. }
  174. else
  175. {
  176. //表示修改
  177. buildingsInfo.Code = buildingsInfoView.Code.Trim();
  178. buildingsInfo.Name = buildingsInfoView.Name;
  179. buildingsInfo.CampusID = buildingsInfoView.CampusID;
  180. buildingsInfo.CollegeID = buildingsInfoView.CollegeID;
  181. buildingsInfo.BuildingsTypeID = buildingsInfoView.BuildingsTypeID;
  182. buildingsInfo.BuildingsStatusID = buildingsInfoView.BuildingsStatusID;
  183. buildingsInfo.BuildingsLevel = buildingsInfoView.BuildingsLevel;
  184. buildingsInfo.BuildingsArea = buildingsInfoView.BuildingsArea;
  185. buildingsInfo.UseArea = buildingsInfoView.UseArea;
  186. buildingsInfo.Position = buildingsInfoView.Position;
  187. buildingsInfo.IsSpecial = buildingsInfoView.IsSpecial;
  188. buildingsInfo.Remark = buildingsInfoView.Remark;
  189. SetModifyStatus(buildingsInfo);
  190. }
  191. }
  192. else
  193. {
  194. //表示新增
  195. CF_BuildingsInfo buildingsInfo = new CF_BuildingsInfo();
  196. buildingsInfo.BuildingsInfoID = Guid.NewGuid();
  197. buildingsInfo.Code = buildingsInfoView.Code.Trim();
  198. buildingsInfo.Name = buildingsInfoView.Name;
  199. buildingsInfo.CampusID = buildingsInfoView.CampusID;
  200. buildingsInfo.CollegeID = buildingsInfoView.CollegeID;
  201. buildingsInfo.BuildingsTypeID = buildingsInfoView.BuildingsTypeID;
  202. buildingsInfo.BuildingsStatusID = buildingsInfoView.BuildingsStatusID;
  203. buildingsInfo.BuildingsLevel = buildingsInfoView.BuildingsLevel;
  204. buildingsInfo.BuildingsArea = buildingsInfoView.BuildingsArea;
  205. buildingsInfo.UseArea = buildingsInfoView.UseArea;
  206. buildingsInfo.Position = buildingsInfoView.Position;
  207. buildingsInfo.IsSpecial = buildingsInfoView.IsSpecial;
  208. buildingsInfo.Remark = buildingsInfoView.Remark;
  209. SetNewStatus(buildingsInfo);
  210. UnitOfWork.Add(buildingsInfo);
  211. }
  212. }
  213. else
  214. {
  215. throw new Exception("已存在相同的建筑编号,请核查");
  216. }
  217. //事务提交
  218. UnitOfWork.Commit();
  219. }
  220. catch (Exception ex)
  221. {
  222. throw new Exception(ex.Message);
  223. }
  224. }
  225. /// <summary>
  226. /// 删除
  227. /// </summary>
  228. /// <param name="buildingsInfoIDList"></param>
  229. /// <returns></returns>
  230. public bool BuildingsInfoDelete(List<Guid?> buildingsInfoIDList)
  231. {
  232. try
  233. {
  234. UnitOfWork.Delete<CF_BuildingsInfo>(x => buildingsInfoIDList.Contains(x.BuildingsInfoID));
  235. UnitOfWork.Commit();
  236. return true;
  237. }
  238. catch (Exception)
  239. {
  240. throw;
  241. }
  242. }
  243. /// <summary>
  244. /// 查询建筑信息中对应的教室信息View(关联排课中教室预留信息、统计排课分配的院系个数)
  245. /// </summary>
  246. /// <param name="configuretView"></param>
  247. /// <param name="buildingsInfoID"></param>
  248. /// <param name="classroomName"></param>
  249. /// <param name="classroomTypeID"></param>
  250. /// <param name="collegeID"></param>
  251. /// <param name="isConcurrentUse"></param>
  252. /// <param name="isReserve"></param>
  253. /// <param name="isAvailable"></param>
  254. /// <param name="pageIndex"></param>
  255. /// <param name="pageSize"></param>
  256. /// <returns></returns>
  257. public IGridResultSet<ClassroomView> GetClassroomViewGrid(ConfiguretView configuretView, Guid? buildingsInfoID, string classroomName, int? classroomTypeID, Guid? collegeID, int? isConcurrentUse, int? isReserve, int? isAvailable, int pageIndex, int pageSize)
  258. {
  259. Expression<Func<CF_BuildingsInfo, bool>> expBuildingsInfo = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  260. expBuildingsInfo = expBuildingsInfo.And(x => x.BuildingsInfoID == buildingsInfoID);
  261. var query = BuildingsInfoDAL.GetClassroomViewQueryable(expBuildingsInfo);
  262. if (!string.IsNullOrEmpty(classroomName) && classroomName != "-1")
  263. {
  264. //教室名称
  265. query = query.Where(x => x.Name == classroomName);
  266. }
  267. if (classroomTypeID.HasValue)
  268. {
  269. //教室类型(模糊查询)
  270. query = query.Where(x => x.CF_ClassroomType.Select(w => w.ClassroomType).Contains(classroomTypeID));
  271. }
  272. if (collegeID.HasValue)
  273. {
  274. //所属院系所
  275. query = query.Where(x => x.CollegeID == collegeID);
  276. }
  277. if (isConcurrentUse.HasValue)
  278. {
  279. //可否多班教学
  280. if (isConcurrentUse.Value == (int)CF_GeneralPurpose.IsYes)
  281. {
  282. query = query.Where(x => x.IsConcurrentUse == true);
  283. }
  284. if (isConcurrentUse.Value == (int)CF_GeneralPurpose.IsNo)
  285. {
  286. query = query.Where(x => x.IsConcurrentUse != true);
  287. }
  288. }
  289. if (isReserve.HasValue)
  290. {
  291. //是否预留(排课用)
  292. if (isReserve.Value == (int)CF_GeneralPurpose.IsYes)
  293. {
  294. query = query.Where(x => x.IsReserve == true);
  295. }
  296. if (isReserve.Value == (int)CF_GeneralPurpose.IsNo)
  297. {
  298. query = query.Where(x => x.IsReserve != true);
  299. }
  300. }
  301. if (isAvailable.HasValue)
  302. {
  303. //是否可用
  304. if (isAvailable.Value == (int)CF_GeneralPurpose.IsYes)
  305. {
  306. query = query.Where(x => x.IsAvailable == true);
  307. }
  308. if (isAvailable.Value == (int)CF_GeneralPurpose.IsNo)
  309. {
  310. query = query.Where(x => x.IsAvailable != true);
  311. }
  312. }
  313. //查询条件
  314. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  315. {
  316. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  317. }
  318. return query.OrderBy(x => x.BuildingsInfoCode.Length).ThenBy(x => x.BuildingsInfoCode).ThenBy(x => x.Code.Length).ThenBy(x => x.Code)
  319. .ThenBy(x => x.RoomUseID).ThenBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode).ToGridResultSet<ClassroomView>(pageIndex, pageSize);
  320. }
  321. /// <summary>
  322. /// 查询建筑信息中对应的教室信息List(关联排课中教室预留信息、统计排课分配的院系个数)
  323. /// </summary>
  324. /// <param name="configuretView"></param>
  325. /// <param name="buildingsInfoID"></param>
  326. /// <param name="classroomName"></param>
  327. /// <param name="classroomTypeID"></param>
  328. /// <param name="collegeID"></param>
  329. /// <param name="isConcurrentUse"></param>
  330. /// <param name="isReserve"></param>
  331. /// <param name="isAvailable"></param>
  332. /// <returns></returns>
  333. public IList<ClassroomView> GetClassroomViewList(ConfiguretView configuretView, Guid? buildingsInfoID, string classroomName,
  334. int? classroomTypeID, Guid? collegeID, int? isConcurrentUse, int? isReserve, int? isAvailable)
  335. {
  336. Expression<Func<CF_BuildingsInfo, bool>> expBuildingsInfo = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  337. expBuildingsInfo = expBuildingsInfo.And(x => x.BuildingsInfoID == buildingsInfoID);
  338. var query = BuildingsInfoDAL.GetClassroomViewQueryable(expBuildingsInfo);
  339. if (!string.IsNullOrEmpty(classroomName) && classroomName != "-1")
  340. {
  341. //教室名称
  342. query = query.Where(x => x.Name == classroomName);
  343. }
  344. if (classroomTypeID.HasValue)
  345. {
  346. //教室类型(模糊查询)
  347. query = query.Where(x => x.CF_ClassroomType.Select(w => w.ClassroomType).Contains(classroomTypeID));
  348. }
  349. if (collegeID.HasValue)
  350. {
  351. //所属院系所
  352. query = query.Where(x => x.CollegeID == collegeID);
  353. }
  354. if (isConcurrentUse.HasValue)
  355. {
  356. //可否多班教学
  357. if (isConcurrentUse.Value == (int)CF_GeneralPurpose.IsYes)
  358. {
  359. query = query.Where(x => x.IsConcurrentUse == true);
  360. }
  361. if (isConcurrentUse.Value == (int)CF_GeneralPurpose.IsNo)
  362. {
  363. query = query.Where(x => x.IsConcurrentUse != true);
  364. }
  365. }
  366. if (isReserve.HasValue)
  367. {
  368. //是否预留(排课用)
  369. if (isReserve.Value == (int)CF_GeneralPurpose.IsYes)
  370. {
  371. query = query.Where(x => x.IsReserve == true);
  372. }
  373. if (isReserve.Value == (int)CF_GeneralPurpose.IsNo)
  374. {
  375. query = query.Where(x => x.IsReserve != true);
  376. }
  377. }
  378. if (isAvailable.HasValue)
  379. {
  380. //是否可用
  381. if (isAvailable.Value == (int)CF_GeneralPurpose.IsYes)
  382. {
  383. query = query.Where(x => x.IsAvailable == true);
  384. }
  385. if (isAvailable.Value == (int)CF_GeneralPurpose.IsNo)
  386. {
  387. query = query.Where(x => x.IsAvailable != true);
  388. }
  389. }
  390. //查询条件
  391. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  392. {
  393. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  394. }
  395. return query.OrderBy(x => x.BuildingsInfoCode.Length).ThenBy(x => x.BuildingsInfoCode).ThenBy(x => x.Code.Length).ThenBy(x => x.Code)
  396. .ThenBy(x => x.RoomUseID).ThenBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode).ToList();
  397. }
  398. /// <summary>
  399. /// 建筑信息Excel导入
  400. /// </summary>
  401. /// <param name="cellheader"></param>
  402. /// <param name="inCount"></param>
  403. /// <param name="upCount"></param>
  404. /// <param name="errdataList"></param>
  405. /// <param name="errCount"></param>
  406. /// <param name="sourcePhysicalPath"></param>
  407. public void BuildingsInfoImport(Dictionary<string, string> cellheader, out int? inCount, out int? upCount, out List<BuildingsInfoView> errdataList, out int? errCount, string sourcePhysicalPath)
  408. {
  409. try
  410. {
  411. StringBuilder errorMsg = new StringBuilder();
  412. List<BuildingsInfoView> errList = new List<BuildingsInfoView>();
  413. cellheader.Remove("ErrorMessage");
  414. List<BuildingsInfoView> enlist = NpoiExcelHelper.ExcelToEntityList<BuildingsInfoView>(cellheader, sourcePhysicalPath, out errorMsg, out errList);
  415. cellheader.Add("ErrorMessage", "未导入原因");
  416. //对List集合进行有效性校验
  417. if (enlist.Count() <= 0)
  418. {
  419. throw new Exception("Excel文件数据为空,请检查。");
  420. }
  421. Regex reg = null; //正则表达式
  422. //DateTime result; //用于返回判断日期字段格式
  423. inCount = 0; //导入个数
  424. upCount = 0; //更新个数
  425. errCount = 0; //失败个数
  426. string errorMsgStr = ""; //错误信息
  427. List<CF_BuildingsInfo> newBuildingsInfoInList = new List<CF_BuildingsInfo>();
  428. List<CF_BuildingsInfo> newBuildingsInfoUpList = new List<CF_BuildingsInfo>();
  429. //将循环中相关数据库查询统一查询出来进行匹配(尽量避免在循环中进行数据库查询)
  430. //校区信息
  431. var campusList = BuildingsInfoDAL.CampusRepository.GetList(x => true).ToList();
  432. //校区代码
  433. var campusNoList = enlist.Where(x => !string.IsNullOrEmpty(x.CampusCode)).Select(x => x.CampusCode).ToList();
  434. //对比后的newCampusList
  435. var newCampusList = campusList.Where(x => campusNoList.Contains(x.No)).ToList();
  436. //院系所信息
  437. var collegeList = BuildingsInfoDAL.CollegeRepository.GetList(x => true, x => x.CF_Campus).ToList();
  438. //院系所代码
  439. var collegeNoList = enlist.Where(x => !string.IsNullOrEmpty(x.CollegeCode)).Select(x => x.CollegeCode).ToList();
  440. //对比后的newCollegeList
  441. var newCollegeList = collegeList.Where(x => collegeNoList.Contains(x.No)).ToList();
  442. //建筑类型
  443. var buildingsTypeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_BuildingsType).ToList();
  444. //建筑状况
  445. var buildingsStatusList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_BuildingsStatus).ToList();
  446. //是否启用
  447. var generalPurposeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_GeneralPurpose).ToList();
  448. //建筑信息
  449. var buildingsInfoList = BuildingsInfoDAL.BuildingsInfoRepository.GetList(x => true).ToList();
  450. //建筑编号
  451. var buildingsInfoCodeList = enlist.Where(x => !string.IsNullOrEmpty(x.Code)).Select(x => x.Code).ToList();
  452. //对比后的newBuildingsInfoList(暂时只对比建筑编号)
  453. var newBuildingsInfoList = buildingsInfoList.Where(x => buildingsInfoCodeList.Contains(x.Code)).ToList();
  454. //循环检测数据列,对各数据列进行验证(必填、字典项验证、数据格式等)
  455. for (int i = 0; i < enlist.Count; i++)
  456. {
  457. BuildingsInfoView en = enlist[i]; //Excel表数据视图
  458. CF_BuildingsInfo newBuildingsInfo = new CF_BuildingsInfo();
  459. //建筑编号
  460. if (string.IsNullOrWhiteSpace(en.Code))
  461. {
  462. errCount++;
  463. errorMsgStr = "建筑编号不能为空";
  464. en.ErrorMessage = errorMsgStr;
  465. errList.Add(en);
  466. errorMsg.AppendLine(errorMsgStr);
  467. continue;
  468. }
  469. else
  470. {
  471. reg = new Regex(@"^[0-9a-zA-Z\s?]+$"); //正则表达式(请输入数字或英文字母)
  472. if (!reg.IsMatch(en.Code.Trim()))
  473. {
  474. errCount++;
  475. errorMsgStr = "建筑编号格式不正确,请检查(数字或英文字母)";
  476. en.ErrorMessage = errorMsgStr;
  477. errList.Add(en);
  478. errorMsg.AppendLine(errorMsgStr);
  479. continue;
  480. }
  481. else
  482. {
  483. //建筑编号
  484. newBuildingsInfo.Code = en.Code.Trim();
  485. }
  486. }
  487. //建筑名称
  488. if (string.IsNullOrWhiteSpace(en.Name))
  489. {
  490. errCount++;
  491. errorMsgStr = "建筑名称不能为空";
  492. en.ErrorMessage = errorMsgStr;
  493. errList.Add(en);
  494. errorMsg.AppendLine(errorMsgStr);
  495. continue;
  496. }
  497. else
  498. {
  499. //建筑名称
  500. newBuildingsInfo.Name = en.Name.Trim();
  501. }
  502. //校区代码
  503. if (string.IsNullOrWhiteSpace(en.CampusCode))
  504. {
  505. errCount++;
  506. errorMsgStr = RSL.Get("CampusCode") + "不能为空";
  507. en.ErrorMessage = errorMsgStr;
  508. errList.Add(en);
  509. errorMsg.AppendLine(errorMsgStr);
  510. continue;
  511. }
  512. else
  513. {
  514. reg = new Regex(@"^[0-9a-zA-Z\s?]+$"); //正则表达式(请输入数字或英文字母)
  515. if (!reg.IsMatch(en.CampusCode.Trim()))
  516. {
  517. errCount++;
  518. errorMsgStr = RSL.Get("CampusCode") + "格式不正确,请检查(数字或英文字母)";
  519. en.ErrorMessage = errorMsgStr;
  520. errList.Add(en);
  521. errorMsg.AppendLine(errorMsgStr);
  522. continue;
  523. }
  524. else
  525. {
  526. var campus = newCampusList.Where(x => x.No == en.CampusCode.Trim()).SingleOrDefault();
  527. if (campus == null)
  528. {
  529. errCount++;
  530. errorMsgStr = RSL.Get("CampusCode") + "不存在,请检查";
  531. en.ErrorMessage = errorMsgStr;
  532. errList.Add(en);
  533. errorMsg.AppendLine(errorMsgStr);
  534. continue;
  535. }
  536. else
  537. {
  538. //校区信息ID
  539. newBuildingsInfo.CampusID = campus.CampusID;
  540. }
  541. }
  542. }
  543. //院系所代码
  544. if (string.IsNullOrWhiteSpace(en.CollegeCode))
  545. {
  546. //不考虑
  547. }
  548. else
  549. {
  550. reg = new Regex(@"^[0-9a-zA-Z\s?]+$"); //正则表达式(请输入数字或英文字母)
  551. if (!reg.IsMatch(en.CollegeCode.Trim()))
  552. {
  553. errCount++;
  554. errorMsgStr = RSL.Get("CollegeCode") + "格式不正确,请检查(数字或英文字母)";
  555. en.ErrorMessage = errorMsgStr;
  556. errList.Add(en);
  557. errorMsg.AppendLine(errorMsgStr);
  558. continue;
  559. }
  560. else
  561. {
  562. var college = newCollegeList.Where(x => x.No == en.CollegeCode.Trim()).SingleOrDefault();
  563. if (college == null)
  564. {
  565. errCount++;
  566. errorMsgStr = RSL.Get("CollegeCode") + "不存在,请检查";
  567. en.ErrorMessage = errorMsgStr;
  568. errList.Add(en);
  569. errorMsg.AppendLine(errorMsgStr);
  570. continue;
  571. }
  572. else
  573. {
  574. ////判断院系所对应的校区(暂不考虑)
  575. //if (college.CampusID == newBuildingsInfo.CampusID)
  576. //{
  577. // //院系所信息ID
  578. // newBuildingsInfo.CollegeID = college.CollegeID;
  579. //}
  580. //else
  581. //{
  582. // errCount++;
  583. // errorMsgStr = RSL.Get("CampusCode") + "与" + RSL.Get("CollegeCode") + "对应关系不存在,请检查";
  584. // en.ErrorMessage = errorMsgStr;
  585. // errList.Add(en);
  586. // errorMsg.AppendLine(errorMsgStr);
  587. // continue;
  588. //}
  589. //院系所信息ID
  590. newBuildingsInfo.CollegeID = college.CollegeID;
  591. }
  592. }
  593. }
  594. //建筑类型
  595. if (string.IsNullOrWhiteSpace(en.BuildingsTypeStr))
  596. {
  597. errCount++;
  598. errorMsgStr = "建筑类型不能为空";
  599. en.ErrorMessage = errorMsgStr;
  600. errList.Add(en);
  601. errorMsg.AppendLine(errorMsgStr);
  602. continue;
  603. }
  604. else
  605. {
  606. var buildingsType = buildingsTypeList.Where(x => x.Name == en.BuildingsTypeStr.Trim()).SingleOrDefault();
  607. if (buildingsType == null)
  608. {
  609. errCount++;
  610. errorMsgStr = "建筑类型不存在,请检查";
  611. en.ErrorMessage = errorMsgStr;
  612. errList.Add(en);
  613. errorMsg.AppendLine(errorMsgStr);
  614. continue;
  615. }
  616. else
  617. {
  618. //建筑类型
  619. newBuildingsInfo.BuildingsTypeID = buildingsType.Value;
  620. }
  621. }
  622. //建筑状况
  623. if (string.IsNullOrWhiteSpace(en.BuildingsStatusStr))
  624. {
  625. errCount++;
  626. errorMsgStr = "建筑状况不能为空";
  627. en.ErrorMessage = errorMsgStr;
  628. errList.Add(en);
  629. errorMsg.AppendLine(errorMsgStr);
  630. continue;
  631. }
  632. else
  633. {
  634. var buildingsStatus = buildingsStatusList.Where(x => x.Name == en.BuildingsStatusStr.Trim()).SingleOrDefault();
  635. if (buildingsStatus == null)
  636. {
  637. errCount++;
  638. errorMsgStr = "建筑状况不存在,请检查";
  639. en.ErrorMessage = errorMsgStr;
  640. errList.Add(en);
  641. errorMsg.AppendLine(errorMsgStr);
  642. continue;
  643. }
  644. else
  645. {
  646. //建筑状况
  647. newBuildingsInfo.BuildingsStatusID = buildingsStatus.Value;
  648. }
  649. }
  650. //建筑层数
  651. if (string.IsNullOrWhiteSpace(en.BuildingsLevelStr))
  652. {
  653. //不考虑
  654. }
  655. else
  656. {
  657. reg = new Regex(@"^[0-9]+([.]{1}[0-9]+){0,1}$"); //正则表达式()
  658. if (!reg.IsMatch(en.BuildingsLevelStr.Trim()))
  659. {
  660. errCount++;
  661. errorMsgStr = "建筑层数格式不正确,请检查";
  662. en.ErrorMessage = errorMsgStr;
  663. errList.Add(en);
  664. errorMsg.AppendLine(errorMsgStr);
  665. continue;
  666. }
  667. else
  668. {
  669. //建筑层数
  670. newBuildingsInfo.BuildingsLevel = Convert.ToDecimal(en.BuildingsLevelStr.Trim());
  671. }
  672. }
  673. //建筑面积
  674. if (string.IsNullOrWhiteSpace(en.BuildingsAreaStr))
  675. {
  676. //不考虑
  677. }
  678. else
  679. {
  680. reg = new Regex(@"^[0-9]+([.]{1}[0-9]+){0,1}$"); //正则表达式()
  681. if (!reg.IsMatch(en.BuildingsAreaStr.Trim()))
  682. {
  683. errCount++;
  684. errorMsgStr = "建筑面积格式不正确,请检查";
  685. en.ErrorMessage = errorMsgStr;
  686. errList.Add(en);
  687. errorMsg.AppendLine(errorMsgStr);
  688. continue;
  689. }
  690. else
  691. {
  692. //建筑面积
  693. newBuildingsInfo.BuildingsArea = Convert.ToDecimal(en.BuildingsAreaStr.Trim());
  694. }
  695. }
  696. //使用面积
  697. if (string.IsNullOrWhiteSpace(en.UseAreaStr))
  698. {
  699. //不考虑
  700. }
  701. else
  702. {
  703. reg = new Regex(@"^[0-9]+([.]{1}[0-9]+){0,1}$"); //正则表达式()
  704. if (!reg.IsMatch(en.UseAreaStr.Trim()))
  705. {
  706. errCount++;
  707. errorMsgStr = "使用面积格式不正确,请检查";
  708. en.ErrorMessage = errorMsgStr;
  709. errList.Add(en);
  710. errorMsg.AppendLine(errorMsgStr);
  711. continue;
  712. }
  713. else
  714. {
  715. //使用面积
  716. newBuildingsInfo.UseArea = Convert.ToDecimal(en.UseAreaStr.Trim());
  717. }
  718. }
  719. //地址
  720. if (string.IsNullOrWhiteSpace(en.Position))
  721. {
  722. //不考虑
  723. }
  724. else
  725. {
  726. newBuildingsInfo.Position = en.Position;
  727. }
  728. //是否可用
  729. if (string.IsNullOrWhiteSpace(en.IsSpecialStr))
  730. {
  731. errCount++;
  732. errorMsgStr = "是否可用不能为空";
  733. en.ErrorMessage = errorMsgStr;
  734. errList.Add(en);
  735. errorMsg.AppendLine(errorMsgStr);
  736. continue;
  737. }
  738. else
  739. {
  740. var generalPurpose = generalPurposeList.Where(x => x.Name == en.IsSpecialStr.Trim()).SingleOrDefault();
  741. if (generalPurpose == null)
  742. {
  743. errCount++;
  744. errorMsgStr = "是否可用不存在,请检查";
  745. en.ErrorMessage = errorMsgStr;
  746. errList.Add(en);
  747. errorMsg.AppendLine(errorMsgStr);
  748. continue;
  749. }
  750. else
  751. {
  752. //是否可用
  753. newBuildingsInfo.IsSpecial = generalPurpose.Value == (int)CF_GeneralPurpose.IsYes ? true : false;
  754. }
  755. }
  756. //备注
  757. if (string.IsNullOrWhiteSpace(en.Remark))
  758. {
  759. //不考虑
  760. }
  761. else
  762. {
  763. newBuildingsInfo.Remark = en.Remark;
  764. }
  765. ////Excel表重复性验证(注:当数据表中没有此记录,但是Excel中有重复数据时的去掉)
  766. //for (int j = i + 1; j < enlist.Count; j++)
  767. //{
  768. // NewBuildingsInfoView enA = enlist[j];
  769. // //根据Excel表中的业务主键进行去重(建筑编号唯一)
  770. // if (en.No == enA.No && en.Name == enA.Name)
  771. // {
  772. // //用于标识Excel表中的重复记录(由于是批量进行插入数据表)
  773. // }
  774. //}
  775. //数据表重复性验证(建筑编号唯一)
  776. var buildingsInfoVerify = newBuildingsInfoList.Where(x => x.Code == newBuildingsInfo.Code).SingleOrDefault();
  777. if (buildingsInfoVerify == null)
  778. {
  779. //新增
  780. if (!newBuildingsInfoInList.Any(x => x.Code == newBuildingsInfo.Code))
  781. {
  782. newBuildingsInfo.BuildingsInfoID = Guid.NewGuid();
  783. SetNewStatus(newBuildingsInfo);
  784. newBuildingsInfoInList.Add(newBuildingsInfo);
  785. inCount++;
  786. }
  787. else
  788. {
  789. //Excel表重复性验证
  790. //(注:当数据表中没有此记录,但是Excel中有重复数据,可在此处进行抛出到失败数据文件中,目前暂不考虑)
  791. inCount++;
  792. }
  793. }
  794. else
  795. {
  796. //更新(Excel有重复时,以最后一条记录的更新为准)
  797. buildingsInfoVerify.Name = newBuildingsInfo.Name;
  798. buildingsInfoVerify.CampusID = newBuildingsInfo.CampusID;
  799. buildingsInfoVerify.CollegeID = newBuildingsInfo.CollegeID;
  800. buildingsInfoVerify.BuildingsTypeID = newBuildingsInfo.BuildingsTypeID;
  801. buildingsInfoVerify.BuildingsStatusID = newBuildingsInfo.BuildingsStatusID;
  802. buildingsInfoVerify.BuildingsLevel = newBuildingsInfo.BuildingsLevel;
  803. buildingsInfoVerify.BuildingsArea = newBuildingsInfo.BuildingsArea;
  804. buildingsInfoVerify.UseArea = newBuildingsInfo.UseArea;
  805. buildingsInfoVerify.Position = newBuildingsInfo.Position;
  806. buildingsInfoVerify.IsSpecial = newBuildingsInfo.IsSpecial;
  807. buildingsInfoVerify.Remark = newBuildingsInfo.Remark;
  808. SetModifyStatus(buildingsInfoVerify);
  809. newBuildingsInfoUpList.Add(buildingsInfoVerify);
  810. upCount++;
  811. }
  812. }
  813. using (TransactionScope ts = new TransactionScope())
  814. {
  815. UnitOfWork.BulkInsert(newBuildingsInfoInList);
  816. //批量统一提交更新
  817. if (newBuildingsInfoUpList != null && newBuildingsInfoUpList.Count() > 0)
  818. {
  819. UnitOfWork.BatchUpdate(newBuildingsInfoUpList);
  820. }
  821. ts.Complete();
  822. }
  823. errdataList = errList.Distinct().ToList(); //错误列表List
  824. }
  825. catch (Exception)
  826. {
  827. //目前会出现,由于错误信息字符太长,无法抛出弹出框的问题
  828. throw;
  829. }
  830. }
  831. }
  832. }