509 lines
23 KiB
C#
509 lines
23 KiB
C#
using BLL;
|
||
using Newtonsoft.Json.Linq;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Data.SqlClient;
|
||
using Model;
|
||
using System.Linq;
|
||
|
||
namespace FineUIPro.Web.ManHours
|
||
{
|
||
public partial class ManHoursActual : PageBase
|
||
{
|
||
private bool AppendToEnd = false;
|
||
|
||
protected void Page_Load(object sender, EventArgs e)
|
||
{
|
||
if (!IsPostBack)
|
||
{
|
||
GetButtonPower();
|
||
btnClose.OnClientClick = ActiveWindow.GetHideReference();
|
||
this.txtMonth.Text = string.Format("{0:yyyyMM}", DateTime.Now);
|
||
if (DateTime.Now.Day > 21)
|
||
{
|
||
txtMonth.MaxDate = DateTime.Now.AddMonths(1);
|
||
}
|
||
else if (DateTime.Now.Day < 25)
|
||
{
|
||
txtMonth.MaxDate = DateTime.Now;
|
||
}
|
||
txtMonth_TextChanged(null,null);
|
||
string UserId = Request.Params["UserId"];
|
||
if (!string.IsNullOrEmpty(UserId))
|
||
{
|
||
this.ddType.DataTextField = "ConstText";
|
||
this.ddType.DataValueField = "ConstValue";
|
||
this.ddType.DataSource = BLL.ConstService.GetConstListByGroupId(BLL.Const.MyTimeSheet_Type);
|
||
this.ddType.DataBind();
|
||
|
||
// 删除选中单元格的客户端脚本
|
||
//string deleteScript = GetDeleteScript();
|
||
//新增数据初始值
|
||
JObject defaultObj = new JObject();
|
||
defaultObj.Add("Type", "");
|
||
defaultObj.Add("Account", "");
|
||
defaultObj.Add("Description", "");
|
||
defaultObj.Add("Hours", "");
|
||
defaultObj.Add("Month", DateTime.Now.ToString("yyyy-MM-dd"));
|
||
defaultObj.Add("Itype", "1");
|
||
defaultObj.Add("DisciplineId", "");
|
||
defaultObj.Add("Discipline", "");
|
||
defaultObj.Add("EProjectId", "");
|
||
defaultObj.Add("UserId", Request.Params["UserId"].ToString());
|
||
defaultObj.Add("UserName", "");
|
||
defaultObj.Add("Roles", "");
|
||
defaultObj.Add("ResourcePlanId", "");
|
||
defaultObj.Add("ManHoursPlanId", "");
|
||
// 在第一行新增一条数据
|
||
btnNew.OnClientClick = Grid1.GetAddNewRecordReference(defaultObj, AppendToEnd);
|
||
// 删除选中行按钮
|
||
//btnDelete.OnClientClick = Grid1.GetNoSelectionAlertReference("Please select at least one record!") + deleteScript;
|
||
|
||
// 绑定表格
|
||
BindGrid(Request.Params["UserId"].ToString());
|
||
}
|
||
}
|
||
}
|
||
|
||
// 删除选中行的脚本
|
||
//private string GetDeleteScript()
|
||
//{
|
||
// return Confirm.GetShowReference("Delete selected row?", String.Empty, MessageBoxIcon.Question, Grid1.GetDeleteSelectedRowsReference(), String.Empty);
|
||
//}
|
||
|
||
#region BindGrid
|
||
private void BindGrid(string UserId)
|
||
{
|
||
//string dt1 = GetFirstDayOfMonth().ToString("yyyy-MM-dd");
|
||
//string dt2 = GetLastDayOfMonth().ToString("yyyy-MM-dd");
|
||
//DateTime m = Convert.ToDateTime(string.Format("{0:yyyyMM}", this.txtMonth.Text));
|
||
//string dt1 = string.Format("{0:yyyy-MM}", m.AddMonths(-1)) + "-21";
|
||
//string dt2 = string.Format("{0:yyyy-MM}", m) + "-20";
|
||
string strSql = @"SELECT [ManHoursActualId],[ManHoursPlanId],[ResourcePlanId],[EProjectId],[Type],[Description],[DisciplineId],
|
||
[Discipline],[UserId],[UserName],[Roles],[Account],[Month],[Hours],[Itype]
|
||
FROM ManHours_Actual
|
||
where UserId=@UserId and ManHoursDate = @manHoursDate";
|
||
SqlParameter[] parameter = new SqlParameter[]
|
||
{
|
||
new SqlParameter("@UserId",UserId),
|
||
new SqlParameter("@manHoursDate",this.txtMonth.Text.Trim()),
|
||
//new SqlParameter("@dt2",dt2)
|
||
};
|
||
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
|
||
|
||
//Grid1.RecordCount = tb.Rows.Count;
|
||
//tb = GetFilteredTable(Grid1.FilteredData, tb);
|
||
//var table = this.GetPagedDataTable(Grid1, tb);
|
||
Grid1.DataSource = tb;
|
||
Grid1.DataBind();
|
||
|
||
OutputSummaryData();//显示本月人工时和总人工时
|
||
}
|
||
|
||
#region 得到一个月的第一天和最后一天的日期
|
||
/// <summary>
|
||
/// 得到本月的第一天日期
|
||
/// </summary>
|
||
/// <returns>DateTime</returns>
|
||
//public static DateTime GetFirstDayOfMonth()
|
||
//{
|
||
// return GetFirstDayOfMonth(DateTime.Now);
|
||
//}
|
||
/// <summary>
|
||
/// 得到本月的最有一天的日期
|
||
/// </summary>
|
||
/// <returns>DateTime</returns>
|
||
//public static DateTime GetLastDayOfMonth()
|
||
//{
|
||
// return GetLastDayOfMonth(DateTime.Now);
|
||
//}
|
||
/// <summary>
|
||
/// 得到一个月的第一天
|
||
/// </summary>
|
||
/// <param name="someday">这个月的随便一天</param>
|
||
/// <returns>DateTime</returns>
|
||
//public static DateTime GetFirstDayOfMonth(DateTime someday)
|
||
//{
|
||
// int totalDays = DateTime.DaysInMonth(someday.Year, someday.Month);
|
||
// DateTime result;
|
||
// int ts = 1 - someday.Day;
|
||
// result = someday.AddDays(ts);
|
||
// return result;
|
||
//}
|
||
/// <summary>
|
||
/// 得到一个月的最后一天
|
||
/// </summary>
|
||
/// <param name="someday">这个月的随便一天</param>
|
||
/// <returns>DateTime</returns>
|
||
//public static DateTime GetLastDayOfMonth(DateTime someday)
|
||
//{
|
||
// int totalDays = DateTime.DaysInMonth(someday.Year, someday.Month);
|
||
// DateTime result;
|
||
// int ts = totalDays - someday.Day;
|
||
// result = someday.AddDays(ts);
|
||
// return result;
|
||
//}
|
||
#endregion
|
||
|
||
#endregion
|
||
|
||
#region Grid1数据绑定前事件
|
||
protected void Grid1_PreDataBound(object sender, EventArgs e)
|
||
{
|
||
// 设置LinkButtonField的点击客户端事件
|
||
//LinkButtonField deleteField = Grid1.FindColumn("Delete") as LinkButtonField;
|
||
//deleteField.OnClientClick = GetDeleteScript();
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 保存
|
||
/// <summary>
|
||
/// 提交按钮
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnSave_Click(object sender, EventArgs e)
|
||
{
|
||
List<Model.ManHours_Actual> list = new List<Model.ManHours_Actual>();
|
||
|
||
DateTime nowTime = DateTime.Now;
|
||
int day = nowTime.Day;
|
||
int house = nowTime.Hour;
|
||
int month = nowTime.Month;
|
||
|
||
int selectMonth = Convert.ToInt32(txtMonth.Text.Substring(4, 2));
|
||
|
||
if (CurrUser.Account != Const.Gly)
|
||
{
|
||
if (month == selectMonth && (day > 25 || (day == 25 && house >= 12)))
|
||
{
|
||
Alert.ShowInTop("本月填写日期已截止!", MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
|
||
else if (selectMonth == month + 1 && day < 21)
|
||
{
|
||
Alert.ShowInTop("下月人工时填写还未开放!", MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
else
|
||
{
|
||
JArray ConstructionArr = Grid1.GetMergedData();
|
||
if (ConstructionArr.Count > 0)
|
||
{
|
||
Model.ManHours_Actual Actual = null;
|
||
for (int c = 0; c < ConstructionArr.Count; c++)
|
||
{
|
||
Actual = new Model.ManHours_Actual();
|
||
JObject objects = (JObject)ConstructionArr[c];
|
||
if (objects["values"]["ManHoursActualId"] != null && !string.IsNullOrEmpty(objects["values"]["ManHoursActualId"].ToString()))
|
||
{
|
||
Actual.ManHoursActualId = Convert.ToString(objects["values"]["ManHoursActualId"]);
|
||
}
|
||
else
|
||
{
|
||
Actual.ManHoursActualId = SQLHelper.GetNewID(typeof(Model.ManHours_Actual));
|
||
}
|
||
Actual.ResourcePlanId = Convert.ToString(objects["values"]["ResourcePlanId"]);
|
||
Actual.Roles = Convert.ToString(objects["values"]["Roles"]);
|
||
Actual.EProjectId = Convert.ToString(objects["values"]["EProjectId"]);
|
||
Actual.ManHoursPlanId = Convert.ToString(objects["values"]["ManHoursPlanId"]);
|
||
Actual.UserId = Convert.ToString(objects["values"]["UserId"]);
|
||
Actual.UserName = Convert.ToString(objects["values"]["UserName"]);
|
||
Actual.DisciplineId = Convert.ToString(objects["values"]["DisciplineId"]);
|
||
Actual.Discipline = Convert.ToString(objects["values"]["Discipline"]);
|
||
if (objects["values"]["Type"] != null && !string.IsNullOrEmpty(objects["values"]["Type"].ToString()))
|
||
{
|
||
Actual.Type = Convert.ToString(objects["values"]["Type"]);
|
||
}
|
||
else
|
||
{
|
||
Alert.ShowInTop("Please select Type!", MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
Actual.Account = Convert.ToString(objects["values"]["Account"]);
|
||
Actual.Month = Convert.ToDateTime(objects["values"]["Month"].ToString());
|
||
if (string.IsNullOrEmpty(objects["values"]["Hours"].ToString()))
|
||
{
|
||
Alert.ShowInTop("Please fill in the Hours!");
|
||
return;
|
||
}
|
||
Actual.Hours = double.Parse(objects["values"]["Hours"].ToString());
|
||
Actual.Description = objects["values"]["Description"].ToString();
|
||
Actual.ManHoursDate = this.txtMonth.Text.Trim();
|
||
// Actual.Itype = int.Parse(objects["values"]["Itype"].ToString());
|
||
if ((Actual.Type == "T00_Normal Work" || Actual.Type.Contains("OverTime")) && Actual.ManHoursPlanId == "")
|
||
{
|
||
Alert.ShowInTop("项目无计划人工时,请联系项目经理确认!");
|
||
return;
|
||
}
|
||
list.Add(Actual);
|
||
}
|
||
}
|
||
bool result = BLL.PlanService.AddTran(Request.Params["UserId"].ToString(), list, txtMonth.Text.Trim());
|
||
if (result)
|
||
{
|
||
ShowNotify("Save successfully!", MessageBoxIcon.Success);
|
||
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
|
||
}
|
||
else
|
||
{
|
||
Alert.ShowInParent("Save failed!");
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
JArray ConstructionArr = Grid1.GetMergedData();
|
||
if (ConstructionArr.Count > 0)
|
||
{
|
||
Model.ManHours_Actual Actual = null;
|
||
for (int c = 0; c < ConstructionArr.Count; c++)
|
||
{
|
||
Actual = new Model.ManHours_Actual();
|
||
JObject objects = (JObject)ConstructionArr[c];
|
||
if (objects["values"]["ManHoursActualId"] != null && !string.IsNullOrEmpty(objects["values"]["ManHoursActualId"].ToString()))
|
||
{
|
||
Actual.ManHoursActualId = Convert.ToString(objects["values"]["ManHoursActualId"]);
|
||
}
|
||
else
|
||
{
|
||
Actual.ManHoursActualId = SQLHelper.GetNewID(typeof(Model.ManHours_Actual));
|
||
}
|
||
Actual.ResourcePlanId = Convert.ToString(objects["values"]["ResourcePlanId"]);
|
||
Actual.Roles = Convert.ToString(objects["values"]["Roles"]);
|
||
Actual.EProjectId = Convert.ToString(objects["values"]["EProjectId"]);
|
||
Actual.ManHoursPlanId = Convert.ToString(objects["values"]["ManHoursPlanId"]);
|
||
Actual.UserId = Convert.ToString(objects["values"]["UserId"]);
|
||
Actual.UserName = Convert.ToString(objects["values"]["UserName"]);
|
||
Actual.DisciplineId = Convert.ToString(objects["values"]["DisciplineId"]);
|
||
Actual.Discipline = Convert.ToString(objects["values"]["Discipline"]);
|
||
if (objects["values"]["Type"] != null && !string.IsNullOrEmpty(objects["values"]["Type"].ToString()))
|
||
{
|
||
Actual.Type = Convert.ToString(objects["values"]["Type"]);
|
||
}
|
||
else
|
||
{
|
||
Alert.ShowInTop("Please select Type!", MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
Actual.Account = Convert.ToString(objects["values"]["Account"]);
|
||
Actual.Month = Convert.ToDateTime(objects["values"]["Month"].ToString());
|
||
if (string.IsNullOrEmpty(objects["values"]["Hours"].ToString()))
|
||
{
|
||
Alert.ShowInTop("Please fill in the Hours!");
|
||
return;
|
||
}
|
||
Actual.Hours = double.Parse(objects["values"]["Hours"].ToString());
|
||
Actual.Description = objects["values"]["Description"].ToString();
|
||
Actual.ManHoursDate = this.txtMonth.Text.Trim();
|
||
// Actual.Itype = int.Parse(objects["values"]["Itype"].ToString());
|
||
if ((Actual.Type == "T00_Normal Work" || Actual.Type.Contains("OverTime")) && Actual.ManHoursPlanId == "")
|
||
{
|
||
Alert.ShowInTop("项目无计划人工时,请联系项目经理确认!");
|
||
return;
|
||
}
|
||
list.Add(Actual);
|
||
}
|
||
}
|
||
bool result = BLL.PlanService.AddTran(Request.Params["UserId"].ToString(), list, txtMonth.Text.Trim());
|
||
if (result)
|
||
{
|
||
ShowNotify("Save successfully!", MessageBoxIcon.Success);
|
||
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
|
||
}
|
||
else
|
||
{
|
||
Alert.ShowInParent("Save failed!");
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 查找
|
||
/// <summary>
|
||
/// 查找计划人工时
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnSelect_Click(object sender, EventArgs e)
|
||
{
|
||
string window = String.Format("SelectPlan.aspx?UserId={0}", Request.Params["UserId"].ToString(), "查找 - ");
|
||
PageContext.RegisterStartupScript(Window1.GetSaveStateReference(hdItemsString.ClientID) + Window1.GetShowReference(window));
|
||
}
|
||
#endregion
|
||
|
||
#region 关闭弹出窗口
|
||
/// <summary>
|
||
/// 关闭窗口
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void Window1_Close(object sender, EventArgs e)
|
||
{
|
||
List<Model.ManHours_Actual> actualLists = new List<Model.ManHours_Actual>();
|
||
//绑定之前已有的人工时
|
||
JArray ConstructionArr = Grid1.GetMergedData();
|
||
if (ConstructionArr.Count > 0)
|
||
{
|
||
Model.ManHours_Actual Actual = null;
|
||
for (int i = 0; i < ConstructionArr.Count; i++)
|
||
{
|
||
Actual = new ManHours_Actual();
|
||
JObject objects = (JObject)ConstructionArr[i];
|
||
|
||
if (objects["values"]["ManHoursActualId"] != null)
|
||
{
|
||
Actual.ManHoursActualId = Convert.ToString(objects["values"]["ManHoursActualId"]);
|
||
}
|
||
else
|
||
{
|
||
Actual.ManHoursActualId = Guid.NewGuid().ToString();
|
||
}
|
||
Actual.ResourcePlanId = Convert.ToString(objects["values"]["ResourcePlanId"]);
|
||
Actual.Roles = Convert.ToString(objects["values"]["Roles"]);
|
||
Actual.EProjectId = Convert.ToString(objects["values"]["EProjectId"]);
|
||
Actual.ManHoursPlanId = Convert.ToString(objects["values"]["ManHoursPlanId"]);
|
||
Actual.UserId = Convert.ToString(objects["values"]["UserId"]);
|
||
Actual.UserName = Convert.ToString(objects["values"]["UserName"]);
|
||
Actual.DisciplineId = Convert.ToString(objects["values"]["DisciplineId"]);
|
||
Actual.Discipline = Convert.ToString(objects["values"]["Discipline"]);
|
||
Actual.Type = Convert.ToString(objects["values"]["Type"]);
|
||
Actual.Account = Convert.ToString(objects["values"]["Account"]);
|
||
Actual.Month = Convert.ToDateTime(objects["values"]["Month"].ToString());
|
||
if (string.IsNullOrEmpty(objects["values"]["Hours"].ToString()))
|
||
{
|
||
Alert.ShowInParent("Please fill in the Hours!");
|
||
return;
|
||
}
|
||
Actual.Hours = int.Parse(objects["values"]["Hours"].ToString());
|
||
Actual.Description = objects["values"]["Description"].ToString();
|
||
|
||
actualLists.Add(Actual);
|
||
}
|
||
}
|
||
|
||
List<Model.ManHours_Actual> newActualLists = new List<Model.ManHours_Actual>();
|
||
List<string> lists = Funs.GetStrListByStr(hdItemsString.Text, ',');
|
||
foreach (var item in lists)
|
||
{
|
||
if (!string.IsNullOrEmpty(item))
|
||
{
|
||
var manHoursPlan = BLL.PlanService.GetPlanById(item);
|
||
Model.ManHours_Actual actual = new Model.ManHours_Actual();
|
||
if (manHoursPlan != null)
|
||
{
|
||
actual.Month = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));
|
||
actual.Account = manHoursPlan.Account;
|
||
actual.Description = manHoursPlan.ProjectControl_JobNo + "-" + manHoursPlan.ProjectControl_JobTitle;
|
||
actual.ResourcePlanId = manHoursPlan.ResourcePlanId;
|
||
actual.ManHoursPlanId = manHoursPlan.ManHoursPlanId;
|
||
actual.Roles = manHoursPlan.Roles;
|
||
actual.EProjectId = manHoursPlan.EProjectId;
|
||
actual.UserId = manHoursPlan.EngineerId;
|
||
actual.UserName = manHoursPlan.EngineerName;
|
||
actual.DisciplineId = manHoursPlan.DisciplineId;
|
||
actual.Discipline = manHoursPlan.Discipline;
|
||
|
||
actualLists.Add(actual);
|
||
}
|
||
}
|
||
}
|
||
|
||
this.Grid1.DataSource = actualLists;
|
||
this.Grid1.DataBind();
|
||
}
|
||
#endregion
|
||
|
||
#region 显示本月总人工时和实际人工时的和
|
||
//显示本月总人工时和实际人工时的和
|
||
private void OutputSummaryData()
|
||
{
|
||
decimal monthManHours = 0;//本月总人工时的和
|
||
decimal actualManHours = 0;//实际人工时的和
|
||
|
||
string userId = Request.Params["UserId"];
|
||
if (!string.IsNullOrEmpty(userId))
|
||
{
|
||
actualManHours = BLL.Sys_ActualManHourMonthSetService.GetHoursByMonth(DateTime.Now);//总月度人工时
|
||
//monthManHours = BLL.PlanService.getSumManHoursByUserIdAndMonth(userId, DateTime.Now);//本月实际人工时
|
||
}
|
||
|
||
int rowsCount = this.Grid1.Rows.Count;
|
||
for (int i = 0; i < rowsCount; i++)
|
||
{
|
||
monthManHours += Convert.ToDecimal(this.Grid1.Rows[i].Values[5]);
|
||
}
|
||
|
||
JObject summary = new JObject();
|
||
summary.Add("Type", "∑Target:" + actualManHours.ToString());
|
||
summary.Add("Hours", "∑Sum:" + monthManHours.ToString());
|
||
|
||
Grid1.SummaryData = summary;
|
||
}
|
||
#endregion
|
||
|
||
#region 权限设置
|
||
/// <summary>
|
||
/// 菜单按钮权限
|
||
/// </summary>
|
||
private void GetButtonPower()
|
||
{
|
||
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.UserId, BLL.Const.ManHoursMenuId);
|
||
if (buttonList.Count() > 0)
|
||
{
|
||
if (buttonList.Contains(BLL.Const.BtnTimeSheet))
|
||
{
|
||
this.btnNew.Hidden = false;
|
||
this.btnDelete.Hidden = false;
|
||
this.btnSelect.Hidden = false;
|
||
this.btnSave.Hidden = false;
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 日期选择事件
|
||
protected void txtMonth_TextChanged(object sender, EventArgs e)
|
||
{
|
||
if (!string.IsNullOrEmpty(this.txtMonth.Text.Trim()))
|
||
{
|
||
BindGrid(Request.Params["UserId"].ToString());
|
||
if ((this.txtMonth.Text.Trim() == string.Format("{0:yyyyMM}", DateTime.Now) && (DateTime.Now.Day < 25 || (DateTime.Now.Day == 25 && DateTime.Now.Hour < 12)))
|
||
|| (this.txtMonth.Text.Trim() == string.Format("{0:yyyyMM}", DateTime.Now.AddMonths(1)) && DateTime.Now.Day >=21 )
|
||
|| this.CurrUser.Account == BLL.Const.Gly)
|
||
{
|
||
IsEnabelButton(true);
|
||
}
|
||
else
|
||
{
|
||
IsEnabelButton(false);
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
private void IsEnabelButton(bool b)
|
||
{
|
||
if (b == true)
|
||
{
|
||
this.btnNew.Enabled = true;
|
||
this.btnSave.Enabled = true;
|
||
this.btnDelete.Enabled = true;
|
||
this.btnSelect.Enabled = true;
|
||
}
|
||
else
|
||
{
|
||
this.btnNew.Enabled = false;
|
||
this.btnSave.Enabled = false;
|
||
this.btnDelete.Enabled = false;
|
||
this.btnSelect.Enabled = false;
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
} |