public static string StreamToPdf(string sql) { return(Public.StreamToPdf(sql)); }
//把数据流写入文件 #region private static void StreamToFile(string FileID, ArrayList sourceFiles, ArrayList pageName) { int DocNum = 0; //注意,下面sql语句中的字段或顺序不能变 string sql = string.Format("SELECT BZ_案卷.案卷号, BZ_文件.件号, BZ_文件.题名,BZ_文件.文件ID " + "FROM BZ_案卷 INNER JOIN BZ_文件 ON BZ_案卷.案卷ID = BZ_文件.案卷ID " + "where BZ_案卷.案卷ID = {0} ORDER BY BZ_文件.件号", FileID); #region 原dataReader写法 //System.Data.SqlClient.SqlDataReader dr = DataAccess.DataSql.ExecuteReader(sql); //while (dr.Read()) //{ // if (!(dr[0] is DBNull)) // { // //注意,下面sql语句中的字段或顺序不能变 // string sql2 = "select 序号, 原件, 扩展名, 描述 " + // "From 城建档案原件 where 文件ID={0}"; // sql2 = string.Format(sql2, dr[3].ToString());//文件ID // System.Data.SqlClient.SqlDataReader dr2 = DataAccess.DataSql.ExecuteReader(sql2); // DocNum++; // Public.WriteToFile(sourceFiles, pageName, DocNum, dr, dr2); // } //} #endregion #region 新dataset写法(从sql获取原件) //DataSet ds = DataAccess.DataSql.Query(sql); //if (ds.Tables[0].Rows.Count > 0) //{ // for (int i = 0; i < ds.Tables[0].Rows.Count; i++) // { // if (Convert.ToString(ds.Tables[0].Rows[i][0]) != string.Empty) // { // //注意,下面sql语句中的字段或顺序不能变 // string sql2 = "select 序号, 原件, 扩展名, 描述 " + // "From 城建档案原件 where 文件ID={0}"; // sql2 = string.Format(sql2, Convert.ToString(ds.Tables[0].Rows[i][3]));//文件ID // DataSet ds2 = DataAccess.DataSql.Query(sql2); // DocNum++; // Public.WriteToFile(sourceFiles, pageName, DocNum, ds, ds2, i); // } // } //} #endregion #region 新dataset写法(从ftp获取原件) DataSet ds = DataAccess.DataSql.Query(sql); if (ds.Tables[0].Rows.Count > 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { if (Convert.ToString(ds.Tables[0].Rows[i][0]) != string.Empty) { //注意,下面sql语句中的字段或顺序不能变 string sql2 = "select 序号, 扩展名, 描述, Ftp目录, Ftp保存名称 " + "From BZ_原件 where 文件ID={0} order by 序号"; sql2 = string.Format(sql2, Convert.ToString(ds.Tables[0].Rows[i][3]));//文件ID DataSet ds2 = DataAccess.DataSql.Query(sql2); DocNum++; Public.WriteToFile(sourceFiles, pageName, DocNum, ds, ds2, i); } } } #endregion }
public static void WriteToFile(ArrayList sourceFiles, ArrayList pageName, int DocNum, DataSet ds, DataSet ds2, int i) { string fileName = ""; string descript = ""; //descript = " " + DocNum.ToString("d3") + "." + Convert.ToString(ds.Tables[0].Rows[i][2]); //pageName.Add(descript); #region 原dataReader写法 //if (dr2.Read()) //{ // //如果存在原件,写入文件 // #region // MemoryStream ms = new MemoryStream((byte[])dr2[1]); //创建Stream对象 // FileStream Fs; // //存下文件名 // string pdfFileName = Myz.FileSystem.ConvertPathTo + Public.LongFileName(Convert.ToInt16(dr[0]), Convert.ToInt16(dr[1]), Convert.ToInt16(dr2[0]), "pdf"); // sourceFiles.Add(pdfFileName); // //存下描述 // if (dr2[3] is DBNull) // descript = "."; // else // descript = " " + DocNum.ToString("d3") + "." + dr2[3].ToString(); // pageName.Add(descript); // if (dr2[2].ToString().ToLower() == "pdf") // fileName = pdfFileName; // else // fileName = Myz.FileSystem.ConvertPathFrom + Public.LongFileName(Convert.ToInt16(dr[0]), Convert.ToInt16(dr[1]), Convert.ToInt16(dr2[0]), dr2[2].ToString()); // Fs = new FileStream(fileName, FileMode.Create); // //写入文件 // BinaryWriter Bw = new BinaryWriter(Fs); // Bw.Write(ms.ToArray()); // Fs.Close(); // Bw.Close(); // System.Windows.Forms.Application.DoEvents(); // #endregion //} //else //{ // //存下文件名 // string pdfFileName = Myz.FileSystem.ConvertPathTo + Public.LongFileName(Convert.ToInt16(dr[0]), Convert.ToInt16(dr[1]), 1, "pdf"); // sourceFiles.Add(pdfFileName); // //存下描述 // descript = " " + DocNum.ToString("d3") + "." + dr[2].ToString(); // pageName.Add(descript); // //生成含有文件标题的空Pdf // Public.MakeNullDocument(dr[2].ToString(), pdfFileName); // System.Windows.Forms.Application.DoEvents(); //} #endregion #region 新dataset写法 //if (ds2.Tables[0].Rows.Count > 0) //{ // //如果存在原件,写入文件 // for (int j = 0; j < ds2.Tables[0].Rows.Count; j++) // { // //MemoryStream ms = new MemoryStream((byte[])dr2[1]); //创建Stream对象 // MemoryStream ms = new MemoryStream((byte[])ds2.Tables[0].Rows[j][1]); //创建Stream对象 // FileStream Fs; // //存下文件名 // //string pdfFileName = Myz.FileSystem.ConvertPathTo + // //Public.LongFileName(Convert.ToInt16(dr[0]), // //Convert.ToInt16(dr[1]), Convert.ToInt16(dr2[0]), "pdf"); // string pdfFileName = Myz.FileSystem.ConvertPathTo + // Public.LongFileName(Convert.ToInt16(ds.Tables[0].Rows[i][0]), // Convert.ToInt16(ds.Tables[0].Rows[i][1]), // Convert.ToInt16(ds2.Tables[0].Rows[j][0]), "pdf"); // sourceFiles.Add(pdfFileName); // //存下描述 // //if (dr2[3] is DBNull) // // descript = "."; // //else // // descript = " " + DocNum.ToString("d3") + "." + dr2[3].ToString(); // if (Convert.ToString(ds2.Tables[0].Rows[j][3]) == string.Empty) // { // descript = "."; // } // else // { // descript = " " + DocNum.ToString() + "." + Convert.ToString(ds2.Tables[0].Rows[j][3]); // } // pageName.Add(descript); // //if (dr2[2].ToString().ToLower() == "pdf") // // fileName = pdfFileName; // //else // // fileName = Myz.FileSystem.ConvertPathFrom + // // Public.LongFileName(Convert.ToInt16(dr[0]), // // Convert.ToInt16(dr[1]), // // Convert.ToInt16(dr2[0]), dr2[2].ToString()); // string ext = Convert.ToString(ds2.Tables[0].Rows[j][2]); // if (ext.ToLower() == "pdf") // { // fileName = pdfFileName; // } // else // { // fileName = Myz.FileSystem.ConvertPathFrom + // Public.LongFileName(Convert.ToInt16(ds.Tables[0].Rows[i][0]), // Convert.ToInt16(ds.Tables[0].Rows[i][1]), // Convert.ToInt16(ds2.Tables[0].Rows[j][0]), // Convert.ToString(ds2.Tables[0].Rows[j][2])); // } // Fs = new FileStream(fileName, FileMode.Create); // //写入文件 // BinaryWriter Bw = new BinaryWriter(Fs); // Bw.Write(ms.ToArray()); // Fs.Close(); // Bw.Close(); // System.Windows.Forms.Application.DoEvents(); // } //} //else //{ // //存下文件名 // string pdfFileName = Myz.FileSystem.ConvertPathTo + // Public.LongFileName(Convert.ToInt16(ds.Tables[0].Rows[i][0]), // Convert.ToInt16(ds.Tables[0].Rows[i][1]), 1, "pdf"); // sourceFiles.Add(pdfFileName); // //存下描述 // descript = " " + DocNum.ToString("d3") + "." + Convert.ToString(ds.Tables[0].Rows[i][2]); // pageName.Add(descript); // //生成含有文件标题的空Pdf // Public.MakeNullDocument(Convert.ToString(ds.Tables[0].Rows[i][2]), pdfFileName); // System.Windows.Forms.Application.DoEvents(); //} #endregion #region 新dataset写法(从ftp获取原件) if (ds2.Tables[0].Rows.Count > 0) { //如果存在原件,写入文件 for (int j = 0; j < ds2.Tables[0].Rows.Count; j++) { //保存pdf文件名 string pdfFileName = Myz.FileSystem.ConvertPathTo + Public.LongFileName(Convert.ToInt16(ds.Tables[0].Rows[i][0]), Convert.ToInt16(ds.Tables[0].Rows[i][1]), Convert.ToInt16(ds2.Tables[0].Rows[j][0]), "pdf"); sourceFiles.Add(pdfFileName); //存下描述 if (Convert.ToString(ds.Tables[0].Rows[i][2]) == string.Empty) { descript = "."; } else { descript = " " + DocNum.ToString("d3") + "." + Convert.ToString(ds.Tables[0].Rows[i][2]); } pageName.Add(descript); //设置原件存放至本地的路径 string LocalPath = Myz.FileSystem.ConvertPathFrom; //设置原件存放至本地的文件名 string ext = Convert.ToString(ds2.Tables[0].Rows[j][1]); if (ext.ToLower() == "pdf") { fileName = pdfFileName; } else { fileName = Public.LongFileName(Convert.ToInt16(ds.Tables[0].Rows[i][0]), Convert.ToInt16(ds.Tables[0].Rows[i][1]), Convert.ToInt16(ds2.Tables[0].Rows[j][0]), Convert.ToString(ds2.Tables[0].Rows[j][1])); } string FtpPath = Convert.ToString(ds2.Tables[0].Rows[j][3]); string FtpFileName = Convert.ToString(ds2.Tables[0].Rows[j][4]); if (FtpPath != string.Empty && FtpFileName != string.Empty) { UIPublicClass.UpLoadDownLoad.DownLoadFile(FtpPath, FtpFileName, LocalPath, fileName); } } } else { //存下文件名 string pdfFileName = Myz.FileSystem.ConvertPathTo + Public.LongFileName(Convert.ToInt16(ds.Tables[0].Rows[i][0]), Convert.ToInt16(ds.Tables[0].Rows[i][1]), 1, "pdf"); sourceFiles.Add(pdfFileName); //存下描述 descript = " " + DocNum.ToString("d3") + "." + Convert.ToString(ds.Tables[0].Rows[i][2]); pageName.Add(descript); //生成含有文件标题的空Pdf Public.MakeNullDocument(Convert.ToString(ds.Tables[0].Rows[i][2]), pdfFileName); System.Windows.Forms.Application.DoEvents(); } #endregion }