コード例 #1
0
    protected void Btnupload_Click(object sender, EventArgs e)
    {
        if (IsValid)
        {
            string Wmid = Request.QueryString["Mid"].ToString();
            if (LearnSite.Common.WordProcess.IsNum(Wmid))
            {
                string Sname = Request.Cookies["StudentCookies"].Values["Sname"].ToString();
                string Syear = Request.Cookies["StudentCookies"].Values["Syear"].ToString();
                string Sgrade = Request.Cookies["StudentCookies"].Values["Sgrade"].ToString();
                string Sclass = Request.Cookies["StudentCookies"].Values["Sclass"].ToString();
                string Wnum = Request.Cookies["StudentCookies"].Values["Snum"].ToString();
                string Wip = Request.Cookies["StudentCookies"].Values["LoginIp"].ToString();
                string LoginTime = Request.Cookies["StudentCookies"].Values["LoginTime"].ToString();
                string Wcid = LabelMcid.Text;
                string Mfiletype = LabelMfiletype.Text;
                string Wmsort = LabelMsort.Text;
                DateTime Wdate = DateTime.Now;
                string iplast = Wip.Substring(Wip.LastIndexOf(".") + 1);

                if (CheckBoxMupload.Checked)//是否可上传
                {
                    string postfilename = this.AttachFile.FileName;
                    int Wlength = Convert.ToInt32(this.AttachFile.ContentLength);
                    if (postfilename != "" && postfilename != null)
                    {
                        if (LearnSite.Common.WorkUpload.CheckType(postfilename, Mfiletype))  //上传类型是否正确
                        {
                            LearnSite.BLL.Works ws = new LearnSite.BLL.Works();
                            string Wid = ws.WorkDone(Wnum, Int32.Parse(Wcid), Int32.Parse(Wmid));//返回空字符表示不存在该记录
                            if (Wid != "")
                            {
                                //重新提交修改作品
                                string MySavePath = LearnSite.Common.WorkUpload.GetWurl(Syear, Sgrade, Sclass, Wcid, Wmid);//获得作品保存路径(如果不存在,自动创建)
                                string RndTime = (DateTime.Parse(LoginTime)).Minute.ToString();
                                string NewFileName = Server.UrlDecode(Sname) + Wcid + "_" + Wmid + "_" + RndTime + iplast + "." + Mfiletype;
                                string Wurl = MySavePath + "/" + NewFileName;
                                string saveFilename = Server.MapPath(Wurl);
                                try
                                {
                                    this.AttachFile.MoveTo(saveFilename, Brettle.Web.NeatUpload.MoveToOptions.Overwrite);//保存提交作品

                                    ws.UpdateWorkUp(Int32.Parse(Wid), Wurl, NewFileName, Wlength, Wdate,CheckBoxCan.Checked);//更新Wfilename, Wurl,Wlength, Wdate
                                    string ch = "课程活动" + Wmsort + "重新提交作品成功!";
                                    Labelmsg.Text = ch;
                                    LearnSite.Common.WordProcess.Alert(ch, this.Page);
                                }
                                catch (Exception ex)
                                {
                                    throw ex;

                                }
                            }
                            else
                            {
                                //如果作品未提交,提交作品(Wnum, Wcid,Wmid,Wmsort, Wfilename, Wurl,Wlength, Wdate, Wip, Wtime)
                                string MySavePath = LearnSite.Common.WorkUpload.GetWurl(Syear, Sgrade, Sclass, Wcid, Wmid);//获得作品保存路径(如果不存在,自动创建)
                                string RndTime = (DateTime.Parse(LoginTime)).Minute.ToString();
                                string NewFileName = Server.UrlDecode(Sname) + Wcid + "_" + Wmid + "_" + RndTime + iplast + "." + Mfiletype;
                                string Wurl = MySavePath + "/" + NewFileName;
                                string Wtime = LearnSite.Common.Computer.TimePassed().ToString();

                                LearnSite.Model.Works wmodel = new LearnSite.Model.Works();
                                wmodel.Wnum = Wnum;
                                wmodel.Wcid = Int32.Parse(Wcid);
                                wmodel.Wmid = Int32.Parse(Wmid);
                                wmodel.Wmsort = Int32.Parse(Wmsort);
                                wmodel.Wfilename = NewFileName;
                                wmodel.Wurl = Wurl;
                                wmodel.Wlength = Wlength;
                                wmodel.Wdate = Wdate;
                                wmodel.Wip = Wip;
                                wmodel.Wtime = Wtime;
                                wmodel.Wcan = CheckBoxCan.Checked;
                                string saveFilename = Server.MapPath(Wurl);
                                try
                                {
                                    this.AttachFile.MoveTo(saveFilename, Brettle.Web.NeatUpload.MoveToOptions.Overwrite);//保存提交作品

                                    ws.AddWorkUp(wmodel);//添加作品提交记录
                                    string worknums = ws.HowCidWorks(Int32.Parse(Wcid), Wnum);
                                    if (worknums != "")
                                    {
                                        LearnSite.BLL.Signin sn = new LearnSite.BLL.Signin();
                                        sn.UpdateQwork(Wnum, Int32.Parse(worknums));//更新今天签到表中的作品数量
                                    }
                                    string ch = "课程活动"+Wmsort+"提交作品成功!";
                                    Labelmsg.Text = ch;
                                    LearnSite.Common.WordProcess.Alert(ch, this.Page);
                                    ShowWorked();
                                }
                                catch (Exception ex)
                                {
                                    throw ex;
                                }
                            }
                        }
                        else
                        {
                            Labelmsg.Text = "提交类型错误!";
                            string ch = "提交作品类型错误!";
                            LearnSite.Common.WordProcess.Alert(ch, this.Page);
                        }

                    }

                    else
                    {
                        Labelmsg.Text = "你没有选择提交作品!";
                        string ch = "你没有浏览选择你的作品,请再选择一遍!";
                        LearnSite.Common.WordProcess.Alert(ch, this.Page);
                    }
                }
                else
                {
                    Labelmsg.Text = "本任务无作品!";
                }
            }
        }
    }