SGGL_JT/SUBQHSE/FineUIPro.Web/Customization/CNCEC4/HSSE/Report/HazardAdministerEdit.aspx.cs

228 lines
8.6 KiB
C#

using BLL;
using Model.Enums;
using System;
using System.Linq;
namespace FineUIPro.Web.Customization.CNCEC4.HSSE.Report
{
public partial class HazardAdministerEdit : PageBase
{
public string Id
{
get
{
return (string)ViewState["Id"];
}
set
{
ViewState["Id"] = value;
}
}
public string action
{
get
{
return (string)ViewState["action"];
}
set
{
ViewState["action"] = value;
}
}
/// <summary>
/// 页面加载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.Id = Request.Params[nameof(Id)];
this.action = Request.Params[nameof(action)];
showInfo();
if (this.action == ActionEnums.View.ToString())
{
btnSave.Hidden = true;
btnSubmit.Hidden = true;
}
}
}
/// <summary>
/// 加载数据
/// </summary>
void showInfo()
{
var project = BLL.ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId);
if (project != null)
{
this.txtProjectName.Text = project.ProjectName;
this.txtUnitName.Text = BLL.UnitService.GetUnitNameByUnitId(project.UnitId);
}
var result = Funs.DB.Report_HazardAdminister.FirstOrDefault(a => a.Id == this.Id);
if (result != null)
{
project = BLL.ProjectService.GetProjectByProjectId(result.ProjectId);
if (project != null)
{
this.txtProjectName.Text = project.ProjectName;
this.txtUnitName.Text = BLL.UnitService.GetUnitNameByUnitId(project.UnitId);
}
this.txtMonths.Text = string.Format("{0:yyyy-MM}", result.Months);
txtTrobleDate.Text = result.TrobleDate.ToString();
txtDescription.Text = result.Description;
drpHazTypes.SelectedValue = result.HazTypes;
txtSeverity.Text = result.Severity;
txtHazNumber.Text = result.HazNumber;
txtHazlocation.Text = result.Hazlocation;
txtMeasure.Text = result.Measure;
txtCheckMan.Text = result.CheckMan;
if (!string.IsNullOrEmpty(result.RecDate.ToString()))
{
txtRecDate.Text = result.RecDate.ToString();
}
if (result.ClosedType == true)
rbClosedType.SelectedValue = "1";
else
rbClosedType.SelectedValue = "0";
txtHeadMan.Text = result.HeadMan;
}
else
{
this.txtMonths.Text = string.Format("{0:yyyy-MM}", Request.Params["monts"].ToString());
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
SaveData(BLL.Const.BtnSave);
ShowNotify("保存成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
/// <summary>
/// 提交
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSubmit_Click(object sender, EventArgs e)
{
SaveData(BLL.Const.BtnSubmit);
ShowNotify("提交成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
void SaveData(string type)
{
Model.Report_HazardAdminister model = new Model.Report_HazardAdminister();
model.ProjectId = this.CurrUser.LoginProjectId;
model.Unitid = BLL.ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId).UnitId;
model.Months = Convert.ToDateTime(this.txtMonths.Text);
model.TrobleDate = Convert.ToDateTime(txtTrobleDate.Text.Trim());
model.Description = txtDescription.Text.Trim();
model.HazTypes = drpHazTypes.SelectedValue;
model.Severity = txtSeverity.Text;
model.HazNumber = txtHazNumber.Text;
model.Hazlocation = txtHazlocation.Text;
model.Measure = txtMeasure.Text;
model.CheckMan = txtCheckMan.Text;
if (!string.IsNullOrEmpty(txtRecDate.Text))
{
model.RecDate = Convert.ToDateTime(txtRecDate.Text);
}
model.HeadMan = txtHeadMan.Text;
if (rbClosedType.SelectedValue == "0")
model.ClosedType = false;
else
model.ClosedType = true;
if (type == BLL.Const.BtnSave)
{
model.States = "0";
}
else
{
model.States = "1";
}
if (this.action == ActionEnums.Edit.ToString()|| !string.IsNullOrEmpty(this.Id))
{
model.Id = this.Id;
HazardAdministerService.Update(model);
}
else
{
model.Id = SQLHelper.GetNewID(typeof(Model.Report_HazardAdminister));
this.Id = model.Id;
HazardAdministerService.Insert(model);
}
}
#region
/// <summary>
/// 上传附件资源
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAttachUrl_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.Id))
{
SaveData(BLL.Const.BtnSave);
}
string edit = "0";
if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.HazardAdministerMenuId, BLL.Const.BtnAdd)
|| this.action == ActionEnums.View.ToString())
{
edit = "1";
Model.Report_HazardAdminister register = BLL.HazardAdministerService.Detail(this.Id);
DateTime date = Convert.ToDateTime(register.Months);
string dateStr = date.Year.ToString() + date.Month.ToString();
if (this.action == ActionEnums.View.ToString())
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/Report/" + dateStr + "&menuId={1}&edit={2}&type=-1", this.Id, Const.HazardAdministerMenuId, edit)));
}
else {
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/Report/" + dateStr + "&menuId={1}&edit={2}", this.Id, Const.HazardAdministerMenuId, edit)));
}
}
}
protected void btnAttachUrl_Click1(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.Id))
{
SaveData(BLL.Const.BtnSave);
}
string edit = "0";
if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.HazardAdministerMenuId, BLL.Const.BtnAdd)
|| this.action == ActionEnums.View.ToString())
{
edit = "1";
Model.Report_HazardAdminister register = BLL.HazardAdministerService.Detail(this.Id);
DateTime date = Convert.ToDateTime(register.Months);
string dateStr = date.Year.ToString() + date.Month.ToString();
if (this.action == ActionEnums.View.ToString())
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/Report/" + dateStr + "&menuId={1}&edit={2}&type=-1", this.Id+"Zgh", Const.HazardAdministerMenuId, edit)));
}
else
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/Report/" + dateStr + "&menuId={1}&edit={2}", this.Id + "Zgh", Const.HazardAdministerMenuId, edit)));
}
}
}
#endregion
}
}