422 lines
17 KiB
C#
422 lines
17 KiB
C#
|
using BLL;
|
|||
|
using FineUIPro.Web.Controls;
|
|||
|
using MiniExcelLibs;
|
|||
|
using MiniExcelLibs.OpenXml;
|
|||
|
using Model;
|
|||
|
using Newtonsoft.Json.Linq;
|
|||
|
using System;
|
|||
|
using System.Collections.Concurrent;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Data;
|
|||
|
using System.IO;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Text.RegularExpressions;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using System.Web;
|
|||
|
using System.Web.UI;
|
|||
|
using System.Web.UI.WebControls;
|
|||
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ListView;
|
|||
|
|
|||
|
namespace FineUIPro.Web.Door
|
|||
|
{
|
|||
|
public partial class InOutRecordStatisticsGrid : PageBase
|
|||
|
{
|
|||
|
public string ProjectId
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return (string)ViewState["ProjectId"];
|
|||
|
}
|
|||
|
set
|
|||
|
{
|
|||
|
ViewState["ProjectId"] = value;
|
|||
|
}
|
|||
|
}
|
|||
|
public InOutRecordStatisticInput InOutRecordStatisticInput
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return (InOutRecordStatisticInput)Session["InOutRecordStatisticInput"];
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private static List<Model.View_SitePerson_Person> getDataLists = new List<View_SitePerson_Person>();
|
|||
|
|
|||
|
public DataTable GridTable
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return (DataTable)ViewState["GridTable"];
|
|||
|
|
|||
|
}
|
|||
|
set
|
|||
|
{
|
|||
|
ViewState["GridTable"] = value;
|
|||
|
}
|
|||
|
}
|
|||
|
public DataTable GridOutTable
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return (DataTable)ViewState["GridOutTable"];
|
|||
|
|
|||
|
}
|
|||
|
set
|
|||
|
{
|
|||
|
ViewState["GridOutTable"] = value;
|
|||
|
}
|
|||
|
}
|
|||
|
#region Page_Init
|
|||
|
|
|||
|
// 注意:动态创建的代码需要放置于Page_Init(不是Page_Load),这样每次构造页面时都会执行
|
|||
|
protected void Page_Init(object sender, EventArgs e)
|
|||
|
{
|
|||
|
InitGrid();
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
private void InitGrid()
|
|||
|
{
|
|||
|
GridTable=new DataTable();
|
|||
|
FineUIPro.BoundField bf;
|
|||
|
FineUIPro.CheckBoxField rf;
|
|||
|
FineUIPro.TextBox txTextBox;
|
|||
|
|
|||
|
GridTable.Columns.Add("PersonId");
|
|||
|
|
|||
|
|
|||
|
ListItem[] list = new ListItem[6];
|
|||
|
list[0] = new ListItem("单位名称", "UnitName");
|
|||
|
list[1] = new ListItem("施工队", "TeamGroupName");
|
|||
|
list[2] = new ListItem("姓名", "EmployName");
|
|||
|
list[3] = new ListItem("身份证", "IDCardNo");
|
|||
|
list[4] = new ListItem("工种", "WorkPostName");
|
|||
|
list[5] = new ListItem("出勤天数", "AttendanceDays");
|
|||
|
|
|||
|
var dateList =Funs. GetMonthDay(InOutRecordStatisticInput.date.Year, InOutRecordStatisticInput.date.Month);
|
|||
|
|
|||
|
foreach (var item in list)
|
|||
|
{
|
|||
|
bf = new FineUIPro.BoundField();
|
|||
|
bf.ColumnID = item.Value;
|
|||
|
bf.DataField = item.Value;
|
|||
|
bf.HeaderText = item.Text;
|
|||
|
bf.HeaderTextAlign = TextAlign.Center;
|
|||
|
bf.TextAlign = TextAlign.Center;
|
|||
|
bf.Locked = true;
|
|||
|
Grid1.Columns.Add(bf);
|
|||
|
GridTable.Columns.Add(item.Value);
|
|||
|
}
|
|||
|
foreach (var item in dateList)
|
|||
|
{
|
|||
|
rf = new FineUIPro.CheckBoxField();
|
|||
|
rf.ColumnID = item.Day.ToString();
|
|||
|
rf.DataField= item.Day.ToString();
|
|||
|
rf.HeaderText = item.Day.ToString();
|
|||
|
rf.HeaderTextAlign = TextAlign.Center;
|
|||
|
rf.TextAlign = TextAlign.Center;
|
|||
|
rf.RenderAsStaticField = true;
|
|||
|
Grid1.Columns.Add(rf);
|
|||
|
GridTable.Columns.Add(item.Day.ToString());
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 以月和年为参数的函数,并返回包含这个月中所有日期的List<DateTime>
|
|||
|
/// </summary>
|
|||
|
/// <param name="year"></param>
|
|||
|
/// <param name="month"></param>
|
|||
|
/// <returns></returns>
|
|||
|
|
|||
|
protected void Page_Load(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (!IsPostBack)
|
|||
|
{
|
|||
|
ProjectId = this.CurrUser.LoginProjectId;
|
|||
|
// 绑定表格
|
|||
|
this.BindGrid();
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#region 绑定数据
|
|||
|
/// <summary>
|
|||
|
/// 绑定数据
|
|||
|
/// </summary>
|
|||
|
private void BindGrid()
|
|||
|
{
|
|||
|
getDataLists=(from x in Funs.DB.View_SitePerson_Person
|
|||
|
where x.IsUsed == true && x.ProjectId == InOutRecordStatisticInput.ProjectId
|
|||
|
&& (string.IsNullOrEmpty(InOutRecordStatisticInput.UnitId)|| x.UnitId .Contains(InOutRecordStatisticInput.UnitId))
|
|||
|
&& (string.IsNullOrEmpty(InOutRecordStatisticInput.TeamGroupId) || x.TeamGroupId.Contains(InOutRecordStatisticInput.TeamGroupId))
|
|||
|
&& (string.IsNullOrEmpty(InOutRecordStatisticInput.WorkPostId) || x.WorkPostId.Contains(InOutRecordStatisticInput.WorkPostId))
|
|||
|
&& (string.IsNullOrEmpty(InOutRecordStatisticInput.PersonName) || x.PersonName.Contains(InOutRecordStatisticInput.PersonName))
|
|||
|
select x).ToList();
|
|||
|
var queryEmployInOutRecordList = (from x in Funs.DB.T_d_EmployInOutRecord
|
|||
|
where x.ProjectId == InOutRecordStatisticInput.ProjectId
|
|||
|
&& x.RecordDate.Value.Year == InOutRecordStatisticInput.date.Year
|
|||
|
&& x.RecordDate.Value.Month == InOutRecordStatisticInput.date.Month
|
|||
|
select x).ToList();
|
|||
|
|
|||
|
var count = getDataLists.Count();
|
|||
|
// getDataLists = getDataLists.Skip(Grid1.PageSize * Grid1.PageIndex).Take(Grid1.PageSize).ToList();
|
|||
|
|
|||
|
var splitDataLists = Funs.SplitList(getDataLists.ToList(), 10);
|
|||
|
|
|||
|
ParallelOptions parallelOptions = new ParallelOptions();
|
|||
|
parallelOptions.MaxDegreeOfParallelism = Environment.ProcessorCount;
|
|||
|
var concurrentGridTable = new ConcurrentDictionary<string, DataRow>();
|
|||
|
// 使用 Parallel.ForEach 来并行处理拆分后的列表
|
|||
|
Parallel.ForEach(splitDataLists, parallelOptions, sublist =>
|
|||
|
{
|
|||
|
var tempTable = GridTable.Clone(); // 创建临时的 DataTable
|
|||
|
foreach (var item in sublist)
|
|||
|
{
|
|||
|
int AttendanceDays = 0;
|
|||
|
DataRow row = tempTable.NewRow();
|
|||
|
row["PersonId"] = item.PersonId;
|
|||
|
row["UnitName"] = item.UnitName;
|
|||
|
row["TeamGroupName"] = item.TeamGroupName;
|
|||
|
row["EmployName"] = item.PersonName;
|
|||
|
row["IDCardNo"] = item.IdentityCard;
|
|||
|
row["WorkPostName"] = item.WorkPostName;
|
|||
|
|
|||
|
var dateList = Funs.GetMonthDay(InOutRecordStatisticInput.date.Year, InOutRecordStatisticInput.date.Month);
|
|||
|
|
|||
|
foreach (var day in dateList)
|
|||
|
{
|
|||
|
var model = queryEmployInOutRecordList.FirstOrDefault(x => x.IDCardNo == item.IdentityCard && x.RecordDate.Value.Date == day.Date);
|
|||
|
if (model != null)
|
|||
|
{
|
|||
|
row[day.Day.ToString()] = true;
|
|||
|
AttendanceDays++;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
row[day.Day.ToString()] = false;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
row["AttendanceDays"] = AttendanceDays;
|
|||
|
concurrentGridTable.TryAdd(item.PersonId, row);
|
|||
|
// GridTable.Rows.Add(row);
|
|||
|
}
|
|||
|
});
|
|||
|
// 将线程安全的数据拷贝到 GridTable
|
|||
|
foreach (var kvp in concurrentGridTable)
|
|||
|
{
|
|||
|
DataRow newRow = GridTable.NewRow();
|
|||
|
newRow.ItemArray = kvp.Value.ItemArray; // 使用 ImportRow 方法创建新的行
|
|||
|
GridTable.Rows.Add(newRow);
|
|||
|
}
|
|||
|
Grid1.RecordCount = count;
|
|||
|
Grid1.DataSource = GridTable.AsEnumerable().OrderBy(x => x["UnitName"].ToString()); ;
|
|||
|
Grid1.DataBind();
|
|||
|
GridOutTable= GridTable.Copy();
|
|||
|
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region GV 数据操作
|
|||
|
/// <summary>
|
|||
|
/// 过滤表头
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
//protected void Grid1_FilterChange(object sender, EventArgs e)
|
|||
|
//{
|
|||
|
// this.BindGrid();
|
|||
|
//}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 分页
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
|
|||
|
{
|
|||
|
this.Grid1.PageIndex = e.NewPageIndex;
|
|||
|
this.BindGrid();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 排序
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected void Grid1_Sort(object sender, GridSortEventArgs e)
|
|||
|
{
|
|||
|
this.Grid1.SortDirection = e.SortDirection;
|
|||
|
this.Grid1.SortField = e.SortField;
|
|||
|
this.BindGrid();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 分页显示条数下拉框
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
|
|||
|
this.BindGrid();
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
|
|||
|
#region 关闭弹出窗
|
|||
|
/// <summary>
|
|||
|
/// 关闭弹出窗
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected void Window1_Close(object sender, WindowCloseEventArgs e)
|
|||
|
{
|
|||
|
BindGrid();
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 导出按钮
|
|||
|
/// 导出按钮
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected void btnOut_Click1(object sender, EventArgs e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
string path = Funs.RootPath + @"File\Excel\Temp\月度考勤表.xlsx";
|
|||
|
path = path.Replace(".xlsx", string.Format("{0:yyyy-MM-dd-HH-mm}", DateTime.Now) + ".xlsx");
|
|||
|
GridOutTable.Columns["UnitName"].ColumnName="单位名称";
|
|||
|
GridOutTable.Columns["TeamGroupName"].ColumnName = "施工队";
|
|||
|
GridOutTable.Columns["EmployName"].ColumnName = "姓名";
|
|||
|
GridOutTable.Columns["IDCardNo"].ColumnName = "身份证";
|
|||
|
GridOutTable.Columns["WorkPostName"].ColumnName = "工种";
|
|||
|
GridOutTable.Columns["AttendanceDays"].ColumnName = "出勤天数";
|
|||
|
GridOutTable.Columns.Remove("PersonId");
|
|||
|
// 假设 dt 是你的 DataTable 对象,columnIndex 是要检查的列的索引
|
|||
|
for (int i = 0; i < GridOutTable.Rows.Count; i++)
|
|||
|
{
|
|||
|
for (int j = 0; j < GridOutTable.Columns.Count; j++)
|
|||
|
{
|
|||
|
// 检查每个单元格的值
|
|||
|
if (GridOutTable.Rows[i][j].ToString() =="True")
|
|||
|
{
|
|||
|
GridOutTable.Rows[i][j] = "√";
|
|||
|
|
|||
|
}else if (GridOutTable.Rows[i][j].ToString() == "False")
|
|||
|
{
|
|||
|
GridOutTable.Rows[i][j] = "×";
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
MiniExcel.SaveAs(path, GridOutTable);
|
|||
|
|
|||
|
string fileName= ProjectService.GetProjectNameByProjectId(this.ProjectId)+ "月度考勤表.xlsx".Replace(".xlsx", string.Format("{0:yyyy-MM}", DateTime.Now) + ".xlsx");
|
|||
|
FileInfo info = new FileInfo(path);
|
|||
|
if (info.Exists)
|
|||
|
{
|
|||
|
long fileSize = info.Length;
|
|||
|
System.Web.HttpContext.Current.Response.BufferOutput = true;
|
|||
|
System.Web.HttpContext.Current.Response.Clear();
|
|||
|
System.Web.HttpContext.Current.Response.ContentType = "application/x-zip-compressed";
|
|||
|
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
|
|||
|
System.Web.HttpContext.Current.Response.AddHeader("Content-Length", fileSize.ToString());
|
|||
|
System.Web.HttpContext.Current.Response.TransmitFile(path, 0, fileSize);
|
|||
|
System.Web.HttpContext.Current.Response.Flush();
|
|||
|
System.Web.HttpContext.Current.Response.Close();
|
|||
|
File.Delete(path);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
catch (System.Exception ex)
|
|||
|
{
|
|||
|
throw;
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
protected void btnOut_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
string path = Funs.RootPath + @"File\Excel\Temp\月度考勤表.xlsx";
|
|||
|
path = path.Replace(".xlsx", string.Format("{0:yyyy-MM-dd-HH-mm}", DateTime.Now) + ".xlsx");
|
|||
|
GridOutTable.Columns["UnitName"].ColumnName = "单位名称";
|
|||
|
GridOutTable.Columns["TeamGroupName"].ColumnName = "施工队";
|
|||
|
GridOutTable.Columns["EmployName"].ColumnName = "姓名";
|
|||
|
GridOutTable.Columns["IDCardNo"].ColumnName = "身份证";
|
|||
|
GridOutTable.Columns["WorkPostName"].ColumnName = "工种";
|
|||
|
GridOutTable.Columns["AttendanceDays"].ColumnName = "出勤天数";
|
|||
|
// GridOutTable.Columns.Remove("PersonId");
|
|||
|
// 假设 dt 是你的 DataTable 对象,columnIndex 是要检查的列的索引
|
|||
|
for (int i = 0; i < GridOutTable.Rows.Count; i++)
|
|||
|
{
|
|||
|
var model = DoorServerService.getInOutRecordStatistics(InOutRecordStatisticInput.ProjectId, GridOutTable.Rows[i]["PersonId"].ToString(), InOutRecordStatisticInput.date);
|
|||
|
|
|||
|
for (int j = 0; j < GridOutTable.Columns.Count; j++)
|
|||
|
{
|
|||
|
|
|||
|
// 检查每个单元格的值
|
|||
|
if (GridOutTable.Rows[i][j].ToString() == "True")
|
|||
|
{
|
|||
|
var todaymodel = model.DayInOutRecordStatistic.FirstOrDefault(x => x.Date.Day.ToString() == GridOutTable.Columns[j].ColumnName);
|
|||
|
// GridOutTable.Columns[j].ColumnName
|
|||
|
if (todaymodel!=null && todaymodel.State==1)
|
|||
|
{
|
|||
|
GridOutTable.Rows[i][j] = "√";
|
|||
|
|
|||
|
}
|
|||
|
else if(todaymodel != null && todaymodel.State == 2)
|
|||
|
{
|
|||
|
GridOutTable.Rows[i][j] = "✰";
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
else if (GridOutTable.Rows[i][j].ToString() == "False")
|
|||
|
{
|
|||
|
GridOutTable.Rows[i][j] = "×";
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
GridOutTable.Columns.Remove("PersonId");
|
|||
|
MiniExcel.SaveAs(path, GridOutTable);
|
|||
|
|
|||
|
string fileName = ProjectService.GetProjectNameByProjectId(this.ProjectId) + "月度考勤表.xlsx".Replace(".xlsx", string.Format("{0:yyyy-MM}", DateTime.Now) + ".xlsx");
|
|||
|
FileInfo info = new FileInfo(path);
|
|||
|
if (info.Exists)
|
|||
|
{
|
|||
|
long fileSize = info.Length;
|
|||
|
System.Web.HttpContext.Current.Response.BufferOutput = true;
|
|||
|
System.Web.HttpContext.Current.Response.Clear();
|
|||
|
System.Web.HttpContext.Current.Response.ContentType = "application/x-zip-compressed";
|
|||
|
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
|
|||
|
System.Web.HttpContext.Current.Response.AddHeader("Content-Length", fileSize.ToString());
|
|||
|
System.Web.HttpContext.Current.Response.TransmitFile(path, 0, fileSize);
|
|||
|
System.Web.HttpContext.Current.Response.Flush();
|
|||
|
System.Web.HttpContext.Current.Response.Close();
|
|||
|
File.Delete(path);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
catch (System.Exception ex)
|
|||
|
{
|
|||
|
throw;
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
}
|