using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using BLL; namespace FineUIPro.Web.HJGL.WeldingManage { public partial class PmiMaterialTemplate : PageBase { public string treeNodeId { get { return (string)ViewState["treeNodeId"]; } set { ViewState["treeNodeId"] = value; } } public string unitId { get { return (string)ViewState["unitId"]; } set { ViewState["unitId"] = value; } } #region 加载 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString(); this.InitTreeMenu();//加载树 // 绑定表格 this.BindGrid(); } } #endregion #region 加载树装置-单位 /// /// 加载树 /// private void InitTreeMenu() { ////this.tvControlItem.Nodes.Clear(); ////TreeNode rootNode = new TreeNode(); ////rootNode.Text = "装置-工区"; ////rootNode.NodeID = "0"; ////rootNode.Expanded = true; ////this.tvControlItem.Nodes.Add(rootNode); //装置 //if (!string.IsNullOrEmpty(this.txtWorkArea.Text.Trim())) //{ //string unitString = this.txtWorkArea.Text.Trim(); //var pInstallation = (from x in Funs.DB.PIM_View_PmiMaterialTemplate where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitName.Contains(unitString) select new { x.InstallationId, x.InstallationName }).Distinct().ToList(); //foreach (var q in pInstallation) //{ // TreeNode newNode = new TreeNode(); // newNode.NodeID = q.InstallationId; // newNode.Text = q.InstallationName; // newNode.ToolTip = "装置"; // newNode.Expanded = false; // rootNode.Nodes.Add(newNode); // var pUnits = (from x in Funs.DB.PIM_View_PmiMaterialTemplate where x.ProjectId == this.CurrUser.LoginProjectId && x.InstallationId == q.InstallationId && x.UnitName.Contains(unitString) select new { x.UnitId, x.UnitName }).Distinct().ToList(); // foreach (var u in pUnits) // { // TreeNode unitsNode = new TreeNode(); // unitsNode.NodeID = u.UnitId + "|" + newNode.NodeID; // unitsNode.Text = u.UnitName; // unitsNode.ToolTip = "工区"; // unitsNode.CommandName = "工区"; // unitsNode.EnableClickEvent = true; // //unitsNode.Expanded = false; // newNode.Nodes.Add(unitsNode); // } //} //} //else //{ // var pInstallation = (from x in Funs.DB.PIM_View_PmiMaterialTemplate where x.ProjectId == this.CurrUser.LoginProjectId select new { x.InstallationId, x.InstallationName }).Distinct().ToList(); // foreach (var q in pInstallation) // { // TreeNode newNode = new TreeNode(); // newNode.NodeID = q.InstallationId; // newNode.Text = q.InstallationName; // newNode.ToolTip = "装置"; // newNode.Expanded = false; // rootNode.Nodes.Add(newNode); // var pUnits = (from x in Funs.DB.PIM_View_PmiMaterialTemplate where x.ProjectId == this.CurrUser.LoginProjectId && x.InstallationId == q.InstallationId select new { x.UnitId, x.UnitName }).Distinct().ToList(); // foreach (var u in pUnits) // { // TreeNode unitsNode = new TreeNode(); // unitsNode.NodeID = u.UnitId + "|" + newNode.NodeID; // unitsNode.Text = u.UnitName; // unitsNode.ToolTip = "工区"; // unitsNode.CommandName = "工区"; // unitsNode.EnableClickEvent = true; // //unitsNode.Expanded = false; // newNode.Nodes.Add(unitsNode); // } // } //} this.tvControlItem.Nodes.Clear(); TreeNode rootNode = new TreeNode(); rootNode.Text = "装置-工区"; rootNode.NodeID = "0"; rootNode.Expanded = true; this.tvControlItem.Nodes.Add(rootNode); //装置 //if (!string.IsNullOrEmpty(this.txtCode.Text.Trim())) //{ //string unitString = this.txtWorkArea.Text.Trim(); var pInstallation = (from x in Funs.DB.Project_Installation where x.ProjectId == this.CurrUser.LoginProjectId select x).ToList();// (from x in Funs.DB.PIM_View_PmiMaterialTemplate where x.ProjectId == this.CurrUser.LoginProjectId && x..Contains(unitString) select new { x.InstallationId, x.InstallationName }).Distinct().ToList(); foreach (var q in pInstallation) { TreeNode newNode = new TreeNode(); newNode.NodeID = q.InstallationId; newNode.Text = q.InstallationName; newNode.ToolTip = "装置"; newNode.Expanded = false; rootNode.Nodes.Add(newNode); var pUnits = (from x in Funs.DB.ProjectData_WorkArea where x.ProjectId == this.CurrUser.LoginProjectId && x.InstallationId == q.InstallationId select new { x.WorkAreaId, x.WorkAreaCode }).Distinct().ToList(); foreach (var u in pUnits) { TreeNode unitsNode = new TreeNode(); unitsNode.NodeID = u.WorkAreaId + "|" + newNode.NodeID; unitsNode.Text = u.WorkAreaCode; unitsNode.ToolTip = "工区"; unitsNode.Expanded = false; unitsNode.EnableClickEvent = true; newNode.Nodes.Add(unitsNode); //var templates = (from x in Funs.DB.PMI_MaterialTemplate where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitIdName == q.InstallationId && x.AreaId == u.WorkAreaId select x).ToList(); //foreach (var t in templates) //{ // TreeNode TrustManage = new TreeNode(); // TrustManage.NodeID = t.MaterialId;// + "|" + unitsNode.NodeID; // TrustManage.Text = t.Pipeline; // TrustManage.ToolTip = "检件号"; // TrustManage.CommandName = "检件号"; // TrustManage.EnableClickEvent = true; // unitsNode.Nodes.Add(TrustManage); //} } } //} //else //{ // var pInstallation = (from x in Funs.DB.PIM_View_PmiMaterialTemplate where x.ProjectId == this.CurrUser.LoginProjectId select new { x.InstallationId, x.InstallationName }).Distinct().ToList(); // foreach (var q in pInstallation) // { // TreeNode newNode = new TreeNode(); // newNode.NodeID = q.InstallationId; // newNode.Text = q.InstallationName; // newNode.ToolTip = "装置"; // newNode.Expanded = false; // rootNode.Nodes.Add(newNode); // var pUnits = (from x in Funs.DB.PIM_View_PmiMaterialTemplate where x.ProjectId == this.CurrUser.LoginProjectId && x.InstallationId == q.InstallationId select new { x.UnitId, x.UnitName }).Distinct().ToList(); // foreach (var u in pUnits) // { // TreeNode unitsNode = new TreeNode(); // unitsNode.NodeID = u.UnitId + "|" + newNode.NodeID; // unitsNode.Text = u.UnitName; // unitsNode.ToolTip = "工区"; // unitsNode.CommandName = "PMI"; // unitsNode.Expanded = false; // newNode.Nodes.Add(unitsNode); // var PMI_TrustManage = (from x in Funs.DB.PMI_TrustManage where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitCode == q.InstallationId && x.AreaIdCode == u.UnitId select new { x.PMITrustId, x.EntrustmentNo, x.PMIProjectName }).Distinct().ToList(); // foreach (var t in PMI_TrustManage) // { // TreeNode TrustManage = new TreeNode(); // TrustManage.NodeID = t.PMITrustId + "|" + unitsNode.NodeID; // TrustManage.Text = t.EntrustmentNo; // TrustManage.ToolTip = "PMI委托单"; // TrustManage.CommandName = "PMI委托单"; // TrustManage.EnableClickEvent = true; // unitsNode.Nodes.Add(TrustManage); // } // } // } //} } #endregion #region 点击TreeView /// /// 点击TreeView /// /// /// protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e) { unitId = e.Node.ParentNode.NodeID; treeNodeId = e.Node.NodeID; this.BindGrid(treeNodeId); } #endregion #region 数据绑定 /// /// 数据绑定 /// private void BindGrid(string treeNodeId = "") { string strSql = @"SELECT [MaterialId] ,[Discpline] ,[UnitId] ,[AreaId] ,[Pipeline] ,[ItemRule] ,[CommoidyCode] ,[Size1] ,[Size2] ,[IdentCode] ,[TagNumber] ,[IdentName] ,[ShortDescription] ,[Quantity] ,[UnitNum] ,[PipeRun] ,[Category] ,[Material] ,[Spec] ,[NominalDiameter] ,[THK] ,[Painting] ,[WeightNum] ,[WeightUnit] ,[Remark] ,[ProjectId] FROM [dbo].[PMI_MaterialTemplate] WHERE ProjectId=@ProjectId"; List listStr = new List(); listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId)); if (!string.IsNullOrEmpty(treeNodeId)) { string[] nodes = treeNodeId.Split('|'); strSql += " AND AreaId=@treeNodeId"; listStr.Add(new SqlParameter("@treeNodeId", nodes[0])); } if (!string.IsNullOrEmpty(unitId)) { strSql += " AND UnitId=@unitId "; listStr.Add(new SqlParameter("@unitId", unitId)); } SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); Grid1.RecordCount = tb.Rows.Count; //tb = GetFilteredTable(Grid1.FilteredData, tb); var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); } #endregion #region 分页排序 #region 页索引改变事件 /// /// 页索引改变事件 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { Grid1.PageIndex = e.NewPageIndex; BindGrid(this.treeNodeId); } #endregion #region 排序 /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { Grid1.SortDirection = e.SortDirection; Grid1.SortField = e.SortField; BindGrid(); } #endregion #region 分页选择下拉改变事件 /// /// 分页选择下拉改变事件 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } #endregion #endregion #region 维护事件 /// /// Grid双击事件 /// /// /// protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { if (GetButtonPower(Const.BtnModify)) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PmiMaterialAddEdit.aspx?MaterialId={0}", Grid1.SelectedRowID, "编辑 - "))); } else { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } /// /// 查询信息 /// /// /// protected void btnSearch_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(treeNodeId)) { BindGrid(treeNodeId); } } /// /// 增加管线信息 /// /// /// protected void btnNew_Click(object sender, EventArgs e) { if (GetButtonPower(Const.BtnAdd)) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PmiMaterialAddEdit.aspx?MaterialId={0}", this.tvControlItem.SelectedNodeID, "新增 - "))); } else { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } /// /// 管线信息编辑 /// /// /// protected void btnMenuEdit_Click(object sender, EventArgs e) { if (GetButtonPower(Const.BtnModify)) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning); return; } PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PmiMaterialAddEdit.aspx?MaterialId={0}", Grid1.SelectedRowID, "维护 - "))); } else { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } /// /// 删除按钮 /// /// /// protected void btnMenuDelete_Click(object sender, EventArgs e) { if (GetButtonPower(Const.BtnDelete)) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning); return; } bool isShow = true; if (Grid1.SelectedRowIndexArray.Length > 1) { isShow = false; } foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][0].ToString(); BLL.PMI_MaterialTemplateService.DeletePMI_MaterialTemplate(rowID); } ShowNotify("删除成功!", MessageBoxIcon.Success); this.BindGrid(); } else { Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } #endregion #region 关闭弹出窗口及刷新页面 /// /// 关闭弹出窗口 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { this.BindGrid(); } /// /// 查询 /// /// /// protected void TextBox_TextChanged(object sender, EventArgs e) { this.BindGrid(); } /// /// 查询 /// /// /// protected void Tree_TextChanged(object sender, EventArgs e) { this.InitTreeMenu(); this.BindGrid(); } #endregion #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private bool GetButtonPower(string button) { return BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.HJGL_PipelineManageMenuId, button); } #endregion #region 导入功能 /// /// 导入功能 /// /// /// protected void btnImport_Click(object sender, EventArgs e) { if (GetButtonPower(Const.BtnAdd)) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PmiMaterialDataIn.aspx", "导入 - "))); } else { Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); return; } } #endregion protected void txtJOT_JointNo_TextChanged(object sender, EventArgs e) { // BindGrid(); } } }