Exemple #1
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());
        }