Exemplo n.º 1
0
 protected void btnSave_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(tbName.Text.Trim()))
     {
         Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('名称不能为空');</script>");
         tbName.Focus();
         return;
     }
     else
     {
         Guid id = new Guid(Request.QueryString["ID"]);
         CY.CSTS.Core.Business.VirtualExperimental vss = CY.CSTS.Core.Business.VirtualExperimental.Load(id);
         if (vss != null)
         {
             vss.Name = tbName.Text.Trim();
             vss.TypeID =new Guid(hdFrontID.Value);
             vss.UploadTime = DateTime.Now;
             vss.UploadPerson = u.UserID;
             if (string.IsNullOrEmpty(vss.FlashUrl))
             {
                 vss.FlashUrl = SaveAnnex();
             }
             vss.Save();
         }
         else
         {
             CY.CSTS.Core.Business.VirtualExperimental vs = new CY.CSTS.Core.Business.VirtualExperimental();
             vs.Name = tbName.Text.Trim();
             vs.TypeID = frontId;
             vs.UploadTime = DateTime.Now;
             vs.UploadPerson = u.UserID;
             if (isPost == 2)
             {
                 vs.FlashUrl = SaveAnnex();
             }
             vs.Save();
         }
         Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('保存实验成功');window.location.href='ExperList.aspx?ID=" + hdFrontID.Value + "&frontID="+hdTop.Value+"'</script>");
     }
 }
Exemplo n.º 2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(tbName.Text.Trim()))
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('名称不能为空');</script>");
                tbName.Focus();
            }
            HttpPostedFile postedFile = HttpContext.Current.Request.Files["file"];
            if (postedFile.ContentLength == 0 || postedFile.FileName == "")
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('请上传FLASH')</script>");
                return;
            }
            else
            {
                if (postedFile.ContentLength > 20971520)
                {
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('上传FLASH不能超过20M')</script>");
                    return;
                }
                else
                {
                    string fileSHowName = postedFile.FileName;
                    int dotIndex = postedFile.FileName.IndexOf("\\");
                    string fileName = string.Empty;
                    if (dotIndex == -1)
                    {
                        fileName = CY.Utility.Common.FileUtility.GetFileName(postedFile.FileName);//文件名
                    }
                    else
                    {
                        string fileNameTemp = CY.Utility.Common.FileUtility.GetFileName(postedFile.FileName);
                        int indElx = fileNameTemp.LastIndexOf("\\") + 1;
                        fileName = fileNameTemp.Substring(indElx);
                    }
                    string fileExtension = CY.Utility.Common.FileUtility.GetFileExtension(postedFile.FileName);//后缀名
                    string appPath = CY.Utility.Common.RequestUtility.CurPhysicalApplicationPath;//绝对路径
                    string dirPath = string.Empty;
                    string httpPath = string.Empty;
                    if (fileExtension == ".swf")
                    {
                        dirPath = appPath + CY.Utility.Common.AnnexUtility.VirtualLabFlashDir;
                        httpPath = "/Content/VirtualLab/FLASH/";
                        System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(dirPath);
                        if (!di.Exists)
                        {
                            di.Create();
                        }
                        string FileName = fileName + DateTime.Now.ToString("yyyyMMddHHmmss") + DateTime.Now.Millisecond.ToString();

                        postedFile.SaveAs(dirPath + "\\" + FileName + fileExtension);
                        CY.CSTS.Core.Business.VirtualExperimental vs = new CY.CSTS.Core.Business.VirtualExperimental();
                        vs.Name = tbName.Text.Trim();
                        vs.TypeID= frontId;
                        vs.UploadTime= DateTime.Now;
                        vs.UploadPerson= u.UserID;
                        vs.FlashUrl =httpPath+FileName + fileExtension;
                        vs.Save();
                        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('新增实验室成功');window.location.href='ExperList.aspx?ID=" + frontId + "&frontID="+hdFrontID.Value+"'</script>");
                    }
                    else
                    {
                        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('请上传flash格式');</script>");
                        return;
                    }
                }
            }
        }