using BLL; using BLL.CQMS.Comprehensive; using System; using System.Linq; namespace FineUIPro.Web.CQMS.Comprehensive { public partial class InspectionEquipmentEdit : PageBase { #region 定义变量 /// /// 主键 /// public string InspectionEquipmentId { get { return (string)ViewState["InspectionEquipmentId"]; } set { ViewState["InspectionEquipmentId"] = value; } } #endregion #region 加载 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GetButtonPower(); BLL.UnitService.InitUnitDownList(this.drpUnitId, this.CurrUser.LoginProjectId, true); this.drpUnitId.SelectedValue = CurrUser.UnitId; BLL.CNProfessionalService.InitCNProfessionalDownList(this.drpCNProfessionalId, true); BLL.InspectionEquipmentService.InitAttributeDropDownList(this.drpAttribute, true); LoadAuditSelect(); this.agree.Hidden = true; this.options.Hidden = true; this.InspectionEquipmentId = Request.Params["InspectionEquipmentId"]; var inspectionEquipment = BLL.InspectionEquipmentService.GetInspectionEquipmentById(this.InspectionEquipmentId); if (inspectionEquipment != null) { this.InspectionEquipmentId = inspectionEquipment.InspectionEquipmentId; if (!string.IsNullOrEmpty(inspectionEquipment.UnitId)) { this.drpUnitId.SelectedValue = inspectionEquipment.UnitId; } this.txtInspectionCode.Text = inspectionEquipment.InspectionCode; if (!string.IsNullOrEmpty(inspectionEquipment.CNProfessionalId)) { this.drpCNProfessionalId.SelectedValue = inspectionEquipment.CNProfessionalId; } this.txtInspectionName.Text = inspectionEquipment.InspectionName; this.txtSpecifications.Text = inspectionEquipment.Specifications; this.txtSupplier.Text = inspectionEquipment.Supplier; if (inspectionEquipment.Counts != null) { this.txtCounts.Text = Convert.ToString(inspectionEquipment.Counts); } this.txtUnit.Text = inspectionEquipment.Unit; if (!string.IsNullOrEmpty(inspectionEquipment.EquipmentOrMatail)) { this.drpEquipmentOrMatail.SelectedValue = inspectionEquipment.EquipmentOrMatail; } if (inspectionEquipment.SamplingCount != null) { this.txtSamplingCount.Text = Convert.ToString(inspectionEquipment.SamplingCount); } if (!string.IsNullOrEmpty(inspectionEquipment.Attribute)) { this.drpAttribute.SelectedValue = inspectionEquipment.Attribute; } if (!string.IsNullOrEmpty(inspectionEquipment.SamplingResult)) { this.drpSamplingResult.SelectedValue = inspectionEquipment.SamplingResult; } this.txtInspectionDate.Text = inspectionEquipment.InspectionDate.HasValue ? string.Format("{0:yyyy-MM-dd}", inspectionEquipment.InspectionDate) : ""; this.txtRemarkCode.Text = inspectionEquipment.RemarkCode; this.txtEquipmentNo.Text = inspectionEquipment.EquipmentNO; this.txtUsedPlace.Text = inspectionEquipment.UsedPlace; var currApprove = InspectionEquipmentApproveService.GetCurrentApprove(inspectionEquipment.InspectionEquipmentId); if(currApprove != null) { this.drpAudit.SelectedValue = currApprove.ApproveMan; //重新编制 编制人 可以 显示 提交 保存按钮 if (currApprove.ApproveType == BLL.Const.Comprehensive_ReCompile && inspectionEquipment.CompileMan == CurrUser.UserId) { this.btnSubmit.Hidden = false; this.btnSave.Hidden = false; }//审核状态 审核人 可以显示 提交 保存按钮 else if (currApprove.ApproveType== BLL.Const.Comprehensive_Audit&&currApprove.ApproveMan== CurrUser.UserId) { //审核状态不可编辑 this.txtInspectionName.Readonly = true; this.drpUnitId.Readonly = true; this.drpCNProfessionalId.Readonly = true; this.txtSpecifications.Readonly = true; this.txtSupplier.Readonly = true; this.drpAttribute.Readonly = true; this.drpSamplingResult.Readonly = true; this.txtInspectionDate.Readonly = true; this.txtRemarkCode.Readonly = true; this.txtEquipmentNo.Readonly = true; this.txtUsedPlace.Readonly = true; this.drpAudit.Readonly = true; this.txtSamplingCount.Readonly = true; this.txtCounts.Readonly = true; this.agree.Hidden = false; this.options.Hidden = false; this.btnSubmit.Hidden = false; this.btnSave.Hidden = false; } }//没有当前审核人,已完成状态 或者 待提交状态 else { if(inspectionEquipment.Status == BLL.Const.Comprehensive_Compile && inspectionEquipment.CompileMan == CurrUser.UserId) { this.btnSubmit.Hidden = false; this.btnSave.Hidden = false; } } //var res = InspectionEquipmentApproveService.GetState(inspectionEquipment.InspectionEquipmentId); //if (inspectionEquipment.CompileMan != CurrUser.UserId) //不是创建用户禁止编辑 //{ // Readonly(); //} //if (res != null) //{ // if (res.ApproveType.Trim() == BLL.Const.Comprehensive_Audit) // { // this.txtInspectionName.Readonly = true; // this.drpUnitId.Readonly = true; // this.drpCNProfessionalId.Readonly = true; // this.txtSpecifications.Readonly = true; // this.txtSupplier.Readonly = true; // this.drpAttribute.Readonly = true; // this.drpSamplingResult.Readonly = true; // this.txtInspectionDate.Readonly = true; // this.txtRemarkCode.Readonly = true; // this.txtEquipmentNo.Readonly = true; // this.txtUsedPlace.Readonly = true; // this.drpAudit.Readonly = true; // this.txtSamplingCount.Readonly = true; // this.txtCounts.Readonly = true; // this.btnAttach.Enabled = false; // this.btnSave.Enabled = false; // if (res.ApproveMan == CurrUser.UserId) // { // this.agree.Hidden = false; // this.options.Hidden = false; // this.drpAudit.Hidden = true; // this.btnSubmit.Enabled = true; // } // } // else if (res.ApproveType.Trim() == BLL.Const.Comprehensive_ReCompile) //重报 // { // } // else if (res.ApproveType.Trim() == BLL.Const.Comprehensive_Complete) //已完成 // { // Readonly(); // } //} } else { this.txtInspectionDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now); this.btnSave.Hidden = false; this.btnSubmit.Hidden = false; } } } /// /// 禁止编辑 /// public void Readonly() { this.txtInspectionName.Readonly = true; this.drpUnitId.Readonly = true; this.drpCNProfessionalId.Readonly = true; this.txtSpecifications.Readonly = true; this.txtSupplier.Readonly = true; this.drpAttribute.Readonly = true; this.drpSamplingResult.Readonly = true; this.txtInspectionDate.Readonly = true; this.txtRemarkCode.Readonly = true; this.txtEquipmentNo.Readonly = true; this.txtUsedPlace.Readonly = true; this.drpAudit.Readonly = true; this.txtSamplingCount.Readonly = true; this.txtCounts.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 (this.drpUnitId.SelectedValue == BLL.Const._Null) { Alert.ShowInTop("请选择报验单位!", MessageBoxIcon.Warning); return; } Model.Comprehensive_InspectionEquipment newInspectionEquipment = new Model.Comprehensive_InspectionEquipment(); newInspectionEquipment.ProjectId = this.CurrUser.LoginProjectId; newInspectionEquipment.UnitId = this.drpUnitId.SelectedValue; newInspectionEquipment.InspectionCode = this.txtInspectionCode.Text.Trim(); if (this.drpCNProfessionalId.SelectedValue != BLL.Const._Null) { newInspectionEquipment.CNProfessionalId = this.drpCNProfessionalId.SelectedValue; } newInspectionEquipment.InspectionName = this.txtInspectionName.Text.Trim(); newInspectionEquipment.Specifications = this.txtSpecifications.Text.Trim(); newInspectionEquipment.Supplier = this.txtSupplier.Text.Trim(); newInspectionEquipment.EquipmentNO = this.txtEquipmentNo.Text.Trim(); newInspectionEquipment.RemarkCode = this.txtRemarkCode.Text.Trim(); newInspectionEquipment.Counts = this.txtCounts.Text.Trim(); newInspectionEquipment.Unit = this.txtUnit.Text.Trim(); newInspectionEquipment.SamplingCount = this.txtSamplingCount.Text.Trim(); newInspectionEquipment.UsedPlace = this.txtUsedPlace.Text.Trim(); newInspectionEquipment.EquipmentOrMatail = drpEquipmentOrMatail.SelectedValue; if (!string.IsNullOrEmpty(this.drpAudit.SelectedValue)) { newInspectionEquipment.AuditMan = drpAudit.SelectedValue; } //审核人 if (this.drpAttribute.SelectedValue != BLL.Const._Null) { newInspectionEquipment.Attribute = this.drpAttribute.SelectedValue; } if (this.drpSamplingResult.SelectedValue != BLL.Const._Null) { newInspectionEquipment.SamplingResult = this.drpSamplingResult.SelectedValue; } if (!string.IsNullOrEmpty(this.txtInspectionDate.Text)) { newInspectionEquipment.InspectionDate = Convert.ToDateTime(this.txtInspectionDate.Text); } if (string.IsNullOrEmpty(this.InspectionEquipmentId)) { newInspectionEquipment.InspectionEquipmentId = SQLHelper.GetNewID(typeof(Model.Comprehensive_InspectionPerson)); newInspectionEquipment.CompileMan = this.CurrUser.UserId; newInspectionEquipment.CompileDate = DateTime.Now; newInspectionEquipment.Status = BLL.Const.Comprehensive_Compile; var sour = Funs.DB.AttachFile.FirstOrDefault(x => x.ToKeyId == newInspectionEquipment.InspectionEquipmentId); if (sour == null || string.IsNullOrEmpty(sour.AttachUrl)) { Alert.ShowInTop("请上传附件!", MessageBoxIcon.Warning); return; } BLL.InspectionEquipmentService.AddInspectionEquipment(newInspectionEquipment); } else { newInspectionEquipment.InspectionEquipmentId = this.InspectionEquipmentId; var sour = Funs.DB.AttachFile.FirstOrDefault(x => x.ToKeyId == this.InspectionEquipmentId); if (sour == null || string.IsNullOrEmpty(sour.AttachUrl)) { Alert.ShowInTop("请上传附件!", MessageBoxIcon.Warning); return; } var oldInspectionEquipment = Funs.DB.Comprehensive_InspectionEquipment.Where(u => u.InspectionEquipmentId == this.InspectionEquipmentId).FirstOrDefault(); if (oldInspectionEquipment == null) { newInspectionEquipment.CompileMan = this.CurrUser.UserId; newInspectionEquipment.CompileDate = DateTime.Now; newInspectionEquipment.Status = BLL.Const.Comprehensive_Compile; BLL.InspectionEquipmentService.AddInspectionEquipment(newInspectionEquipment); } else { newInspectionEquipment.CompileMan = oldInspectionEquipment.CompileMan; newInspectionEquipment.CompileDate = oldInspectionEquipment.CompileDate; newInspectionEquipment.Status = oldInspectionEquipment.Status; BLL.InspectionEquipmentService.UpdateInspectionEquipment(newInspectionEquipment); } } //else //{ // newInspectionEquipment.InspectionEquipmentId = this.InspectionEquipmentId; // var sour = Funs.DB.AttachFile.FirstOrDefault(x => x.ToKeyId == this.InspectionEquipmentId); // if (sour == null || string.IsNullOrEmpty(sour.AttachUrl)) // { // Alert.ShowInTop("请上传附件!", MessageBoxIcon.Warning); // return; // } // BLL.InspectionEquipmentService.UpdateInspectionEquipment(newInspectionEquipment); //} //#region 审核记录 //var approve = InspectionEquipmentApproveService.GetApproveByApproveMan(newInspectionEquipment.InspectionEquipmentId, CurrUser.UserId); //if (approve == null) //未添加审核信息时 //{ // approve = new Model.Comprehensive_InspectionEquipmentApprove(); // approve.InspectionEquipmentId = newInspectionEquipment.InspectionEquipmentId; // approve.ApproveMan = this.CurrUser.UserId; // approve.ApproveType = Const.Comprehensive_Compile; // approve.ApproveDate = DateTime.Now; // InspectionEquipmentApproveService.EditApprove(approve); //新增编制记录 //} //else //{ // approve.IsAgree = Convert.ToBoolean(rblIsAgree.SelectedValue); // approve.ApproveIdea = txtidea.Text.Trim(); //} //#endregion ShowNotify("保存成功!", MessageBoxIcon.Success); PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } #endregion protected void btnSubmit_Click(object sender, EventArgs e) { if (this.drpUnitId.SelectedValue == BLL.Const._Null) { Alert.ShowInTop("请选择报验单位!", MessageBoxIcon.Warning); return; } Model.Comprehensive_InspectionEquipment newInspectionEquipment = new Model.Comprehensive_InspectionEquipment(); newInspectionEquipment.ProjectId = this.CurrUser.LoginProjectId; newInspectionEquipment.UnitId = this.drpUnitId.SelectedValue; newInspectionEquipment.InspectionCode = this.txtInspectionCode.Text.Trim(); if (this.drpCNProfessionalId.SelectedValue != BLL.Const._Null) { newInspectionEquipment.CNProfessionalId = this.drpCNProfessionalId.SelectedValue; } newInspectionEquipment.InspectionName = this.txtInspectionName.Text.Trim(); newInspectionEquipment.Specifications = this.txtSpecifications.Text.Trim(); newInspectionEquipment.Supplier = this.txtSupplier.Text.Trim(); newInspectionEquipment.EquipmentNO = this.txtEquipmentNo.Text.Trim(); newInspectionEquipment.RemarkCode = this.txtRemarkCode.Text.Trim(); newInspectionEquipment.Counts = this.txtCounts.Text.Trim(); newInspectionEquipment.Unit = this.txtUnit.Text.Trim(); newInspectionEquipment.SamplingCount = this.txtSamplingCount.Text.Trim(); newInspectionEquipment.UsedPlace = this.txtUsedPlace.Text.Trim(); if (!string.IsNullOrEmpty(this.drpAudit.SelectedValue)) { newInspectionEquipment.AuditMan = drpAudit.SelectedValue; } //审核人 if (this.drpAttribute.SelectedValue != BLL.Const._Null) { newInspectionEquipment.Attribute = this.drpAttribute.SelectedValue; } if (this.drpSamplingResult.SelectedValue != BLL.Const._Null) { newInspectionEquipment.SamplingResult = this.drpSamplingResult.SelectedValue; } if (!string.IsNullOrEmpty(this.txtInspectionDate.Text)) { newInspectionEquipment.InspectionDate = Convert.ToDateTime(this.txtInspectionDate.Text); } if (string.IsNullOrEmpty(this.InspectionEquipmentId)) { newInspectionEquipment.CompileMan = this.CurrUser.UserId; newInspectionEquipment.CompileDate = DateTime.Now; newInspectionEquipment.Status = BLL.Const.Comprehensive_Audit; newInspectionEquipment.InspectionEquipmentId = SQLHelper.GetNewID(typeof(Model.Comprehensive_InspectionPerson)); var sour = Funs.DB.AttachFile.FirstOrDefault(x => x.ToKeyId == newInspectionEquipment.InspectionEquipmentId); if (sour == null || string.IsNullOrEmpty(sour.AttachUrl)) { Alert.ShowInTop("请上传附件!", MessageBoxIcon.Warning); return; } BLL.InspectionEquipmentService.AddInspectionEquipment(newInspectionEquipment); } else { var sour = Funs.DB.AttachFile.FirstOrDefault(x => x.ToKeyId == this.InspectionEquipmentId); if (sour == null || string.IsNullOrEmpty(sour.AttachUrl)) { Alert.ShowInTop("请上传附件!", MessageBoxIcon.Warning); return; } newInspectionEquipment.InspectionEquipmentId = this.InspectionEquipmentId; var oldInspectionEquipment = Funs.DB.Comprehensive_InspectionEquipment.Where(u => u.InspectionEquipmentId == this.InspectionEquipmentId).FirstOrDefault(); if (oldInspectionEquipment == null) //数据库没有记录 直接点提交 当前状态为 审核状态 { newInspectionEquipment.CompileMan = this.CurrUser.UserId; newInspectionEquipment.CompileDate = DateTime.Now; newInspectionEquipment.Status = BLL.Const.Comprehensive_Audit; BLL.InspectionEquipmentService.AddInspectionEquipment(newInspectionEquipment); } else { newInspectionEquipment.CompileMan = oldInspectionEquipment.CompileMan; newInspectionEquipment.CompileDate = oldInspectionEquipment.CompileDate; if(oldInspectionEquipment.Status==BLL.Const.Comprehensive_Compile)//编制状态提交变审核 { newInspectionEquipment.Status = BLL.Const.Comprehensive_Audit; } else if (oldInspectionEquipment.Status == BLL.Const.Comprehensive_ReCompile)//重新编制状态提交变审核 { newInspectionEquipment.Status = BLL.Const.Comprehensive_Audit; } else //审核状态 提交 变 完成 或者 重新编制 { if (Convert.ToBoolean(rblIsAgree.SelectedValue)) { newInspectionEquipment.Status = BLL.Const.Comprehensive_Complete; } else { newInspectionEquipment.Status = BLL.Const.Comprehensive_ReCompile; } } BLL.InspectionEquipmentService.UpdateInspectionEquipment(newInspectionEquipment); } } #region 审核记录 var currApprove = InspectionEquipmentApproveService.GetCurrentApprove(newInspectionEquipment.InspectionEquipmentId); if (currApprove == null) //为获取到为 当前编制状态 直接提交 { var approve = new Model.Comprehensive_InspectionEquipmentApprove(); approve.InspectionEquipmentId = newInspectionEquipment.InspectionEquipmentId; approve.ApproveMan = this.CurrUser.UserId; approve.ApproveType = Const.Comprehensive_Compile; approve.ApproveDate = DateTime.Now; InspectionEquipmentApproveService.EditApprove(approve); //新增编制记录 Model.Comprehensive_InspectionEquipmentApprove newApprove = new Model.Comprehensive_InspectionEquipmentApprove(); newApprove.InspectionEquipmentId = newInspectionEquipment.InspectionEquipmentId; newApprove.ApproveMan = this.drpAudit.SelectedValue; newApprove.ApproveType = Const.InspectionManagement_Audit; InspectionEquipmentApproveService.EditApprove(newApprove); //新增专业工程师审核记录 }else if (currApprove.ApproveMan == CurrUser.UserId) { if (currApprove.ApproveType == BLL.Const.Comprehensive_ReCompile) { currApprove.ApproveDate = DateTime.Now; //currApprove.IsAgree = true; InspectionEquipmentApproveService.EditApprove(currApprove); //新增专业工程师审核记录 Model.Comprehensive_InspectionEquipmentApprove newApprove = new Model.Comprehensive_InspectionEquipmentApprove(); newApprove.InspectionEquipmentId = newInspectionEquipment.InspectionEquipmentId; newApprove.ApproveMan = this.drpAudit.SelectedValue; newApprove.ApproveType = Const.InspectionManagement_Audit; InspectionEquipmentApproveService.EditApprove(newApprove); //新增专业工程师审核记录 } else { currApprove.ApproveDate = DateTime.Now; //更新审核时间 currApprove.IsAgree = Convert.ToBoolean(rblIsAgree.SelectedValue); currApprove.ApproveIdea = this.txtidea.Text; InspectionEquipmentApproveService.EditApprove(currApprove); if (Convert.ToBoolean(rblIsAgree.SelectedValue)) //同意时 审批完成 { Model.Comprehensive_InspectionEquipmentApprove reApprove = new Model.Comprehensive_InspectionEquipmentApprove(); reApprove.InspectionEquipmentId = currApprove.InspectionEquipmentId; reApprove.ApproveDate = DateTime.Now.AddSeconds(10); reApprove.ApproveMan = CurrUser.UserId; reApprove.ApproveType = Const.Comprehensive_Complete; //reApprove.ApproveIdea = txtidea.Text; InspectionEquipmentApproveService.EditApprove(reApprove); } else { Model.Comprehensive_InspectionEquipmentApprove reApprove = new Model.Comprehensive_InspectionEquipmentApprove(); reApprove.InspectionEquipmentId = currApprove.InspectionEquipmentId; reApprove.ApproveMan = newInspectionEquipment.CompileMan; reApprove.ApproveType = Const.Comprehensive_ReCompile; InspectionEquipmentApproveService.EditApprove(reApprove); } } } #endregion ShowNotify("保存成功!", MessageBoxIcon.Success); PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } #region 附件上传 /// /// 附件上传 /// /// /// protected void btnAttach_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.InspectionEquipmentId)) //新增记录 { this.InspectionEquipmentId = SQLHelper.GetNewID(typeof(Model.Comprehensive_InspectionEquipment)); } var oldInspectionEquipment = Funs.DB.Comprehensive_InspectionEquipment.Where(u => u.InspectionEquipmentId == this.InspectionEquipmentId).FirstOrDefault(); //if (oldInspectionEquipment == null || ((oldInspectionEquipment.CompileMan == CurrUser.UserId && oldInspectionEquipment.Status == BLL.Const.Comprehensive_Compile) || (oldInspectionEquipment.CompileMan == CurrUser.UserId && oldInspectionEquipment.Status == BLL.Const.Comprehensive_ReCompile))) //{ PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=0&toKeyId={0}&path=FileUpload/CQMS/InspectionEquipment&menuId={1}", this.InspectionEquipmentId, BLL.Const.InspectionEquipmentMenuId))); //} //else //{ PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/CQMS/InspectionEquipment&menuId={1}", this.InspectionEquipmentId, BLL.Const.InspectionEquipmentMenuId))); //} } #endregion #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private void GetButtonPower() { if (Request.Params["value"] == "0") { return; } var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.InspectionEquipmentMenuId); if (buttonList.Count() > 0) { if (buttonList.Contains(BLL.Const.BtnSave)) { this.btnSave.Hidden = false; } } } #endregion } }