Beispiel #1
0
        public bool AddProduct(string name, string unit, decimal price, bool isVisible, int count, decimal tax, decimal shipping, out BL.Product product)
        {
            bool addProduct = false;
            using (ShopDataContext db = new ShopDataContext())
            {
                product = new BL.Product();

                if (db.Products.Any(p => p.Name == name))
                    return false;
                BL.Modules.Products.ProductProperies ppbl = new ProductProperies();

                product.ProductID = Guid.NewGuid();
                product.Name = name;
                product.CreateDate = DateTime.Now;
                product.Unit = unit;
                product.Price = price;
                product.InStock = (count > 0);
                product.IsVisible = isVisible;
                product.ProductTypeID = (int)ProductType.Types.Real;
                product.Count = count;
                product.Tax = tax;
                product.Shipping = shipping;
                db.Products.InsertOnSubmit(product);
                db.SubmitChanges();
                addProduct = ppbl.AddProductPhoto(BL.Site.DefaultPhotoPreview, BL.Site.DefaultPhotoOriginal, product.ProductID);
                addProduct = true;

            }
            return addProduct;
        }
Beispiel #2
0
        public void AddToCart(List<ProductCounter> prodIDs, Guid userID)
        {
            using (var db = new ShopDataContext())
            {
                var user = db.Users.First(u => u.UserID == userID);

                var order = user.Orders.FirstOrDefault(o => o.IsActive);

                if (order == null)
                {
                    order = new Order()
                    {
                        DeliveryTypeID = (int)DeliveryTypes.NotDelivered,
                        IsActive = true,
                        IsPaid = false,
                        OrderID = Guid.NewGuid(),
                        OrderStatusID = (int)OrderStatus.NotPaid,
                        PaymentTypeID = (int)PaymentTypes.PayPal,
                        UserID = userID,
                        CreateDate = DateTime.Now,
                        DeliveryDate = DateTime.Now,
                        CountryID = db.Countries.First().ID
                    };
                    db.Orders.InsertOnSubmit(order);
                }

                foreach (var item in prodIDs)
                {
                    var ord = order.OrdersRefProducts.FirstOrDefault(r => r.ProductID == item.ID);
                    int oldCount = 0;
                    BL.Product prod = null;
                    if (ord != null)
                    {
                        oldCount = ord.Count;
                        //ord.Count = Math.Min(item.Count, ord.Product.Count);
                        ord.CreateDate = DateTime.Now;
                    }
                    else
                    {
                        prod = db.Products.First(p => p.ProductID == item.ID);
                        if (prod == null)
                            continue;
                        ord = new OrdersRefProduct()
                        {
                            ProductID = item.ID,
                            ID = Guid.NewGuid(),
                            CreateDate = DateTime.Now,
                        };
                        oldCount = 0;
                        order.OrdersRefProducts.Add(ord);
                    }
                    prod = (prod == null) ? db.Products.First(p => p.ProductID == item.ID) : prod;
                    ord.Count += Math.Min(item.Count, prod.Count);
                    prod.Count -= ord.Count - oldCount;
                    prod.IsVisible = prod.Count > 0;

                }
                db.SubmitChanges();
            }
        }
Beispiel #3
0
        public bool AddProductPhoto(string previewUrl, string originalUrl, Guid productId)
        {
            bool allRight = false;
            using (var db = new ShopDataContext())
            {
                BL.ProductProperty productPropertyPreview = new BL.ProductProperty();
                BL.ProductProperty productPropertyOriginal = new BL.ProductProperty();
                try
                {
                    using (var ts = new TransactionScope())
                    {
                        productPropertyPreview.PropertyID = Guid.NewGuid();
                        productPropertyOriginal.PropertyID = Guid.NewGuid();

                        productPropertyPreview.ProductID = productId;
                        productPropertyOriginal.ProductID = productId;

                        productPropertyPreview.PropertyName = ProductPhoto.ProductPhotoPreview.ToString();
                        productPropertyOriginal.PropertyName = ProductPhoto.ProductPhotoOriginal.ToString();

                        productPropertyPreview.PropertyValue = previewUrl;
                        productPropertyOriginal.PropertyValue = originalUrl;

                        productPropertyPreview.IsImportant = true;
                        productPropertyOriginal.IsImportant = true;

                        productPropertyPreview.Sort = 0;
                        productPropertyOriginal.Sort = 0;

                        db.ProductProperties.InsertOnSubmit(productPropertyPreview);
                        db.SubmitChanges();

                        db.ProductProperties.InsertOnSubmit(productPropertyOriginal);
                        db.SubmitChanges();

                        ts.Complete();
                        allRight = true;
                    }
                }
                catch (Exception)
                {
                    allRight = false;
                }
                return allRight;
            }
        }
Beispiel #4
0
 public void CreateAdmin(string email, string password)
 {
     using (var db = new ShopDataContext())
     {
         db.Admins.InsertOnSubmit(new Admin {Email = email, Password = password});
         db.SubmitChanges();
     }
 }
Beispiel #5
0
 public void AddUnit(Unit unit)
 {
     using (var db = new ShopDataContext())
     {
         db.Units.InsertOnSubmit(unit);
         db.SubmitChanges();
     }
 }
Beispiel #6
0
 public void ConfirmOrder(int id)
 {
     using (var db = new ShopDataContext())
     {
         var unit = db.Orders.FirstOrDefault(u => u.Id == id);
         unit.State = (int) OrderState.InProgress;
         db.SubmitChanges();
     }
 }
Beispiel #7
0
 public void AddCountry(string Name)
 {
     using (ShopDataContext db = new ShopDataContext())
     {
         db.Countries.InsertOnSubmit(new Country()
         {
             Name = Name
         });
         db.SubmitChanges();
     }
 }
Beispiel #8
0
 public bool DeleteCountry(int ID)
 {
     using (ShopDataContext db = new ShopDataContext())
     {
         var country = db.Countries.FirstOrDefault(c => c.ID == ID);
         if (country == null)
             return false;
         db.Countries.DeleteOnSubmit(country);
         db.SubmitChanges();
     }
     return true;
 }
