Пример #1
0
        public async Task <int> CreateStock(Models.Stock stock)
        {
            var query   = new InsertQuery(Tables.StockTable, Tables.StockFields.Where(x => !x.Equals("ID")).ToList(), stock.GetFieldValues());
            var command = new SqlCommand(query.ToString(), _connection);

            return(await command.ExecuteNonQueryAsync());
        }
Пример #2
0
 private async void Sure_Click(object sender, RoutedEventArgs e)
 {
     if (string.IsNullOrEmpty(BookIDBox.Text) || string.IsNullOrEmpty(SaleNumberBox.Text))
     {
         return;
     }
     Models.Stock stock = StockUtil.QueryStock(BookIDBox.Text);
     if (stock != null)
     {
         int n = int.Parse(SaleNumberBox.Text);
         SaleNumberBox.Text = "";
         if (n < 0)
         {
             await new MessageDialog("还书的数值不正确!").ShowAsync();
             return;
         }
         // 库存记录
         StockViewModel.GetInstance().UpdateStock(stock.Book.BId, n);
         // 还书记录
         Models.Return @return = new Models.Return {
             Book = stock.Book, Number = n, Time = DateTimeOffset.Now, TotalPrice = stock.SalePrice * n
         };
         ReturnUtil.AddReturn(@return);
         await new MessageDialog("归还成功!").ShowAsync();
     }
     else
     {
         await new MessageDialog("本店没有进过这种书,不必归还到此!").ShowAsync();
     }
     BookIDBox.Text = "";
 }
Пример #3
0
 private async void Sure_Click(object sender, RoutedEventArgs e)
 {
     if (string.IsNullOrEmpty(SaleNumberBox.Text) || string.IsNullOrEmpty(BookIDBox.Text))
     {
         return;
     }
     Models.Stock stock = StockUtil.QueryStock(BookIDBox.Text);
     if (stock != null)
     {
         int n = int.Parse(SaleNumberBox.Text);
         SaleNumberBox.Text = "";
         if (n > stock.Number)
         {
             await new MessageDialog("这种书没有多么多了!").ShowAsync();
             return;
         }
         // 库存记录
         StockViewModel.GetInstance().UpdateStock(stock.Book.BId, 0 - n);
         // 销售记录
         Models.Sale sale = new Models.Sale {
             Book = stock.Book, Number = n, Time = DateTimeOffset.Now, TotalPrice = n * stock.SalePrice
         };
         SalesUtil.AddSale(sale);
         await new MessageDialog("销售成功!").ShowAsync();
     }
     else
     {
         await new MessageDialog("没有这种书,请重新输入书籍编号!").ShowAsync();
     }
     BookIDBox.Text = "";
 }
Пример #4
0
 public StocksEdit()
 {
     InitializeComponent();
     StockVolumeTb.PreviewTextInput += new TextCompositionEventHandler(textBox_PreviewTextInput);
     StockItem   = new Models.Stock();
     DataContext = this;
 }
Пример #5
0
        public async Task <int> UpdateStock(Models.Stock stock)
        {
            var getById = new Condition("id", Convert.ToString(stock.Id), BinaryOperators.Equal);
            Dictionary <LogicOperators, Condition> condition = new Dictionary <LogicOperators, Condition> {
                { LogicOperators.FirstCondition, getById }
            };
            var query   = new UpdateQuery(Tables.StockTable, Tables.StockFields.Where(x => x != "ID").ToList(), stock.GetFieldValues(false), condition);
            var command = new SqlCommand(query.ToString(), _connection);

            return(await command.ExecuteNonQueryAsync());
        }
Пример #6
0
        public async Task <int> DeleteStock(Models.Stock stock)
        {
            var cnd = new Condition("ID", Convert.ToString(stock.Id), BinaryOperators.Equal);
            Dictionary <LogicOperators, Condition> conditions = new Dictionary <LogicOperators, Condition> {
                { LogicOperators.FirstCondition, cnd }
            };
            var query   = new DeleteQuery(Tables.StockTable, conditions);
            var command = new SqlCommand(query.ToString(), _connection);

            return(await command.ExecuteNonQueryAsync());
        }
Пример #7
0
 public void Update(Models.Stock stock)
 {
     Symbol        = stock.Symbol;
     Price         = stock.Price;
     Change        = stock.Change;
     LastChange    = stock.LastChange;
     PercentChange = stock.PercentChange;
     DayHigh       = stock.DayHigh;
     DayLow        = stock.DayLow;
     DayOpen       = stock.DayOpen;
     Index         = stock.Index;
 }
