This commit is contained in:
2025-05-16 17:54:16 +08:00
parent 1d2aee2c7c
commit 1773ec1dde
24 changed files with 1025 additions and 475 deletions
@@ -1,6 +1,7 @@
using Aspose.Words;
using Aspose.Words.Tables;
using BLL;
using FineUIPro.Web.BaseInfo;
using System;
using System.Collections.Generic;
using System.Data;
@@ -9,6 +10,7 @@ using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ListView;
namespace FineUIPro.Web.CQMS.ProcessControl
{
@@ -47,113 +49,149 @@ namespace FineUIPro.Web.CQMS.ProcessControl
/// </summary>
public void BindGrid()
{
if (this.CurrUser.UserId==BLL.Const.hfnbdId)
{
DataTable tb = BindData();
Grid1.RecordCount = tb.Rows.Count;
//tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
//if (this.CurrUser.UserId == BLL.Const.hfnbdId)
//{
// string strSql = @"SELECT P.InspectionId,P.ProjectId,P.UnitId,
// P.CNProfessionalId,
// P.UnitWorkId,U.UnitName,
// C.DetectionItems as ProfessionalName,
// P.NoticeCode,UnitWork.UnitWorkName,
// DP.DivisionName AS Branch,
// BP.BreakdownName AS ControlPointType,
// BP.Class,P.AcceptanceSite, P.AcceptanceCheckMan"
// + @" FROM ProcessControl_InspectionManagement AS P"
// + @" LEFT JOIN Base_Unit AS U ON U.UnitId = P.UnitId"
// + @" LEFT JOIN Control_PointCropping C ON C.ControlId = P.CNProfessionalId"
// + @" LEFT JOIN WBS_UnitWork AS UnitWork ON UnitWork.UnitWorkId = P.UnitWorkId"
// + @" LEFT JOIN WBS_DivisionProject AS DP ON DP.DivisionProjectId = P.Branch"
// + @" LEFT JOIN WBS_BreakdownProject AS BP ON BP.BreakdownProjectId = P.ControlPointType"
// + @" WHERE P.ProjectId=@ProjectId ";
// List<SqlParameter> listStr = new List<SqlParameter>();
// listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
// if (drpUnit.SelectedValue != BLL.Const._Null)
// {
// strSql += " AND P.UnitId=@UnitId";
// listStr.Add(new SqlParameter("@UnitId", drpUnit.SelectedValue));
// }
// if (drpCNProfessional.SelectedValue != BLL.Const._Null)
// {
// strSql += " AND P.CNProfessionalId=@CNProfessionalId";
// listStr.Add(new SqlParameter("@CNProfessionalId", drpCNProfessional.SelectedValue));
// }
// if (!string.IsNullOrEmpty(txtStarTime.Text.Trim()))
// {
// strSql += " AND P.InspectionDate >= @startTime";
// listStr.Add(new SqlParameter("@startTime", Funs.GetNewDateTime(txtStarTime.Text.Trim())));
// }
// if (!string.IsNullOrEmpty(txtEndTime.Text.Trim()))
// {
// strSql += " AND P.InspectionDate <= @endTime";
// listStr.Add(new SqlParameter("@endTime", Funs.GetNewDateTime(txtEndTime.Text.Trim())));
// }
// SqlParameter[] parameter = listStr.ToArray();
// DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
// Grid1.RecordCount = tb.Rows.Count;
// //tb = GetFilteredTable(Grid1.FilteredData, tb);
// var table = this.GetPagedDataTable(Grid1, tb);
// Grid1.DataSource = table;
// Grid1.DataBind();
//}
//else
//{
// string strSql = @"SELECT P.InspectionId,P.ProjectId,P.UnitId,
// P.CNProfessionalId,
// P.UnitWorkId,U.UnitName,
// C.ProfessionalName as ProfessionalName,
// P.NoticeCode,UnitWork.UnitWorkName,
// DP.DivisionName AS Branch,
// BP.BreakdownName AS ControlPointType,
// BP.Class,P.AcceptanceSite,P.AcceptanceCheckMan"
// + @" FROM ProcessControl_InspectionManagement AS P"
// + @" LEFT JOIN Base_Unit AS U ON U.UnitId = P.UnitId"
// + @" left join Base_CNProfessional c on c.CNProfessionalId = P.CNProfessionalId"
// + @" LEFT JOIN WBS_UnitWork AS UnitWork ON UnitWork.UnitWorkId = P.UnitWorkId"
// + @" LEFT JOIN WBS_DivisionProject AS DP ON DP.DivisionProjectId = P.Branch"
// + @" LEFT JOIN WBS_BreakdownProject AS BP ON BP.BreakdownProjectId = P.ControlPointType"
// + @" WHERE P.ProjectId=@ProjectId ";
// List<SqlParameter> listStr = new List<SqlParameter>();
// listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
// if (drpUnit.SelectedValue != BLL.Const._Null)
// {
// strSql += " AND P.UnitId=@UnitId";
// listStr.Add(new SqlParameter("@UnitId", drpUnit.SelectedValue));
// }
// if (drpCNProfessional.SelectedValue != BLL.Const._Null)
// {
// strSql += " AND P.CNProfessionalId=@CNProfessionalId";
// listStr.Add(new SqlParameter("@CNProfessionalId", drpCNProfessional.SelectedValue));
// }
// if (!string.IsNullOrEmpty(txtStarTime.Text.Trim()))
// {
// strSql += " AND P.InspectionDate >= @startTime";
// listStr.Add(new SqlParameter("@startTime", Funs.GetNewDateTime(txtStarTime.Text.Trim())));
// }
// if (!string.IsNullOrEmpty(txtEndTime.Text.Trim()))
// {
// strSql += " AND P.InspectionDate <= @endTime";
// listStr.Add(new SqlParameter("@endTime", Funs.GetNewDateTime(txtEndTime.Text.Trim())));
// }
// SqlParameter[] parameter = listStr.ToArray();
// DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
// Grid1.RecordCount = tb.Rows.Count;
// //tb = GetFilteredTable(Grid1.FilteredData, tb);
// var table = this.GetPagedDataTable(Grid1, tb);
// Grid1.DataSource = table;
// Grid1.DataBind();
//}
}
string strSql = @"SELECT P.InspectionId,
P.ProjectId,
P.UnitId,
P.CNProfessionalId,
P.UnitWorkId,
U.UnitName,
C.DetectionItems as ProfessionalName,
P.NoticeCode,
UnitWork.UnitWorkName,
DP.DivisionName AS Branch,
BP.BreakdownName AS ControlPointType,
BP.Class,
P.AcceptanceSite,
P.AcceptanceCheckMan"
+ @" FROM ProcessControl_InspectionManagement AS P"
+ @" LEFT JOIN Base_Unit AS U ON U.UnitId = P.UnitId"
+ @" LEFT JOIN Control_PointCropping C ON C.ControlId = P.CNProfessionalId"
+ @" LEFT JOIN WBS_UnitWork AS UnitWork ON UnitWork.UnitWorkId = P.UnitWorkId"
+ @" LEFT JOIN WBS_DivisionProject AS DP ON DP.DivisionProjectId = P.Branch"
+ @" LEFT JOIN WBS_BreakdownProject AS BP ON BP.BreakdownProjectId = P.ControlPointType"
+ @" WHERE P.ProjectId=@ProjectId ";
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
if (drpUnit.SelectedValue != BLL.Const._Null)
{
strSql += " AND P.UnitId=@UnitId";
listStr.Add(new SqlParameter("@UnitId", drpUnit.SelectedValue));
}
if (drpCNProfessional.SelectedValue != BLL.Const._Null)
{
strSql += " AND P.CNProfessionalId=@CNProfessionalId";
listStr.Add(new SqlParameter("@CNProfessionalId", drpCNProfessional.SelectedValue));
}
if (!string.IsNullOrEmpty(txtStarTime.Text.Trim()))
{
strSql += " AND P.InspectionDate >= @startTime";
listStr.Add(new SqlParameter("@startTime", Funs.GetNewDateTime(txtStarTime.Text.Trim())));
}
if (!string.IsNullOrEmpty(txtEndTime.Text.Trim()))
{
strSql += " AND P.InspectionDate <= @endTime";
listStr.Add(new SqlParameter("@endTime", Funs.GetNewDateTime(txtEndTime.Text.Trim())));
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
Grid1.RecordCount = tb.Rows.Count;
//tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
else
/// <summary>
/// 查询数据
/// </summary>
/// <returns></returns>
public DataTable BindData()
{
StringBuilder sb = new StringBuilder();
sb.Append("SELECT P.InspectionId,P.ProjectId,P.UnitId,P.CNProfessionalId,P.UnitWorkId,U.UnitName,C.ProfessionalName as ProfessionalName,P.NoticeCode,UnitWork.UnitWorkName,DP.DivisionName AS Branch,BP.BreakdownName AS ControlPointType,BP.Class,P.AcceptanceSite,P.AcceptanceCheckMan ");
sb.Append("FROM ProcessControl_InspectionManagement AS P ");
sb.Append("LEFT JOIN Base_Unit AS U ON U.UnitId = P.UnitId ");
sb.Append("LEFT JOIN Base_CNProfessional AS C on c.CNProfessionalId = P.CNProfessionalId ");
sb.Append("LEFT JOIN WBS_UnitWork AS UnitWork ON UnitWork.UnitWorkId = P.UnitWorkId ");
sb.Append("LEFT JOIN WBS_DivisionProject AS DP ON DP.DivisionProjectId = P.Branch ");
sb.Append("LEFT JOIN WBS_BreakdownProject AS BP ON BP.BreakdownProjectId = P.ControlPointType ");
sb.Append("WHERE P.ProjectId=@ProjectId ");
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
if (drpUnit.SelectedValue != BLL.Const._Null)
{
string strSql = @"SELECT P.InspectionId,
P.ProjectId,
P.UnitId,
P.CNProfessionalId,
P.UnitWorkId,
U.UnitName,
C.ProfessionalName as ProfessionalName,
P.NoticeCode,
UnitWork.UnitWorkName,
DP.DivisionName AS Branch,
BP.BreakdownName AS ControlPointType,
BP.Class,
P.AcceptanceSite,
P.AcceptanceCheckMan"
+ @" FROM ProcessControl_InspectionManagement AS P"
+ @" LEFT JOIN Base_Unit AS U ON U.UnitId = P.UnitId"
+ @" left join Base_CNProfessional c on c.CNProfessionalId = P.CNProfessionalId"
+ @" LEFT JOIN WBS_UnitWork AS UnitWork ON UnitWork.UnitWorkId = P.UnitWorkId"
+ @" LEFT JOIN WBS_DivisionProject AS DP ON DP.DivisionProjectId = P.Branch"
+ @" LEFT JOIN WBS_BreakdownProject AS BP ON BP.BreakdownProjectId = P.ControlPointType"
+ @" WHERE P.ProjectId=@ProjectId ";
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
if (drpUnit.SelectedValue != BLL.Const._Null)
{
strSql += " AND P.UnitId=@UnitId";
listStr.Add(new SqlParameter("@UnitId", drpUnit.SelectedValue));
}
if (drpCNProfessional.SelectedValue != BLL.Const._Null)
{
strSql += " AND P.CNProfessionalId=@CNProfessionalId";
listStr.Add(new SqlParameter("@CNProfessionalId", drpCNProfessional.SelectedValue));
}
if (!string.IsNullOrEmpty(txtStarTime.Text.Trim()))
{
strSql += " AND P.InspectionDate >= @startTime";
listStr.Add(new SqlParameter("@startTime", Funs.GetNewDateTime(txtStarTime.Text.Trim())));
}
if (!string.IsNullOrEmpty(txtEndTime.Text.Trim()))
{
strSql += " AND P.InspectionDate <= @endTime";
listStr.Add(new SqlParameter("@endTime", Funs.GetNewDateTime(txtEndTime.Text.Trim())));
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
Grid1.RecordCount = tb.Rows.Count;
//tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
sb.Append("AND P.UnitId=@UnitId ");
listStr.Add(new SqlParameter("@UnitId", drpUnit.SelectedValue));
}
if (drpCNProfessional.SelectedValue != BLL.Const._Null)
{
sb.Append("AND P.CNProfessionalId=@CNProfessionalId ");
listStr.Add(new SqlParameter("@CNProfessionalId", drpCNProfessional.SelectedValue));
}
if (!string.IsNullOrEmpty(txtStarTime.Text.Trim()))
{
sb.Append("AND P.InspectionDate >= @startTime ");
listStr.Add(new SqlParameter("@startTime", Funs.GetNewDateTime(txtStarTime.Text.Trim())));
}
if (!string.IsNullOrEmpty(txtEndTime.Text.Trim()))
{
sb.Append("AND P.InspectionDate <= @endTime ");
listStr.Add(new SqlParameter("@endTime", Funs.GetNewDateTime(txtEndTime.Text.Trim())));
}
sb.Append("ORDER BY P.NoticeCode DESC ");
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(sb.ToString(), parameter);
return tb;
}
#endregion
@@ -342,6 +380,142 @@ namespace FineUIPro.Web.CQMS.ProcessControl
string newUrl = string.Empty;
uploadfilepath = rootPath + initTemplatePath;
var db = Funs.DB;
var lists = (from x in db.ProcessControl_InspectionManagement
join bu in db.Base_Unit on x.UnitId equals bu.UnitId into buGroup
from bu in buGroup.DefaultIfEmpty()
join bcn in db.Base_CNProfessional on x.CNProfessionalId equals bcn.CNProfessionalId into bcnGroup
from bcn in bcnGroup.DefaultIfEmpty()
//join wbsuw in db.WBS_UnitWork on x.UnitWorkId equals wbsuw.UnitWorkId into wbsuwGroup
//from wbsuw in wbsuwGroup.DefaultIfEmpty()
//join wbsd in db.WBS_DivisionProject on x.Branch equals wbsd.DivisionProjectId into wbsdGroup
//from wbsd in wbsdGroup.DefaultIfEmpty()
//join wbsbp in db.WBS_BreakdownProject on x.ControlPointType equals wbsbp.BreakdownProjectId into wbsbpGroup
//from wbsbp in wbsbpGroup.DefaultIfEmpty()
where x.ProjectId == this.CurrUser.LoginProjectId
orderby x.NoticeCode descending
select new
{
UnitId = x.UnitId,
UnitName = bu.UnitName,
CNProfessionalId = x.CNProfessionalId,
ProfessionalName = bcn.ProfessionalName,
NoticeCode = x.NoticeCode,
AcceptanceSite = x.AcceptanceSite,
AcceptanceCheckMan = x.AcceptanceCheckMan,
InspectionDate = x.InspectionDate
});
if (drpUnit.SelectedValue != BLL.Const._Null)
{
lists = lists.Where(x => x.UnitId == drpUnit.SelectedValue);
}
if (drpCNProfessional.SelectedValue != BLL.Const._Null)
{
lists = lists.Where(x => x.CNProfessionalId == drpCNProfessional.SelectedValue);
}
if (!string.IsNullOrEmpty(txtStarTime.Text.Trim()))
{
lists = lists.Where(x => x.InspectionDate >= Funs.GetNewDateTime(txtStarTime.Text.Trim()));
}
if (!string.IsNullOrEmpty(txtEndTime.Text.Trim()))
{
lists = lists.Where(x => x.InspectionDate <= Funs.GetNewDateTime(txtEndTime.Text.Trim()));
}
if (lists != null)
{
string projectName = BLL.ProjectService.GetShortNameByProjectId(this.CurrUser.LoginProjectId);
newUrl = uploadfilepath.Replace("共检通知单模板", "共检通知单(" + projectName + DateTime.Now.ToString("yyyyMMdd") + "");
if (File.Exists(newUrl))
{
File.Delete(newUrl);
}
File.Copy(uploadfilepath, newUrl);
// 第一步:读取文件流
NPOI.SS.UserModel.IWorkbook workbook;
using (FileStream stream = new FileStream(newUrl, FileMode.Open, FileAccess.Read))
{
//workbook = new NPOI.XSSF.UserModel.XSSFWorkbook(stream);
workbook = new NPOI.HSSF.UserModel.HSSFWorkbook(stream);
}
// 创建单元格样式
NPOI.SS.UserModel.ICellStyle cellStyle = workbook.CreateCellStyle();
cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
cellStyle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
cellStyle.WrapText = true;//自动换行
var font = workbook.CreateFont();
font.FontHeightInPoints = 11;
cellStyle.SetFont(font);
// 第二步:创建新数据行
NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(0);
NPOI.SS.UserModel.IRow row = sheet.GetRow(0);
NPOI.SS.UserModel.ICell cell;
int i = 2;
foreach (var item in lists)
{
// 第二步:创建新数据行
row = sheet.CreateRow(i);
// 添加数据
cell = row.CreateCell(0);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.UnitName);//施工分包商
cell = row.CreateCell(1);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.ProfessionalName);//专业
cell = row.CreateCell(2);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.NoticeCode);//共检通知单编号
cell = row.CreateCell(3);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.AcceptanceSite);//验收部位
cell = row.CreateCell(4);
cell.CellStyle = cellStyle;
string userName = string.Empty;
if (!string.IsNullOrEmpty(item.AcceptanceCheckMan))
{
userName = ConvertCheckMan(item.AcceptanceCheckMan);
}
cell.SetCellValue(userName);//检查人
i++;
}
// 第三步:写入文件流
using (FileStream stream = new FileStream(newUrl, FileMode.Create, FileAccess.Write))
{
workbook.Write(stream);
workbook.Close();
}
string fileName = Path.GetFileName(newUrl);
FileInfo info = new FileInfo(newUrl);
long fileSize = info.Length;
Response.Clear();
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(newUrl, 0, fileSize);
Response.Flush();
Response.Close();
File.Delete(newUrl);
}
else
{
Alert.ShowInTop("当前无记录,无法导出!", MessageBoxIcon.Warning);
}
}
protected void btnOut_Click2(object sender, EventArgs e)
{
string rootPath = Server.MapPath("~/");
string initTemplatePath = Const.InspectionNoticesTempUrl;
string uploadfilepath = string.Empty;
string newUrl = string.Empty;
uploadfilepath = rootPath + initTemplatePath;
var lists = (from x in Funs.DB.ProcessControl_InspectionManagementDetail
join y in Funs.DB.ProcessControl_InspectionManagement
on x.InspectionId equals y.InspectionId
@@ -1082,7 +1256,7 @@ namespace FineUIPro.Web.CQMS.ProcessControl
newInspection.UnqualifiedReason = inspection.UnqualifiedReason;
//通知单编号后有字母递增,无则加“a”
string fisrtE = inspection.NoticeCode.Substring(0,inspection.NoticeCode.Length - 1);
string fisrtE = inspection.NoticeCode.Substring(0, inspection.NoticeCode.Length - 1);
string lastE = inspection.NoticeCode.Substring(inspection.NoticeCode.Length - 1, 1);
bool b = Regex.IsMatch(lastE, "[a-zA-Z]");
if (b)
@@ -1093,7 +1267,7 @@ namespace FineUIPro.Web.CQMS.ProcessControl
else
{
newInspection.NoticeCode = inspection.NoticeCode + "a";
}
}
newInspection.AcceptanceCheckMan = inspection.AcceptanceCheckMan;
newInspection.ParentDivisionProjectId = inspection.ParentDivisionProjectId;