/// <summary> /// 测试导出Excel /// </summary> //static void aExcel() //{ // var newFile = @"Test\test.xlsx"; // using (var fs = new FileStream(newFile, FileMode.Create, FileAccess.Write)) // { // IWorkbook workbook = new XSSFWorkbook(); // ISheet sheet1 = workbook.CreateSheet("公司信息表"); // sheet1.DisplayGuts = true; // IRow row = sheet1.CreateRow(0); // var style1 = workbook.CreateCellStyle(); // style1.FillForegroundColor = HSSFColor.Tan.Index; // style1.FillPattern = FillPattern.SolidForeground; // style1.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center; // sheet1.SetColumnWidth(0, 20 * 256); // sheet1.SetColumnWidth(1, 15 * 256); // sheet1.SetColumnWidth(2, 15 * 256); // sheet1.SetColumnWidth(3, 15 * 256); // sheet1.SetColumnWidth(4, 30 * 256); // var // cell1 = row.CreateCell(0); cell1.CellStyle = style1; cell1.SetCellValue("名称"); // cell1 = row.CreateCell(1); cell1.CellStyle = style1; cell1.SetCellValue("地址"); // cell1 = row.CreateCell(2); cell1.CellStyle = style1; cell1.SetCellValue("联系方式"); // cell1 = row.CreateCell(3); cell1.CellStyle = style1; cell1.SetCellValue("法人"); // cell1 = row.CreateCell(4); cell1.CellStyle = style1; cell1.SetCellValue("注册日期"); // CompanySQLiteDao companySQLiteDao = new CompanySQLiteDao(); // IList<CompanyModel> companyModel = companySQLiteDao.Qurey(); // for (int i = 0; i < companyModel.Count; i++) // { // IRow row1 = sheet1.CreateRow(i+1); // var // cell = row1.CreateCell(0); cell.CellStyle = style1; cell.SetCellValue(companyModel[i].Name); // cell = row1.CreateCell(1); cell.CellStyle = style1; cell.SetCellValue(companyModel[i].Address); // cell = row1.CreateCell(2); cell.CellStyle = style1; cell.SetCellValue(companyModel[i].Telephone); // cell = row1.CreateCell(3); cell.CellStyle = style1; cell.SetCellValue(companyModel[i].LegalPerson); // cell = row1.CreateCell(4); cell.CellStyle = style1; cell.SetCellValue(companyModel[i].RegistrationDate); // } // workbook.Write(fs); // } //} /// <summary> /// 测试插入数据 /// </summary> void Insert() { CompanyModel companyModel = new CompanyModel(); for (int i = 0; i < 100; i++) { companyModel.Name = "DingSheng" + i.ToString(); companyModel.Address = "LiaoNingHuLudao"; companyModel.Telephone = "0430-22223333"; companyModel.LegalPerson = "MiaoMiao"; companyModel.RegistrationDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); CompanySQLiteDao companySQLiteDao = new CompanySQLiteDao(); companySQLiteDao.Insert(companyModel); } }
/// <summary> /// 加载数据库内容 /// </summary> void Reloade() { CompanySQLiteDao companySQLiteDao = new CompanySQLiteDao(); IList <CompanyModel> companyModel = companySQLiteDao.Qurey(2); CompanyData.Clear(); for (int i = 0; i < companyModel.Count; i++) { CompanyModel companyDataTemp = new CompanyModel(); companyDataTemp.Number = i + 1; companyDataTemp.Name = companyModel[i].Name; companyDataTemp.Address = companyModel[i].Address; companyDataTemp.Telephone = companyModel[i].Telephone; companyDataTemp.LegalPerson = companyModel[i].LegalPerson; companyDataTemp.RegistrationDate = companyModel[i].RegistrationDate; CompanyData.Add(companyDataTemp); } }