예제 #1
0
 public frmStockTransactions(StockAnalysis stockAnalysis)
 {
     InitializeComponent();
     setTranslateMessage();
     this.stockAnalysis = stockAnalysis;
     Text = $"{stockAnalysis.StockCode} - {Translate.GetMessage("stock-transactions")}";
 }
예제 #2
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;
        }
예제 #3
0
        private void cbStock_Fill()
        {
            cbStock.Items.Clear();
            cbStock.ValueMember = "Value";
            cbStock.Items.Add(new ComboboxItem
            {
                Code  = "",
                Value = Translate.GetMessage("all")
            });
            DateTime startDate = period.StartDate;
            DateTime endDate   = period.EndDate;

            stocks = (from st in Session.Entities.GetStockTransactions()
                      join s in Session.Entities.GetStocks() on st.StockCode equals s.StockCode
                      where st.Date >= startDate && st.Date <= endDate
                      orderby st.Date descending
                      select s).Distinct().ToList();
            foreach (var stock in stocks)
            {
                cbStock.Items.Add(new ComboboxItem
                {
                    Code  = stock.StockCode,
                    Value = stock.StockCode
                });
            }
        }
예제 #4
0
 private void setTranslateMessage()
 {
     StockCode.Text                          = Translate.GetMessage("stock-code");
     StockName.Text                          = Translate.GetMessage("stock-name");
     UnitPrice.Text                          = Translate.GetMessage("unit-price");
     Amount.Text                             = Translate.GetMessage("amount");
     Type.Text                               = Translate.GetMessage("type");
     TotalPrice.Text                         = Translate.GetMessage("total-price");
     Const.Text                              = Translate.GetMessage("const");
     Date.Text                               = Translate.GetMessage("date");
     editToolStripMenuItem.Text              = Translate.GetMessage("edit");
     refreshToolStripMenuItem.Text           = Translate.GetMessage("refresh");
     addToolStripMenuItem.Text               = Translate.GetMessage("add");
     deleteToolStripMenuItem.Text            = Translate.GetMessage("delete");
     analysisToolStripMenuItem.Text          = Translate.GetMessage("analysis");
     changeAccountToolStripMenuItem.Text     = Translate.GetMessage("change-account");
     periodListToolStripMenuItem.Text        = Translate.GetMessage("period-list");
     getcurrentvaluesToolStripMenuItem.Text  = Translate.GetMessage("get-current-values");
     getcurrentvaluesToolStripMenuItem1.Text = Translate.GetMessage("get-current-values");
     exitToolStripMenuItem.Text              = Translate.GetMessage("exit");
     notifyIcon.Text                         = Translate.GetMessage("stock-tracing");
     lblInformations.Text                    = Translate.GetMessage("information");
     lblInformation2.Text                    = Translate.GetMessage("information");
     label4.Text                             = $"{Translate.GetMessage("stock")} : ";
     label5.Text                             = $"{Translate.GetMessage("period")} : ";
     translateMessagesToolStripMenuItem.Text = Translate.GetMessage("translate-message");
     Text        = $"{Translate.GetMessage("stock-tracing")} - [{(period != null ? period.PeriodName : "")}]";
     label2.Text = $"{Translate.GetMessage("language")} : ";
     periodtransToolStripMenuItem.Text          = Translate.GetMessage("period-transaction-chart");
     addcurrentstockpriceToolStripMenuItem.Text = Translate.GetMessage("add-current-stock-price");
 }
