/// <summary> /// search student information /// </summary> /// <param name="query">query string </param> /// <param name="e">reference variable use for return query error information</param> /// <returns>query result</returns> /// public static List <tbl_student> search(string keywords, ref Err e) { //todo judge query exist try { DataBase db = new DataBase(); List <tbl_student> result = new List <tbl_student>(); result.AddRange(( from d in db.tbl_student where d.S_Num.IndexOf(keywords) >= 0 orderby d.S_index select d ).ToList()); result.AddRange(( from d in db.tbl_student where d.S_Name.IndexOf(keywords) >= 0 orderby d.S_index select d ).ToList()); result.AddRange(( from d in db.tbl_student where d.S_Gender.IndexOf(keywords) >= 0 orderby d.S_index select d ).ToList()); result.AddRange(( from d in db.tbl_student where d.S_Department.IndexOf(keywords) >= 0 orderby d.S_index select d ).ToList()); return(result); } catch (Exception ex) { e.res = false; e.info = ex.Message; return(null); } }
public static Err update(tbl_course cc) { Err e = new Err(); try { DataBase db = new DataBase(); tbl_course c = ( from d in db.tbl_course where d.C_index == cc.C_index select d ).Single(); c = cc; db.SaveChanges(); } catch (Exception ex) { e.res = false; e.info = ex.Message; } return(e); }
/// <summary> /// change user information(not include index!!!!) /// /// 1. connecting to database /// 2. find the object befor information /// 3. change the value of the object /// 4. save change in database /// </summary> /// <param name="user">input user information</param> /// <returns>error information</returns> public static Err update(tbl_user user) { Err e = new Err(); try { var db = new DataBase(); var before = (from d in db.tbl_user where d.U_index == user.U_index select d).Single(); before.U_ID = user.U_ID; before.U_Power = user.U_Power; before.U_PWD = user.U_PWD; db.SaveChanges(); } catch (Exception ex) { e.res = false; e.info = ex.Message; } return(e); }
public static Err mark_update(int index, decimal new_mark) { Err e = new Err(); try { using (var db = new DataBase()) { tbl_stu_mark tsm = ( from d in (new DataBase()).tbl_stu_mark where d.mk_index == index select d ).Single(); tsm.mk_mark = new_mark; db.SaveChanges(); } } catch (Exception ex) { } return(e); }
public static List <tbl_student> searchtime( DateTime birthday_start, DateTime birthday_end, ref Err e) { //todo judge query exist try { DataBase db = new DataBase(); var q = from d in db.tbl_student where d.S_Birthday >= birthday_start && d.S_Birthday <= birthday_end orderby d.S_index select d; return(q.ToList()); } catch (Exception ex) { e.res = false; e.info = ex.Message; return(null); } }
public static List <tbl_course> search(string keyword, ref Err e) { try { using (var db = new DataBase()) { List <tbl_course> result = new List <tbl_course>(); result.AddRange(( from d in db.tbl_course where d.C_Num.IndexOf(keyword) >= 0 orderby d.C_Num select d ).ToList()); result.AddRange(( from d in db.tbl_course where d.C_Name.IndexOf(keyword) >= 0 orderby d.C_Num select d ).ToList()); result.AddRange(( from d in db.tbl_course where d.C_Course.IndexOf(keyword) >= 0 orderby d.C_Num select d ).ToList()); return(result); } } catch (Exception ex) { e.res = false; e.info = ex.Message; return(null); } }
public static Err mark_update(v_mark vv) { Err e = new Err(); try { using (var db = new DataBase()) { tbl_stu_mark tsm = ( from d in db.tbl_stu_mark where d.mk_index == vv.mk_index select d ).Single(); tsm.mk_mark = vv.mk_mark; db.SaveChanges(); } } catch (Exception ex) { e.res = false; e.info = ex.Message; } return(e); }