Пример #8
0
 // GET: Stocks/Details/5
 public ActionResult Details(string id)
 {
     if (id == null)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     Models.Stock stock = db.Stocks.Find(id);
     if (stock == null)
     {
         return(HttpNotFound());
     }
     return(View(stock));
 }
Пример #9
0
        public async Task StockManagementRemoveAsync(ICollection <SalesItem> salesItem, int BusinessId)
        {
            foreach (var item in salesItem)
            {
                Models.Stock stockDB = await _stockRepository.FindByIdAsync(item.StockId, BusinessId);

                if (stockDB != null)
                {
                    stockDB.RemoveQuantityStock(item.Quantity);
                    await _stockRepository.Update(stockDB);
                }
                //TODO Implementar throw
            }
        }
Пример #10
0
        // Inscription
        private void AddGestionnaire()
        {
            Models.Stock stock = new Models.Stock()
            {
                Titre = ("Stock de " + _addedGestionnaire.NomGestionnaire)
            };
            DBContext.SaveChanges();

            _addedGestionnaire.Stock       = stock;
            _addedGestionnaire.LoginStatus = "initial";

            DBContext.Add(_addedGestionnaire);
            DBContext.SaveChanges();

            this.OpenGestionnaireConnexion();
        }
        public ActionResult NewStock(ViewModels.StockNew form)
        {
            var ourUser = Database.Session.Query <Models.User>()
                          .Where(u => u.Username == HttpContext.User.Identity.Name)
                          .FirstOrDefault();

            if (form.unit_price <= 0)
            {
                ModelState.AddModelError("unit_price", "Birim Fiyat 0'dan büyük olmalıdır.");
            }
            if (form.stock_desc.IsEmpty())
            {
                ModelState.AddModelError("stock_desc", "Stok açıklaması boş bırakılamaz.");
            }
            if (form.stock_number <= 0)
            {
                ModelState.AddModelError("stock_number", "Stok adedi 0'dan büyük olmalıdır.");
            }

            if (!ModelState.IsValid)
            {
                form.user_id = ourUser.Id;
                return(View(form));
            }

            Models.Stock yeniUrun = new Models.Stock
            {
                Belongstouser   = ourUser,
                Description     = form.stock_desc,
                Quantityinstock = form.stock_number,
                Unitprice       = form.unit_price
            };

            try
            {
                Database.Session.Save(yeniUrun);
            }catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message.ToString());
                return(View());
            }
            Database.Session.Flush();

            return(RedirectToAction("Index", new { id = ourUser.Id }));
        }
Пример #12
0
        private bool TryUpdateStockPrice(Models.Stock stock)
        {
            // Randomly choose whether to update this stock or not
            var r = _updateOrNotRandom.NextDouble();

            if (r > .1)
            {
                return(false);
            }

            // Update the stock price by a random factor of the range percent
            var random        = new Random((int)Math.Floor(stock.Price));
            var percentChange = random.NextDouble() * _rangePercent;
            var pos           = random.NextDouble() > .51;
            var change        = Math.Round(stock.Price * (decimal)percentChange, 2);

            change = pos ? change : -change;

            stock.Price += change;
            return(true);
        }
Пример #13
0
        public async Task StockManagementAddAsync(PurchaseItemOrder itemOrder, int BusinessId)
        {
            Models.Stock stockDB = await _stockRepository.FindByIdAsync(itemOrder.ProductId, BusinessId);

            if (stockDB == null)
            {
                Models.Stock stock = new Models.Stock();
                stock.InsertDate = DateTime.Now;
                stock.ProductId  = itemOrder.ProductId;
                stock.AddQuantityStock(itemOrder.Quantity);
                stock.SalesPrice     = itemOrder.SalesPrice;
                stock.ValidationDate = itemOrder.ValidationDate;
                await _stockRepository.Insert(stock);
            }
            else
            {
                stockDB.AddQuantityStock(itemOrder.Quantity);
                stockDB.SalesPrice = itemOrder.SalesPrice;
                await _stockRepository.Update(stockDB);
            }
        }
