using BLL; using BLL.CQMS.Comprehensive; using System; using System.Linq; namespace FineUIPro.Web.CQMS.Comprehensive { public partial class DesignDrawingsEdit : PageBase { #region 定义变量 /// /// 主键 /// public string DesignDrawingsId { get { return (string)ViewState["DesignDrawingsId"]; } set { ViewState["DesignDrawingsId"] = value; } } #endregion #region 加载 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GetButtonPower(); BLL.CNProfessionalService.InitCNProfessionalDownList(this.drpCNProfessionalId, true); BLL.UnitWorkService.InitUnitWorkDownList(this.drpUnitWorkIds, 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.DesignDrawingsId = Request.Params["DesignDrawingsId"]; Model.Comprehensive_DesignDrawings designDrawings = BLL.DesignDrawingsService.GetDesignDrawingsById(this.DesignDrawingsId); if (designDrawings != null) { this.DesignDrawingsId = designDrawings.DesignDrawingsId; this.hdAttachUrl.Text = this.DesignDrawingsId; if (!string.IsNullOrEmpty(designDrawings.CNProfessionalId)) { this.drpCNProfessionalId.SelectedValue = designDrawings.CNProfessionalId; } if (!string.IsNullOrEmpty(designDrawings.UnitWorkId)) { this.drpUnitWorkIds.SelectedValueArray = designDrawings.UnitWorkId.Split(','); } this.txtDesignDrawingsCode.Text = designDrawings.DesignDrawingsCode; this.txtDesignDrawingsContent.Text = designDrawings.DesignDrawingsContent; this.txtEdition.Text = designDrawings.Edition; this.txtPageNumber.Text = designDrawings.PageNumber.HasValue ? designDrawings.PageNumber.ToString() : ""; this.txtReceiveDate.Text = designDrawings.ReceiveDate.HasValue ? string.Format("{0:yyyy-MM-dd}", designDrawings.ReceiveDate) : ""; this.txtSendDate.Text = designDrawings.SendDate.HasValue ? string.Format("{0:yyyy-MM-dd}", designDrawings.SendDate) : ""; if (!string.IsNullOrEmpty(designDrawings.ReceiveUnits)) { this.drpUnitIds.SelectedValueArray = designDrawings.ReceiveUnits.Split(','); } this.txtReceiveMan.Text = designDrawings.ReceiveMan; this.txtRemark.Text = designDrawings.Remark; this.txtRemarkCode.Text = designDrawings.RemarkCode; var currApprove = DesignDrawingsApproveService.GetCurrentApprove(designDrawings.DesignDrawingsId); if (currApprove != null) { //重新编制 编制人 可以 显示 提交 保存按钮 this.drpAudit.SelectedValue = currApprove.ApproveMan; if (currApprove.ApproveType == BLL.Const.Comprehensive_ReCompile && designDrawings.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 (designDrawings.Status == BLL.Const.Comprehensive_Compile && designDrawings.CompileMan == CurrUser.UserId) { this.btnSubmit.Hidden = false; this.btnSave.Hidden = false; } } } else { this.btnSave.Hidden = false; this.btnSubmit.Hidden = false; } } } /// /// 禁止编辑 /// public void Readonly() { this.txtDesignDrawingsCode.Readonly = true; this.txtDesignDrawingsContent.Readonly = true; this.drpCNProfessionalId.Readonly = true; this.txtEdition.Readonly = true; this.txtPageNumber.Readonly = true; this.txtReceiveDate.Readonly = true; this.txtReceiveMan.Readonly = true; this.txtRemark.Readonly = true; this.txtRemarkCode.Readonly = true; this.txtSendDate.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_DesignDrawings designDrawings = new Model.Comprehensive_DesignDrawings(); designDrawings.ProjectId = this.CurrUser.LoginProjectId; designDrawings.CNProfessionalId = this.drpCNProfessionalId.SelectedValue; designDrawings.DesignDrawingsCode = this.txtDesignDrawingsCode.Text.Trim(); designDrawings.DesignDrawingsContent = this.txtDesignDrawingsContent.Text.Trim(); designDrawings.Edition = this.txtEdition.Text.Trim(); designDrawings.PageNumber = Funs.GetNewInt(this.txtPageNumber.Text.Trim()); designDrawings.ReceiveDate = Funs.GetNewDateTime(this.txtReceiveDate.Text); designDrawings.SendDate = Funs.GetNewDateTime(this.txtSendDate.Text); designDrawings.ReceiveMan = this.txtReceiveMan.Text.Trim(); designDrawings.Remark = this.txtRemark.Text.Trim(); designDrawings.CompileMan = this.CurrUser.UserId; designDrawings.RemarkCode = this.txtRemarkCode.Text.Trim(); if (!string.IsNullOrEmpty(this.drpAudit.SelectedValue)) { designDrawings.AuditMan = drpAudit.SelectedValue; } //审核人 string ids = string.Empty; var lists = this.drpUnitWorkIds.SelectedValueArray; foreach (var item in lists) { ids += item + ","; } if (!string.IsNullOrEmpty(ids)) { ids = ids.Substring(0, ids.LastIndexOf(",")); } designDrawings.UnitWorkId = ids; string unitIds = string.Empty; var unitLists = this.drpUnitIds.SelectedValueArray; foreach (var item in unitLists) { unitIds += item + ","; } if (!string.IsNullOrEmpty(unitIds)) { unitIds = unitIds.Substring(0, unitIds.LastIndexOf(",")); } designDrawings.ReceiveUnits = unitIds; if (!string.IsNullOrEmpty(this.DesignDrawingsId)) { designDrawings.DesignDrawingsId = this.DesignDrawingsId; var sour = Funs.DB.AttachFile.FirstOrDefault(x => x.ToKeyId == this.DesignDrawingsId); if (sour == null || string.IsNullOrEmpty(sour.AttachUrl)) { Alert.ShowInTop("请上传附件!", MessageBoxIcon.Warning); return; } var model = Funs.DB.Comprehensive_DesignDrawings.Where(u => u.DesignDrawingsId == this.DesignDrawingsId).FirstOrDefault(); if (model != null) { designDrawings.Status = model.Status; } BLL.DesignDrawingsService.UpdateDesignDrawings(designDrawings); } else { if (!string.IsNullOrEmpty(this.hdAttachUrl.Text)) { designDrawings.DesignDrawingsId = this.hdAttachUrl.Text; } else { designDrawings.DesignDrawingsId = SQLHelper.GetNewID(typeof(Model.Comprehensive_DesignDrawings)); this.hdAttachUrl.Text = designDrawings.DesignDrawingsId; } var sour = Funs.DB.AttachFile.FirstOrDefault(x => x.ToKeyId == designDrawings.DesignDrawingsId); if (sour == null || string.IsNullOrEmpty(sour.AttachUrl)) { Alert.ShowInTop("请上传附件!", MessageBoxIcon.Warning); return; } designDrawings.Status = BLL.Const.Comprehensive_Compile; BLL.DesignDrawingsService.AddDesignDrawings(designDrawings); } 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_DesignDrawings designDrawings = new Model.Comprehensive_DesignDrawings(); designDrawings.ProjectId = this.CurrUser.LoginProjectId; designDrawings.CNProfessionalId = this.drpCNProfessionalId.SelectedValue; designDrawings.DesignDrawingsCode = this.txtDesignDrawingsCode.Text.Trim(); designDrawings.DesignDrawingsContent = this.txtDesignDrawingsContent.Text.Trim(); designDrawings.Edition = this.txtEdition.Text.Trim(); designDrawings.PageNumber = Funs.GetNewInt(this.txtPageNumber.Text.Trim()); designDrawings.ReceiveDate = Funs.GetNewDateTime(this.txtReceiveDate.Text); designDrawings.SendDate = Funs.GetNewDateTime(this.txtSendDate.Text); designDrawings.ReceiveMan = this.txtReceiveMan.Text.Trim(); designDrawings.Remark = this.txtRemark.Text.Trim(); designDrawings.CompileMan = this.CurrUser.UserId; designDrawings.RemarkCode = this.txtRemarkCode.Text.Trim(); if (!string.IsNullOrEmpty(this.drpAudit.SelectedValue)) { designDrawings.AuditMan = drpAudit.SelectedValue; } //审核人 string ids = string.Empty; var lists = this.drpUnitWorkIds.SelectedValueArray; foreach (var item in lists) { ids += item + ","; } if (!string.IsNullOrEmpty(ids)) { ids = ids.Substring(0, ids.LastIndexOf(",")); } designDrawings.UnitWorkId = ids; string unitIds = string.Empty; var unitLists = this.drpUnitIds.SelectedValueArray; foreach (var item in unitLists) { unitIds += item + ","; } if (!string.IsNullOrEmpty(unitIds)) { unitIds = unitIds.Substring(0, unitIds.LastIndexOf(",")); } designDrawings.ReceiveUnits = unitIds; if (!string.IsNullOrEmpty(this.DesignDrawingsId)) { designDrawings.DesignDrawingsId = this.DesignDrawingsId; var sour = Funs.DB.AttachFile.FirstOrDefault(x => x.ToKeyId == this.DesignDrawingsId); if (sour == null || string.IsNullOrEmpty(sour.AttachUrl)) { Alert.ShowInTop("请上传附件!", MessageBoxIcon.Warning); return; } //BLL.DesignDrawingsService.UpdateDesignDrawings(designDrawings); var oldDesignDrawings = Funs.DB.Comprehensive_DesignDrawings.Where(u => u.DesignDrawingsId == this.DesignDrawingsId).FirstOrDefault(); if (oldDesignDrawings == null) //数据库没有记录 直接点提交 当前状态为 审核状态 { designDrawings.CompileMan = this.CurrUser.UserId; designDrawings.Status = BLL.Const.Comprehensive_Audit; BLL.DesignDrawingsService.AddDesignDrawings(designDrawings); } else { designDrawings.CompileMan = oldDesignDrawings.CompileMan; if (oldDesignDrawings.Status == BLL.Const.Comprehensive_Compile)//编制状态提交变审核 { designDrawings.Status = BLL.Const.Comprehensive_Audit; } else if (oldDesignDrawings.Status == BLL.Const.Comprehensive_ReCompile)//重新编制状态提交变审核 { designDrawings.Status = BLL.Const.Comprehensive_Audit; } else //审核状态 提交 变 完成 或者 重新编制 { if (Convert.ToBoolean(rblIsAgree.SelectedValue)) { designDrawings.Status = BLL.Const.Comprehensive_Complete; } else { designDrawings.Status = BLL.Const.Comprehensive_ReCompile; } } BLL.DesignDrawingsService.UpdateDesignDrawings(designDrawings); } } else { if (!string.IsNullOrEmpty(this.hdAttachUrl.Text)) { designDrawings.DesignDrawingsId = this.hdAttachUrl.Text; } else { designDrawings.DesignDrawingsId = SQLHelper.GetNewID(typeof(Model.Comprehensive_DesignDrawings)); this.hdAttachUrl.Text = designDrawings.DesignDrawingsId; } var sour = Funs.DB.AttachFile.FirstOrDefault(x => x.ToKeyId == designDrawings.DesignDrawingsId); if (sour == null || string.IsNullOrEmpty(sour.AttachUrl)) { Alert.ShowInTop("请上传附件!", MessageBoxIcon.Warning); return; } designDrawings.Status = BLL.Const.Comprehensive_Audit; BLL.DesignDrawingsService.AddDesignDrawings(designDrawings); } #region 审核记录 var currApprove =DesignDrawingsApproveService.GetCurrentApprove(designDrawings.DesignDrawingsId); if (currApprove == null) //为获取到为 当前编制状态 直接提交 { var approve = new Model.Comprehensive_DesignDrawingsApprove(); approve.DesignDrawingsId = designDrawings.DesignDrawingsId; approve.ApproveMan = this.CurrUser.UserId; approve.ApproveType = Const.Comprehensive_Compile; approve.ApproveDate = DateTime.Now; DesignDrawingsApproveService.EditApprove(approve); //新增编制记录 Model.Comprehensive_DesignDrawingsApprove newApprove = new Model.Comprehensive_DesignDrawingsApprove(); newApprove.DesignDrawingsId = designDrawings.DesignDrawingsId; newApprove.ApproveMan = this.drpAudit.SelectedValue; newApprove.ApproveType = Const.InspectionManagement_Audit; DesignDrawingsApproveService.EditApprove(newApprove); //新增专业工程师审核记录 } else if (currApprove.ApproveMan == CurrUser.UserId) { if (currApprove.ApproveType == BLL.Const.Comprehensive_ReCompile) { currApprove.ApproveDate = DateTime.Now; //currApprove.IsAgree = true; DesignDrawingsApproveService.EditApprove(currApprove); //新增专业工程师审核记录 Model.Comprehensive_DesignDrawingsApprove newApprove = new Model.Comprehensive_DesignDrawingsApprove(); newApprove.DesignDrawingsId = designDrawings.DesignDrawingsId; newApprove.ApproveMan = this.drpAudit.SelectedValue; newApprove.ApproveType = Const.InspectionManagement_Audit; DesignDrawingsApproveService.EditApprove(newApprove); //新增专业工程师审核记录 } else { currApprove.ApproveDate = DateTime.Now; //更新审核时间 currApprove.IsAgree = Convert.ToBoolean(rblIsAgree.SelectedValue); currApprove.ApproveIdea = this.txtidea.Text; DesignDrawingsApproveService.EditApprove(currApprove); if (Convert.ToBoolean(rblIsAgree.SelectedValue)) //同意时 审批完成 { Model.Comprehensive_DesignDrawingsApprove reApprove = new Model.Comprehensive_DesignDrawingsApprove(); reApprove.DesignDrawingsId = currApprove.DesignDrawingsId; reApprove.ApproveDate = DateTime.Now.AddSeconds(10); reApprove.ApproveMan = CurrUser.UserId; reApprove.ApproveType = Const.Comprehensive_Complete; // reApprove.ApproveIdea = txtidea.Text; DesignDrawingsApproveService.EditApprove(reApprove); } else { Model.Comprehensive_DesignDrawingsApprove reApprove = new Model.Comprehensive_DesignDrawingsApprove(); reApprove.DesignDrawingsId = currApprove.DesignDrawingsId; reApprove.ApproveMan = designDrawings.CompileMan; reApprove.ApproveType = Const.Comprehensive_ReCompile; DesignDrawingsApproveService.EditApprove(reApprove); } } } PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); #endregion } /// /// 保存方法 /// #endregion #region 附件上传 /// /// 附件上传 /// /// /// protected void btnAttach_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.hdAttachUrl.Text)) //新增记录 { this.hdAttachUrl.Text = SQLHelper.GetNewID(typeof(Model.Comprehensive_DesignDrawings)); } Model.Comprehensive_DesignDrawings designDrawings = BLL.DesignDrawingsService.GetDesignDrawingsById(this.DesignDrawingsId); if (designDrawings == null || ((designDrawings.CompileMan == CurrUser.UserId && designDrawings.Status == BLL.Const.Comprehensive_Compile) || (designDrawings.CompileMan == CurrUser.UserId && designDrawings.Status == BLL.Const.Comprehensive_ReCompile))) { PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=0&toKeyId={0}&path=FileUpload/CQMS/designDrawings&menuId={1}", this.hdAttachUrl.Text, BLL.Const.DesignDrawingsMenuId))); } else { PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/CQMS/designDrawings&menuId={1}", this.hdAttachUrl.Text, BLL.Const.DesignDrawingsMenuId))); } } #endregion #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private void GetButtonPower() { if (Request.Params["value"] == "0") { return; } var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.DesignDrawingsMenuId); if (buttonList.Count() > 0) { if (buttonList.Contains(BLL.Const.BtnSave)) { this.btnSave.Hidden = false; } } } #endregion } }