コード例 #1
0
        public Boolean delete_winform_use_only(HinhAnh obj)
        {
            try
            {
                string url = Setting.get_by_key("path_to_website") + "/ImageUpload/Delete?hinhanh_id=" + obj.id;
                WebClient webClient = new WebClient();
                string result = webClient.DownloadString(url);
                if (TextLibrary.ToBoolean(result.Substring(0,1)))
                {
                    _db.Entry<HinhAnh>(obj).State = System.Data.EntityState.Detached;

                    return true;
                }
                else return false;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                return false;
            }
        }
コード例 #2
0
 //method
 public void change(HinhAnh ha)
 {
     duongdan = ha.duongdan;
     duongdan_thumb = ha.duongdan_thumb;
     macdinh = ha.macdinh;
     if(ha.sanpham != null) sanpham = ha.sanpham;
 }
コード例 #3
0
 public void _set_hinhanh_macdinh(HinhAnh ha)
 {
     _get_hinhanh_macdinh().macdinh = false;
     ha.macdinh = true;
 }
コード例 #4
0
 public HinhAnh _get_hinhanh_macdinh()
 {
     HinhAnh tmp = this.ds_hinhanh.Where(x => x.macdinh == true).FirstOrDefault();
     if (tmp == null)
     {
         tmp = new HinhAnh();
         tmp.duongdan =tmp.duongdan_thumb= "default.jpg";
     }
     return tmp;
 }
コード例 #5
0
        private void btThemHinhAnh_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Multiselect = true;
            ofd.ShowDialog();
            bool file_ok = false;
            foreach (string path in ofd.FileNames)
            {
                if (path.Trim() == "") continue;
                HinhAnh ha = new HinhAnh();
                ha.source_picture_from_web = false;
                ha.duongdan = path;
                ha.duongdan_thumb = path;
                sp.ds_hinhanh.Add(ha);
                file_ok = true;
            }

            if (file_ok)
            {
                LoadDTGV_HinhAnh();
                MessageBox.Show("Thêm thành công.");
                IsChange = true;
            }
        }
コード例 #6
0
 public int add(HinhAnh dt)
 {
     _db.ds_hinhanh.Add(dt);
     _db.SaveChanges();
     return _db.ds_hinhanh.Max(x => x.id);
 }
コード例 #7
0
 public HinhAnh upload_winform_use_only(string local_file_path="")
 {
     string fileToUpload = local_file_path;
     string url = Setting.get_by_key("path_to_website") + "/ImageUpload/Index";
     using (var client = new WebClient())
     {
         byte[] result = client.UploadFile(url, "POST", fileToUpload);
         string responseAsString = Encoding.UTF8.GetString(result);
         //ngan ket qua bang cac dau |
         string[] file_names = responseAsString.Split('|');
         HinhAnh re = new HinhAnh();
         re.duongdan = file_names[0];
         re.duongdan_thumb = file_names[1];
         return re;
     }
 }
コード例 #8
0
        public HinhAnh upload_mvc_use_only(HttpServerUtilityBase server_context, HttpFileCollectionBase file_list)
        {
            Debug.WriteLine("file count: "+file_list.Count);
            //pre setting
            int max_width_height = 300;
            String relative_directory = "~/_Upload/HinhAnh/";
            //
            String server_path = "";
            String server_path_thumb = "";
            foreach (string file_name in file_list)
            {
                HttpPostedFileBase hpf = file_list[file_name];
                string _ext = Path.GetExtension(hpf.FileName);
                String random_prefix = TextLibrary.GetSHA1HashData(DateTime.Now.ToLongDateString() + DateTime.Now.ToLongTimeString() + file_name).Substring(0,20);
                server_path = server_context.MapPath(Path.Combine(relative_directory, random_prefix + _ext /* + Path.GetFileName(hpf.FileName)*/));

                server_path_thumb = server_context.MapPath(Path.Combine(relative_directory, "_thumb_" + random_prefix + _ext /* + Path.GetFileName(hpf.FileName)*/));
                if (hpf.ContentLength == 0)
                {
                    continue;
                }
                HinhAnh hinhanh = new HinhAnh();
                //save origin
                    hpf.SaveAs(server_path);
                    hinhanh.duongdan = random_prefix + _ext;
                //save thumb
                    Image imgOriginal = Image.FromFile(server_path);
                    Image hinhanh_thumb = ImageLibrary.ScaleBySize(imgOriginal, max_width_height);
                    imgOriginal.Dispose();
                    hinhanh_thumb.Save(server_path_thumb);
                    hinhanh_thumb.Dispose();
                    hinhanh.duongdan_thumb = "_thumb_" + random_prefix + _ext;
                //add to re
                return hinhanh;
            }
            return new HinhAnh();
        }
コード例 #9
0
 public Boolean edit(HinhAnh kt)
 {
     if (this.is_exist(kt.id))
     {
         HinhAnh obj = this.get_by_id(kt.id);
         obj.duongdan = kt.duongdan;
         _db.SaveChanges();
         return true;
     }
     return false;
 }