Exemple #1
0
        public HttpResponseMessage EditTeacher([FromBody] TeacherInfo m)
        {
            Tch_Info tch = MongoDbHelper.FindOne <Tch_Info>(m.ID, DbName.Tch_Info);

            if (tch == null)
            {
                return(ResultHelper.Failed("未找到该老师信息"));
            }
            if (!Function.MathPhone(m.Phone.ToString()))
            {
                return(ResultHelper.Failed("请输入有效手机号"));
            }
            tch.sb = m.Subject;
            tch.nm = m.Name;
            tch.sx = m.Sex == "男" ? 1 : 0;
            tch.zc = m.Title;
            tch.ph = m.Phone;
            MongoDbHelper.ReplaceOne(m.ID, tch, DbName.Tch_Info);
            return(ResultHelper.OK());
        }
Exemple #2
0
 public HttpResponseMessage DelTeacher([FromBody] DelStuOrTch m)
 {
     lock (_locker)
     {
         var exam = MongoDbHelper.FindOne <E_Info>(m.ExamID, DbName.E_Info);
         if (exam == null)
         {
             return(ResultHelper.Failed("未找到该次考试"));
         }
         Tch_Info tch = MongoDbHelper.FindOne <Tch_Info>(m.UserID, DbName.Tch_Info);
         if (tch == null)
         {
             return(ResultHelper.Failed("未找到该老师信息"));
         }
         var sb = exam.sbs.Where(w => w.sbnm == tch.sb).FirstOrDefault();
         sb.tchct--;
         MongoDbHelper.DeleteOne <Tch_Info>(m.UserID, DbName.Tch_Info);
         MongoDbHelper.ReplaceOne(m.ExamID, exam, DbName.E_Info);
         return(ResultHelper.OK());
     }
 }
Exemple #3
0
        /// <summary>
        /// 导入老师表格
        /// </summary>
        /// <param name="path"></param>
        /// <param name="exam"></param>
        /// <returns></returns>
        public static string ImportTchExcel(string path, E_Info exam, string SchoolID, out int errnum)
        {
            HSSFWorkbook hssfworkbook;

            #region//初始化信息
            try
            {
                using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
                {
                    hssfworkbook = new HSSFWorkbook(fs);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            #endregion
            NPOI.SS.UserModel.ISheet       sheet = hssfworkbook.GetSheetAt(0);
            System.Collections.IEnumerator rows  = sheet.GetRowEnumerator();
            DataTable dt = new DataTable();
            rows.MoveNext();
            HSSFRow       row  = (HSSFRow)rows.Current;
            List <string> cols = new List <string>();
            for (int j = 0; j < (sheet.GetRow(0).LastCellNum); j++)
            {
                cols.Add(row.GetCell(j).ToString().Trim());
                dt.Columns.Add(row.GetCell(j).ToString());
            }
            var colHead = GetTchColumn();
            if (!(colHead.All(cols.Contains) && cols.All(colHead.Contains)))
            {
                errnum = 0;
                return("表格格式错误,请重新下载模板");
            }
            cols.Add("错误原因");
            dt.Columns.Add("错误原因");
            while (rows.MoveNext())
            {
                row = (HSSFRow)rows.Current;
                if (!IsNull(row, 0) || !IsNull(row, 1) || !IsNull(row, 2))
                {
                    continue;
                }
                var school = MongoDbHelper.QueryOne <U_Info>(DbName.U_Info, w => w._id == row.GetCell(0).ToString());
                var ifTrue = false;
                if (SchoolID != "SchoolID" && school != null)
                {
                    ifTrue = !(SchoolID == school._id);
                }
                var sbsnm = exam.sbs.Select(s => s.sbnm).ToList();
                if (!sbsnm.Contains(row.GetCell(2).ToString()) || school == null || ifTrue || !IsNull(row, 4) || !IsNull(row, 5) || !IsNull(row, 6) || !Function.MathPhone(row.GetCell(6).ToString()))
                {
                    DataRow dr = dt.NewRow();
                    for (int i = 0; i < (sheet.GetRow(0).LastCellNum); i++)
                    {
                        NPOI.SS.UserModel.ICell cell = row.GetCell(i);
                        if (cell == null)
                        {
                            dr[i] = null;
                        }
                        else
                        {
                            dr[i] = cell.ToString();
                        }
                    }
                    if (school == null)
                    {
                        dr[sheet.GetRow(0).LastCellNum] += "学校不存在;";
                    }
                    if (ifTrue)
                    {
                        dr[sheet.GetRow(0).LastCellNum] += "学校代号错误;";
                    }
                    if (!sbsnm.Contains(row.GetCell(2).ToString()))
                    {
                        dr[sheet.GetRow(0).LastCellNum] += "学科不存在;";
                    }
                    if (!Function.MathPhone(row.GetCell(6).ToString()))
                    {
                        dr[sheet.GetRow(0).LastCellNum] += "手机号不正确;";
                    }
                    dt.Rows.Add(dr);
                    continue;
                }

                Tch_Info tch = new Tch_Info();
                tch.eid = exam._id;
                tch.sid = row.GetCell(0).ToString();
                tch.snm = school.snm;
                tch.sb  = row.GetCell(2).ToString().Replace(" ", "");
                tch.nm  = row.GetCell(3).ToString();
                tch.sx  = row.GetCell(4).ToString() == "男" ? 1 : 0;
                tch.zc  = row.GetCell(5).ToString();
                tch.ph  = Convert.ToInt64(row.GetCell(6).ToString());
                var sbinfo = exam.sbs.Where(w => w.sbnm == tch.sb).FirstOrDefault();
                if (sbinfo != null)
                {
                    sbinfo.tchct++;
                }
                MongoDbHelper.Insert(tch, DbName.Tch_Info);
            }
            MongoDbHelper.ReplaceOne(exam._id.ToString(), exam, DbName.E_Info);
            errnum = dt.Rows.Count;
            if (dt.Rows.Count > 0)
            {
                return(BuildExcel1(cols.ToArray(), dt));
            }
            return("");
        }