From e2b5b2e4b961b4ec926492d37235d2cf817db1cd Mon Sep 17 00:00:00 2001 From: gaofei1985 <181547018@qq.com> Date: Sun, 8 Oct 2023 10:38:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../版本日志/SGGLDB_WH_2023-10-08.sql | 27 + .../HSSE/APIGeneralEquipmentQualityService.cs | 148 ++ SGGL/BLL/BLL.csproj | 2 + SGGL/BLL/Common/NPOIExcel.cs | 1559 +++++++++++++++++ .../HSSE/QualityAudit/EquipmentQuality.aspx | 3 +- .../QualityAudit/EquipmentQuality.aspx.cs | 118 ++ .../EquipmentQuality.aspx.designer.cs | 59 +- .../QualityAudit/GeneralEquipmentQuality.aspx | 3 +- .../GeneralEquipmentQuality.aspx.cs | 132 +- .../GeneralEquipmentQuality.aspx.designer.cs | 59 +- .../APIItem/HSSE/EquipmentQualityItem.cs | 8 + SGGL/Model/Model.cs | 305 ++++ .../HSSE/GeneralEquipmentQualityController.cs | 160 ++ SGGL/WebAPI/WebAPI.csproj | 1 + 14 files changed, 2531 insertions(+), 53 deletions(-) create mode 100644 DataBase/版本日志/SGGLDB_WH_2023-10-08.sql create mode 100644 SGGL/BLL/API/HSSE/APIGeneralEquipmentQualityService.cs create mode 100644 SGGL/BLL/Common/NPOIExcel.cs create mode 100644 SGGL/WebAPI/Controllers/HSSE/GeneralEquipmentQualityController.cs diff --git a/DataBase/版本日志/SGGLDB_WH_2023-10-08.sql b/DataBase/版本日志/SGGLDB_WH_2023-10-08.sql new file mode 100644 index 00000000..9ae0578d --- /dev/null +++ b/DataBase/版本日志/SGGLDB_WH_2023-10-08.sql @@ -0,0 +1,27 @@ +Create VIEW [dbo].[View_QualityAudit_GeneralEquipmentQuality] AS +/*豸Ϣбͼ*/ +SELECT equ.GeneralEquipmentQualityId + ,equ.ProjectId + ,equ.GeneralEquipmentQualityCode + ,equ.UnitId + ,Unit.UnitName + ,equ.SpecialEquipmentId + ,sp.SpecialEquipmentName + ,equ.[IsQualified] + ,equ.EquipmentCount + ,equ.InDate + ,equ.Remark + ,equ.CompileMan + ,U.UserName AS CompileManName + ,equ.CompileDate + ,equ.QRCodeAttachUrl + ,REPLACE(a.AttachUrl,'\', '/') AS AttachUrl +FROM QualityAudit_GeneralEquipmentQuality AS equ +LEFT JOIN Base_Unit AS Unit ON Unit.UnitId=equ.UnitId +LEFT JOIN Base_SpecialEquipment AS sp ON equ.SpecialEquipmentId = sp.SpecialEquipmentId +LEFT JOIN Sys_User AS U ON U.UserId = equ.CompileMan +LEFT JOIN AttachFile AS a ON a.ToKeyId = equ.GeneralEquipmentQualityId + + + +GO diff --git a/SGGL/BLL/API/HSSE/APIGeneralEquipmentQualityService.cs b/SGGL/BLL/API/HSSE/APIGeneralEquipmentQualityService.cs new file mode 100644 index 00000000..458e6492 --- /dev/null +++ b/SGGL/BLL/API/HSSE/APIGeneralEquipmentQualityService.cs @@ -0,0 +1,148 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using EmitMapper; + +namespace BLL +{ + public static class APIGeneralEquipmentQualityService + { + #region 根据equipmentQualityId获取机具设备信息 + /// + /// 根据equipmentQualityId获取机具设备信息 + /// + /// + /// + public static Model.EquipmentQualityItem getEquipmentQualityByEquipmentQualityIdFactoryCode(string equipmentQualityId) + { + using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) + { + var getEquipmentQuality = (from x in db.View_QualityAudit_GeneralEquipmentQuality + where x.GeneralEquipmentQualityId == equipmentQualityId + select new Model.EquipmentQualityItem + { + EquipmentQualityId = x.GeneralEquipmentQualityId, + ProjectId = x.ProjectId, + EquipmentQualityCode = x.GeneralEquipmentQualityCode, + EquipmentCount = x.EquipmentCount.HasValue? x.EquipmentCount.Value.ToString():"", + UnitId = x.UnitId, + IsQualified =x.IsQualified.HasValue? x.IsQualified.Value?"是":"否":"", + UnitName = x.UnitName, + SpecialEquipmentName = x.SpecialEquipmentName, + InDate = string.Format("{0:yyyy-MM-dd}", x.InDate), + Remark = x.Remark, + CompileManId = x.CompileMan, + CompileManName = x.CompileManName, + CompileDate = string.Format("{0:yyyy-MM-dd}", x.CompileDate), + AttachUrl = x.AttachUrl.Replace('\\', '/') + }); ; + return getEquipmentQuality.FirstOrDefault(); + } + } + #endregion + + #region 获取机具设备列表信息 + /// + /// 获取机具设备列表信息 + /// + /// + /// + /// + /// + public static List getEquipmentQualityList(string projectId, string unitId, string strParam) + { + using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) + { + var getEquipmentQuality = from x in db.View_QualityAudit_GeneralEquipmentQuality + where x.ProjectId == projectId && (x.UnitId == unitId || unitId == null) + && (strParam == null || x.SpecialEquipmentName.Contains(strParam) ) + orderby x.GeneralEquipmentQualityCode descending + select new Model.EquipmentQualityItem + { + EquipmentQualityId = x.GeneralEquipmentQualityId, + ProjectId = x.ProjectId, + EquipmentQualityCode = x.GeneralEquipmentQualityCode, + EquipmentCount = x.EquipmentCount.HasValue ? x.EquipmentCount.Value.ToString() : "", + UnitId = x.UnitId, + IsQualified = x.IsQualified.HasValue ? x.IsQualified.Value ? "是" : "否" : "", + UnitName = x.UnitName, + SpecialEquipmentName = x.SpecialEquipmentName, + InDate = string.Format("{0:yyyy-MM-dd}", x.InDate), + Remark = x.Remark, + CompileManId = x.CompileMan, + CompileManName = x.CompileManName, + CompileDate = string.Format("{0:yyyy-MM-dd}", x.CompileDate), + AttachUrl = x.AttachUrl.Replace('\\', '/') + }; + return getEquipmentQuality.ToList(); + } + } + #endregion + + #region 保存QualityAudit_EquipmentQuality + /// + /// 保存QualityAudit_EquipmentQuality + /// + /// 机具设备资质 + /// + public static void SaveEquipmentQuality(Model.EquipmentQualityItem newItem) + { + Model.SGGLDB db = Funs.DB; + Model.QualityAudit_GeneralEquipmentQuality newEquipmentQuality = new Model.QualityAudit_GeneralEquipmentQuality + { + GeneralEquipmentQualityId = newItem.EquipmentQualityId, + ProjectId = newItem.ProjectId, + GeneralEquipmentQualityCode = newItem.EquipmentQualityCode, + UnitId = newItem.UnitId, + SpecialEquipmentId = newItem.SpecialEquipmentId, + InDate = Funs.GetNewDateTime(newItem.InDate), + Remark = newItem.Remark, + CompileMan = newItem.CompileManId, + }; + if (!string.IsNullOrEmpty(newItem.IsQualified)) + { + if ("1".Equals(newItem.IsQualified)) + { + newEquipmentQuality.IsQualified = true; + } + else + { + newEquipmentQuality.IsQualified = false; + + } + } + if (!string.IsNullOrEmpty(newItem.EquipmentCount)) + { + try + { + newEquipmentQuality.EquipmentCount = int.Parse(newItem.EquipmentCount); + } + catch (Exception e) { } + } + var updateEquipmentQuality = db.QualityAudit_GeneralEquipmentQuality.FirstOrDefault(x => x.GeneralEquipmentQualityId == newItem.EquipmentQualityId); + if (updateEquipmentQuality == null) + { + newEquipmentQuality.CompileDate = DateTime.Now; + newEquipmentQuality.GeneralEquipmentQualityId = SQLHelper.GetNewID(); + newEquipmentQuality.GeneralEquipmentQualityCode = BLL.CodeRecordsService.ReturnCodeByMenuIdProjectId(BLL.Const.GeneralEquipmentQualityMenuId, newItem.ProjectId, newItem.UnitId); + GeneralEquipmentQualityService.AddGeneralEquipmentQuality(newEquipmentQuality); + } + else + { + GeneralEquipmentQualityService.UpdateGeneralEquipmentQuality(newEquipmentQuality); + } + if (!string.IsNullOrEmpty(newItem.AttachUrl)) + { + ////保存附件 + UploadFileService.SaveAttachUrl(UploadFileService.GetSourceByAttachUrl(newItem.AttachUrl, 10, null), newItem.AttachUrl, Const.GeneralEquipmentQualityMenuId, newEquipmentQuality.GeneralEquipmentQualityId); + } + else + { + CommonService.DeleteAttachFileById(newEquipmentQuality.GeneralEquipmentQualityId); + } + } + #endregion + } +} diff --git a/SGGL/BLL/BLL.csproj b/SGGL/BLL/BLL.csproj index f8b66252..81372eff 100644 --- a/SGGL/BLL/BLL.csproj +++ b/SGGL/BLL/BLL.csproj @@ -103,6 +103,7 @@ + @@ -174,6 +175,7 @@ + diff --git a/SGGL/BLL/Common/NPOIExcel.cs b/SGGL/BLL/Common/NPOIExcel.cs new file mode 100644 index 00000000..62868551 --- /dev/null +++ b/SGGL/BLL/Common/NPOIExcel.cs @@ -0,0 +1,1559 @@ +using NPOI.HSSF.UserModel; +using NPOI.SS.UserModel; +using NPOI.SS.Util; +using NPOI.XSSF.UserModel; +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.OleDb; +using System.IO; +using System.Linq; +using System.Text; + +namespace BLL.Common +{ + public class NPOIExcel + { + internal IWorkbook Book { get; set; } + + private int sheetID = 0; + /// + /// 当前活动的SheetID,所有的操作将指向这个Sheet + /// + public int ActiveSheetID + { + get + { + return sheetID; + } + set + { + sheetID = value; + } + } + + /// + /// 当前活动的SheetName,所有的操作将指向这个Sheet + /// + public String ActiveSheetName + { + get + { + return Book.GetSheetAt(sheetID).SheetName; + } + set + { + sheetID = Book.GetSheetIndex(value); + } + } + /// + /// 当前活动的Sheet,所有的操作将指向这个Sheet + /// + public ISheet ActiveSheet + { + get + { + return Book.GetSheetAt(sheetID); + } + } + + /// + /// 第一行非空行的行号 + /// + public int FirstRowNum + { + get + { + return Book.GetSheetAt(sheetID).FirstRowNum; + } + } + + /// + /// 最后一行非空行的行号 + /// + public int LastRostNum + { + get + { + return Book.GetSheetAt(sheetID).LastRowNum; + } + } + + /// + /// 无模板的Excel生成或操作 + /// + public NPOIExcel() + { + Book = new HSSFWorkbook(); + Book.CreateSheet(); + } + + public NPOIExcel(Stream fileStream, String fileName) + { + if (fileName.Substring(fileName.LastIndexOf(".")) == ".xls") + { + Book = new HSSFWorkbook(fileStream); + } + else + { + Book = new XSSFWorkbook(fileStream); + } + } + /// + /// 带模板或数据的Excel生成或操作 + /// + /// + public NPOIExcel(String fileName) + { + Book = CreateBook(fileName); + } + + /// + /// 创建Excel Book + /// + /// 模板文件名 + /// + private IWorkbook CreateBook(String fileName) + { + FileInfo file = new FileInfo(fileName); + if (!file.Exists) + { + File.Create(fileName).Close(); + } + FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); + IWorkbook book; + if (file.Extension == ".xls") + { + book = new HSSFWorkbook(fs); + } + else + { + book = new XSSFWorkbook(fs); + } + fs.Close(); + if (book.NumberOfSheets == 0) + { + book.CreateSheet(); + } + return book; + } + + /// + /// 新建Sheet + /// + /// 新建Sheet + public ISheet CreateSheet() + { + return Book.CreateSheet(); + } + + /// + /// 新建Sheet + /// + /// 新建Sheet的名称 + /// 新建Sheet + public ISheet CreateSheet(String sheetName) + { + return Book.CreateSheet(sheetName); + } + + /// + /// 设置行高 + /// 注:只对当前ActiveSheet有效 + /// + /// 行号 + /// 高度 + public void SetRowHeight(int rowIndex, float height) + { + IRow row = Book.GetSheetAt(sheetID).GetRow(rowIndex); + if (row == null) + { + row = Book.GetSheetAt(sheetID).CreateRow(rowIndex); + } + row.Height = (short)(height * 20); + } + + /// + /// 设置列宽 + /// 注:只对当前ActiveSheet有效 + /// + /// 列号 + /// 宽度 + public void SetColumnWidth(int columnIndex, short width) + { + Book.GetSheetAt(sheetID).SetColumnWidth(columnIndex, width * 256); + } + + /// + /// 获取或设置默认行高 + /// 注:只对当前ActiveSheet有效 + /// + public short DefaultRowHeight + { + get + { + return (short)(Book.GetSheetAt(sheetID).DefaultRowHeight / 20); + } + set + { + Book.GetSheetAt(sheetID).DefaultRowHeight = (short)(value * 20); + + } + } + + /// + /// 获取或设置默认列宽 + /// 注:只对当前ActiveSheet有效 + /// + public int DefaultColWidth + { + get + { + return Book.GetSheetAt(sheetID).DefaultColumnWidth; + } + set + { + Book.GetSheetAt(sheetID).DefaultColumnWidth = value; + } + } + + /// + /// 某一列的列宽自动调整大小 + /// 注:只对当前ActiveSheet有效 + /// + /// 列号 + public void AutoColWidth(int colIndex) + { + Book.GetSheetAt(sheetID).AutoSizeColumn(colIndex, true); + } + + /// + /// 隐藏一行 + /// 注:只对当前ActiveSheet有效 + /// + /// 行号 + public void HiddenRow(int rowIndex) + { + IRow row = Book.GetSheetAt(sheetID).GetRow(rowIndex); + if (row == null) + { + row = Book.GetSheetAt(sheetID).CreateRow(rowIndex); + } + row.ZeroHeight = true; + } + + /// + /// 删除一行 + /// 注:只对当前ActiveSheet有效 + /// + /// 行号 + public void RemoveRow(int rowIndex) + { + IRow row = Book.GetSheetAt(sheetID).GetRow(rowIndex); + if (row != null) + { + ActiveSheet.RemoveRow(row); + } + } + + /// + /// 读取单元格的值 + /// 注:只对当前ActiveSheet有效 + /// + /// 行号 + /// 列号 + /// 单元格的值 + public object ReadValue(int rowIndex, int columnIndex, bool? isDateTime = null) + { + try + { + ICell cell = Book.GetSheetAt(sheetID).GetRow(rowIndex).GetCell(columnIndex); + short df = cell.CellStyle.DataFormat; + + //return cell.ToString(); + switch (cell.CellType) + { + case CellType.Blank: + return null; + case CellType.Boolean: + return cell.BooleanCellValue; + case CellType.Error: + throw new Exception("Cell Value Error"); + case CellType.Formula: + { + switch (cell.CachedFormulaResultType) + { + case CellType.Blank: + return ""; + case CellType.Boolean: + return cell.BooleanCellValue; + case CellType.Error: + throw new Exception("Cell Value Error"); + case CellType.Formula: + throw new Exception("The Formula of this cell is too complex!"); + case CellType.Numeric: + if (isDateTime == null) + { + if (DateUtil.IsCellDateFormatted(cell)) + { + return cell.DateCellValue; + } + else + { + return cell.NumericCellValue; + } + } + else if (isDateTime == true) + { + return cell.DateCellValue; + } + else + { + return cell.NumericCellValue; + } + case CellType.String: + return cell.StringCellValue; + case CellType.Unknown: + return cell.ToString(); + default: + return cell.ToString(); + } + } + case CellType.Numeric: + { + if (isDateTime == null) + { + if (DateUtil.IsCellDateFormatted(cell)) + { + return cell.DateCellValue; + } + else + { + return cell.NumericCellValue; + } + } + else if (isDateTime == true) + { + return cell.DateCellValue; + } + else + { + return cell.NumericCellValue; + } + } + case CellType.String: + return cell.StringCellValue; + case CellType.Unknown: + return cell.ToString(); + default: + return cell.ToString(); + } + } + catch (System.NullReferenceException) + { + return null; + } + catch (Exception ex) + { + throw ex; + } + } + + /// + /// 设置单元格的值 + /// 注:只对当前ActiveSheet有效 + /// + /// 行号 + /// 列号 + /// 单元格的值 + public void SetValue(int rowIndex, int columnIndex, object value) + { + SetValue(rowIndex, columnIndex, value, false); + } + public void SetPicValue(int rowIndex, int columnIndex, string value) + { + byte[] bytes = System.IO.File.ReadAllBytes(value); + int pictureIdx = Book.AddPicture(bytes, PictureType.JPEG); + + // 第三步:创建画部 + IDrawing patriarch = ActiveSheet.CreateDrawingPatriarch(); + // 第四步:设置锚点 + int rowline = 1; // y方向 + // 参数说明:(在起始单元格的X坐标0-1023,Y的坐标0-255,在终止单元格的X坐标0-1023,Y的坐标0-255,起始单元格列数,行数,终止单元格列数,行数) + IClientAnchor anchor = patriarch.CreateAnchor(0, 0, 0, 0, columnIndex, rowIndex, columnIndex+1, rowIndex + 1); + // 第五步:把图片插到相应的位置+1 + IPicture pict = patriarch.CreatePicture(anchor, pictureIdx); + + + } + /// + /// 设置单元格的值 + /// 注:只对当前ActiveSheet有效 + /// + /// 行号 + /// 列号 + /// 单元格的值 + /// 是否是公式 + public void SetValue(int rowIndex, int columnIndex, object value, bool isFormula) + { + IRow row = Book.GetSheetAt(sheetID).GetRow(rowIndex); + if (row == null) + { + row = Book.GetSheetAt(sheetID).CreateRow(rowIndex); + } + ICell cell = row.GetCell(columnIndex); + if (cell == null) + { + cell = row.CreateCell(columnIndex); + } + if (value == null) + { + cell.SetCellValue(""); + } + if (isFormula) + { + cell.SetCellFormula(value.ToString()); + } + else + { + if (value is short) + { + cell.SetCellValue((short)value); + } + else if (value is int) + { + cell.SetCellValue((int)value); + } + else if (value is long) + { + cell.SetCellValue((long)value); + } + else if (value is float) + { + cell.SetCellValue((float)value); + } + else if (value is double) + { + cell.SetCellValue((double)value); + } + else if (value is bool) + { + cell.SetCellValue((bool)value); + } + else if (value is DateTime) + { + cell.SetCellValue((DateTime)value); + } + else if (value == null) + { + } + else + { + cell.SetCellValue(value.ToString()); + } + } + + } + + /// + /// 设置一个区域内的单元格的值范围 + /// 注:只对当前ActiveSheet有效 + /// + /// 开始行 + /// 结束行 + /// 开始列 + /// 结束列 + /// 验证类型 + /// 验证方式 + /// 最小值 + /// 最大值 + public void SetValueRange(int startRowIndex, int EndRowIndex, int startColInex, int endColIndex, NPOIDataType type, OperatorTypes operatorType, String minValue, String maxValue) + { + SetValueRange(startRowIndex, EndRowIndex, startColInex, endColIndex, type, operatorType, minValue, maxValue, "", ""); + } + + /// + /// 设置一个区域内的单元格的值范围 + /// 注:只对当前ActiveSheet有效 + /// + /// 开始行 + /// 结束行 + /// 开始列 + /// 结束列 + /// 验证类型 + /// 验证方式 + /// 最小值 + /// 最大值 + /// 数据格式 + public void SetValueRange(int startRowIndex, int EndRowIndex, int startColInex, int endColIndex, NPOIDataType type, OperatorTypes operatorType, String minValue, String maxValue, String formate) + { + SetValueRange(startRowIndex, EndRowIndex, startColInex, endColIndex, type, operatorType, minValue, maxValue, formate, ""); + } + + /// + /// 设置一个区域内的单元格的值范围 + /// 注:只对当前ActiveSheet有效 + /// + /// 开始行 + /// 结束行 + /// 开始列 + /// 结束列 + /// 验证类型 + /// 验证方式 + /// 最小值 + /// 最大值 + /// 数据格式 + /// 报错信息 + public void SetValueRange(int startRowIndex, int EndRowIndex, int startColInex, int endColIndex, NPOIDataType type, OperatorTypes operatorType, String minValue, String maxValue, String formate, String AlertMassage) + { + CellRangeAddressList regions = new CellRangeAddressList(startRowIndex, EndRowIndex, startColInex, endColIndex); + DVConstraint constraint = DVConstraint.CreateNumericConstraint(ValidationType.ANY, 0, null, null); + switch (type) + { + case NPOIDataType.Integer: + constraint = DVConstraint.CreateNumericConstraint(ValidationType.INTEGER, (int)operatorType, minValue, maxValue); + break; + case NPOIDataType.Float: + constraint = DVConstraint.CreateNumericConstraint(ValidationType.DECIMAL, (int)operatorType, minValue, maxValue); + break; + case NPOIDataType.Date: + if (formate == "") + { + formate = "yyyy/MM/dd"; + } + constraint = DVConstraint.CreateDateConstraint((int)operatorType, minValue, maxValue, formate); + break; + case NPOIDataType.Time: + constraint = DVConstraint.CreateTimeConstraint((int)operatorType, minValue, maxValue); + break; + case NPOIDataType.TextLength: + constraint = DVConstraint.CreateNumericConstraint(ValidationType.TEXT_LENGTH, (int)operatorType, minValue, maxValue); + break; + default: + break; + } + + HSSFDataValidation dataValidate1 = new HSSFDataValidation(regions, constraint); + if (!String.IsNullOrEmpty(AlertMassage)) + { + dataValidate1.CreateErrorBox("Error", AlertMassage); + } + ActiveSheet.AddValidationData(dataValidate1); + + } + + /// + /// 设置一个区域内的单元格的值范围 + /// 注:只对当前ActiveSheet有效 + /// + /// 开始行 + /// 结束行 + /// 开始列 + /// 结束列 + /// 值系列 + public void SetValueRange(int startRowIndex, int EndRowIndex, int startColInex, int endColIndex, String[] dataRange) + { + + SetValueRange(startRowIndex, EndRowIndex, startColInex, endColIndex, dataRange, ""); + } + + /// + /// 设置一个区域内的单元格的值范围 + /// 注:只对当前ActiveSheet有效 + /// + /// 开始行 + /// 结束行 + /// 开始列 + /// 结束列 + /// 值系列 + /// 报错信息 + public void SetValueRange(int startRowIndex, int endRowIndex, int startColInex, int endColIndex, String[] dataRange, String alertMassage) + { + ISheetConditionalFormatting hscf = ActiveSheet.SheetConditionalFormatting; + CellRangeAddress[] regions = { + new CellRangeAddress(startRowIndex, endRowIndex,startColInex,endColIndex) + }; + + CellRangeAddressList rangeList = new CellRangeAddressList(); + rangeList.AddCellRangeAddress(new CellRangeAddress(startRowIndex, endRowIndex, startColInex, endColIndex)); + DVConstraint dvconstraint = DVConstraint.CreateExplicitListConstraint(dataRange); + HSSFDataValidation dataValidation = new HSSFDataValidation(rangeList, dvconstraint); + + if (!String.IsNullOrEmpty(alertMassage)) + { + dataValidation.CreateErrorBox("Error", alertMassage); + } + + ActiveSheet.AddValidationData(dataValidation); + } + + /// + /// 设置一个区域内的单元格的值范围 + /// 注:只对当前ActiveSheet有效 + /// + /// 开始行 + /// 结束行 + /// 开始列 + /// 结束列 + /// 计算公式 + /// 报错信息 + public void SetValueRange(int startRowIndex, int endRowIndex, int startColInex, int endColIndex, String Formula, String alertMassage) + { + ISheetConditionalFormatting hscf = ActiveSheet.SheetConditionalFormatting; + CellRangeAddress[] regions = { + new CellRangeAddress(startRowIndex, endRowIndex,startColInex,endColIndex) + }; + + CellRangeAddressList rangeList = new CellRangeAddressList(); + rangeList.AddCellRangeAddress(new CellRangeAddress(startRowIndex, endRowIndex, startColInex, endColIndex)); + DVConstraint dvconstraint = DVConstraint.CreateFormulaListConstraint(Formula); + HSSFDataValidation dataValidation = new HSSFDataValidation(rangeList, dvconstraint); + + if (!String.IsNullOrEmpty(alertMassage)) + { + dataValidation.CreateErrorBox("Error", alertMassage); + } + + ActiveSheet.AddValidationData(dataValidation); + } + + /// + /// 设置一个区域内的单元格的值范围 + /// 注:只对当前ActiveSheet有效 + /// + /// 开始行 + /// 结束行 + /// 开始列 + /// 结束列 + /// 计算公式 + public void SetValueRange(int startRowIndex, int endRowIndex, int startColInex, int endColIndex, String Formula) + { + SetValueRange(startRowIndex, endColIndex, startRowIndex, endColIndex, Formula, ""); + } + + /// + /// 生成单元格样式 + /// + /// 与当前Excel相关的单元格样式 + public ICellStyle CreateCellStyle() + { + return Book.CreateCellStyle(); + } + + /// + /// 生成字体 + /// + /// 与当前Excel相关的字体 + public IFont CreateFont() + { + return Book.CreateFont(); + } + + /// + /// 设置单元格样式 + /// 注:只对当前ActiveSheet有效 + /// + /// 行号 + /// 列号 + /// 样式 + public void SetStyle(int rowIndex, int columnIndex, ICellStyle style) + { + IRow row = Book.GetSheetAt(sheetID).GetRow(rowIndex); + if (row == null) + { + row = Book.GetSheetAt(sheetID).CreateRow(rowIndex); + } + ICell cell = row.GetCell(columnIndex); + if (cell == null) + { + cell = row.CreateCell(columnIndex); + } + cell.CellStyle = style; + } + + /// + /// 合并单元格 + /// 注:只对当前ActiveSheet有效 + /// + /// 开始行号 + /// 开始列号 + /// 结束行号 + /// 结束列号 + public void MergeCells(int startRowIndex, int startColumnIndex, int endRowIndex, int endColumnIndex) + { + int Index = Book.GetSheetAt(sheetID).AddMergedRegion(new CellRangeAddress(startRowIndex, endRowIndex, startColumnIndex, endColumnIndex)); + } + + /// + /// 拆分单元格 + /// 注1:只对当前ActiveSheet有效 + /// 注2:只有合并的单元格才能拆分 + /// + /// 开始行号 + /// 开始列号 + public void UnMergeCells(int startRowIndex, int startColumnIndex) + { + int merges = Book.GetSheetAt(sheetID).NumMergedRegions; + CellRangeAddress merge; + for (int i = 0; i < merges; i++) + { + merge = Book.GetSheetAt(sheetID).GetMergedRegion(i); + if (merge.FirstRow == startRowIndex && merge.FirstColumn == startColumnIndex) + { + Book.GetSheetAt(sheetID).RemoveMergedRegion(i); + break; + } + } + } + + /// + /// 保存到文件 + /// 注:有模板的,文件扩展名与模板一样;没有模板的,文件扩展名为“.xls”; + /// + /// 保存文件名 + public void Save(String fileName) + { + FileStream file = new FileStream(fileName, FileMode.Create); + Book.Write(file); + file.Close(); + } + + /// + /// 保存到流 + /// 注:保存或下载时,有模板的,文件扩展名与模板一样;没有模板的,文件扩展名为“.xls”; + /// + /// 内存流 + public MemoryStream Save() + { + MemoryStream ms = new MemoryStream(); + Book.Write(ms); + return ms; + } + + /// + /// 把Excel读成DataSet + /// 注:必须是正规表格式 + /// + /// 读出的Excel + public DataSet ReadAsDataSet() + { + DataSet rtn = new DataSet(); + for (int i = 0; i < SheetCount; i++) + { + ISheet sheet = Book.GetSheetAt(i); + rtn.Tables.Add(GetDataTableBySheet(sheet)); + } + return rtn; + } + + private DataTable GetDataTableBySheet(ISheet sheet) + { + DataTable dt = new DataTable(sheet.SheetName); + int maxCols = 0; + object value; + while ((value = ReadValue(sheet, 0, maxCols)) != null) + { + dt.Columns.Add(value.ToString()); + maxCols++; + } + + int row = 1; + + bool emptyRow = false; + int emptyRowCount = 0; + while (emptyRowCount < 10) + { + emptyRow = true; + DataRow dr = dt.NewRow(); + for (int i = 0; i < maxCols; i++) + { + value = ReadValue(sheet, row, i); + if (value != null) + { + dr[i] = value; + emptyRow = false; + } + } + if (!emptyRow) + { + dt.Rows.Add(dr); + emptyRowCount = 0; + } + else + { + emptyRowCount++; + } + row++; + } + + return dt; + } + + /// + /// 根据SheetName导出数据为DataTable + /// + /// Sheet名称 + /// + public DataTable GetDataTableBySheet(String sheetName) + { + + ISheet sheet = Book.GetSheet(sheetName); + if (sheet != null) + { + return GetDataTableBySheet(sheet); + } + return null; + + } + + /// + /// 根据SheetName导出数据为DataTable + /// + /// Sheet编号 + /// + public DataTable GetDataTableBySheet(int sheetIndex) + { + + ISheet sheet = Book.GetSheetAt(sheetIndex); + if (sheet != null) + { + return GetDataTableBySheet(sheet); + } + return null; + + } + + /// + /// 写入表格 + /// + /// 表格数据 + /// 写入的起始列 + /// 写入的起始行 + /// 标题颜色 + /// 是否需要四周边框 + public void WriteDataTable(DataTable Data, int col = 1, int row = 1, short? titleColor = null, bool fullBorder = true) + { + if (Data == null) + { + return; + } + + var titleStyle = CreateCellStyle(); + var rowStyle = CreateCellStyle(); + if (titleColor != null) + titleStyle.FillForegroundColor = titleColor.Value; + + titleStyle.FillPattern = FillPattern.SolidForeground; + if (fullBorder) + { + titleStyle.BorderBottom = BorderStyle.Thin; + titleStyle.BorderLeft = BorderStyle.Thin; + titleStyle.BorderRight = BorderStyle.Thin; + titleStyle.BorderTop = BorderStyle.Thin; + titleStyle.BottomBorderColor = NPOIColor.BLACK; + titleStyle.LeftBorderColor = NPOIColor.BLACK; + titleStyle.RightBorderColor = NPOIColor.BLACK; + titleStyle.TopBorderColor = NPOIColor.BLACK; + rowStyle.BorderBottom = BorderStyle.Thin; + rowStyle.BorderLeft = BorderStyle.Thin; + rowStyle.BorderRight = BorderStyle.Thin; + rowStyle.BorderTop = BorderStyle.Thin; + rowStyle.BottomBorderColor = NPOIColor.BLACK; + rowStyle.LeftBorderColor = NPOIColor.BLACK; + rowStyle.RightBorderColor = NPOIColor.BLACK; + rowStyle.TopBorderColor = NPOIColor.BLACK; + } + + int iCol = 0, iRow = 1; + + foreach (DataColumn dc in Data.Columns) + { + SetValue(row, col + iCol, dc.ColumnName); + SetStyle(row, col + iCol, titleStyle); + iCol++; + } + + rowStyle.FillForegroundColor = NPOIColor.WHITE; + + foreach (DataRow dr in Data.Rows) + { + iCol = 0; + foreach (DataColumn dc in Data.Columns) + { + SetValue(row + iRow, col + iCol, dr[dc]); + SetStyle(row + iRow, col + iCol, rowStyle); + iCol++; + } + iRow++; + } + + for (int i = 0; i < iCol; i++) + { + this.AutoColWidth(i); + } + } + + /// + /// 读取单元格的值 + /// 注:只对当前ActiveSheet有效 + /// + /// 行号 + /// 列号 + /// 单元格的值 + public object ReadValue(ISheet sheet, int rowIndex, int columnIndex, bool? isDateTime = null) + { + try + { + ICell cell = sheet.GetRow(rowIndex).GetCell(columnIndex); + short df = cell.CellStyle.DataFormat; + + //return cell.ToString(); + switch (cell.CellType) + { + case CellType.Blank: + return null; + case CellType.Boolean: + return cell.BooleanCellValue; + case CellType.Error: + throw new Exception("Cell Value Error"); + case CellType.Formula: + { + switch (cell.CachedFormulaResultType) + { + case CellType.Blank: + return ""; + case CellType.Boolean: + return cell.BooleanCellValue; + case CellType.Error: + throw new Exception("Cell Value Error"); + case CellType.Formula: + throw new Exception("The Formula of this cell is too complex!"); + case CellType.Numeric: + if (isDateTime == null) + { + if (DateUtil.IsCellDateFormatted(cell)) + { + return cell.DateCellValue; + } + else + { + return cell.NumericCellValue; + } + } + else if (isDateTime == true) + { + return cell.DateCellValue; + } + else + { + return cell.NumericCellValue; + } + case CellType.String: + return cell.StringCellValue; + case CellType.Unknown: + return cell.ToString(); + default: + return cell.ToString(); + } + } + case CellType.Numeric: + { + if (isDateTime == null) + { + if (DateUtil.IsCellDateFormatted(cell)) + { + return cell.DateCellValue; + } + else + { + return cell.NumericCellValue; + } + } + else if (isDateTime == true) + { + return cell.DateCellValue; + } + else + { + return cell.NumericCellValue; + } + } + case CellType.String: + return cell.StringCellValue; + case CellType.Unknown: + return cell.ToString(); + default: + return cell.ToString(); + } + } + catch (System.NullReferenceException) + { + return null; + } + catch (Exception ex) + { + throw ex; + } + } + + public int SheetCount + { + get + { + return Book.NumberOfSheets; + } + } + + public String GetSheetName(int Index) + { + return Book.GetSheetName(Index); + } + + public void AddPicture(byte[] data, int row, int col) + { + int picIndex = Book.AddPicture(data, PictureType.PNG); + + IDrawing draw = ActiveSheet.CreateDrawingPatriarch(); + + IClientAnchor anchor = draw.CreateAnchor(0, 0, 255, 255, col, row, col + 5, col + 5); + IPicture pic = draw.CreatePicture(anchor, picIndex); + pic.Resize(); + } + } + + public enum OperatorTypes + { + /// + /// 介于最大值与小值之间 + /// + BETWEEN = OperatorType.BETWEEN, + /// + /// 等于最小值 + /// + EQUAL = OperatorType.EQUAL, + /// + /// 大于或等于最小值 + /// + GREATER_OR_EQUAL = OperatorType.GREATER_OR_EQUAL, + /// + /// 大于最小值 + /// + GREATER_THAN = OperatorType.GREATER_THAN, + /// + /// 忽略 + /// + NO_COMPARISON = OperatorType.IGNORED, + /// + /// 小于或等于最小值 + /// + LESS_OR_EQUAL = OperatorType.LESS_OR_EQUAL, + /// + /// 小于最小值 + /// + LESS_THAN = OperatorType.LESS_THAN, + /// + /// 不在最小值与最大值之间 + /// + NOT_BETWEEN = OperatorType.NOT_BETWEEN, + /// + /// 不等于最小值 + /// + NOT_EQUAL = OperatorType.NOT_EQUAL + } + + public enum NPOIDataType + { + /// + /// 验证整数 + /// + Integer, + /// + /// 验证符点数 + /// + Float, + /// + /// 验证日期 + /// + Date, + /// + /// 验证时间 + /// + Time, + /// + /// 验证字符长度 + /// + TextLength + } + + public static class NPOIColor + { + + /// + /// 红色 + /// + public static short RED { get { return NPOI.HSSF.Util.HSSFColor.Red.Index; } } + + /// + /// 蓝色 + /// + public static short BLUE { get { return NPOI.HSSF.Util.HSSFColor.Blue.Index; } } + + /// + /// 浅绿色 + /// + public static short AQUA { get { return NPOI.HSSF.Util.HSSFColor.Aqua.Index; } } + + /// + /// 自动 + /// + public static short AUTOMATIC { get { return NPOI.HSSF.Util.HSSFColor.Automatic.Index; } } + + /// + /// 黑色 + /// + public static short BLACK { get { return NPOI.HSSF.Util.HSSFColor.Black.Index; } } + + /// + /// 蓝灰色 + /// + public static short BLUE_GREY { get { return NPOI.HSSF.Util.HSSFColor.BlueGrey.Index; } } + + /// + /// 明绿色 + /// + public static short BRIGHT_GREEN { get { return NPOI.HSSF.Util.HSSFColor.BrightGreen.Index; } } + + /// + /// 棕色 + /// + public static short BROWN { get { return NPOI.HSSF.Util.HSSFColor.Brown.Index; } } + + /// + /// 正常 + /// + public static short COLOR_NORMAL { get { return NPOI.HSSF.Util.HSSFColor.COLOR_NORMAL; } } + + /// + /// 珊瑚色 + /// + public static short CORAL { get { return NPOI.HSSF.Util.HSSFColor.Coral.Index; } } + + /// + /// 亮蓝色 + /// + public static short CORNFLOWER_BLUE { get { return NPOI.HSSF.Util.HSSFColor.CornflowerBlue.Index; } } + + /// + /// 深蓝色 + /// + public static short DARK_BLUE { get { return NPOI.HSSF.Util.HSSFColor.DarkBlue.Index; } } + + /// + /// 深绿色 + /// + public static short DARK_GREEN { get { return NPOI.HSSF.Util.HSSFColor.DarkGreen.Index; } } + + /// + /// 深红色 + /// + public static short DARK_RED { get { return NPOI.HSSF.Util.HSSFColor.DarkRed.Index; } } + + /// + /// 深茶色 + /// + public static short DARK_TEAL { get { return NPOI.HSSF.Util.HSSFColor.DarkTeal.Index; } } + + /// + /// 深黄 + /// + public static short DARK_YELLOW { get { return NPOI.HSSF.Util.HSSFColor.DarkYellow.Index; } } + + /// + /// 金色 + /// + public static short GOLD { get { return NPOI.HSSF.Util.HSSFColor.Gold.Index; } } + + /// + /// 绿色 + /// + public static short GREEN { get { return NPOI.HSSF.Util.HSSFColor.Green.Index; } } + + /// + /// 25%灰色 + /// + public static short GREY_25_PERCENT { get { return NPOI.HSSF.Util.HSSFColor.Grey25Percent.Index; } } + + /// + /// 40%灰色 + /// + public static short GREY_40_PERCENT { get { return NPOI.HSSF.Util.HSSFColor.Grey40Percent.Index; } } + + /// + /// 50%灰色 + /// + public static short GREY_50_PERCENT { get { return NPOI.HSSF.Util.HSSFColor.Grey50Percent.Index; } } + + /// + /// 80%灰色 + /// + public static short GREY_80_PERCENT { get { return NPOI.HSSF.Util.HSSFColor.Grey80Percent.Index; } } + + /// + /// 靛蓝色 + /// + public static short INDIGO { get { return NPOI.HSSF.Util.HSSFColor.Indigo.Index; } } + + /// + /// 淡紫色 + /// + public static short LAVENDER { get { return NPOI.HSSF.Util.HSSFColor.Lavender.Index; } } + + /// + /// 粉黄色 + /// + public static short LEMON_CHIFFON { get { return NPOI.HSSF.Util.HSSFColor.LemonChiffon.Index; } } + + /// + /// 淡蓝色 + /// + public static short LIGHT_BLUE { get { return NPOI.HSSF.Util.HSSFColor.LightBlue.Index; } } + + /// + /// 淡亮蓝色 + /// + public static short LIGHT_CORNFLOWER_BLUE { get { return NPOI.HSSF.Util.HSSFColor.LightCornflowerBlue.Index; } } + + /// + /// 淡绿色 + /// + public static short LIGHT_GREEN { get { return NPOI.HSSF.Util.HSSFColor.LightGreen.Index; } } + + /// + /// 淡桔黄色 + /// + public static short LIGHT_ORANGE { get { return NPOI.HSSF.Util.HSSFColor.LightOrange.Index; } } + + /// + /// 淡蓝绿色 + /// + public static short LIGHT_TURQUOISE { get { return NPOI.HSSF.Util.HSSFColor.LightTurquoise.Index; } } + + /// + /// 淡黄色 + /// + public static short LIGHT_YELLOW { get { return NPOI.HSSF.Util.HSSFColor.LightYellow.Index; } } + + /// + /// 绿黄色 + /// + public static short LIME { get { return NPOI.HSSF.Util.HSSFColor.Lime.Index; } } + + /// + /// 栗色 + /// + public static short MAROON { get { return NPOI.HSSF.Util.HSSFColor.Maroon.Index; } } + + /// + /// 橄榄绿色 + /// + public static short OLIVE_GREEN { get { return NPOI.HSSF.Util.HSSFColor.OliveGreen.Index; } } + + /// + /// 桔色 + /// + public static short ORANGE { get { return NPOI.HSSF.Util.HSSFColor.Orange.Index; } } + + /// + /// 白灰蓝色 + /// + public static short PALE_BLUE { get { return NPOI.HSSF.Util.HSSFColor.PaleBlue.Index; } } + + /// + /// 粉红色 + /// + public static short PINK { get { return NPOI.HSSF.Util.HSSFColor.Pink.Index; } } + + /// + /// 紫红色 + /// + public static short PLUM { get { return NPOI.HSSF.Util.HSSFColor.Plum.Index; } } + + /// + /// 玫瑰红色 + /// + public static short ROSE { get { return NPOI.HSSF.Util.HSSFColor.Rose.Index; } } + + /// + /// 高贵蓝 + /// + public static short ROYAL_BLUE { get { return NPOI.HSSF.Util.HSSFColor.RoyalBlue.Index; } } + + /// + /// 海绿色 + /// + public static short SEA_GREEN { get { return NPOI.HSSF.Util.HSSFColor.SeaGreen.Index; } } + + /// + /// 天空蓝 + /// + public static short SKY_BLUE { get { return NPOI.HSSF.Util.HSSFColor.SkyBlue.Index; } } + + /// + /// 棕褐色 + /// + public static short TAN { get { return NPOI.HSSF.Util.HSSFColor.Tan.Index; } } + + /// + /// 茶色 + /// + public static short TEAL { get { return NPOI.HSSF.Util.HSSFColor.Teal.Index; } } + + /// + /// 蓝绿色 + /// + public static short TURQUOISE { get { return NPOI.HSSF.Util.HSSFColor.Turquoise.Index; } } + + /// + /// 紫色 + /// + public static short VIOLET { get { return NPOI.HSSF.Util.HSSFColor.Violet.Index; } } + + /// + /// 白色 + /// + public static short WHITE { get { return NPOI.HSSF.Util.HSSFColor.White.Index; } } + + /// + /// 黄色 + /// + public static short YELLOW { get { return NPOI.HSSF.Util.HSSFColor.Yellow.Index; } } + + } + + /// + /// 针对excel的Oledb + /// + public class OleDbExcel + { + /// + /// OLEDB连接 + /// + public OleDbConnection Connection + { + get; + set; + } + + /// + /// 用Oledb对Excel进行操作 + /// 注:必须是标准表形式Excel内容 + /// + /// Excel文件 + public OleDbExcel(String excelFile) + { + String conStr = String.Empty; + FileInfo file = new FileInfo(excelFile); + if (!file.Exists) { throw new Exception("文件不存在"); } + String extension = file.Extension; + switch (extension) + { + case ".xls": + conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + excelFile + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'"; + break; + case ".xlsx": + conStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excelFile + ";Extended Properties='Excel 12.0;HDR=Yes;IMEX=1;'"; + break; + default: + conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + excelFile + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'"; + break; + } + + //链接Excel + Connection = new OleDbConnection(conStr); + } + + private List tableNames; + + /// + /// 获取Excel内的Sheet名称 + /// + public List Sheets + { + get + { + if (tableNames == null) + { + try + { + tableNames = new List(); + //读取Excel里面的sheet名 + Connection.Open(); + + DataTable schemaTable = Connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" }); + + for (int i = 0; i < schemaTable.Rows.Count; i++) + { + DataRow dr = schemaTable.Rows[i]; + String tbName = dr["table_name"].ToString(); + if (tbName[tbName.Length - 1] == '$') + { + tableNames.Add(tbName); + } + } + Connection.Close(); + } + catch (Exception ex) + { + if (Connection.State != ConnectionState.Closed) + { + Connection.Close(); + } + throw new Exception(ex.Message, ex); + } + } + return tableNames; + } + } + + /// + /// 查询出所有数据 + /// + /// Sheet名称 + /// sheet内的所有数据 + public DataSet QueryAll(String tableName) + { + try + { + DataSet excelData = new DataSet(); + OleDbDataAdapter adapter = new OleDbDataAdapter(); + adapter.SelectCommand = new OleDbCommand(); + adapter.SelectCommand.Connection = Connection; + adapter.SelectCommand.CommandText = String.Format("SELECT * FROM {0}", "[" + tableName + "]"); + adapter.Fill(excelData); + return excelData; + } + catch (Exception ex) + { + if (Connection.State != ConnectionState.Closed) + { + Connection.Close(); + } + throw new Exception(ex.Message, ex); + } + } + + /// + /// 查询出所有数据 + /// + /// Sheet序号(从0开始) + /// sheet内的所有数据 + public DataSet QueryAll(int tableIndex) + { + return QueryAll(Sheets[tableIndex]); + } + + /// + /// 利用Sql进行查询 + /// + /// Sql语句 + /// 查询出的数据 + public DataSet Query(String sql) + { + try + { + DataSet excelData = new DataSet(); + OleDbDataAdapter adapter = new OleDbDataAdapter(sql, Connection); + adapter.Fill(excelData); + return excelData; + } + catch (Exception ex) + { + if (Connection.State != ConnectionState.Closed) + { + Connection.Close(); + } + throw new Exception(ex.Message, ex); + } + } + + /// + /// 利用Sql进行查询 + /// + /// Sql语句 + /// 查询参数 + /// 查询出的数据 + public DataSet Query(String sql, params OleDbParameter[] param) + { + try + { + DataSet excelData = new DataSet(); + OleDbDataAdapter adapter = new OleDbDataAdapter(sql, Connection); + adapter.SelectCommand.Parameters.AddRange(param); + adapter.Fill(excelData); + return excelData; + } + catch (Exception ex) + { + if (Connection.State != ConnectionState.Closed) + { + Connection.Close(); + } + throw new Exception(ex.Message, ex); + } + } + + /// + /// 利用Sql进行数据操作 + /// + /// sql语句 + /// 影响的行数 + public int ExecuteSql(String sql) + { + try + { + Connection.Open(); + OleDbCommand cmd = Connection.CreateCommand(); + cmd.CommandText = sql; + int rtn = cmd.ExecuteNonQuery(); + Connection.Close(); + return rtn; + } + catch (Exception ex) + { + if (Connection.State != ConnectionState.Closed) + { + Connection.Close(); + } + throw new Exception(ex.Message, ex); + } + } + + /// + /// 利用Sql进行数据操作 + /// + /// sql语句 + /// 执行参数 + /// 影响的行数 + public int ExecuteSql(String sql, params OleDbParameter[] param) + { + try + { + Connection.Open(); + OleDbCommand cmd = Connection.CreateCommand(); + cmd.CommandText = sql; + cmd.Parameters.AddRange(param); + int rtn = cmd.ExecuteNonQuery(); + Connection.Close(); + return rtn; + } + catch (Exception ex) + { + if (Connection.State != ConnectionState.Closed) + { + Connection.Close(); + } + throw new Exception(ex.Message, ex); + } + } + } +} \ No newline at end of file diff --git a/SGGL/FineUIPro.Web/HSSE/QualityAudit/EquipmentQuality.aspx b/SGGL/FineUIPro.Web/HSSE/QualityAudit/EquipmentQuality.aspx index 9cf6fddb..08f3b06f 100644 --- a/SGGL/FineUIPro.Web/HSSE/QualityAudit/EquipmentQuality.aspx +++ b/SGGL/FineUIPro.Web/HSSE/QualityAudit/EquipmentQuality.aspx @@ -36,7 +36,8 @@ + + diff --git a/SGGL/FineUIPro.Web/HSSE/QualityAudit/EquipmentQuality.aspx.cs b/SGGL/FineUIPro.Web/HSSE/QualityAudit/EquipmentQuality.aspx.cs index 14616a04..6506bee0 100644 --- a/SGGL/FineUIPro.Web/HSSE/QualityAudit/EquipmentQuality.aspx.cs +++ b/SGGL/FineUIPro.Web/HSSE/QualityAudit/EquipmentQuality.aspx.cs @@ -1,10 +1,13 @@ using BLL; +using BLL.Common; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; +using System.IO; using System.Linq; using System.Text; +using ThoughtWorks.QRCode.Codec; using AspNet = System.Web.UI.WebControls; namespace FineUIPro.Web.HSSE.QualityAudit @@ -294,5 +297,120 @@ namespace FineUIPro.Web.HSSE.QualityAudit } } #endregion + + protected void btnQR_Click(object sender, EventArgs e) + { + string strSql = @"SELECT EquipmentQuality.EquipmentQualityId, CodeRecords.Code AS EquipmentQualityCode, + EquipmentQuality.FactoryCode ,EquipmentQuality.QRCodeAttachUrl + FROM QualityAudit_EquipmentQuality AS EquipmentQuality + LEFT JOIN Sys_CodeRecords AS CodeRecords ON EquipmentQuality.EquipmentQualityId = CodeRecords.DataId + LEFT JOIN Base_SpecialEquipment AS SpecialEquipment ON SpecialEquipment.SpecialEquipmentId = EquipmentQuality.SpecialEquipmentId WHERE 1=1 "; + List listStr = new List(); + if (!string.IsNullOrEmpty(this.CurrUser.LoginProjectId)) + { + strSql += " AND EquipmentQuality.ProjectId = @ProjectId"; + listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId)); + } + if (!string.IsNullOrEmpty(this.txtEquipmentQualityCode.Text.Trim())) + { + strSql += " AND EquipmentQualityCode LIKE @EquipmentQualityCode"; + listStr.Add(new SqlParameter("@EquipmentQualityCode", "%" + this.txtEquipmentQualityCode.Text.Trim() + "%")); + } + if (this.drpUnitId.SelectedValue != BLL.Const._Null) + { + strSql += " AND EquipmentQuality.UnitId = @UnitId"; + listStr.Add(new SqlParameter("@UnitId", this.drpUnitId.SelectedValue.Trim())); + } + if (!string.IsNullOrEmpty(this.txtSpecialEquipmentName.Text.Trim())) + { + strSql += " AND SpecialEquipmentName LIKE @SpecialEquipmentName"; + listStr.Add(new SqlParameter("@SpecialEquipmentName", "%" + this.txtSpecialEquipmentName.Text.Trim() + "%")); + } + SqlParameter[] parameter = listStr.ToArray(); + DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); + + NPOIExcel excel = new NPOIExcel(); + excel.SetColumnWidth(0, 50); + excel.SetColumnWidth(1, 50); + excel.SetColumnWidth(2, 50); + for (int i = 0; i < tb.Rows.Count; i++) + { + if (i % 3 == 0) + { + excel.SetRowHeight(2 * (int)(i / 3), 200); + } + string QRCodeAttachUrl = tb.Rows[i]["QRCodeAttachUrl"].ToString(); + string EquipmentQualityCode = tb.Rows[i]["EquipmentQualityCode"].ToString(); + if (string.IsNullOrEmpty(QRCodeAttachUrl)) + { + try + { + var equipmentQuality = Funs.DB.QualityAudit_EquipmentQuality.FirstOrDefault(x => x.EquipmentQualityId == tb.Rows[i]["EquipmentQualityId"].ToString()); + equipmentQuality.QRCodeAttachUrl = CreateCode_Simple("equipment$" + tb.Rows[i]["FactoryCode"].ToString()); + QRCodeAttachUrl = equipmentQuality.QRCodeAttachUrl; + Funs.DB.SubmitChanges(); + } + catch (Exception e1) { } + + } + //add picture data to this workbook. + excel.SetPicValue(2 * (int)(i / 3), i % 3, Server.MapPath("~/") + QRCodeAttachUrl); + excel.SetValue(2 * (int)(i / 3) + 1, i % 3, EquipmentQualityCode); + } + string initTemplatePath = Const.ExcelUrl + Funs.GetNewFileName() + ".xls"; + string uploadfilepath = Server.MapPath("~/") + initTemplatePath; + string fileName = Path.GetFileName(initTemplatePath); + excel.Save(uploadfilepath); + FileInfo info = new FileInfo(uploadfilepath); + + long fileSize = info.Length; + Response.ClearContent(); + Response.ContentType = "application/x-zip-compressed"; + Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8)); + Response.AddHeader("Content-Length", fileSize.ToString()); + Response.TransmitFile(uploadfilepath, 0, fileSize); + Response.Flush(); + Response.End(); + + + + } + + private string CreateCode_Simple(string nr) + { + try + { + string imageUrl = string.Empty; + QRCodeEncoder qrCodeEncoder = new QRCodeEncoder + { + QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE, + QRCodeScale = nr.Length, + QRCodeVersion = 0, + QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M + }; + System.Drawing.Image image = qrCodeEncoder.Encode(nr, Encoding.UTF8); + string filepath = Server.MapPath("~/") + UploadFileService.QRCodeImageFilePath; + //如果文件夹不存在,则创建 + if (!Directory.Exists(filepath)) + { + Directory.CreateDirectory(filepath); + } + string filename = DateTime.Now.ToString("yyyymmddhhmmssfff").ToString() + ".jpg"; + imageUrl = filepath + filename; + FileStream fs = new FileStream(imageUrl, FileMode.OpenOrCreate, FileAccess.Write); + image.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg); + fs.Close(); + image.Dispose(); + return UploadFileService.QRCodeImageFilePath + filename; + } + + catch (Exception ex) + + { + } + return ""; + } + + } } \ No newline at end of file diff --git a/SGGL/FineUIPro.Web/HSSE/QualityAudit/EquipmentQuality.aspx.designer.cs b/SGGL/FineUIPro.Web/HSSE/QualityAudit/EquipmentQuality.aspx.designer.cs index 1b1a9e21..d1027b11 100644 --- a/SGGL/FineUIPro.Web/HSSE/QualityAudit/EquipmentQuality.aspx.designer.cs +++ b/SGGL/FineUIPro.Web/HSSE/QualityAudit/EquipmentQuality.aspx.designer.cs @@ -7,11 +7,13 @@ // //------------------------------------------------------------------------------ -namespace FineUIPro.Web.HSSE.QualityAudit { - - - public partial class EquipmentQuality { - +namespace FineUIPro.Web.HSSE.QualityAudit +{ + + + public partial class EquipmentQuality + { + /// /// form1 控件。 /// @@ -20,7 +22,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::System.Web.UI.HtmlControls.HtmlForm form1; - + /// /// PageManager1 控件。 /// @@ -29,7 +31,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.PageManager PageManager1; - + /// /// Panel1 控件。 /// @@ -38,7 +40,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.Panel Panel1; - + /// /// Grid1 控件。 /// @@ -47,7 +49,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.Grid Grid1; - + /// /// Toolbar2 控件。 /// @@ -56,7 +58,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.Toolbar Toolbar2; - + /// /// txtEquipmentQualityCode 控件。 /// @@ -65,7 +67,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.TextBox txtEquipmentQualityCode; - + /// /// drpUnitId 控件。 /// @@ -74,7 +76,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.DropDownList drpUnitId; - + /// /// txtSpecialEquipmentName 控件。 /// @@ -83,7 +85,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.TextBox txtSpecialEquipmentName; - + /// /// ToolbarFill1 控件。 /// @@ -92,7 +94,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.ToolbarFill ToolbarFill1; - + /// /// btnNew 控件。 /// @@ -101,7 +103,16 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.Button btnNew; - + + /// + /// btnQR 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::FineUIPro.Button btnQR; + /// /// btnOut 控件。 /// @@ -110,7 +121,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.Button btnOut; - + /// /// lblNumber 控件。 /// @@ -119,7 +130,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::System.Web.UI.WebControls.Label lblNumber; - + /// /// ToolbarSeparator1 控件。 /// @@ -128,7 +139,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.ToolbarSeparator ToolbarSeparator1; - + /// /// ToolbarText1 控件。 /// @@ -137,7 +148,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.ToolbarText ToolbarText1; - + /// /// ddlPageSize 控件。 /// @@ -146,7 +157,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.DropDownList ddlPageSize; - + /// /// Window1 控件。 /// @@ -155,7 +166,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.Window Window1; - + /// /// WindowAtt 控件。 /// @@ -164,7 +175,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.Window WindowAtt; - + /// /// Menu1 控件。 /// @@ -173,7 +184,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.Menu Menu1; - + /// /// btnMenuEdit 控件。 /// @@ -182,7 +193,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.MenuButton btnMenuEdit; - + /// /// btnMenuDelete 控件。 /// diff --git a/SGGL/FineUIPro.Web/HSSE/QualityAudit/GeneralEquipmentQuality.aspx b/SGGL/FineUIPro.Web/HSSE/QualityAudit/GeneralEquipmentQuality.aspx index 79b9f6df..015698e7 100644 --- a/SGGL/FineUIPro.Web/HSSE/QualityAudit/GeneralEquipmentQuality.aspx +++ b/SGGL/FineUIPro.Web/HSSE/QualityAudit/GeneralEquipmentQuality.aspx @@ -38,7 +38,8 @@ + + diff --git a/SGGL/FineUIPro.Web/HSSE/QualityAudit/GeneralEquipmentQuality.aspx.cs b/SGGL/FineUIPro.Web/HSSE/QualityAudit/GeneralEquipmentQuality.aspx.cs index 0532f26f..1fcbfec5 100644 --- a/SGGL/FineUIPro.Web/HSSE/QualityAudit/GeneralEquipmentQuality.aspx.cs +++ b/SGGL/FineUIPro.Web/HSSE/QualityAudit/GeneralEquipmentQuality.aspx.cs @@ -1,10 +1,13 @@ using BLL; +using BLL.Common; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; +using System.IO; using System.Linq; using System.Text; +using ThoughtWorks.QRCode.Codec; using AspNet = System.Web.UI.WebControls; namespace FineUIPro.Web.HSSE.QualityAudit @@ -50,7 +53,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit if (this.CurrUser != null && this.CurrUser.PageSize.HasValue) { Grid1.PageSize = this.CurrUser.PageSize.Value; - } + } this.ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); // 绑定表格 this.BindGrid(); @@ -109,7 +112,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); Grid1.RecordCount = tb.Rows.Count; - + var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); @@ -265,11 +268,134 @@ namespace FineUIPro.Web.HSSE.QualityAudit Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("一般机具设备资质" + filename, System.Text.Encoding.UTF8) + ".xls"); Response.ContentType = "application/excel"; Response.ContentEncoding = System.Text.Encoding.UTF8; - this.Grid1.PageSize = this.Grid1.RecordCount; + this.Grid1.PageSize = this.Grid1.RecordCount; BindGrid(); Response.Write(GetGridTableHtml(Grid1)); Response.End(); } #endregion + + + + + + protected void btnQR_Click(object sender, EventArgs e) + { + string strSql = @"SELECT GeneralEquipmentQuality.GeneralEquipmentQualityId," + + @"CodeRecords.Code AS GeneralEquipmentQualityCode," + + @"GeneralEquipmentQuality.GeneralEquipmentQualityCode," + + @"GeneralEquipmentQuality.QRCodeAttachUrl," + + @"SpecialEquipment.SpecialEquipmentName" + + @" FROM QualityAudit_GeneralEquipmentQuality AS GeneralEquipmentQuality " + + @" LEFT JOIN Base_SpecialEquipment AS SpecialEquipment ON SpecialEquipment.SpecialEquipmentId = GeneralEquipmentQuality.SpecialEquipmentId " + + @" LEFT JOIN Sys_CodeRecords AS CodeRecords ON GeneralEquipmentQuality.GeneralEquipmentQualityId = CodeRecords.DataId WHERE 1=1 "; + List listStr = new List(); + if (!string.IsNullOrEmpty(this.CurrUser.LoginProjectId)) + { + strSql += " AND GeneralEquipmentQuality.ProjectId = @ProjectId"; + listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId)); + } + if (BLL.ProjectUnitService.GetProjectUnitTypeByProjectIdUnitId(this.ProjectId, this.CurrUser.UnitId)) + { + strSql += " AND GeneralEquipmentQuality.UnitId = @UnitId"; ///状态为已完成 + listStr.Add(new SqlParameter("@UnitId", this.CurrUser.UnitId)); + } + if (!string.IsNullOrEmpty(this.txtGeneralEquipmentQualityCode.Text.Trim())) + { + strSql += " AND GeneralEquipmentQualityCode LIKE @GeneralEquipmentQualityCode"; + listStr.Add(new SqlParameter("@GeneralEquipmentQualityCode", "%" + this.txtGeneralEquipmentQualityCode.Text.Trim() + "%")); + } + if (!string.IsNullOrEmpty(this.txtUnitName.Text.Trim())) + { + strSql += " AND UnitName LIKE @UnitName"; + listStr.Add(new SqlParameter("@UnitName", "%" + this.txtUnitName.Text.Trim() + "%")); + } + if (!string.IsNullOrEmpty(this.txtSpecialEquipmentName.Text.Trim())) + { + strSql += " AND SpecialEquipmentName LIKE @SpecialEquipmentName"; + listStr.Add(new SqlParameter("@SpecialEquipmentName", "%" + this.txtSpecialEquipmentName.Text.Trim() + "%")); + } + SqlParameter[] parameter = listStr.ToArray(); + DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); + + NPOIExcel excel = new NPOIExcel(); + excel.SetColumnWidth(0, 50); + excel.SetColumnWidth(1, 50); + excel.SetColumnWidth(2, 50); + for (int i = 0; i < tb.Rows.Count; i++) + { + if (i % 3 == 0) + { + excel.SetRowHeight(2 * (int)(i / 3), 200); + } + string QRCodeAttachUrl = tb.Rows[i]["QRCodeAttachUrl"].ToString(); + string GeneralEquipmentQualityCode = tb.Rows[i]["GeneralEquipmentQualityCode"].ToString(); + if (string.IsNullOrEmpty(QRCodeAttachUrl)) + { + try + { + var equipmentQuality = Funs.DB.QualityAudit_GeneralEquipmentQuality.FirstOrDefault(x => x.GeneralEquipmentQualityId == tb.Rows[i]["GeneralEquipmentQualityId"].ToString()); + equipmentQuality.QRCodeAttachUrl = CreateCode_Simple("equipment$" + tb.Rows[i]["GeneralEquipmentQualityId"].ToString()); + QRCodeAttachUrl = equipmentQuality.QRCodeAttachUrl; + Funs.DB.SubmitChanges(); + } + catch (Exception e1) { } + } + //add picture data to this workbook. + excel.SetPicValue(2 * (int)(i / 3), i % 3, Server.MapPath("~/") + QRCodeAttachUrl); + excel.SetValue(2 * (int)(i / 3) + 1, i % 3, GeneralEquipmentQualityCode); + } + string initTemplatePath = Const.ExcelUrl + Funs.GetNewFileName() + ".xls"; + string uploadfilepath = Server.MapPath("~/") + initTemplatePath; + string fileName = Path.GetFileName(initTemplatePath); + excel.Save(uploadfilepath); + FileInfo info = new FileInfo(uploadfilepath); + + long fileSize = info.Length; + Response.ClearContent(); + Response.ContentType = "application/x-zip-compressed"; + Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8)); + Response.AddHeader("Content-Length", fileSize.ToString()); + Response.TransmitFile(uploadfilepath, 0, fileSize); + Response.Flush(); + Response.End(); + + + + } + private string CreateCode_Simple(string nr) + { + try + { + string imageUrl = string.Empty; + QRCodeEncoder qrCodeEncoder = new QRCodeEncoder + { + QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE, + QRCodeScale = nr.Length, + QRCodeVersion = 0, + QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M + }; + System.Drawing.Image image = qrCodeEncoder.Encode(nr, Encoding.UTF8); + string filepath = Server.MapPath("~/") + UploadFileService.QRCodeImageFilePath; + //如果文件夹不存在,则创建 + if (!Directory.Exists(filepath)) + { + Directory.CreateDirectory(filepath); + } + string filename = DateTime.Now.ToString("yyyymmddhhmmssfff").ToString() + ".jpg"; + imageUrl = filepath + filename; + FileStream fs = new FileStream(imageUrl, FileMode.OpenOrCreate, FileAccess.Write); + image.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg); + fs.Close(); + image.Dispose(); + return UploadFileService.QRCodeImageFilePath + filename; + } + + catch (Exception ex) + + { + } + return ""; + } } } \ No newline at end of file diff --git a/SGGL/FineUIPro.Web/HSSE/QualityAudit/GeneralEquipmentQuality.aspx.designer.cs b/SGGL/FineUIPro.Web/HSSE/QualityAudit/GeneralEquipmentQuality.aspx.designer.cs index ec16217b..fcba2593 100644 --- a/SGGL/FineUIPro.Web/HSSE/QualityAudit/GeneralEquipmentQuality.aspx.designer.cs +++ b/SGGL/FineUIPro.Web/HSSE/QualityAudit/GeneralEquipmentQuality.aspx.designer.cs @@ -7,11 +7,13 @@ // //------------------------------------------------------------------------------ -namespace FineUIPro.Web.HSSE.QualityAudit { - - - public partial class GeneralEquipmentQuality { - +namespace FineUIPro.Web.HSSE.QualityAudit +{ + + + public partial class GeneralEquipmentQuality + { + /// /// form1 控件。 /// @@ -20,7 +22,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::System.Web.UI.HtmlControls.HtmlForm form1; - + /// /// PageManager1 控件。 /// @@ -29,7 +31,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.PageManager PageManager1; - + /// /// Panel1 控件。 /// @@ -38,7 +40,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.Panel Panel1; - + /// /// Grid1 控件。 /// @@ -47,7 +49,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.Grid Grid1; - + /// /// Toolbar2 控件。 /// @@ -56,7 +58,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.Toolbar Toolbar2; - + /// /// txtGeneralEquipmentQualityCode 控件。 /// @@ -65,7 +67,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.TextBox txtGeneralEquipmentQualityCode; - + /// /// txtUnitName 控件。 /// @@ -74,7 +76,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.TextBox txtUnitName; - + /// /// txtSpecialEquipmentName 控件。 /// @@ -83,7 +85,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.TextBox txtSpecialEquipmentName; - + /// /// ToolbarFill1 控件。 /// @@ -92,7 +94,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.ToolbarFill ToolbarFill1; - + /// /// btnNew 控件。 /// @@ -101,7 +103,16 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.Button btnNew; - + + /// + /// btnQR 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::FineUIPro.Button btnQR; + /// /// btnOut 控件。 /// @@ -110,7 +121,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.Button btnOut; - + /// /// lblNumber 控件。 /// @@ -119,7 +130,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::System.Web.UI.WebControls.Label lblNumber; - + /// /// ToolbarSeparator1 控件。 /// @@ -128,7 +139,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.ToolbarSeparator ToolbarSeparator1; - + /// /// ToolbarText1 控件。 /// @@ -137,7 +148,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.ToolbarText ToolbarText1; - + /// /// ddlPageSize 控件。 /// @@ -146,7 +157,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.DropDownList ddlPageSize; - + /// /// Window1 控件。 /// @@ -155,7 +166,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.Window Window1; - + /// /// WindowAtt 控件。 /// @@ -164,7 +175,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.Window WindowAtt; - + /// /// Menu1 控件。 /// @@ -173,7 +184,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.Menu Menu1; - + /// /// btnMenuEdit 控件。 /// @@ -182,7 +193,7 @@ namespace FineUIPro.Web.HSSE.QualityAudit { /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 /// protected global::FineUIPro.MenuButton btnMenuEdit; - + /// /// btnMenuDelete 控件。 /// diff --git a/SGGL/Model/APIItem/HSSE/EquipmentQualityItem.cs b/SGGL/Model/APIItem/HSSE/EquipmentQualityItem.cs index 16689aae..8b1b84da 100644 --- a/SGGL/Model/APIItem/HSSE/EquipmentQualityItem.cs +++ b/SGGL/Model/APIItem/HSSE/EquipmentQualityItem.cs @@ -95,5 +95,13 @@ namespace Model /// 附件 /// public string AttachUrl { get; set; } + /// + /// 是否合格 + /// + public string IsQualified { get; set; } + /// + /// 数量 + /// + public string EquipmentCount { get; set; } } } diff --git a/SGGL/Model/Model.cs b/SGGL/Model/Model.cs index cf137fd9..8db11614 100644 --- a/SGGL/Model/Model.cs +++ b/SGGL/Model/Model.cs @@ -9179,6 +9179,14 @@ namespace Model } } + public System.Data.Linq.Table View_QualityAudit_GeneralEquipmentQuality + { + get + { + return this.GetTable(); + } + } + public System.Data.Linq.Table View_QualityAudit_PersonQuality { get @@ -393032,6 +393040,303 @@ namespace Model } } + [global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.View_QualityAudit_GeneralEquipmentQuality")] + public partial class View_QualityAudit_GeneralEquipmentQuality + { + + private string _GeneralEquipmentQualityId; + + private string _ProjectId; + + private string _GeneralEquipmentQualityCode; + + private string _UnitId; + + private string _UnitName; + + private string _SpecialEquipmentId; + + private string _SpecialEquipmentName; + + private System.Nullable _IsQualified; + + private System.Nullable _EquipmentCount; + + private System.Nullable _InDate; + + private string _Remark; + + private string _CompileMan; + + private string _CompileManName; + + private System.Nullable _CompileDate; + + private string _QRCodeAttachUrl; + + private string _AttachUrl; + + public View_QualityAudit_GeneralEquipmentQuality() + { + } + + [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_GeneralEquipmentQualityId", DbType="NVarChar(50) NOT NULL", CanBeNull=false)] + public string GeneralEquipmentQualityId + { + get + { + return this._GeneralEquipmentQualityId; + } + set + { + if ((this._GeneralEquipmentQualityId != value)) + { + this._GeneralEquipmentQualityId = value; + } + } + } + + [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ProjectId", DbType="NVarChar(50) NOT NULL", CanBeNull=false)] + public string ProjectId + { + get + { + return this._ProjectId; + } + set + { + if ((this._ProjectId != value)) + { + this._ProjectId = value; + } + } + } + + [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_GeneralEquipmentQualityCode", DbType="NVarChar(50) NOT NULL", CanBeNull=false)] + public string GeneralEquipmentQualityCode + { + get + { + return this._GeneralEquipmentQualityCode; + } + set + { + if ((this._GeneralEquipmentQualityCode != value)) + { + this._GeneralEquipmentQualityCode = value; + } + } + } + + [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_UnitId", DbType="NVarChar(50) NOT NULL", CanBeNull=false)] + public string UnitId + { + get + { + return this._UnitId; + } + set + { + if ((this._UnitId != value)) + { + this._UnitId = value; + } + } + } + + [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_UnitName", DbType="NVarChar(200)")] + public string UnitName + { + get + { + return this._UnitName; + } + set + { + if ((this._UnitName != value)) + { + this._UnitName = value; + } + } + } + + [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_SpecialEquipmentId", DbType="NVarChar(50) NOT NULL", CanBeNull=false)] + public string SpecialEquipmentId + { + get + { + return this._SpecialEquipmentId; + } + set + { + if ((this._SpecialEquipmentId != value)) + { + this._SpecialEquipmentId = value; + } + } + } + + [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_SpecialEquipmentName", DbType="NVarChar(50)")] + public string SpecialEquipmentName + { + get + { + return this._SpecialEquipmentName; + } + set + { + if ((this._SpecialEquipmentName != value)) + { + this._SpecialEquipmentName = value; + } + } + } + + [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_IsQualified", DbType="Bit")] + public System.Nullable IsQualified + { + get + { + return this._IsQualified; + } + set + { + if ((this._IsQualified != value)) + { + this._IsQualified = value; + } + } + } + + [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_EquipmentCount", DbType="Int")] + public System.Nullable EquipmentCount + { + get + { + return this._EquipmentCount; + } + set + { + if ((this._EquipmentCount != value)) + { + this._EquipmentCount = value; + } + } + } + + [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_InDate", DbType="DateTime")] + public System.Nullable InDate + { + get + { + return this._InDate; + } + set + { + if ((this._InDate != value)) + { + this._InDate = value; + } + } + } + + [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Remark", DbType="NVarChar(500)")] + public string Remark + { + get + { + return this._Remark; + } + set + { + if ((this._Remark != value)) + { + this._Remark = value; + } + } + } + + [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_CompileMan", DbType="NVarChar(50)")] + public string CompileMan + { + get + { + return this._CompileMan; + } + set + { + if ((this._CompileMan != value)) + { + this._CompileMan = value; + } + } + } + + [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_CompileManName", DbType="NVarChar(50)")] + public string CompileManName + { + get + { + return this._CompileManName; + } + set + { + if ((this._CompileManName != value)) + { + this._CompileManName = value; + } + } + } + + [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_CompileDate", DbType="DateTime")] + public System.Nullable CompileDate + { + get + { + return this._CompileDate; + } + set + { + if ((this._CompileDate != value)) + { + this._CompileDate = value; + } + } + } + + [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_QRCodeAttachUrl", DbType="NVarChar(200)")] + public string QRCodeAttachUrl + { + get + { + return this._QRCodeAttachUrl; + } + set + { + if ((this._QRCodeAttachUrl != value)) + { + this._QRCodeAttachUrl = value; + } + } + } + + [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_AttachUrl", DbType="NVarChar(MAX)", UpdateCheck=UpdateCheck.Never)] + public string AttachUrl + { + get + { + return this._AttachUrl; + } + set + { + if ((this._AttachUrl != value)) + { + this._AttachUrl = value; + } + } + } + } + [global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.View_QualityAudit_PersonQuality")] public partial class View_QualityAudit_PersonQuality { diff --git a/SGGL/WebAPI/Controllers/HSSE/GeneralEquipmentQualityController.cs b/SGGL/WebAPI/Controllers/HSSE/GeneralEquipmentQualityController.cs new file mode 100644 index 00000000..30335139 --- /dev/null +++ b/SGGL/WebAPI/Controllers/HSSE/GeneralEquipmentQualityController.cs @@ -0,0 +1,160 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Web.Http; +using BLL; + +namespace WebAPI.Controllers +{ + /// + /// 一般机具设备资质 + /// + public class GeneralEquipmentQualityController : ApiController + { + #region 根据equipmentQualityId获取机具设备资质信息 + /// + /// 根据equipmentQualityId获取机具设备资质信息 + /// + /// + /// + public Model.ResponeData getEquipmentQualityByEquipmentQualityId(string equipmentQualityId) + { + var responeData = new Model.ResponeData(); + try + { + responeData.data = APIGeneralEquipmentQualityService.getEquipmentQualityByEquipmentQualityIdFactoryCode(equipmentQualityId); + } + catch (Exception ex) + { + responeData.code = 0; + responeData.message = ex.Message; + } + + return responeData; + } + #endregion + + + + #region 根据projectId、unitid获取机具设备资质信息 + /// + /// 根据projectId、unitid获取机具设备资质信息 + /// + /// + /// + /// + /// + public Model.ResponeData getEquipmentQualityByProjectIdUnitId(string projectId, string unitId, int pageIndex) + { + var responeData = new Model.ResponeData(); + try + { + var getDataList = APIGeneralEquipmentQualityService.getEquipmentQualityList(projectId, unitId, null); + int pageCount = getDataList.Count(); + if (pageCount > 0 && pageIndex > 0) + { + getDataList = getDataList.Skip(Funs.PageSize * (pageIndex - 1)).Take(Funs.PageSize).ToList(); + } + responeData.data = new { pageCount, getDataList }; + } + catch (Exception ex) + { + responeData.code = 0; + responeData.message = ex.Message; + } + return responeData; + } + #endregion + + #region 根据projectId、unitid获取机具设备资质信息-查询 + /// + /// 根据projectId、unitid获取机具设备资质信息 + /// + /// + /// + /// + /// 查询条件 + /// + public Model.ResponeData getEquipmentQualityByProjectIdUnitIdQuery(string projectId, string unitId, string strParam, int pageIndex) + { + var responeData = new Model.ResponeData(); + try + { + var getDataList = APIGeneralEquipmentQualityService.getEquipmentQualityList(projectId, unitId, strParam); + int pageCount = getDataList.Count(); + if (pageCount > 0 && pageIndex > 0) + { + getDataList = getDataList.Skip(Funs.PageSize * (pageIndex - 1)).Take(Funs.PageSize).ToList(); + } + responeData.data = new { pageCount, getDataList }; + } + catch (Exception ex) + { + responeData.code = 0; + responeData.message = ex.Message; + } + return responeData; + } + #endregion + + #region 根据projectId、unitid获取特岗机具设备资质资质各状态数 + /// + /// 根据projectId、unitid获取特岗机具设备资质资质各状态数 + /// + /// + /// + /// + public Model.ResponeData getEquipmentQualityCount(string projectId, string unitId) + { + var responeData = new Model.ResponeData(); + try + { + var getDataList = new Model.SGGLDB(Funs.ConnString).QualityAudit_GeneralEquipmentQuality.Where(x => x.ProjectId == projectId); + if (ProjectUnitService.GetProjectUnitTypeByProjectIdUnitId(projectId, unitId)) + { + getDataList = getDataList.Where(x => x.UnitId == unitId); + } + ////总数 + int tatalCount = getDataList.Count(); + + responeData.data = new { tatalCount }; + } + catch (Exception ex) + { + responeData.code = 0; + responeData.message = ex.Message; + } + + return responeData; + } + #endregion + + + + #region 保存QualityAudit_EquipmentQuality + /// + /// 保存QualityAudit_EquipmentQuality + /// + /// 机具设备资质 + /// + [HttpPost] + public Model.ResponeData SaveEquipmentQuality([FromBody] Model.EquipmentQualityItem newitem) + { + var responeData = new Model.ResponeData(); + try + { + APIGeneralEquipmentQualityService.SaveEquipmentQuality(newitem); + } + catch (Exception ex) + { + responeData.code = 0; + responeData.message = ex.Message; + } + + return responeData; + } + #endregion + } +} diff --git a/SGGL/WebAPI/WebAPI.csproj b/SGGL/WebAPI/WebAPI.csproj index 43dc784e..47f019c7 100644 --- a/SGGL/WebAPI/WebAPI.csproj +++ b/SGGL/WebAPI/WebAPI.csproj @@ -153,6 +153,7 @@ +