using System; using System.Collections.Generic; using System.Linq; using System.Data.SqlClient; using System.Data; using System.Web.UI.WebControls; using BLL; namespace FineUIPro.Web.common.ProjectSet { public partial class SelectWelder : PageBase { #region 加载 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { InitTreeMenu();//加载树 } } private void BindGrid() { string projectId = Request.Params["projectId"]; string unitid = this.tvUnit.SelectedNodeID; string strSql = @"select WelderId,WelderCode,WelderName,ProjectId,UnitId from dbo.Welder_Welder where UnitId=@UnitId"; List listStr = new List(); listStr.Add(new SqlParameter("@UnitId", unitid)); strSql += " order by WelderCode"; SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); tb = GetFilteredTable(Grid1.FilteredData, tb); Grid1.DataSource = tb; Grid1.DataBind(); var welders = BLL.WelderService.GetWelderByProjectIdAndUnitId(projectId, unitid); if (welders != null) { string[] arr = new string[welders.Count()]; int i = 0; foreach (var q in welders) { arr[i] = q.WelderId; i++; } Grid1.SelectedRowIDArray = arr; } } #endregion #region /// /// 加载树 /// private void InitTreeMenu() { this.tvUnit.Nodes.Clear(); var projectUnits = from x in Funs.DB.Project_Unit where x.ProjectId == Request.Params["projectId"] && x.UnitType == BLL.Const.UnitType_5 orderby x.UnitType descending select x; if (projectUnits.Count() > 0) { foreach (var item in projectUnits) { var baseUnit = Funs.DB.Base_Unit.FirstOrDefault(x => x.UnitId == item.UnitId); TreeNode rootNode = new TreeNode();//定义根节点 rootNode.Text = baseUnit.UnitName; rootNode.NodeID = item.UnitId; rootNode.EnableClickEvent = true; this.tvUnit.Nodes.Add(rootNode); } } } #endregion #region 点击TreeView /// /// 点击TreeView /// /// /// protected void tvUnit_NodeCommand(object sender, TreeCommandEventArgs e) { if (!string.IsNullOrEmpty(this.tvUnit.SelectedNode.NodeID)) { BindGrid(); } } #endregion #region 编辑 protected void btnEdit_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_ProjectWelderMenuId, Const.BtnSave)) { string projectId = Request.Params["projectId"]; //string coutValue = IsSave(); //if (!string.IsNullOrEmpty(coutValue)) //{ // ShowNotify(coutValue + Resources.Lan.PleaseSelectTeamGroup); //} //else //{ BLL.Welder_ProjectWelderService.DeleteProjectWelderByProjectId(projectId, this.tvUnit.SelectedNode.NodeID); string[] selectRowId = Grid1.SelectedRowIDArray; int n = 0; int j = 0; int[] selections = new int[selectRowId.Count()]; foreach (GridRow row in Grid1.Rows) { if (selectRowId.Contains(row.DataKeys[0])) { selections[n] = j; n++; } j++; } var select = selections.Distinct(); foreach (int i in select) { System.Web.UI.WebControls.DropDownList drpUnitId = (System.Web.UI.WebControls.DropDownList)Grid1.Rows[i].FindControl("drpUnitId"); System.Web.UI.WebControls.DropDownList drpTeamGroupId = (System.Web.UI.WebControls.DropDownList)Grid1.Rows[i].FindControl("drpTeamGroupId"); Model.Welder_ProjectWelder newProjectWelder = new Model.Welder_ProjectWelder(); newProjectWelder.ProjectId = projectId; newProjectWelder.WelderId = Grid1.DataKeys[i][0].ToString(); if (drpUnitId.SelectedValue != Const._Null && !string.IsNullOrEmpty(drpUnitId.SelectedValue)) { newProjectWelder.UnitId = drpUnitId.SelectedValue; } if (drpTeamGroupId.SelectedValue != Const._Null && !string.IsNullOrEmpty(drpTeamGroupId.SelectedValue)) { newProjectWelder.TeamGroupId = drpTeamGroupId.SelectedValue; } else { newProjectWelder.TeamGroupId = null; } newProjectWelder.ProjectWelderId = SQLHelper.GetNewID(typeof(Model.Welder_ProjectWelder)); BLL.Welder_ProjectWelderService.AddProjectWelder(newProjectWelder); } BLL.Sys_LogService.AddLog(Const.System_1, this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_ProjectWelderMenuId, Const.BtnSave, ""); PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); //} } else { ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning); } } #endregion #region 排序 /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { Grid1.SortDirection = e.SortDirection; Grid1.SortField = e.SortField; BindGrid(); } #endregion #region Grid行绑定事件 protected void Grid1_RowDataBound(object sender, GridRowEventArgs e) { string projectId = Request.Params["projectId"]; System.Web.UI.WebControls.DropDownList drpUnitId = (System.Web.UI.WebControls.DropDownList)Grid1.Rows[e.RowIndex].FindControl("drpUnitId"); System.Web.UI.WebControls.DropDownList drpTeamGroupId = (System.Web.UI.WebControls.DropDownList)Grid1.Rows[e.RowIndex].FindControl("drpTeamGroupId"); var units = (from x in Funs.DB.Base_Unit join y in Funs.DB.Project_Unit on x.UnitId equals y.UnitId where y.ProjectId == projectId && y.UnitType.Contains(BLL.Const.UnitType_5) select x).ToList(); System.Web.UI.WebControls.ListItem[] list = new System.Web.UI.WebControls.ListItem[units.Count]; for (int i = 0; i < units.Count; i++) { list[i] = new System.Web.UI.WebControls.ListItem(units[i].UnitName, units[i].UnitId); } drpUnitId.Items.AddRange(list); Funs.PleaseSelect(drpUnitId, Resources.Lan.PleaseSelect); Funs.PleaseSelect(drpTeamGroupId, Resources.Lan.PleaseSelect); drpTeamGroupId.Items.AddRange(BLL.Welder_TeamGroupService.GetAllTeamGroupList(projectId, tvUnit.SelectedNodeID)); var projectWelder = BLL.Welder_ProjectWelderService.GetProjectWelderByProjectIdAndWelderId(projectId, e.RowID); if (projectWelder != null) { if (!string.IsNullOrEmpty(projectWelder.UnitId)) { drpUnitId.SelectedValue = projectWelder.UnitId; } else { var welder = BLL.WelderService.GetWelderById(e.RowID); if (welder != null) { drpUnitId.SelectedValue = welder.UnitId; } } if (!string.IsNullOrEmpty(projectWelder.TeamGroupId)) { drpTeamGroupId.SelectedValue = projectWelder.TeamGroupId; } } } #endregion protected void drpUnitId_OnSelectedIndexChanged(object sender, EventArgs e) { //int i = ((FineUIPro.GridTemplateContainer)((System.Web.UI.WebControls.DropDownList)sender).DataItemContainer).DataItemIndex; //System.Web.UI.WebControls.DropDownList drpTeamGroupId = (System.Web.UI.WebControls.DropDownList)Grid1.Rows[i].FindControl("drpTeamGroupId"); //drpTeamGroupId.Items.Clear(); //Funs.PleaseSelect(drpTeamGroupId, Resources.Lan.PleaseSelect); //drpTeamGroupId.Items.AddRange(BLL.Welder_TeamGroupService.GetAllTeamGroupList(drpUnitId.SelectedValue)); } #region 验证是否选择班组 /// /// 验证是否选择班组 /// /// protected string IsSave() { string coutValue = string.Empty; string[] selectRowId = Grid1.SelectedRowIDArray; int n = 0; int j = 0; int[] selections = new int[selectRowId.Count()]; foreach (GridRow row in Grid1.Rows) { if (selectRowId.Contains(row.DataKeys[0])) { selections[n] = j; n++; } j++; } foreach (int i in selections) { System.Web.UI.WebControls.DropDownList drpTeamGroupId = (System.Web.UI.WebControls.DropDownList)Grid1.Rows[i].FindControl("drpTeamGroupId"); if (drpTeamGroupId.SelectedValue == BLL.Const._Null || string.IsNullOrEmpty(drpTeamGroupId.SelectedValue)) { coutValue += Resources.Lan.Line + (i + 1).ToString() + ","; } } return coutValue; } #endregion } }