254 lines
		
	
	
		
			9.8 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			254 lines
		
	
	
		
			9.8 KiB
		
	
	
	
		
			C#
		
	
	
	
| using BLL;
 | |
| using Newtonsoft.Json.Linq;
 | |
| using System;
 | |
| using System.Collections.Generic;
 | |
| using System.Data;
 | |
| using System.Linq;
 | |
| 
 | |
| namespace FineUIPro.Web.Door
 | |
| {
 | |
|     public partial class InOutManHours : PageBase
 | |
|     {
 | |
|         /// <summary>
 | |
|         /// 项目id
 | |
|         /// </summary>
 | |
|         public string ProjectId
 | |
|         {
 | |
|             get
 | |
|             {
 | |
|                 return (string)ViewState["ProjectId"];
 | |
|             }
 | |
|             set
 | |
|             {
 | |
|                 ViewState["ProjectId"] = value;
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         protected void Page_Load(object sender, EventArgs e)
 | |
|         {
 | |
|             if (!IsPostBack)
 | |
|             {
 | |
|                 this.ProjectId = this.CurrUser.LoginProjectId;
 | |
|                 if (!string.IsNullOrEmpty(Request.Params["projectId"]) && Request.Params["projectId"] != this.ProjectId)
 | |
|                 {
 | |
|                     this.ProjectId = Request.Params["projectId"];
 | |
|                 }
 | |
|                 Funs.DropDownPageSize(this.ddlPageSize);
 | |
| 
 | |
|                 UnitService.InitUnitDropDownList(this.drpUnit, this.ProjectId, true);           
 | |
|                 WorkPostService.InitWorkPostDropDownList(this.drpWorkPost, true);
 | |
| 
 | |
|                 this.txtStartDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
 | |
|                 this.txtEndDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
 | |
|                 GetPersonStatistic();
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 获取数据
 | |
|         /// </summary>
 | |
|         private void GetPersonStatistic()
 | |
|         {
 | |
|             string unitId = null;
 | |
|             string PostId = null;
 | |
|             if (this.drpUnit.SelectedValue != Const._Null && !string.IsNullOrEmpty(this.drpUnit.SelectedValue))
 | |
|             {
 | |
|                 unitId = Funs.GetStringByArray(this.drpUnit.SelectedValueArray);              
 | |
|             }
 | |
|             if (this.drpWorkPost.SelectedValue != Const._Null && !string.IsNullOrEmpty(this.drpWorkPost.SelectedValue))
 | |
|             {
 | |
|                 PostId = Funs.GetStringByArray(this.drpWorkPost.SelectedValueArray);
 | |
|             }
 | |
| 
 | |
|             var getData = Funs.DB.spInOutManHoursReport(this.ProjectId, unitId, PostId, Funs.GetNewDateTimeOrNow(this.txtStartDate.Text), Funs.GetNewDateTimeOrNow(this.txtEndDate.Text));            
 | |
|             DataTable tb = GetTreeDataTable(getData.ToList()); //this.LINQToDataTable(getData.ToList());
 | |
|             Grid1.RecordCount = tb.Rows.Count;
 | |
|             //tb = GetFilteredTable(Grid1.FilteredData, tb);
 | |
|              this.OutputSummaryData(tb); ///取合计值
 | |
|             var table = this.GetPagedDataTable(Grid1, tb);
 | |
|             Grid1.DataSource = table;
 | |
|             Grid1.DataBind();
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 获取模拟树表格
 | |
|         /// </summary>
 | |
|         /// <returns></returns>
 | |
|         public  DataTable GetTreeDataTable(List<Model.InOutstatisticsItem> getData)
 | |
|         {
 | |
|             DataTable table = new DataTable();
 | |
|             table.Columns.Add(new DataColumn("ID", typeof(string)));
 | |
|             table.Columns.Add(new DataColumn("ParentId", typeof(string)));
 | |
|             table.Columns.Add(new DataColumn("AllUnitName", typeof(String)));
 | |
|             table.Columns.Add(new DataColumn("PostName", typeof(String)));
 | |
|             table.Columns.Add(new DataColumn("PersonCountSum", typeof(int)));
 | |
|             table.Columns.Add(new DataColumn("ManCountSum", typeof(int)));
 | |
|             table.Columns.Add(new DataColumn("ManHoursSum", typeof(int)));
 | |
|             DataRow row;
 | |
|             var getSum = from p in getData
 | |
|                          group p by p.UnitId into g
 | |
|                          select new
 | |
|                          {
 | |
|                             ID=SQLHelper.GetNewID(),
 | |
|                              g.First().UnitId,
 | |
|                              g.First().AllUnitName,
 | |
|                              PostName = "小计",
 | |
|                              ManHoursSum = g.Sum(x => x.ManHoursSum ?? 0),
 | |
|                              ManCountSum = g.Sum(x => x.ManCountSum ?? 0),
 | |
|                              PersonCountSum = getSumSysCount(g.First().ProjectId, g.First().UnitId),
 | |
|                          };
 | |
|             foreach (var item in getSum)
 | |
|             {
 | |
|                 row = table.NewRow();
 | |
|                 row[0] = item.ID;
 | |
|                 row[1] = "-1";
 | |
|                 row[2] = item.AllUnitName;
 | |
|                 row[3] =item.PostName;
 | |
|                 row[4] = item.PersonCountSum;
 | |
|                 row[5] = item.ManCountSum;
 | |
|                 row[6] = item.ManHoursSum;
 | |
|                 table.Rows.Add(row);
 | |
|                 var getU = getData.Where(x => x.UnitId == item.UnitId);
 | |
|                 foreach (var itemU in getU)
 | |
|                 {
 | |
|                     row = table.NewRow();
 | |
|                     row[0] = itemU.ID;
 | |
|                     row[1] = item.ID;
 | |
|                     row[2] = itemU.AllUnitName;
 | |
|                     row[3] = itemU.PostName;
 | |
|                     row[4] = itemU.PersonCountSum ?? 0;
 | |
|                     row[5] = itemU.ManCountSum ?? 0;
 | |
|                     row[6] = itemU.ManHoursSum ?? 0;
 | |
|                     table.Rows.Add(row);
 | |
|                 }
 | |
|             }
 | |
|             return table;
 | |
|         }
 | |
|         /// <returns></returns>
 | |
|         private int getSumSysCount(string projectId, string unitId)
 | |
|         {
 | |
|             return Funs.DB.SitePerson_Person.Where(x => x.ProjectId == projectId && x.UnitId == unitId && x.IsUsed == true && x.InTime <= DateTime.Now && (!x.OutTime.HasValue || x.OutTime > DateTime.Now)).Count();
 | |
|         }
 | |
|         #region 计算合计
 | |
|         /// <summary>
 | |
|         /// 计算合计
 | |
|         /// </summary>
 | |
|         private void OutputSummaryData(DataTable tb)
 | |
|         {
 | |
|             int PersonCountSumT = 0;
 | |
|             int ManCountSumT = 0;
 | |
|             int ManHoursSumT = 0;
 | |
|             for (int i = 0; i < tb.Rows.Count; i++)
 | |
|             {
 | |
|                 if (tb.Rows[i].ItemArray[1].ToString() == "-1")
 | |
|                 {
 | |
|                     PersonCountSumT += Funs.GetNewIntOrZero(tb.Rows[i]["PersonCountSum"].ToString());
 | |
|                     ManCountSumT += Funs.GetNewIntOrZero(tb.Rows[i]["ManCountSum"].ToString());
 | |
|                     ManHoursSumT += Funs.GetNewIntOrZero(tb.Rows[i]["ManHoursSum"].ToString());
 | |
|                 }
 | |
|             }
 | |
| 
 | |
|             JObject summary = new JObject
 | |
|             {
 | |
|                 { "PostName", "合计:" },
 | |
|                 { "PersonCountSum", PersonCountSumT+"人" },
 | |
|                 { "ManCountSum", ManCountSumT + "人" },
 | |
|                 { "ManHoursSum", ManHoursSumT+"小时"}
 | |
|             };
 | |
|             Grid1.SummaryData = summary;
 | |
|         }
 | |
|         #endregion
 | |
| 
 | |
|         protected void btnSearch_Click(object sender, EventArgs e)
 | |
|         {
 | |
|             GetPersonStatistic();
 | |
|         }
 | |
| 
 | |
|         #region 导出按钮
 | |
|         /// 导出按钮
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param>
 | |
|         protected void btnOut_Click(object sender, EventArgs e)
 | |
|         {
 | |
|             Response.ClearContent();
 | |
|             string filename = Funs.GetNewFileName();
 | |
|             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;
 | |
|             GetPersonStatistic();
 | |
|             Response.Write(GetGridTableHtml(Grid1));
 | |
|             Response.End();
 | |
|         }
 | |
|         #endregion
 | |
|         
 | |
|         #region 分页 排序
 | |
|         /// <summary>
 | |
|         /// 改变索引事件
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param>
 | |
|         protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
 | |
|         {
 | |
|             GetPersonStatistic();
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 分页下拉选择事件
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param>
 | |
|         protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
 | |
|         {
 | |
|             this.Grid1.PageSize = Convert.ToInt32(this.ddlPageSize.SelectedValue);
 | |
|             GetPersonStatistic();
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param>
 | |
|         protected void Grid1_Sort(object sender, GridSortEventArgs e)
 | |
|         {
 | |
|             GetPersonStatistic();
 | |
|         }
 | |
| 
 | |
|         #endregion
 | |
| 
 | |
|         protected void btnView_Click(object sender, EventArgs e)
 | |
|         {
 | |
|             ViewItem();
 | |
|         }
 | |
| 
 | |
|         protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
 | |
|         {
 | |
|             ViewItem();
 | |
|         }
 | |
| 
 | |
|         private void ViewItem()
 | |
|         {
 | |
|             if (Grid1.SelectedRowIndexArray.Length == 0)
 | |
|             {
 | |
|                 Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
 | |
|                 return;
 | |
|             }
 | |
|             if (Grid1.SelectedRow.Values[2].ToString() != "小计")
 | |
|             {
 | |
|                 this.CurrUser.SessionString = this.ProjectId + "#" + Grid1.SelectedRow.Values[1].ToString() + "#" + Grid1.SelectedRow.Values[2].ToString() + "#" + this.txtStartDate.Text + "#" + this.txtEndDate.Text;
 | |
|                 PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("InOutManHoursItem.aspx?strValue={0}", (this.ProjectId + "#" + Grid1.SelectedRow.Values[1] + "#" + Grid1.SelectedRow.Values[2] + "#" + this.txtStartDate.Text + "#" + this.txtEndDate.Text), "查看 - ")));
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         protected void drpUnit_SelectedIndexChanged(object sender, EventArgs e)
 | |
|         {
 | |
|             this.drpUnit.SelectedValueArray = Funs.RemoveDropDownListNull(this.drpUnit.SelectedValueArray);
 | |
|         }
 | |
| 
 | |
|         protected void drpWorkPost_SelectedIndexChanged(object sender, EventArgs e)
 | |
|         {
 | |
|             this.drpWorkPost.SelectedValueArray = Funs.RemoveDropDownListNull(this.drpWorkPost.SelectedValueArray);
 | |
|         }
 | |
|     }
 | |
| } |