Search in sources :

Example 16 with DataSet

use of cn.cerc.jdb.core.DataSet in project summer-bean by cn-cerc.

the class BarcodeTemplate method add.

public BarcodeTemplate add(String barcode, String descspec) {
    DataSet ds = this.getDataSet();
    if (ds == null) {
        ds = new DataSet();
        this.setDataSet(ds);
    }
    ds.append();
    ds.setField("Code_", barcode);
    ds.setField("Name_", descspec);
    return this;
}
Also used : DataSet(cn.cerc.jdb.core.DataSet)

Example 17 with DataSet

use of cn.cerc.jdb.core.DataSet in project summer-bean by cn-cerc.

the class ImportExcel method exportTemplate.

public void exportTemplate() throws IOException, WriteException {
    DataSet dataOut = getDataSet();
    this.setResponse(response);
    // 取得输出流
    OutputStream os = response.getOutputStream();
    // 清空输出流
    response.reset();
    template = this.getTemplate();
    // 下面是对中文文件名的处理
    // 设置相应内容的编码格式
    response.setCharacterEncoding("UTF-8");
    String fname = URLEncoder.encode(template.getFileName(), "UTF-8");
    response.setHeader("Content-Disposition", "attachment;filename=" + fname + ".xls");
    // 定义输出类型
    response.setContentType("application/msexcel");
    List<Column> columns = template.getColumns();
    // 创建工作薄
    WritableWorkbook workbook = Workbook.createWorkbook(os);
    // 创建新的一页
    WritableSheet sheet = workbook.createSheet("First Sheet", 0);
    // 输出列头
    int row = 0;
    for (int col = 0; col < columns.size(); col++) {
        Column column = columns.get(col);
        Label item = new Label(col, row, column.getName());
        sheet.addCell(item);
    }
    // 输出列数据
    if (dataOut != null) {
        dataOut.first();
        while (dataOut.fetch()) {
            row++;
            for (int col = 0; col < columns.size(); col++) {
                Column column = columns.get(col);
                column.setRecord(dataOut.getCurrent());
                if (column instanceof NumberColumn) {
                    jxl.write.Number item = new jxl.write.Number(col, row, (double) column.getValue());
                    sheet.addCell(item);
                } else {
                    Label item = new Label(col, row, (String) column.getValue());
                    sheet.addCell(item);
                }
            }
        }
    }
    // 把创建的内容写入到输出流中,并关闭输出流
    workbook.write();
    workbook.close();
    os.close();
}
Also used : DataSet(cn.cerc.jdb.core.DataSet) OutputStream(java.io.OutputStream) Label(jxl.write.Label) WritableSheet(jxl.write.WritableSheet) WritableWorkbook(jxl.write.WritableWorkbook)

Example 18 with DataSet

use of cn.cerc.jdb.core.DataSet in project summer-bean by cn-cerc.

the class ImportFile method init.

public int init() throws UnsupportedEncodingException {
    dataSet = new DataSet();
    // 处理文件上传
    DiskFileItemFactory factory = new DiskFileItemFactory();
    // 设置最大缓存
    factory.setSizeThreshold(5 * 1024);
    ServletFileUpload upload = new ServletFileUpload(factory);
    try {
        uploadFiles = upload.parseRequest(request);
    } catch (FileUploadException e) {
        // e.printStackTrace();
        uploadFiles = null;
        return 0;
    }
    if (uploadFiles != null) {
        for (int i = 0; i < uploadFiles.size(); i++) {
            FileItem fileItem = uploadFiles.get(i);
            if (fileItem.isFormField()) {
                // 普通数据
                String val = new String(fileItem.getString().getBytes("ISO-8859-1"), "UTF-8");
                dataSet.getHead().setField(fileItem.getFieldName(), val);
            } else {
                // 文件数据
                if (fileItem.getSize() > 0) {
                    Record rs = dataSet.append().getCurrent();
                    rs.setField("_FieldNo", i);
                    rs.setField("_FieldName", fileItem.getFieldName());
                    rs.setField("_ContentType", fileItem.getContentType());
                    rs.setField("_FileName", fileItem.getName());
                    rs.setField("_FileSize", fileItem.getSize());
                }
            }
        }
    }
    dataSet.first();
    return dataSet.size();
}
Also used : FileItem(org.apache.commons.fileupload.FileItem) ServletFileUpload(org.apache.commons.fileupload.servlet.ServletFileUpload) DataSet(cn.cerc.jdb.core.DataSet) Record(cn.cerc.jdb.core.Record) DiskFileItemFactory(org.apache.commons.fileupload.disk.DiskFileItemFactory) FileUploadException(org.apache.commons.fileupload.FileUploadException)

Example 19 with DataSet

use of cn.cerc.jdb.core.DataSet in project summer-bean by cn-cerc.

the class HtmlGridTest method test_getDataSet.

@Test
public void test_getDataSet() {
    DataSet ds = new DataSet();
    for (int i = 1; i < 3; i++) ds.append().setField("Code", "C00" + i).setField("Name", "N00" + i);
    String str = HtmlGrid.getDataSet(ds);
    assertTrue(!"".equals(str));
}
Also used : DataSet(cn.cerc.jdb.core.DataSet) Test(org.junit.Test)

Example 20 with DataSet

use of cn.cerc.jdb.core.DataSet in project summer-bean by cn-cerc.

the class DataSetFileTest method testExecute.

@Test
@Ignore(value = "测试文件建立,仅在本地执行")
public void testExecute() throws RowsExceededException, WriteException, IOException {
    DataSet ds = new DataSet();
    ds.append();
    ds.setField("code", "code1");
    ds.append();
    ds.setField("code", "code2");
    String fileName = "d:\\tempfile.xls";
    new DataSetFile(ds).save(fileName);
    File file = new File(fileName);
    assertTrue("文件建立失败!", file.exists());
}
Also used : DataSet(cn.cerc.jdb.core.DataSet) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

DataSet (cn.cerc.jdb.core.DataSet)26 Record (cn.cerc.jdb.core.Record)4 LocalService (cn.cerc.jbean.client.LocalService)3 IField (cn.cerc.jpage.core.IField)3 Test (org.junit.Test)3 BuildQuery (cn.cerc.jdb.mysql.BuildQuery)2 IColumn (cn.cerc.jpage.core.IColumn)2 AbstractField (cn.cerc.jpage.fields.AbstractField)2 RowCell (cn.cerc.jpage.grid.RowCell)2 Font (com.itextpdf.text.Font)2 Paragraph (com.itextpdf.text.Paragraph)2 BaseFont (com.itextpdf.text.pdf.BaseFont)2 PdfContentByte (com.itextpdf.text.pdf.PdfContentByte)2 IOException (java.io.IOException)2 Label (jxl.write.Label)2 WritableSheet (jxl.write.WritableSheet)2 WritableWorkbook (jxl.write.WritableWorkbook)2 FileItem (org.apache.commons.fileupload.FileItem)2 Ignore (org.junit.Ignore)2 RemoteService (cn.cerc.jbean.client.RemoteService)1