Пример #14
0
 private void SearchId_Click(object sender, RoutedEventArgs e)
 {
     if (string.IsNullOrEmpty(BookIDBox.Text))
     {
         return;
     }
     Models.Stock stock = StockUtil.QueryStock(BookIDBox.Text);
     if (stock != null)
     {
         BookDetail.Visibility = Visibility.Visible;
         BookId.Text           = stock.Book.BId.ToString();
         BookName.Text         = stock.Book.BName;
         BookAuthor.Text       = stock.Book.BAuthor;
         BookNumber.Text       = stock.Number.ToString();
         BookSalePrice.Text    = stock.SalePrice.ToString();
         BookBuyPrice.Text     = stock.OfferPrice.ToString();
     }
     else
     {
         BookDetail.Visibility = Visibility.Collapsed;
     }
 }
        public async Task <IActionResult> Update([FromBody] Models.Stock stock)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(stock);
                    await _context.SaveChangesAsync();

                    return(Ok());
                }
                catch (Exception ex)
                {
                    if (ex.GetType().FullName == "Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException")
                    {
                        return(NotFound());
                    }

                    return(BadRequest());
                }
            }

            return(BadRequest());
        }
        public async Task <IActionResult> Create([FromBody] Models.Stock stock)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    _context.Add(stock);
                    await _context.SaveChangesAsync();

                    if (stock.Id > 0)
                    {
                        return(Ok(stock.Id));
                    }

                    return(NotFound());
                }
                catch (Exception)
                {
                    return(BadRequest());
                }
            }

            return(BadRequest());
        }
Пример #17
0
        public ActionResult NewSale(ViewModels.SalesNew form)
        {
            var currUser = Database.Session.Query <Models.User>()
                           .Where(u => u.Username == HttpContext.User.Identity.Name)
                           .FirstOrDefault();

            Models.Stock stockToSell = Database.Session.Query <Models.Stock>()
                                       .Where(c => c.StockId == form.selectedStockID)
                                       .OrderBy(c => c.Description)
                                       .FirstOrDefault();

            if (form.selectedStockID == 0)
            {
                ModelState.AddModelError("stocks", "Ürün Seçimi Yapılmalıdır.");
            }

            if (form.quantity <= 0)
            {
                ModelState.AddModelError("quantity", "Satış Adedi 0 veya 0'dan Küçük Olamaz.");
            }

            if (stockToSell != null)
            {
                if (form.quantity > stockToSell.Quantityinstock)
                {
                    ModelState.AddModelError("quantity", "Stoktaki Ürün Miktarından Fazla Satış Yapılamaz.\nStok Ürün Miktarı: " + stockToSell.Quantityinstock.ToString());
                }
            }

            if (!ModelState.IsValid)
            {
                form.stocks = Database.Session.Query <Models.Stock>()
                              .Where(c => c.Belongstouser.Id == currUser.Id)
                              .OrderBy(c => c.Description)
                              .ToList();
                form.user_id = currUser.Id;
                return(View(form));
            }


            var newSale = new Sales
            {
                belongsToUser = currUser,
                quantity      = form.quantity,
                date          = DateTime.Now,
                stock_id      = stockToSell,
                sale_sum      = stockToSell.Unitprice * form.quantity
            };

            stockToSell.Quantityinstock   -= form.quantity;
            newSale.belongsToUser.Balance += stockToSell.Unitprice * form.quantity;

            try {
                Database.Session.Save(newSale);
                Database.Session.Update(stockToSell);
                Database.Session.Update(newSale.belongsToUser);
            }catch (Exception ex)
            {
                ModelState.AddModelError(String.Empty, ex.Message);
                return(View(form));
            }

            Database.Session.Flush();
            return(RedirectToAction("Index", new { id = currUser.Id }));
        }
Пример #18
0
 public static MoveStockModel Create(Models.Stock stock)
 {
     return(new MoveStockModel {
         Stock = stock, StockId = stock.Id
     });
 }
Пример #19
0
 public void RemoveStock(Models.Stock stock)
 {
     stocks.Remove(stock);
 }
Пример #20
0
 public void AddStock(Models.Stock stock)
 {
     stocks.Add(stock);
 }
Пример #21
0
 public TestBetweenStocks(Models.Stock stock, int sharesOwned) : base(stock, sharesOwned)
 {
 }
Пример #22
0
 private void BroadcastStockPrice(Models.Stock stock)
 {
     Clients.All.updateStockPrice(stock);
 }
Пример #23
0
 public StockModelObject(Models.Stock stock)
 {
     Update(stock);
 }