public IActionResult MultipleCreate(MultiplePhotoUploadViewModel model)
        {
            if (ModelState.IsValid)
            {
                foreach (var item in model.Photos)
                {
                    var isFormatCorrect = SD.IsImage(item);
                    if (isFormatCorrect == true)
                    {
                        string uniqueFileName = MProcessUploadedFile(item);
                        var    pic            = new pic
                        {
                            Address = uniqueFileName,
                        };
                        _db.pics.Add(pic);
                        _db.SaveChanges();
                    }

                    else
                    {
                        ModelState.AddModelError("", "Wrong Format File Uploaded");
                        return(View(model));
                    }
                }
            }

            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 2
0
        public static void updateProduct(int id, int type, int[] filters, String name,
                                         String code, String specs, float price, float offer, int items, String[] uploadedImages)
        {
            using (DB_entities db = new DB_entities())
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    var prod = (from p in db.products where p.id == id select p).FirstOrDefault();
                    prod.name        = name;
                    prod.code        = code;
                    prod.specs       = specs;
                    prod.price       = price;
                    prod.offer       = offer;
                    prod.items       = items;
                    prod.prodtype_id = type;

                    try
                    {
                        db.SaveChanges();

                        var picsDel = from p in db.pics where p.product_id == id select p;
                        foreach (var item in picsDel)
                        {
                            db.pics.Remove(item);
                        }

                        pic pics = new pic();
                        for (int i = 0; i < uploadedImages.Length; i++)
                        {
                            pics.pic_path   = uploadedImages[i];
                            pics.product_id = id;
                            db.pics.Add(pics);
                            db.SaveChanges();
                        }


                        var filterDel = from p in db.product_filters where p.product_id == id select p;
                        foreach (var item in filterDel)
                        {
                            db.product_filters.Remove(item);
                        }
                        product_filters filterList = new product_filters();
                        for (int i = 0; i < filters.Length; i++)
                        {
                            filterList.value_id   = filters[i];
                            filterList.product_id = id;
                            db.product_filters.Add(filterList);
                            db.SaveChanges();
                        }

                        db.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        Log.error("updateProduct - Update.cs", DateTime.Now, ex);
                    }
                    scope.Complete();
                }
            }
        }
Exemplo n.º 3
0
        // computes distance between a pic element and a location
        public Double GetDistance(pic p, Location location)
        {
            string[] tmp          = p.Coordinates.Split(';');
            Double   picLatitude  = Convert.ToDouble(tmp[0]);
            Double   picLongitude = Convert.ToDouble(tmp[1]);
            Location picLocation  = new Location(picLatitude, picLongitude);
            Double   Distance     = Location.CalculateDistance(picLocation, location, DistanceUnits.Kilometers);

            return(Distance);
        }
Exemplo n.º 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (DefaultBase.IsSetTong)
            {
                MessageBox.Show("请先检测设定", "检测", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
            }

            pic pic = new pic(_tempCode);

            pic.Show();
            pic.TopMost = true;
        }
Exemplo n.º 5
0
 private void piccc(bool bl)
 {
     if (pictureBox1.InvokeRequired)
     {
         pic p = new pic(piccc);
         this.Invoke(p, new object[] { bl });
     }
     else
     {
         pictureBox1.Visible = bl;
     }
 }
Exemplo n.º 6
0
 private void piccc(bool bl)
 {
     if (pictureBox1.InvokeRequired)
     {
         pic p = new pic(piccc);
         this.Invoke(p, new object[] { bl });
     }
     else
     {
         pictureBox1.Visible = bl;
     }
 }
Exemplo n.º 7
0
        public static void addProduct(int type, int[] filters, String name,
                                      String code, String specs, float price, float offer, int items, String[] uploadedImages)
        {
            using (DB_entities db = new DB_entities())
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    product prod = new product();
                    prod.name        = name;
                    prod.code        = code;
                    prod.specs       = specs;
                    prod.price       = price;
                    prod.offer       = offer;
                    prod.items       = items;
                    prod.prodtype_id = type;

                    try
                    {
                        db.products.Add(prod);
                        db.SaveChanges();

                        int productId = prod.id;

                        pic pics = new pic();
                        for (int i = 0; i < uploadedImages.Length; i++)
                        {
                            pics.pic_path   = uploadedImages[i];
                            pics.product_id = productId;
                            db.pics.Add(pics);
                            db.SaveChanges();
                        }

                        product_filters filterList = new product_filters();
                        for (int i = 0; i < filters.Length; i++)
                        {
                            filterList.value_id   = filters[i];
                            filterList.product_id = productId;
                            db.product_filters.Add(filterList);
                            db.SaveChanges();
                        }

                        db.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        Log.error("addProduct - Insert.cs", DateTime.Now, ex);
                    }
                    scope.Complete();
                }
            }
        }
