1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| using Test.BLL; using Test.Models.Book; using System.Threading.Tasks; using System; using System.Collections.Generic;
namespace Test.DAL.Book { public class Book { public DataSet ExportBookData(int BookId) { IDbConnection sqlconn = SqlUtil.SqlConnection(ConfigUtil.GetSysSettings().Book); try { string sql = @"SELECT * FROM book WHERE BookId = @BookId" sqlconn.Open(); SqlCommand sqlcomm = new SqlCommand(); sqlcomm.CommandType = CommandType.Text; sqlcomm.Connection = sqlconn; sqlcomm.CommandText = sql; sqlcomm.Parameters.Add(new SqlParameter("@BookId", BookId)); SqlDataAdapter sqlda = new SqlDataAdapter(sqlcomm); DataSet ds = new DataSet(); sqlda.Fill(ds); return ds; } catch (Exception ex) { throw new Exception("查询失败"); } finally { sqlconn.Close(); } }
public List<ExcelColumn> ExportBookColumns() { string[] columns = { "BookId" ,"BookName" ,"BookDetail" ,"BookDate" ,"SaleNumber" ,"BookPrice" ,"SaleCity" }; List<ExcelColumn> listColumns = new List<ExcelColumn>(); foreach (var column in columns) { string headName = column; switch (column) { case "BookId": headName = "BookId"; break; case "BookName": headName = "BookName"; break; case "BookDetail": headName = "BookDetail"; break; case "BookDate": headName = "BookDate"; break; case "SaleNumber": headName = "SaleNumber"; break; case "BookPrice": headName = "BookPrice"; break; case "SaleCity": headName = "SaleCity"; break; } listColumns.Add(new ExcelColumn(headName, column, 200)); } return listColumns; } } }
|