예제 #5
0
        private void frmStockAnalysis_Load(object sender, EventArgs e)
        {
            var chartType = SeriesChartType.Spline;

            chartCurrentStock.Series.Clear();
            Series valueSeries = new Series();

            valueSeries.ChartType         = chartType;
            valueSeries.MarkerBorderColor = Color.MediumVioletRed;
            valueSeries.MarkerColor       = Color.MediumVioletRed;
            valueSeries.Color             = Color.Crimson;
            valueSeries.MarkerSize        = 5;
            valueSeries.MarkerStep        = 1;
            valueSeries.MarkerBorderWidth = 5;
            valueSeries.BorderWidth       = 3;
            valueSeries.MarkerStyle       = MarkerStyle.Circle;
            valueSeries.Name = Translate.GetMessage("value");

            foreach (var stockCurrent in Session.Entities.GetCurrentStocks().Where(c => c.StockCode == stock.StockCode))
            {
                DataPoint pointTotalConst = new DataPoint();
                pointTotalConst.SetValueXY(stockCurrent.UpdateDate.ToShortDateString(), stockCurrent.Price.ToMoneyStirng(2));
                pointTotalConst.ToolTip = $"{Session.DefaultAccount.MoneyType.MoneyTypeToString()} {stockCurrent.Price.ToMoneyStirng(2)} - {stockCurrent.UpdateDate.ToShortDateString()} {stockCurrent.UpdateDate.ToShortTimeString()}";
                valueSeries.Points.Add(pointTotalConst);
            }
            chartCurrentStock.Series.Add(valueSeries);
            series.Add(valueSeries);
        }
예제 #6
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);
     }
 }
예제 #7
0
        private bool validation()
        {
            bool result = true;

            if (string.IsNullOrEmpty(txtStockCode.Text))
            {
                result = false;
                errorProvider1.SetError(txtStockCode, Translate.GetMessage("cant-be-empty"));
            }

            decimal price;

            if (string.IsNullOrEmpty(txtCurrentPrice.Text))
            {
                result = false;
                errorProvider1.SetError(txtCurrentPrice, Translate.GetMessage("cant-be-empty"));
            }
            else if (!decimal.TryParse(txtCurrentPrice.Text, out price))
            {
                result = false;
                errorProvider1.SetError(txtCurrentPrice, Translate.GetMessage("enter-a-numerical-value"));
            }

            if (dtUpdateDate.Value > DateTime.Now)
            {
                result = false;
                errorProvider1.SetError(dtUpdateDate, Translate.GetMessage("updatedate-cannot-be-greater-than-the-now"));
            }

            return(result);
        }
예제 #8
0
        private void frmLogin_Load(object sender, EventArgs e)
        {
            try
            {
                Session.DefaultAccount     = null;
                cbRememberUserName.Checked = Session.Entities.GetSetting().RememberUserName;
                cbRememberPassword.Checked = Session.Entities.GetSetting().RememberPassword;
                passwordIsHash             = Session.Entities.GetSetting().RememberPassword;
                txtUserName.Text           = Session.Entities.GetSetting().UserName;
                if (Session.Entities.GetSetting().RememberPassword)
                {
                    txtPassword.Text = "PASSWORD";
                    passwordIsHash   = true;
                }

                if (Session.Entities.GetSetting().RememberUserName)
                {
                    txtPassword.Focus();
                }
                if (Session.Entities.GetSetting().RememberPassword)
                {
                    txtUserName.Focus();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Translate.GetMessage("error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #9
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);
                }
            }
        }
