using BLL; using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Data; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; namespace FineUIPro.Web.JGZL { public partial class IndustrialPipelineInstallationQualityCertificate : PageBase { #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString(); this.drpProjectId.DataTextField = "ProjectCode"; this.drpProjectId.DataValueField = "ProjectId"; this.drpProjectId.DataSource = BLL.Base_ProjectService.GetOnProjectListByUserId(this.CurrUser.UserId, "1"); this.drpProjectId.DataBind(); Funs.FineUIPleaseSelect(this.drpProjectId); this.drpProjectId.SelectedValue = this.CurrUser.LoginProjectId; this.InitTreeMenu();//加载树 this.tvControlItem.SelectedNodeID = this.drpProjectId.SelectedValue; this.BindGrid(); } } #endregion #region 加载树项目 /// /// 加载树 /// private void InitTreeMenu() { this.tvControlItem.Nodes.Clear(); TreeNode rootNode = new TreeNode(); rootNode.Text = "项目"; rootNode.ToolTip = "项目"; rootNode.NodeID = "0"; rootNode.Expanded = true; this.tvControlItem.Nodes.Add(rootNode); List projects = BLL.Base_ProjectService.GetOnProjectListByUserId(this.CurrUser.UserId, "1"); if (this.drpProjectId.SelectedValue != BLL.Const._Null) { projects = projects.Where(e => e.ProjectId == this.drpProjectId.SelectedValue).ToList(); } foreach (var item in projects) { TreeNode rootProjectNode = new TreeNode();//定义根节点 rootProjectNode.Text = item.ProjectCode; rootProjectNode.NodeID = item.ProjectId; rootProjectNode.EnableClickEvent = true; rootProjectNode.Expanded = true; rootProjectNode.ToolTip = item.ProjectName; rootProjectNode.CommandName = "项目名称"; rootNode.Nodes.Add(rootProjectNode); } } #endregion #region 点击TreeView /// /// 点击TreeView /// /// /// protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e) { if (this.tvControlItem.SelectedNodeID != "0") { this.BindGrid(); } } #endregion #region 数据绑定 /// /// 数据绑定 /// private void BindGrid() { //string projectIds = BLL.Base_ProjectService.GetStrOnProjectIds(this.CurrUser.UserId, "1"); string strSql = @"SELECT * from JGZL_IndustrialPipelineInstallationQualityCertificate where 1=1"; List listStr = new List(); if (!string.IsNullOrEmpty(this.tvControlItem.SelectedNodeID)) { strSql += " AND ProjectId = @ProjectId"; listStr.Add(new SqlParameter("@ProjectId", this.tvControlItem.SelectedNodeID)); } //else //{ // strSql += " AND CHARINDEX(ProjectId,@ProjectId)>0 "; // listStr.Add(new SqlParameter("@ProjectId", projectIds)); //} SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); // 2.获取当前分页数据 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) { BindGrid(); } #endregion #region 排序 /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { BindGrid(); } #endregion #region 分页选择下拉改变事件 /// /// 分页选择下拉改变事件 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } #endregion #endregion #region 查询 /// ///查询 /// /// /// protected void drpProjectId_SelectedIndexChanged(object sender, EventArgs e) { this.InitTreeMenu(); this.BindGrid(); } /// /// 查询 /// /// /// protected void TextBox_TextChanged(object sender, EventArgs e) { this.BindGrid(); } #endregion #region 打印 /// /// 打印 /// /// /// protected void btnPrint_Click(object sender, EventArgs e) { string projectId = this.tvControlItem.SelectedNodeID; if (projectId != null) { string initTemplatePath = ""; string rootPath = Server.MapPath("~/"); BLL.Common.FastReportService.ResetData(); string strSql = @"SELECT * from JGZL_IndustrialPipelineInstallationQualityCertificate where ProjectId = @ProjectId order by DrawingNumber desc"; List listStr = new List(); listStr.Add(new SqlParameter("@ProjectId", projectId)); SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); DataTable dt = new DataTable(); dt.TableName = "Data"; dt.Columns.Add("Num"); dt.Columns.Add("CertificateCode"); dt.Columns.Add("EngineeringName"); dt.Columns.Add("EngineeringCode"); dt.Columns.Add("DeliveryUnit"); dt.Columns.Add("DeliveryUnitCode"); dt.Columns.Add("InstallStartDate"); dt.Columns.Add("InstallEndDate"); dt.Columns.Add("PipelineLevel"); dt.Columns.Add("PipelineLength"); dt.Columns.Add("DesignUnit"); dt.Columns.Add("LosslessTestingAgency"); dt.Columns.Add("SupervisoryAndInspectionAgency"); dt.Columns.Add("ConstructionUnit"); dt.Columns.Add("SpecialEquipmentProductionLicenseCode"); dt.Columns.Add("Remark"); DataRow[] rows = tb.DefaultView.ToTable().Select(); int i = 0; foreach (var row in rows) { var newRow = dt.NewRow(); newRow["Num"] = (i + 1).ToString(); newRow["CertificateCode"] = row["CertificateCode"].ToString(); newRow["EngineeringName"] = row["EngineeringName"].ToString(); newRow["EngineeringCode"] = row["EngineeringCode"].ToString(); newRow["DeliveryUnit"] = row["DeliveryUnit"].ToString(); newRow["DeliveryUnitCode"] = row["DeliveryUnitCode"].ToString(); newRow["InstallStartDate"] = row["InstallStartDate"].ToString(); newRow["InstallEndDate"] = row["InstallEndDate"].ToString(); newRow["PipelineLevel"] = row["PipelineLevel"].ToString(); newRow["PipelineLength"] = row["PipelineLength"].ToString(); newRow["DesignUnit"] = row["DesignUnit"].ToString(); newRow["LosslessTestingAgency"] = row["LosslessTestingAgency"].ToString(); newRow["SupervisoryAndInspectionAgency"] = row["SupervisoryAndInspectionAgency"].ToString(); newRow["ConstructionUnit"] = row["ConstructionUnit"].ToString(); newRow["SpecialEquipmentProductionLicenseCode"] = row["SpecialEquipmentProductionLicenseCode"].ToString(); newRow["Remark"] = row["Remark"].ToString(); dt.Rows.Add(newRow); i++; } BLL.Common.FastReportService.AddFastreportTable(dt); Dictionary keyValuePairs = new Dictionary(); keyValuePairs.Add("ProjectName", BLL.Base_ProjectService.GetProjectByProjectId(projectId).ProjectName); BLL.Common.FastReportService.AddFastreportParameter(keyValuePairs); initTemplatePath = "File\\Fastreport\\JGZL\\工业管道安装质量证明书.frx"; if (File.Exists(rootPath + initTemplatePath)) { PageContext.RegisterStartupScript(WindowPrint.GetShowReference(String.Format("../common/ReportPrint/Fastreport.aspx?ReportPath={0}", rootPath + initTemplatePath))); } } else { Alert.ShowInTop("请选择项目!", MessageBoxIcon.Warning); return; } } #endregion #region 维护 /// /// 增加 /// /// /// protected void btnAdd_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(this.tvControlItem.SelectedNodeID)) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("IndustrialPipelineInstallationQualityCertificateEdit.aspx?projectId={0}", this.tvControlItem.SelectedNodeID, "新增 - "))); } else { Alert.ShowInTop("请选择项目!", MessageBoxIcon.Warning); return; } } /// /// 双击编辑 /// /// /// protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.JGZL_IndustrialPipelineInstallationQualityCertificateMenuId, BLL.Const.BtnModify)) { if (!string.IsNullOrEmpty(this.tvControlItem.SelectedNodeID)) { if (!string.IsNullOrEmpty(this.Grid1.SelectedRowID)) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("IndustrialPipelineInstallationQualityCertificateEdit.aspx?certificateId={0}", this.Grid1.SelectedRowID, "编辑 - "))); } else { Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning); return; } } else { Alert.ShowInTop("请选择项目!", MessageBoxIcon.Warning); return; } } else { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } /// /// 右键编辑 /// /// /// protected void btnMenuEdit_Click(object sender, EventArgs e) { if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.JGZL_IndustrialPipelineInstallationQualityCertificateMenuId, BLL.Const.BtnModify)) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning); return; } PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("IndustrialPipelineInstallationQualityCertificateEdit.aspx?certificateId={0}", Grid1.SelectedRowID, "维护 - "))); } else { Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } /// /// 右键删除 /// /// /// protected void btnMenuDelete_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.JGZL_IndustrialPipelineInstallationQualityCertificateMenuId, Const.BtnDelete)) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning); return; } bool isShow = true; if (Grid1.SelectedRowIndexArray.Length > 1) { isShow = false; } bool isDelete = false; foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][0].ToString(); if (judgementDelete(rowID, isShow)) { isDelete = true; BLL.IndustrialPipelineInstallationQualityCertificateService.DeleteIndustrialPipelineInstallationQualityCertificateById(rowID); BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "删除工业管道安装质量证明书"); } } if (isDelete) { ShowNotify("删除成功!", MessageBoxIcon.Success); } this.BindGrid(); } else { Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } #region 判断是否可删除 /// /// 判断是否可以删除 /// /// private bool judgementDelete(string id, bool isShow) { string content = string.Empty; if (string.IsNullOrEmpty(content)) { return true; } else { if (isShow) { Alert.ShowInTop(content, MessageBoxIcon.Error); } return false; } } #endregion #endregion #region 关闭弹出窗口及刷新页面 /// /// 关闭弹出窗口 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { this.InitTreeMenu();//加载树 this.BindGrid(); } #endregion } }