using BLL; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace FineUIPro.Web.SubPackManage { public partial class LaborTeamEdit : PageBase { /// /// 主键 /// public string LaborTeamId { get { return (string)ViewState["LaborTeamId"]; } set { ViewState["LaborTeamId"] = value; } } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.btnClose.OnClientClick = ActiveWindow.GetHideReference(); GetButtonPower(); BLL.SubPackLaborTeamService.DropSelectUnitWork(drpUnit, this.CurrUser.LoginProjectId, true); this.LaborTeamId = Request.Params["LaborTeamId"]; var laborTeam = Funs.DB.SubPack_LaborTeam.FirstOrDefault(p => p.LaborTeamId == this.LaborTeamId); if (laborTeam != null) { drpUnit.SelectedValue = laborTeam.UnitId; BLL.SubPackTeamListService.DropSelectTeamWorkUpdate(drpBranchTeamList, drpUnit.SelectedValue, this.CurrUser.LoginProjectId, true); drpBranchTeamList.SelectedValue = laborTeam.BranchTeamListId; txtLaborTeamName.Text = laborTeam.LaborTeamName; txtRemark.Text = laborTeam.Remark; txtCaptainName.Text = laborTeam.CaptainName; txtCaptainIDCard.Text = laborTeam.CaptainIDCard; } else { BLL.BaseBranchTeamListTeamService.DropSelectTeamWork(drpBranchTeamList, drpUnit.SelectedValue, true); } } } protected void btnSave_Click(object sender, EventArgs e) { if (BLL.CommonService.GetAllButtonPowerList(null, this.CurrUser.UserId, BLL.Const.SubPackLaborTeamMenuId, BLL.Const.BtnSave)) { string allMess = string.Empty; if (!string.IsNullOrWhiteSpace(txtCaptainIDCard.Text)) { allMess = SubPackBlacklistService.GetMessAlert(txtCaptainIDCard.Text.Trim(), Const.SubPackBlackLaborTeam); } if (!string.IsNullOrWhiteSpace(allMess)) { allMess += "是否继续操作?"; PageContext.RegisterStartupScript(Confirm.GetShowReference(allMess, String.Empty, MessageBoxIcon.Question, PageManager1.GetCustomEventReference(true, "btnSave_OK"), // 第一个参数 false 用来指定当前不是AJAX请求 PageManager1.GetCustomEventReference("btnSave_Cancel"))); return; } //保存失败时 if (SaveDate("save") == 0) return; if (string.IsNullOrEmpty(Request.Params["Main"])) { PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } else { PageContext.RegisterStartupScript(String.Format("window.close();")); } } else { Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } /// /// 保存方法 /// /// private int SaveDate(string saveType) { if (drpUnit.SelectedValue == BLL.Const._Null) { Alert.ShowInTop("请选择施工分包商!", MessageBoxIcon.Warning); return 0; } if (drpBranchTeamList.SelectedValue == BLL.Const._Null) { Alert.ShowInTop("请选择分包公司!", MessageBoxIcon.Warning); return 0; } var laborTeam = Funs.DB.SubPack_LaborTeam.FirstOrDefault(p => p.LaborTeamId == this.LaborTeamId); if (laborTeam != null) { laborTeam.ProjectId = this.CurrUser.LoginProjectId; laborTeam.UnitId = drpUnit.SelectedValue; laborTeam.BranchTeamListId = drpBranchTeamList.SelectedValue; laborTeam.LaborTeamName = txtLaborTeamName.Text.Trim(); laborTeam.Remark = txtRemark.Text.Trim(); laborTeam.CaptainName = txtCaptainName.Text.Trim(); laborTeam.CaptainIDCard = txtCaptainIDCard.Text.Trim(); if (Funs.DB.SubPack_LaborTeam.Where(p => p.ProjectId == this.CurrUser.LoginProjectId && p.LaborTeamId != laborTeam.LaborTeamId && p.CaptainIDCard == laborTeam.CaptainIDCard).Count() > 0) { Alert.ShowInTop($"此队长身份证号【{laborTeam.CaptainIDCard}】已经在此项目的劳务队伍中使用过,不能重复使用!", MessageBoxIcon.Warning); return 0; } if (!IDCardValid.CheckIDCard(laborTeam.CaptainIDCard)) { Alert.ShowInTop($"【{laborTeam.CaptainIDCard}】身份证号码非法!", MessageBoxIcon.Warning); return 0; } BLL.SubPackLaborTeamService.UpdateSubPackLaborTeam(laborTeam); } else { Model.SubPack_LaborTeam newLaborTeam = new Model.SubPack_LaborTeam(); newLaborTeam.LaborTeamId = SQLHelper.GetNewID(typeof(Model.SubPack_LaborTeam)); newLaborTeam.ProjectId = this.CurrUser.LoginProjectId; newLaborTeam.UnitId = drpUnit.SelectedValue; newLaborTeam.BranchTeamListId = drpBranchTeamList.SelectedValue; newLaborTeam.LaborTeamName = txtLaborTeamName.Text.Trim(); newLaborTeam.Remark = txtRemark.Text.Trim(); newLaborTeam.CaptainName = txtCaptainName.Text.Trim(); newLaborTeam.CaptainIDCard = txtCaptainIDCard.Text.Trim(); if (Funs.DB.SubPack_LaborTeam.Where(p => p.ProjectId == this.CurrUser.LoginProjectId && p.CaptainIDCard == newLaborTeam.CaptainIDCard).Count() > 0) { Alert.ShowInTop($"此队长身份证号【{newLaborTeam.CaptainIDCard}】已经在此项目的劳务队伍中使用过,不能重复使用!", MessageBoxIcon.Warning); return 0; } if (!IDCardValid.CheckIDCard(newLaborTeam.CaptainIDCard)) { Alert.ShowInTop($"【{newLaborTeam.CaptainIDCard}】身份证号码非法!", MessageBoxIcon.Warning); return 0; } BLL.SubPackLaborTeamService.AddSubPackLaborTeam(newLaborTeam); } return 1; } #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private void GetButtonPower() { if (Request.Params["value"] == "0") { return; } var buttonList = BLL.CommonService.GetAllButtonList(null, this.CurrUser.UserId, BLL.Const.SubPackLaborTeamMenuId); if (buttonList.Count() > 0) { if (buttonList.Contains(BLL.Const.BtnSave)) { this.btnSave.Hidden = false; } } } #endregion /// /// 施工分包商下拉框 /// /// /// protected void drpUnit_SelectedIndexChanged(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(this.LaborTeamId)) BLL.SubPackTeamListService.DropSelectTeamWork(drpBranchTeamList, drpUnit.SelectedValue, this.CurrUser.LoginProjectId, true); else BLL.SubPackTeamListService.DropSelectTeamWorkUpdate(drpBranchTeamList, drpUnit.SelectedValue, this.CurrUser.LoginProjectId, true); drpBranchTeamList.SelectedValue = BLL.Const._Null; } protected void PageManager1_CustomEvent(object sender, CustomEventArgs e) { if (e.EventArgument == "btnSave_OK") { //保存失败时 if (SaveDate("save") == 0) return; if (string.IsNullOrEmpty(Request.Params["Main"])) { PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } else { PageContext.RegisterStartupScript(String.Format("window.close();")); } } else if (e.EventArgument == "btnSave_Cancel") { // AJAX回发 ShowNotify("已取消保存!"); } } } }