CNCEC_SUBQHSE_WUHUAN/SGGL/FineUIPro.Web/CQMS/Comprehensive/ReviewDrawingsEdit.aspx.cs

458 lines
19 KiB
C#

using BLL;
using BLL.CQMS.Comprehensive;
using System;
using System.Linq;
namespace FineUIPro.Web.CQMS.Comprehensive
{
public partial class ReviewDrawingsEdit : PageBase
{
#region
/// <summary>
/// 主键
/// </summary>
public string Id
{
get
{
return (string)ViewState["Id"];
}
set
{
ViewState["Id"] = value;
}
}
#endregion
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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.Id = Request.Params["Id"];
var model = BLL.ReviewDrawingsService.Detail(this.Id);
if (model != null)
{
this.Id = model.Id;
this.hdAttachUrl.Text = this.Id;
if (!string.IsNullOrEmpty(model.CNProfessionalId))
{
this.drpCNProfessionalId.SelectedValue = model.CNProfessionalId;
}
if (!string.IsNullOrEmpty(model.UnitWorkId))
{
this.drpUnitWorkIds.SelectedValueArray = model.UnitWorkId.Split(',');
}
this.txtDraCode.Text = model.DraCode;
this.txtReviewDate.Text = model.ReviewDate.HasValue ? string.Format("{0:yyyy-MM-dd}", model.ReviewDate) : "";
if (!string.IsNullOrEmpty(model.ReceiveUnits))
{
this.drpUnitIds.SelectedValueArray = model.ReceiveUnits.Split(',');
}
this.txtRemarks.Text = model.Remarks;
var currApprove = DesignDrawingsApproveService.GetCurrentApprove(model.Id);
if (currApprove != null)
{ //重新编制 编制人 可以 显示 提交 保存按钮
this.drpAudit.SelectedValue = currApprove.ApproveMan;
if (currApprove.ApproveType == BLL.Const.Comprehensive_ReCompile && model.CreateMan == 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 (model.Status == BLL.Const.Comprehensive_Compile && model.CreateMan == CurrUser.UserId)
{
this.btnSubmit.Hidden = false;
this.btnSave.Hidden = false;
}
}
}
else
{
this.btnSave.Hidden = false;
this.btnSubmit.Hidden = false;
}
}
}
/// <summary>
/// 禁止编辑
/// </summary>
public void Readonly()
{
this.txtDraCode.Readonly = true;
this.txtReviewDate.Readonly = true;
this.drpCNProfessionalId.Readonly = true;
this.drpUnitWorkIds.Readonly = true;
this.drpUnitIds.Readonly = true;
this.txtRemarks.Readonly = true;
this.txtReviewDate.Readonly = true;
this.drpAudit.Readonly = true;
//this.btnAttach.Enabled = false;
}
/// <summary>
/// 加载专业工程师
/// </summary>
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
/// <summary>
/// 获取按钮权限
/// </summary>
/// <param name="button"></param>
/// <returns></returns>
private void GetButtonPower()
{
if (Request.Params["value"] == "0")
{
return;
}
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.ReviewDrawingsMenuId);
if (buttonList.Count() > 0)
{
if (buttonList.Contains(BLL.Const.BtnSave))
{
this.btnSave.Hidden = false;
}
}
}
#endregion
#region
/// <summary>
/// 附件上传
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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.Id);
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.ReviewDrawingsMenuId)));
}
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.ReviewDrawingsMenuId)));
}
}
#endregion
#region
/// <summary>
/// 保存按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
if (drpCNProfessionalId.SelectedValue == BLL.Const._Null)
{
Alert.ShowInTop("请选择专业!", MessageBoxIcon.Warning);
return;
}
var designDrawings = new Model.Comprehensive_ReviewDrawings();
designDrawings.ProjectId = this.CurrUser.LoginProjectId;
designDrawings.CNProfessionalId = this.drpCNProfessionalId.SelectedValue;
designDrawings.DraCode = this.txtDraCode.Text.Trim();
designDrawings.ReviewDate = Funs.GetNewDateTime(this.txtReviewDate.Text);
designDrawings.Remarks = this.txtRemarks.Text.Trim();
designDrawings.CreateMan = this.CurrUser.UserId;
designDrawings.CreateDate = DateTime.Now;
//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.Id))
{
designDrawings.Id = this.Id;
var model = Funs.DB.Comprehensive_ReviewDrawings.Where(u => u.Id == this.Id).FirstOrDefault();
if (model != null)
{
designDrawings.Status = model.Status;
}
BLL.ReviewDrawingsService.Update(designDrawings);
}
else
{
if (!string.IsNullOrEmpty(this.hdAttachUrl.Text))
{
designDrawings.Id = this.hdAttachUrl.Text;
}
else
{
designDrawings.Id = SQLHelper.GetNewID(typeof(Model.Comprehensive_DesignDrawings));
this.hdAttachUrl.Text = designDrawings.Id;
}
designDrawings.Status = BLL.Const.Comprehensive_Compile;
BLL.ReviewDrawingsService.Insert(designDrawings);
}
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (drpCNProfessionalId.SelectedValue == BLL.Const._Null)
{
Alert.ShowInTop("请选择专业!", MessageBoxIcon.Warning);
return;
}
var designDrawings = new Model.Comprehensive_ReviewDrawings();
designDrawings.ProjectId = this.CurrUser.LoginProjectId;
designDrawings.CNProfessionalId = this.drpCNProfessionalId.SelectedValue;
designDrawings.DraCode = this.txtDraCode.Text.Trim();
designDrawings.ReviewDate = Funs.GetNewDateTime(this.txtReviewDate.Text);
designDrawings.Remarks = this.txtRemarks.Text.Trim();
designDrawings.CreateMan = this.CurrUser.UserId;
designDrawings.CreateDate = DateTime.Now;
//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.Id))
{
designDrawings.Id = this.Id;
//BLL.DesignDrawingsService.UpdateDesignDrawings(designDrawings);
var oldDesignDrawings = Funs.DB.Comprehensive_ReviewDrawings.Where(u => u.Id == this.Id).FirstOrDefault();
if (oldDesignDrawings == null) //数据库没有记录 直接点提交 当前状态为 审核状态
{
designDrawings.CreateMan = this.CurrUser.UserId;
designDrawings.Status = BLL.Const.Comprehensive_Audit;
BLL.ReviewDrawingsService.Insert(designDrawings);
}
else
{
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.ReviewDrawingsService.Update(designDrawings);
}
}
else
{
if (!string.IsNullOrEmpty(this.hdAttachUrl.Text))
{
designDrawings.Id = this.hdAttachUrl.Text;
}
else
{
designDrawings.Id = SQLHelper.GetNewID(typeof(Model.Comprehensive_DesignDrawings));
this.hdAttachUrl.Text = designDrawings.Id;
}
designDrawings.Status = BLL.Const.Comprehensive_Audit;
BLL.ReviewDrawingsService.Insert(designDrawings);
}
#region
var currApprove = DesignDrawingsApproveService.GetCurrentApprove(designDrawings.Id);
if (currApprove == null) //为获取到为 当前编制状态 直接提交
{
var approve = new Model.Comprehensive_DesignDrawingsApprove();
approve.DesignDrawingsId = designDrawings.Id;
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.Id;
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.Id;
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.CreateMan;
reApprove.ApproveType = Const.Comprehensive_ReCompile;
DesignDrawingsApproveService.EditApprove(reApprove);
}
}
}
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
#endregion
}
/// <summary>
/// 保存方法
/// </summary>
#endregion
}
}