Beispiel #9
0
 public void CreateOrder(IEnumerable<UnitOrderRelation> unitOrderRelations, CustomerInfo customerInfo)
 {
     var order = new Order();
     foreach (var rel in unitOrderRelations)
     {
         order.UnitOrderRelations.Add(rel);
     }
     customerInfo.FillOrder(order);
     order.TimeStamp = DateTime.Now;
     order.State = (int)OrderState.New;
     using (var hren = new ShopDataContext())
     {
         hren.Orders.InsertOnSubmit(order);
         hren.SubmitChanges();
     }
 }
Beispiel #10
0
        public bool DeletePropertyById(Guid propertyId)
        {
            bool deletePropepry = false;

            using (ShopDataContext db = new ShopDataContext())
            {
                BL.CategoryProperty cp = db.CategoryProperties.Where(c => c.CategoriesPropertyID == propertyId).FirstOrDefault();
                if (cp != null)
                {
                    db.CategoryProperties.DeleteOnSubmit(cp);
                    db.SubmitChanges();
                    return true;
                }
            }
            return deletePropepry;
        }
Beispiel #11
0
 public bool AddProductRefCategoryes(Guid productId, Guid categoryId)
 {
     bool add = false;
     using (ShopDataContext db = new ShopDataContext())
     {
         BL.ProductsRefCategory prc = new BL.ProductsRefCategory();
         prc.ID = Guid.NewGuid();
         prc.ProductID = productId;
         prc.CategoryID = categoryId;
         prc.Sort = 0;
         db.ProductsRefCategories.InsertOnSubmit(prc);
         db.SubmitChanges();
         add = true;
     }
     return add;
 }
Beispiel #12
0
 public void DeAcivateNewsById(int newsid)
 {
     using (var db = new ShopDataContext())
     {
         BL.News news = db.News.Where(n => n.NewsID == newsid).FirstOrDefault();
         if (news != null)
         {
             using (var ts = new TransactionScope())
             {
                 news.IsActive = false;
                 db.SubmitChanges();
                 ts.Complete();
             }
         }
     }
 }
Beispiel #13
0
 public void DeleteNewsById(int newsId)
 {
     using (var db = new ShopDataContext())
     {
         BL.News news = db.News.Where(n => n.NewsID == newsId).FirstOrDefault();
         if (news != null)
         {
             using (var ts = new TransactionScope())
             {
                 db.News.DeleteOnSubmit(news);
                 db.SubmitChanges();
                 ts.Complete();
             }
         }
     }
 }
Beispiel #14
0
        public void UpdateUser(Users user)
        {
            using (var db = new ShopDataContext())
            {
                var itemFromDb = db.Users.FirstOrDefault(z => z.Id == user.Id);
                if (itemFromDb == null)
                {
                    return;
                }

                itemFromDb.Email   = user.Email;
                itemFromDb.IsAdmin = user.IsAdmin;
                itemFromDb.Login   = user.Login;
                itemFromDb.Name    = user.Name;
                itemFromDb.Surname = user.Surname;
                db.SubmitChanges();
            }
        }
Beispiel #15
0
 public void AddCategory(string name, Guid? parentId)
 {
     using (var db = new ShopDataContext())
     {
         BL.Category category = new BL.Category();
         using (var ts = new TransactionScope())
         {
             category.Name = name;
             category.CreateDate = DateTime.Now;
             category.ParentID = parentId;
             category.CategoryID = Guid.NewGuid();
             category.Sort = db.Categories.Count(c => c.ParentID == parentId);
             db.Categories.InsertOnSubmit(category);
             db.SubmitChanges();
             ts.Complete();
         }
     }
 }
Beispiel #16
0
 public bool AddProdProp(string name, string value, Guid productId)
 {
     bool allRight = false;
     using (var db = new ShopDataContext())
     {
         BL.ProductProperty productProp = new BL.ProductProperty();
         productProp.ProductID = productId;
         productProp.PropertyID = Guid.NewGuid();
         productProp.IsImportant = true;
         productProp.PropertyName = name;
         productProp.PropertyValue = value;
         productProp.Sort = 0;
         db.ProductProperties.InsertOnSubmit(productProp);
         db.SubmitChanges();
         allRight = true;
     }
     return allRight;
 }
        public void UpdateProduct(Products product)
        {
            using (var db = new ShopDataContext())
            {
                var item = db.Products.FirstOrDefault(z => z.Id == product.Id);
                if (item != null)
                {
                    item.Price       = product.Price;
                    item.PublicKey   = product.PublicKey;
                    item.Title       = product.Title;
                    item.UpdateDate  = DateTime.Now;
                    item.CategoryId  = product.CategoryId;
                    item.Color       = item.Color;
                    item.Description = item.Description;

                    db.SubmitChanges();
                }
            }
        }
        public void SaveCartItems(DataGridView view, decimal discount, string salesid)
        {
            ShopDataContext dbs  = new ShopDataContext();
            int             row1 = view.CurrentRow.Index;

            for (int i = 0; i < view.Rows.Count; i++)
            {
                dbs.SalesDetails.InsertOnSubmit(
                    new SalesDetail
                {
                    Product  = Convert.ToString(view.Rows[i].Cells[0].Value),
                    SalesID  = salesid,
                    Discount = discount,
                    Price    = Convert.ToDecimal(view.Rows[i].Cells[2].Value),
                    Quantity = Convert.ToInt32(view.Rows[i].Cells[1].Value),
                });

                dbs.SubmitChanges();
            }
        }
Beispiel #19
0
 public bool AddProperties(Guid categoryId, string name, string value, int sort)
 {
     bool saveProperty = false;
     using (ShopDataContext db = new ShopDataContext())
     {
         BL.Category category = db.Categories.Where(c => c.CategoryID == categoryId).FirstOrDefault();
         if (categoryId != null)
         {
             BL.CategoryProperty cp = new BL.CategoryProperty();
             cp.CategoriesID = categoryId;
             cp.PropertName = name;
             cp.PropertyValue = value;
             cp.Sort = (sort == -1) ? 0 : sort;
             cp.CategoriesPropertyID = Guid.NewGuid();
             db.CategoryProperties.InsertOnSubmit(cp);
             db.SubmitChanges();
             saveProperty = true;
         }
     }
     return saveProperty;
 }
