private static long PrepareStudent(CardInfo cardInfo) { string sql = "select student_id,student_no,student_name from student where student_rfid=?"; var ds = SqlLiteHelper.ExecuteQuery(sql, cardInfo.Rfid); bool update = false; long student_id = 0; foreach (DataRow row in ds.Tables[0].Rows) { string student_no = row["student_no"].ToString(); string student_name = row["student_name"].ToString(); student_id = (long)row["student_id"]; if (string.Equals(student_name, cardInfo.Name) && string.Equals(student_no, cardInfo.No)) { return(student_id); } update = true; } //need insert or update if (update) { SqlLiteHelper.ExecuteNonQuery("update student set student_name=?,student_no=?,updated_time=datetime('now','localtime') where student_id=?", cardInfo.Name, cardInfo.No, student_id); return(student_id); } else { SqlLiteHelper.ExecuteNonQuery("insert into student( student_name,student_no,student_rfid,created_time,updated_time) values(?,?,?,datetime('now','localtime'),datetime('now','localtime'))", cardInfo.Name, cardInfo.No, cardInfo.Rfid); object result = SqlLiteHelper.ExecuteScalar("SELECT last_insert_rowid()"); return((long)result); } }
internal static long StartCourseTask(CourseTask ct) { //课程允许开课 //准备好教师和学生数据 long?master_id = PrepareTeacher(ct.Master); long?assistant1_id = PrepareTeacher(ct.Assistant1); long?assistant2_id = PrepareTeacher(ct.Assistant2); //main table insert string sql = "insert into course_task (begin_time,status,master_id,assistant1_id,assistant2_id,status,course_id) values( datetime('now','localtime'),?,?,?,?,?,?)"; SqlLiteHelper.ExecuteNonQuery(sql, CourseTask.STATUS_START, master_id, assistant1_id, assistant2_id, CourseTask.STATUS_START, ct.CourseId); //student? object result = SqlLiteHelper.ExecuteScalar("SELECT last_insert_rowid()"); //get id = result; //to students table ; List <long> students = PrepareStudents(ct.Students); //insert students sql = "insert into course_task_student (course_task_id,student_id) values(?,?)"; foreach (long sid in students) { SqlLiteHelper.ExecuteNonQuery(sql, result, sid); } return((long)result); }
private void UpdateLeftCourseCount() { //查找已完成但未上报的数量 object obj = SqlLiteHelper.ExecuteScalar("select count(1) from course_task where status=2"); long l = (long)obj; if (l == 0) { lblSyncLeft.Text = "暂无待同步的内容"; } else { lblSyncLeft.Text = "尚有" + l.ToString() + "笔数据未同步"; } }