コード例 #1
0
        public void ReportCard()
        {
            IList <Registration> _registrationList = null;

            Employee _employee = Session["logonUser"] as Employee;

            if (_employee != null)
            {
                Registration _registration = new Registration();
                _registration.EmployeeID = _employee.ID;

                _registrationList = _registrationService.GetRegistration(_registration);
                foreach (Registration Registration in _registrationList)
                {
                    IDictionary _hash = new Hashtable();

                    _hash.Add("pageIndex", 1);
                    _hash.Add("pageSize", 100);
                    _hash.Add("JOIN", "INNER");
                    _hash.Add("EmployeeID", Registration.EmployeeID);

                    Registration.ReportCardList = _reportCardService.GetReportCard(_hash);
                }

                PropertyBag["employee"]         = _employee;
                PropertyBag["registrationList"] = _registrationList;
            }
        }
コード例 #2
0
        /// <summary>
        /// 学生成绩列表
        /// </summary>
        /// <param name="userID">用户ID</param>
        public void ReportCardList(int userID)
        {
            IList <Registration> _registrationList = null;

            Registration _registration = new Registration();

            _registration.EmployeeID = userID;

            _registrationList = _registrationService.GetRegistration(_registration);
            foreach (Registration Registration in _registrationList)
            {
                IDictionary _hash = new Hashtable();

                _hash.Add("EmployeeID", Registration.EmployeeID);

                Registration.ReportCardList = _reportCardService.GetReportCard(_hash);
            }

            _result.Code = 0;
            _result.Data = _registrationList;
            string _jsonString = JsonConvert.SerializeObject(_result, Formatting.Indented);

            RenderText(_jsonString);
            CancelLayout();
        }
コード例 #3
0
        public void PostImportExcel()
        {
            string _fileExt = string.Empty;
            int    _code    = 0;
            string _message = string.Empty;

            try
            {
                HttpPostedFile _uploadFiles = Request.Files["uploadFile"] as HttpPostedFile;

                if (_uploadFiles == null || _uploadFiles.FileName.Length < 3)
                {
                    _message = "您没有选择要上传的文件!";
                    _code    = -4;
                }
                else
                {
                    _fileExt = Path.GetExtension(_uploadFiles.FileName).ToLower(); //获取文件扩展名
                    String[] _allowedExt = { ".xls", ".xlsx" };                    //允许上传的文件格式
                    if (!_allowedExt.Contains(_fileExt))
                    {
                        _message = "您上传的格式为" + _fileExt + ", 本统只接受扩展名为" + string.Join("、", _allowedExt) + "格式文件";
                        _code    = -3;
                    }
                    else if (_uploadFiles.ContentLength == 0)
                    {
                        _message = "上传的内容为空!";
                        _code    = -2;
                    }
                    else if (_uploadFiles.ContentLength > 1024 * 1024 * 8)
                    {
                        _message = "您上传的文件超过了8M!";
                        _code    = -1;
                    }
                }

                if (_code == 0)
                {
                    string _fileName    = ShortFileNameUtil.ShortFileName(Guid.NewGuid().ToString()) + _fileExt;
                    string _virtualPath = "/UploadFiles/reportCardXls/";

                    string _physicalPath = HttpContext.Server.MapPath(_virtualPath);
                    if (!Directory.Exists(_physicalPath))
                    {
                        Directory.CreateDirectory(_physicalPath);
                    }
                    string _fullPath = _physicalPath + _fileName;
                    _uploadFiles.SaveAs(_fullPath);

                    DataTable _employeeData = JNyuluUtils.ImportExcel(_fullPath);
                    int       _i            = 0;

                    StringBuilder _result = new StringBuilder();
                    _result.AppendLine("上传路径为:" + _virtualPath + _fileName);
                    _result.AppendLine("导入记录数为:" + _employeeData.Rows.Count + " , Excel解析日志记录:");
                    foreach (DataRow dr in _employeeData.Rows)
                    {
                        _i++;
                        try
                        {
                            //dr["班级"] dr["学籍号"] dr["学生姓名"] dr["考试时间"] dr["试卷路径"];
                            string   _name     = dr["学籍号"].ToString() + "";
                            Employee _employee = _employeeService.GetEmployeeByName(_name);

                            if (_employee == null)
                            {
                                LogHelper.Info("记录[" + _i + "]学籍:" + _name + "  不存在");
                                _result.AppendLine("记录[" + _i + "]学籍:" + _name + "  不存在");
                                continue;
                            }

                            string     _schoolTermName = dr["班级"].ToString() + "";
                            SchoolTerm _schoolTerm     = _schoolTermService.GetBaseSchoolTermByName(_schoolTermName);
                            if (_schoolTerm == null)
                            {
                                LogHelper.Info("记录[" + _i + "]班级:" + _schoolTermName + "  不存在");
                                _result.AppendLine("记录[" + _i + "]班级:" + _schoolTermName + "  不存在");
                                continue;
                            }

                            _result.AppendLine("记录[" + _i + "] employeeID:[" + _employee.ID + "]  班级ID:[" + _schoolTerm.ID + "]");

                            if (_employee.ID > 0 && _schoolTerm.ID > 0)
                            {
                                ReportCard _reportCard = new ReportCard();
                                _reportCard.EmployeeID = _employee.ID;
                                _reportCard.STID       = _schoolTerm.ID;

                                DateTime _examDate = DateTime.Today;
                                if (DateTime.TryParse(dr["考试时间"].ToString() + "", out _examDate))
                                {
                                    _reportCard.ExamDate = _examDate;
                                }
                                else
                                {
                                    LogHelper.Info("记录[" + _i + "]考试时间格式错误");
                                    _result.AppendLine("记录[" + _i + "]考试时间格式错误");
                                    continue;
                                }
                                string _testPaper = dr["试卷路径"].ToString() + "";
                                if (!string.IsNullOrEmpty(_testPaper))
                                {
                                    _reportCard.TestPaperUrl = "/UploadFiles/testPaperFiles/" + _testPaper;
                                }

                                IDictionary _hash = new Hashtable();

                                _hash.Add("EmployeeID", _reportCard.EmployeeID);
                                _hash.Add("STID", _reportCard.STID);
                                _hash.Add("TestPaperUrl", _reportCard.TestPaperUrl);

                                IList <ReportCard> _reportCardList = _reportCardService.GetReportCard(_hash);
                                _result.AppendLine("记录[" + _i + "](" + _reportCard.TestPaperUrl + ") _reportCardList.Count:" + _reportCardList.Count);
                                if (_reportCardList.Count > 0)
                                {
                                    _reportCard.ID = _reportCardList[0].ID;
                                    _code          = _reportCardService.UpdateReportCard(_reportCard);
                                }
                                else
                                {
                                    _reportCard.ID = _reportCardService.InsertReportCard(_reportCard);
                                }
                                _result.AppendLine("记录[" + _i + "] _reportCard.ID:" + _reportCard.ID);

                                _code = _reportCard.ID;
                            }
                        }
                        catch (Exception ex)
                        {
                            _result.AppendLine(ex.ToString());
                            LogHelper.Error(ex.ToString());
                            continue;
                        }
                    }

                    _message = _result.ToString();
                }
            }
            catch (Exception ex)
            {
                _code    = -1;
                _message = ex.Message;
            }
            finally
            {
                RenderText("{code: " + _code + ",message: \"" + _message.Replace(@"\", @"\\") + "\"}");

                CancelLayout();
            }
        }