Basf_TCC7/HJGL/FineUIPro.Web/common/ProjectSet/ProjectPictureEdit.aspx.cs

142 lines
6.0 KiB
C#
Raw Normal View History

2024-05-08 10:02:08 +08:00
using System;
using BLL;
namespace FineUIPro.Web.common.ProjectSet
{
public partial class ProjectPictureEdit : PageBase
{
#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();
string projectPictureId = Request.Params["ProjectPictureId"];
if (!string.IsNullOrEmpty(projectPictureId))
{
Model.Project_ProjectPicture projectPicture = BLL.Project_ProjectPictureService.GetProjectPictureById(projectPictureId);
if (projectPicture != null)
{
this.txtProjectPictureCode.Text = projectPicture.ProjectPictureCode;
this.txtProjectPictureName.Text = projectPicture.ProjectPictureName;
if (projectPicture.CreateDate.HasValue)
{
this.txtCreateDate.Text = string.Format("{0:yyyy-MM-dd}", projectPicture.CreateDate);
}
if (projectPicture.IsShow == true)
{
this.cbIsShow.Checked = true;
}
else
{
this.cbIsShow.Checked = false;
}
this.txtRemark.Text = projectPicture.Remark;
if (!string.IsNullOrEmpty(projectPicture.AttachUrl))
{
imgPhoto.ImageUrl = projectPicture.AttachUrl;
}
}
}
else
{
this.txtCreateDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
}
}
}
#endregion
#region
/// <summary>
/// 保存按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.ProjectPictureMenuId, Const.BtnSave))
{
string projectPictureId = Request.Params["ProjectPictureId"];
Model.Project_ProjectPicture newProjectPicture = new Model.Project_ProjectPicture();
newProjectPicture.ProjectPictureCode = this.txtProjectPictureCode.Text.Trim();
newProjectPicture.ProjectPictureName = this.txtProjectPictureName.Text.Trim();
newProjectPicture.CreateDate = Funs.GetNewDateTime(this.txtCreateDate.Text.Trim());
if (this.cbIsShow.Checked == true)
{
newProjectPicture.IsShow = true;
}
else
{
newProjectPicture.IsShow = false;
}
newProjectPicture.Remark = this.txtRemark.Text.Trim();
newProjectPicture.AttachUrl = imgPhoto.ImageUrl;
if (!string.IsNullOrEmpty(projectPictureId))
{
newProjectPicture.ProjectPictureId = projectPictureId;
BLL.Project_ProjectPictureService.UpdateProjectPicture(newProjectPicture);
BLL.Sys_LogService.AddLog(Const.System_1, this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.ProjectPictureMenuId, Const.BtnModify, projectPictureId);
}
else
{
projectPictureId = SQLHelper.GetNewID(typeof(Model.Project_ProjectPicture));
newProjectPicture.ProjectPictureId = projectPictureId;
BLL.Project_ProjectPictureService.AddProjectPicture(newProjectPicture);
BLL.Sys_LogService.AddLog(Const.System_1, this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.ProjectPictureMenuId, Const.BtnAdd, projectPictureId);
}
ShowNotify(Resources.Lan.SaveSuccessfully, MessageBoxIcon.Success);
// 关闭本窗体,然后回发父窗体
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
else
{
Alert.ShowInTop(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
return;
}
}
#endregion
#region
/// <summary>
/// 上传图片
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void filePhoto_FileSelected(object sender, EventArgs e)
{
if (filePhoto.HasFile)
{
string fileName = filePhoto.ShortFileName;
if (!ValidateFileType(fileName))
{
ShowNotify(Resources.Lan.InvalidFileType, MessageBoxIcon.Warning);
return;
}
fileName = fileName.Replace(":", "_").Replace(" ", "_").Replace("\\", "_").Replace("/", "_");
fileName = DateTime.Now.Ticks.ToString() + "_" + fileName;
filePhoto.SaveAs(Server.MapPath("~/upload/" + fileName));
imgPhoto.ImageUrl = "~/upload/" + fileName;
// 清空文件上传组件
filePhoto.Reset();
//截取图片格式如果是jpg格式勾选是否显示否则不勾选
string imgFormat = fileName.Substring(fileName.LastIndexOf('.'));
if (imgFormat == ".jpg")
{
this.cbIsShow.Checked = true;
}
else
{
this.cbIsShow.Checked = false;
}
}
}
#endregion
}
}