xinjiang/SGGL/FineUIPro.Web/HSSE/Material/MaterialEdit.aspx.cs

156 lines
5.4 KiB
C#

using BLL;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
namespace FineUIPro.Web.HSSE.Material
{
public partial class MaterialEdit : PageBase
{
#region
/// <summary>
/// 主键
/// </summary>
private string MaterialId
{
get
{
return (string)ViewState["MaterialId"];
}
set
{
ViewState["MaterialId"] = 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.GetHideReference();
this.MaterialId = Request.Params["MaterialId"];
if (!string.IsNullOrEmpty(this.MaterialId))
{
this.hdId.Text = this.MaterialId;
Model.HSSE_Material material = Funs.DB.HSSE_Material.FirstOrDefault(x=>x.MaterialId==this.MaterialId);
if (material != null)
{
if (material.PublishDate != null)
{
this.txtInDate.Text = string.Format("{0:yyyy-MM-dd}", material.PublishDate);
}
if (!string.IsNullOrEmpty(material.Name))
{
this.txtName.Text = material.Name;
}
if (!string.IsNullOrEmpty(material.Remark))
{
this.txtRemark.Text = material.Remark;
}
}
}
else
{
////自动生成编码
this.txtInDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
}
if (Request.Params["value"] == "0")
{
this.btnSave.Hidden = true;
}
}
}
#endregion
#region
/// <summary>
/// 保存按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
SaveData(true);
}
/// <summary>
/// 保存数据
/// </summary>
/// <param name="isClose"></param>
private void SaveData(bool isClose)
{
Model.HSSE_Material material = new Model.HSSE_Material
{
ProjectId = this.CurrUser.LoginProjectId ,
CreateMan = this.CurrUser.UserId,
PublishMan=this.CurrUser.UserId
};
material.PublishDate = Funs.GetNewDateTimeOrNow(this.txtInDate.Text.Trim());
material.Name = this.txtName.Text.Trim();
material.Remark = this.txtRemark.Text.Trim();
material.CreateMan = this.CurrUser.UserId;
material.CreateDate = DateTime.Now;
if (!string.IsNullOrEmpty(this.MaterialId))
{
material.MaterialId = this.MaterialId;
BLL.HSSE.MaterialService.UpdateMaterial(material);
BLL.LogService.AddSys_Log(this.CurrUser, material.Name, material.MaterialId, BLL.Const.GeneralEquipmentQualityMenuId, BLL.Const.BtnModify);
}
else
{
if (!string.IsNullOrEmpty(hdId.Text))
{
material.MaterialId = this.hdId.Text;
}
else
{
material.MaterialId = SQLHelper.GetNewID(typeof(Model.HSSE_Material));
}
BLL.HSSE.MaterialService.AddMaterial(material);
BLL.LogService.AddSys_Log(this.CurrUser, material.Name, material.MaterialId, BLL.Const.GeneralEquipmentQualityMenuId, BLL.Const.BtnAdd);
}
if (isClose)
{
PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
}
}
#endregion
#region
/// <summary>
/// 上传附件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAttachUrl_Click(object sender, EventArgs e)
{
if (this.btnSave.Hidden)
{
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/GeneralEquipmentQualityAttachUrl&type=-1", this.hdId.Text, BLL.Const.HSSEMaterialMenuId)));
}
else
{
if (string.IsNullOrEmpty(this.hdId.Text))
{
this.hdId.Text = SQLHelper.GetNewID(typeof(Model.HSSE_Material));
}
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/GeneralEquipmentQualityAttachUrl&menuId={1}", this.hdId.Text, BLL.Const.HSSEMaterialMenuId)));
}
}
#endregion
}
}