Ejemplo n.º 1
0
        private void TestLockButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (String.IsNullOrWhiteSpace(ConnectionStringTextBox.Text))
                {
                    throw new ArgumentException("ConnectionString");
                }

                ConnectionStringHolder.Initialize(ConnectionStringTextBox.Text);
                StringBuilder sb = new StringBuilder("Spojeno:\n");

                using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext())
                {
                    sb.AppendFormat("LockedBy: {0}\n{1}", dataContext.LockedBy, dataContext.LockedByUser);
                }

                MessageBox.Show(sb.ToString(), "Info", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(String.Format("Chyba spojení: {0}", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                ConnectionStringHolder.Close();
            }
        }
Ejemplo n.º 2
0
        public bool RemoveMaterial(IMaterial material)
        {
            try
            {
                _longOperationHandler.Start("MaterialRemoving");

                GetLock();

                using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext())
                {
                    SqlParameter articleIdParam = new SqlParameter("@ArticleId", SqlDbType.UniqueIdentifier)
                    {
                        Value = material.MaterialId.ToGuid()
                    };
                    dataContext.Database.ExecuteSqlCommand("exec RemoveMaterial @ArticleId", articleIdParam);
                }

                ReloadData();
                LongOperationResult result = new LongOperationResult {
                    RefreshAll = true
                };
                _longOperationHandler.End(result);

                RequestForCalculation();
                return(true);
            }
            catch (Exception ex)
            {
                _longOperationHandler.OperationFailed(ex.Message);
                Logger.Error(ex);
                return(false);
            }
        }
Ejemplo n.º 3
0
        private void LoadMaterials()
        {
            if (_materials.Count > 0)
            {
                return;
            }

            try
            {
                using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext())
                {
                    foreach (Article article in dataContext.Articles.OrderBy(a => a.Code))
                    {
                        if (article.ArticleStat != null)
                        {
                            _materials.Add(new Material(new MaterialDataProxy(this, article.Id)));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
        }
Ejemplo n.º 4
0
        internal override void Load()
        {
            using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext())
            {
                Guid id    = ItemId;
                Guid ordId = OrderId;
                ProductArticleItem        articleItem = dataContext.ProductArticleItems.Find(id);
                ProductArticleReservation reservation = articleItem.ProductArticleReservations.FirstOrDefault(r => r.ProductArticleOrderId == ordId);

                ArticleId             = articleItem.ArticleId;
                Code                  = articleItem.Article.Code;
                Type                  = articleItem.Article.ArticleType;
                Name                  = articleItem.Article.Name;
                Count                 = articleItem.Quantity;
                StockAvailable        = reservation != null ? reservation.CurrentCount : 0;
                Storage               = articleItem.Storage.Name;
                ProductionReservation = reservation != null ? reservation.ReservationCount : 0;
                OrderCount            = reservation != null ? reservation.OrderCount : 0;

                if (Type == ArticleType.Card)
                {
                    ArticleOrder articleOrder = dataContext.ArticleOrders.FirstOrDefault(ao => ao.ArticleId == articleItem.ArticleId);
                    if (reservation != null && Math.Abs(reservation.OrderCount - 0) < 0.001)
                    {
                        articleOrder = null;
                    }

                    MaterialOrderStatus = new MaterialOrderStatus(DataChange, articleOrder != null ? articleOrder.Count : 0, articleOrder != null ? articleOrder.Article.OrderCount : 0);
                }
                else
                {
                    MaterialOrderStatus = new MaterialOrderStatus(DataChange, 0, 0);
                }
            }
        }
Ejemplo n.º 5
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();
            }
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        private void TestButton_OnClick(object sender, RoutedEventArgs e)
        {
            try
            {
                if (String.IsNullOrWhiteSpace(ConnectionStringTextBox.Text))
                {
                    throw new ArgumentException("ConnectionString");
                }

                ConnectionStringHolder.Initialize(ConnectionStringTextBox.Text);

                using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext())
                {
                    dataContext.Database.ExecuteSqlCommand("SELECT 1");
                }

                MessageBox.Show("Spojeno!", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(String.Format("Chyba spojení: {0}", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                ConnectionStringHolder.Close();
            }
        }
Ejemplo n.º 8
0
 public bool ExistsExternStorage(string name, ObjectId excludedStorageId)
 {
     using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext())
     {
         return(dataContext.Storages.FirstOrDefault(e => e.Name.ToUpper().Equals(name.ToUpper()) && e.Id != (Guid)excludedStorageId) != null);
     }
 }
Ejemplo n.º 9
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
                });
            });
        }
