Files
SGGL_SHJ/SGGL/FineUIPro.Web/HSSE/CostGoods/ExpenseEdit.aspx.cs
T

216 lines
8.0 KiB
C#

using BLL;
using System;
using System.Collections.Generic;
using System.Linq;
namespace FineUIPro.Web.HSSE.CostGoods
{
public partial class ExpenseEdit : PageBase
{
#region
/// <summary>
/// 主键
/// </summary>
private string ExpenseId
{
get
{
return (string)ViewState["ExpenseId"];
}
set
{
ViewState["ExpenseId"] = 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.ProjectId = this.CurrUser.LoginProjectId;
this.btnClose.OnClientClick = ActiveWindow.GetHideReference();
BLL.UnitService.InitUnitDropDownList(this.drpUnit, this.ProjectId, false);
if (!string.IsNullOrEmpty(this.CurrUser.UnitId) && !CommonService.IsSedinOrSub(this.CurrUser.UnitId))
{
this.drpUnit.SelectedValue = this.CurrUser.UnitId;
this.drpUnit.Readonly = true;
}
this.ExpenseId = Request.Params["ExpenseId"];
if (string.IsNullOrEmpty(this.ExpenseId))
{
this.drpUnit.SelectedValue = this.CurrUser.UnitId ?? Const.UnitId_SEDIN;
this.txtYear.Text = DateTime.Now.Year.ToString();
this.txtReportDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
var getEx = Funs.DB.CostGoods_Expense.FirstOrDefault(x => x.UnitId == this.drpUnit.SelectedValue && x.Year == Funs.GetNewInt(this.txtYear.Text));
if (getEx != null)
{
this.ExpenseId = getEx.ExpenseId;
}
else
{
if (CommonService.IsSedinOrSub(this.drpUnit.SelectedValue))
{
this.lbSortIndex.Text = "1";
}
else
{
var index = Funs.DB.CostGoods_Expense.Where(x => x.Year.ToString() == this.txtYear.Text).Max(x => x.SortIndex);
if (index.HasValue)
{
this.lbSortIndex.Text = (index.Value + 1).ToString();
}
else
{
this.lbSortIndex.Text = "2";
}
}
Model.CostGoods_Expense newExpense = new Model.CostGoods_Expense
{
ExpenseId = SQLHelper.GetNewID(),
ProjectId = this.ProjectId,
UnitId = this.drpUnit.SelectedValue,
ReportDate = DateTime.Now,
CreateDate = DateTime.Now,
CompileMan =this.CurrUser.PersonId,
CompileDate = DateTime.Now,
Year =Funs.GetNewInt(this.txtYear.Text),
SortIndex=Funs.GetNewIntOrZero(this.lbSortIndex.Text),
};
ExpenseService.AddExpense(newExpense);
ExpenseDetailService.AddCostDetail(newExpense.ExpenseId);
}
}
SetPage(BLL.ExpenseService.GetExpenseById(this.ExpenseId));
}
}
#endregion
/// <summary>
///
/// </summary>
private void SetPage(Model.CostGoods_Expense expense)
{
if (expense != null)
{
this.ExpenseId = expense.ExpenseId;
this.ProjectId = expense.ProjectId;
this.drpUnit.SelectedValue = expense.UnitId;
this.txtYear.Text = expense.Year.ToString();
this.lbSortIndex.Text=expense.SortIndex.ToString();
}
}
#region
/// <summary>
/// 保存按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
if (this.drpUnit.SelectedValue == BLL.Const._Null || string.IsNullOrEmpty(this.txtYear.Text))
{
Alert.ShowInTop("请选择单位、年度!", MessageBoxIcon.Warning);
return;
}
this.SaveData(BLL.Const.BtnSave);
PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
}
/// <summary>
/// 保存数据
/// </summary>
/// <param name="type"></param>
private void SaveData(string type)
{
Model.CostGoods_Expense expense = new Model.CostGoods_Expense
{
ProjectId = this.ProjectId,
UnitId = this.drpUnit.SelectedValue,
ReportDate = Funs.GetNewDateTime(this.txtReportDate.Text.Trim()),
CompileDate = DateTime.Now,
CompileMan = this.CurrUser.PersonId,
SortIndex = Funs.GetNewInt(this.lbSortIndex.Text),
Year =Funs.GetNewInt(this.txtYear.Text),
};
if (!string.IsNullOrEmpty(this.ExpenseId))
{
expense.ExpenseId = this.ExpenseId;
BLL.ExpenseService.UpdateExpense(expense);
BLL.LogService.AddSys_Log(this.CurrUser, expense.ExpenseCode, expense.ExpenseId, BLL.Const.ProjectExpenseMenuId, BLL.Const.BtnModify);
BLL.ExpenseDetailService.DeleteCostDetailByExpenseId(this.ExpenseId);
}
else
{
this.ExpenseId = SQLHelper.GetNewID();
expense.ExpenseId = this.ExpenseId;
expense.CreateDate = DateTime.Now;
BLL.ExpenseService.AddExpense(expense);
BLL.LogService.AddSys_Log(this.CurrUser, expense.ExpenseCode, expense.ExpenseId, BLL.Const.ProjectExpenseMenuId, BLL.Const.BtnAdd);
}
}
#endregion
#region
/// <summary>
/// 上传附件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAttachUrl_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.ExpenseId))
{
SaveData(BLL.Const.BtnSave);
}
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/ExpenseAttachUrl&menuId={1}", ExpenseId, BLL.Const.ProjectExpenseMenuId)));
}
#endregion
#region
/// <summary>
/// 单位变化事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void drpUnit_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.drpUnit.SelectedValue != Const._Null && !string.IsNullOrEmpty(this.txtYear.Text))
{
SetPage(Funs.DB.CostGoods_Expense.FirstOrDefault(x => x.UnitId == this.drpUnit.SelectedValue && x.Year.ToString() == this.txtYear.Text));
}
}
#endregion
}
}