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); LoadAuditSelect(); this.agree.Hidden = true; this.options.Hidden = true; this.btnSave.Hidden = true; this.btnSubmit.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 (!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); if (auditApprove!=null) { drpAudit.SelectedValue = auditApprove.ApproveMan; } var currApprove = DesignDetailsApproveService.GetCurrentApprove(designDetails.DesignDetailsId); if (currApprove != null) { this.drpAudit.SelectedValue = currApprove.ApproveMan; //重新编制 编制人 可以 显示 提交 保存按钮 if (currApprove.ApproveType == BLL.Const.Comprehensive_ReCompile && designDetails.CompileMan == CurrUser.UserId) { this.btnSubmit.Hidden = false; this.btnSave.Hidden = false; }//审核状态 审核人 可以显示 提交 保存按钮 else if (currApprove.ApproveType == BLL.Const.Comprehensive_Audit && currApprove.ApproveMan == CurrUser.UserId) { //审核状态不可编辑 Readonly(); this.agree.Hidden = false; this.options.Hidden = false; this.btnSubmit.Hidden = false; this.btnSave.Hidden = false; } }//没有当前审核人,已完成状态 或者 待提交状态 else { if (designDetails.Status == BLL.Const.Comprehensive_Compile && designDetails.CompileMan == CurrUser.UserId) { this.btnSubmit.Hidden = false; this.btnSave.Hidden = false; } } } else { this.txtDetailsDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now); this.btnSave.Hidden = false; this.btnSubmit.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.drpAudit.Readonly = true; //this.btnAttach.Enabled = false; } /// /// 加载专业工程师 /// public void LoadAuditSelect() { var db = Funs.DB; var userList = from x in db.Sys_User join y in db.Project_ProjectUnit on x.UnitId equals y.UnitId join p in db.Project_ProjectUser on x.UserId equals p.UserId where y.UnitId == Const.UnitId_CWCEC && p.ProjectId == CurrUser.LoginProjectId && y.ProjectId == CurrUser.LoginProjectId where p.RoleId.Contains(Const.ZBCNEngineer) select new { UserId = x.UserId, UserName = x.UserName }; drpAudit.DataValueField = "UserId"; drpAudit.DataTextField = "UserName"; this.drpAudit.DataSource = userList.ToList(); this.drpAudit.DataBind(); } #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 (!string.IsNullOrEmpty(this.drpAudit.SelectedValue)) { designDetails.AuditMan = drpAudit.SelectedValue; } //审核人 if (this.drpCNProfessionalId.SelectedValue != BLL.Const._Null) { designDetails.CNProfessionalId = this.drpCNProfessionalId.SelectedValue; } designDetails.DesignDetailsCode = this.txtDesignDetailsCode.Text.Trim(); designDetails.DetailsMan = this.txtDetailsMan.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); } ShowNotify("保存成功!", MessageBoxIcon.Success); PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } protected void btnSubmit_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 (!string.IsNullOrEmpty(this.drpAudit.SelectedValue)) { designDetails.AuditMan = drpAudit.SelectedValue; } //审核人 if (this.drpCNProfessionalId.SelectedValue != BLL.Const._Null) { designDetails.CNProfessionalId = this.drpCNProfessionalId.SelectedValue; } designDetails.DesignDetailsCode = this.txtDesignDetailsCode.Text.Trim(); designDetails.DetailsMan = this.txtDetailsMan.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_Audit; 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 oldDesignDetails = Funs.DB.Comprehensive_DesignDetails.Where(u => u.DesignDetailsId == this.DesignDetailsId).FirstOrDefault(); if (oldDesignDetails == null) //数据库没有记录 直接点提交 当前状态为 审核状态 { designDetails.CompileMan = this.CurrUser.UserId; designDetails.CompileDate = DateTime.Now; designDetails.Status = BLL.Const.Comprehensive_Audit; BLL.DesignDetailsService.AddDesignDetails(designDetails); } else { designDetails.CompileMan = oldDesignDetails.CompileMan; designDetails.CompileDate = oldDesignDetails.CompileDate; if (oldDesignDetails.Status == BLL.Const.Comprehensive_Compile)//编制状态提交变审核 { designDetails.Status = BLL.Const.Comprehensive_Audit; } else if (oldDesignDetails.Status == BLL.Const.Comprehensive_ReCompile)//重新编制状态提交变审核 { designDetails.Status = BLL.Const.Comprehensive_Audit; } else //审核状态 提交 变 完成 或者 重新编制 { if (Convert.ToBoolean(rblIsAgree.SelectedValue)) { designDetails.Status = BLL.Const.Comprehensive_Complete; } else { designDetails.Status = BLL.Const.Comprehensive_ReCompile; } } BLL.DesignDetailsService.UpdateDesignDetails(designDetails); } } #region 审核记录 var currApprove = DesignDetailsApproveService.GetCurrentApprove(designDetails.DesignDetailsId); if (currApprove == null) //为获取到为 当前编制状态 直接提交 { var approve = new Model.Comprehensive_DesignDetailsApprove(); approve.DesignDetailsId = designDetails.DesignDetailsId; approve.ApproveMan = this.CurrUser.UserId; approve.ApproveType = Const.Comprehensive_Compile; approve.ApproveDate = DateTime.Now; DesignDetailsApproveService.EditApprove(approve); //新增编制记录 Model.Comprehensive_DesignDetailsApprove newApprove = new Model.Comprehensive_DesignDetailsApprove(); newApprove.DesignDetailsId = designDetails.DesignDetailsId; newApprove.ApproveMan = this.drpAudit.SelectedValue; newApprove.ApproveType = Const.InspectionManagement_Audit; DesignDetailsApproveService.EditApprove(newApprove); //新增专业工程师审核记录 } else if (currApprove.ApproveMan == CurrUser.UserId) { if (currApprove.ApproveType == BLL.Const.Comprehensive_ReCompile) { currApprove.ApproveDate = DateTime.Now; //currApprove.IsAgree = true; DesignDetailsApproveService.EditApprove(currApprove); //新增专业工程师审核记录 Model.Comprehensive_DesignDetailsApprove newApprove = new Model.Comprehensive_DesignDetailsApprove(); newApprove.DesignDetailsId = designDetails.DesignDetailsId; newApprove.ApproveMan = this.drpAudit.SelectedValue; newApprove.ApproveType = Const.InspectionManagement_Audit; DesignDetailsApproveService.EditApprove(newApprove); //新增专业工程师审核记录 } else { currApprove.ApproveDate = DateTime.Now; //更新审核时间 currApprove.IsAgree = Convert.ToBoolean(rblIsAgree.SelectedValue); currApprove.ApproveIdea = this.txtidea.Text; DesignDetailsApproveService.EditApprove(currApprove); if (Convert.ToBoolean(rblIsAgree.SelectedValue)) //同意时 审批完成 { Model.Comprehensive_DesignDetailsApprove reApprove = new Model.Comprehensive_DesignDetailsApprove(); reApprove.DesignDetailsId = currApprove.DesignDetailsId; reApprove.ApproveDate = DateTime.Now.AddSeconds(10); reApprove.ApproveMan = CurrUser.UserId; reApprove.ApproveType = Const.Comprehensive_Complete; // reApprove.ApproveIdea = txtidea.Text; DesignDetailsApproveService.EditApprove(reApprove); } else { Model.Comprehensive_DesignDetailsApprove reApprove = new Model.Comprehensive_DesignDetailsApprove(); reApprove.DesignDetailsId = currApprove.DesignDetailsId; reApprove.ApproveMan = designDetails.CompileMan; reApprove.ApproveType = Const.Comprehensive_ReCompile; DesignDetailsApproveService.EditApprove(reApprove); } } } #endregion 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 } }