Beispiel #1
0
    public void FindBaseByCode()
    {
        string          startTime = Context.Request.Form["startTime"];
        string          endTime   = Context.Request.Form["endTime"];
        string          baseCode  = Context.Request.Form["baseName"];
        string          rows      = Context.Request.Form["rows"];
        string          page      = Context.Request.Form["page"];
        IList <BasBase> baseInfo  = _bal.FindBaseByCode(startTime, endTime, baseCode);
        List <BasBase>  bs        = new List <BasBase>();
        int             istart    = (Convert.ToInt32(page) - 1) * Convert.ToInt32(rows);
        int             iend      = Convert.ToInt32(page) * Convert.ToInt32(rows) + 1;
        int             j         = 1;

        foreach (BasBase bb in baseInfo)
        {
            if (j > istart && j < iend)
            {
                BasBase bbtemp = new BasBase();
                bbtemp           = bb;
                bbtemp.UpdatedBy = FindUserNameByCode(bbtemp.UpdatedBy);
                bs.Add(bbtemp);
            }
            j++;
        }
        Dictionary <String, Object> map = new Dictionary <String, Object>();

        if (baseInfo != null & baseInfo.Count > 0)
        {
            map.Add("total", baseInfo.Count);
        }
        map.Add("rows", bs);
        Context.Response.Write(JsonConvert.SerializeObject(map));
    }
Beispiel #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string startTime = Request.QueryString["startTime"];
        string endTime   = Request.QueryString["endTime"];
        string baseCode  = Request.QueryString["baseName"];


        BasicBO         _bal     = BLLFactory.GetBal <BasicBO>(userInfo);
        IList <BasBase> baseInfo = _bal.FindBaseByCode(startTime, endTime, baseCode);
        WsSystem        ws       = new WsSystem();

        if (baseInfo == null || baseInfo.Count == 0)
        {
            Response.Write("no data");
            return;
        }

        HSSFWorkbook hssfWorkbook = new HSSFWorkbook();
        Row          row          = null;
        Cell         cell         = null;
        Sheet        hssfSheet    = hssfWorkbook.CreateSheet("BaseInfo");

        row = hssfSheet.CreateRow(0);
        //填充头
        string objs = "信息编号,信息名称,子信息编码,子信息名称,操作人,时间";

        for (int i = 0; i < objs.Split(',').Length; i++)
        {
            cell = row.CreateCell(i);
            cell.SetCellValue(objs.Split(',')[i]);
        }
        if (baseInfo != null)
        {
            for (int i = 2; i <= baseInfo.Count + 1; i++)
            {
                row  = hssfSheet.CreateRow(i);
                cell = row.CreateCell(0);
                cell.SetCellValue(baseInfo[i - 2].CODE);
                cell = row.CreateCell(1);
                cell.SetCellValue(baseInfo[i - 2].NAME);
                cell = row.CreateCell(2);
                cell.SetCellValue(baseInfo[i - 2].SubCode);
                cell = row.CreateCell(3);
                cell.SetCellValue(baseInfo[i - 2].SubName);
                cell = row.CreateCell(4);
                cell.SetCellValue(ws.FindUserNameByCode(baseInfo[i - 2].UpdatedBy));
                cell = row.CreateCell(5);
                cell.SetCellValue(baseInfo[i - 2].UpdatedDate == null ? baseInfo[i - 2].CreatedDate.ToString() : baseInfo[i - 2].UpdatedDate.ToString());
            }
        }

        MemoryStream file = new MemoryStream();

        hssfWorkbook.Write(file);
        String fileName = "BaseInfo" + DateTime.Now.ToString("yyyyMMddHHmmss");

        Response.Clear();
        Response.ClearContent();
        Response.ClearHeaders();
        Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}.xls", fileName));
        Response.AddHeader("Content-Length", file.Length.ToString());
        Response.AddHeader("Content-Transfer-Encoding", "binary");
        Response.ContentType     = "application/octet-stream";
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
        Response.BinaryWrite(file.GetBuffer());
        Response.Flush();
        Response.End();
    }