Beispiel #20
0
        public bool UpdateAllPropertiesByCategoryId(IQueryable<BL.CategoryProperty> properties, Guid categoryId)
        {
            bool updateProperties = false;

            using (ShopDataContext db = new ShopDataContext())
            {
                BL.Category category = db.Categories.Where(c => c.CategoryID == categoryId).FirstOrDefault();
                if (category != null)
                {
                    using (var ts = new TransactionScope())
                    {
                        db.CategoryProperties.AttachAll(properties);
                        db.Refresh(System.Data.Linq.RefreshMode.KeepCurrentValues, properties);
                        db.SubmitChanges();
                        ts.Complete();
                        updateProperties = true;
                    }
                }
            }
            return updateProperties;
        }
 private void BtnSubmit_Click(object sender, EventArgs e)
 {
     try
     {
         ShopDataContext db = new ShopDataContext();
         db.Suppliers.InsertOnSubmit(new Supplier
         {
             Name     = txtSupplier.Text,
             Product  = txtProdt.Text,
             Phone    = txtPhone.Text,
             Location = txtLocation.Text,
             CeatedBy = Settings.Default.Username,
             CeatedAt = DateTime.UtcNow
         });
         db.SubmitChanges();
         MessageBox.Show("Inserted Succesfully");
         Clear();
     }
     catch (Exception)
     {
         throw;
     }
 }
Beispiel #22
0
        public bool AddCategoryToProduct(Guid categoryId, Guid productId, ShopDataContext db)
        {
            bool addCategoryToProduct = false;

            BL.Category category = db.Categories.FirstOrDefault(c => c.CategoryID == categoryId);
            if (category != null)
            {
                BL.Product product = db.Products.FirstOrDefault(p => p.ProductID == productId);
                if (product != null)
                {
                    if (product.ProductsRefCategories.Any(c => c.CategoryID == category.CategoryID))
                        return false;
                    BL.ProductsRefCategory prc = new ProductsRefCategory();
                    prc.ID = Guid.NewGuid();
                    prc.CategoryID = categoryId;
                    prc.ProductID = productId;
                    prc.Sort = category.ProductsRefCategories.Count();
                    product.ProductsRefCategories.Add(prc);
                    db.SubmitChanges();
                    addCategoryToProduct = true;
                }
            }
            return addCategoryToProduct;
        }
Beispiel #23
0
        public void DeleteProduct(Guid prodID)
        {
            using (ShopDataContext db = new ShopDataContext())
            {
                var prod = db.Products.FirstOrDefault(p => p.ProductID == prodID);
                if (prod == null) return;

                db.ProductsRefCategories.DeleteAllOnSubmit(prod.ProductsRefCategories);
                db.OrdersRefProducts.DeleteAllOnSubmit(prod.OrdersRefProducts);
                db.ProductsRefProperies.DeleteAllOnSubmit(prod.ProductsRefProperies);
                db.ProductProperties.DeleteAllOnSubmit(prod.ProductProperties);
                db.Stocks.DeleteAllOnSubmit(prod.Stocks);
                db.Products.DeleteOnSubmit(prod);
                db.SubmitChanges();
            }
        }
