/// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                StudentWorkTeaUpload stuworkUpload = new StudentWorkTeaUpload();
                stuworkUpload.CatalogID = this.ddlCatalog.SelectedValue;
                stuworkUpload.Description = this.txtWorkDescription.Text.Trim();
                stuworkUpload.WorkName = this.txtWorkName.Text.Trim();
                stuworkUpload.Type = (EnumWorkType)Enum.Parse(typeof(EnumWorkType), this.ddlWorkType.SelectedValue);
                stuworkUpload.Status = EnumWorkStatus.Submit;
                bool isUploadWork = false;
                this.uploadAttachments.SaveUploadAs(new EventHandler<iPower.Web.Upload.UploadViewEventArgs>(delegate(object o, iPower.Web.Upload.UploadViewEventArgs s)
                {
                    try
                    {
                        isUploadWork = true;
                        StudentWorkFile workfile = new StudentWorkFile();
                        stuworkUpload.WorkID = workfile.FileID = s.ItemRaw.FileID;
                        workfile.FileName = s.ItemRaw.FileName;
                        workfile.FileExt = s.ItemRaw.Extension;
                        workfile.OffSet = 0;
                        workfile.Size = s.ItemRaw.Size;
                        workfile.ContentType = s.ItemRaw.ContentType;
                        workfile.Data = s.ItemRaw.FileRaw;

                        stuworkUpload.CheckCode = s.ItemRaw.CheckCode;
                        stuworkUpload.Files = workfile;
                        if (this.presenter.UploadStudentWork(this.CurrentUserID, stuworkUpload))
                        {
                            this.SaveData();
                        }
                        else
                        {
                            this.ShowMessage("上传失败!发生未知异常。");
                        }
                    }
                    catch (Exception e1)
                    {
                        this.ShowMessage("发生异常:" + e1.Message);
                    }
                }));
                if (!isUploadWork)this.ShowMessage("请上传学生作业文件!");
            }
            catch (Exception ex)
            {
                this.ShowMessage(ex.Message);
            }
        }
Пример #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUpload_Click(object sender, EventArgs e)
        {
            string oldbtnText = this.btnUpload.Text;
            try
            {
                if (!this.btnUpload.Enabled) return;
                this.bUploadComplete = false;
                if (this.catalog == null) return;
                this.btnUpload.Text = "开始上传..";
                this.btnUpload.Enabled = false;
                System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(delegate(object o)
                {
                    UploadFileMSG msg = new UploadFileMSG();
                    msg.CatalogID = this.catalog.CatalogID;
                    msg.Student = this.CoreService["student"] as Student;
                    if (msg.Student != null)
                        msg.UID = msg.Student.StudentID;
                    msg.WorkID = Guid.NewGuid().ToString().Replace("-", "");
                    msg.WorkName = this.txtWorkName.Text.Trim();

                    this.OnClearErrorEvent();
                    if (string.IsNullOrEmpty(msg.WorkName))
                    {
                        this.OnSetErrorEvent(this.txtWorkName, "作品名称不能为空!");
                        return;
                    }
                    this.OnMessageEvent(MessageType.Normal, "开始上传数据准备...");
                    msg.WorkType = this.chkPublic.Checked ? EnumWorkType.Public : EnumWorkType.Protected;
                    msg.Description = this.txtDescription.Text;
                    msg.Time = DateTime.Now;
                    if (this.fileUploadItems == null || this.fileUploadItems.Count == 0)
                    {
                        this.OnMessageEvent(MessageType.Normal | MessageType.PopupInfo, "未选择上传的作品附件!");
                        return;
                    }
                    msg.Files = new StudentWorkFiles();
                    #region 装载文件数据。
                    string path = null;
                    for (int i = 0; i < this.fileUploadItems.Count; i++)
                    {
                        if (File.Exists(path = this.fileUploadItems[i].Path))
                        {
                            StudentWorkFile swf = new StudentWorkFile();
                            swf.FileID = Guid.NewGuid().ToString().Replace("-", "");
                            swf.FileName = this.fileUploadItems[i].FileName;
                            swf.FileExt = this.fileUploadItems[i].Ext;
                            swf.ContentType = "application/octet-stream";
                            using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read))
                            {
                                byte[] buf = new byte[512];
                                swf.Size = stream.Length;
                                using (MemoryStream ms = new MemoryStream())
                                {
                                    int len = 0;
                                    while ((len = stream.Read(buf, 0, buf.Length)) > 0)
                                    {
                                        ms.Write(buf, 0, len);
                                    }
                                    swf.Data = ms.ToArray();
                                }
                            }
                            msg.Files.Add(swf);
                        }
                    }
                    #endregion

                    PortSettings ports = this.CoreService["portsettings"] as PortSettings;
                    IPAddress hostIP = IPAddress.Parse(string.Format("{0}", this.CoreService["host_ip"]));
                    this.OnMessageEvent(MessageType.Normal, "上传数据准备完成,开始连接教师机主机...");
                    bool result = false;
                    using (TcpClientService tcs = new WorkUpTcpClient(new IPEndPoint(hostIP, ports.FileUpTransfer), ports.MaxFileSize))
                    {
                        tcs.Changed += new Yaesoft.SFIT.Client.RaiseChangedHandler(delegate(string content)
                        {
                            this.OnMessageEvent(MessageType.Normal, content);
                        });
                        result = tcs.Upload(msg);
                    }
                    System.Threading.Thread.Sleep(700);
                    this.ThreadSafeMethod(new MethodInvoker(delegate()
                    {
                        if (result) this.DialogResult = DialogResult.Yes;
                    }));
                    this.OnMessageEvent(MessageType.Normal | MessageType.PopupInfo, result ? "作品上传成功" : "作品上传失败,请重新上传!");
                    this.bUploadComplete = true;
                    this.ThreadSafeMethod(new MethodInvoker(delegate()
                    {
                        this.btnUpload.Text = oldbtnText;
                        this.btnUpload.Enabled = true;
                    }));
                }));
            }
            catch (Exception x)
            {
                this.OnMessageEvent(MessageType.Normal | MessageType.PopupWarn, "系统异常:" + x.Message);
                this.btnUpload.Text = oldbtnText;
                this.btnUpload.Enabled = true;
            }
        }
Пример #3
0
 /// <summary>
 /// 构造函数。
 /// </summary>
 public StudentWorkTeaUpload()
 {
     this.review = new TeacherReview();
     this.files = new StudentWorkFile();
 }