Ejemplo n.º 10
0
        private void ClearLockButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (String.IsNullOrWhiteSpace(ConnectionStringTextBox.Text))
                {
                    throw new ArgumentException("ConnectionString");
                }

                ConnectionStringHolder.Initialize(ConnectionStringTextBox.Text);
                StringBuilder sb = new StringBuilder("OK");

                using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext())
                {
                    dataContext.Database.ExecuteSqlCommand("UPDATE SystemInformations SET Value='' where Name='LockedBy'");
                }

                MessageBox.Show("OK", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(String.Format("Chyba spojení: {0}", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                ConnectionStringHolder.Close();
            }
        }
Ejemplo n.º 11
0
        public bool ResolveProductOrder(IProductOrder order, bool resolve)
        {
            try
            {
                GetLock();

                using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext())
                {
                    SqlParameter orderIdParam = new SqlParameter("@OrderId", SqlDbType.UniqueIdentifier)
                    {
                        Value = order.OrderId.ToGuid()
                    };
                    SqlParameter resolveParam = new SqlParameter("@Resolve", SqlDbType.Bit)
                    {
                        Value = resolve
                    };
                    dataContext.Database.ExecuteSqlCommand("exec ResolveProductOrder @OrderId, @Resolve", orderIdParam, resolveParam);
                }

                _productOrders.Clear();
                LoadProductOrders();
                RequestForCalculation();
                return(true);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                return(false);
            }
        }
Ejemplo n.º 12
0
        private void UpdateButton_OnClick(object sender, RoutedEventArgs e)
        {
            try
            {
                if (String.IsNullOrWhiteSpace(ConnectionStringTextBox.Text))
                {
                    throw new ArgumentException("ConnectionString");
                }

                string script = File.ReadAllText(FileName.Text, Encoding.UTF8);
                IEnumerable <string> scriptParts = PrepareScript(script);

                ConnectionStringHolder.Initialize(ConnectionStringTextBox.Text);

                using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext())
                {
                    foreach (string part in scriptParts)
                    {
                        dataContext.Database.ExecuteSqlCommand(part);
                    }
                }

                MessageBox.Show("Aktualizováno!", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(String.Format("Chyba spojení: {0}", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                ConnectionStringHolder.Close();
            }
        }
Ejemplo n.º 13
0
        public Task <bool> CalculateAndSave(SessionId sessionId)
        {
            return(Task <bool> .Factory.StartNew(() =>
            {
                try
                {
                    using (StoreKeeperDataContext context = new StoreKeeperDataContext())
                    {
                        if (context.Database.Connection.State == ConnectionState.Closed)
                        {
                            context.Database.Connection.Open();
                        }

                        SqlParameter publishParam = new SqlParameter("@Publish", SqlDbType.Bit)
                        {
                            Value = 1
                        };

                        DbCommand cmd = context.Database.Connection.CreateCommand();
                        cmd.CommandText = "exec CalculateData @Publish";
                        cmd.CommandTimeout = 0;
                        cmd.Parameters.Add(publishParam);
                        cmd.ExecuteNonQuery();
                    }
                    ISessionManager sessionManager = StoreKeeperServer.Service <ISessionManager>();
                    sessionManager.NotifyDataUpdated(sessionId);
                    return true;
                }
                catch (Exception ex)
                {
                    ApplicationContext.Log.Error(GetType(), ex);
                    return false;
                }
            }));
        }
Ejemplo n.º 14
0
        public bool CanExternStorageBeSafelyRemoved(ObjectId storageId)
        {
            Guid id = storageId;

            using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext())
            {
                return(!dataContext.ProductArticleItems.Any(m => m.StorageId == id) &&
                       !dataContext.ArticleStats.Any(es => es.StorageId == id));
            }
        }
Ejemplo n.º 15
0
 public IProductStorageMapping GetProductStorageMapping(ObjectId productId)
 {
     using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext())
     {
         Guid           articleId      = productId;
         ProductArticle productArticle = dataContext.ProductArticles.FirstOrDefault(pa => pa.ArticleId == articleId);
         if (productArticle == null)
         {
             throw new ProductArticleNotFoundException(GetType(), productId);
         }
         return(new ProductStorageMapping(new ProductStorageMappingDataProxy(this, productArticle.Id)));
     }
 }
Ejemplo n.º 16
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();
            }
        }
Ejemplo n.º 17
0
        internal override void Load()
        {
            using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext())
            {
                Guid id = OrderId;
                ProductArticleOrder order = dataContext.ProductArticleOrders.Find(id);

                ProductId   = order.ProductArticle.ArticleId;
                Name        = order.ProductArticle.Article.Name;
                Title       = order.ProductArticle.Article.Code;
                ItemId      = ProductId;
                Description = Name;
            }
        }
Ejemplo n.º 18
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();
            }
        }
Ejemplo n.º 19
0
        public void CheckDatabaseStatus()
        {
            string lockedBy = String.Empty;

            using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext())
            {
                lockedBy = dataContext.LockedBy;
            }

            if (!String.IsNullOrWhiteSpace(lockedBy))
            {
                DatabaseStatus = String.Compare(lockedBy, UserContext.UserId, StringComparison.Ordinal) == 0 ? DatabaseStatus.Locked : DatabaseStatus.Blocked;
            }
        }
