Exemple #1
0
        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);
        }
Exemple #2
0
        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);
            }
        }
Exemple #3
0
 //处理未激活的错误信息
 internal static void ProcessNotActived(RemoteService.JsonResultList jr)
 {
     if (jr.error && "999".Equals(jr.no))
     {
         FrmActive.activeCode = null;
         //删除注册信息
         SqlLiteHelper.ExecuteNonQuery("update system set active_code=null");
     }
 }
Exemple #4
0
        public static bool IsActive()
        {
            DataSet ds = SqlLiteHelper.ExecuteQuery("select machine_code,node_name,active_code,expire_time from system");

            //AddLog("Count=" + ds.Tables.Count.ToString());
            if (ds.Tables[0].Rows.Count > 0)
            {
                string machine_code = ds.Tables[0].Rows[0]["machine_code"].ToString();
                string name         = ds.Tables[0].Rows[0]["node_name"].ToString();
                activeCode = ds.Tables[0].Rows[0]["active_code"].ToString();

                if (ds.Tables[0].Rows[0].IsNull("expire_time"))
                {
                    expireTime = null;
                }
                else
                {
                    expireTime = (DateTime?)ds.Tables[0].Rows[0]["expire_time"];
                }

                if (expireTime != null && expireTime.Value.CompareTo(System.DateTime.Now) <= 0)
                {
                    //到期了
                    expired = true;
                }

                if (String.Equals(machine_code, machineCode))
                {
                    //AddLog("machine code match!");
                }
                else
                {
                    //need update
                    //AddLog("machine code not match ,old =" + machine_code);
                    SqlLiteHelper.ExecuteNonQuery("update system set machine_code=?,active_code=null ", machineCode);
                    //机器码,不同,强制设为无效
                    activeCode = null;
                    //AddLog("updated");
                }
                //AddLog("machine name=" + name);
            }
            else
            {
                //AddLog("don't have machine code yet ");
                int n = SqlLiteHelper.ExecuteNonQuery("insert into system( machine_code) values(?)", machineCode);
                //AddLog("inserted :" + n.ToString());
            }


            if (string.IsNullOrEmpty(activeCode) || expired)
            {
                return(false);
            }
            return(true);
        }
Exemple #5
0
        internal static void FinishCourseTask(long id, IDictionary <string, string> files)
        {
            //关闭课程
            string sql = "update course_task set end_time=datetime('now','localtime'),status=? where course_task_id=?";
            int    n   = SqlLiteHelper.ExecuteNonQuery(sql, CourseTask.STATUS_END, id);

            //提交作品内容
            sql = "insert into course_task_file ( student_no,file_path,course_task_id) values( ?,?,?)";

            foreach (var item in files)
            {
                SqlLiteHelper.ExecuteNonQuery(sql, item.Key, item.Value, id);
            }
        }
Exemple #6
0
        private void btnSyncActive_Click(object sender, EventArgs e)
        {
            JsonResult jr = RemoteServiceProxy.SyncActive(machineCode);

            if (jr.error)
            {
                UIHelper.ShowAlert(jr.message);
            }
            else
            {
                long tick = 0;
                long.TryParse(jr.data["expiredTime"], out tick);
                tick = tick / 1000;



                // AddLog("success=" + jr.message);
                //save
                int n = 0;
                if (tick == 0)
                {
                    SqlLiteHelper.ExecuteNonQuery("update system set active_code=?,node_name=?,active_time=datetime('now','localtime'),node_id=?,expire_time=null",
                                                  jr.data["licenseKey"], jr.data["name"], jr.data["classroomId"]);
                }
                else
                {
                    DateTime expire_time = UnixTool.ConvertIntDateTime(tick);
                    if (expire_time.CompareTo(System.DateTime.Now) <= 0)
                    {
                        //到期了
                        expired = true;
                        UIHelper.ShowAlert("激活信息已经失效,请与总部联系");
                        return;
                    }


                    n = SqlLiteHelper.ExecuteNonQuery("update system set active_code=?,node_name=?,active_time=datetime('now','localtime'),node_id=?,expire_time=datetime(?, 'unixepoch', 'localtime')",
                                                      jr.data["licenseKey"], jr.data["name"], jr.data["classroomId"], tick);
                }
                // int n = SqlLiteHelper.ExecuteNonQuery("update system set node_id=?", jr.data["classroomId"]);
                UIHelper.ShowInfo("成功同步激活信息");
                ShowSuccess(true);

                DialogResult = DialogResult.OK;
            }
        }
Exemple #7
0
        private void btnSyncCourse_Click(object sender, EventArgs e)
        {
            JsonResultList jr = RemoteServiceProxy.SyncCourse(FrmActive.machineCode, FrmActive.activeCode);

            StoreModel.ProcessNotActived(jr);

            if (jr.error)
            {
                AddLog("错误:" + jr.message);
                UIHelper.ShowAlert(jr.message);
                return;
            }
            // AddLog("success=" + jr.message);
            //save
            string sql = @"select course_no,removed from course";

            //load all
            DataSet ds = SqlLiteHelper.ExecuteQuery(sql);
            Dictionary <string, bool> exists_courses = new Dictionary <string, bool>();

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                string course_no = row["course_no"].ToString();
                bool   removed   = (bool)row["removed"];

                exists_courses.Add(course_no, removed);
            }

            //所有数据是否存在,所有都要更新,多出来的还没删掉的,要标记为删除
            int updateCount = 0;
            int insertCount = 0;

            foreach (var row in jr.data)
            {
                int idx = GetCourseCategoryIndex(row["categoryNo"]);
                //去除击中的
                string course_no = row["courseNo"];
                if (exists_courses.ContainsKey(course_no))
                {
                    //update
                    int n = SqlLiteHelper.ExecuteNonQuery("update course set course_name=?,key=?,course_category=?,sub_category=?,updated_time=datetime('now','localtime'),removed=? where course_no=?", row["courseName"], row["courseKey"],
                                                          idx, row["subCategoryName"], false, course_no);
                    //remove hits
                    exists_courses.Remove(course_no);

                    //AddLog("update result=" + n.ToString());
                    updateCount++;
                }
                else
                {
                    //insert
                    int n = SqlLiteHelper.ExecuteNonQuery(@"insert into course (course_name,key,course_no,course_category,sub_category,created_time,updated_time,removed)
                                    values( ?,?,?,?,?,datetime('now','localtime'),datetime('now','localtime'),?)",
                                                          row["courseName"], row["courseKey"], row["courseNo"], idx, row["subCategoryName"], false);


                    //AddLog("insert result=" + n.ToString());
                    insertCount++;
                }
            }

            //尚未集中的,如果没有标为删除,则标为删除
            int cc = 0;

            foreach (var row in exists_courses)
            {
                if (!row.Value)
                {
                    SqlLiteHelper.ExecuteNonQuery("update course set removed=?,updatedTime=datetime('now','localtime') where course_no=?", true, row.Key);
                    cc++;
                }
            }

            AddLog("新增课程:" + insertCount.ToString());
            AddLog("更新课程:" + updateCount.ToString());
            AddLog("移除课程:" + cc.ToString());
        }
Exemple #8
0
 internal static void FinishReportCourseTask(long id)
 {
     //关闭课程
     string sql = "update course_task set submit_time=datetime('now','localtime'),status=? where course_task_id=?";
     int    n   = SqlLiteHelper.ExecuteNonQuery(sql, CourseTask.STATUS_SUBMITED, id);
 }