示例#1
0
    private void uploadthiswork()
    {
        if (Request.Files["Filedata"] != null)
        {
            try
            {
                HttpPostedFile          work_upload = Request.Files["Filedata"];
                string                  Wmid        = Request.QueryString["mid"].ToString();
                string                  Wnum        = Request.QueryString["num"].ToString();
                string                  info        = HttpUtility.UrlDecode(Request.QueryString["info"].ToString());
                LearnSite.BLL.Mission   mbll        = new LearnSite.BLL.Mission();
                LearnSite.Model.Mission mmodel      = new LearnSite.Model.Mission();
                mmodel = mbll.GetModel(Int32.Parse(Wmid));

                string Wcid      = mmodel.Mcid.ToString();
                string Wmsort    = mmodel.Msort.ToString();
                string Wfiletype = work_upload.FileName.Substring(work_upload.FileName.LastIndexOf(".") + 1).ToLower();
                // string Wextention = mmodel.Mfiletype;
                int Wlength = work_upload.ContentLength;
                //Syear | Sgrade | Sclass | Sid | Sname | Wip | Sterm | LoginTime
                string[] infoarray = info.Split('|');

                string Syear     = infoarray[0];
                string Sgrade    = infoarray[1];
                string Sclass    = infoarray[2];
                string Wsid      = infoarray[3];
                string Sname     = infoarray[4];
                string Wip       = infoarray[5];
                string Wterm     = infoarray[6];
                string Logintime = infoarray[7];

                DateTime Wdate    = DateTime.Now;
                bool     checkcan = true;

                LearnSite.BLL.Works ws = new LearnSite.BLL.Works();
                string Wid             = ws.WorkDone(Wnum, Int32.Parse(Wcid), Int32.Parse(Wmid));//返回空字符表示不存在该记录
                if (Wid != "")
                {
                    if (!ws.IsChecked(Int32.Parse(Wid)))
                    {
                        //如果未评价,则重新提交修改作品
                        string MySavePath     = LearnSite.Common.WorkUpload.GetWurl(Syear, Sgrade, Sclass, Wcid, Wmid);//获得作品保存路径(如果不存在,自动创建)
                        string RndTime        = LearnSite.Common.WordProcess.GetRandomNum(99).ToString();
                        string OnlyFileName   = Wnum + "_" + Wcid + "_" + Wmid + "_" + RndTime;
                        string NewFileName    = OnlyFileName + "." + Wfiletype;
                        string Wurl           = MySavePath + "/" + NewFileName;
                        string resaveFilename = Server.MapPath(Wurl);
                        try
                        {
                            ws.UpdateWorkUp(Int32.Parse(Wid), Wurl, NewFileName, Wlength, Wdate, checkcan, "");//更新Wfilename, Wurl,Wlength, Wdate

                            //LearnSite.BLL.Signin sn = new LearnSite.BLL.Signin();
                            //sn.UpdateQwork(Int32.Parse(Wsid), Int32.Parse(Wcid));//更新今天签到表中的作品数量
                            work_upload.SaveAs(resaveFilename);//保存提交作品
                            Response.StatusCode = 200;
                            Response.Write(NewFileName);
                        }
                        catch (Exception ex)
                        {
                            Response.StatusCode = 200;
                            Response.Write(ex);
                        }
                        finally
                        {
                            Response.End();
                        }
                    }
                    else
                    {
                        Response.StatusCode = 200;
                        Response.Write("老师已经评价了!");
                        Response.End();
                    }
                }
                else
                {
                    //如果作品未提交,提交作品(Wnum, Wcid,Wmid,Wmsort, Wfilename, Wurl,Wlength, Wdate, Wip, Wtime)
                    string MySavePath   = LearnSite.Common.WorkUpload.GetWurl(Syear, Sgrade, Sclass, Wcid, Wmid);//获得作品保存路径(如果不存在,自动创建)
                    string RndTime      = LearnSite.Common.WordProcess.GetRandomNum(99).ToString();
                    string OnlyFileName = Wnum + "_" + Wcid + "_" + Wmid + "_" + RndTime;
                    string NewFileName  = OnlyFileName + "." + Wfiletype;
                    string Wurl         = MySavePath + "/" + NewFileName;
                    string Wtime        = LearnSite.Common.Computer.TimePassed(Logintime).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.Wtype     = Wfiletype;
                    wmodel.Wurl      = Wurl;
                    wmodel.Wlength   = Wlength;
                    wmodel.Wdate     = Wdate;
                    wmodel.Wip       = Wip;
                    wmodel.Wtime     = Wtime;
                    wmodel.Wcan      = checkcan;
                    wmodel.Wcheck    = false;
                    wmodel.Wegg      = 12;//设定票数为12张
                    wmodel.Whit      = 0;
                    wmodel.Wgrade    = Int32.Parse(Sgrade);
                    wmodel.Wterm     = Int32.Parse(Wterm);
                    wmodel.Wsid      = Int32.Parse(Wsid);
                    wmodel.Wclass    = Int32.Parse(Sclass);
                    wmodel.Wname     = HttpUtility.UrlDecode(Sname);
                    wmodel.Wyear     = Int32.Parse(Syear);
                    switch (Wfiletype)
                    {
                    case "doc":
                    case "ppt":
                    case "xls":
                    case "docx":
                    case "pptx":
                    case "xlsx":
                    case "wps":
                    case "dps":
                    case "et":
                        wmodel.Woffice = true;
                        break;

                    default:
                        wmodel.Woffice = false;
                        break;
                    }
                    wmodel.Wflash = false;
                    wmodel.Werror = false;
                    string saveFilename = Server.MapPath(Wurl);
                    try
                    {
                        ws.AddWorkUp(wmodel);                                 //添加作品提交记录
                        LearnSite.BLL.Signin sn = new LearnSite.BLL.Signin();
                        sn.UpdateQwork(Int32.Parse(Wsid), Int32.Parse(Wcid)); //更新今天签到表中的作品数量

                        work_upload.SaveAs(saveFilename);                     //保存提交作品
                        Response.StatusCode = 200;
                        Response.Write(NewFileName);
                    }
                    catch (Exception ex)
                    {
                        Response.StatusCode = 200;
                        Response.Write(ex);
                    }
                    finally
                    {
                        Response.End();
                    }
                }
            }
            catch (Exception ex)
            {
                Response.StatusCode = 200;
                Response.Write(ex);
            }
            finally
            {
                Response.End();
            }
        }
    }