예제 #10
0
 private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show(Translate.GetMessage("delete-record"), Translate.GetMessage("delete"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     {
         Session.Entities.DeleteStockTransaction(int.Parse(lvList.SelectedItems[0].Text));
         refreshList();
     }
 }
예제 #11
0
 private void setTranslateMessage()
 {
     btnSave.Text      = Translate.GetMessage("save");
     label1.Text       = $"{Translate.GetMessage("account-name")} : ";
     btnCancel.Text    = Translate.GetMessage("cancel");
     cbSetDefault.Text = Translate.GetMessage("default-account");
     label4.Text       = $"{Translate.GetMessage("money-type")} : ";
     Text = Translate.GetMessage("account");
 }
예제 #12
0
 private void setTranslateMessage()
 {
     btnSave.Text   = Translate.GetMessage("save");
     label1.Text    = $"{Translate.GetMessage("language-code")} : ";
     btnCancel.Text = Translate.GetMessage("cancel");
     label2.Text    = $"{Translate.GetMessage("code")} : ";
     label3.Text    = $"{Translate.GetMessage("value")} : ";
     Text           = Translate.GetMessage("period");
 }
예제 #13
0
 private void setTranslateMessage()
 {
     btnSave.Text   = Translate.GetMessage("save");
     label1.Text    = $"{Translate.GetMessage("stock-code")} : ";
     btnCancel.Text = Translate.GetMessage("cancel");
     label2.Text    = $"{Translate.GetMessage("current-price")} : ";
     label3.Text    = $"{Translate.GetMessage("update-date")} : ";
     Text           = Translate.GetMessage("current-stock-information");
 }
예제 #14
0
        private void gridFill()
        {
            #region Grid
            foreach (var item in stockAnalysis.StockTransactions.OrderBy(c => c.Date))
            {
                var li = new ListViewItem();
                li.Text = item.StockTransactionId.ToString();
                if (item.TransactionType == Model.TransactionType.Buy)
                {
                    li.BackColor = Color.LightSkyBlue;
                    li.ForeColor = Color.Black;
                }
                else
                {
                    li.BackColor = Color.LightPink;
                    li.ForeColor = Color.Black;
                }

                li.SubItems.Add(new ListViewItem.ListViewSubItem()
                {
                    Name = "UnitPrice",
                    Text = item.UnitPrice.ToMoneyStirng(6)
                });
                li.SubItems.Add(new ListViewItem.ListViewSubItem()
                {
                    Name = "Amount",
                    Text = item.Amount.ToMoneyStirng(0)
                });
                li.SubItems.Add(new ListViewItem.ListViewSubItem()
                {
                    Name = "Total",
                    Text = (item.Amount * item.UnitPrice).ToMoneyStirng(2)
                });
                li.SubItems.Add(new ListViewItem.ListViewSubItem()
                {
                    Name = "Const",
                    Text = item.Const.ToMoneyStirng(2)
                });
                li.SubItems.Add(new ListViewItem.ListViewSubItem()
                {
                    Name = "TransactionType",
                    Text = item.TransactionType == Model.TransactionType.Buy ? Translate.GetMessage("buy") : Translate.GetMessage("sell")
                });
                li.SubItems.Add(new ListViewItem.ListViewSubItem()
                {
                    Name = "Date",
                    Text = item.Date.ToShortDateString()
                });

                lvList.Items.Add(li);
            }

            decimal totalConst = stockAnalysis.StockTransactions.Sum(c => c.Const);
            decimal gain       = stockAnalysis.StockTransactions.Sum(c => c.Amount * c.UnitPrice * (c.TransactionType == Model.TransactionType.Buy ? -1 : 1));
            lblInformations.Text = $"[{Translate.GetMessage("total-buy")}: {stockAnalysis.StockTransactions.Where(c => c.TransactionType == Model.TransactionType.Buy).Sum(c => c.Amount).ToMoneyStirng(0)}, {Translate.GetMessage("total-sell")}: {stockAnalysis.StockTransactions.Where(c => c.TransactionType == Model.TransactionType.Sell).Sum(c => c.Amount).ToMoneyStirng(0)}, {Translate.GetMessage("total-const")}: {totalConst.ToMoneyStirng(2)}, {Translate.GetMessage("gain")}: {(gain - totalConst).ToMoneyStirng(2)}]";
            #endregion
        }
예제 #15
0
 private void setTranslateMessage()
 {
     btnSave.Text     = Translate.GetMessage("save");
     label1.Text      = $"{Translate.GetMessage("period-name")} : ";
     btnCancel.Text   = Translate.GetMessage("cancel");
     label2.Text      = $"{Translate.GetMessage("start-date")} : ";
     label3.Text      = $"{Translate.GetMessage("end-date")} : ";
     Text             = Translate.GetMessage("period");
     lblIsPublic.Text = Translate.GetMessage("is-public");
 }
예제 #16
0
 private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show(Translate.GetMessage("delete-message"), Translate.GetMessage("delete"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     {
         string code = lvList.SelectedItems[0].Text;
         Session.Entities.GetTranslateMessages().RemoveAll(c => c.Code == code);
         Session.SaveChanges();
         refreshList();
     }
 }
예제 #17
0
 private void setTranslateMessage()
 {
     lblInformations.Text = Translate.GetMessage("information");
     UnitPrice.Text       = Translate.GetMessage("unit-price");
     Amount.Text          = Translate.GetMessage("amount");
     Const.Text           = Translate.GetMessage("const");
     Total.Text           = Translate.GetMessage("total");
     TransactionType.Text = Translate.GetMessage("transaction-type");
     Date.Text            = Translate.GetMessage("date");
 }
예제 #18
0
 private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show(Translate.GetMessage("delete-period"), Translate.GetMessage("delete"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     {
         int periodId = int.Parse(lvList.SelectedItems[0].Text);
         Session.Entities.DeletePeriod(periodId);
         Session.SaveChanges();
         refreshList();
     }
 }
예제 #19
0
 private void setTranslateMessage()
 {
     btnLogin.Text           = Translate.GetMessage("login");
     label1.Text             = $"{Translate.GetMessage("user-name")} : ";
     label2.Text             = $"{Translate.GetMessage("password")} : ";
     btnCreate.Text          = Translate.GetMessage("create");
     cbRememberUserName.Text = Translate.GetMessage("remember-user-name");
     cbRememberPassword.Text = Translate.GetMessage("remember-password");
     Text = Translate.GetMessage("login");
 }
예제 #20
0
 private void setTranslateMessage()
 {
     AccountName.Text = Translate.GetMessage("account-name");
     MoneyType.Text   = Translate.GetMessage("money-type");
     chooseAccountToolStripMenuItem.Text = Translate.GetMessage("choose-account");
     refreshToolStripMenuItem.Text       = Translate.GetMessage("refresh");
     editToolStripMenuItem.Text          = Translate.GetMessage("edit");
     addToolStripMenuItem.Text           = Translate.GetMessage("add");
     deleteToolStripMenuItem.Text        = Translate.GetMessage("delete");
     Text = Translate.GetMessage("bank-choose");
 }
예제 #21
0
 private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show($"{Translate.GetMessage("delete-account")}?", $"{Translate.GetMessage("delete")}?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     {
         int accountId = int.Parse(lvList.SelectedItems[0].Text);
         Session.User.Accounts.RemoveAll(c => c.AccountId == accountId);
         Session.Entities.DeleteAccount(accountId);
         Session.SaveChanges();
         refreshList();
     }
 }
예제 #22
0
 private void setTranslateMessage()
 {
     PeriodName.Text = Translate.GetMessage("period-name");
     StartDate.Text = Translate.GetMessage("start-date");
     EndDate.Text = Translate.GetMessage("end-date");
     editToolStripMenuItem.Text = Translate.GetMessage("edit");
     addToolStripMenuItem.Text = Translate.GetMessage("add");
     deleteToolStripMenuItem.Text = Translate.GetMessage("delete");
     refreshToolStripMenuItem.Text = Translate.GetMessage("refresh");
     Text = Translate.GetMessage("period-list");
 }
예제 #23
0
 private void setTranslateMessage()
 {
     btnSave.Text            = Translate.GetMessage("save");
     label1.Text             = $"{Translate.GetMessage("user-name")} : ";
     btnCancel.Text          = Translate.GetMessage("cancel");
     cbIsActive.Text         = Translate.GetMessage("is-active");
     label2.Text             = $"{Translate.GetMessage("password")} : ";
     label3.Text             = $"{Translate.GetMessage("confirm-password")} : ";
     lblCurrentPassword.Text = $"{Translate.GetMessage("current-password")} : ";
     Text = Translate.GetMessage("user");
 }
예제 #24
0
 private void setTranslateMessage()
 {
     PeriodName.Text               = Translate.GetMessage("language-code");
     StartDate.Text                = Translate.GetMessage("code");
     EndDate.Text                  = Translate.GetMessage("value");
     editToolStripMenuItem.Text    = Translate.GetMessage("edit");
     addToolStripMenuItem.Text     = Translate.GetMessage("add");
     deleteToolStripMenuItem.Text  = Translate.GetMessage("delete");
     refreshToolStripMenuItem.Text = Translate.GetMessage("refresh");
     Text        = Translate.GetMessage("period-list");
     label2.Text = $"{Translate.GetMessage("language")} : ";
 }
 private void txtAmount_Leave(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(txtAmount.Text))
     {
         errorProvider1.SetError(txtAmount, Translate.GetMessage("cant-be-empty"));
     }
     else if (!decimal.TryParse(txtAmount.Text, out amount))
     {
         errorProvider1.SetError(txtAmount, Translate.GetMessage("enter-a-numerical-value"));
     }
     else
     {
         calculateTotalPrice();
     }
 }
예제 #26
0
 private void setTranslateMessage()
 {
     Text                    = Translate.GetMessage("period-gain-list");
     cbConst.Text            = Translate.GetMessage("const");
     cbExceptedGain.Text     = Translate.GetMessage("expected-gain");
     cbGain.Text             = Translate.GetMessage("gain");
     const1.Text             = Translate.GetMessage("const");
     gain.Text               = Translate.GetMessage("gain");
     period.Text             = Translate.GetMessage("period");
     endOfDay.Text           = Translate.GetMessage("end-of-day");
     expectedGain.Text       = Translate.GetMessage("expected-gain");
     cumulativeEndOfDay.Text = Translate.GetMessage("end-of-period");
     tabGraphich.Text        = Translate.GetMessage("graphic");
     tabGrid.Text            = Translate.GetMessage("grid");
 }
        private bool validation()
        {
            decimal amount;
            decimal unitPrice;
            bool    result = true;

            if (string.IsNullOrEmpty(cbType.Text))
            {
                result = false;
                errorProvider1.SetError(cbType, Translate.GetMessage("cant-be-empty"));
            }

            if (string.IsNullOrEmpty(txtAmount.Text))
            {
                result = false;
                errorProvider1.SetError(txtAmount, Translate.GetMessage("cant-be-empty"));
            }
            else if (!decimal.TryParse(txtAmount.Text, out amount))
            {
                result = false;
                errorProvider1.SetError(txtAmount, Translate.GetMessage("enter-a-numerical-value"));
            }

            if (string.IsNullOrEmpty(txtUnitPrice.Text))
            {
                result = false;
                errorProvider1.SetError(txtUnitPrice, Translate.GetMessage("cant-be-empty"));
            }
            else if (!decimal.TryParse(txtUnitPrice.Text, out unitPrice))
            {
                result = false;
                errorProvider1.SetError(txtUnitPrice, Translate.GetMessage("enter-a-numerical-value"));
            }

            if (string.IsNullOrEmpty(txtStockCode.Text))
            {
                result = false;
                errorProvider1.SetError(txtStockCode, Translate.GetMessage("cant-be-empty"));
            }

            if (string.IsNullOrEmpty(txtStockName.Text))
            {
                result = false;
                errorProvider1.SetError(txtStockName, Translate.GetMessage("cant-be-empty"));
            }

            return(result);
        }
        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();
            }
        }
 private void setTranslateMessage()
 {
     btnSave.Text = Translate.GetMessage("save");
     label1.Text  = $"{Translate.GetMessage("stock-code")} : ";
     label2.Text  = $"{Translate.GetMessage("stock-name")} : ";
     label3.Text  = $"{Translate.GetMessage("amount")} : ";
     label4.Text  = $"{Translate.GetMessage("type")} : ";
     cbType.Items.AddRange(new object[] {
         Translate.GetMessage("buy"),
         Translate.GetMessage("sell")
     });
     label5.Text    = $"{Translate.GetMessage("date")} : ";
     label6.Text    = $"{Translate.GetMessage("unit-price")} : ";
     label7.Text    = $"{Translate.GetMessage("total-price")} : ";
     btnCancel.Text = Translate.GetMessage("cancel");
     Text           = Translate.GetMessage("stock-transaction");
 }
예제 #30
0
 private void setTranslateMessage()
 {
     lblInformations.Text          = Translate.GetMessage("information");
     refreshToolStripMenuItem.Text = Translate.GetMessage("refresh");
     deleteToolStripMenuItem.Text  = Translate.GetMessage("delete");
     addToolStripMenuItem.Text     = Translate.GetMessage("add");
     editToolStripMenuItem.Text    = Translate.GetMessage("edit");
     StockCode.Text   = Translate.GetMessage("stock-code");
     Status.Text      = Translate.GetMessage("status");
     TotalAmount.Text = Translate.GetMessage("total-amount");
     BuyPrice.Text    = Translate.GetMessage("buy-price");
     SellPrice.Text   = Translate.GetMessage("sell-price");
     Gain.Text        = Translate.GetMessage("gain");
     TotalValue.Text  = Translate.GetMessage("total-value");
     Text             = Translate.GetMessage("stock-analysis");
     Date.Text        = Translate.GetMessage("date");
 }