Exemple #1
0
        private List <StockModels> GetStockItemBasedOnPrdNCmp(List <SalesModel> items)
        {
            List <StockModels> lstSaleItems = new List <StockModels>();

            try
            {
                List <StockModels> lstStock = mngStock.GetAllStock();


                foreach (SalesModel item in items)
                {
                    StockModels stockItem = null;
                    lstStock.ForEach(st =>
                    {
                        if (st.ProductName.Replace(" ", "").ToLower().Equals(item.ProductName.Replace(" ", "").ToLower()) &&
                            st.Company.Replace(" ", "").ToLower().Equals(item.Company.Replace(" ", "").ToLower()))
                        {
                            stockItem       = st;
                            stockItem.Stock = (Convert.ToInt32(stockItem.Stock) - Convert.ToInt32(item.Quantity)).ToString();
                            lstSaleItems.Add(stockItem);
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                Logger.WriteErrorMessage(ex);
            }
            return(lstSaleItems);
        }
Exemple #2
0
        private void GetItemInStockOnUnit(StockModels stModel)
        {
            int temp = !string.IsNullOrEmpty(txtUnit.Text) ? Convert.ToInt32(txtUnit.Text) : 0;

            lblStock.Text   = Convert.ToString(Convert.ToInt32(stModel.Stock) - temp);
            txtUnit.Enabled = true;
        }
        public async Task <IHttpActionResult> PostStockModels(StockModels stockModels)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.StockModels.Add(stockModels);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (StockModelsExists(stockModels.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = stockModels.Id }, stockModels));
        }
        public async Task <IHttpActionResult> PutStockModels(string id, StockModels stockModels)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != stockModels.Id)
            {
                return(BadRequest());
            }

            db.Entry(stockModels).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StockModelsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
 public UpdateStockForm(List <Product> Products, List <Company> Companies, string Connection, StockModels sm, DataGridView _gridStock, int rowIndex) : this()
 {
     this.Connection = Connection;
     this.Products   = Products;
     this.Companies  = Companies;
     this.Stock      = sm;
     this._gridStock = _gridStock;
     this.rowIndex   = rowIndex;
 }
Exemple #6
0
        private void ChangePageTo(int index)
        {
            if (index <= 0)
            {
                return;
            }
            PageStockModels.Clear();
            var temp = new List <StockModel>(StockModels.Skip((CurrentPageIndex - 1) * PageSize).Take(PageSize));

            temp.ToList().ForEach(m => PageStockModels.Add(m));
        }
        public async Task <IHttpActionResult> GetStockModels(string id)
        {
            StockModels stockModels = await db.StockModels.FindAsync(id);

            if (stockModels == null)
            {
                return(NotFound());
            }

            return(Ok(stockModels));
        }
        public async Task <IHttpActionResult> DeleteStockModels(string id)
        {
            StockModels stockModels = await db.StockModels.FindAsync(id);

            if (stockModels == null)
            {
                return(NotFound());
            }

            db.StockModels.Remove(stockModels);
            await db.SaveChangesAsync();

            return(Ok(stockModels));
        }
Exemple #9
0
        private void gridStock_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            gridStock.ClearSelection();
            if (e.ColumnIndex == 1 && e.RowIndex != -1)
            {
                StockModels sm = gridStock.Rows[e.RowIndex].DataBoundItem as StockModels;

                List <Product> lstProduct = null;
                List <Company> lstCmp     = null;
                getCompanyAndProduct(out lstProduct, out lstCmp);

                UpdateStockForm upStockForm = new RajEnterprise.UpdateStockForm(lstProduct, lstCmp, ConnectioString, sm, gridStock, e.RowIndex);
                upStockForm.ShowDialog();
                gridStock.ClearSelection();
            }
        }
