コード例 #1
0
        public JsonResult SendVideo(FormCollection collection)
        {
            using (剧享网Entities db = new 剧享网Entities())
            {
                //判断该功能权限是否关闭
                var JudgePermission = from judgepermission in db.T_Function where judgepermission.F_SubId == "3F1" && judgepermission.F_Function == "SendFunction" && judgepermission.F_FatherId == "2F3" select judgepermission;
                int F_IsOpen        = 1;
                foreach (var open in JudgePermission)
                {
                    F_IsOpen = open.F_IsOpen;
                }
                if (F_IsOpen == 0)
                {
                    return(Json("Close"));
                }

                string UserName = Session["UserName"].ToString();
                string PassWord = Session["PassWord"].ToString();
                string Email    = Session["Email"].ToString();
                //string UserName = "******";
                //string PassWord = "******";
                //string Email = "*****@*****.**";
                string NowTime = Convert.ToString(DateTime.Now);
                //视频发送时间
                string VideoSendTime = null;

                //获取对应用户的信息
                var selectinfo = from info in db.T_User where info.U_Email == Email && info.U_UserName == UserName && info.U_UserPassWord == PassWord select info;
                //获取用户Id
                int U_Id = 0;
                foreach (char signal in NowTime)
                {
                    if (signal != ':' && signal != '/')
                    {
                        VideoSendTime += signal;
                    }
                }
                string VideoName                 = collection["VideoName"];
                string VideoIntroduction         = collection["VideoIntroduction"];
                HttpFileCollectionBase hfcb      = Request.Files;
                HttpPostedFileBase     hpfbVideo = hfcb["video"];
                HttpPostedFileBase     hpfbImg   = hfcb["img"];
                string DirectoryPath             = UserName + "视频" + VideoName + VideoSendTime;

                //获取用户可发送大小
                int SendSpace = 0;
                foreach (var info in selectinfo)
                {
                    U_Id      = info.U_Id;
                    SendSpace = info.U_SendSpace;
                }
                var HadSentSize = from size in db.T_SendWork where size.U_Id == U_Id select size;
                //获取已发送的总大小
                int VideoSize = 0;
                foreach (var size in HadSentSize)
                {
                    VideoSize += size.S_WorkSize;
                }
                if ((SendSpace - VideoSize) <= (hpfbVideo.ContentLength + hpfbImg.ContentLength))
                {
                    return(Json("Fail"));//空间不够发送失败
                }

                try
                {
                    //获取视频名称
                    string videoinfo         = System.IO.Path.GetFileName(hpfbVideo.FileName);
                    string getVideoExtension = System.IO.Path.GetExtension(videoinfo);
                    string VideoFileName     = DirectoryPath + getVideoExtension;
                    //获取图片名称
                    string imginfo         = System.IO.Path.GetFileName(hpfbImg.FileName);
                    string getImgExtension = System.IO.Path.GetExtension(imginfo);
                    string ImgFileName     = DirectoryPath + getImgExtension;
                    if ((hpfbVideo.ContentLength + hpfbImg.ContentLength) > (1024 * 1024 * 30))
                    {
                        return(Json("30M"));
                    }
                    //创建父文件夹
                    if (!System.IO.Directory.Exists(Server.MapPath("~/MyVideo/" + DirectoryPath)))
                    {
                        System.IO.Directory.CreateDirectory(Server.MapPath("~/MyVideo/" + DirectoryPath));
                    }
                    //写入视频介绍内容
                    FileStream   fs     = new FileStream(Server.MapPath("~/MyVideo/" + DirectoryPath + "\\" + DirectoryPath + ".txt"), FileMode.Create, FileAccess.ReadWrite);
                    StreamWriter writer = new StreamWriter(fs);
                    writer.Write(VideoIntroduction);
                    writer.Close();
                    fs.Close();
                    //保存封面图片到指定文件夹下
                    hpfbImg.SaveAs(Server.MapPath("~/MyVideo/" + DirectoryPath + "\\" + ImgFileName));
                    //保存上传的视频到指定文件夹下
                    hpfbVideo.SaveAs(Server.MapPath("~/MyVideo/" + DirectoryPath + "\\" + VideoFileName));

                    T_SendWork sendWork = new T_SendWork();
                    sendWork.U_UserName = UserName;
                    sendWork.U_Id       = U_Id;
                    sendWork.W_Id       = 2;
                    sendWork.S_WorkName = VideoName;
                    sendWork.S_WorkPath = "~/MyVideo/" + DirectoryPath;
                    sendWork.S_WorkSize = (hpfbVideo.ContentLength + hpfbImg.ContentLength);
                    sendWork.S_SendTime = NowTime;
                    db.T_SendWork.Add(sendWork);
                    db.SaveChanges();
                }
                catch
                { }
            }
            return(Json("OK"));
        }
コード例 #2
0
        public JsonResult SendMyEassy(FormCollection collection)
        {
            string UserName = Session["UserName"].ToString();
            string PassWord = Session["PassWord"].ToString();
            string Email    = Session["Email"].ToString();

            //string UserName = "******";
            //string PassWord = "******";
            //string Email = "*****@*****.**";
            using (剧享网Entities db = new 剧享网Entities())
            {
                //判断该功能权限是否关闭
                var JudgePermission = from judgepermission in db.T_Function where judgepermission.F_SubId == "3F1" && judgepermission.F_Function == "SendFunction" && judgepermission.F_FatherId == "2F3" select judgepermission;
                int F_IsOpen        = 1;
                foreach (var open in JudgePermission)
                {
                    F_IsOpen = open.F_IsOpen;
                }
                if (F_IsOpen == 0)
                {
                    return(Json("Close"));
                }
                //获取对应用户的信息
                var selectinfo = from info in db.T_User where info.U_Email == Email && info.U_UserName == UserName && info.U_UserPassWord == PassWord select info;
                //获取用户Id
                int U_Id = 0;
                foreach (var info in selectinfo)
                {
                    U_Id = info.U_Id;
                }

                //
                string EassyName = collection["EassyName"].Trim();
                //
                string EassyContent = collection["EassyContent"];
                string NowTime      = Convert.ToString(DateTime.Now);
                //
                string EassySendTime = null;
                foreach (char signal in NowTime)
                {
                    if (signal != ':' && signal != '/')
                    {
                        EassySendTime += signal;
                    }
                }
                //
                string EassyTxtName = UserName + "文章" + EassyName + EassySendTime;
                //
                string EassyImgName = UserName + "文章" + EassyName + EassySendTime;
                //
                string FatherFilePath = "~/MyEassy/" + UserName + "文章" + EassyName + EassySendTime;
                //获取前台的文件信息
                HttpFileCollectionBase httpFile = Request.Files;
                //获取文件中图片的信息,这个参数是对应前台的input的name值
                HttpPostedFileBase fileBase = httpFile["img"];

                //获取用户可发送大小
                int SendSpace = 0;
                foreach (var info in selectinfo)
                {
                    U_Id      = info.U_Id;
                    SendSpace = info.U_SendSpace;
                }
                var HadSentSize = from size in db.T_SendWork where size.U_Id == U_Id select size;
                //获取已发送的总大小
                int VideoSize = 0;
                foreach (var size in HadSentSize)
                {
                    VideoSize += size.S_WorkSize;
                }
                if ((SendSpace - VideoSize) <= fileBase.ContentLength)
                {
                    return(Json("Fail"));//空间不够发送失败
                }

                try
                {
                    string imginfo      = System.IO.Path.GetFileName(fileBase.FileName);
                    string imgextension = System.IO.Path.GetExtension(imginfo);
                    EassyImgName += imgextension;
                    //如果用户的文章文件夹不存在,则创建
                    if (!Directory.Exists(Server.MapPath(FatherFilePath)))
                    {
                        Directory.CreateDirectory(Server.MapPath(FatherFilePath));
                    }
                    //
                    FileStream   fs   = new FileStream(Server.MapPath(FatherFilePath + "\\" + EassyTxtName + ".txt"), FileMode.Create, FileAccess.ReadWrite);
                    StreamWriter mysw = new StreamWriter(fs);
                    //只存入文章的内容
                    mysw.Write(EassyContent);
                    //必须关掉文件流!!!
                    mysw.Close();
                    fs.Close();
                    //
                    string imgPath = Server.MapPath(FatherFilePath + "\\" + EassyImgName);
                    fileBase.SaveAs(imgPath);

                    //将发布的文章信息保存到数据库
                    T_SendWork sendWork = new T_SendWork();
                    sendWork.U_UserName      = UserName;
                    sendWork.U_Id            = U_Id;
                    sendWork.W_Id            = 1;
                    sendWork.S_WorkName      = EassyName;
                    sendWork.S_WorkPath      = FatherFilePath;
                    sendWork.S_WorkSize      = fileBase.ContentLength; //给发布的文章大小赋值
                    sendWork.S_WorkViewCount = 0;                      //发送文章初试浏览数为0
                    sendWork.S_SendTime      = NowTime;
                    db.T_SendWork.Add(sendWork);
                    db.SaveChanges();
                    return(Json("OK"));
                }
                catch { return(Json("")); }
            }
        }