Ejemplo n.º 20
0
        public IEnumerable <IProductOrderItem> GetProductOrderDetailItems(ObjectId productItemId, ObjectId productOrderId)
        {
            List <IProductOrderItem> items = new List <IProductOrderItem>();

            using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext())
            {
                ProductArticle productArticle = dataContext.ProductArticles.First(pa => pa.ArticleId == (Guid)productItemId);
                foreach (ProductArticleItem item in productArticle.ProductArticleItems.Where(i => !i.SkipCalculation).OrderBy(i => i.Article.Code))
                {
                    items.Add(new ProductOrderItem(new ProductOrderItemDataProxy(this, item.Id, productOrderId)));
                }
            }

            return(items);
        }
Ejemplo n.º 21
0
 internal override void Load()
 {
     using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext())
     {
         Parlor    = dataContext.GetStringConstant("DN_Parlor");
         Street    = dataContext.GetStringConstant("DN_Street");
         Number    = dataContext.GetStringConstant("DN_Number");
         ZipCode   = dataContext.GetStringConstant("DN_Zip");
         City      = dataContext.GetStringConstant("DN_City");
         Phone     = dataContext.GetStringConstant("DN_Phone");
         CellPhone = dataContext.GetStringConstant("DN_CellPhone");
         Email     = dataContext.GetStringConstant("DN_Email");
         Web       = dataContext.GetStringConstant("DN_Web");
     }
 }
Ejemplo n.º 22
0
        private void LoadExternStorages()
        {
            if (_externStorages.Count > 0)
            {
                return;
            }

            using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext())
            {
                foreach (Storage storage in dataContext.Storages)
                {
                    _externStorages.Add(new ExternStorage(new ExternStorageDataProxy(this, storage.Id)));
                }
            }
        }
Ejemplo n.º 23
0
 public void Open()
 {
     try
     {
         using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext())
         {
             dataContext.TestConnect();
         }
         DatabaseStatus = DatabaseStatus.Connected;
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
         DatabaseStatus = DatabaseStatus.NotConnected;
     }
 }
        internal override void Load()
        {
            using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext())
            {
                Guid           id             = ProductArticleId;
                ProductArticle productArticle = dataContext.ProductArticles.Find(id);
                ProductId = productArticle.ArticleId;
                Name      = productArticle.Article.Name;

                _itemProxies.Clear();
                foreach (ProductArticleItem item in productArticle.ProductArticleItems)
                {
                    _itemProxies.Add(new ProductStorageMappingItemDataProxy(DataChange, item.Id));
                }
            }
        }
Ejemplo n.º 25
0
        internal override void Load()
        {
            using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext())
            {
                Guid id = ArticleItemId;
                ProductArticleItem articleItem = dataContext.ProductArticleItems.Find(id);

                ArticleId        = articleItem.ArticleId;
                Code             = articleItem.Article.Code;
                Type             = articleItem.Article.ArticleType;
                Name             = articleItem.Article.Name;
                Storage          = articleItem.Storage.Name;
                _storageId       = articleItem.StorageId;
                _skipCalculation = articleItem.SkipCalculation;
            }
        }
Ejemplo n.º 26
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();
            }
        }
Ejemplo n.º 27
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);
        }
Ejemplo n.º 28
0
        public IEnumerable <IArticleCode> GetMatchingArticleCodes(string codePart, ArticleCodeType codeType)
        {
            int codeTypeValue          = (int)codeType;
            List <IArticleCode> result = new List <IArticleCode>();

            using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext())
            {
                foreach (Article article in dataContext.Articles.Where(a => a.Code.ToUpper().StartsWith(codePart.ToUpper())))
                {
                    if (article.Type == codeTypeValue || codeTypeValue == 0)
                    {
                        result.Add(new ArticleCode(article.Code, article.Name));
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 29
0
        private void LoadProductOrders()
        {
            if (_productOrders.Count > 0)
            {
                return;
            }

            using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext())
            {
                foreach (ProductArticleOrder productOrder in dataContext.ProductArticleOrders.OrderBy(po => po.Priority))
                {
                    if (dataContext.IsOrderValid(productOrder.Id))
                    {
                        _productOrders.Add(new ProductOrder(new ProductOrderDataProxy(this, productOrder.Id)));
                    }
                }
            }
        }
Ejemplo n.º 30
0
        private void LoadExternStorageMaterials()
        {
            if (_externStorageMaterials.Count > 0)
            {
                return;
            }

            using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext())
            {
                foreach (ArticleStat externStorageStat in dataContext.ArticleStats.OrderBy(es => es.Article.Code))
                {
                    if (externStorageStat.StorageId != Constants.CentralStorageId)
                    {
                        _externStorageMaterials.Add(new ExternStorageMaterial(new ExternStorageMaterialDataProxy(this, externStorageStat.ArticleId, externStorageStat.StorageId)));
                    }
                }
            }
        }