using BLL; using System; using System.Linq; using System.Web; namespace FineUIPro.Web.HSSE.QualityAudit { public partial class SubcontractLeasingProtocolEdit : PageBase { #region 定义项 /// /// 主键 /// private string Id { get { return (string)ViewState["Id"]; } set { ViewState["Id"] = value; } } #endregion #region 加载 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.btnClose.OnClientClick = ActiveWindow.GetHideReference(); BLL.UnitService.InitUnitDropDownList(this.drpUnitId, this.CurrUser.LoginProjectId, false); this.Id = Request.Params["Id"]; if (!string.IsNullOrEmpty(this.Id)) { Model.QualityAudit_SubcontractLeasingProtocol model = BLL.SubcontractLeasingProtocolService.GetSubcontractLeasingProtocolById(this.Id); if (model != null) { this.txtCode.Text = BLL.CodeRecordsService.ReturnCodeByDataId(this.Id); if (!string.IsNullOrEmpty(model.UnitId)) { this.drpUnitId.SelectedValue = model.UnitId; } ///读取编号 this.txtCode.Text = model.Code; this.txtName.Text = model.Name; if (model.ValidStartDate.HasValue) this.dpValidStartDate.SelectedDate = model.ValidStartDate; if (model.ValidEndDate.HasValue) this.dpValidEndDate.SelectedDate = model.ValidEndDate; this.txtFileContent.Text = HttpUtility.HtmlDecode(model.Content); } } else { ////自动生成编码 this.txtCode.Text = SQLHelper.RunProcNewId2("SpGetNewCode3ByProjectId", "dbo.QualityAudit_SubcontractLeasingProtocol", "Code", CurrUser.LoginProjectId); this.txtName.Text = this.SimpleForm1.Title; //////自动生成编码 //this.txtCode.Text = BLL.CodeRecordsService.ReturnCodeByMenuIdProjectId(BLL.Const.SubcontractLeasingProtocolMenuId, this.CurrUser.LoginProjectId, this.CurrUser.UnitId); } if (Request.Params["value"] == "0") { this.btnSave.Hidden = true; } } } #endregion #region 保存 /// /// 保存按钮 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.drpUnitId.SelectedValue)) { Alert.ShowInTop("请选择单位名称", MessageBoxIcon.Warning); return; } SaveData(BLL.Const.BtnSave); PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference()); } /// /// 保存数据 /// /// private void SaveData(string type) { Model.QualityAudit_SubcontractLeasingProtocol model = new Model.QualityAudit_SubcontractLeasingProtocol { ProjectId = this.CurrUser.LoginProjectId, Code = this.txtCode.Text.Trim(), Name = this.txtName.Text.Trim(), CompileMan = this.CurrUser.UserId, CompileDate = DateTime.Now, }; model.ValidStartDate = this.dpValidStartDate.SelectedDate; model.ValidEndDate = this.dpValidEndDate.SelectedDate; model.Content = HttpUtility.HtmlEncode(this.txtFileContent.Text); if (!string.IsNullOrEmpty(this.drpUnitId.SelectedValue)) { model.UnitId = this.drpUnitId.SelectedValue; } if (!string.IsNullOrEmpty(this.Id)) { model.Id = this.Id; BLL.SubcontractLeasingProtocolService.UpdateSubcontractLeasingProtocol(model); BLL.LogService.AddSys_Log(this.CurrUser, model.Code, model.Id, BLL.Const.SubcontractLeasingProtocolMenuId, BLL.Const.BtnModify); } else { this.Id = BLL.SQLHelper.GetNewID(typeof(Model.QualityAudit_SubcontractLeasingProtocol)); model.Id = this.Id; BLL.SubcontractLeasingProtocolService.AddSubcontractLeasingProtocol(model); BLL.LogService.AddSys_Log(this.CurrUser, model.Code, model.Id, BLL.Const.SubcontractLeasingProtocolMenuId, BLL.Const.BtnAdd); } } #endregion #region 附件上传 /// /// 上传附件 /// /// /// protected void btnAttachUrl_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.Id)) { SaveData(BLL.Const.BtnSave); } PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?toKeyId={0}&path=QualityAudit/SubcontractLeasingProtocolAttachUrl&menuId={1}", Id, BLL.Const.SubcontractLeasingProtocolMenuId))); } #endregion } }