using BLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace FineUIPro.Web.HSSE.CostGoods
{
public partial class FeeRegistrationEdit : PageBase
{
#region 定义项
///
/// 主键
///
public string Id
{
get
{
return (string)ViewState["Id"];
}
set
{
ViewState["Id"] = value;
}
}
#endregion
///
/// 页面加载
///
///
///
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.btnClose.OnClientClick = ActiveWindow.GetHideReference();
BLL.UnitService.InitUnitDownList(this.drpUnitId, this.CurrUser.LoginProjectId, true);
//如果不是中国五环工程有限公司,只加载自己的
if (CurrUser.UnitId == CommonService.GetThisUnitId() || CurrUser.UserId == Const.hfnbdId)
{
drpUnitId.Readonly = false;
}
else {
drpUnitId.Readonly = true;
drpUnitId.SelectedValue = CurrUser.UnitId;
}
this.Id = Request.Params["Id"];
if (!string.IsNullOrEmpty(this.Id))
{
var result = BLL.FeeRegistration.Detail(this.Id);
if (result != null)
{
if (!string.IsNullOrEmpty(result.UnitId))
{
this.drpUnitId.SelectedValue = result.UnitId;
}
if (result.CompileDate != null)
{
this.txtCompileDate.Text = string.Format("{0:yyyy-MM-dd}", result.CompileDate);
}
this.txtCost.Text = result.Cost.ToString();
}
}
else
{
this.txtCompileDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
}
if (Request.Params["value"] == "0")
{
this.btnSave.Hidden = true;
}
}
}
#region 保存
///
/// 保存按钮
///
///
///
protected void btnSave_Click(object sender, EventArgs e)
{
if (this.drpUnitId.SelectedValue == BLL.Const._Null)
{
Alert.ShowInTop("请选择单位名称!", MessageBoxIcon.Warning);
return;
}
SaveData();
PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
}
///
/// 保存数据
///
///
private void SaveData()
{
var model = new Model.CostGoods_FeeRegistration
{
ProjectId = this.CurrUser.LoginProjectId,
};
if (this.drpUnitId.SelectedValue != BLL.Const._Null)
{
model.UnitId = this.drpUnitId.SelectedValue;
}
model.Cost =Convert.ToDecimal(this.txtCost.Text.Trim());
model.CompileMan = this.CurrUser.UserId;
model.CompileDate = Funs.GetNewDateTime(this.txtCompileDate.Text.Trim());
if (!string.IsNullOrEmpty(this.Id))
{
model.Id = this.Id;
BLL.FeeRegistration.Update(model);
}
else
{
this.Id = SQLHelper.GetNewID(typeof(Model.CostGoods_MeasuresPlan));
model.Id = this.Id;
BLL.FeeRegistration.Insert(model);
}
}
#endregion
}
}