using BLL;
using BLL.CQMS.Comprehensive;
using System;
using System.Linq;
namespace FineUIPro.Web.CQMS.Comprehensive
{
public partial class DesignDetailsEdit : PageBase
{
#region 定义变量
///
/// 主键
///
public string DesignDetailsId
{
get
{
return (string)ViewState["DesignDetailsId"];
}
set
{
ViewState["DesignDetailsId"] = value;
}
}
#endregion
#region 加载
///
/// 加载页面
///
///
///
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BLL.CNProfessionalService.InitCNProfessionalDownList(this.drpCNProfessionalId, true);
BLL.UnitWorkService.InitUnitWorkDownList(this.drpUnitWorks, this.CurrUser.LoginProjectId, false);
BLL.UnitService.InitUnitDownList(this.drpUnitIds, this.CurrUser.LoginProjectId, false);
this.btnSave.Hidden = true;
this.DesignDetailsId = Request.Params["DesignDetailsId"];
Model.Comprehensive_DesignDetails designDetails = BLL.DesignDetailsService.GetDesignDetailsById(this.DesignDetailsId);
if (designDetails != null)
{
this.DesignDetailsId = designDetails.DesignDetailsId;
this.hdAttachUrl.Text = this.DesignDetailsId;
if (!string.IsNullOrEmpty(designDetails.CNProfessionalId))
{
this.drpCNProfessionalId.SelectedValue = designDetails.CNProfessionalId;
}
this.txtDesignDetailsCode.Text = designDetails.DesignDetailsCode;
this.txtDetailsMan.Text = designDetails.DetailsMan;
if (designDetails.DetailsDate != null)
{
this.txtDetailsDate.Text = string.Format("{0:yyyy-MM-dd}", designDetails.DetailsDate);
}
if (designDetails.JoinPersonNum != null)
{
this.txtJoinPersonNum.Text = designDetails.JoinPersonNum.ToString();
}
if (!string.IsNullOrEmpty(designDetails.UnitWorkId))
{
this.drpUnitWorks.SelectedValueArray = designDetails.UnitWorkId.Split(',');
}
if (!string.IsNullOrEmpty(designDetails.UnitName))
{
this.drpUnitIds.SelectedValueArray = designDetails.UnitName.Split(',');
}
var auditApprove = DesignDetailsApproveService.GetAuditApprove(designDetails.DesignDetailsId, BLL.Const.Comprehensive_Audit);
var currApprove = DesignDetailsApproveService.GetCurrentApprove(designDetails.DesignDetailsId);
if (currApprove != null)
{ //重新编制 编制人 可以 显示 提交 保存按钮
if (currApprove.ApproveType == BLL.Const.Comprehensive_ReCompile && designDetails.CompileMan == CurrUser.UserId)
{
this.btnSave.Hidden = false;
}//审核状态 审核人 可以显示 提交 保存按钮
else if (currApprove.ApproveType == BLL.Const.Comprehensive_Audit && currApprove.ApproveMan == CurrUser.UserId)
{
//审核状态不可编辑
Readonly();
this.btnSave.Hidden = false;
}
}//没有当前审核人,已完成状态 或者 待提交状态
else
{
if (designDetails.Status == BLL.Const.Comprehensive_Compile && designDetails.CompileMan == CurrUser.UserId)
{
this.btnSave.Hidden = false;
}
}
}
else
{
this.txtDetailsDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
this.btnSave.Hidden = false;
}
}
}
///
/// 禁止编辑
///
public void Readonly()
{
this.txtDesignDetailsCode.Readonly = true;
this.txtDetailsDate.Readonly = true;
this.drpCNProfessionalId.Readonly = true;
this.txtDetailsMan.Readonly = true;
this.drpUnitIds.Readonly = true;
this.drpUnitWorks.Readonly = true;
//this.btnAttach.Enabled = false;
}
#endregion
#region 保存
///
/// 保存按钮
///
///
///
protected void btnSave_Click(object sender, EventArgs e)
{
if (drpCNProfessionalId.SelectedValue == BLL.Const._Null)
{
Alert.ShowInTop("请选择专业!", MessageBoxIcon.Warning);
return;
}
Model.Comprehensive_DesignDetails designDetails = new Model.Comprehensive_DesignDetails();
designDetails.ProjectId = this.CurrUser.LoginProjectId;
if (this.drpCNProfessionalId.SelectedValue != BLL.Const._Null)
{
designDetails.CNProfessionalId = this.drpCNProfessionalId.SelectedValue;
}
designDetails.DesignDetailsCode = this.txtDesignDetailsCode.Text.Trim();
designDetails.DetailsMan = this.txtDetailsMan.Text.Trim();
designDetails.JoinPersonNum = Funs.GetNewIntOrZero(this.txtJoinPersonNum.Text.Trim());
if (!string.IsNullOrEmpty(this.txtDetailsDate.Text))
{
designDetails.DetailsDate = Convert.ToDateTime(this.txtDetailsDate.Text);
}
string ids = string.Empty;
var lists = this.drpUnitWorks.SelectedValueArray;
foreach (var item in lists)
{
ids += item + ",";
}
if (!string.IsNullOrEmpty(ids))
{
ids = ids.Substring(0, ids.LastIndexOf(","));
}
designDetails.UnitWorkId = ids;
string unitIds = string.Empty;
var units = this.drpUnitIds.SelectedValueArray;
foreach (var item in units)
{
unitIds += item + ",";
}
if (!string.IsNullOrEmpty(unitIds))
{
unitIds = unitIds.Substring(0, unitIds.LastIndexOf(","));
}
designDetails.UnitName = unitIds;
if (string.IsNullOrEmpty(this.DesignDetailsId))
{
if (!string.IsNullOrEmpty(this.hdAttachUrl.Text))
{
designDetails.DesignDetailsId = this.hdAttachUrl.Text;
}
else
{
designDetails.DesignDetailsId = SQLHelper.GetNewID(typeof(Model.Comprehensive_DesignDetails));
this.hdAttachUrl.Text = designDetails.DesignDetailsId;
}
var sour = Funs.DB.AttachFile.FirstOrDefault(x => x.ToKeyId == designDetails.DesignDetailsId);
if (sour == null || string.IsNullOrEmpty(sour.AttachUrl))
{
Alert.ShowInTop("请上传附件!", MessageBoxIcon.Warning);
return;
}
designDetails.CompileMan = this.CurrUser.UserId;
designDetails.CompileDate = DateTime.Now;
designDetails.Status = BLL.Const.Comprehensive_Compile;
BLL.DesignDetailsService.AddDesignDetails(designDetails);
}
else
{
designDetails.DesignDetailsId = this.DesignDetailsId;
var sour = Funs.DB.AttachFile.FirstOrDefault(x => x.ToKeyId == this.DesignDetailsId);
if (sour == null || string.IsNullOrEmpty(sour.AttachUrl))
{
Alert.ShowInTop("请上传附件!", MessageBoxIcon.Warning);
return;
}
var model = Funs.DB.Comprehensive_DesignDetails.Where(u => u.DesignDetailsId == this.DesignDetailsId).FirstOrDefault();
if (model != null)
{
designDetails.Status = model.Status;
}
BLL.DesignDetailsService.UpdateDesignDetails(designDetails);
}
// Project_CQMSDataService.StatisticalData(this.CurrUser.LoginProjectId, Project_CQMSDataService.CQMSDateType.QualityTraining);
ShowNotify("保存成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
#endregion
#region 附件上传
///
/// 附件上传
///
///
///
protected void btnAttach_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.hdAttachUrl.Text)) //新增记录
{
this.hdAttachUrl.Text = SQLHelper.GetNewID(typeof(Model.Comprehensive_DesignDetails));
}
Model.Comprehensive_DesignDetails designDetails = BLL.DesignDetailsService.GetDesignDetailsById(this.DesignDetailsId);
if (designDetails == null || ((designDetails.CompileMan == CurrUser.UserId && designDetails.Status == BLL.Const.Comprehensive_Compile) || (designDetails.CompileMan == CurrUser.UserId && designDetails.Status == BLL.Const.Comprehensive_ReCompile)))
{
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=0&toKeyId={0}&path=FileUpload/CQMS/designDetails&menuId={1}", this.hdAttachUrl.Text, BLL.Const.DesignDetailsMenuId)));
}
else
{
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/CQMS/designDetails&menuId={1}", this.hdAttachUrl.Text, BLL.Const.DesignDetailsMenuId)));
}
}
#endregion
}
}