Пример #1
0
        private void refreshInformations(List <int> ids = null)
        {
            lblInformations.Text = string.Empty;
            var result = from st in Session.Entities.GetStockTransactions()
                         join s in Session.Entities.GetStocks() on st.StockCode equals s.StockCode
                         where (ids == null || ids.Contains(st.AccountTransactionId))
                         orderby st.Date
                         select new
            {
                Stock            = s,
                StockTransaction = st
            };
            var stocks = from s in Session.Entities.GetStocks()
                         where result.Select(c => c.Stock.StockCode).Contains(s.StockCode)
                         select new StockInformation
            {
                Stock       = s,
                TotalAmount = result.Where(c => c.Stock.StockCode == s.StockCode)
                              .Sum(c => c.StockTransaction.Amount *
                                   (c.StockTransaction.TransactionType == TransactionType.Sell ? -1 : 1)),
                TotalPrice = result.Where(c => c.Stock.StockCode == s.StockCode)
                             .Sum(c => c.StockTransaction.UnitPrice * c.StockTransaction.Amount *
                                  (c.StockTransaction.TransactionType == TransactionType.Buy ? -1 : 1)),
                Const = result.Where(c => c.Stock.StockCode == s.StockCode).Sum(c => c.StockTransaction.Const)
            };

            foreach (var item in stocks)
            {
                lblInformations.Text += $"[{Translate.GetMessage("stock-code")}: {item.Stock.StockCode}, {Translate.GetMessage("total-amount")}: {item.TotalAmount.ToMoneyStirng(0)}, {Translate.GetMessage("total-price")}: {(item.TotalPrice).ToMoneyStirng(2)}] | ";
            }
            lblInformations.Text += $"[{Translate.GetMessage("const")}: {stocks.Sum(c => c.Const).ToMoneyStirng(2)}, {Translate.GetMessage("total-price")}: {stocks.Sum(c => c.TotalPrice - c.Const).ToMoneyStirng(2)}]";
            lblInformation2.Text  = lblInformations.Text;
        }
