Example #1
0
        public ActionResult ExportFines()
        {
            string strErrText;

            #region 提取参数

            var request = HttpContext.Request;
            string strStartTime = request.QueryString["startTime"] ?? string.Empty;
            string strEndTime = request.QueryString["endTime"] ?? string.Empty;
            string strCreatorId = request.QueryString["creatorId"] ?? string.Empty;

            #endregion

            #region 读取罚款数据

            ContractSystem contract = new ContractSystem();
            List<Contract> listContract = contract.LoadContractFinesByConditions(strStartTime, strEndTime, strCreatorId, LoginAccountId, LoginStaffName, out strErrText);
            if (listContract == null)
            {
                throw new Exception(strErrText);
            }

            #endregion

            #region 输出Excel

            //生成GridView
            BoundField colStaffName = new BoundField();
            colStaffName.HeaderText = InnoSoft.LS.Resources.Labels.StaffName;
            colStaffName.DataField = "CreatorName";

            BoundField colFineTime = new BoundField();
            colFineTime.HeaderText = InnoSoft.LS.Resources.Labels.FineTime;
            colFineTime.DataField = "FineTime";

            BoundField colContractNo = new BoundField();
            colContractNo.HeaderText = InnoSoft.LS.Resources.Labels.ContractNo;
            colContractNo.DataField = "ContractNo";

            BoundField colOriginalContractNo = new BoundField();
            colOriginalContractNo.HeaderText = InnoSoft.LS.Resources.Labels.OriginalContractNo;
            colOriginalContractNo.DataField = "OriginalContractNo";

            BoundField colFineAmount = new BoundField();
            colFineAmount.HeaderText = InnoSoft.LS.Resources.Labels.FineAmount;
            colFineAmount.DataField = "FineAmount";

            var grid = new GridView();
            grid.Columns.Add(colStaffName);
            grid.Columns.Add(colFineTime);
            grid.Columns.Add(colContractNo);
            grid.Columns.Add(colOriginalContractNo);
            grid.Columns.Add(colFineAmount);

            grid.AutoGenerateColumns = false;

            grid.DataSource = from c in listContract
                              select new
                              {
                                  CreatorName = c.CreatorName,
                                  FineTime = c.FineTime.ToString("yyyy-MM-dd"),
                                  ContractNo = c.ContractNo,
                                  OriginalContractNo = c.OriginalContractNo,
                                  FineAmount = c.FineAmount.ToString("N")
                              };
            grid.DataBind();

            //导出GridView
            Response.ClearContent();
            Response.Charset = InnoSoft.LS.Resources.Encoding.ExcelCharset;
            Response.ContentEncoding = System.Text.Encoding.GetEncoding(InnoSoft.LS.Resources.Encoding.ExcelContent);
            Response.ContentType = "application/ms-excel";
            Response.Write("<meta http-equiv=Content-Type content=text/html charset=" + InnoSoft.LS.Resources.Encoding.ExcelCharset + ">");
            Response.AddHeader("content-disposition", "attachment; filename=ContractFines.xls");
            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            grid.RenderControl(htw);
            Response.Write(sw.ToString());
            Response.End();

            #endregion

            return View("SearchFines");
        }
Example #2
0
        public JsonResult LoadSearchContractFinesGrid(string sidx, string sord, int page, int rows, string startTime, string endTime, string creatorId)
        {
            //读取数据
            string strErrText;
            ContractSystem contract = new ContractSystem();
            List<Contract> listContract = contract.LoadContractFinesByConditions(startTime, endTime, creatorId, LoginAccountId, LoginStaffName, out strErrText);
            if (listContract == null)
            {
                throw new Exception(strErrText);
            }

            //提取当前页面数据
            int nTotalRows = listContract.Count;
            int nPageIndex = page;
            int nPageSize = rows;
            int nTotalPages = nTotalRows / nPageSize;
            if (nTotalRows % nPageSize > 0)
                nTotalPages++;

            string sortExpression = (sidx ?? "FineTime") + " " + (sord ?? "ASC");
            var data = listContract.OrderBy(sortExpression).Skip((nPageIndex - 1) * nPageSize).Take(nPageSize).ToList();

            //生成表格数据
            var ret = new
            {
                total = nTotalPages,
                page = nPageIndex,
                records = nTotalRows,
                rows = (
                      from c in data
                      select new
                      {
                          id = c.Id,
                          cell = new string[] {
                              c.Id.ToString(),
                              c.CreatorName,
                              c.FineTime.ToString("yyyy-MM-dd"),
                              c.ContractNo,
                              c.OriginalContractNo,
                              c.FineAmount.ToString()
                          }
                      }).ToArray(),
                userdata = new
                {
                    CreatorName = InnoSoft.LS.Resources.Labels.Total,
                    FineAmount = data.Sum(s => s.FineAmount)
                }
            };
            return Json(ret, JsonRequestBehavior.AllowGet);
        }