Exemplo n.º 8
0
        public ActionResult ImgDetails(int ImgId, string imgName, string ImgAlt, bool Share, string thumb)
        {
            pic thisPic = new pic();

            thisPic.imgName = imgName;
            thisPic.ImgAlt  = ImgAlt;
            thisPic.Share   = Share;
            thisPic.themb   = thumb;
            thisPic.Id      = ImgId;

            ViewBag.AlbumName = (string)Session["AlbumName"];
            ViewBag.NoPic     = (int)Session["NoPic"];
            ViewBag.Status    = (bool)Session["Status"];
            ViewBag.Cdate     = (DateTime)Session["Cdate"];
            ViewBag.ABI       = (int)Session["albumId"];

            return(PartialView("_ImgDetails", thisPic));
        }
Exemplo n.º 9
0
 public static int addPictures(String path, int productId)
 {
     using (DB_entities db = new DB_entities())
     {
         pic pics = new pic();
         pics.pic_path   = path;
         pics.product_id = productId;
         try
         {
             db.pics.Add(pics);
             db.SaveChanges();
             return(pics.id);
         }
         catch (Exception ex)
         {
             Log.error("addPictures - Insert.cs", DateTime.Now, ex);
             return(0);
         }
     }
 }
Exemplo n.º 10
0
        public ActionResult GetPicByAlbum(int AID)
        {
            if (Session["IDs"] != null)
            {
                List <int> IDs   = (List <int>)Session["IDs"];
                List <pic> MyImg = IMGPRO.AlbumPic(User.Identity.Name, AID);

                foreach (int i in IDs)
                {
                    pic thispic = MyImg.Where(x => x.Id == i).FirstOrDefault();
                    MyImg.Remove(thispic);
                }

                return(PartialView("_LP", MyImg));
            }

            else
            {
                List <pic> MyImg = IMGPRO.AlbumPic(User.Identity.Name, AID);
                return(PartialView("_LP", MyImg));
            }
        }
Exemplo n.º 11
0
 public pic SelectedPic(pic selectedItem)
 {
     return(selectedItem);
 }
Exemplo n.º 12
0
        //Saves image to jsonFile. Does overwrite if a pic with the same TimeStamp is already in there
        public static void SaveImage(String Name, String TimeStamp, String Location, String Category, String Directory, int Rating)
        {
            String dir      = "/storage/emulated/0/Android/data/com.companyname.projectapp/files/";
            pic    savedPic = new pic();

            savedPic.Name        = Name;
            savedPic.TimeStamp   = TimeStamp;
            savedPic.Category    = Category;
            savedPic.Coordinates = Location;
            savedPic.Directory   = dir + "Pictures/cs191t/" + Directory;
            savedPic.Rating      = Rating;
            string     fileName = dir + "jsonFile.txt";
            List <pic> pics     = new List <pic>();

            if (File.Exists(dir + "jsonFile.txt"))
            {
                string text = File.ReadAllText(fileName);
                try
                {
                    pics = JsonConvert.DeserializeObject <List <pic> >(text);
                }
                catch (Exception e)
                {
                    Console.WriteLine("--------------Json did not save--------------");
                }
                //Linq to find if already saved
                var match = from p in pics
                            where p.TimeStamp == savedPic.TimeStamp
                            select p;
                pic firstmatch = null;
                try
                {
                    firstmatch = match.First();
                }
                catch (Exception e)
                {
                }

                if (firstmatch != null)
                {
                    savedPic.Directory = firstmatch.Directory;
                    pics.Remove(firstmatch);
                    pics.Add(savedPic);
                    string json = JsonConvert.SerializeObject(pics);
                    File.WriteAllText(fileName, json);
                }

                else
                {
                    pics.Add(savedPic);
                    string json = JsonConvert.SerializeObject(pics);
                    File.WriteAllText(fileName, json);
                }
            }
            else
            {
                pics.Add(savedPic);
                string json = JsonConvert.SerializeObject(pics);
                File.WriteAllText(fileName, json);
            }
        }