Пример #2
0
 void getCurrentValues()
 {
     try
     {
         DovizComApi api = new DovizComApi();
         if (api.IsError)
         {
             MessageBox.Show(Translate.GetMessage("get-current-stock-values-failed"), Translate.GetMessage("error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         foreach (var item in (from s in Session.Entities.GetStocks()
                               join cs in api.StockCurrents on s.StockCode equals cs.StockCode
                               select new
         {
             Stock = s,
             CurrentStock = cs
         }))
         {
             Session.Entities.GetCurrentStocks().Add(item.CurrentStock);
             item.Stock.Name = item.CurrentStock.StockName;
         }
         Session.SaveChanges();
         MessageBox.Show(Translate.GetMessage("get-current-stock-values-success"), Translate.GetMessage("success"), MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     catch
     {
         MessageBox.Show(Translate.GetMessage("get-current-stock-values-failed"), Translate.GetMessage("error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Пример #3
0
        private void refreshList()
        {
            Text = $"{Translate.GetMessage("stock-tracing")} - [{Session.DefaultAccount.AccountName} - {Session.DefaultAccount.MoneyType.MoneyTypeToString()}]";
            string   selectedStockCode = (cbStock.SelectedItem != null && !string.IsNullOrEmpty(cbStock.Text)) ? ((ComboboxItem)cbStock.SelectedItem).Code : "";
            DateTime startDate         = period.StartDate;
            DateTime endDate           = period.EndDate;

            lvList.Items.Clear();
            var list = from st in Session.Entities.GetStockTransactions()
                       join s in Session.Entities.GetStocks() on st.StockCode equals s.StockCode
                       where (string.IsNullOrEmpty(selectedStockCode) || s.StockCode == selectedStockCode) &&
                       st.Date >= startDate &&
                       st.Date <= endDate
                       orderby st.Date descending
                       select new
            {
                Stock            = s,
                StockTransaction = st
            };

            foreach (var item in list)
            {
                var li = new ListViewItem();
                li.Text = item.StockTransaction.StockTransactionId.ToString();
                li.SubItems.Add(new ListViewItem.ListViewSubItem()
                {
                    Name = "StockCode",
                    Text = item.Stock.StockCode
                });
                li.SubItems.Add(new ListViewItem.ListViewSubItem()
                {
                    Name = "StockName",
                    Text = item.Stock.Name
                });
                li.SubItems.Add(new ListViewItem.ListViewSubItem()
                {
                    Name = "UnitPrice",
                    Text = item.StockTransaction.UnitPrice.ToMoneyStirng(6)
                });
                li.SubItems.Add(new ListViewItem.ListViewSubItem()
                {
                    Name = "Amount",
                    Text = item.StockTransaction.Amount.ToMoneyStirng(0)
                });
                li.SubItems.Add(new ListViewItem.ListViewSubItem()
                {
                    Name = "Status",
                    Text = item.StockTransaction.TransactionType == TransactionType.Buy ? Translate.GetMessage("buy") : Translate.GetMessage("sell")
                });
                li.SubItems.Add(new ListViewItem.ListViewSubItem()
                {
                    Name = "TotalPrice",
                    Text = (item.StockTransaction.UnitPrice * item.StockTransaction.Amount).ToMoneyStirng(2)
                });
                li.SubItems.Add(new ListViewItem.ListViewSubItem()
                {
                    Name = "Const",
                    Text = (item.StockTransaction.Const).ToMoneyStirng(2)
                });
                li.SubItems.Add(new ListViewItem.ListViewSubItem()
                {
                    Name = "Date",
                    Text = item.StockTransaction.Date.ToShortDateString()
                });

                lvList.Items.Add(li);
            }

            var liTotal = new ListViewItem();

            liTotal.Text = "0";
            liTotal.SubItems.Add(new ListViewItem.ListViewSubItem()
            {
                Name = "StockCode",
                Text = ""
            });
            liTotal.SubItems.Add(new ListViewItem.ListViewSubItem()
            {
                Name = "StockName",
                Text = ""
            });
            liTotal.SubItems.Add(new ListViewItem.ListViewSubItem()
            {
                Name = "UnitPrice",
                Text = ""
            });
            liTotal.SubItems.Add(new ListViewItem.ListViewSubItem()
            {
                Name = "Amount",
                Text = ""
            });
            liTotal.SubItems.Add(new ListViewItem.ListViewSubItem()
            {
                Name = "Status",
                Text = Translate.GetMessage("total")
            });;
            var totalPrice = list.Sum(c => c.StockTransaction.TotalPrice * (c.StockTransaction.TransactionType == TransactionType.Buy ? -1 : 1));

            liTotal.SubItems.Add(new ListViewItem.ListViewSubItem()
            {
                Name = "TotalPrice",
                Text = totalPrice.ToMoneyStirng(2)
            });
            var totalConst = list.Sum(c => c.StockTransaction.Const);

            liTotal.SubItems.Add(new ListViewItem.ListViewSubItem()
            {
                Name = "Const",
                Text = totalConst.ToMoneyStirng(2)
            });
            liTotal.SubItems.Add(new ListViewItem.ListViewSubItem()
            {
                Name = "Date",
                Text = ""
            });
            liTotal.BackColor = Color.DarkSlateGray;

            lvList.Items.Add(liTotal);
            refreshInformations();
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            errorProvider1.Clear();
            if (validation())
            {
                stock.Name = txtStockName.Text;
                decimal amount    = decimal.Parse(txtAmount.Text);
                decimal unitPrice = decimal.Parse(txtUnitPrice.Text);
                stock.StockCode  = txtStockCode.Text.ToUpper();
                stock.UpdateDate = DateTime.Now;


                decimal currentAmount = Session.Entities.GetStockTransactions().Where(c => c.StockCode == stock.StockCode).Sum(c => c.Amount * (c.TransactionType == TransactionType.Sell ? -1 : 1));
                if (stockTransaction.StockTransactionId > 0)
                {
                    currentAmount += stockTransaction.Amount;
                }

                if (cbType.Text == Translate.GetMessage("Sell") && amount > currentAmount)
                {
                    MessageBox.Show(Translate.GetMessage("there-is-not-enough-stock"), Translate.GetMessage("error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                stockTransaction.StockCode = txtStockCode.Text.ToUpper();
                stockTransaction.Date      = dtDate.Value;
                stockTransaction.UnitPrice = stock.Value;

                if (cbType.Text == Translate.GetMessage("buy"))
                {
                    stockTransaction.TransactionType = TransactionType.Buy;
                }
                else if (cbType.Text == Translate.GetMessage("sell"))
                {
                    stockTransaction.TransactionType = TransactionType.Sell;
                }

                stockTransaction.Amount     = amount;
                stockTransaction.UnitPrice  = unitPrice;
                stockTransaction.TotalPrice = stockTransaction.UnitPrice * stockTransaction.Amount;

                Session.Entities.PostStock(stock);
                Session.Entities.PostStockTransaction(stockTransaction);
                Session.SaveChanges();
                Close();
            }
        }
 public frmStockTransaction(int?stockTransactionId = null)
 {
     InitializeComponent();
     setTranslateMessage();
     if (stockTransactionId.HasValue)
     {
         stockTransaction   = Session.Entities.GetStockTransaction(stockTransactionId.Value);
         stock              = stockTransaction.Stock;
         txtAmount.Text     = stockTransaction.Amount.ToMoneyStirng(2);
         txtStockCode.Text  = stockTransaction.StockCode;
         txtStockName.Text  = stock.Name;
         txtTotalPrice.Text = stockTransaction.TotalPrice.ToMoneyStirng(2);
         txtUnitPrice.Text  = stockTransaction.UnitPrice.ToMoneyStirng(6);
         cbType.Text        = stockTransaction.TransactionType == TransactionType.Buy ? Translate.GetMessage("buy") : Translate.GetMessage("sell");
         dtDate.Value       = stockTransaction.Date;
     }
     else
     {
         stockTransaction = new StockTransaction();
         stock            = new Stock();
     }
     dtDate.Value = DateTime.Now;
 }
Пример #6
0
 private void setTranslateMessage()
 {
     Text = $"[{stock.StockCode} - {stock.Name}] {Translate.GetMessage("stock-chart")}";
 }
Пример #7
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (validation())
            {
                var user = Session.Entities.GetUser(txtUserName.Text, passwordIsHash ? Session.Entities.GetSetting().PasswordHash : txtPassword.Text.ComputeSha256Hash(txtUserName.Text));
                if (user != null)
                {
                    if (!string.IsNullOrEmpty(user.LanguageCode))
                    {
                        Session.Entities.GetSetting().LanguageCode = user.LanguageCode;
                    }
                    SettingSave();
                    frmMain frmMain = new frmMain();
                    Session.User = user;

                    if (Session.User.Accounts.Count == 0)
                    {
                        frmAccount frm = new frmAccount();
                        frm.ShowDialog();
                        Session.DefaultAccount = Session.User.Accounts.FirstOrDefault();
                        if (Session.DefaultAccount != null)
                        {
                            Hide();
                            frmMain.Show();
                        }
                        else
                        {
                            MessageBox.Show(Translate.GetMessage("account-not-found"), Translate.GetMessage("error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else if (Session.User.Accounts.Count == 1)
                    {
                        Hide();
                        Session.DefaultAccount = user.Accounts.FirstOrDefault();
                        frmMain.Show();
                    }
                    else if (Session.User.Accounts.Any(c => c.DefaultAccount))
                    {
                        Hide();
                        Session.DefaultAccount = user.Accounts.FirstOrDefault(c => c.DefaultAccount);
                        frmMain.Show();
                    }
                    else
                    {
                        frmAccountChoose frmAccountChoose = new frmAccountChoose();
                        frmAccountChoose.ShowDialog();
                        if (Session.DefaultAccount != null)
                        {
                            frmMain.Show();
                            Hide();
                        }
                    }
                }
                else
                {
                    MessageBox.Show(Translate.GetMessage("username-or-password-incorrect"), Translate.GetMessage("error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }