예제 #1
0
 protected void btImage_Click(object sender, EventArgs e)
 {
     //檔名切換
     if (fuImage.HasFile)
     {
         string imgFileName = WebUtility.ChangeFileNameAsRandom(fuImage.FileName);
         if (WebUtility.CheckImageExt(System.IO.Path.GetExtension(imgFileName)))
         {
             //從Web.Config取得路徑
             string serverFileName = WebUtility.MergePathAndFileName(imgFileName, Tools.GetAppSettings("NewsImageTempPath"));
             fuImage.SaveAs(serverFileName);
             if (Session["npImginfo"] == null)
             {
                 npImgInfos = new List <NewsImageInfo>();
             }
             else
             {
                 npImgInfos = (List <NewsImageInfo>)Session["npImginfo"];
             }
             NewsImageInfo info = new NewsImageInfo();
             info.np_name      = imgFileName;
             info.np_imagename = imgFileName;
             npImgInfos.Add(info);
             tfBLL.InsertTempFiles("News", Tools.GetAppSettings("NewsImageTempPath") + imgFileName);
             Session["npImginfo"] = npImgInfos;
             rpImage.DataSource   = npImgInfos;
             rpImage.DataBind();
         }
         else
         {
             this.Page.Controls.Add(Tools.Tomsg("副檔名格式錯誤"));
         }
     }
 }
예제 #2
0
        public void Delete(int np_id)
        {
            NewsImageInfo info = GetImgWithKey(np_id);

            if (File.Exists(HttpContext.Current.Server.MapPath(Tools.GetAppSettings("NewsImageTruePath") + info.np_name)))
            {
                File.Delete(HttpContext.Current.Server.MapPath(Tools.GetAppSettings("NewsImageTruePath") + info.np_name));
            }
            db.Delete(np_id);
        }
예제 #3
0
        public List <NewsImageInfo> GetAllImgWithNews(int n_id)
        {
            List <NewsImageInfo> infos  = new List <Model.NewsImageInfo>();
            IDataReader          reader = db.GetAllImgWithNews(n_id).CreateDataReader();

            while (reader.Read())
            {
                infos.Add(NewsImageInfo.Populate(reader));
            }
            return(infos);
        }
예제 #4
0
        public NewsImageInfo GetImgWithKey(int np_id)
        {
            NewsImageInfo info   = new Model.NewsImageInfo();
            IDataReader   reader = db.GetImageWithKey(np_id).CreateDataReader();

            if (reader.Read())
            {
                info = NewsImageInfo.Populate(reader);
            }
            return(info);
        }
예제 #5
0
 protected void rpImage_ItemCommand(object source, RepeaterCommandEventArgs e)
 {
     if (e.CommandName == "Delete")
     {
         niBLL.Delete(int.Parse(e.CommandArgument.ToString()));
     }
     if (e.CommandName == "Update")
     {
         NewsImageInfo info = niBLL.GetImgWithKey(int.Parse(e.CommandArgument.ToString()));
         hfImageIndex.Value = info.np_imagename;
     }
     rpImage.DataSource = niBLL.GetAllImgWithNews(Tools.GetInt32SafeFromQueryString(this.Page, "id", 0));
     rpImage.DataBind();
 }
예제 #6
0
        public void AllMethodTest()
        {
            var imagemodel = new NewsImageInfo()
            {
                Id             = 1,
                NewsId         = 1,
                NormalURL      = "",
                HDURL          = "",
                Status         = 1,
                CreateDateTime = DateTime.Now
            };

            var add_value = dbContextService.Add <NewsImageInfo>(imagemodel);

            Console.WriteLine(add_value);

            imagemodel.Status = 0;

            var update_value = dbContextService.Update <NewsImageInfo>(imagemodel);

            Assert.Equal(0, imagemodel.Status);
            Console.WriteLine(imagemodel.Status);

            var find_model = dbContextService.Find <NewsImageInfo>(x => x.Id == 1);

            Assert.Equal(1, find_model.Count);
            Console.WriteLine(find_model.Count);

            var single_model = dbContextService.Single <NewsImageInfo>(1);

            Assert.Equal(1, single_model.Id);

            var exsit = dbContextService.Exists <NewsImageInfo>(x => x.Id == 1);

            Assert.Equal(true, exsit);

            var del_value = dbContextService.Delete <NewsImageInfo>(imagemodel);

            Console.WriteLine(del_value);
        }
예제 #7
0
    private void InsertNewsImage(int NewsID)
    {
        NewsImageInfo npinfo = new NewsImageInfo();

        //筆數
        for (int i = 0; i < rpImage.Items.Count; i++)
        {
            Image lbtxtFormatName = (Image)rpImage.Items[i].FindControl("Image1");
            if (lbtxtFormatName != null)
            {
                //由此寫入真實檔原圖轉移程序
                if (System.IO.File.Exists(Server.MapPath(Tools.GetAppSettings("NewsImageTempPath") + lbtxtFormatName.AlternateText)))
                {
                    System.IO.FileInfo file = new System.IO.FileInfo(Server.MapPath(Tools.GetAppSettings("NewsImageTempPath") + lbtxtFormatName.AlternateText));
                    file.CopyTo(Server.MapPath(Tools.GetAppSettings("NewsImageTruePath") + lbtxtFormatName.AlternateText));
                }
                npinfo.n_id         = NewsID;
                npinfo.np_name      = lbtxtFormatName.AlternateText;
                npinfo.np_imagename = lbtxtFormatName.AlternateText;
            }
            niBLL.Insert(npinfo);
        }
    }
예제 #8
0
 protected void btImage_Click(object sender, EventArgs e)
 {
     if (fuImage.HasFile)
     {
         string imgFilename = WebUtility.ChangeFileNameAsRandom(fuImage.FileName);
         if (WebUtility.CheckImageExt(System.IO.Path.GetExtension(imgFilename)))
         {
             string serverFileName = WebUtility.MergePathAndFileName(imgFilename, Tools.GetAppSettings("NewsImageTruePath"));
             fuImage.SaveAs(serverFileName);
             NewsImageInfo info = new NewsImageInfo();
             info.n_id         = Tools.GetInt32SafeFromQueryString(this.Page, "id", 0);
             info.np_name      = imgFilename;
             info.np_imagename = imgFilename;
             niBLL.Insert(info);
             tfBLL.InsertTempFiles("News", Tools.GetAppSettings("NewsImageTruePath") + imgFilename);
             rpImage.DataSource = niBLL.GetAllImgWithNews(Tools.GetInt32SafeFromQueryString(this.Page, "id", 0));
             rpImage.DataBind();
         }
     }
     else
     {
         this.ShowMessage("請選擇一個檔案");
     }
 }
예제 #9
0
 public void Insert(NewsImageInfo info)
 {
     db.Insert(info.n_id, info.np_name, info.np_imagename);
 }