/// <summary> /// 从CSV文件导入导师信息 /// </summary> /// <param name="filename"></param> public static string ImportTeacherFromCSVFile(string filename) { var dt = GetTemplate("teacher"); var data = CsvHelper.csv2dt(filename, 1, dt); if (data.Rows.Count < 1) { return("没有数据或数据格式不正确"); } var dal = new DAL.t_teacher(); lock (dal)//锁定 { int i = 0; int total = data.Rows.Count; var _start = DateTime.Now.Ticks; // 开始时间 foreach (DataRow item in data.Rows) { try { string gh = item["工号"].ToString(); dal.Add(new Model.t_teacher { teacher_dept_id = item["系别UUID"].ToString(), teacher_major_id = item["专业UUID"].ToString(), teacher_gh = gh, teacher_name = item["姓名"].ToString(), teacher_type = int.Parse(item["导师类型"].ToString()), teacher_pwd = Utils.HashPasswd("abc" + gh.Substring(gh.Length - 4))//默认密码取abc工号后4四位 }); i += 1; } catch { continue; } } string str = "总共" + total + "行数据,成功处理" + i + "行数据"; str += "\\n" + "耗时:" + (DateTime.Now.Ticks - _start) / 1000 + "ms"; return(str); } }
/// <summary> /// 从CSV文件导入学生信息 /// </summary> /// <param name="filename"></param> public static string ImportStudentFromCSVFile(string filename) { var dt = GetTemplate("student"); var data = CsvHelper.csv2dt(filename, 1, dt); if (data.Rows.Count < 1) { return("没有数据或数据格式不正确"); } var dal = new DAL.t_student(); lock (dal)//锁定 { int i = 0; int total = data.Rows.Count; var _start = DateTime.Now.Ticks; // 开始时间 foreach (DataRow item in data.Rows) { try { string xh = item["学号"].ToString(); dal.Add(new Model.t_student { student_class_id = item["班级UUID"].ToString(), student_name = item["姓名"].ToString(), student_xh = xh, student_pwd = Utils.HashPasswd("abc" + xh.Substring(xh.Length - 4))//默认密码取abc学号后4四位 }); i += 1; } catch { continue; } } string str = "总共" + total + "行数据,成功处理" + i + "行数据"; str += "\\n" + "耗时:" + (DateTime.Now.Ticks - _start) / 1000 + "ms"; return(str); } }
/// <summary> /// 从CSV文件导入班级信息 /// </summary> /// <param name="filename"></param> public static string ImportClassFromCSVFile(string filename) { var dt = GetTemplate("class"); var data = CsvHelper.csv2dt(filename, 1, dt); if (data.Rows.Count < 1) { return("没有数据或数据格式不正确"); } var dal = new DAL.t_class(); lock (dal)//锁定 { int i = 0; int total = data.Rows.Count; var _start = DateTime.Now.Ticks; // 开始时间 foreach (DataRow item in data.Rows) { try { dal.Add(new Model.t_class { class_major_id = item["专业UUID"].ToString(), class_name = item["姓名"].ToString(), }); i += 1; } catch { continue; } } string str = "总共" + total + "行数据,成功处理" + i + "行数据"; str += "\\n" + "耗时:" + (DateTime.Now.Ticks - _start) / 1000 + "ms"; return(str); } }