예제 #1
0
 protected void btnSave_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(tbTitle.Text.Trim()))
     {
         Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('标题不能为空');</script>");
         tbTitle.Focus();
         return;
     }
     else if (ddlBig.SelectedValue == "0")
     {
         Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('请选择版块');</script>");
         ddlBig.Focus();
         return;
     }
     else
     {
         int t = 0;
         HttpFileCollection files = HttpContext.Current.Request.Files;
         if (files.Count == 0 || files[0].ContentLength == 0 || files[0].FileName == "")
         {
             t = 2;//没有
         }
         else
         {
             t = 1;
         }
         Guid pID = new Guid();
         if (ddlBig.SelectedValue != "0")
         {
             if (Request.Form["ddlSub"] != "0" && Request.Form["ddlSub"] != null)
             {
                 pID = new Guid(Request.Form["ddlSub"].ToString());
             }
             else
             {
                 pID = new Guid(ddlBig.SelectedValue.ToString());
             }
         }
         CY.CSTS.Core.Business.VirtualLabDataSon vss = new CY.CSTS.Core.Business.VirtualLabDataSon();
         vss.Content = fck.Value;
         vss.Name = tbTitle.Text.Trim();
         vss.AddPerson = u.Name;
         vss.AddTime = DateTime.Now;
         vss.FrontID = pID;
         vss.HasAnnex = t;
         vss.Save();
         if (t == 1)
         {
             //SaveAnnex(2, vss.Id);
         }
         Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('保存成功');window.location.href='newsList.aspx'</script>");
     }
 }
예제 #2
0
        private void SaveAnnex(int type, Guid id)
        {
            CY.CSTS.Core.Business.VirtualLabDataSon vs;
            if (type == 1)//Load
            {
                vs = CY.CSTS.Core.Business.VirtualLabDataSon.Load(id);
            }
            else if (type == 2)//Add
            {
                vs = new CY.CSTS.Core.Business.VirtualLabDataSon();
            }
            try
            {
                HttpFileCollection files = HttpContext.Current.Request.Files;
                if (files.Count > 0 && files[0].ContentLength > 0)
                {
                    for (int i = 0; i < files.Count; i++)
                    {
                        HttpPostedFile postedFile = files[i];
                        if (postedFile.ContentLength > 20971520)
                        {
                            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('上传附件不能超过20M,附件:" + postedFile.FileName + "上传失败');</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;

                            dirPath = appPath + CY.Utility.Common.AnnexUtility.VirtualLabFileDir;

                            httpPath = "/Content/VirtualLab/File/";

                            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.VirtualLabDataAnnex annex = new CY.CSTS.Core.Business.VirtualLabDataAnnex();
                            annex.ContentID = id;
                            annex.Name = fileName;
                            annex.Url = httpPath + FileName + fileExtension;
                            annex.Save();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert(" + ex.Message + ");</script>");
            }
        }
예제 #3
0
 /// <summary>
 /// 保存
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void btnSave_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(tbTitle.Text.Trim()))
     {
         Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('标题不能为空');</script>");
         tbTitle.Focus();
         return;
     }
     else
     {
         int t = 0;
         HttpFileCollection files = HttpContext.Current.Request.Files;
         if (files.Count == 0 || files[0].ContentLength == 0 || files[0].FileName == "")
         {
             t = 2;//没有
         }
         else
         {
             t = 1;
         }
         Guid amid = new Guid();
         if (!string.IsNullOrEmpty(hdTemp.Value))
         {
             amid = new Guid(hdTemp.Value);
         }
         else
         {
             amid = id;
         }
         CY.CSTS.Core.Business.VirtualLabDataSon vs = CY.CSTS.Core.Business.VirtualLabDataSon.Load(amid);
         if (vs != null)
         {
             vs.Content = fck.Value;
             vs.Name = tbTitle.Text.Trim();
             vs.AddPerson = u.Name;
             vs.AddTime = DateTime.Now;
             vs.HasAnnex = t;
             vs.Save();
             if (t == 1)
             {
                 //SaveAnnex(1, vs.Id);
             }
         }
         else
         {
             CY.CSTS.Core.Business.VirtualLabDataSon vss = new CY.CSTS.Core.Business.VirtualLabDataSon();
             vss.Content = fck.Value;
             vss.Name = tbTitle.Text.Trim();
             vss.AddPerson = u.Name;
             vss.AddTime = DateTime.Now;
             vss.FrontID = new Guid(hdTemp.Value);
             vss.HasAnnex = t;
             vss.Save();
             if (t == 1)
             {
                 //SaveAnnex(2, vss.Id);
             }
         }
         if (!string.IsNullOrEmpty(hdTopID.Value))
         {
             //Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('保存成功!');window.location.href='LabBigInfo.aspx?ID="+ hdTopID.Value + "&frontID="+hdID.Value+"'</script>");
             Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('保存成功!');</script>");
         }
         else if (!string.IsNullOrEmpty(hdTemp.Value))
         {
             //Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('保存成功!');window.location.href='LabBigInfo.aspx?ID=" + hdTemp.Value + "&frontID=" + hdID.Value + "'</script>");
             Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('保存成功!');</script>");
         }
     }
 }