xinjiang/SGGL/FineUIPro.Web/HSSE/SitePerson/DayReport.aspx.cs

569 lines
23 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using BLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using AspNet = System.Web.UI.WebControls;
namespace FineUIPro.Web.HSSE.SitePerson
{
public partial class DayReport : PageBase
{
#region
/// <summary>
/// 清单主键
/// </summary>
public string ProjectId
{
get
{
return (string)ViewState["ProjectId"];
}
set
{
ViewState["ProjectId"] = value;
}
}
#endregion
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Funs.DropDownPageSize(this.ddlPageSize);
this.ProjectId = this.CurrUser.LoginProjectId;
if (!string.IsNullOrEmpty(Request.Params["ProjectId"]))
{
this.ProjectId = Request.Params["ProjectId"];
}
////权限按钮方法
this.GetButtonPower();
ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
// 绑定表格
BindGrid();
}
}
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid()
{
//DateTime? sDate = Funs.GetNewDateTime(this.txtDate.Text);
//var dayReports = BLL.SitePerson_DayReportService.getDayReports(this.ProjectId, sDate);
//DataTable tb = this.LINQToDataTable(dayReports);
//// 2.获取当前分页数据
////var table = this.GetPagedDataTable(GridNewDynamic, tb1);
//Grid1.RecordCount = tb.Rows.Count;
//tb = GetFilteredTable(Grid1.FilteredData, tb);
//var table = this.GetPagedDataTable(Grid1, tb);
//Grid1.DataSource = table;
//Grid1.DataBind();
string strSql = string.Empty;
if (!this.ckRecord.Checked)
{
strSql = "select DayReport.DayReportId,Users.UserName,DayReport.CompileDate,CodeRecords.Code AS DayReportCode "
+ @" ,(CASE WHEN DayReport.States = " + BLL.Const.State_0 + " OR DayReport.States IS NULL THEN '待['+OperateUser.UserName+']提交' WHEN DayReport.States = " + BLL.Const.State_2 + " THEN '审核/审批完成' ELSE '待['+OperateUser.UserName+']办理' END) AS FlowOperateName"
+ @" from SitePerson_DayReport AS DayReport "
+ @" LEFT JOIN Sys_FlowOperate AS FlowOperate ON DayReport.DayReportId=FlowOperate.DataId AND FlowOperate.IsClosed <> 1"
+ @" LEFT JOIN Sys_User AS OperateUser ON FlowOperate.OperaterId=OperateUser.UserId "
+ @" LEFT JOIN Sys_User AS Users ON DayReport.CompileMan=Users.UserId "
+ @" LEFT JOIN Sys_CodeRecords AS CodeRecords ON DayReport.DayReportId=CodeRecords.DataId WHERE 1=1 ";
}
else
{
strSql = "select DayReport.DayReportId,Users.UserName,DayReport.CompileDate,CodeRecords.Code AS DayReportCode "
+ @" ,(CASE WHEN DayReport.States = " + BLL.Const.State_0 + " OR DayReport.States IS NULL THEN '待['+OperateUser.UserName+']提交' WHEN DayReport.States = " + BLL.Const.State_2 + " THEN '审核/审批完成' ELSE '待['+OperateUser.UserName+']办理' END) AS FlowOperateName"
+ @" from SitePerson_DayReport_Bak AS DayReport "
+ @" LEFT JOIN Sys_FlowOperate AS FlowOperate ON DayReport.DayReportId=FlowOperate.DataId AND FlowOperate.IsClosed <> 1"
+ @" LEFT JOIN Sys_User AS OperateUser ON FlowOperate.OperaterId=OperateUser.UserId "
+ @" LEFT JOIN Sys_User AS Users ON DayReport.CompileMan=Users.UserId "
+ @" LEFT JOIN Sys_CodeRecords AS CodeRecords ON DayReport.DayReportId=CodeRecords.DataId WHERE 1=1 ";
}
List<SqlParameter> listStr = new List<SqlParameter>();
strSql += " AND DayReport.ProjectId = @ProjectId";
if (!string.IsNullOrEmpty(Request.Params["projectId"])) ///是否文件柜查看页面传项目值
{
listStr.Add(new SqlParameter("@ProjectId", Request.Params["projectId"]));
strSql += " AND DayReport.States = @States"; ///状态为已完成
listStr.Add(new SqlParameter("@States", BLL.Const.State_2));
}
else
{
listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
}
if (!string.IsNullOrEmpty(this.txtDate.Text.Trim()))
{
strSql += " AND DayReport.CompileDate = @DayReportDate";
listStr.Add(new SqlParameter("@DayReportDate", this.txtDate.Text.Trim()));
}
strSql += " order by DayReport.CompileDate desc";
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();
}
#endregion
#region
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void TextBox_TextChanged(object sender, EventArgs e)
{
this.BindGrid();
}
#endregion
#region
/// <summary>
/// 页索引改变事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
Grid1.PageIndex = e.NewPageIndex;
BindGrid();
}
#endregion
#region
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
BindGrid();
}
#endregion
#region
/// <summary>
/// 分页选择下拉改变事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
BindGrid();
}
#endregion
#region
/// <summary>
/// 弹出编辑窗体关闭事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
BindGrid();
}
#endregion
#region Grid双击事件
/// <summary>
/// Grid行双击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
btnView_Click(null, null);
}
#endregion
#region
/// <summary>
/// 转换当日人工时
/// </summary>
/// <param name="workStage"></param>
/// <returns></returns>
protected string ConvertPersonWorkTimeSum(object dayReportId)
{
if (dayReportId != null)
{
if (!this.ckRecord.Checked)
{
return (Funs.DB.SitePerson_DayReportDetail.Where(x => x.DayReportId == dayReportId.ToString()).Sum(x => x.PersonWorkTime) ?? 0).ToString();
}
//else
//{
// return (Funs.DB.SitePerson_DayReportDetail_Bak.Where(x => x.DayReportId == dayReportId.ToString()).Sum(x => x.PersonWorkTime) ?? 0).ToString();
//}
}
return "";
}
/// <summary>
/// 转换当年累计人工时
/// </summary>
/// <param name="workStage"></param>
/// <returns></returns>
protected string ConvertYearPersonWorkTime(object compileDate)
{
if (compileDate != null)
{
Model.SGGLDB db = Funs.DB;
DateTime date = Convert.ToDateTime(compileDate);
var q = from y in db.SitePerson_DayReportDetail
where
(from z in db.SitePerson_DayReport
where z.CompileDate <= date && z.CompileDate.Value.Year == date.Year
&& z.ProjectId == this.CurrUser.LoginProjectId
select z.DayReportId).Contains(y.DayReportId)
select y;
if (q.Count() > 0)
{
return q.Sum(x => x.PersonWorkTime ?? 0).ToString();
}
}
return "";
}
/// <summary>
/// 转换累计人工时
/// </summary>
/// <param name="workStage"></param>
/// <returns></returns>
protected string ConvertTotalPersonWorkTimeSum(object compileDate)
{
if (compileDate != null)
{
Model.SGGLDB db = Funs.DB;
DateTime date = Convert.ToDateTime(compileDate);
var q = from y in db.SitePerson_DayReportDetail where (from z in db.SitePerson_DayReport where z.CompileDate <= date && z.ProjectId == this.CurrUser.LoginProjectId select z.DayReportId).Contains(y.DayReportId) select y;
if (q.Count() > 0)
{
return q.Sum(x => x.PersonWorkTime ?? 0).ToString();
}
}
return "";
}
#endregion
#region
/// <summary>
/// 获取按钮权限
/// </summary>
/// <param name="button"></param>
/// <returns></returns>
private void GetButtonPower()
{
if (Request.Params["value"] == "0")
{
return;
}
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.DayReportMenuId);
if (buttonList.Count() > 0)
{
if (buttonList.Contains(BLL.Const.BtnAdd))
{
this.btnNew.Hidden = false;
//this.btnImport.Hidden = false;
}
if (buttonList.Contains(BLL.Const.BtnModify))
{
// this.btnMenuModify.Hidden = false;
}
if (buttonList.Contains(BLL.Const.BtnDelete))
{
this.btnMenuDel.Hidden = false;
}
if (buttonList.Contains(BLL.Const.BtnIn))
{
//this.btnImport.Hidden = false;
//this.btnImport2.Hidden = false;
}
}
}
#endregion
#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;
BindGrid();
Response.Write(GetGridTableHtml(Grid1));
Response.End();
}
#pragma warning disable CS0108 // “DayReport.GetGridTableHtml(Grid)”隐藏继承的成员“PageBase.GetGridTableHtml(Grid)”。如果是有意隐藏,请使用关键字 new。
/// <summary>
/// 导出方法
/// </summary>
/// <param name="grid"></param>
/// <returns></returns>
private string GetGridTableHtml(Grid grid)
#pragma warning restore CS0108 // “DayReport.GetGridTableHtml(Grid)”隐藏继承的成员“PageBase.GetGridTableHtml(Grid)”。如果是有意隐藏,请使用关键字 new。
{
StringBuilder sb = new StringBuilder();
sb.Append("<meta http-equiv=\"content-type\" content=\"application/excel; charset=UTF-8\"/>");
sb.Append("<table cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"border-collapse:collapse;\">");
sb.Append("<tr>");
foreach (GridColumn column in grid.Columns)
{
sb.AppendFormat("<td>{0}</td>", column.HeaderText);
}
sb.Append("</tr>");
foreach (GridRow row in grid.Rows)
{
sb.Append("<tr>");
foreach (GridColumn column in grid.Columns)
{
string html = row.Values[column.ColumnIndex].ToString();
if (column.ColumnID == "tfPageIndex")
{
html = (row.FindControl("lblPageIndex") as AspNet.Label).Text;
}
if (column.ColumnID == "tfWorkTime")
{
html = (row.FindControl("lblWorkTime") as AspNet.Label).Text;
}
if (column.ColumnID == "tfWorkTimeYear")
{
html = (row.FindControl("lblWorkTimeYear") as AspNet.Label).Text;
}
if (column.ColumnID == "tfTotal")
{
html = (row.FindControl("lblTotal") as AspNet.Label).Text;
}
sb.AppendFormat("<td>{0}</td>", html);
}
sb.Append("</tr>");
}
sb.Append("</table>");
return sb.ToString();
}
#endregion
protected void btnView_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("DayReportEdit.aspx?DayReportId={0}&nowData=-1", Grid1.SelectedRowID, "查看 - ")));
}
public string DayReportId
{
get
{
return (string)ViewState["DayReportId"];
}
set
{
ViewState["DayReportId"] = value;
}
}
/// <summary>
/// 新增
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnNew_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.txtCompileDate.Text.Trim()))
{
Alert.ShowInTop("请选择日期!", MessageBoxIcon.Warning);
return;
}
DateTime? compileDate = BLL.Funs.GetNewDateTime(this.txtCompileDate.Text);
if (compileDate.HasValue && !BLL.SitePerson_DayReportService.IsExistDayReport(compileDate.Value, this.CurrUser.LoginProjectId))
{
this.DayReportId = SQLHelper.GetNewID(typeof(Model.SitePerson_DayReport));
Model.SitePerson_DayReport newDayReport = new Model.SitePerson_DayReport
{
DayReportId = this.DayReportId,
ProjectId = this.CurrUser.LoginProjectId,
CompileMan = this.CurrUser.UserId,
CompileDate = compileDate,
States = BLL.Const.State_0 //待提交
};
BLL.SitePerson_DayReportService.AddDayReport(newDayReport);
var units = from x in Funs.DB.Project_ProjectUnit
where x.ProjectId == this.CurrUser.LoginProjectId && (x.UnitType == BLL.Const.ProjectUnitType_1 || x.UnitType == BLL.Const.ProjectUnitType_2)
select x; //1为总包2为施工分包
if (units.Count() > 0)
{
foreach (var item in units)
{
if (item.OutTime == null || item.OutTime >= DateTime.Now.Date)
{
Model.SitePerson_DayReportDetail newDayReportDetail = new Model.SitePerson_DayReportDetail();
string newKeyID = SQLHelper.GetNewID(typeof(Model.SitePerson_DayReportDetail));
newDayReportDetail.DayReportDetailId = newKeyID;
newDayReportDetail.DayReportId = this.DayReportId;
newDayReportDetail.UnitId = item.UnitId;
newDayReportDetail.WorkTime = 8;
//newDayReportDetail.StaffData = this.GetStaffData(item.UnitId, item.UnitType, compileDate.Value);
BLL.SitePerson_DayReportDetailService.AddDayReportDetail(newDayReportDetail);
var posts = (from x in Funs.DB.Base_WorkPost
join y in Funs.DB.SitePerson_Person
on x.WorkPostId equals y.WorkPostId
where y.UnitId == item.UnitId && y.ProjectId == this.CurrUser.LoginProjectId
orderby x.WorkPostCode
select x).Distinct().ToList();
foreach (var postItem in posts)
{
Model.SitePerson_DayReportUnitDetail newDayReportUnitDetail = new Model.SitePerson_DayReportUnitDetail
{
DayReportDetailId = newKeyID,
PostId = postItem.WorkPostId,
CheckPersonNum = this.GetCheckingCout(postItem.WorkPostId)
};
newDayReportUnitDetail.RealPersonNum = newDayReportUnitDetail.CheckPersonNum;
newDayReportUnitDetail.PersonWorkTime = newDayReportUnitDetail.RealPersonNum * newDayReportDetail.WorkTime;
BLL.SitePerson_DayReportUnitDetailService.AddDayReportUnitDetail(newDayReportUnitDetail);
}
}
}
}
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("DayReportEdit.aspx?DayReportId={0}", this.DayReportId, "编辑 - ")));
}
else
{
Alert.ShowInTop("当日日报已存在,请到列表点击日报日期查看!", MessageBoxIcon.Warning);
return;
}
}
protected void ckRecord_CheckedChanged(object sender, CheckedEventArgs e)
{
this.BindGrid();
}
protected void btnMenuDel_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
string id = Grid1.SelectedRowID.Split(',')[0];
if (CommonService.GetAllButtonPowerList(CurrUser.LoginProjectId, CurrUser.UserId, Const.CQMSConstructSolutionMenuId, Const.BtnDelete))
{
var db = Funs.DB;
var day = db.SitePerson_DayReport.Where(u => u.DayReportId == id).FirstOrDefault();
if (day != null)
{
var detail = db.SitePerson_DayReportDetail.Where(u => u.DayReportId == id).ToList();
if (detail != null && detail.Count > 0)
{
foreach (var item in detail)
{
var unitDetails = db.SitePerson_DayReportUnitDetail.Where(u => u.DayReportDetailId == item.DayReportDetailId).ToList();
db.SitePerson_DayReportUnitDetail.DeleteAllOnSubmit(unitDetails);
}
}
db.SitePerson_DayReportDetail.DeleteAllOnSubmit(detail);
db.SitePerson_DayReport.DeleteOnSubmit(day);
db.SubmitChanges();
LogService.AddSys_Log(CurrUser, day.DayReportId, id, Const.DayReportMenuId, "人工时日报");
BindGrid();
Alert.ShowInTop("删除成功!", MessageBoxIcon.Success);
}
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Success);
}
}
#region
/// <summary>
/// 得到当前岗位考勤人数
/// </summary>
/// <param name="postId"></param>
/// <returns></returns>
private int GetCheckingCout(string workPostId)
{
int count = 0;
DateTime? nowMont = BLL.Funs.GetNewDateTime(this.txtCompileDate.Text);
if (nowMont.HasValue)
{
var checks = from x in Funs.DB.SitePerson_Checking
join y in Funs.DB.SitePerson_Person on x.PersonId equals y.PersonId
join z in Funs.DB.Base_WorkPost on y.WorkPostId equals z.WorkPostId
where x.IntoOutTime > nowMont.Value.AddDays(-1) && x.IntoOutTime < nowMont.Value.AddDays(1) && y.ProjectId == this.CurrUser.LoginProjectId
&& z.WorkPostId == workPostId
select x;
count = checks.Count();
}
return count;
}
#endregion
#region
/// <summary>
/// 导入按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnImport_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("DayReportIn.aspx", "导入 - ")));
}
#endregion
#region
/// <summary>
/// 导入按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnImport2_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("DayReportImport.aspx", "导入 - ")));
}
#endregion
}
}