SGGL_SHJ/SGGL/FineUIPro.Web/PZHGL/InformationProject/ConstructionMonthReportEdit...

411 lines
22 KiB
C#

using BLL;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
namespace FineUIPro.Web.PZHGL.InformationProject
{
public partial class ConstructionMonthReportEdit : PageBase
{
/// <summary>
/// 检查月报主键
/// </summary>
public string ConstructionMonthReportId
{
get
{
return (string)ViewState["ConstructionMonthReportId"];
}
set
{
ViewState["ConstructionMonthReportId"] = value;
}
}
private static DateTime startTime;
private static DateTime endTime;
protected void Page_Load(object sender, EventArgs e)
{
ConstructionMonthReportId = Request.Params["ConstructionMonthReportId"];
if (!IsPostBack)
{
this.btnClose.OnClientClick = ActiveWindow.GetHideReference();
if (!string.IsNullOrEmpty(Request.Params["see"]))
{
btnSave.Visible = false;
}
if (!string.IsNullOrEmpty(Request.Params["month"]))
{
Model.Project_Sys_Set ConstructionMonthReportStartDay = BLL.Project_SysSetService.GetSysSetBySetName("月报开始日期", this.CurrUser.LoginProjectId);
Model.Project_Sys_Set ConstructionMonthReportEndDay = BLL.Project_SysSetService.GetSysSetBySetName("月报结束日期", this.CurrUser.LoginProjectId);
DateTime fromPageMonths = Convert.ToDateTime(Request.Params["month"]).AddMonths(-1);
startTime = Convert.ToDateTime(fromPageMonths.Year.ToString() + "-" + fromPageMonths.Month.ToString() + "-25");
endTime = startTime.AddMonths(1);
if (ConstructionMonthReportStartDay != null)
{
if (ConstructionMonthReportStartDay.SetValue != "")
{
if (ConstructionMonthReportEndDay != null)
{
if (ConstructionMonthReportEndDay.SetValue != "")
{
startTime = Convert.ToDateTime(fromPageMonths.Year.ToString() + "-" + fromPageMonths.Month.ToString() + "-" + ConstructionMonthReportStartDay.SetValue);
endTime = Convert.ToDateTime(fromPageMonths.Year.ToString() + "-" + fromPageMonths.Month.ToString() + "-" + ConstructionMonthReportEndDay.SetValue).AddMonths(1);
}
else
{
startTime = Convert.ToDateTime(fromPageMonths.Year.ToString() + "-" + fromPageMonths.Month.ToString() + "-" + ConstructionMonthReportStartDay.SetValue);
endTime = startTime.AddMonths(1);
}
}
else
{
startTime = Convert.ToDateTime(fromPageMonths.Year.ToString() + "-" + fromPageMonths.Month.ToString() + "-" + ConstructionMonthReportStartDay.SetValue);
endTime = startTime.AddMonths(1);
}
}
else
{
if (ConstructionMonthReportEndDay != null)
{
if (ConstructionMonthReportEndDay.SetValue != "")
{
startTime = Convert.ToDateTime(fromPageMonths.Year.ToString() + "-" + fromPageMonths.Month.ToString() + "-" + ConstructionMonthReportEndDay.SetValue);
endTime = startTime.AddMonths(1);
}
}
}
}
else
{
if (ConstructionMonthReportEndDay != null)
{
if (ConstructionMonthReportEndDay.SetValue != "")
{
startTime = Convert.ToDateTime(fromPageMonths.Year.ToString() + "-" + fromPageMonths.Month.ToString() + "-" + ConstructionMonthReportEndDay.SetValue);
endTime = startTime.AddMonths(1);
}
}
}
}
var project = BLL.ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId);
Model.ZHGL_ConstructionMonthReport constructionMonthReport = ConstructionMonthReportService.GetConstructionMonthReport(ConstructionMonthReportId);
if (constructionMonthReport != null)
{
this.hdId.Text = ConstructionMonthReportId;
startTime = Convert.ToDateTime(constructionMonthReport.Month.Value.AddMonths(-1).Year.ToString() + "-" + constructionMonthReport.Month.Value.AddMonths(-1).Month.ToString() + "-25");
endTime = startTime.AddMonths(1);
this.txtOwnerName.Text = constructionMonthReport.OwnerName;
this.txtContractScope.Text = constructionMonthReport.ContractScope;
this.txtContractPriceAndPricingModel.Text = constructionMonthReport.ContractPriceAndPricingModel;
if (constructionMonthReport.ContractStartDate != null)
{
this.txtContractStartDate.Text = string.Format("{0:yyyy-MM-dd}", constructionMonthReport.ContractStartDate);
}
if (constructionMonthReport.ContractEndDate != null)
{
this.txtContractEndDate.Text = string.Format("{0:yyyy-MM-dd}", constructionMonthReport.ContractEndDate);
}
this.txtMainConstructionActivities.Text = constructionMonthReport.MainConstructionActivities;
this.txtProgressDeviationAndCauseAnalysis.Text = constructionMonthReport.ProgressDeviationAndCauseAnalysis;
this.txtKeyDeviationAndCauseAnalysis.Text = constructionMonthReport.KeyDeviationAndCauseAnalysis;
this.txtTargetedCorrectiveMeasures.Text = constructionMonthReport.TargetedCorrectiveMeasures;
this.txtNextMonthWork.Text = constructionMonthReport.NextMonthWork;
this.txtNeedCoordinateMatter.Text = constructionMonthReport.NeedCoordinateMatter;
}
else
{
var ownerUnit = BLL.ProjectUnitService.GetProjectUnitListByProjectIdUnitType(this.CurrUser.LoginProjectId, BLL.Const.ProjectUnitType_4);
if (ownerUnit.Count > 0)
{
this.txtOwnerName.Text = BLL.UnitService.GetUnitNameByUnitId(ownerUnit[0].UnitId);
}
if (project.StartDate != null)
{
this.txtContractStartDate.Text = string.Format("{0:yyyy-MM-dd}", project.StartDate);
}
if (project.EndDate != null)
{
this.txtContractEndDate.Text = string.Format("{0:yyyy-MM-dd}", project.EndDate);
}
}
if (project != null)
{
this.txtProjectName.Text = project.ProjectName;
}
lbMonths.Text = endTime.Year.ToString() + "年" + endTime.Month.ToString() + "月";
DataTable table = BLL.WorkPackageService.GetAllTreeDataTableConstructionMonthReport(this.CurrUser.LoginProjectId, string.Empty, startTime, endTime);
Grid1.DataSource = table;
Grid1.DataBind();
BindMainCost();
BindSubCost();
DateTime nextStartTime = startTime.AddMonths(1);
DateTime nextEndTime = endTime.AddMonths(1);
DataTable table2 = BLL.WorkPackageService.GetAllTreeDataTableConstructionMonthReport(this.CurrUser.LoginProjectId, string.Empty, nextStartTime, nextEndTime);
Grid2.DataSource = table2;
Grid2.DataBind();
BindGrid();
OutputSummaryData();
}
else
{
if (GetRequestEventArgument() == "UPDATE_SUMMARY")
{
// 页面要求重新计算合计行的值
OutputSummaryData();
}
}
}
#region
/// <summary>
/// 计算合计
/// </summary>
private void OutputSummaryData()
{
decimal contractAmount = 0, thisNeedPay = 0, thisRealPay = 0, totalNeedPay = 0, totalRealPay = 0, totalRealPayRate = 0;
JArray mergedData = GridSubCost.GetMergedData();
foreach (JObject mergedRow in mergedData)
{
JObject values = mergedRow.Value<JObject>("values");
contractAmount += Funs.GetNewDecimalOrZero(values.Value<string>("ContractAmount"));
thisNeedPay += Funs.GetNewDecimalOrZero(values.Value<string>("ThisNeedPay"));
thisRealPay += Funs.GetNewDecimalOrZero(values.Value<string>("ThisRealPay"));
totalNeedPay += Funs.GetNewDecimalOrZero(values.Value<string>("TotalNeedPay"));
totalRealPay += Funs.GetNewDecimalOrZero(values.Value<string>("TotalRealPay"));
}
if (contractAmount > 0 && totalRealPay > 0)
{
totalRealPayRate = totalRealPay / contractAmount * 100;
}
JObject summary = new JObject();
summary.Add("tfPageIndex", "合计:");
summary.Add("ContractAmount", contractAmount.ToString("0.####"));
summary.Add("ThisNeedPay", thisNeedPay.ToString("0.####"));
summary.Add("ThisRealPay", thisRealPay.ToString("0.####"));
summary.Add("TotalNeedPay", totalNeedPay.ToString("0.####"));
summary.Add("TotalRealPay", totalRealPay.ToString("0.####"));
summary.Add("TotalRealPayRate", totalRealPayRate.ToString("0.##"));
GridSubCost.SummaryData = summary;
}
#endregion
private void BindMainCost()
{
var list = ConstructionMonthReportMainCostService.getListData(ConstructionMonthReportId);
if (list.Count == 0)
{
List<Model.ZHGL_ConstructionMonthReportMainCost> lists = new List<Model.ZHGL_ConstructionMonthReportMainCost>();
Model.ZHGL_ConstructionMonthReportMainCost mainCost = new Model.ZHGL_ConstructionMonthReportMainCost();
mainCost.ConstructionMonthReportMainCostId = SQLHelper.GetNewID();
lists.Add(mainCost);
GridMainCost.DataSource = lists;
GridMainCost.DataBind();
}
else
{
GridMainCost.DataSource = list;
GridMainCost.DataBind();
}
}
private void BindSubCost()
{
var list = ConstructionMonthReportSubCostService.getListData(ConstructionMonthReportId);
if (list.Count == 0)
{
List<Model.ZHGL_ConstructionMonthReportSubCost> lists = new List<Model.ZHGL_ConstructionMonthReportSubCost>();
List<Model.Base_Unit> units = UnitService.GetUnitByProjectIdUnitTypeList(CurrUser.LoginProjectId, BLL.Const.ProjectUnitType_2);
foreach (var unit in units)
{
Model.ZHGL_ConstructionMonthReportSubCost subCost = new Model.ZHGL_ConstructionMonthReportSubCost();
subCost.ConstructionMonthReportSubCostId = SQLHelper.GetNewID();
subCost.UnitId = unit.UnitId;
lists.Add(subCost);
}
GridSubCost.DataSource = lists;
GridSubCost.DataBind();
}
else
{
GridSubCost.DataSource = list;
GridSubCost.DataBind();
}
}
//<summary>
//获取单位名称
//</summary>
//<param name="state"></param>
//<returns></returns>
protected string ConvertUnitName(object UnitId)
{
string unitName = string.Empty;
if (UnitId != null)
{
Model.Base_Unit unit = BLL.UnitService.GetUnitByUnitId(UnitId.ToString());
if (unit != null)
{
unitName = unit.UnitName;
}
}
return unitName;
}
#region
/// <summary>
/// 关闭弹出窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void WindowAtt_Close(object sender, WindowCloseEventArgs e)
{
BindGrid();
}
/// <summary>
/// 数据绑定
/// </summary>
public void BindGrid()
{
string strSql = @"select * from AttachFile where ToKeyId='" + this.hdId.Text + "' and MenuId='" + BLL.Const.ConstructionMonthReportMenuId + "'";
DataTable tb = SQLHelper.GetDataTableRunText(strSql, null);
Grid3.RecordCount = tb.Rows.Count;
var table = this.GetPagedDataTable(Grid1, tb);
Grid3.DataSource = table;
Grid3.DataBind();
}
/// <summary>
/// 获取图片(放于Img中)
/// </summary>
/// <param name="registrationId"></param>
/// <returns></returns>
protected string ConvertImageUrlByImage(object CompanyModelId)
{
string url = string.Empty;
if (CompanyModelId != null)
{
var attachFile = BLL.AttachFileService.GetAttachFileByToKeyId(CompanyModelId.ToString());
if (attachFile != null)
{
url = HttpUtility.HtmlDecode(BLL.UploadAttachmentService.ShowImage("../../", attachFile.AttachUrl));
}
}
return url;
}
#endregion
#region
/// <summary>
/// 附件上传
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAttach_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.hdId.Text)) //新增记录
{
this.hdId.Text = SQLHelper.GetNewID(typeof(Model.ZHGL_ConstructionMonthReport));
}
if (!string.IsNullOrEmpty(Request.Params["see"]))
{
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/ZHGL/ConstructionMonthReport&menuId={1}", this.hdId.Text, BLL.Const.ConstructionMonthReportMenuId)));
}
else
{
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?type=0&toKeyId={0}&path=FileUpload/ZHGL/ConstructionMonthReport&menuId={1}", this.hdId.Text, BLL.Const.ConstructionMonthReportMenuId)));
}
}
#endregion
protected void btnSave_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(CurrUser.LoginProjectId, CurrUser.PersonId, Const.ConstructionMonthReportMenuId, Const.BtnSave))
{
Model.ZHGL_ConstructionMonthReport ConstructionMonthReport = new Model.ZHGL_ConstructionMonthReport();
ConstructionMonthReport.ProjectId = CurrUser.LoginProjectId;
ConstructionMonthReport.OwnerName = txtOwnerName.Text.Trim();
ConstructionMonthReport.ContractScope = txtContractScope.Text.Trim();
ConstructionMonthReport.ContractPriceAndPricingModel = txtContractPriceAndPricingModel.Text.Trim();
ConstructionMonthReport.ContractStartDate = Funs.GetNewDateTime(txtContractStartDate.Text.Trim());
ConstructionMonthReport.ContractEndDate = Funs.GetNewDateTime(txtContractEndDate.Text.Trim());
ConstructionMonthReport.MainConstructionActivities = this.txtMainConstructionActivities.Text.Trim();
ConstructionMonthReport.ProgressDeviationAndCauseAnalysis = this.txtProgressDeviationAndCauseAnalysis.Text.Trim();
ConstructionMonthReport.KeyDeviationAndCauseAnalysis = this.txtKeyDeviationAndCauseAnalysis.Text.Trim();
ConstructionMonthReport.TargetedCorrectiveMeasures = this.txtTargetedCorrectiveMeasures.Text.Trim();
ConstructionMonthReport.NextMonthWork = this.txtNextMonthWork.Text.Trim();
ConstructionMonthReport.NeedCoordinateMatter = this.txtNeedCoordinateMatter.Text.Trim();
if (!string.IsNullOrEmpty(ConstructionMonthReportId))
{
ConstructionMonthReport.ConstructionMonthReportId = ConstructionMonthReportId;
ConstructionMonthReportService.UpdateConstructionMonthReport(ConstructionMonthReport);
}
else
{
if (string.IsNullOrEmpty(this.hdId.Text))
{
ConstructionMonthReport.ConstructionMonthReportId = SQLHelper.GetNewID(typeof(Model.ZHGL_ConstructionMonthReport));
}
else
{
ConstructionMonthReport.ConstructionMonthReportId = this.hdId.Text;
}
ConstructionMonthReport.Month = Convert.ToDateTime(Request.Params["month"]);
ConstructionMonthReport.CompileMan = CurrUser.PersonId;
ConstructionMonthReport.CompileDate = DateTime.Now;
ConstructionMonthReportService.AddConstructionMonthReport(ConstructionMonthReport);
}
BLL.ConstructionMonthReportMainCostService.DeleteConstructionMonthReportMainCostsByConstructionMonthReportId(ConstructionMonthReport.ConstructionMonthReportId);
foreach (JObject mergedRow in GridMainCost.GetMergedData()) //总包工程施工请款情况表
{
Model.ZHGL_ConstructionMonthReportMainCost mainCost = new Model.ZHGL_ConstructionMonthReportMainCost();
int i = mergedRow.Value<int>("index");
JObject values = mergedRow.Value<JObject>("values");
mainCost.ConstructionMonthReportMainCostId = SQLHelper.GetNewID();
mainCost.ConstructionMonthReportId = ConstructionMonthReport.ConstructionMonthReportId;
mainCost.ContractConstructionCost = Funs.GetNewDecimalOrZero(values.Value<string>("ContractConstructionCost"));
mainCost.ThisRequestCost = Funs.GetNewDecimalOrZero(values.Value<string>("ThisRequestCost"));
mainCost.TotalRequestCost = Funs.GetNewDecimalOrZero(values.Value<string>("TotalRequestCost"));
mainCost.ThisCollection = Funs.GetNewDecimalOrZero(values.Value<string>("ThisCollection"));
mainCost.TotalCollection = Funs.GetNewDecimalOrZero(values.Value<string>("TotalCollection"));
mainCost.TotalCollectionRate = Funs.GetNewDecimalOrZero(values.Value<string>("TotalCollectionRate"));
ConstructionMonthReportMainCostService.AddConstructionMonthReportMainCost(mainCost);
}
BLL.ConstructionMonthReportSubCostService.DeleteConstructionMonthReportSubCostsByConstructionMonthReportId(ConstructionMonthReport.ConstructionMonthReportId);
foreach (JObject mergedRow in GridSubCost.GetMergedData()) //分包工程施工付款情况表
{
Model.ZHGL_ConstructionMonthReportSubCost subCost = new Model.ZHGL_ConstructionMonthReportSubCost();
int i = mergedRow.Value<int>("index");
JObject values = mergedRow.Value<JObject>("values");
subCost.ConstructionMonthReportSubCostId = SQLHelper.GetNewID();
subCost.ConstructionMonthReportId = ConstructionMonthReport.ConstructionMonthReportId;
subCost.UnitId = values.Value<string>("UnitId");
subCost.ContractAmount = Funs.GetNewDecimalOrZero(values.Value<string>("ContractAmount"));
subCost.ThisNeedPay = Funs.GetNewDecimalOrZero(values.Value<string>("ThisNeedPay"));
subCost.ThisRealPay = Funs.GetNewDecimalOrZero(values.Value<string>("ThisRealPay"));
subCost.TotalNeedPay = Funs.GetNewDecimalOrZero(values.Value<string>("TotalNeedPay"));
subCost.TotalRealPay = Funs.GetNewDecimalOrZero(values.Value<string>("TotalRealPay"));
subCost.TotalRealPayRate = Funs.GetNewDecimalOrZero(values.Value<string>("TotalRealPayRate"));
ConstructionMonthReportSubCostService.AddConstructionMonthReportSubCost(subCost);
}
ShowNotify("提交成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
}
}