Basf_TCC7/HJGL/FineUIPro.Web/WelderManage/WelderManageEdit.aspx.cs

223 lines
8.7 KiB
C#

using System;
using System.Linq;
using BLL;
namespace FineUIPro.Web.WelderManage
{
public partial class WelderManageEdit : PageBase
{
#region
/// <summary>
/// 照片附件路径
/// </summary>
public string PhotoAttachUrl
{
get
{
return (string)ViewState["PhotoAttachUrl"];
}
set
{
ViewState["PhotoAttachUrl"] = 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();
BLL.Base_UnitService.InitUnitDropDownList(this.drpUnitId, true, BLL.Const.UnitType_5, Resources.Lan.PleaseSelect);//单位
//BLL.Base_ProjectTypeService.InitProjectTypeDropDownList(this.drpPojectType, true, Resources.Lan.PleaseSelect);//项目类型
string welderId = Request.Params["WelderId"];
if (!string.IsNullOrEmpty(welderId))
{
Model.Welder_Welder welder = BLL.WelderService.GetWelderById(welderId);
if (welder != null)
{
this.txtWelderCode.Text = welder.WelderCode;
this.txtWelderName.Text = welder.WelderName;
//if (!string.IsNullOrEmpty(welder.ProjectTypeId))
//{
// this.drpPojectType.SelectedValue = welder.ProjectTypeId;
//}
if (!string.IsNullOrEmpty(welder.UnitId))
{
this.drpUnitId.SelectedValue = welder.UnitId;
}
this.rblSex.SelectedValue = welder.Sex;
if (welder.Birthday.HasValue)
{
this.txtBirthday.Text = string.Format("{0:yyyy-MM-dd}", welder.Birthday);
}
this.txtIdentityCard.Text = welder.IdentityCard;
this.txtCertificateNum.Text = welder.CertificateNum;
if (welder.CertificateValidity.HasValue)
{
this.txtCertificateValidity.Text = string.Format("{0:yyyy-MM-dd}", welder.CertificateValidity);
}
this.txtWelderLevel.Text = welder.WelderLevel;
if (welder.IsOnDuty == true)
{
cbIsOnDuty.Checked = true;
}
else
{
cbIsOnDuty.Checked = false;
}
this.txtRemark.Text = welder.Remark;
if (!string.IsNullOrEmpty(welder.PhotoUrl))
{
this.PhotoAttachUrl = welder.PhotoUrl;
this.Image1.ImageUrl = "~/" + this.PhotoAttachUrl;
}
}
}
else
{
this.cbIsOnDuty.Checked = true;
}
}
}
#endregion
#region
/// <summary>
/// 保存按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
string welderId = Request.Params["WelderId"];
var q = Funs.DB.Welder_Welder.FirstOrDefault(x => x.WelderCode == this.txtWelderCode.Text.Trim()
&& (x.WelderId != welderId || (welderId == null && welderId != null)));
if (q != null)
{
Alert.ShowInTop(Resources.Lan.WelderCodeExists, MessageBoxIcon.Warning);
return;
}
if (this.drpUnitId.SelectedValue == BLL.Const._Null)
{
Alert.ShowInTop(Resources.Lan.SelectCompany, MessageBoxIcon.Warning);
return;
}
welderId = SaveData(welderId);
ShowNotify(Resources.Lan.SaveSuccessfully, MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
private string SaveData(string welderId)
{
Model.Welder_Welder newWelder = new Model.Welder_Welder();
newWelder.WelderCode = this.txtWelderCode.Text.Trim();
newWelder.WelderName = this.txtWelderName.Text.Trim();
if (this.drpUnitId.SelectedValue != BLL.Const._Null)
{
newWelder.UnitId = this.drpUnitId.SelectedValue;
}
newWelder.Sex = this.rblSex.SelectedValue;
newWelder.Birthday = Funs.GetNewDateTime(this.txtBirthday.Text.Trim());
newWelder.IdentityCard = this.txtIdentityCard.Text.Trim();
newWelder.CertificateNum = this.txtCertificateNum.Text.Trim();
newWelder.CertificateValidity = Funs.GetNewDateTime(this.txtCertificateValidity.Text.Trim());
newWelder.WelderLevel = this.txtWelderLevel.Text.Trim();
if (this.cbIsOnDuty.Checked)
{
newWelder.IsOnDuty = true;
}
else
{
newWelder.IsOnDuty = false;
}
newWelder.Remark = this.txtRemark.Text.Trim();
newWelder.PhotoUrl = this.PhotoAttachUrl;
if (!string.IsNullOrEmpty(welderId))
{
if (!BLL.WelderService.IsExisWelderCode(welderId, this.txtWelderCode.Text))
{
newWelder.WelderId = welderId;
BLL.WelderService.UpdateWelder(newWelder);
BLL.Sys_LogService.AddLog(Const.System_1, this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.WelderManageMenuId, Const.BtnModify, welderId);
}
else
{
Alert.ShowInParent(Resources.Lan.WelderCodeExists, MessageBoxIcon.Warning);
}
}
else
{
welderId = SQLHelper.GetNewID(typeof(Model.Welder_Welder));
if (!BLL.WelderService.IsExisWelderCode(welderId, this.txtWelderCode.Text))
{
newWelder.WelderId = welderId;
BLL.WelderService.AddWelder(newWelder);
BLL.Sys_LogService.AddLog(Const.System_1, this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.WelderManageMenuId, Const.BtnAdd, welderId);
}
else
{
Alert.ShowInParent(Resources.Lan.WelderCodeExists, MessageBoxIcon.Warning);
}
}
return welderId;
}
#endregion
#region
/// <summary>
/// 上传附件资源
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAttachUrl_Click(object sender, EventArgs e)
{
string edit = "0";
string welderId = Request.Params["WelderId"];
if (string.IsNullOrEmpty(welderId))
{
SaveData(welderId);
}
else
{
edit = "1";
}
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("../AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/WelderManage&menuId={1}&edit={2}", welderId, BLL.Const.WelderManageMenuId, edit)));
}
#endregion
#region
/// <summary>
/// 上传照片
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnPhoto_Click(object sender, EventArgs e)
{
if (filePhoto.HasFile)
{
string fileName = filePhoto.ShortFileName;
if (!ValidateFileType(fileName))
{
ShowNotify(Resources.Lan.InvalidFileType, MessageBoxIcon.Warning);
return;
}
this.PhotoAttachUrl = BLL.UploadFileService.UploadAttachment(BLL.Funs.RootPath, this.filePhoto, this.PhotoAttachUrl, Const.WelderFilePath);
this.Image1.ImageUrl = "~/" + this.PhotoAttachUrl;
}
}
#endregion
}
}