using BLL; using System; using System.Linq; using System.Web.UI.WebControls; namespace FineUIPro.Web.CQMS.Comprehensive { public partial class DataReceivingDocEdit : PageBase { #region 定义变量 /// /// 主键 /// public string DataReceivingDocId { get { return (string)ViewState["DataReceivingDocId"]; } set { ViewState["DataReceivingDocId"] = value; } } #endregion #region 加载专业工程师 /// /// 加载专业工程师 /// 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 禁止编辑 /// /// 禁止编辑 /// public void Readonly() { this.txtFileCode.Readonly = true; this.txtFileName.Readonly = true; this.txtReceiveDate.Readonly = true; this.txtFileType.Readonly = true; this.drpCNProfessionalId.Readonly = true; //this.drpSendUnit.Readonly = true; this.drpSendUnitId.Readonly = true; this.txtCopies.Readonly = true; this.txtSendMan.Readonly = true; this.txtDocumentHandler.Readonly = true; this.txtSendDate.Readonly = true; this.drpReceiveUnit.Readonly = true; this.txtReceiveMan.Readonly = true; this.rblIsReply.Readonly = true; this.txtReturnWuhuangDate.Readonly = true; this.txtRetrunWuhuangCopies.Readonly = true; this.drpIssueToUnit.Readonly = true; this.txtIssueCopies.Readonly = true; this.txtIssueUnitReceiver.Readonly = true; this.rblIsOnFile.Readonly = true; this.drpAudit.Readonly = true; this.btnAttach.Enabled = false; } #endregion #region 加载 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GetButtonPower(); BLL.UnitService.InitUnitDownList(this.drpSendUnitId, this.CurrUser.LoginProjectId, false);//发件单位 BLL.UnitService.InitUnitDownList(this.drpReceiveUnit, this.CurrUser.LoginProjectId, false);//接收单位 BLL.UnitService.InitUnitDownList(this.drpIssueToUnit, this.CurrUser.LoginProjectId, false);//下发至单位 BLL.CNProfessionalService.InitCNProfessionalDownList(this.drpCNProfessionalId, true);//专业 LoadAuditSelect(); this.agree.Hidden = true; this.options.Hidden = true; this.btnSave.Hidden = true; this.btnSubmit.Hidden = true; this.DataReceivingDocId = Request.Params["DataReceivingDocId"]; Model.Comprehensive_DataReceivingDoc dataReceivingDoc = BLL.DataReceivingDocService.GetDataReceivingDocById(this.DataReceivingDocId); if (dataReceivingDoc != null) { this.hdAttachUrl.Text = this.DataReceivingDocId; this.txtFileCode.Text = dataReceivingDoc.FileCode; this.txtFileName.Text = dataReceivingDoc.FileName; this.txtReceiveDate.Text = dataReceivingDoc.ReceiveDate.HasValue ? string.Format("{0:yyyy-MM-dd}", dataReceivingDoc.ReceiveDate) : ""; this.txtFileType.Text = dataReceivingDoc.FileType; if (!string.IsNullOrEmpty(dataReceivingDoc.SendUnit)) { //this.drpSendUnit.SelectedValueArray = dataReceivingDoc.SendUnit.Split(','); this.drpSendUnitId.SelectedValue = dataReceivingDoc.SendUnit; } if (!string.IsNullOrEmpty(dataReceivingDoc.CNProfessionalId)) { this.drpCNProfessionalId.SelectedValue = dataReceivingDoc.CNProfessionalId; } this.txtCopies.Text = dataReceivingDoc.Copies.HasValue ? dataReceivingDoc.Copies.ToString() : ""; this.txtSendMan.Text = dataReceivingDoc.SendMan; this.txtDocumentHandler.Text = dataReceivingDoc.DocumentHandler; this.txtSendDate.Text = dataReceivingDoc.SendDate.HasValue ? string.Format("{0:yyyy-MM-dd}", dataReceivingDoc.SendDate) : ""; if (!string.IsNullOrEmpty(dataReceivingDoc.ReceiveUnit)) { this.drpReceiveUnit.SelectedValueArray = dataReceivingDoc.ReceiveUnit.Split(','); } this.txtReceiveMan.Text = dataReceivingDoc.ReceiveMan; if (dataReceivingDoc.IsReply == true) { this.rblIsReply.SelectedValue = "true"; } else { this.rblIsReply.SelectedValue = "false"; } this.txtReturnWuhuangDate.Text = dataReceivingDoc.ReturnWuhuangDate.HasValue ? string.Format("{0:yyyy-MM-dd}", dataReceivingDoc.ReturnWuhuangDate) : ""; this.txtRetrunWuhuangCopies.Text = dataReceivingDoc.RetrunWuhuangCopies.HasValue ? dataReceivingDoc.RetrunWuhuangCopies.ToString() : ""; if (!string.IsNullOrEmpty(dataReceivingDoc.IssueToUnit)) { this.drpIssueToUnit.SelectedValueArray = dataReceivingDoc.IssueToUnit.Split(','); } this.txtIssueCopies.Text = dataReceivingDoc.IssueCopies.HasValue ? dataReceivingDoc.IssueCopies.ToString() : ""; this.txtIssueUnitReceiver.Text = dataReceivingDoc.IssueUnitReceiver; if (dataReceivingDoc.IsOnFile == true) { this.rblIsOnFile.SelectedValue = "true"; } else { this.rblIsOnFile.SelectedValue = "false"; } var currApprove = DataReceivingDocApproveService.GetCurrentApprove(dataReceivingDoc.DataReceivingDocId); if (currApprove != null) { //重新编制 编制人 可以 显示 提交 保存按钮 this.drpAudit.SelectedValue = currApprove.ApproveMan; if (currApprove.ApproveType == BLL.Const.Comprehensive_ReCompile && dataReceivingDoc.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 (dataReceivingDoc.Status == BLL.Const.Comprehensive_Compile && dataReceivingDoc.CompileMan == CurrUser.UserId) { this.btnSubmit.Hidden = false; this.btnSave.Hidden = false; } } } else { this.btnSave.Hidden = false; this.btnSubmit.Hidden = false; } } } #endregion #region 保存、提交 /// /// 保存按钮 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { if (drpSendUnitId.SelectedValue==BLL.Const._Null) { Alert.ShowInTop("请选择发件单位!", MessageBoxIcon.Warning); return; } if (drpCNProfessionalId.SelectedValue == BLL.Const._Null) { Alert.ShowInTop("请选择专业!", MessageBoxIcon.Warning); return; } Model.Comprehensive_DataReceivingDoc dataReceivingDoc = new Model.Comprehensive_DataReceivingDoc(); dataReceivingDoc.ProjectId = this.CurrUser.LoginProjectId; dataReceivingDoc.FileCode = this.txtFileCode.Text.Trim(); dataReceivingDoc.FileName = this.txtFileName.Text.Trim(); dataReceivingDoc.ReceiveDate = Funs.GetNewDateTime(this.txtReceiveDate.Text.Trim()); dataReceivingDoc.FileType = this.txtFileType.Text.Trim(); dataReceivingDoc.CNProfessionalId = this.drpCNProfessionalId.SelectedValue; //string unitIds = string.Empty; //var unitList = this.drpSendUnit.SelectedValueArray; //foreach (var item in unitList) //{ // unitIds += item + ","; //} //if (!string.IsNullOrEmpty(unitIds)) //{ // unitIds = unitIds.Substring(0, unitIds.LastIndexOf(",")); //} //dataReceivingDoc.SendUnit = unitIds; dataReceivingDoc.SendUnit = this.drpSendUnitId.SelectedValue; dataReceivingDoc.SendMan = this.txtSendMan.Text.Trim(); dataReceivingDoc.Copies = Funs.GetNewInt(this.txtCopies.Text.Trim()); dataReceivingDoc.DocumentHandler = this.txtDocumentHandler.Text.Trim(); dataReceivingDoc.SendDate = Funs.GetNewDateTime(this.txtSendDate.Text); string receivingUnits = string.Empty; var receivingUnitList = this.drpReceiveUnit.SelectedValueArray; foreach (var item in receivingUnitList) { receivingUnits += item + ","; } if (!string.IsNullOrEmpty(receivingUnits)) { receivingUnits = receivingUnits.Substring(0, receivingUnits.LastIndexOf(",")); } dataReceivingDoc.ReceiveUnit = receivingUnits; dataReceivingDoc.ReceiveMan = this.txtReceiveMan.Text.Trim(); dataReceivingDoc.IsReply = Convert.ToBoolean(this.rblIsReply.SelectedValue); dataReceivingDoc.ReturnWuhuangDate = Funs.GetNewDateTime(this.txtReturnWuhuangDate.Text.Trim()); dataReceivingDoc.RetrunWuhuangCopies = Funs.GetNewInt(this.txtRetrunWuhuangCopies.Text.Trim()); string issueToUnits = string.Empty; var issueToUnitLists = this.drpIssueToUnit.SelectedValueArray; foreach (var item in issueToUnitLists) { issueToUnits += item + ","; } if (!string.IsNullOrEmpty(issueToUnits)) { issueToUnits = issueToUnits.Substring(0, issueToUnits.LastIndexOf(",")); } dataReceivingDoc.IssueToUnit = issueToUnits; dataReceivingDoc.IssueCopies = Funs.GetNewInt(this.txtIssueCopies.Text.Trim()); dataReceivingDoc.IssueUnitReceiver = this.txtIssueUnitReceiver.Text.Trim(); dataReceivingDoc.IsOnFile = Convert.ToBoolean(this.rblIsOnFile.SelectedValue); if (!string.IsNullOrEmpty(this.drpAudit.SelectedValue)) { dataReceivingDoc.AuditMan = drpAudit.SelectedValue; } //审核人 if (string.IsNullOrEmpty(this.DataReceivingDocId)) { if (!string.IsNullOrEmpty(this.hdAttachUrl.Text)) { dataReceivingDoc.DataReceivingDocId = this.hdAttachUrl.Text; } else { dataReceivingDoc.DataReceivingDocId = SQLHelper.GetNewID(typeof(Model.Comprehensive_DataReceivingDoc)); this.hdAttachUrl.Text = dataReceivingDoc.DataReceivingDocId; } //var sour = Funs.DB.AttachFile.FirstOrDefault(x => x.ToKeyId == dataReceivingDoc.DataReceivingDocId); //if (sour == null || string.IsNullOrEmpty(sour.AttachUrl)) //{ // Alert.ShowInTop("请上传附件!", MessageBoxIcon.Warning); // return; //} dataReceivingDoc.CompileMan = this.CurrUser.UserId; dataReceivingDoc.CompileDate = DateTime.Now; dataReceivingDoc.Status = BLL.Const.Comprehensive_Compile; dataReceivingDoc.DataReceivingDocId = SQLHelper.GetNewID(typeof(Model.Comprehensive_DataReceivingDoc)); BLL.DataReceivingDocService.AddDataReceivingDoc(dataReceivingDoc); } else { dataReceivingDoc.DataReceivingDocId = this.DataReceivingDocId; var model = Funs.DB.Comprehensive_DataReceivingDoc.Where(u => u.DataReceivingDocId == this.DataReceivingDocId).FirstOrDefault(); if (model != null) { dataReceivingDoc.Status = model.Status; } else { dataReceivingDoc.Status = BLL.Const.Comprehensive_Compile; } //var sour = Funs.DB.AttachFile.FirstOrDefault(x => x.ToKeyId == this.DataReceivingDocId); //if (sour == null || string.IsNullOrEmpty(sour.AttachUrl)) //{ // Alert.ShowInTop("请上传附件!", MessageBoxIcon.Warning); // return; //} BLL.DataReceivingDocService.UpdateDataReceivingDoc(dataReceivingDoc); } 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_DataReceivingDoc dataReceivingDoc = new Model.Comprehensive_DataReceivingDoc(); dataReceivingDoc.ProjectId = this.CurrUser.LoginProjectId; dataReceivingDoc.FileCode = this.txtFileCode.Text.Trim(); dataReceivingDoc.FileName = this.txtFileName.Text.Trim(); dataReceivingDoc.ReceiveDate = Funs.GetNewDateTime(this.txtReceiveDate.Text.Trim()); dataReceivingDoc.FileType = this.txtFileType.Text.Trim(); dataReceivingDoc.CNProfessionalId = this.drpCNProfessionalId.SelectedValue; //string unitIds = string.Empty; //var unitList = this.drpSendUnit.SelectedValueArray; //foreach (var item in unitList) //{ // unitIds += item + ","; //} //if (!string.IsNullOrEmpty(unitIds)) //{ // unitIds = unitIds.Substring(0, unitIds.LastIndexOf(",")); //} dataReceivingDoc.SendUnit = drpSendUnitId.SelectedValue; dataReceivingDoc.SendMan = this.txtSendMan.Text.Trim(); dataReceivingDoc.Copies = Funs.GetNewInt(this.txtCopies.Text.Trim()); dataReceivingDoc.DocumentHandler = this.txtDocumentHandler.Text.Trim(); dataReceivingDoc.SendDate = Funs.GetNewDateTime(this.txtSendDate.Text); string receivingUnits = string.Empty; var receivingUnitList = this.drpReceiveUnit.SelectedValueArray; foreach (var item in receivingUnitList) { receivingUnits += item + ","; } if (!string.IsNullOrEmpty(receivingUnits)) { receivingUnits = receivingUnits.Substring(0, receivingUnits.LastIndexOf(",")); } dataReceivingDoc.ReceiveUnit = receivingUnits; dataReceivingDoc.ReceiveMan = this.txtReceiveMan.Text.Trim(); dataReceivingDoc.IsReply = Convert.ToBoolean(this.rblIsReply.SelectedValue); dataReceivingDoc.ReturnWuhuangDate = Funs.GetNewDateTime(this.txtReturnWuhuangDate.Text.Trim()); dataReceivingDoc.RetrunWuhuangCopies = Funs.GetNewInt(this.txtRetrunWuhuangCopies.Text.Trim()); string issueToUnits = string.Empty; var issueToUnitLists = this.drpIssueToUnit.SelectedValueArray; foreach (var item in issueToUnitLists) { issueToUnits += item + ","; } if (!string.IsNullOrEmpty(issueToUnits)) { issueToUnits = issueToUnits.Substring(0, issueToUnits.LastIndexOf(",")); } dataReceivingDoc.IssueToUnit = issueToUnits; dataReceivingDoc.IssueCopies = Funs.GetNewInt(this.txtIssueCopies.Text.Trim()); dataReceivingDoc.IssueUnitReceiver = this.txtIssueUnitReceiver.Text.Trim(); dataReceivingDoc.IsOnFile = Convert.ToBoolean(this.rblIsOnFile.SelectedValue); if (!string.IsNullOrEmpty(this.drpAudit.SelectedValue)) { dataReceivingDoc.AuditMan = drpAudit.SelectedValue; } //审核人 if (string.IsNullOrEmpty(this.DataReceivingDocId)) { if (!string.IsNullOrEmpty(this.hdAttachUrl.Text)) { dataReceivingDoc.DataReceivingDocId = this.hdAttachUrl.Text; } else { dataReceivingDoc.DataReceivingDocId = SQLHelper.GetNewID(typeof(Model.Comprehensive_DataReceivingDoc)); this.hdAttachUrl.Text = dataReceivingDoc.DataReceivingDocId; } var sour = Funs.DB.AttachFile.FirstOrDefault(x => x.ToKeyId == dataReceivingDoc.DataReceivingDocId); if (sour == null || string.IsNullOrEmpty(sour.AttachUrl)) { Alert.ShowInTop("请上传附件!", MessageBoxIcon.Warning); return; } dataReceivingDoc.CompileMan = this.CurrUser.UserId; dataReceivingDoc.CompileDate = DateTime.Now; dataReceivingDoc.Status = BLL.Const.Comprehensive_Audit; BLL.DataReceivingDocService.AddDataReceivingDoc(dataReceivingDoc); } else { dataReceivingDoc.DataReceivingDocId = this.DataReceivingDocId; var sour = Funs.DB.AttachFile.FirstOrDefault(x => x.ToKeyId == this.DataReceivingDocId); if (sour == null || string.IsNullOrEmpty(sour.AttachUrl)) { Alert.ShowInTop("请上传附件!", MessageBoxIcon.Warning); return; } var model = Funs.DB.Comprehensive_DataReceivingDoc.Where(u => u.DataReceivingDocId == this.DataReceivingDocId).FirstOrDefault(); if (model.Status == BLL.Const.Comprehensive_Compile)//编制状态提交变审核 { dataReceivingDoc.Status = BLL.Const.Comprehensive_Audit; } else if (model.Status == BLL.Const.Comprehensive_ReCompile)//重新编制状态提交变审核 { dataReceivingDoc.Status = BLL.Const.Comprehensive_Audit; } else //审核状态 提交 变 完成 或者 重新编制 { if (Convert.ToBoolean(rblIsAgree.SelectedValue)) { dataReceivingDoc.Status = BLL.Const.Comprehensive_Complete; } else { dataReceivingDoc.Status = BLL.Const.Comprehensive_ReCompile; } } BLL.DataReceivingDocService.UpdateDataReceivingDoc(dataReceivingDoc); } #region 审核记录 var currApprove = DataReceivingDocApproveService.GetCurrentApprove(dataReceivingDoc.DataReceivingDocId); if (currApprove == null) //为获取到为 当前编制状态 直接提交 { var approve = new Model.Comprehensive_DataReceivingDocApprove(); approve.DataReceivingDocId = dataReceivingDoc.DataReceivingDocId; approve.ApproveMan = this.CurrUser.UserId; approve.ApproveType = Const.Comprehensive_Compile; approve.ApproveDate = DateTime.Now; DataReceivingDocApproveService.EditApprove(approve); //新增编制记录 Model.Comprehensive_DataReceivingDocApprove newApprove = new Model.Comprehensive_DataReceivingDocApprove(); newApprove.DataReceivingDocId = dataReceivingDoc.DataReceivingDocId; newApprove.ApproveMan = this.drpAudit.SelectedValue; newApprove.ApproveType = Const.InspectionManagement_Audit; DataReceivingDocApproveService.EditApprove(newApprove); //新增专业工程师审核记录 } else if (currApprove.ApproveMan == CurrUser.UserId) { if (currApprove.ApproveType == BLL.Const.Comprehensive_ReCompile) { currApprove.ApproveDate = DateTime.Now; DataReceivingDocApproveService.EditApprove(currApprove); //新增专业工程师审核记录 Model.Comprehensive_DataReceivingDocApprove newApprove = new Model.Comprehensive_DataReceivingDocApprove(); newApprove.DataReceivingDocId = dataReceivingDoc.DataReceivingDocId; newApprove.ApproveMan = this.drpAudit.SelectedValue; newApprove.ApproveType = Const.InspectionManagement_Audit; DataReceivingDocApproveService.EditApprove(newApprove); //新增专业工程师审核记录 } else { currApprove.ApproveDate = DateTime.Now; //更新审核时间 currApprove.IsAgree = Convert.ToBoolean(rblIsAgree.SelectedValue); currApprove.ApproveIdea = this.txtidea.Text; DataReceivingDocApproveService.EditApprove(currApprove); if (Convert.ToBoolean(rblIsAgree.SelectedValue)) //同意时 审批完成 { Model.Comprehensive_DataReceivingDocApprove reApprove = new Model.Comprehensive_DataReceivingDocApprove(); reApprove.DataReceivingDocId = currApprove.DataReceivingDocId; reApprove.ApproveDate = DateTime.Now.AddSeconds(10); reApprove.ApproveMan = CurrUser.UserId; reApprove.ApproveType = Const.Comprehensive_Complete; reApprove.ApproveIdea = txtidea.Text; DataReceivingDocApproveService.EditApprove(reApprove); } else { Model.Comprehensive_DataReceivingDocApprove reApprove = new Model.Comprehensive_DataReceivingDocApprove(); reApprove.DataReceivingDocId = currApprove.DataReceivingDocId; reApprove.ApproveMan = dataReceivingDoc.CompileMan; reApprove.ApproveType = Const.Comprehensive_ReCompile; DataReceivingDocApproveService.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_DataReceivingDoc)); } var dataReceivingDoc = BLL.DataReceivingDocService.GetDataReceivingDocById(this.DataReceivingDocId); if (dataReceivingDoc == null || ((dataReceivingDoc.CompileMan == CurrUser.UserId && dataReceivingDoc.Status == BLL.Const.Comprehensive_Compile) || (dataReceivingDoc.CompileMan == CurrUser.UserId && dataReceivingDoc.Status == BLL.Const.Comprehensive_ReCompile))) { PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=0&toKeyId={0}&path=FileUpload/CQMS/DataReceivingDoc&menuId={1}", this.hdAttachUrl.Text, BLL.Const.DataReceivingDocMenuId))); } else { PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/CQMS/DataReceivingDoc&menuId={1}", this.hdAttachUrl.Text, BLL.Const.DataReceivingDocMenuId))); } } #endregion #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private void GetButtonPower() { if (Request.Params["value"] == BLL.Const._Null) { return; } var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.DataReceivingDocMenuId); if (buttonList.Count > 0) { if (buttonList.Contains(BLL.Const.BtnSave)) { this.btnSave.Hidden = false; } } } #endregion } }