using Learun.Application.TwoDevelopment.ZZDT_EC; using Learun.Util; using Learun.Util.SqlSugar; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web.Mvc; namespace Learun.Application.Web.Areas.ZZDT_EC.Controllers { /// /// 版 本 PIT-ADMS V7.0.3 敏捷开发框架 /// Copyright (c) 2013-2018 Hexagon PPM /// 创 建:超级管理员 /// 日 期:2022-03-07 13:44 /// 描 述:工程数据表 /// public class ec_enginedataController : MvcControllerBase { private ec_enginedataIBLL ec_enginedataIBLL = new ec_enginedataBLL(); #region 视图功能 /// /// 主页面 /// /// [HttpGet] public ActionResult Index() { return View(); } /// /// 表单页 /// /// [HttpGet] public ActionResult Form() { return View(); } /// /// 工程数据Tag回收站 /// /// [HttpGet] public ActionResult RecycleBin() { return View(); } #endregion #region 获取数据 /// /// 获取页面显示列表数据 /// /// 查询参数 /// [HttpGet] [AjaxOnly] public ActionResult GetPageList(string pagination, string queryJson) { Pagination paginationobj = pagination.ToObject(); var data = ec_enginedataIBLL.GetList(queryJson, paginationobj, true, true); var jsonData = new { rows = data, total = paginationobj.total, page = paginationobj.page, records = paginationobj.records }; return Success(jsonData); } /// /// 获取回收站页面显示列表数据 /// /// 查询参数 /// [HttpGet] [AjaxOnly] public ActionResult GetRecycleBinPageList(string pagination, string queryJson) { Pagination paginationobj = pagination.ToObject(); var data = ec_enginedataIBLL.GetRecycleBinPageList(paginationobj, queryJson); var jsonData = new { rows = data, total = paginationobj.total, page = paginationobj.page, records = paginationobj.records }; return Success(jsonData); } /// /// 获取表单数据 /// /// [HttpGet] [AjaxOnly] public ActionResult GetFormData(string keyValue, string ProjectId) { var ec_enginedataData = ec_enginedataIBLL.GetEntity(keyValue, ProjectId); var jsonData = new { ec_enginedata = ec_enginedataData, }; return Success(jsonData); } #endregion #region 提交数据 /// /// 删除实体数据 /// 主键 /// /// [HttpPost] [AjaxOnly] public ActionResult DeleteForm(string strEntity, string ProjectId) { var entitys = strEntity.ToObject>(); var ids = entitys.Select(x => x.EngineDataID).ToList(); var tableName = ProjectSugar.TableName(ProjectId); var cables = SqlSugarHelper.Db.Queryable().AS(tableName).Where(x => ids.Contains(x.EngineerDataID)).ToList(); string res = ""; cables.ForEach(x => { var entity = entitys.First(y => x.EngineerDataID == y.EngineDataID); res += $"位号{entity.TagNumber},已绑定电缆,无法删除\n"; }); if (!string.IsNullOrEmpty(res)) { return Fail(res); } foreach (var item in entitys) { ec_enginedataIBLL.DeleteEntity(item.EngineDataID, ProjectId); } return Success("删除成功!"); } /// /// 保存实体数据(新增、修改) /// 主键 /// /// [HttpPost] [ValidateAntiForgeryToken] [AjaxOnly] public ActionResult SaveForm(string keyValue, string strEntity, string ProjectId) { ec_enginedataEntity entity = strEntity.ToObject(); //位号不允许重复 var data = ec_enginedataIBLL.GetList("{ProjectId:\"" + ProjectId + "\",TagNumber:\"" + entity.TagNumber + "\"}").ToList(); if (data != null && data.Count > 0) { if (!string.IsNullOrEmpty(keyValue)) { data = data.FindAll(x => x.EngineDataID != keyValue); if (data != null && data.Count > 0) { return Fail("位号不允许重复!"); } } else { return Fail($"位号不允许重复!在{data[0].FullPathCN}中有一个相同位号的设备或电缆。"); } } //截取位号后面的数字作为流水号 if (!string.IsNullOrEmpty(entity.ObjectTypeNameEN)) { string strSerialNumber = entity.TagNumber.Replace(entity.ObjectTypeNameEN, "").Trim(); if (IsInteger(strSerialNumber)) { entity.SerialNumber = strSerialNumber.ToInt(); } else { entity.SerialNumber = 0; } } ec_enginedataIBLL.SaveEntity(keyValue, entity, ProjectId); return Success("保存成功!"); } /// /// 验证字符串是否为整数 /// /// 要验证的字符串 public static bool IsInteger(string value) { //如果为空,认为验证不合格 if (string.IsNullOrEmpty(value)) { return false; } return System.Text.RegularExpressions.Regex.IsMatch(value, @"^\d*$"); } /// /// 批量修改数据状态 /// /// [HttpPost] [AjaxOnly] public ActionResult UpdateDataStatus(string strEntity, string ProjectId) { List entityList = strEntity.ToList(); ec_enginedataIBLL.UpdateDataStatus(entityList, ProjectId); return Success("审批成功!"); } #endregion } }