/// <summary>
 /// 批量上传处理。
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void menuItemBatchUpload_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show(this, "将上传已批阅学生作品,您确认?", "批量上传提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk) == DialogResult.OK)
     {
         try
         {
             WorkUploadToServer win = new WorkUploadToServer(this.CoreService, this.store, this.students.ToStudentIDs());
             win.StartPosition = FormStartPosition.CenterParent;
             win.Changed += new RaiseChangedHandler(delegate(string msg)
             {
                 this.OnMessageEvent(MessageType.Normal, msg);
             });
             win.ShowDialog(this);
             this.btnQuery_Click(this.btnQuery, e);
         }
         catch (Exception x)
         {
             Program.GlobalExceptionHandler(x);
             this.OnMessageEvent(MessageType.Normal, string.Format("批量上传异常:{0}", x.Message));
         }
     }
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            Button btn = sender as Button;
            string btnStr = string.Empty;
            try
            {
                if (btn != null)
                {
                    btnStr = btn.Text;
                    btn.Text = "处理中...";
                    btn.Enabled = false;
                }
                string[] checkStudentWorks = GetSelectedThumbnails(this.panelWork);
                if (checkStudentWorks == null || checkStudentWorks.Length == 0)
                {
                    this.OnMessageEvent(MessageType.Normal | MessageType.PopupInfo, "请选中学生作业后方可保存!");
                    btn.Text = btnStr;
                    btn.Enabled = true;
                    return;
                }
                LocalWorkReview teaReview = Tools.GetEvaluateFromWin(this.store, this.cbbReviewValue, this.txtSubjectiveReviews);
                if (teaReview == null)
                {
                    this.OnMessageEvent(MessageType.Normal | MessageType.PopupInfo, "请评阅后方可保存!");
                    btn.Text = btnStr;
                    btn.Enabled = true;
                    return;
                }
                btn.Text = "保存中..";
                bool bPublish = this.chkPublish.Checked, bUpload = this.chkUpload.Checked;
                this.store = LocalStudentWorkStore.DeSerializer(this.store.FileSavePath());
                for (int i = 0; i < checkStudentWorks.Length; i++)
                {
                    LocalStudent ls = this.store.Students[checkStudentWorks[i]];
                    if (ls != null && ls.Work != null)
                    {
                        WorkStoreHelper.WorkReviewQueueEntity entity = new WorkStoreHelper.WorkReviewQueueEntity(ls.StudentID,
                                                                                                         ls.Work.WorkID,
                                                                                                         bPublish ? (EnumWorkStatus.Review | EnumWorkStatus.Release) : EnumWorkStatus.Review,
                                                                                                         teaReview,
                                                                                                         this.store.FileSavePath());
                        entity.Changed += new RaiseChangedHandler(delegate(string msg)
                        {
                            this.OnMessageEvent(MessageType.Normal, msg);
                        });
                        //添加到保存队列。
                        WorkStoreHelper.ReviewWorkToQueueStore(entity);
                        this.OnMessageEvent(MessageType.Normal, string.Format("开始保存[{0},{1}]作业批阅...",ls.StudentName, ls.Work.WorkName));
                    }
                }

                if (bUpload)
                {
                    btn.Text = "上传中...";
                    WorkUploadToServer win = new WorkUploadToServer(this.CoreService, this.store, checkStudentWorks);
                    win.StartPosition = FormStartPosition.CenterParent;
                    win.Changed += new RaiseChangedHandler(delegate(string msg)
                    {
                        this.OnMessageEvent(MessageType.Normal, msg);
                    });
                    win.ShowDialog(this);
                }

                btn.Text = "刷新状态...";
                //刷新学生作品评阅状态。
                for (int i = 0; i < checkStudentWorks.Length; i++)
                {
                    StudentEx stuEx = Program.STUDENTS != null ? Program.STUDENTS[checkStudentWorks[i]] : null;
                    if (stuEx != null && ((stuEx.Status & StudentControl.EnumStudentState.Review) != StudentControl.EnumStudentState.Review))
                    {
                        stuEx.Status |= StudentControl.EnumStudentState.Review;
                        if (this.NetService != null) this.NetService.OnUpdateControls(stuEx);
                    }
                }

                //
                this.DialogResult = DialogResult.OK;
                this.Close();

            }
            catch (Exception ex)
            {
                Program.GlobalExceptionHandler(ex);
                this.OnMessageEvent(MessageType.Normal, "发生异常:" + ex.Message);
            }
            finally
            {
                if (btn != null)
                {
                    btn.Text = btnStr;
                    btn.Enabled = true;
                }
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                #region 设置按钮状态。
                this.btnSave.Enabled = this.btnDelete.Enabled = this.btnClose.Enabled = false;
                if (this.isPrevEnabled)
                {
                    this.btnPrev.Enabled = false;
                }
                if (this.isNextEnabled)
                {
                    this.btnNext.Enabled = false;
                }
                #endregion

                if (this.store != null && this.store.Students != null && this.Tag != null)
                {
                    LocalStudent ls = this.Tag as LocalStudent;
                    if (ls != null && ls.HasWork())
                    {
                        #region 装载数据。
                        ls.Work.WorkName = this.txtWorkName.Text.Trim();
                        ls.Work.Type = (this.chkPublic.Checked ? EnumWorkType.Public : EnumWorkType.Protected);
                        ls.Work.Description = this.txtDescription.Text.Trim();
                        if ((ls.Work.Review = Tools.GetEvaluateFromWin(this.store, this.cbbReviewValue, this.txtSubjectiveReviews)) != null)
                        {
                            ls.Work.Status |= EnumWorkStatus.Review;
                        }
                        else if ((ls.Work.Status & EnumWorkStatus.Review) == EnumWorkStatus.Review)
                        {
                            ls.Work.Status &= ~EnumWorkStatus.Review;
                        }
                        if (this.chkPublish.Checked)
                        {
                            ls.Work.Status |= EnumWorkStatus.Release;
                        }
                        else if ((ls.Work.Status & EnumWorkStatus.Release) == EnumWorkStatus.Release)
                        {
                            ls.Work.Status &= ~EnumWorkStatus.Release;
                        }
                        if (((int)ls.Work.Status) < -1)
                        {
                            ls.Work.Status = EnumWorkStatus.Recive;
                        }
                        #endregion

                        WorkStoreHelper.UpdateWorkInfoQueueEntity entity = new WorkStoreHelper.UpdateWorkInfoQueueEntity(ls.StudentID, ls.Work, this.store.FileSavePath(), this.chkUpload.Checked);
                        entity.Changed += new RaiseChangedHandler(delegate(string msg)
                        {
                            this.OnMessageEvent(MessageType.Normal, msg);
                        });
                        entity.UpdateComplete += new WorkStoreHelper.UpdateWorkInfoCompleteHandler(delegate(StudentEx student, bool upload)
                        {
                            if (this.NetService != null) this.NetService.OnUpdateControls(student);
                            if (upload)
                            {
                                this.ThreadSafeMethod(new MethodInvoker(delegate()
                                {
                                    WorkUploadToServer win = new WorkUploadToServer(this.CoreService, this.store, new string[] { ls.StudentID });
                                    win.StartPosition = FormStartPosition.CenterParent;
                                    win.Changed += new RaiseChangedHandler(delegate(string msg)
                                    {
                                        this.OnMessageEvent(MessageType.Normal, msg);
                                    });
                                    win.ShowDialog(this);
                                }));
                            }
                        });
                        WorkStoreHelper.UpdateWorkInfoToQueueStore(entity);
                        this.OnMessageEvent(MessageType.Normal, string.Format("开始保存[{0}]作品[{1}]...!", ls.StudentName, ls.Work.WorkName));
                        this.isDialogResult = true;
                    }
                }
            }
            catch (Exception x)
            {
                Program.GlobalExceptionHandler(x);
                this.OnMessageEvent(MessageType.Normal, "发生异常:" + x.Message);
            }
            finally
            {
                this.btnSave.Enabled = this.btnDelete.Enabled = this.btnClose.Enabled = true;
                if (this.isPrevEnabled)
                {
                    this.btnPrev.Enabled = this.isPrevEnabled;
                }
                if (this.isNextEnabled)
                {
                    this.btnNext.Enabled = this.isNextEnabled;
                }
            }
        }