using BLL; using Newtonsoft.Json.Linq; using System; using System.Data; using System.Data.SqlClient; using System.Collections.Generic; using System.Linq; using System.Web.UI.WebControls; using AspNet = System.Web.UI.WebControls; namespace FineUIPro.Web.CQMS.RewardAndPunish { public partial class RewardAndPunishEdit : PageBase { /// /// 主键 /// public string RewardAndPunishId { get { return (string)ViewState["RewardAndPunishId"]; } set { ViewState["RewardAndPunishId"] = value; } } /// /// 办理类型 /// public string State { get { return (string)ViewState["State"]; } set { ViewState["State"] = value; } } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { RewardAndPunishId = Request.Params["RewardAndPunishId"]; this.drpHandleType.DataTextField = "Text"; this.drpHandleType.DataValueField = "Value"; BLL.UnitService.InitUnitByProjectIdUnitTypeDropDownList(this.drpUnit, this.CurrUser.LoginProjectId, Const.ProjectUnitType_2, true); this.HideOptions.Hidden = true; this.rblIsAgree.Hidden = true; if (!string.IsNullOrEmpty(RewardAndPunishId)) { Model.RewardAndPunish_RewardAndPunish RewardAndPunish = BLL.RewardAndPunishService.GetRewardAndPunishById(RewardAndPunishId); hdId.Text = this.RewardAndPunishId; if (!string.IsNullOrEmpty(RewardAndPunish.UnitId)) { this.drpUnit.SelectedValue = RewardAndPunish.UnitId; } txtRewardAndPunishCode.Text = RewardAndPunish.RewardAndPunishCode; if (!string.IsNullOrEmpty(RewardAndPunish.Type)) { this.rblType.SelectedValue = RewardAndPunish.Type; if (RewardAndPunish.Type == "1") //奖励 { BLL.RewardTypeService.InitRewardTypeDropDownList(drpRewardAndPunishType, true); } else //处罚 { BLL.PunishTypeService.InitPunishTypeDropDownList(drpRewardAndPunishType, true); } } txtRewardAndPunishBasis.Text = RewardAndPunish.RewardAndPunishBasis; if (!string.IsNullOrEmpty(RewardAndPunish.RewardAndPunishTypeId)) { drpRewardAndPunishType.SelectedValue = RewardAndPunish.RewardAndPunishTypeId; drpRewardAndPunishType_SelectedIndexChanged(null, null); } gvApprove.DataSource = BLL.RewardAndPunishApproveService.getListData(this.RewardAndPunishId); gvApprove.DataBind(); if (!string.IsNullOrEmpty(RewardAndPunish.State)) { State = RewardAndPunish.State; } else { State = BLL.Const.RewardAndPunish_Compile; this.HideOptions.Hidden = true; this.rblIsAgree.Hidden = true; } if (State != BLL.Const.RewardAndPunish_Complete.ToString()) { drpHandleType.DataSource = BLL.RewardAndPunishService.GetDHandleTypeByState(State); drpHandleType.DataBind(); } if (State == BLL.Const.RewardAndPunish_Compile || State == BLL.Const.RewardAndPunish_ReCompile) { this.HideOptions.Visible = false; this.rblIsAgree.Visible = false; this.drpHandleMan.Enabled = true; } else { this.HideOptions.Hidden = false; this.rblIsAgree.Hidden = false; } if (State == Const.RewardAndPunish_Audit2) { this.drpHandleMan.Enabled = false; } if (State == BLL.Const.RewardAndPunish_Complete || !string.IsNullOrEmpty(Request.Params["see"])) { this.btnSave.Visible = false; this.btnSubmit.Visible = false; this.next.Hidden = true; } drpHandleType_SelectedIndexChanged(null, null); } else { State = BLL.Const.RewardAndPunish_Compile; this.txtRewardAndPunishBasis.Text = "SD C0312-2020施工质量奖惩管理规定"; drpHandleType.DataSource = BLL.RewardAndPunishService.GetDHandleTypeByState(State); drpHandleType.DataBind(); drpHandleType_SelectedIndexChanged(null, null); } } } protected void Grid1_Sort(object sender, GridSortEventArgs e) { } protected void WindowAtt_Close(object sender, WindowCloseEventArgs e) { } /// /// 时间转换 /// /// /// public string ConvertDate(object date) { if (date != null) { return string.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(date)); } else { return null; } } /// /// 把状态转换代号为文字形式 /// /// /// protected string ConvertState(object state) { if (state != null) { if (state.ToString() == BLL.Const.RewardAndPunish_ReCompile) { return "重新编制"; } else if (state.ToString() == BLL.Const.RewardAndPunish_Compile) { return "编制"; } else if (state.ToString() == BLL.Const.RewardAndPunish_Audit1) { return "质量经理审核"; } else if (state.ToString() == BLL.Const.RewardAndPunish_Audit2) { return "项目经理批准"; } else if (state.ToString() == BLL.Const.RewardAndPunish_Complete) { return "审批完成"; } else { return ""; } } return ""; } protected void imgBtnFile_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(hdId.Text)) { hdId.Text = SQLHelper.GetNewID(); } PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=1&toKeyId={0}&path=FileUpload/CQMS/RewardAndPunish&menuId={1}", hdId.Text, BLL.Const.RewardAndPunishMenuId))); } /// /// 同意审核单选框改变事件 /// /// /// protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e) { this.drpHandleMan.Enabled = true; string State = BLL.RewardAndPunishService.GetRewardAndPunishById(this.RewardAndPunishId).State; if (this.RadioButtonList1.SelectedValue.Equals("true")) { if (State == Const.RewardAndPunish_Audit2) { this.drpHandleMan.Items.Clear(); Funs.FineUIPleaseSelect(this.drpHandleMan); this.drpHandleMan.Enabled = false; this.drpHandleMan.SelectedValue = BLL.Const._Null; } else { SitePerson_PersonService.InitProjectUserListByProjectUnitTypeDropDownList(drpHandleMan, this.CurrUser.LoginProjectId, Const.ProjectUnitType_1, false); } this.drpHandleType.SelectedIndex = 0; } else { this.drpHandleMan.Items.Clear(); Funs.FineUIPleaseSelect(drpHandleMan); this.drpHandleType.SelectedIndex = 1; ListItem item = new ListItem(); var user = BLL.Person_PersonsService.GetPerson_PersonsById(BLL.RewardAndPunishApproveService.GetAuditMan(this.RewardAndPunishId, BLL.Const.RewardAndPunish_Compile).ApproveMan); item.Value = user.PersonId; item.Text = user.PersonName; this.drpHandleMan.Items.Add(item); this.drpHandleMan.SelectedIndex = 1; } } /// /// 办理步骤下拉框改变事件 /// /// /// protected void drpHandleType_SelectedIndexChanged(object sender, EventArgs e) { this.drpHandleMan.Items.Clear(); Funs.FineUIPleaseSelect(this.drpHandleMan); if (this.drpHandleType.SelectedValue == BLL.Const.RewardAndPunish_Complete) { this.drpHandleMan.Enabled = false; } else if (this.drpHandleType.SelectedValue == BLL.Const.RewardAndPunish_ReCompile) { this.drpHandleMan.Enabled = true; string userId = (from x in Funs.DB.RewardAndPunish_RewardAndPunishApprove where x.RewardAndPunishId == RewardAndPunishId && x.ApproveType == BLL.Const.RewardAndPunish_Compile select x.ApproveMan).First(); ListItem lis = new ListItem(BLL.Person_PersonsService.GetPersonsNameById(userId), userId); this.drpHandleMan.Items.Add(lis); this.drpHandleMan.SelectedIndex = 0; } else { this.drpHandleMan.Enabled = true; if (this.drpHandleType.SelectedValue == BLL.Const.RewardAndPunish_Audit1 || this.drpHandleType.SelectedValue == BLL.Const.RewardAndPunish_Audit2) { SitePerson_PersonService.InitProjectUserListByProjectUnitTypeDropDownList(drpHandleMan, this.CurrUser.LoginProjectId, Const.ProjectUnitType_1, false); } this.drpHandleMan.SelectedIndex = 0; } } protected void btnSave_Click(object sender, EventArgs e) { if (validate()) { SaveRewardAndPunish("save"); } } /// /// 保存 /// public void SaveRewardAndPunish(string saveType) { Model.RewardAndPunish_RewardAndPunish RewardAndPunish = new Model.RewardAndPunish_RewardAndPunish(); RewardAndPunish.ProjectId = this.CurrUser.LoginProjectId; RewardAndPunish.UnitId = this.drpUnit.SelectedValue; RewardAndPunish.RewardAndPunishCode = this.txtRewardAndPunishCode.Text.Trim(); RewardAndPunish.Type = this.rblType.SelectedValue; RewardAndPunish.RewardAndPunishTypeId = this.drpRewardAndPunishType.SelectedValue; RewardAndPunish.RewardAndPunishBasis = this.txtRewardAndPunishBasis.Text.Trim(); if (saveType == "submit") { RewardAndPunish.State = this.drpHandleType.SelectedValue; } else { Model.RewardAndPunish_RewardAndPunish RewardAndPunish1 = RewardAndPunishService.GetRewardAndPunishById(RewardAndPunishId); if (RewardAndPunish1 != null) { if (string.IsNullOrEmpty(RewardAndPunish1.State)) { RewardAndPunish.State = BLL.Const.RewardAndPunish_Compile; } else { RewardAndPunish.State = RewardAndPunish1.State; } } else { RewardAndPunish.State = BLL.Const.RewardAndPunish_Compile; } } if (!string.IsNullOrEmpty(RewardAndPunishId)) { RewardAndPunish.RewardAndPunishId = RewardAndPunishId; RewardAndPunishService.UpdateRewardAndPunish(RewardAndPunish); if (saveType == "submit") { Model.RewardAndPunish_RewardAndPunishApprove approve1 = BLL.RewardAndPunishApproveService.GetRewardAndPunishApproveByRewardAndPunishId(RewardAndPunishId); approve1.ApproveDate = DateTime.Now; approve1.ApproveIdea = this.txtOpinions.Text.Trim(); approve1.IsAgree = Convert.ToBoolean(this.RadioButtonList1.SelectedValue); BLL.RewardAndPunishApproveService.UpdateRewardAndPunishApprove(approve1); if (this.drpHandleMan.SelectedValue != BLL.Const._Null) { Model.RewardAndPunish_RewardAndPunishApprove approve = new Model.RewardAndPunish_RewardAndPunishApprove(); approve.RewardAndPunishId = RewardAndPunish.RewardAndPunishId; approve.ApproveMan = this.drpHandleMan.SelectedValue; approve.ApproveType = this.drpHandleType.SelectedValue; BLL.RewardAndPunishApproveService.AddRewardAndPunishApprove(approve); } //if (this.drpHandleType.SelectedValue == Const.RewardAndPunish_Complete) //审批完成 //{ // var getSitePerson = (from x in Funs.DB.SitePerson_Person // join z in Funs.DB.Project_ProjectUnit on x.UnitId equals z.UnitId // where x.ProjectId == this.CurrUser.LoginProjectId && x.States == Const.ProjectPersonStates_1 && x.RoleIds != null // && z.UnitType == Const.ProjectUnitType_2 // select new // { // x.PersonId, // RoleNames = BLL.RoleService.getRoleNamesRoleIds(x.RoleIds) // }).AsEnumerable(); // var list = getSitePerson.Where(x => !x.RoleNames.Contains("安全")); // foreach (var item in list) // { // Model.RewardAndPunish_RewardAndPunishApprove approve = new Model.RewardAndPunish_RewardAndPunishApprove(); // approve.RewardAndPunishId = RewardAndPunish.RewardAndPunishId; // approve.ApproveMan = item.PersonId; // approve.ApproveType = "S"; // BLL.RewardAndPunishApproveService.AddRewardAndPunishApprove(approve); // } //} } } else { if (string.IsNullOrEmpty(hdId.Text)) { RewardAndPunish.RewardAndPunishId = SQLHelper.GetNewID(); } else { RewardAndPunish.RewardAndPunishId = hdId.Text; } RewardAndPunish.CompileMan = this.CurrUser.PersonId; RewardAndPunish.CompileDate = DateTime.Now; RewardAndPunishService.AddRewardAndPunish(RewardAndPunish); if (saveType == "submit") { Model.RewardAndPunish_RewardAndPunishApprove approve1 = new Model.RewardAndPunish_RewardAndPunishApprove(); approve1.RewardAndPunishId = RewardAndPunish.RewardAndPunishId; approve1.ApproveMan = this.CurrUser.PersonId; approve1.ApproveType = BLL.Const.RewardAndPunish_Compile; approve1.ApproveDate = DateTime.Now; BLL.RewardAndPunishApproveService.AddRewardAndPunishApprove(approve1); Model.RewardAndPunish_RewardAndPunishApprove approve = new Model.RewardAndPunish_RewardAndPunishApprove(); approve.RewardAndPunishId = RewardAndPunish.RewardAndPunishId; if (this.drpHandleMan.SelectedValue != BLL.Const._Null) { approve.ApproveMan = this.drpHandleMan.SelectedValue; } approve.ApproveType = this.drpHandleType.SelectedValue; BLL.RewardAndPunishApproveService.AddRewardAndPunishApprove(approve); } else { Model.RewardAndPunish_RewardAndPunishApprove approve1 = new Model.RewardAndPunish_RewardAndPunishApprove(); approve1.RewardAndPunishId = RewardAndPunish.RewardAndPunishId; approve1.ApproveMan = this.CurrUser.PersonId; approve1.ApproveType = BLL.Const.RewardAndPunish_Compile; BLL.RewardAndPunishApproveService.AddRewardAndPunishApprove(approve1); } } LogService.AddSys_Log(CurrUser, RewardAndPunish.RewardAndPunishCode, RewardAndPunish.RewardAndPunishId, Const.RewardAndPunishMenuId, "修改质量奖罚"); PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } /// /// 表格数据验证 /// private bool validate() { bool res = false; string err = string.Empty; if (this.drpUnit.SelectedValue == BLL.Const._Null) { err += "请选择奖罚对象!"; } if (this.rblType.SelectedValue == null) { err += "请选择类别!"; } if (this.drpRewardAndPunishType.SelectedValue == BLL.Const._Null) { err += "请选择奖罚事由!"; } //var att = BLL.AttachFileService.GetAttachFileByToKeyId(this.hdId.Text); //if (att == null) //{ // err += "请上传文件!"; //} if (!string.IsNullOrWhiteSpace(err)) { Alert.ShowInTop(err, MessageBoxIcon.Warning); } else { res = true; } return res; } protected void btnSubmit_Click(object sender, EventArgs e) { if (validate()) { if (this.drpHandleMan.Enabled == true && this.drpHandleMan.SelectedValue == BLL.Const._Null) { Alert.ShowInTop("请选择办理人!", MessageBoxIcon.Warning); return; } SaveRewardAndPunish("submit"); } } private string GetStringByArray(string[] array) { string str = string.Empty; foreach (var item in array) { if (item != BLL.Const._Null) { str += item + ","; } } if (!string.IsNullOrEmpty(str)) { str = str.Substring(0, str.LastIndexOf(",")); } return str; } protected void drpUnit_SelectedIndexChanged(object sender, EventArgs e) { if (this.drpUnit.SelectedValue != BLL.Const._Null) { string prefix = BLL.ProjectService.GetProjectCodeByProjectId(this.CurrUser.LoginProjectId) + "-" + BLL.UnitService.GetUnitCodeByUnitId(this.drpUnit.SelectedValue) + "-ZLJC-"; txtRewardAndPunishCode.Text = BLL.SQLHelper.RunProcNewId("SpGetThreeNumber", "RewardAndPunish_RewardAndPunish", "RewardAndPunishCode", this.CurrUser.LoginProjectId, prefix); } else { this.txtRewardAndPunishCode.Text = string.Empty; } } protected void drpRewardAndPunishType_SelectedIndexChanged(object sender, EventArgs e) { if (this.drpRewardAndPunishType.SelectedValue != BLL.Const._Null) { Model.Base_RewardType rt = BLL.RewardTypeService.GetRewardTypeById(this.drpRewardAndPunishType.SelectedValue); Model.Base_PunishType pt = BLL.PunishTypeService.GetPunishTypeById(this.drpRewardAndPunishType.SelectedValue); if (rt != null) { this.txtRewardAndPunishDecision.Text = rt.RewardDecision; } else { this.txtRewardAndPunishDecision.Text = pt.PunishDecision; } } else { this.txtRewardAndPunishDecision.Text = string.Empty; } } protected void rblType_SelectedIndexChanged(object sender, EventArgs e) { if (rblType.SelectedValue == "1") //奖励 { BLL.RewardTypeService.InitRewardTypeDropDownList(drpRewardAndPunishType, true); } else //处罚 { BLL.PunishTypeService.InitPunishTypeDropDownList(drpRewardAndPunishType, true); } this.drpRewardAndPunishType.SelectedValue = BLL.Const._Null; } } }