提交代码

This commit is contained in:
2025-03-05 16:48:17 +08:00
parent 64ee6e8635
commit 58beeab458
59 changed files with 4829 additions and 532 deletions
@@ -1,8 +1,10 @@
using BLL;
using NPOI.SS.Util;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Web.UI.WebControls;
@@ -20,6 +22,14 @@ namespace FineUIPro.Web.CQMS.QuantityManagement
{
if (!IsPostBack)
{
this.txtMonths.Text = string.Format("{0:yyyy-MM}", DateTime.Now);
ProjectService.InitAllProjectDropDownList(this.drpProject, false);
if (!string.IsNullOrEmpty(this.CurrUser.LoginProjectId))
{
this.drpProject.SelectedValue = this.CurrUser.LoginProjectId;
this.drpProject.Enabled = false;
this.drpProject.Hidden = true;
}
GetButtonPower();
BindGrid();
}
@@ -30,24 +40,15 @@ namespace FineUIPro.Web.CQMS.QuantityManagement
/// </summary>
public void BindGrid()
{
string strSql = @"select BaseId,C.ProjectId,a.WorkSection,DrawingNo,DrawingName,Part,ProjectContent,Unit,Amount,WorkTeam,
isnull((select sum(DayAmount) from QuantityManagement_DayInput d where d.BaseId=C.BaseId),0) as TotalComplete,
Amount-isnull((select sum(DayAmount) from QuantityManagement_DayInput d where d.BaseId=C.BaseId),0) as Remain
from QuantityManagement_Base C
left join QuantityManagement_Drawing a on a.DrawingId=C.DrawingId
string strSql = @"select * from View_QuantityManagement_WorkTeamStatistics C
where C.ProjectId = @ProjectId";
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
listStr.Add(new SqlParameter("@ProjectId", this.drpProject.SelectedValue));
if (!string.IsNullOrEmpty(this.txtWorkSection.Text.Trim()))
{
strSql += " AND WorkSection like @WorkSection";
listStr.Add(new SqlParameter("@WorkSection", "%" + this.txtWorkSection.Text.Trim() + "%"));
}
if (!string.IsNullOrEmpty(this.txtDrawingNo.Text.Trim()))
{
strSql += " AND DrawingNo like @DrawingNo";
listStr.Add(new SqlParameter("@DrawingNo", "%" + this.txtDrawingNo.Text.Trim() + "%"));
}
if (!string.IsNullOrEmpty(this.txtWorkTeam.Text.Trim()))
{
strSql += " AND WorkTeam like @WorkTeam";
@@ -62,28 +63,37 @@ namespace FineUIPro.Web.CQMS.QuantityManagement
//绑定数据
DateTime startDate, endDate, startDate1, endDate1;
List<DateTime> days = new List<DateTime>();
int year = DateTime.Now.Year;
int month = DateTime.Now.Month;
DateTime now = Convert.ToDateTime(txtMonths.Text + "-01");
int year = now.Year;
int month = now.Month;
int day = DateTime.Now.Day;
if (day >= 26)
{
startDate = Convert.ToDateTime(DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + "26");
DateTime lastMonth = now.AddMonths(-1);
startDate = Convert.ToDateTime(lastMonth.Year.ToString() + "-" + lastMonth.Month.ToString() + "-" + "26");
endDate = now.AddDays(24);
startDate1 = startDate;
endDate = DateTime.Now;
endDate1 = endDate;
}
else
{
DateTime lastMonth = DateTime.Now.AddMonths(-1);
DateTime lastMonth = now.AddMonths(-1);
startDate = Convert.ToDateTime(lastMonth.Year.ToString() + "-" + lastMonth.Month.ToString() + "-" + "26");
startDate1 = startDate;
endDate = DateTime.Now;
startDate1 = startDate;
endDate1 = endDate;
}
var dayInputs = from x in Funs.DB.QuantityManagement_DayInput
where x.ProjectId == this.CurrUser.LoginProjectId && x.Date >= startDate && x.Date <= endDate
var totalDayInputs = from x in Funs.DB.View_QuantityManagement_DayInput2
where x.ProjectId == this.drpProject.SelectedValue && x.Date <= endDate
orderby x.Date
select x;
var dayInputs = from x in Funs.DB.View_QuantityManagement_DayInput2
where x.ProjectId == this.drpProject.SelectedValue && x.Date >= startDate && x.Date <= endDate
orderby x.Date
select x;
var bases = from x in Funs.DB.View_QuantityManagement_Base
where x.ProjectId == this.drpProject.SelectedValue
select x;
do
{
days.Add(startDate1);
@@ -91,19 +101,22 @@ namespace FineUIPro.Web.CQMS.QuantityManagement
} while (startDate1 <= endDate1);
for (int i = 0; i < this.Grid1.Rows.Count; i++)
{
string baseId = this.Grid1.Rows[i].RowID;
int j = 0;
decimal monthComplete = 0;
string[] strs = this.Grid1.Rows[i].RowID.Split(',');
string workSection = strs[1];
string projectContent = strs[2];
string workTeam = strs[3];
decimal totalAmount = 0, completedAmount = 0, totalCompletedAmount = 0, monthComplete = 0;
totalAmount = bases.Where(x => x.WorkSection == workSection && x.ProjectContent == projectContent).ToList().Sum(x => x.Amount ?? 0);
foreach (var d in days)
{
var dayInput = dayInputs.FirstOrDefault(x => x.BaseId == baseId && x.Date == d);
if (dayInput != null)
{
monthComplete += dayInput.DayAmount.Value;
}
j++;
monthComplete = dayInputs.Where(x => x.WorkSection == workSection && x.ProjectContent == projectContent && x.WorkTeam == workTeam).ToList().Sum(x => x.DayAmount ?? 0);
}
this.Grid1.Rows[i].Values[11] = monthComplete.ToString("0.##");
completedAmount= totalDayInputs.Where(x => x.WorkSection == workSection && x.ProjectContent == projectContent && x.WorkTeam == workTeam).ToList().Sum(x => x.DayAmount ?? 0);
totalCompletedAmount = totalDayInputs.Where(x => x.WorkSection == workSection && x.ProjectContent == projectContent).ToList().Sum(x => x.DayAmount ?? 0);
this.Grid1.Rows[i].Values[4] = totalAmount.ToString("0.##");
this.Grid1.Rows[i].Values[6] = completedAmount.ToString("0.##");
this.Grid1.Rows[i].Values[7] = (totalAmount - totalCompletedAmount).ToString("0.##");
this.Grid1.Rows[i].Values[8] = monthComplete.ToString("0.##");
}
}
#endregion
@@ -189,5 +202,158 @@ namespace FineUIPro.Web.CQMS.QuantityManagement
}
}
#endregion
#region
/// 导出按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnOut_Click(object sender, EventArgs e)
{
string rootPath = Server.MapPath("~/");
string initTemplatePath = string.Empty;
string uploadfilepath = string.Empty;
string newUrl = string.Empty;
string filePath = string.Empty;
initTemplatePath = Const.WorkTeamStatisticsTemplateUrl;
uploadfilepath = rootPath + initTemplatePath;
if (this.Grid1.Rows.Count > 0)
{
newUrl = uploadfilepath.Replace(".xlsx", "(" + this.txtMonths.Text.Trim() + ")" + ".xlsx");
File.Copy(uploadfilepath, newUrl);
DateTime startDate, endDate;
List<DateTime> days = new List<DateTime>();
DateTime now = Convert.ToDateTime(txtMonths.Text + "-01");
int year = now.Year;
int month = now.Month;
int day = DateTime.Now.Day;
if (day >= 26)
{
DateTime lastMonth = now.AddMonths(-1);
startDate = Convert.ToDateTime(lastMonth.Year.ToString() + "-" + lastMonth.Month.ToString() + "-" + "26");
endDate = now.AddDays(24);
}
else
{
DateTime lastMonth = now.AddMonths(-1);
startDate = Convert.ToDateTime(lastMonth.Year.ToString() + "-" + lastMonth.Month.ToString() + "-" + "26");
endDate = DateTime.Now;
}
do
{
days.Add(startDate);
startDate = startDate.AddDays(1);
} while (startDate <= endDate);
// 第一步:读取文件流
NPOI.SS.UserModel.IWorkbook workbook;
using (FileStream stream = new FileStream(newUrl, FileMode.Open, FileAccess.Read))
{
workbook = new NPOI.XSSF.UserModel.XSSFWorkbook(stream);
}
// 创建单元格样式
NPOI.SS.UserModel.ICellStyle cellStyle0 = workbook.CreateCellStyle();
cellStyle0.BorderTop = NPOI.SS.UserModel.BorderStyle.None;
cellStyle0.BorderRight = NPOI.SS.UserModel.BorderStyle.None;
cellStyle0.BorderBottom = NPOI.SS.UserModel.BorderStyle.None;
cellStyle0.BorderLeft = NPOI.SS.UserModel.BorderStyle.None;
cellStyle0.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
cellStyle0.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
var font = workbook.CreateFont();
font.FontHeightInPoints = 12;
font.IsBold = true;
//font.FontHeightInPoints = (short)8.5;字号为小数时要转为short
cellStyle0.SetFont(font);
// 第二步:创建新数据行
NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(0);
var font2 = workbook.CreateFont();
font2.FontHeightInPoints = 10;
// 创建单元格样式
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;
cellStyle.SetFont(font2);
// 创建单元格样式
NPOI.SS.UserModel.ICellStyle cellStyleYellow = workbook.CreateCellStyle();
cellStyleYellow.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyleYellow.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyleYellow.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyleYellow.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyleYellow.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
cellStyleYellow.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
//NPOI.SS.UserModel.IRow row5 = sheet.GetRow(5);
//NPOI.SS.UserModel.ICell cell5;
//cell5 = row5.GetCell(4);
cellStyleYellow.FillBackgroundColor = 120;
cellStyleYellow.SetFont(font2);
int r = 1;
NPOI.SS.UserModel.IRow row;
NPOI.SS.UserModel.ICell cell;
for (int i = 0; i < Grid1.Rows.Count; i++)
{
row = sheet.CreateRow(r + i);
cell = row.CreateCell(0);
cell.CellStyle = cellStyle;
cell.SetCellValue((i + 1).ToString());
cell = row.CreateCell(1);
cell.CellStyle = cellStyle;
cell.SetCellValue(Grid1.Rows[i].Values[1].ToString());
cell = row.CreateCell(2);
cell.CellStyle = cellStyle;
cell.SetCellValue(Grid1.Rows[i].Values[2].ToString());
cell = row.CreateCell(3);
cell.CellStyle = cellStyle;
cell.SetCellValue(Grid1.Rows[i].Values[3].ToString());
cell = row.CreateCell(4);
cell.CellStyle = cellStyle;
cell.SetCellValue(Grid1.Rows[i].Values[4].ToString());
cell = row.CreateCell(5);
cell.CellStyle = cellStyle;
cell.SetCellValue(Grid1.Rows[i].Values[5].ToString());
cell = row.CreateCell(6);
cell.CellStyle = cellStyle;
cell.SetCellValue(Grid1.Rows[i].Values[6].ToString());
cell = row.CreateCell(7);
cell.CellStyle = cellStyle;
cell.SetCellValue(Grid1.Rows[i].Values[7].ToString());
cell = row.CreateCell(8);
cell.CellStyle = cellStyle;
cell.SetCellValue(Grid1.Rows[i].Values[8].ToString());
}
// 第三步:写入文件流
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);
}
}
#endregion
}
}