コード例 #1
0
        public static ImagesTable FindLastAddedImage()
        {
            LinqToSqlDataContext db   = DatabaseSetup.Database;
            ImagesTable          last = (from l in db.ImagesTables
                                         select l).OrderByDescending(l => l.id).First();

            return(last);
        }
コード例 #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            ImagesTable imagesTable = db.ImagesTable.Find(id);

            db.ImagesTable.Remove(imagesTable);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #3
0
        public static ImagesTable GetImageById(int id)
        {
            LinqToSqlDataContext db    = DatabaseSetup.Database;
            ImagesTable          image = (from i in db.ImagesTables
                                          where i.id == id
                                          select i).Single();

            return(image);
        }
コード例 #4
0
        public static void RemoveImage(int imageId)
        {
            LinqToSqlDataContext db       = DatabaseSetup.Database;
            ImagesTable          imgGoner = (from goner in db.ImagesTables
                                             where goner.id == imageId
                                             select goner).Single();

            db.ImagesTables.DeleteOnSubmit(imgGoner);
            db.SubmitChanges();
        }
コード例 #5
0
 public ActionResult Edit([Bind(Include = "ID,ErrorNo,Name,AddedPlace,ImagePath")] ImagesTable imagesTable)
 {
     if (ModelState.IsValid)
     {
         db.Entry(imagesTable).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ErrorNo = new SelectList(db.ErrorListTable, "ErrorNo", "Company", imagesTable.ErrorNo);
     return(View(imagesTable));
 }
コード例 #6
0
        public static void AddImage(ImageStruct imageStruct)
        {
            LinqToSqlDataContext db  = DatabaseSetup.Database;
            ImagesTable          img = new ImagesTable();

            byte[] array = ImageToByte(imageStruct.image);
            img.name = imageStruct.imgName;
            img.img  = array;
            db.ImagesTables.InsertOnSubmit(img);
            db.SubmitChanges();
        }
コード例 #7
0
        // GET: ImagesTables/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ImagesTable imagesTable = db.ImagesTable.Find(id);

            if (imagesTable == null)
            {
                return(HttpNotFound());
            }
            return(View(imagesTable));
        }
コード例 #8
0
        private void BtnRemoveImage_Click(object sender, RoutedEventArgs e)
        {
            int         gonerId    = gallery.GetSelectedImageDatabaseID();
            ImagesTable gonerImage = Images.GetImageById(gonerId);

            // odstranit propojení
            Images.RemoveRelationship(gonerId, _id);
            // odstranit obrázek z databáze
            Images.RemoveImage(gonerId);

            //Refresh gallery
            gallery.Images = Images.GetImages(StorageSetup.GetProductById(_id));
            gallery.Update();
        }
コード例 #9
0
        // GET: ImagesTables/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ImagesTable imagesTable = db.ImagesTable.Find(id);

            if (imagesTable == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ErrorNo = new SelectList(db.ErrorListTable, "ErrorNo", "Company", imagesTable.ErrorNo);
            return(View(imagesTable));
        }
コード例 #10
0
        private void BtnAddImage_Click(object sender, RoutedEventArgs e)
        {
            // Nahrání obrázků do databáze


            System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog();
            ofd.Multiselect = true;
            ofd.Filter      = "Obrázky|*.jpg;*.bmp;*.png;*.gif";
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string[] paths = ofd.FileNames;
                Uri[]    uris  = new Uri[paths.Count()];
                for (int i = 0; i <= paths.Count() - 1; i++)
                {
                    uris[i] = new Uri(paths[i]);
                }

                List <ImageStruct> imagesAdded = new List <ImageStruct>();
                for (int u = 0; u <= uris.Count() - 1; u++)
                {
                    ImageStruct s = new ImageStruct()
                    {
                        imgName = System.IO.Path.GetFileNameWithoutExtension(paths[u]),
                        image   = new BitmapImage(uris[u])
                    };
                    imagesAdded.Add(s);
                }

                foreach (ImageStruct istr in imagesAdded)
                {
                    // Práce s databází
                    Images.AddImage(istr);
                    Product     p   = StorageSetup.GetProductById(_id);
                    ImagesTable imt = Images.FindLastAddedImage();

                    Images.AssignImageToProduct(p, imt);
                }

                // Získání obrázků z databáze - i s ID's
                gallery.Images = Images.GetImages(StorageSetup.GetProductById(_id));
                gallery.Update();
            }
        }
