Basf_FCL/FCL/FineUIPro.Web/SES/StandardTemplateEdit.aspx.cs

138 lines
5.5 KiB
C#

using BLL;
using System;
using System.Linq;
namespace FineUIPro.Web.SES
{
public partial class StandardTemplateEdit : PageBase
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.btnClose.OnClientClick = ActiveWindow.GetHideReference();
//上传人
BLL.Sys_UserService.InitUserDropDownList(this.drpUploadMan, true);
this.drpTemplateType.DataTextField = "ConstText";
this.drpTemplateType.DataValueField = "ConstValue";
this.drpTemplateType.DataSource = BLL.ConstValue.drpConstItemList(ConstValue.Group_StandardTemplate);//状态
this.drpTemplateType.DataBind();
Funs.FineUIPleaseSelect(this.drpTemplateType);
if (CurrUser.Account == Const.Gly)
{
drpUploadMan.Enabled = true;
}
else
{
drpUploadMan.SelectedValue = CurrUser.UserId;
drpUploadMan.Enabled = false;
}
string templateId = Request.Params["templateId"];
if (!string.IsNullOrEmpty(templateId))
{
Model.StandardTemplate t = BLL.StandardTemplateService.GetStandardTemplateById(templateId);
if (t != null)
{
this.txtTemplateCode.Text = t.TemplateCode;
if (!string.IsNullOrEmpty(t.TemplateName))
{
this.drpTemplateType.SelectedValue = t.TemplateName;
}
if (!string.IsNullOrEmpty(t.UploadMan))
{
this.drpUploadMan.SelectedValue = t.UploadMan;
}
this.txtUploadDate.Text = t.UploadDate.HasValue ? string.Format("{0:yyyy-MM-dd}", t.UploadDate) : "";
this.txtRemark.Text = t.Remark;
hdId.Text = templateId;
}
}
else
{
this.drpUploadMan.SelectedValue = this.CurrUser.UserId;
this.txtUploadDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
}
}
}
#region
protected void btnSave_Click(object sender, EventArgs e)
{
string templateId = Request.Params["templateId"];
Model.StandardTemplate temp = new Model.StandardTemplate();
if (this.drpTemplateType.SelectedValue == BLL.Const._Null)
{
ShowNotify("Template Type cannot be empty!", MessageBoxIcon.Warning);
}
else
{
temp.TemplateName = this.drpTemplateType.SelectedValue;
}
temp.TemplateCode = this.txtTemplateCode.Text.Trim();
if (this.drpUploadMan.SelectedValue != BLL.Const._Null)
{
temp.UploadMan = this.drpUploadMan.SelectedValue;
}
temp.UploadDate = Funs.GetNewDateTime(this.txtUploadDate.Text.Trim());
temp.Remark = this.txtRemark.Text.Trim();
if (!string.IsNullOrEmpty(templateId))
{
temp.TemplateId = templateId;
var att = from x in Funs.DB.AttachFile where x.ToKeyId == templateId select x;
if (att.Count() > 0)
{
temp.AttachUrl = att.First().AttachUrl;
}
BLL.StandardTemplateService.UpdateStandardTemplate(temp);
BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Modify Standard Template!");
ShowNotify("Save successfully!", MessageBoxIcon.Success);
}
else
{
if (!string.IsNullOrEmpty(this.hdId.Text))
{
temp.TemplateId = this.hdId.Text.Trim();
}
else
{
temp.TemplateId = SQLHelper.GetNewID(typeof(Model.StandardTemplate));
this.hdId.Text = temp.TemplateId;
}
var att = from x in Funs.DB.AttachFile where x.ToKeyId == temp.TemplateId select x;
if (att.Count() > 0)
{
temp.AttachUrl = att.First().AttachUrl;
}
BLL.StandardTemplateService.AddStandardTemplate(temp);
BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Add Standard Template!");
ShowNotify("Save successfully!", MessageBoxIcon.Success);
}
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
#endregion
#region
/// <summary>
/// 附件上传
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAttach_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.hdId.Text)) //新增记录
{
this.hdId.Text = SQLHelper.GetNewID(typeof(Model.StandardTemplate));
}
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../AttachFile/webuploader2.aspx?type=0&toKeyId={0}&path=FileUpload/SES/StandardTemplate&menuId={1}", this.hdId.Text, BLL.Const.StandardTemplateMenuId)));
}
#endregion
}
}