Пример #1
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());
        }
Пример #2
0
        private void btnSyncCourseTask_Click(object sender, EventArgs e)
        {
            /*JsonResult jr = RemoteServiceProxy.UploadWork(@"C:\Users\乙郎\Pictures\7cbc9488-0a4b-4ab5-a6ed-70e319096680.png", "12", "14");
             * AddLog("result=" + jr.message);*/

            EnableButton(false);
            List <long> courseTaskIds = StoreModel.GetFinishCourseTaskIds();

            pb.Maximum = courseTaskIds.Count;
            int syncCount    = 0;
            int successCount = 0;
            int errorCount   = 0;

            foreach (var id in courseTaskIds)
            {
                syncCount++;
                pb.Value = syncCount;


                CourseTask     ct   = StoreModel.GetById(id);
                JsonResultList list = RemoteServiceProxy.Report(ct, FrmActive.machineCode, FrmActive.activeCode);

                if (list.error)
                {
                    AddLog("同步课程任务失败:" + id.ToString() + " 错误信息:" + list.message);
                    errorCount++;
                    continue;
                }


                List <WorkInfo4Upload> works = RemoteServiceProxy.PrepareWork(ct.Works, list.data);

                //然后传到服务器!--作品!
                bool error = false;
                foreach (var w in works)
                {
                    JsonResult jr = RemoteServiceProxy.ReportWork(w);
                    if (jr.error)
                    {
                        AddLog("同步作品失败:" + id.ToString() + " 作品=" + w.StudentNo);
                        error = true;
                        continue;
                    }
                }
                if (!error)
                {
                    StoreModel.FinishReportCourseTask(id);
                    StoreModel.RemoveFiles(ct.Works);
                    successCount++;
                }
                else
                {
                    errorCount++;
                }
            }

            //全部更新完成了
            //界面刷新一下
            this.UpdateLeftCourseCount();
            pb.Value = 0;
            EnableButton(true);

            AddLog("同步数量:" + syncCount.ToString() + " 成功数量:" + successCount.ToString() + " 错误数量:" + errorCount.ToString());
        }