Exemple #10
0
        private bool TryUpdateStockPrice(StockModels stock)
        {
            // Randomly choose whether to udpate this stock or not
            var r = _updateOrNotRandom.NextDouble();

            if (r > 0.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() > 0.51;
            var change        = Math.Round(stock.Price * (decimal)percentChange, 2);

            change = pos ? change : -change;

            stock.Price += change;
            return(true);
        }
Exemple #11
0
 /// <summary>
 /// 大单
 /// </summary>
 /// <param name="args"></param>
 private void StockAnalysisService_StockAnalysisResultUpdatedEvent(StockAnalysisResultUpdatedEventArgs <StockTransactionModel> args)
 {
     DispatcherHelper.RunAsync(new Action(() =>
     {
         args.AnalysisResults.ForEach(x =>
         {
             var model = CommonStockDataManager.Instance.GetStockDetailModel(x.Code);
             if (model != null)
             {
                 x.Name = model.Name;
             }
             var bks = CommonStockDataManager.Instance.GetStorageSectionsStr(x.Code);
             if (!string.IsNullOrEmpty(bks))
             {
                 x.Topic = bks;
             }
             //contentListBox.Items.Add($"[大单] - {x.ToString()}");
             var temp = new StockModel(x);
             StockModels.Insert(0, temp);
         });
     }));
 }
Exemple #12
0
 private void BroadcastStockPrice(StockModels stock)
 {
     Clients.All.updateStockPrice(stock);
 }
        public JsonResult TransferStockIn([FromBody] StockModels stock)
        {
            string AddedBy = Constant.GetUserID();

            return(Json(StockTransferredOutSQL.TransferStockIn(stock, AddedBy), JsonRequestBehavior.AllowGet));
        }
Exemple #14
0
        /// <summary>
        /// 开始监控
        /// </summary>
        private async void OnStart()
        {
            this.CanStart = false;
            StockModels.Clear();
            PageStockModels.Clear();
            _count = 0;
            this.TotalCrawledCount  = 0;
            this.BigDealRemainCount = 0;
            this.QuickRemainCount   = 0;
            StockModel.StaticIndex  = 1;
            try
            {
                _configModel = ConfigJsonHelper.GetConfigModel();
                Messenger.Default.Send(new StatusBarArgs(true, ResourceHelper.FindKey("StatusBar_Message_CheckingConfig")), StatusBarToken.UpdateStatus);
                bool isConfigUseful = await Task.Run(() => CheckConfig());

                if (!isConfigUseful)
                {
                    this.CanStart = true;
                    return;
                }

                Messenger.Default.Send(new StatusBarArgs(true, ResourceHelper.FindKey("StatusBar_Message_FilteringStock")), StatusBarToken.UpdateStatus);
                List <string> monitorStocks = GetMonitorStocks();

                if (monitorStocks == null)
                {
                    this.CanStart = true;
                    return;
                }

                if (!monitorStocks.Any())
                {
                    Messenger.Default.Send(new StatusBarArgs(true, ResourceHelper.FindKey("StatusBar_ConfigError_FilterNone")), StatusBarToken.UpdateStatus);
                    this.CanStart = true;
                    return;
                }

                CanStart = false;
                CanStop  = true;

                WebProxy proxy = null;
                if (_configModel.IsUseProxy)
                {
                    proxy = new WebProxy(_configModel.ProxyData.IP, _configModel.ProxyData.Port);
                }

                try
                {
                    _iStockRealTimeDealCrawler?.StartCrawler(proxy, _configModel.ClawlerConfigData.QueryInterval, monitorStocks);
                }
                catch (ClawlerConfigException clawlerConfigException)
                {
                    Messenger.Default.Send(new StatusBarArgs(true, clawlerConfigException.Message), StatusBarToken.UpdateStatus);
                    await Task.Run(() => _iStockRealTimeDealCrawler?.StopCrawler());

                    this.CanStart = true;
                    this.CanStop  = false;
                    return;
                }
                catch (Exception ex)
                {
                    LogBuilder.Logger.Error("start crawler error.", ex);
                }

                if (false)
                {
                    try
                    {
                        var stockAnalysisService = ServiceManager <StockTransactionModel> .Instance.GetStockAnalysisService();

                        _stockAnalysisService = stockAnalysisService;
                        _stockAnalysisService.StockAnalysisResultUpdatedEvent += StockAnalysisService_StockAnalysisResultUpdatedEvent;
                        _stockAnalysisService.RemainderCountUpdatedEvent      += _stockAnalysisService_RemainderCountUpdatedEvent;
                        _stockAnalysisService.StartAnalysis(new BigDealAnalysisStrategy(), _cacheBigDealAnalysisStrategy);
                    }
                    catch (StrategyConfigException strategyConfigException)
                    {
                        _stockAnalysisService.StockAnalysisResultUpdatedEvent -= StockAnalysisService_StockAnalysisResultUpdatedEvent;
                        _stockAnalysisService.RemainderCountUpdatedEvent      -= _stockAnalysisService_RemainderCountUpdatedEvent;
                        _stockAnalysisService.StopAnalysis();
                        Messenger.Default.Send(new StatusBarArgs(true, strategyConfigException.Message), StatusBarToken.UpdateStatus);
                        await Task.Run(() => _iStockRealTimeDealCrawler?.StopCrawler());

                        this.CanStart = true;
                        this.CanStop  = false;
                        return;
                    }
                    catch (Exception ex)
                    {
                        LogBuilder.Logger.Error("start moniter BigOrderStrategy error.", ex);
                    }
                }

                if (true)
                {
                    try
                    {
                        var quickAnalysisService = ServiceManager <StockTransactionModelExtern> .Instance.GetStockAnalysisService();

                        _quickAnalysisService = quickAnalysisService;
                        _quickAnalysisService.StockAnalysisResultUpdatedEvent += _quickAnalysisService_StockAnalysisResultUpdatedEvent;
                        _quickAnalysisService.RemainderCountUpdatedEvent      += _quickAnalysisService_RemainderCountUpdatedEvent;
                        _quickAnalysisService.StartAnalysis(new QuickUpAnalysisStrategy(), _cacheQuickUpAnalysisStrategy);
                    }
                    catch (StrategyConfigException strategyConfigException)
                    {
                        _quickAnalysisService.StockAnalysisResultUpdatedEvent -= _quickAnalysisService_StockAnalysisResultUpdatedEvent;
                        _quickAnalysisService.RemainderCountUpdatedEvent      -= _quickAnalysisService_RemainderCountUpdatedEvent;
                        _quickAnalysisService.StopAnalysis();
                        Messenger.Default.Send(new StatusBarArgs(true, strategyConfigException.Message), StatusBarToken.UpdateStatus);
                        await Task.Run(() => _iStockRealTimeDealCrawler?.StopCrawler());

                        this.CanStart = true;
                        this.CanStop  = false;
                        return;
                    }
                    catch (Exception ex)
                    {
                        LogBuilder.Logger.Error("start moniter RapidRiseStrategy error.", ex);
                    }
                }
                MonitoringStockCount = monitorStocks.Count;
                Messenger.Default.Send(new StatusBarArgs(true, ResourceHelper.FindKey("StatusBar_Message_Monitoring")), StatusBarToken.UpdateStatus);
            }
            catch (Exception ex)
            {
                CanStart = true;
                CanStop  = false;
                Messenger.Default.Send(new StatusBarArgs(true, string.Format(ResourceHelper.FindKey("StatusBar_Message_StartMonitorFailed"), ex.Message)), StatusBarToken.UpdateStatus);
                LogBuilder.Logger.Error("开始监控 - 失败", ex);
            }
        }
Exemple #15
0
        private void btnCart_Click(object sender, EventArgs e)
        {
            try
            {
                List <StockModels> stList      = getSelectedItemFromStock();
                StockModels        itemForSale = null;
                if (cmbUnit.DataSource != null)
                {
                    itemForSale = stList.Where(st => st.Weight == cmbUnit.Text).ToList()[0];
                }
                else
                {
                    itemForSale = stList[0];
                }
                //master stock list manage
                stockList.ForEach(st => { if (st.ID == itemForSale.ID)
                                          {
                                              st.Stock = (Convert.ToInt32(st.Stock) - Convert.ToInt32(txtUnit.Text)).ToString();
                                          }
                                  });

                SalesModel slModel = new SalesModel();

                slModel.ID          = stList[0].ID;
                slModel.ProductName = stList[0].ProductName;
                slModel.Company     = stList[0].Company;
                slModel.Quantity    = txtUnit.Text;
                slModel.Weight      = cmbUnit.Text;
                slModel.Details     = stList[0].Details;
                slModel.MRP         = stList[0].MRP;
                slModel.Rate        = stList[0].Rate;
                slModel.CGST        = stList[0].CGST;
                slModel.SGST        = stList[0].SGST;
                slModel.IGST        = stList[0].IGST;
                slModel.Total       = (decimal)calculateTotal(Convert.ToInt32(txtUnit.Text), !string.IsNullOrEmpty(slModel.SGST) ? Convert.ToDouble(slModel.SGST) : 0,
                                                              !string.IsNullOrEmpty(slModel.SGST) ? Convert.ToDouble(slModel.SGST) : 0,
                                                              !string.IsNullOrEmpty(slModel.SGST) ? Convert.ToDouble(slModel.SGST) : 0,
                                                              Convert.ToDouble(slModel.Rate), 0);
                if (saleItemList.ToList().Exists(slm => slm.ID == stList[0].ID))
                {
                    saleItemList.ToList().ForEach(slm =>
                    {
                        if (slm.ID == stList[0].ID)
                        {
                            slm.Quantity = Convert.ToString(Convert.ToInt32(slm.Quantity) + Convert.ToInt32(slModel.Quantity));
                            slm.Total    = slm.Total + slModel.Total;
                        }
                    });
                }
                else
                {
                    saleItemList.Add(slModel);
                }
                gridSale.DataSource = null;
                gridSale.DataSource = saleItemList;
                gridSale.ClearSelection();

                txtUnit.Text       = "";
                lblStock.Text      = "";
                cmbCompany.Text    = "";
                cmbProduct.Text    = "";
                txtUnit.Enabled    = false; btnCart.Enabled = false;
                cmbUnit.DataSource = null;
                cmbUnit.Enabled    = false;

                getSaleItemGrandTotalAmt();
                MakeInvoiceGenerationEnable();
            }
            catch (Exception ex)
            {
                Logger.WriteErrorMessage(ex);
            }
        }