SGGL_SHJ/SGGL/FineUIPro.Web/HSSE/CostGoods/CostManageEdit.aspx.cs

372 lines
14 KiB
C#

using BLL;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
namespace FineUIPro.Web.HSSE.CostGoods
{
public partial class CostManageEdit : PageBase
{
#region
/// <summary>
/// 主键
/// </summary>
private string CostManageId
{
get
{
return (string)ViewState["CostManageId"];
}
set
{
ViewState["CostManageId"] = value;
}
}
/// <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)
{
this.btnClose.OnClientClick = ActiveWindow.GetHideRefreshReference();
this.ProjectId = this.CurrUser.LoginProjectId;
//BLL.ContractService.InitCompletedContractsDropDownList(this.ProjectId,this.drpContractNum);
BLL.UnitService.InitUnitDropDownList(this.drpUnit, this.ProjectId, false);
this.CostManageId = Request.Params["CostManageId"] ?? SQLHelper.GetNewID();
var costManage = BLL.CostManageService.GetCostManageById(this.CostManageId);
if (costManage != null)
{
this.ProjectId = costManage.ProjectId;
if (this.ProjectId != this.CurrUser.LoginProjectId)
{
BLL.UnitService.InitUnitDropDownList(this.drpUnit, this.ProjectId, false);
}
if (!string.IsNullOrEmpty(costManage.UnitId))
{
this.drpUnit.SelectedValue = costManage.UnitId;
}
//this.drpContractNum.SelectedValue = costManage.ContractNum;
this.txtContractNum.Text = costManage.ContractNum;
this.txtCostManageDate.Text = string.Format("{0:yyyy-MM-dd}", costManage.CostManageDate);
}
else
{
this.drpUnit.SelectedValue = this.CurrUser.UnitId ?? Const.UnitId_SEDIN;
this.txtCostManageDate.Text = string.Format("{0:yyyy-MM-dd}", System.DateTime.Now);
}
if (BLL.ProjectUnitService.GetProjectUnitTypeByProjectIdUnitId(this.ProjectId, this.CurrUser.UnitId))
{
this.drpUnit.Readonly = true;
}
BindGrid();
this.txtProjectName.Text = ProjectService.GetProjectNameByProjectId(this.ProjectId);
this.txtHseCost.Text = ProjectUnitService.GetSumHSECost(this.ProjectId, this.drpUnit.SelectedValue).ToString();
this.txtGetCost.Text = CostManageService.GetSumHSECost(this.ProjectId, this.drpUnit.SelectedValue, this.CostManageId).ToString();
Person_PersonsService.InitFlowOperateControlUserDropDownList(this.drpNextMan, this.ProjectId, this.drpUnit.SelectedValue, true);
if (ProjectUnitService.GetProjectUnitTypeByProjectIdUnitId(this.ProjectId, this.drpUnit.SelectedValue))
{
this.drpNextMan.Label = "分包单位项目经理审批";
}
else
{
this.drpNextMan.Label = "安全经理审核";
}
BindGrid2();
}
}
#endregion
#region Grid
/// <summary>
/// 绑定Grid
/// </summary>
private void BindGrid()
{
var costManageItems = BLL.CostManageItemService.GetCostManageItemByCostManageId(this.CostManageId);
this.Grid1.DataSource = costManageItems;
this.Grid1.PageIndex = 0;
this.Grid1.DataBind();
OutputSummaryData(costManageItems);
}
private void OutputSummaryData(List<Model.CostGoods_CostManageItem> getItem)
{
JObject summary = new JObject();
summary.Add("InvestCostProject", "本次申请合计金额(元)");
summary.Add("PriceMoney", getItem.Sum(x => x.PriceMoney ?? 0));
Grid1.SummaryData = summary;
}
/// <summary>
/// 关闭弹出窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close(object sender, EventArgs e)
{
BindGrid();
}
#endregion
#region
/// <summary>
/// 新增费用申请情况
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnNew_Click(object sender, EventArgs e)
{
if (this.drpUnit.SelectedValue == BLL.Const._Null && !string.IsNullOrEmpty(this.drpUnit.SelectedValue))
{
Alert.ShowInTop("请选择分包商!", MessageBoxIcon.Warning);
return;
}
var getCost = CostManageService.GetCostManageById(this.CostManageId);
if (getCost == null)
{
SaveData(Const.BtnSave);
}
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("CostManageItemEdit.aspx?CostManageId={0}", this.CostManageId, "编辑 - ")));
}
/// <summary>
/// 编辑
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
this.Edit();
}
/// <summary>
/// 编辑
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuEdit_Click(object sender, EventArgs e)
{
this.Edit();
}
private void Edit()
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
string id = Grid1.SelectedRowID;
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("CostManageItemEdit.aspx?CostManageItemId={0}", id, "编辑 - ")));
}
/// <summary>
/// 删除
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length > 0)
{
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
Delete(rowID);
}
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gvMonthPlan_RowCommand(object sender, GridCommandEventArgs e)
{
string rowID = this.Grid1.DataKeys[e.RowIndex][0].ToString();
if (e.CommandName == "Delete")
{
Delete(rowID);
}
}
/// <summary>
///
/// </summary>
/// <param name="rowId"></param>
private void Delete(string rowId)
{
BLL.CostManageItemService.DeleteCostManageItemById(rowId);
this.BindGrid();
ShowNotify("删除数据成功!", MessageBoxIcon.Success);
}
#endregion
#region BindGrid2
/// <summary>
/// 绑定Grid
/// </summary>
private void BindGrid2()
{
var FlowOperates = from x in Funs.DB.CostGoods_CostManageFlowOperate
where x.CostManageId == this.CostManageId
select new
{
x.FlowOperateId,
x.CostManageId,
x.AuditFlowName,
x.SortIndex,
x.UnitId,
UnitName = Funs.DB.Base_Unit.First(u => u.UnitId == x.UnitId).UnitName,
x.OperaterId,
OperaterName = Funs.DB.Person_Persons.First(u => u.PersonId == x.OperaterId).PersonName,
x.OperaterTime,
x.IsAgree,
x.Opinion,
x.IsClosed
};
this.Grid2.DataSource = FlowOperates.OrderByDescending(x => x.SortIndex);
this.Grid2.DataBind();
}
#endregion
#region
/// <summary>
/// 保存按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
this.SaveData(BLL.Const.BtnSave);
PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
}
/// <summary>
/// 提交按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (this.drpNextMan.SelectedValue == BLL.Const._Null)
{
Alert.ShowInTop("请选择" + this.drpNextMan.Label + "!", MessageBoxIcon.Warning);
return;
}
this.SaveData(BLL.Const.BtnSubmit);
PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
}
/// <summary>
/// 保存数据
/// </summary>
/// <param name="type"></param>
private void SaveData(string type)
{
if (this.drpUnit.SelectedValue == BLL.Const._Null)
{
Alert.ShowInTop("请选择单位!", MessageBoxIcon.Warning);
return;
}
Model.CostGoods_CostManage costManage = new Model.CostGoods_CostManage
{
ProjectId = this.ProjectId,
UnitId = this.drpUnit.SelectedValue == Const._Null ? null : this.drpUnit.SelectedValue,
//ContractNum = this.drpContractNum.SelectedValue,
ContractNum = this.txtContractNum.Text.Trim(),
CostManageDate = Funs.GetNewDateTime(this.txtCostManageDate.Text.Trim()),
States = BLL.Const.State_0,
CompileMan = this.CurrUser.PersonId,
CompileDate = DateTime.Now,
};
var costManageItems = CostManageItemService.GetCostManageItemByCostManageId(this.CostManageId);
if (costManageItems.Count == 0)
{
costManage.SumMoney = decimal.Parse(txtHseCost.Text.Trim());
}
if (type == Const.BtnSubmit)
{
costManage.States = BLL.Const.State_1;
costManage.NextManId = this.drpNextMan.SelectedValue;
}
else
{
costManage.NextManId = costManage.CompileMan;
}
var getCost = CostManageService.GetCostManageById(this.CostManageId);
if (getCost != null)
{
costManage.CostManageId = this.CostManageId;
BLL.CostManageService.UpdateCostManage(costManage);
BLL.LogService.AddSys_Log(this.CurrUser, costManage.CostManageCode, costManage.CostManageId, BLL.Const.ProjectCostManageMenuId, BLL.Const.BtnModify);
}
else
{
costManage.CostManageCode = Funs.GetNewFileName();
costManage.CostManageId = this.CostManageId;
BLL.CostManageService.AddCostManage(costManage);
BLL.LogService.AddSys_Log(this.CurrUser, costManage.CostManageCode, costManage.CostManageId, BLL.Const.ProjectCostManageMenuId, BLL.Const.BtnAdd);
}
if (type == Const.BtnSubmit)
{
var getNext = CostManageService.getNextCostManageFlowOperateList(this.CostManageId, this.CurrUser.PersonId);
if (getNext != null)
{
getNext.OperaterId = this.drpNextMan.SelectedValue;
CostManageService.updateCostManageFlowOperate(getNext);
}
}
}
#endregion
#region
/// <summary>
/// 上传附件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAttachUrl_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.CostManageId))
{
this.SaveData(BLL.Const.BtnSave);
}
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/CostManageAttachUrl&menuId={1}", this.CostManageId, BLL.Const.ProjectCostManageMenuId)));
}
#endregion
}
}