コード例 #11
0
        public static bool AssignImageToProduct(Product product, ImagesTable image)
        {
            LinqToSqlDataContext db          = DatabaseSetup.Database;
            ProductImage         assignTable = new ProductImage();

            try
            {
                assignTable.idImage   = image.id;
                assignTable.idProduct = product.id;

                db.ProductImages.InsertOnSubmit(assignTable);
                db.SubmitChanges();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
コード例 #12
0
        public static void AddImage(string resourceName, string imageName)
        {
            LinqToSqlDataContext db  = DatabaseSetup.Database;
            ImagesTable          img = new ImagesTable();
            var assembly             = Assembly.GetExecutingAssembly();

            byte[] imageBinary = null;


            using (BinaryReader br = new BinaryReader(assembly.GetManifestResourceStream(resourceName)))
            {
                imageBinary = br.ReadBytes((int)br.BaseStream.Length);
            }

            img.name = imageName;
            img.img  = imageBinary;

            db.ImagesTables.InsertOnSubmit(img);
            db.SubmitChanges();
        }
コード例 #13
0
ファイル: FileHelper.cs プロジェクト: EMREERGN/InanSoftMvc
        public void saveImagesDB(HttpPostedFileBase[] imageFiles, string addedStep, string errorNo)
        {
            var userModel = common.getCurrentUserModel();

            System.IO.Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/images/" + userModel.Company)); // geçerli şirket resimlerine ait klasör yaratılır

            // Add image flie to db------------------
            int counter = 0;

            foreach (var image in imageFiles)
            {
                try
                {
                    counter++;
                    ImagesTable imageTable = new ImagesTable();
                    imageTable.ErrorNo    = errorNo;
                    imageTable.AddedPlace = addedStep;


                    var fileNameWithOutExtension = Path.GetFileNameWithoutExtension(image.FileName); // uzantısız adı alınır
                    var extension = Path.GetExtension(image.FileName);                               // uzantısı alınır


                    // uzantısız dosya adı illegal karakterlerden arındırıldı
                    fileNameWithOutExtension = Regex.Replace(fileNameWithOutExtension, "[^a-zA-Z0-9_]+", "_", RegexOptions.Compiled); // dosya adı uzantısız olarak değiştirildi

                    imageTable.Name = fileNameWithOutExtension;
                    string filePath = "~/images/" + userModel.Company + "/" + "(" + addedStep + ")" + errorNo + "_" + counter.ToString() + "_" + fileNameWithOutExtension + extension;
                    imageTable.ImagePath = filePath;
                    db.ImagesTable.Add(imageTable);
                    db.SaveChanges();
                    //Save the Image File in Folder.
                    image.SaveAs(HttpContext.Current.Server.MapPath(filePath));
                }
                catch (Exception ex) { }
            }
        }
コード例 #14
0
        private void btnSubmit_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string   name         = ValidateProduct.Name(tbName.Text);
                int      quantity     = ValidateProduct.Quantity(tbQuantity.Text);
                string   unitName     = cbUnit.Text;
                decimal  unitQuantity = ValidateProduct.UnitQuantity(tbUnitQuantity.Text);
                DateTime?date         = ValidateProduct.Date(dpExpirationDate.SelectedDate);
                int      code         = ValidateProduct.Code(tbCode.Text);
                decimal  price        = ValidateProduct.Price(tbPrice.Text);
                price = Convert.ToDecimal(Math.Round(Convert.ToDouble(price), 1, MidpointRounding.AwayFromZero)); // cena se zaokrouhlí na jedno desetinné místo
                bool priceForUnit = cbPriceForUnit.Text == "Ano" ? true : false;
                char VAT          = cbVAT.SelectedItem.ToString()[0];

                LinqToSqlDataContext db = DatabaseSetup.Database;
                int i = (from u in db.Units
                         where u.name == unitName
                         select u.id).Single();
                int unitId = i;

                if (StorageSetup.AddProduct(name, quantity, unitId, unitQuantity, date, code, price, priceForUnit, VAT))
                {
                    // ještě je potřeba uložit do databáze obrázky a asociovat je s produktem
                    Product lastAddedProduct = StorageSetup.GetLastAddedProduct();
                    if (gallery.lbContainer.HasItems)
                    {
                        foreach (ImageStruct istr in gallery.Images)
                        {
                            Images.AddImage(istr);
                            ImagesTable lastAddedImage = Images.FindLastAddedImage();
                            Images.AssignImageToProduct(lastAddedProduct, lastAddedImage);
                        }
                    }

                    DialogHelper.ShowInfo("Produkt přidán.");
                    this.Close();
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
            catch (InvalidNameException ex)
            {
                DialogHelper.ShowWarning(ex.Message);
            }
            catch (InvalidQuantityException ex)
            {
                DialogHelper.ShowWarning(ex.Message);
            }
            catch (InvalidUnitQuantityException ex)
            {
                DialogHelper.ShowWarning(ex.Message);
            }
            catch (ExistingCodeException ex)
            {
                DialogHelper.ShowWarning(ex.Message);
            }
            catch (InvalidCodeException ex)
            {
                DialogHelper.ShowWarning(ex.Message);
            }

            catch (InvalidPriceException ex)
            {
                DialogHelper.ShowWarning(ex.Message);
            }
            catch (NullDateTimeException ex)
            {
                DialogHelper.ShowWarning(ex.Message);
            }
            catch
            {
                DialogHelper.ShowError("Produkt nebylo možné přidat.");
            }
        }