Example #1
0
        /// <summary>
        /// 绑定数据
        /// </summary>
        protected void BindData()
        {
            //当前登录人站段ID
            int _OrgId = PrjPub.CurrentLoginUser.StationOrgID;
            //等1:路局 等于0:站段
            int _SuitRangeId = PrjPub.CurrentLoginUser.SuitRange;

            //考试开始时间
            if (string.IsNullOrEmpty(dateStartDateTime.DateValue.ToString()))
            {
                SessionSet.PageMessage = "请选择有效开始日期!";
            }
            DateTime _DateFrom = Convert.ToDateTime(dateStartDateTime.DateValue);

            //考试结束时间
            if (string.IsNullOrEmpty(dateEndDateTime.DateValue.ToString()))
            {
                SessionSet.PageMessage = "请选择有效结束日期!";
            }
            DateTime _DateTo = Convert.ToDateTime(dateEndDateTime.DateValue);

            beginTime.Value = _DateFrom.ToString();
            endTime.Value   = _DateTo.ToString();

            int style = Convert.ToInt32(ddlStyle.SelectedValue);

            RandomExamCountStatisticBLL objBll = new RandomExamCountStatisticBLL();
            IList <RailExam.Model.RandomExamCountStatistic> objList = objBll.GetCountWithOrg(_SuitRangeId, _OrgId, _DateFrom, _DateTo, PrjPub.GetRailSystemId(), style);

            examsGrid.DataSource = objList;
            examsGrid.DataBind();
        }
Example #2
0
        private void OutPut()
        {
            RandomExamCountStatisticBLL objBll = new RandomExamCountStatisticBLL();
            //I当前登录人ID
            int _OrgId = PrjPub.CurrentLoginUser.StationOrgID;
            //等1:路局 等于0:站段
            int _SuitRangeId = PrjPub.CurrentLoginUser.SuitRange;
            //考试开始时间
            DateTime _DateFrom = Convert.ToDateTime(dateStartDateTime.DateValue);
            //考试结束时间
            DateTime _DateTo = Convert.ToDateTime(dateEndDateTime.DateValue);
            int      style   = Convert.ToInt32(ddlStyle.SelectedValue);
            IList <RailExam.Model.RandomExamCountStatistic> objList = objBll.GetCountWithOrg(_SuitRangeId, _OrgId, _DateFrom, _DateTo, PrjPub.GetRailSystemId(), style);


            Excel.Application objApp   = new Excel.ApplicationClass();
            Excel.Workbooks   objbooks = objApp.Workbooks;
            Excel.Workbook    objbook  = objbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);
            Excel.Worksheet   objSheet = (Excel.Worksheet)objbook.Worksheets[1];          //取得sheet1
            Excel.Range       range;
            string            filename = "";

            try
            {
                //生成.xls文件完整路径名
                filename = Server.MapPath("/RailExamBao/Excel/Count.xls");

                if (File.Exists(filename.ToString()))
                {
                    File.Delete(filename.ToString());
                }

                //将所得到的表的列名,赋值给单元格

                objSheet.Cells[1, 1] = "序号";

                objSheet.Cells[1, 2] = "站段单位";
                range = objSheet.get_Range(objSheet.Cells[1, 2], objSheet.Cells[1, 4]);
                range.Merge(0);

                objSheet.Cells[1, 5] = "考试次数";

                objSheet.Cells[1, 6] = "参考人次";

                //同样方法处理数据
                for (int i = 0; i < objList.Count; i++)
                {
                    objSheet.Cells[2 + i, 1] = i + 1;

                    objSheet.Cells[2 + i, 2] = objList[i].OrgName;
                    range = objSheet.get_Range(objSheet.Cells[2 + i, 2], objSheet.Cells[2 + i, 4]);
                    range.Merge(0);

                    objSheet.Cells[2 + i, 5] = objList[i].ExamCount;

                    objSheet.Cells[2 + i, 6] = objList[i].EmployeeCount;
                }

                //不可见,即后台处理
                objApp.Visible = false;

                objbook.Saved = true;
                objbook.SaveCopyAs(filename);
            }
            catch
            {
                SessionSet.PageMessage = "系统错误,导出Excel文件失败!";
            }
            finally
            {
                objbook.Close(Type.Missing, filename, Type.Missing);
                objbooks.Close();
                objApp.Application.Workbooks.Close();
                objApp.Application.Quit();
                objApp.Quit();
                GC.Collect();
            }
        }