Beispiel #24
0
 public bool DeleteCategoryFromProduct(Guid categoryId, Guid productId)
 {
     bool deleteCategoryFromProduct = false;
     using (ShopDataContext db = new ShopDataContext())
     {
         BL.ProductsRefCategory prc = db.ProductsRefCategories.Where(p => p.ProductID == productId && p.CategoryID == categoryId).FirstOrDefault();
         if (prc != null)
         {
             db.ProductsRefCategories.DeleteOnSubmit(prc);
             db.SubmitChanges();
         }
     }
     return deleteCategoryFromProduct;
 }
        private void ImportOBarcodes(XDocument o_Products, Connector connector)
        {
            using (ShopDataContext context = new ShopDataContext(connector.ConnectionString))
            {
                var ids = (from r in o_Products.Root.Elements("Product")
                           where !String.IsNullOrEmpty(r.Attribute("CustomProductID").Value)
                           select r.Attribute("CustomProductID").Value).Distinct().ToArray();

                var barcodes = (from b in context.ProductBarcodes
                                select b).ToList();

                Dictionary <int, ProductBarcode> existingBarcode = new Dictionary <int, ProductBarcode>();

                for (int i = barcodes.Count - 1; i >= 0; i--)
                {
                    ProductBarcode bar = barcodes[i];

                    var pr = (from p in o_Products.Root.Elements("Product")
                              where p.Attribute("CustomProductID").Value == bar.ProductID.ToString() &&
                              p.Elements("Barcodes").Where(x => x.Element("Barcode").Value.Trim() == bar.Barcode).Count() > 0
                              select p).FirstOrDefault();

                    if (pr == null)
                    {
                        log.InfoFormat("Delete productbarcode item {0} ({1})", bar.ProductID, bar.Barcode);

                        context.ProductBarcodes.DeleteOnSubmit(bar);
                        context.SubmitChanges();
                    }
                }

                barcodes = (from b in context.ProductBarcodes
                            select b).ToList();

                foreach (string id in ids)
                {
                    int prodid = 0;
                    if (!int.TryParse(id, out prodid))
                    {
                        log.InfoFormat("Could not process product {0}", id);
                        continue;
                    }

                    var stk = (from c in barcodes
                               where c.ProductID == prodid
                               select c).FirstOrDefault();

                    if (stk != null && !existingBarcode.ContainsKey(stk.ProductID))
                    {
                        existingBarcode.Add(stk.ProductID, stk);
                    }
                }

                List <ProductBarcode> barcodeList = new List <ProductBarcode>();

                foreach (var prod in o_Products.Root.Elements("Product"))
                {
                    try
                    {
                        int prodid = 0;
                        if (!int.TryParse(prod.Attribute("CustomProductID").Value, out prodid))
                        {
                            log.InfoFormat("Could not process product {0}", prod.Attribute("CustomProductID").Value);
                            continue;
                        }

                        foreach (var bar in prod.Elements("Barcodes"))
                        {
                            if (bar.Element("Barcode") != null && !string.IsNullOrEmpty(bar.Element("Barcode").Value))
                            {
                                string barcodecode = bar.Element("Barcode").Value.Trim();
                                string barcodetype;
                                switch (barcodecode.Length)
                                {
                                case 8:
                                    barcodetype = "Ean8";
                                    break;

                                case 12:
                                    barcodetype = "UpcA";
                                    break;

                                case 13:
                                    barcodetype = "Ean13";
                                    break;

                                default:
                                    barcodetype = "Ean13";
                                    break;
                                }

                                ProductBarcode barcode = null;
                                if (existingBarcode.ContainsKey(int.Parse(prod.Attribute("CustomProductID").Value)))
                                {
                                    int custom = int.Parse(prod.Attribute("CustomProductID").Value);
                                    if (existingBarcode[custom].Barcode.Trim() != barcodecode ||
                                        existingBarcode[custom].BarcodeType.Trim() != barcodetype)
                                    {
                                        barcode = existingBarcode[custom];
                                        context.ProductBarcodes.DeleteOnSubmit(barcode);
                                        context.SubmitChanges();

                                        if (barcodeList.Where(x => x.Barcode.Trim() == barcodecode).Count() < 1 &&
                                            barcodes.Where(x => x.Barcode.Trim() == barcodecode).Count() < 1)
                                        {
                                            barcode = ShopUtility.InsertBarcode(int.Parse(prod.Attribute("CustomProductID").Value), barcodecode, barcodetype);
                                            context.ProductBarcodes.InsertOnSubmit(barcode);
                                            barcodeList.Add(barcode);
                                        }
                                    }
                                }
                                else
                                {
                                    if (barcodeList.Where(x => x.Barcode.Trim() == barcodecode).Count() < 1 &&
                                        barcodes.Where(x => x.Barcode.Trim() == barcodecode).Count() < 1)
                                    {
                                        barcode = ShopUtility.InsertBarcode(int.Parse(prod.Attribute("CustomProductID").Value), barcodecode, barcodetype);
                                        context.ProductBarcodes.InsertOnSubmit(barcode);
                                        context.SubmitChanges();
                                        barcodeList.Add(barcode);
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        log.Error("Error import barcode", ex);
                    }
                }
                context.SubmitChanges();
            }
        }
        private void ImportOItems(XDocument o_Products, Connector connector, decimal unitprice, decimal costprice)
        {
            try
            {
                using (ShopDataContext context = new ShopDataContext(connector.ConnectionString))
                {
                    var ids = (from r in o_Products.Root.Elements("Product")
                               select r.Attribute("CustomProductID").Value).Distinct().ToArray();

                    var productList = (from p in context.Products
                                       select p).ToList();

                    Dictionary <int, Product> existingProducts = new Dictionary <int, Product>();

                    foreach (string id in ids)
                    {
                        int prodid = 0;
                        if (!int.TryParse(id, out prodid))
                        {
                            log.InfoFormat("Could not process product {0}", id);
                            continue;
                        }

                        var pr = (from c in productList
                                  where c.ProductID == prodid
                                  select c).SingleOrDefault();

                        if (pr != null && !existingProducts.ContainsKey(pr.ProductID))
                        {
                            existingProducts.Add(pr.ProductID, pr);
                        }
                    }

                    var brands = (from b in context.Brands
                                  select b).ToDictionary(x => x.BrandCode.Trim(), x => x);

                    var productgroups = (from p in context.ProductGroups
                                         select p).ToList();

                    List <int> addedcustomOItemNumbers = new List <int>();

                    foreach (var r in o_Products.Root.Elements("Product"))
                    {
                        Product product          = null;
                        string  shortDescription = r.Element("Content").Attribute("ShortDescription").Value;
                        string  longDescription  = r.Element("Content").Attribute("LongDescription").Value;

                        int customproductID = -1;
                        if (int.TryParse(r.Attribute("CustomProductID").Value, out customproductID))
                        {
                            try
                            {
                                if (!addedcustomOItemNumbers.Contains(customproductID))
                                {
                                    int?taxRateID = (from t in context.TaxRates
                                                     where t.TaxRate1.HasValue &&
                                                     (t.TaxRate1.Value * 100) == decimal.Parse(r.Element("Price").Attribute("TaxRate").Value, CultureInfo.InvariantCulture)
                                                     select t.TaxRateID).SingleOrDefault();

                                    if (!taxRateID.HasValue)
                                    {
                                        taxRateID = 1;
                                    }


                                    int?productgroupid = (from p in productgroups
                                                          where p.ProductGroupCode == "n.v.t."
                                                          select p.ProductGroupID).FirstOrDefault();


                                    int brandID = 0;

                                    if (!brands.ContainsKey(r.Attribute("BrandCode").Value.Trim()))
                                    {
                                        Brand br = new Brand
                                        {
                                            BrandCode            = r.Attribute("BrandCode").Value.Trim(),
                                            BrandName            = r.Attribute("BrandCode").Value.Trim(),
                                            CreatedBy            = 0,
                                            CreationTime         = DateTime.Now,
                                            LastModifiedBy       = 0,
                                            LastModificationTime = DateTime.Now
                                        };
                                        context.Brands.InsertOnSubmit(br);
                                        context.SubmitChanges();
                                        brandID = br.BrandID;
                                        brands  = (from b in context.Brands
                                                   select b).ToDictionary(x => x.BrandCode.Trim(), x => x);
                                    }
                                    else
                                    {
                                        brandID = brands[r.Attribute("BrandCode").Value.Trim()].BrandID;
                                    }

                                    if (connector.ConcatenateBrandName && brandID > 0)
                                    {
                                        StringBuilder sb = new StringBuilder();
                                        sb.Append(brands[r.Attribute("BrandCode").Value.Trim()].BrandName);
                                        sb.Append(" ");
                                        sb.Append(shortDescription);
                                        shortDescription = sb.ToString();
                                    }

                                    if (productgroupid.Value == 0)
                                    {
                                        //int? parentProductGroupID = (from p in productgroups
                                        //                             where p.BackendProductGroupCode == r.Attribute("ProductGroupID").Value
                                        //                             select p.ParentProductGroupID).FirstOrDefault();

                                        //if (!parentProductGroupID.HasValue && parentProductGroupID.Value > 0)
                                        //{
                                        int?parentProductGroupID = (from p in productgroups
                                                                    where p.ProductGroupName == "Missing category"
                                                                    select p.ProductGroupID).FirstOrDefault();

                                        if (parentProductGroupID.Value == 0)
                                        {
                                            ProductGroup ppg = new ProductGroup
                                            {
                                                ProductGroupCode        = "n.v.t.",
                                                BackendProductGroupCode = "n.v.t.",
                                                ProductGroupName        = "Missing category",
                                                CreationTime            = DateTime.Now,
                                                LastModificationTime    = DateTime.Now
                                            };
                                            context.ProductGroups.InsertOnSubmit(ppg);
                                            context.SubmitChanges();
                                            parentProductGroupID = ppg.ProductGroupID;
                                            productgroups        = (from p in context.ProductGroups
                                                                    select p).ToList();
                                        }
                                        //}

                                        ProductGroup pg = new ProductGroup
                                        {
                                            ProductGroupCode        = r.Attribute("ProductGroupID").Value,
                                            BackendProductGroupCode = r.Attribute("ProductSubGroup").Value,
                                            ParentProductGroupID    = parentProductGroupID.Value,
                                            ProductGroupName        = r.Attribute("ProductGroupName").Value,
                                            CreationTime            = DateTime.Now,
                                            LastModificationTime    = DateTime.Now
                                        };
                                        context.ProductGroups.InsertOnSubmit(pg);
                                        context.SubmitChanges();
                                        productgroupid = pg.ProductGroupID;
                                        productgroups  = (from p in context.ProductGroups
                                                          select p).ToList();
                                    }

                                    bool extended = false;
                                    bool.TryParse(r.Element("ShopInformation").Element("ExtendedCatalog").Value, out extended);

                                    if (existingProducts.ContainsKey(customproductID))
                                    {
                                        continue;
                                        // product = existingProducts[int.Parse(r.Attribute("CustomProductID").Value)];
                                        //if (!product.IsVisible)
                                        //{

                                        //if (
                                        //  existingProducts[customproductID].ShortDescription.Trim() != shortDescription.Trim()
                                        //  || existingProducts[customproductID].LongDescription.Trim() != longDescription.Trim()
                                        //  || existingProducts[customproductID].UnitPrice != decimal.Parse(r.Element("Price").Element("UnitPrice").Value, CultureInfo.InvariantCulture)
                                        //  || existingProducts[customproductID].ProductStatus != r.Attribute("CommercialStatus").Value
                                        //  || existingProducts[customproductID].ManufacturerID != r.Attribute("ManufacturerID").Value
                                        //  || existingProducts[customproductID].IsVisible != false
                                        //  || existingProducts[customproductID].BrandID != brandID
                                        //  || existingProducts[customproductID].TaxRateID != taxRateID.Value
                                        //  || existingProducts[customproductID].LineType != r.Attribute("LineType").Value.Trim()
                                        //  //|| existingProducts[customproductID].ProductGroupID != productgroupid.Value
                                        //  || existingProducts[customproductID].LedgerClass != r.Element("ShopInformation").Element("LedgerClass").Value.Trim()
                                        //  || existingProducts[customproductID].ProductDesk != r.Element("ShopInformation").Element("ProductDesk").Value
                                        //  || existingProducts[customproductID].ExtendedCatalog != extended
                                        //  || existingProducts[customproductID].UnitCost != decimal.Parse(r.Element("Price").Element("CostPrice").Value, CultureInfo.InvariantCulture))
                                        //{
                                        //  product.ShortDescription = shortDescription.Trim();
                                        //  product.LongDescription = longDescription.Trim();
                                        //  product.BrandID = brandID;
                                        //  product.UnitPrice = decimal.Parse(r.Element("Price").Element("UnitPrice").Value, CultureInfo.InvariantCulture);
                                        //  product.ManufacturerID = r.Attribute("ManufacturerID").Value;
                                        //  product.ProductStatus = r.Attribute("CommercialStatus").Value;
                                        //  product.LastModificationTime = DateTime.Now;
                                        //  product.IsVisible = false;
                                        //  product.TaxRateID = taxRateID.Value;
                                        //  product.LineType = r.Attribute("LineType").Value.Trim();
                                        //  //product.ProductGroupID = productgroupid.Value;
                                        //  product.LedgerClass = r.Element("ShopInformation").Element("LedgerClass").Value.Trim();
                                        //  product.ProductDesk = r.Element("ShopInformation").Element("ProductDesk").Value;
                                        //  product.ExtendedCatalog = extended;
                                        //  product.UnitCost = decimal.Parse(r.Element("Price").Element("CostPrice").Value, CultureInfo.InvariantCulture);

                                        //  log.InfoFormat("updateproduct {0}", customproductID);
                                        // }
                                        //}
                                    }
                                    else
                                    {
                                        product = new Product
                                        {
                                            ProductID            = int.Parse(r.Attribute("CustomProductID").Value),
                                            ProductGroupID       = productgroupid.Value,
                                            ShortDescription     = shortDescription.Trim(),
                                            LongDescription      = longDescription.Trim(),
                                            ManufacturerID       = r.Attribute("ManufacturerID").Value,
                                            BrandID              = brandID,
                                            TaxRateID            = taxRateID.Value,
                                            UnitPrice            = unitprice,
                                            UnitCost             = costprice,
                                            IsCustom             = false,
                                            LineType             = r.Attribute("LineType").Value.Trim(),
                                            ProductStatus        = r.Attribute("CommercialStatus").Value,
                                            IsVisible            = false,
                                            CreationTime         = DateTime.Now,
                                            LastModificationTime = DateTime.Now,
                                            LedgerClass          = r.Element("ShopInformation").Element("LedgerClass").Value.Trim(),
                                            ProductDesk          = r.Element("ShopInformation").Element("ProductDesk").Value,
                                            ExtendedCatalog      = extended
                                        };

                                        context.Products.InsertOnSubmit(product);
                                        log.InfoFormat("addedproduct {0}", customproductID);
                                        //}
                                        //else
                                        //{
                                        //  if (!string.IsNullOrEmpty(r.Attribute("BrandCode").Value))
                                        //  {
                                        //    log.DebugFormat("Insert product failed, brand {0} not availible", r.Attribute("BrandCode").Value.Trim());
                                        //  }
                                        //  else
                                        //    log.Debug("Insert product failed");
                                        //}
                                        try
                                        {
                                            foreach (var bar in r.Elements("Barcodes").Elements("Barcode"))
                                            {
                                                if (!string.IsNullOrEmpty(bar.Value))
                                                {
                                                    string barcodecode = bar.Value.Trim();
                                                    string barcodetype;
                                                    switch (barcodecode.Length)
                                                    {
                                                    case 8:
                                                        barcodetype = "Ean8";
                                                        break;

                                                    case 12:
                                                        barcodetype = "UpcA";
                                                        break;

                                                    case 13:
                                                        barcodetype = "Ean13";
                                                        break;

                                                    default:
                                                        barcodetype = "Ean13";
                                                        break;
                                                    }

                                                    if (!context.ProductBarcodes.Any(x => x.Barcode == barcodecode && x.BarcodeType == barcodetype))
                                                    {
                                                        ProductBarcode barcode = ShopUtility.InsertBarcode(int.Parse(r.Attribute("CustomProductID").Value), barcodecode, barcodetype);
                                                        context.ProductBarcodes.InsertOnSubmit(barcode);
                                                        context.SubmitChanges();
                                                    }
                                                }
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            log.Error("Error insert Third party Barcode for product " + r.Attribute("CustomProductID").Value, ex);
                                        }
                                    }
                                    addedcustomOItemNumbers.Add(customproductID);

                                    context.SubmitChanges();
                                }
                            }
                            catch (Exception ex)
                            {
                                log.Error("Error processing product" + customproductID, ex);
                                throw ex;
                            }
                        }
                        else
                        {
                            log.InfoFormat("Import failed for product {0}", r.Attribute("CustomProductID").Value);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("Error import O products", ex);
                throw ex;
            }
        }
Beispiel #27
0
        public int DeleteCategoryByIdWithErrorMessage(Guid id)
        {
            if (CategoryHasChild(id))
            {
                return (int)DeleteErrors.HasChilds;
            }
            if (CategoryHasProducts(id))
            {
                return (int)DeleteErrors.HasProducts;
            }

            ShopDataContext db = new ShopDataContext();
            BL.Category category = db.Categories.Where(c => c.CategoryID == id).FirstOrDefault();
            if (category == null)
            {
                return (int)DeleteErrors.Invalid;
            }

            db.Categories.DeleteOnSubmit(category);
            db.SubmitChanges();
            return (int)DeleteErrors.Success;
        }
Beispiel #28
0
 public void UpdateProductsRefCategoriesSort(List<Guid> prodIds)
 {
     using (var db = new ShopDataContext())
     {
         using (var ts = new TransactionScope())
         {
             var index = 0;
             foreach (var item in prodIds)
             {
                 var categ = db.ProductsRefCategories.First(c => c.ID == item);
                 categ.Sort = index;
                 index++;
             }
             db.SubmitChanges();
             ts.Complete();
         }
     }
 }
Beispiel #29
0
 public void UpdateCategoryName(Guid categoryId, string name)
 {
     using (var db = new ShopDataContext())
     {
         BL.Category category = db.Categories.Where(c => c.CategoryID == categoryId).FirstOrDefault();
         if (category != null)
         {
             category.Name = name;
             db.SubmitChanges();
         }
         db.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues);
     }
 }
Beispiel #30
0
        public void UpdateCategory(Guid categoryId, string name, Guid? parentId)
        {
            using (ShopDataContext db = new ShopDataContext())
            {
                BL.Category category = db.Categories.Where(c => c.CategoryID == categoryId).FirstOrDefault();
                if (category != null)
                {
                    using (var ts = new TransactionScope())
                    {
                        category.Name = name;
                        category.ParentID = parentId;
                        db.SubmitChanges();
                        ts.Complete();
                        db.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues);
                    }
                }

            }
        }
Beispiel #31
0
        public void UpdateAllCategories(List<Guid> categories)
        {
            using (var db = new ShopDataContext())
            {

                using (var ts = new TransactionScope())
                {
                    var index = 0;
                    foreach (var item in categories)
                    {
                        var categ = db.Categories.First(c => c.CategoryID == item);
                        categ.Sort = index;
                        index++;
                    }
                    db.SubmitChanges();
                    db.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues);
                    ts.Complete();
                }
            }
        }
Beispiel #32
0
        private void SaveProducts(DataGridView view)
        {
            string  code;
            string  productname;
            string  productunit;
            string  category;
            decimal costprice;
            decimal retailprice;
            string  supplier;
            string  description;


            for (int i = 0; i < view.Rows.Count; i++)
            {
                code        = Convert.ToString(view.Rows[i].Cells[0].Value);
                productname = Convert.ToString(view.Rows[i].Cells[1].Value);
                productunit = Convert.ToString(view.Rows[i].Cells[2].Value);
                category    = Convert.ToString(view.Rows[i].Cells[3].Value);
                costprice   = Convert.ToDecimal(view.Rows[i].Cells[4].Value);
                retailprice = Convert.ToDecimal(view.Rows[i].Cells[5].Value);
                supplier    = Convert.ToString(view.Rows[i].Cells[6].Value);
                description = Convert.ToString(view.Rows[i].Cells[7].Value);



                // batchAddGridView.Rows.RemoveAt(batchAddGridView.CurrentCell.RowIndex);
                ShopDataContext db = new ShopDataContext();
                db.Products.InsertOnSubmit(new Product
                {
                    ProductCode = code,
                    ProductName = productname,
                    ProductUnit = productunit,
                    Category    = category,
                    CostPrice   = costprice,
                    RetailPrice = retailprice,
                    Supplier    = supplier,
                    Description = description,
                    CreatedDate = DateTime.UtcNow
                });
                db.SubmitChanges();


                MessageBox.Show("Added,Reopen if you want to add new products");

                batchAddGridView.AllowUserToAddRows = false;

                //else
                //{
                //    // batchAddGridView.Rows.RemoveAt(batchAddGridView.CurrentCell.RowIndex);
                //    ShopDataContext db = new ShopDataContext();
                //    db.Products.InsertOnSubmit(new Product
                //    {
                //        ProductCode = code,
                //        ProductName = productname,
                //        ProductUnit = productunit,
                //        Category = category,
                //        CostPrice = costprice,
                //        RetailPrice = retailprice,
                //        Supplier = supplier,
                //        Description = description,
                //        CreatedDate = DateTime.UtcNow

                //    });
                //    db.SubmitChanges();


                //    MessageBox.Show("Added");
                //    batchAddGridView.AllowUserToAddRows = false;
                //}
            }
        }
Beispiel #33
0
 public bool AddCustomer(int ID, string Name)
 {
     if (GetCustomer(ID) == null && !Name.Equals(null))
     {
         Customers NewReader = new Customers
         {
             name = Name,
             id   = ID
         };
         context.Customers.InsertOnSubmit(NewReader);
         context.SubmitChanges();
         return(true);
     }
     return(false);
 }
        private void ImportStock(Connector connector, XDocument products, log4net.ILog log)
        {
            try
            {
                using (ShopDataContext context = new ShopDataContext(connector.ConnectionString))
                {
                    //var ids = (from r in products.Root.Elements("Product")
                    //select int.Parse(r.Attribute("CustomProductID").Value)).Distinct().ToArray();

                    //Dictionary<int, List<VendorStock>> existingStock = new Dictionary<int, List<VendorStock>>();

                    //foreach (int id in ids)
                    //{
                    //  var stk = (from c in context.VendorStocks
                    //             where c.ProductID == id
                    //             select c).ToList();

                    //  if (stk.Count() > 0)
                    //  {
                    //    if (!existingStock.ContainsKey(stk.First().ProductID))
                    //      existingStock.Add(stk.First().ProductID, stk);
                    //    else
                    //    {
                    //      foreach (VendorStock vs in stk)
                    //      {
                    //        if (!existingStock[stk.First().ProductID].Contains(vs))
                    //          existingStock[stk.First().ProductID].Add(vs);
                    //      }
                    //    }
                    //  }
                    //}

                    //List<int> addedstock = new List<int>();

                    context.VendorStocks.DeleteAllOnSubmit(context.VendorStocks.Where(x => x.RelationID == BASrelationID));


                    var records = (from r in products.Root.Elements("Product")
                                   where !String.IsNullOrEmpty(r.Attribute("CustomProductID").Value)
                                   select r);

                    var groupedByProduct = (from r in records
                                            group r by r.Attribute("CustomProductID").Value
                                            into grouped
                                            select grouped
                                            );

                    foreach (var r in groupedByProduct)
                    {
                        var product = r;
                        int custom  = int.Parse(product.Key);

                        var stock = new VendorStock();
                        stock.CreationTime         = DateTime.Now;
                        stock.LastModificationTime = DateTime.Now;
                        stock.CreatedBy            = 0;
                        stock.LastModifiedBy       = 0;
                        stock.ProductID            = custom;
                        stock.RelationID           = BASrelationID;
                        stock.VendorProductStatus  = "S";
                        stock.StockLocationID      = BASLocation;

                        int qty = product.Sum(x => int.Parse(x.Element("Stock").Attribute("InStock").Value));
                        stock.QuantityOnHand = qty;
                        context.VendorStocks.InsertOnSubmit(stock);
                    }
                    context.SubmitChanges();
                }
            }
            catch (Exception ex)
            {
                log.Error("Error import stock", ex);
                log.Debug(ex.InnerException);
            }
        }
Beispiel #35
0
        private void UpdateNews(int id,string title,string desc,string body)
        {
            using (var db = new ShopDataContext())
            {
                BL.News news = db.News.Where(n => n.NewsID == id).FirstOrDefault();
                if (news != null)
                {

                    using (var ts = new TransactionScope())
                    {
                        news.NewsBody = body;
                        news.NewsDescription = desc;
                        news.NewsTitle = title;
                        db.SubmitChanges();
                        ts.Complete();
                    }
                }
            }
        }
Beispiel #36
0
        public void DeleteProductCategories(Guid productID)
        {
            BL.Product poducts = new BL.Product();

            BL.ShopDataContext ctx = new ShopDataContext();
            var refs = ctx.ProductsRefCategories.Where(r => r.ProductID == productID);

            foreach (var item in refs)
            {
                var catRef = item.Category.ProductsRefCategories.Where(s => s.Sort > item.Sort);
                foreach (var refs1 in catRef)
                {
                    refs1.Sort--;
                }
            }

            ctx.ProductsRefCategories.DeleteAllOnSubmit(refs);
            ctx.SubmitChanges();
        }
Beispiel #37
0
        public bool UpdateProduct(Guid productId, string name, string unit, decimal price, bool isVisible, int count, decimal tax, decimal shipping)
        {
            bool updateProduct = false;

            using (ShopDataContext db = new ShopDataContext())
            {
                BL.Product product = db.Products.FirstOrDefault(p => p.ProductID == productId);
                if (product.Name != name && db.Products.Count(p => p.Name == name) == 1)
                    return false;
                if (product != null)
                {
                    using (var ts = new TransactionScope())
                    {
                        product.Name = name;
                        product.Unit = unit;
                        product.Price = price;
                        product.IsVisible = isVisible;
                        product.InStock = (count > 0);
                        product.Count = count;
                        product.Tax = tax;
                        product.Shipping = shipping;
                        updateProduct = true;
                        db.SubmitChanges();
                        ts.Complete();
                    }
                }
            }
            return updateProduct;
        }
Beispiel #38
0
        public void ProcessRequest(HttpContext context)
        {
            Response = context.Response;
            Request  = context.Request;
            RetURL   = Request.QueryString["ReturnUrl"];
            Guid?  productID   = Request.QueryString["OID"].ToNullableGuid();
            string Comments    = HttpUtility.UrlDecode(Request.QueryString["COM"]);
            int?   quantiyty   = null;
            Guid   currentUser = Request.IsAuthenticated ? UserDataContext.GetUserDataContext().UserID : UserDataContext.GetUserDataContext().AnonymousUserId;

            if (!string.IsNullOrEmpty(Request.QueryString["QTY"]))
            {
                quantiyty = Convert.ToInt32(Request.QueryString["QTY"]);
            }
            int addQuantity = 1;

            if (!string.IsNullOrEmpty(Request.QueryString["AQTY"]))
            {
                addQuantity = Convert.ToInt32(Request.QueryString["AQTY"]);
            }

            bool AddToCartOnlyAuthenticated = Convert.ToBoolean(ShopSection.CachedInstance.ShopSettings["AddToCartOnlyAuthenticated"]);

            if (AddToCartOnlyAuthenticated && !Request.IsAuthenticated)
            {
                //go to the LoginPage

                string LoginURL = string.Format("/Pages/Other/Login.aspx?ReturnUrl={0}", context.Server.UrlEncode(Request.RawUrl));
                Response.Redirect(LoginURL);
            }

            //DELETE ALL ACTIVE CARTS FORM THE USER; THAT ARE NOT IN THE TIMERANGE
            ShopDataContext             csb         = new ShopDataContext();
            hitbl_ShoppingCart_Cart_SHO currentCart = null;
            var activeCart = from allCarts in csb.hitbl_ShoppingCart_Cart_SHOs.Where(x => x.SHO_CARTSTATUS == 0 && x.SHO_USERID == currentUser)
                             select allCarts;

            foreach (var cart in activeCart)
            {
                if (cart.SHO_DATEADDED.AddMinutes(Convert.ToDouble(ShopSection.CachedInstance.ShopSettings["CartActiveRangeMinutes"])) < DateTime.Now)
                {
                    csb.hitbl_ShoppingCart_Cart_SHOs.DeleteOnSubmit(cart);
                }
            }
            csb.SubmitChanges();
            currentCart = activeCart.SingleOrDefault();
            if (currentCart == null)
            {
                currentCart = new hitbl_ShoppingCart_Cart_SHO();
                currentCart.SHO_CARTSTATUS = 0;
                currentCart.SHO_DATEADDED  = DateTime.Now;
                currentCart.SHO_CARTID     = Guid.NewGuid();
                currentCart.SHO_USERID     = currentUser;
                currentCart.SHO_TAXES      = Convert.ToDouble(ShopSection.CachedInstance.ShopSettings["TaxesPercent"]);
                //currentCart.SHO_TRANSPORT = Convert.ToDouble(ShopSection.CachedInstance.ShopSettings["TransportCosts"]);
                csb.hitbl_ShoppingCart_Cart_SHOs.InsertOnSubmit(currentCart);
            }
            //Check if an Item allready exists, in that case add the addQuantity
            //else add a new Item with the addQuantity
            hitbl_ShoppingCart_Items_ITE currItem;

            if (productID.HasValue)
            {
                currItem = (from items in currentCart.hitbl_ShoppingCart_Items_ITEs.Where(x => x.OBJ_ID == productID.Value)
                            select items).SingleOrDefault();
                if (currItem == null)
                {
                    if (addQuantity <= 0 || (quantiyty.HasValue && quantiyty.Value < 0))
                    {
                        return;
                    }
                    DataObjectProduct doProduct = DataObject.Load <DataObjectProduct>(productID);
                    if (doProduct != null)
                    {
                        currItem              = new hitbl_ShoppingCart_Items_ITE();
                        currItem.ITE_ITEM_ID  = Guid.NewGuid();
                        currItem.ITE_QUANTITY = quantiyty.HasValue ? quantiyty.Value : addQuantity;
                        currItem.ITE_REFNR    = doProduct.ProductRef;
                        currItem.ITE_TEXT     = doProduct.Description;
                        currItem.ITE_TITEL    = doProduct.Title;
                        currItem.ITE_PRICE1   = doProduct.Price1;
                        currItem.ITE_PRICE2   = doProduct.Price2;
                        currItem.ITE_PRICE3   = doProduct.Price3;
                        currItem.ITE_Porto    = doProduct.Porto;
                        currItem.OBJ_ID       = productID.Value;
                        if (!string.IsNullOrEmpty(Comments))
                        {
                            currItem.ITE_COMENT = Comments.CropString(256);
                        }
                        currentCart.hitbl_ShoppingCart_Items_ITEs.Add(currItem);
                    }
                }
                else
                {
                    currItem.ITE_QUANTITY = quantiyty.HasValue ? quantiyty.Value : currItem.ITE_QUANTITY + addQuantity;
                    if (!string.IsNullOrEmpty(Comments))
                    {
                        currItem.ITE_COMENT = Comments.CropString(256);
                    }
                    if (currItem.ITE_QUANTITY <= 0)
                    {
                        currentCart.hitbl_ShoppingCart_Items_ITEs.Remove(currItem);
                    }
                }
                currentCart.SHO_DATEADDED = DateTime.Now; //Keep the Cart Time alive!
                csb.SubmitChanges();
            }

            Response.Redirect(RetURL);
        }
Beispiel #39
0
        public void CopyProperties(Guid fromID, Guid toID)
        {
            using (ShopDataContext db = new ShopDataContext())
            {
                var fromProd = db.Products.First(p => p.ProductID == fromID);
                var toProd = db.Products.First(p => p.ProductID == toID);

                List<BL.ProductProperty> newProps = new List<BL.ProductProperty>();
                List<BL.ProductsRefProperty> newRefs = new List<ProductsRefProperty>();

                foreach (var item in fromProd.ProductProperties.Where(p =>
                        p.PropertyName != ProductPropertyConstants.ProductPhotoPreview
                        && p.PropertyName != ProductPropertyConstants.ProductPhotoOriginal
                        && p.PropertyName != ProductPropertyConstants.ProductDescription
                        && p.PropertyName != ProductPropertyConstants.ProductPhotoOriginal2
                        && p.PropertyName != ProductPropertyConstants.ProductPhotoOriginal3).OrderBy(pp => pp.Sort))
                {
                    var newProp = new ProductProperty()
                    {
                        IsImportant = item.IsImportant,
                        PropertyID = Guid.NewGuid(),
                        PropertyName = item.PropertyName,
                        PropertyValue = item.PropertyValue,
                        Sort = newProps.Count
                    };
                    newProps.Add(newProp);
                    newRefs.Add(new ProductsRefProperty()
                    {
                        ID = Guid.NewGuid(),
                        ProductPropertiesID = newProp.PropertyID,
                        Sort = newRefs.Count
                    });
                }
                toProd.ProductProperties.AddRange(newProps);
                toProd.ProductsRefProperies.AddRange(newRefs);

                db.SubmitChanges();
            }
        }
Beispiel #40
0
 private void AddNews(string title, string desc, string body)
 {
     using (var db = new ShopDataContext())
     {
         BL.News news = new BL.News();
         using (var ts = new TransactionScope())
         {
             news.NewsTitle = title;
             news.NewsDescription = desc;
             news.NewsBody = body;
             news.CreateDate = DateTime.Now;
             news.IsActive = false;
             db.News.InsertOnSubmit(news);
             db.SubmitChanges();
             ts.Complete();
         }
     }
 }