using BLL; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace FineUIPro.Web.HJGL.TestPackageManage { public partial class ShowTestPackageSearch : PageBase { #region 定义变量 /// /// 单位ID /// public string UnitId { get { return (string)ViewState["UnitId"]; } set { ViewState["UnitId"] = value; } } public string selectedList { get { return (string)ViewState["selectedList"]; } set { ViewState["selectedList"] = value; } } /// /// 装置 /// public string InstallationId { get { return (string)ViewState["InstallationId"]; } set { ViewState["InstallationId"] = value; } } /// /// 选择列表 /// public List CheckList { get { return (List)ViewState["CheckList"]; } set { ViewState["CheckList"] = value; } } /// /// 选择列表 /// public List isoList { get { return (List)ViewState["isoList"]; } set { ViewState["isoList"] = value; } } /// /// 定义集合 /// private static List viewTestPackageSearchList = new List(); #endregion #region 加载 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.UnitId = Request.Params["unitId"]; this.InstallationId = Request.Params["installationId"]; selectedList = ""; var unit = BLL.UnitService.GetUnitByUnitId(this.CurrUser.UnitId); if (BLL.WorkAreaService.IsSupervisor(this.CurrUser.UnitId, this.CurrUser.LoginProjectId)) { BLL.WorkAreaService.GetWorkAreaListByInstallSupervisorUnit(this.drpWorkArea, this.CurrUser.LoginProjectId, this.InstallationId, this.UnitId, this.CurrUser.UnitId, true); } else { BLL.WorkAreaService.GetWorkAreaListByInstallUnit(this.drpWorkArea, this.CurrUser.LoginProjectId, this.InstallationId, this.UnitId, true); } } } #endregion #region 查询 /// ///查询按钮 /// /// /// protected void btnSearch_Click(object sender, EventArgs e) { viewTestPackageSearchList.Clear(); this.Grid1.DataSource = viewTestPackageSearchList; this.Grid1.DataBind(); List workAreaIds = new List(); if (this.drpWorkArea.SelectedValue != BLL.Const._Null) { workAreaIds.Add(this.drpWorkArea.SelectedValue); } BindGrid(workAreaIds); //this.InitTreeMenu(workAreaId);//加载树 //if (tvControlItem.GetCheckedNodes().Length > 0) //{ // tvControlItem_NodeCheck(null, null); //} } #endregion #region 加载树 /// /// 加载树节点 /// /// private void InitTreeMenu(string workAreaId) { if (!string.IsNullOrEmpty(workAreaId)) { this.tvControlItem.Nodes.Clear(); TreeNode rootNode = new TreeNode(); rootNode.Text = BLL.WorkAreaService.GetWorkAreaCodeByWorkAreaId(workAreaId); rootNode.NodeID = workAreaId; rootNode.Expanded = true; rootNode.EnableCheckEvent = true; this.tvControlItem.Nodes.Add(rootNode); } else { var workAreas = (from x in Funs.DB.ProjectData_WorkArea where x.UnitId == UnitId && x.InstallationId == InstallationId select x).ToList(); foreach (var item in workAreas) { this.tvControlItem.Nodes.Clear(); TreeNode rootNode = new TreeNode(); rootNode.Text = item.WorkAreaCode; rootNode.NodeID = item.WorkAreaId; rootNode.Expanded = true; rootNode.EnableCheckEvent = true; this.tvControlItem.Nodes.Add(rootNode); } } } #endregion #region Tree点击事件 /// /// 点击Tree /// /// /// protected void tvControlItem_NodeCheck(object sender, TreeCheckEventArgs e) { CheckList = new List(); TreeNode[] nodes = tvControlItem.GetCheckedNodes(); if (nodes.Length > 0) { StringBuilder sb = new StringBuilder(); foreach (TreeNode node in nodes) { CheckList.Add(node.NodeID); } } BindGrid(CheckList); } #endregion protected void drpWorkArea_SelectedIndexChanged(object sender, EventArgs e) { List workAreaIds = new List(); if (this.drpWorkArea.SelectedValue != BLL.Const._Null) { HashSet selectedSet = new HashSet(); if (!string.IsNullOrEmpty(selectedList)) { string[] ids = selectedList.Split(','); foreach (string id in ids) { selectedSet.Add(id); } } foreach (var item in Grid1.SelectedRowIDArray) { selectedSet.Add(item); } selectedList = string.Join(",", selectedSet.ToArray()); workAreaIds.Add(this.drpWorkArea.SelectedValue); BindGrid(workAreaIds); } } #region 数据绑定 /// /// 数据绑定 /// /// private void BindGrid(List checkList) { viewTestPackageSearchList = (from x in Funs.DB.View_TestPackageSearch where x.ProjectId == this.CurrUser.LoginProjectId select x).ToList(); if (!string.IsNullOrEmpty(this.txtISO_ID.Text.Trim())) { viewTestPackageSearchList = viewTestPackageSearchList.Where(e => e.ISO_IsoNo.Contains(this.txtISO_ID.Text.Trim())).ToList(); } if (checkList != null) { viewTestPackageSearchList = viewTestPackageSearchList.Where(e => checkList.Contains(e.WorkAreaId)).ToList(); } this.Grid1.DataSource = viewTestPackageSearchList; this.Grid1.DataBind(); if (!string.IsNullOrEmpty(selectedList)) { string[] ids = selectedList.Split(','); List needSelected = new List(); foreach(var id in ids) { foreach(var item in viewTestPackageSearchList) { if (id == item.ISO_ID) { needSelected.Add(id); } } } this.Grid1.SelectedRowIDArray = needSelected.ToArray(); } this.GetCheckgvList(); } #endregion #region 选择列表某项事件 /// /// 选择列表某项事件 /// private void GetCheckgvList() { isoList = new List(); foreach (var item in viewTestPackageSearchList) { isoList.Add(item.ISO_ID); } } #endregion #region 确定按钮 /// /// 确定按钮 /// /// /// protected void btnSure_Click(object sender, EventArgs e) { HashSet selectedSet = new HashSet(); if (!string.IsNullOrEmpty(selectedList)) { string[] ids = selectedList.Split(','); foreach (string id in ids) { selectedSet.Add(id); } } foreach (var item in Grid1.SelectedRowIDArray) { selectedSet.Add(item); } string res = string.Join(",", selectedSet.ToArray()); PageContext.RegisterStartupScript(ActiveWindow.GetWriteBackValueReference(res) + ActiveWindow.GetHidePostBackReference()); } #endregion } }