示例#2
0
    private void ShowIpWorkDone()
    {
        string Sname  = cook.Sname;
        int    Sgrade = cook.Sgrade;
        int    Sclass = cook.Sclass;
        string Snum   = cook.Snum;
        string Wip    = cook.LoginIp;

        string Wcid = Request.QueryString["Cid"].ToString();
        string Wmid = Request.QueryString["Mid"].ToString();

        LearnSite.BLL.Works ws = new LearnSite.BLL.Works();
        string Wid             = ws.WorkDone(Snum, Int32.Parse(Wcid), Int32.Parse(Wmid));//返回空字符表示不存在该记录
        string SnumDone        = ws.IpWorkDoneSnum(Sgrade, Sclass, Int32.Parse(Wcid), Int32.Parse(Wmid), Wip);
        string retureUrl       = ws.WorkUrl(Snum, Int32.Parse(Wmid));

        VoteLink.NavigateUrl = "~/Student/myevaluate.aspx?Mid=" + Wmid + "&Cid=" + Wcid;
        if (LearnSite.Common.XmlHelp.GetWorkIpLimit())//判断有无进行IP限制
        {
            if (Snum == SnumDone || isTeacher(Wid, Snum))
            {
                if (retureUrl != "")
                {
                    upFileUrl.Visible     = true;
                    upFileType.Visible    = true;
                    upFileType.ImageUrl   = "~/Images/FileType/" + LabelMfiletype.Text.ToLower() + ".gif";
                    upFileUrl.Text        = Server.UrlDecode(Sname);
                    upFileUrl.NavigateUrl = "~/Plugins/download.aspx?Id=" + LearnSite.Common.EnDeCode.Encrypt(retureUrl, "ls");
                }
            }
        }
        else
        {
            if (retureUrl != "")
            {
                upFileUrl.Visible     = true;
                upFileType.Visible    = true;
                upFileType.ImageUrl   = "~/Images/FileType/" + LabelMfiletype.Text.ToLower() + ".gif";
                upFileUrl.Text        = Server.UrlDecode(Sname);
                upFileUrl.NavigateUrl = "~/Plugins/download.aspx?Id=" + LearnSite.Common.EnDeCode.Encrypt(retureUrl, "ls");
            }
        }
        if (Wid != "")//判断有无作品提交
        {
            bool ischeck = ws.IsChecked(Int32.Parse(Wid));
            if (ischeck)//判断作品有无评价
            {
                Labelmsg.Text          = "该作品已经评分!<br/>你不可以重新提交!";
                Panelswfupload.Visible = false;
            }
            else
            {
                if (LearnSite.Common.XmlHelp.GetWorkIpLimit())//判断有无进行IP限制
                {
                    if (Snum == SnumDone || isTeacher(Wid, Snum))
                    {
                        Labelmsg.Text          = "你已经提交该活动作品.!<br/>你可以修改作品后重新提交!";
                        Panelswfupload.Visible = true;
                    }
                    else
                    {
                        Panelswfupload.Visible = false;
                        if (LabelMfiletype.Text != "htm")
                        {
                            Labelmsg.Text = SnumDone + "学号<br/>已经在该IP提交本活动作品.!";
                        }
                    }
                }
                else
                {
                    Labelmsg.Text          = "你已经提交该活动作品.!!<br/>你可以修改作品后重新提交!";
                    Panelswfupload.Visible = true;
                }
            }
        }
        else
        {
            LearnSite.BLL.Mission mbll = new LearnSite.BLL.Mission();
            int  minMsort        = mbll.GetLastMaxMsort(Int32.Parse(Wcid), Int32.Parse(LabelMsort.Text));//任务活动中查询
            bool isExitFirstWork = ws.ExistsMyFirstWork(Int32.Parse(Wcid), Snum, minMsort);

            if (LearnSite.Common.XmlHelp.GetWorkIpLimit())//判断有无进行IP限制
            {
                if (SnumDone == "")
                {
                    if (isExitFirstWork || minMsort == 0)//如果是上个任务已经提交或是第一个任务,则显示提交按钮
                    {
                        DateTime dt    = DateTime.Now;
                        string   today = dt.Year.ToString() + "-" + dt.Month.ToString() + "-" + dt.Day;
                        Labelmsg.Text          = today;
                        Panelswfupload.Visible = true;
                    }
                    else
                    {
                        Labelmsg.Text = "请先提交前面活动作品!";
                    }
                }
                else
                {
                    Panelswfupload.Visible = false;
                    if (LabelMfiletype.Text != "htm")
                    {
                        Labelmsg.Text = SnumDone + "学号<br/>已经在该IP提交本活动作品!";
                    }
                }
            }
            else
            {
                if (isExitFirstWork || minMsort == 0)//如果是上个任务已经提交或是第一个任务,则显示提交按钮
                {
                    DateTime dt    = DateTime.Now;
                    string   today = dt.Year.ToString() + "-" + dt.Month.ToString() + "-" + dt.Day;
                    Labelmsg.Text          = today;
                    Panelswfupload.Visible = true;
                }
                else
                {
                    Labelmsg.Text = "请先提交前面的活动作品!";
                }
            }
        }
    }
    private void uploadthiswork()
    {
        HttpPostedFile work_upload = Request.Files["imgFile"];
        int            maxSize     = 104857600;//定义上传最大值为100MB

        if (work_upload != null)
        {
            string Wmid = Request.QueryString["mid"].ToString();
            string Wnum = Request.QueryString["num"].ToString();
            LearnSite.BLL.Mission   mbll   = new LearnSite.BLL.Mission();
            LearnSite.Model.Mission mmodel = new LearnSite.Model.Mission();
            mmodel = mbll.GetModel(Int32.Parse(Wmid));

            string Wcid       = mmodel.Mcid.ToString();
            string Wmsort     = mmodel.Msort.ToString();
            string Wfiletype  = work_upload.FileName.Substring(work_upload.FileName.LastIndexOf(".") + 1).ToLower();
            string Wextention = mmodel.Mfiletype;
            string limitext   = Wextention;//初始化,随意
            switch (Wextention)
            {
            case "doc":
                limitext = "*.doc;*.docx";
                break;

            case "ppt":
                limitext = "*.ppt;*.pptx";
                break;

            case "xls":
                limitext = "*.xls;*.xlsx";
                break;

            case "office":
                limitext = "*.doc;*.docx;*.ppt;*.pptx;*.xls;*.xlsx";
                break;

            case "sb":
                limitext = "*.sb;*.sb2";
                break;

            default:
                limitext = "*." + Wextention;
                break;
            }
            if (Wfiletype == Wextention || limitext.Contains(Wfiletype))
            {
                if (work_upload.InputStream != null || work_upload.InputStream.Length < maxSize)
                {
                    int      Wlength  = work_upload.ContentLength;
                    string   Syear    = Request.Cookies[LearnSite.Common.CookieHelp.stuCookieNname].Values["Syear"].ToString();
                    string   Sgrade   = Request.Cookies[LearnSite.Common.CookieHelp.stuCookieNname].Values["Sgrade"].ToString();
                    string   Sclass   = Request.Cookies[LearnSite.Common.CookieHelp.stuCookieNname].Values["Sclass"].ToString();
                    string   Wsid     = Request.Cookies[LearnSite.Common.CookieHelp.stuCookieNname].Values["Sid"].ToString();
                    string   Wip      = Request.Cookies[LearnSite.Common.CookieHelp.stuCookieNname].Values["LoginIp"].ToString();
                    string   Sname    = Request.Cookies[LearnSite.Common.CookieHelp.stuCookieNname].Values["Sname"].ToString();
                    string   Wterm    = Request.Cookies[LearnSite.Common.CookieHelp.stuCookieNname].Values["ThisTerm"].ToString();
                    DateTime Wdate    = DateTime.Now;
                    bool     checkcan = true;

                    LearnSite.BLL.Works ws = new LearnSite.BLL.Works();
                    string Wid             = ws.WorkDone(Wnum, Int32.Parse(Wcid), Int32.Parse(Wmid));//返回空字符表示不存在该记录
                    if (Wid != "")
                    {
                        if (!ws.IsChecked(Int32.Parse(Wid)))
                        {
                            //如果未评价,则重新提交修改作品
                            string MySavePath     = LearnSite.Common.WorkUpload.GetWurl(Syear, Sgrade, Sclass, Wcid, Wmid);//获得作品保存路径(如果不存在,自动创建)
                            string RndTime        = LearnSite.Common.WordProcess.GetRandomNum(99).ToString();
                            string OnlyFileName   = Wnum + "_" + Wcid + "_" + Wmid + "_" + RndTime;
                            string NewFileName    = OnlyFileName + "." + Wfiletype;
                            string Wurl           = MySavePath + "/" + NewFileName;
                            string resaveFilename = Server.MapPath(Wurl);
                            ws.UpdateWorkUp(Int32.Parse(Wid), Wurl, NewFileName, Wlength, Wdate, checkcan, ""); //更新Wfilename, Wurl,Wlength, Wdate
                            LearnSite.BLL.Signin sn = new LearnSite.BLL.Signin();
                            sn.UpdateQwork(Int32.Parse(Wsid), Int32.Parse(Wcid));                               //更新今天签到表中的作品数量
                            work_upload.SaveAs(resaveFilename);                                                 //保存提交作品

                            Hashtable hash = new Hashtable();
                            hash["error"] = 0;
                            Response.AddHeader("Content-Type", "text/html; charset=UTF-8");
                            Response.Write(JsonMapper.ToJson(hash));
                            Response.End();
                        }
                        else
                        {
                            showError("老师已经评价了!");
                        }
                    }
                    else
                    {
                        //如果作品未提交,提交作品(Wnum, Wcid,Wmid,Wmsort, Wfilename, Wurl,Wlength, Wdate, Wip, Wtime)
                        string MySavePath   = LearnSite.Common.WorkUpload.GetWurl(Syear, Sgrade, Sclass, Wcid, Wmid);//获得作品保存路径(如果不存在,自动创建)
                        string RndTime      = LearnSite.Common.WordProcess.GetRandomNum(99).ToString();
                        string OnlyFileName = Wnum + "_" + Wcid + "_" + Wmid + "_" + RndTime;
                        string NewFileName  = OnlyFileName + "." + Wfiletype;
                        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.Wtype     = Wextention;
                        wmodel.Wurl      = Wurl;
                        wmodel.Wlength   = Wlength;
                        wmodel.Wdate     = Wdate;
                        wmodel.Wip       = Wip;
                        wmodel.Wtime     = Wtime;
                        wmodel.Wcan      = checkcan;
                        wmodel.Wcheck    = false;
                        wmodel.Wegg      = 12;//设定票数为12张
                        wmodel.Whit      = 0;
                        wmodel.Wgrade    = Int32.Parse(Sgrade);
                        wmodel.Wterm     = Int32.Parse(Wterm);
                        wmodel.Wsid      = Int32.Parse(Wsid);
                        wmodel.Wclass    = Int32.Parse(Sclass);
                        wmodel.Wname     = HttpUtility.UrlDecode(Sname);
                        wmodel.Wyear     = Int32.Parse(Syear);

                        switch (Wfiletype)
                        {
                        case "doc":
                        case "ppt":
                        case "xls":
                        case "docx":
                        case "pptx":
                        case "xlsx":
                        case "wps":
                        case "dps":
                        case "et":
                            wmodel.Woffice = true;
                            break;

                        default:
                            wmodel.Woffice = false;
                            break;
                        }
                        wmodel.Wflash = false;
                        wmodel.Werror = false;
                        string saveFilename = Server.MapPath(Wurl);
                        ws.AddWorkUp(wmodel);                                 //添加作品提交记录
                        LearnSite.BLL.Signin sn = new LearnSite.BLL.Signin();
                        sn.UpdateQwork(Int32.Parse(Wsid), Int32.Parse(Wcid)); //更新今天签到表中的作品数量

                        work_upload.SaveAs(saveFilename);                     //保存提交作品
                        Hashtable hash = new Hashtable();
                        hash["error"] = 0;

                        Response.AddHeader("Content-Type", "text/html; charset=UTF-8");
                        Response.Write(JsonMapper.ToJson(hash));
                        Response.End();
                    }
                }
                else
                {
                    showError("选择的文件大小超过限制!(最大为100MB)");
                }
            }
            else
            {
                showError("选择的文件类型错误!");
            }
        }
        else
        {
            showError("请选择文件!");
        }
    }