using System; using System.Collections.Generic; using System.Data; using System.Data.OleDb; using System.Data.SqlClient; using System.IO; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using BLL; namespace FineUIPro.Web.HJGL.DataIn { public partial class PipeLineIn : PageBase { /// /// 导入管线的管线ID /// public string ISO_IDStr { get { return (string)ViewState["ISO_IDStr"]; } set { ViewState["ISO_IDStr"] = value; } } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ISO_IDStr = string.Empty; BindGrid(); } } private void BindGrid() { string sqlStr = @"SELECT i.ISO_ID, i.BSU_ID,i.ProjectId,i.SER_ID,ser.SER_Name AS SERName,i.ISO_IsoNo,i.ISO_Insulator,i.STE_ID,st.STE_Code AS STECode, exe.ExecStandardName AS ISO_Executive,i.ISO_Modifier,i.ISO_ModifyDate,i.ISO_Creator,i.ISO_CreateDate,i.ISO_Dia,i.ISO_Sch, i.ISO_DesignPress,i.ISO_DesignTemperature,i.ISO_TestPress,i.ISO_TestTemperature,ic.ISC_IsoName AS IDName,i.ISO_Remark,i.MaterialStandardId, i.PressureTestPackageNo,i.OperatingPressure,i.OperatingTemperature,i.PipeLineClass,i.PipeLineLength,i.LeakageTest,i.TestCategoryNum, ms.MaterialStandardCode FROM dbo.HJGL_PW_IsoInfo i LEFT OUTER JOIN dbo.HJGL_BS_Service ser ON ser.SER_ID=i.SER_ID LEFT OUTER JOIN dbo.HJGL_BS_Steel st ON st.STE_ID=i.STE_ID LEFT OUTER JOIN dbo.HJGL_BS_IsoClass ic ON ic.ISC_ID=i.ISC_ID LEFT OUTER JOIN dbo.HJGL_BS_ExecStandard exe ON exe.ExecStandardId=i.ISO_Executive LEFT OUTER JOIN dbo.HJGL_BS_MaterialStandard ms ON ms.MaterialStandardId = i.MaterialStandardId"; List listStr = new List(); sqlStr += " where CHARINDEX(i.ISO_ID,@ISO_ID)>0"; listStr.Add(new SqlParameter("@ISO_ID", ISO_IDStr)); SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(sqlStr, parameter); // 2.获取当前分页数据 //var table = this.GetPagedDataTable(Grid1, tb1); Grid1.RecordCount = tb.Rows.Count; tb = GetFilteredTable(Grid1.FilteredData, tb); var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); } protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { Grid1.PageIndex = e.NewPageIndex; BindGrid(); } protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } protected void imgbtnImport_Click(object sender, EventArgs e) { if (GetButtonPower(Const.BtnIn)) { try { if (this.FileExcel.HasFile == false) { Alert.ShowInTop("请您选择Excel文件!", MessageBoxIcon.Warning); return; } string IsXls = Path.GetExtension(FileExcel.FileName).ToString().Trim().ToLower(); if (IsXls != ".xls") { Alert.ShowInTop("只可以选择Excel文件"); return; } string rootPath = Server.MapPath("~/"); string initFullPath = rootPath + Const.ExcelUrl; if (!Directory.Exists(initFullPath)) { Directory.CreateDirectory(initFullPath); } string fileUrl = initFullPath + BLL.Funs.GetNewFileName() + IsXls; this.FileExcel.PostedFile.SaveAs(fileUrl); string oleDBConnString = String.Empty; oleDBConnString = "Provider=Microsoft.Jet.OLEDB.4.0;"; oleDBConnString += "Data Source="; oleDBConnString += fileUrl; oleDBConnString += ";Extended Properties=Excel 8.0;"; OleDbConnection oleDBConn = null; OleDbDataAdapter oleAdMaster = null; DataTable m_tableName = new DataTable(); DataSet ds = new DataSet(); oleDBConn = new OleDbConnection(oleDBConnString); oleDBConn.Open(); m_tableName = oleDBConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); if (m_tableName != null && m_tableName.Rows.Count > 0) { m_tableName.TableName = m_tableName.Rows[0]["TABLE_NAME"].ToString().Trim(); } string sqlMaster; sqlMaster = " SELECT * FROM [" + m_tableName.TableName + "]"; oleAdMaster = new OleDbDataAdapter(sqlMaster, oleDBConn); oleAdMaster.SelectCommand.CommandTimeout = 3600; oleAdMaster.Fill(ds, "m_tableName"); oleAdMaster.Dispose(); oleDBConn.Close(); oleDBConn.Dispose(); this.AddDatasetToSQL(ds.Tables[0]); if (!string.IsNullOrEmpty(fileUrl) && System.IO.File.Exists(fileUrl)) { System.IO.File.Delete(fileUrl);//删除上传的XLS文件 } this.FileExcel.Reset(); } catch (Exception ex) { ShowNotify(ex.Message, MessageBoxIcon.Warning); return; } } else { ShowNotify("您没有这个权限,请与管理员联系!"); } } #region 将Dataset的数据导入数据库 /// /// 将Dataset的数据导入数据库 /// /// 数据集 /// 数据集列数 /// private void AddDatasetToSQL(DataTable pds) { string errorInfos = string.Empty; if (pds != null && pds.Rows.Count > 0) { int ir = pds.Rows.Count; for (int i = 0; i < ir; i++) { string result = string.Empty; string col0 = pds.Rows[i][0].ToString().Trim();//单位 string col1 = pds.Rows[i][1].ToString().Trim();//项目 string col2 = pds.Rows[i][2].ToString().Trim();//单线图号 string col3 = pds.Rows[i][3].ToString().Trim();//管道等级 string col4 = pds.Rows[i][4].ToString().Trim();//执行标准 string col5 = pds.Rows[i][5].ToString().Trim();//材质 string col6 = pds.Rows[i][6].ToString().Trim();//材质标准 string col7 = pds.Rows[i][7].ToString().Trim();//介质 string col8 = pds.Rows[i][8].ToString().Trim();//试压标号 string col9 = pds.Rows[i][9].ToString().Trim();//管道类别 string col10 = pds.Rows[i][10].ToString().Trim();//涂漆类别 string col11 = pds.Rows[i][11].ToString().Trim();//绝热能力 string col12 = pds.Rows[i][12].ToString().Trim();//操作压力 string col13 = pds.Rows[i][13].ToString().Trim();//操作温度 string col14 = pds.Rows[i][14].ToString().Trim();//泄露性试验 string col15 = pds.Rows[i][15].ToString().Trim();//设计压力 string col16 = pds.Rows[i][16].ToString().Trim();//设计温度 string col17 = pds.Rows[i][17].ToString().Trim();//耐压试验 string col18 = pds.Rows[i][18].ToString().Trim();//外径 string col19 = pds.Rows[i][19].ToString().Trim();//壁厚 string col20 = pds.Rows[i][20].ToString().Trim();//管线长度 string col21 = pds.Rows[i][21].ToString().Trim();//检测类别序号 string col22 = pds.Rows[i][22].ToString().Trim();//备注 Model.HJGL_PW_IsoInfo NewIsoInfo = new Model.HJGL_PW_IsoInfo(); var getUnit = Funs.DB.Base_Unit.FirstOrDefault(x => x.UnitName == col0); var getProject = Funs.DB.Base_Project.FirstOrDefault(x => x.ProjectCode == col1); var getPipeLineClass = Funs.DB.HJGL_BS_IsoClass.FirstOrDefault(x => x.ISC_IsoName == col3);//管道等级 var getExecStandard = Funs.DB.HJGL_BS_ExecStandard.FirstOrDefault(x => x.ExecStandardName == col4);//执行标准 var getSteel = Funs.DB.HJGL_BS_Steel.FirstOrDefault(x => x.STE_Code == col5);//材质 var getMaterialStandard = Funs.DB.HJGL_BS_MaterialStandard.FirstOrDefault(x => x.MaterialStandardCode == col6);//材质标准 var getService = Funs.DB.HJGL_BS_Service.FirstOrDefault(x => x.SER_Name == col7);//介质 var PipeLineClass = BLL.DropListService.HJGL_PipeLineClassItem().FirstOrDefault(x => x.Value == col9);//管道类别 Model.HJGL_PW_IsoInfo iso = new Model.HJGL_PW_IsoInfo(); if (getUnit == null) { if (string.IsNullOrEmpty(col0)) { result += "第" + (i + 2).ToString() + "行," + "单位不能为空" + "|"; } else { result += "第" + (i + 2).ToString() + "行," + "该单位不存在" + "|"; } } if (getProject == null) { if (string.IsNullOrEmpty(col1)) { result += "第" + (i + 2).ToString() + "行," + "项目号不能为空" + "|"; } else { result += "第" + (i + 2).ToString() + "行," + "该项目不存在" + "|"; } } if (string.IsNullOrEmpty(col2)) { result += "第" + (i + 2).ToString() + "行," + "单线图号不能为空" + "|"; } if (getPipeLineClass == null) { if (string.IsNullOrEmpty(col3)) { result += "第" + (i + 2).ToString() + "行," + "管道等级不能为空" + "|"; } else { result += "第" + (i + 2).ToString() + "行," + "该管道等级不存在" + "|"; } } if (getExecStandard == null) { if (string.IsNullOrEmpty(col4)) { result += "第" + (i + 2).ToString() + "行," + "执行标准不能为空" + "|"; } else { result += "第" + (i + 2).ToString() + "行," + "该执行标准不存在" + "|"; } } if (getSteel == null) { if (string.IsNullOrEmpty(col5)) { result += "第" + (i + 2).ToString() + "行," + "材质不能为空" + "|"; } else { result += "第" + (i + 2).ToString() + "行," + "该材质不存在" + "|"; } } if (getService == null) { if (string.IsNullOrEmpty(col7)) { result += "第" + (i + 2).ToString() + "行," + "介质不能为空" + "|"; } else { result += "第" + (i + 2).ToString() + "行," + "该介质不存在" + "|"; } } if (!string.IsNullOrEmpty(col15)) { try { var DesignPress = Funs.GetNewDecimal(col15); iso.ISO_DesignPress = DesignPress; } catch (Exception) { result += "第" + (i + 2).ToString() + "行," + "设计压力格式输入有误" + "|"; } } if (!string.IsNullOrEmpty(col16)) { try { var DesignTemperature = Funs.GetNewDecimal(col16); iso.ISO_DesignTemperature = DesignTemperature; } catch (Exception) { result += "第" + (i + 2).ToString() + "行," + "设计温度格式输入有误" + "|"; } } if (!string.IsNullOrEmpty(col17)) { try { var TestPress = Funs.GetNewDecimal(col17); iso.ISO_TestPress = TestPress; } catch (Exception) { result += "第" + (i + 2).ToString() + "行," + "耐压试验格式输入有误" + "|"; } } if (!string.IsNullOrEmpty(col18)) { try { var Dia = Funs.GetNewDecimal(col18); iso.ISO_Dia = Dia; } catch (Exception) { result += "第" + (i + 2).ToString() + "行," + "外径格式输入有误" + "|"; } } if (!string.IsNullOrEmpty(col19)) { try { var Sch = Funs.GetNewDecimal(col19); iso.ISO_Sch = Sch; } catch (Exception) { result += "第" + (i + 2).ToString() + "行," + "壁厚格式输入有误" + "|"; } } if (!string.IsNullOrEmpty(col20)) { try { var PipeLineLength = Funs.GetNewDecimal(col20); iso.PipeLineLength = PipeLineLength; } catch (Exception) { result += "第" + (i + 2).ToString() + "行," + "管线长度格式输入有误" + "|"; } } if (string.IsNullOrEmpty(result)) { iso.ProjectId = getProject.ProjectId; iso.BSU_ID = getUnit.UnitId; iso.ISO_Executive = getExecStandard.ExecStandardId; iso.ISC_ID = getPipeLineClass.ISC_ID; iso.STE_ID = getSteel.STE_ID; iso.SER_ID = getService.SER_ID; if (getMaterialStandard != null) { iso.MaterialStandardId = getMaterialStandard.MaterialStandardId; } if (PipeLineClass != null) { iso.PipeLineClass = PipeLineClass.Value; } iso.PressureTestPackageNo = col8; iso.ISO_Paint = col10; iso.ISO_Insulator = col11; iso.OperatingPressure = col12; iso.OperatingTemperature = col13; iso.LeakageTest = col14; iso.TestCategoryNum = col21; iso.ISO_Remark = col22; var getIsoInfo = Funs.DB.HJGL_PW_IsoInfo.FirstOrDefault(x =>x.BSU_ID==getUnit.UnitId && x.ProjectId==getProject.ProjectId && x.ISO_IsoNo == col2); if (getIsoInfo == null) { iso.ISO_IsoNo = col2; iso.ISO_ID = SQLHelper.GetNewID(typeof(Model.HJGL_PW_IsoInfo)); BLL.HJGL_PW_IsoInfoService.AddIsoInfo(iso); ISO_IDStr += Funs.DB.HJGL_PW_IsoInfo.FirstOrDefault(x => x.BSU_ID == getUnit.UnitId && x.ProjectId == getProject.ProjectId && x.ISO_IsoNo == col2).ISO_ID + ",";//获取当前导入的管线ID(绑定列表时用) } else { result += "第" + (i + 2).ToString() + "行," + "该工艺管线已存在" + "|"; } } errorInfos += result; } if (!string.IsNullOrEmpty(ISO_IDStr)) { ISO_IDStr = ISO_IDStr.Substring(0, ISO_IDStr.LastIndexOf(",")); } this.BindGrid(); if (!string.IsNullOrEmpty(errorInfos)) { errorInfos = "未成功数据:" + errorInfos.Substring(0, errorInfos.LastIndexOf("|")); Alert.ShowInParent("数据已导入!" + errorInfos, MessageBoxIcon.Warning); } else { ShowNotify("数据导入成功!", MessageBoxIcon.Success); } } else { ShowNotify("导入数据为空!", MessageBoxIcon.Success); return; } } #endregion protected void imgbtnUpload_Click(object sender, EventArgs e) { string uploadfilepath = Server.MapPath("~/") + BLL.Const.PiprLineInTemplateUrl; string fileName = Path.GetFileName(BLL.Const.PiprLineInTemplateUrl); FileInfo info = new FileInfo(uploadfilepath); if (info.Exists) { long fileSize = info.Length; Response.Clear(); Response.ContentType = "application/x-zip-compressed"; Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8)); Response.AddHeader("Content-Length", fileSize.ToString()); Response.TransmitFile(uploadfilepath, 0, fileSize); Response.Flush(); Response.Close(); } else { ShowNotify("文件不存在!", MessageBoxIcon.Warning); } } protected void btnMenuDelete_Click(object sender, EventArgs e) { if (GetButtonPower(Const.BtnDelete)) { if (Grid1.SelectedRowIndexArray.Length > 0) { foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][0].ToString(); var IsoIn = BLL.HJGL_PW_IsoInfoService.GetIsoInfoByIsoInfoId(rowID); if (IsoIn != null) { BLL.HJGL_PW_IsoInfoService.DeleteIsoInfo(rowID); ShowNotify("删除数据成功!(表格数据已重新绑定)"); } } } BindGrid(); } else { ShowNotify("您没有这个权限,请与管理员联系!"); } } #region 判断按钮权限 /// /// 获取按钮权限 /// /// /// private bool GetButtonPower(string button) { return BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.PipeLineInMenuId, button); } #endregion } }