Esempio n. 1
0
        public IExternStorage CreateExternStorage(string name, string companyName, string street, string number, string zipCode, string city, string companyId, string taxId)
        {
            GetLock();
            Storage storage;

            using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext())
            {
                storage             = new Storage();
                storage.Id          = ObjectId.NewId();
                storage.Name        = name;
                storage.IsExtern    = true;
                storage.CompanyName = companyName;
                storage.Street      = street ?? String.Empty;
                storage.Number      = number;
                storage.ZipCode     = zipCode;
                storage.City        = city;
                storage.CompanyId   = companyId ?? String.Empty;
                storage.TaxId       = taxId ?? String.Empty;

                dataContext.Storages.Add(storage);
                dataContext.SaveChanges();
            }

            ExternStorage externStorage = new ExternStorage(new ExternStorageDataProxy(this, storage.Id));

            _externStorages.Add(externStorage);
            return(externStorage);
        }
Esempio n. 2
0
        public void RefreshProductOrdersPriorities(int oldPriority, int newPriority, ObjectId changedOrderId)
        {
            int value = 1;

            if (newPriority > oldPriority)
            {
                value = -1;
            }

            int min = Math.Min(oldPriority, newPriority);
            int max = Math.Max(oldPriority, newPriority);

            using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext())
            {
                foreach (ProductArticleOrder order in dataContext.ProductArticleOrders.Where(o => o.Priority >= min && o.Priority <= max))
                {
                    if (order.Id != (Guid)changedOrderId)
                    {
                        order.Priority += value;
                    }
                }

                dataContext.SaveChanges();
            }
        }
Esempio n. 3
0
        public void SetStorageMappingAsync(ObjectId productId, ObjectId storageId, Action reloadAction)
        {
            Task.Factory.StartNew(() =>
            {
                GetLock();

                _longOperationHandler.Start("SettingStorageOperation");
                Guid articleId = productId;

                using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext())
                {
                    ProductArticle productArticle = dataContext.ProductArticles.FirstOrDefault(pa => pa.ArticleId == articleId);
                    if (productArticle == null)
                    {
                        throw new ProductArticleNotFoundException(GetType(), productId);
                    }
                    foreach (
                        ProductArticleItem item in
                        productArticle.ProductArticleItems.Where(
                            i => i.Article.Type == (int)ArticleType.Card && !i.SkipCalculation))
                    {
                        item.StorageId = storageId;
                    }
                    dataContext.SaveChanges();
                }

                _longOperationHandler.End(new LongOperationResult
                {
                    CustomAction = reloadAction
                });
            });
        }
Esempio n. 4
0
        private void ChangeValue(Action <ProductArticleOrder> changeAction)
        {
            DataChange.GetLock();

            using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext())
            {
                Guid id = OrderId;
                ProductArticleOrder order = dataContext.ProductArticleOrders.Find(id);

                changeAction(order);
                dataContext.SaveChanges();
            }
        }
Esempio n. 5
0
        private void ChangeValue(Action <ProductArticleItem> changeAction)
        {
            DataChange.GetLock();

            using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext())
            {
                Guid id = ArticleItemId;
                ProductArticleItem articleItem = dataContext.ProductArticleItems.Find(id);

                changeAction(articleItem);

                dataContext.SaveChanges();
            }
        }
Esempio n. 6
0
        public bool RemoveExternStorage(IExternStorage externStorage)
        {
            Guid storageId = externStorage.StorageId;

            using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext())
            {
                Storage storage = dataContext.Storages.FirstOrDefault(es => es.Id == storageId);
                if (storage != null)
                {
                    dataContext.Storages.Remove(storage);
                    _externStorages.Remove(externStorage);
                    dataContext.SaveChanges();
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 7
0
        internal void Save()
        {
            using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext())
            {
                dataContext.SetStringConstant("DN_Parlor", Parlor);
                dataContext.SetStringConstant("DN_Street", Street);
                dataContext.SetStringConstant("DN_Number", Number);
                dataContext.SetStringConstant("DN_Zip", ZipCode);
                dataContext.SetStringConstant("DN_City", City);
                dataContext.SetStringConstant("DN_Phone", Phone);
                dataContext.SetStringConstant("DN_CellPhone", CellPhone);
                dataContext.SetStringConstant("DN_Email", Email);
                dataContext.SetStringConstant("DN_Web", Web);

                dataContext.SaveChanges();
            }
        }
Esempio n. 8
0
        public void IndexDatabase(bool filePrepared)
        {
            AccountingDataSync globalDataSync = ProcessAccountingData(filePrepared, false);

            using (StoreKeeperDataContext context = new StoreKeeperDataContext())
            {
                SqlParameter userIdParam = new SqlParameter("@UserId", new Guid("F2024637-2251-479A-8ED9-940E4354F37B"));
                SqlParameter unlockParam = new SqlParameter("@Unlock", SqlDbType.Bit)
                {
                    Value = 0
                };
                context.Database.ExecuteSqlCommand("exec LockDatabase @UserId, @Unlock", userIdParam, unlockParam);

                context.SaveLoadedData(globalDataSync);
                context.LastUpdate      = DateTime.Now;
                context.ResponsibleUser = "******";
                context.SaveChanges();
            }
        }
        internal void Save()
        {
            DataChange.GetLock();

            using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext())
            {
                Guid    id      = StorageId;
                Storage storage = dataContext.Storages.Find(id);

                storage.Name        = Name;
                storage.Prefix      = id != Constants.CentralStorageId ? Prefix : null;
                storage.IsExtern    = IsExtern;
                storage.CompanyName = CompanyName;
                storage.Street      = Street;
                storage.Number      = Number;
                storage.ZipCode     = ZipCode;
                storage.City        = City;
                storage.CompanyId   = CompanyId;
                storage.TaxId       = TaxId;

                dataContext.SaveChanges();
            }
        }
Esempio n. 10
0
        public IProductOrder CreateProductOrder(string code, double count = 0)
        {
            GetLock();
            ProductArticleOrder order;

            using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext())
            {
                Article article = dataContext.Articles.FirstOrDefault(a => a.Code.ToUpper() == code.ToUpper());
                if (article == null || (article.ArticleType != ArticleType.Product))
                {
                    throw new ProductArticleNotFoundException(GetType(), code);
                }

                ProductArticle productArticle =
                    dataContext.ProductArticles.FirstOrDefault(pa => pa.ArticleId == article.Id);
                if (productArticle == null)
                {
                    throw new ProductArticleNotFoundException(GetType(), code);
                }

                order    = new ProductArticleOrder();
                order.Id = ObjectId.NewId();
                order.ProductArticleId = productArticle.Id;
                order.Count            = count;
                order.Priority         = dataContext.ProductArticleOrders.Count() + 1;
                order.UserId           = UserContext.UserId;

                dataContext.ProductArticleOrders.Add(order);
                dataContext.SaveChanges();
            }

            IProductOrder productOrder = new ProductOrder(new ProductOrderDataProxy(this, order.Id));

            _productOrders.Add(productOrder);
            RequestForCalculation();
            return(productOrder);
        }