Ejemplo n.º 1
0
        private void btnLogOn_Click(object sender, EventArgs e)
        {
            string account  = txtAccount.Text.Trim();
            string password = txtPassword.Text.Trim();

            password = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(password, "SHA1");

            member = memberModel.LogOncheck(account, password);

            if (member != null)
            {
                this.txtAccount.Text  = "";
                this.txtPassword.Text = "";
                FrmHomePage frm = new FrmHomePage();
                frm.Tag = member;

                if (this.cbox.Checked)
                {
                    this.txtAccount.Text = member.account;
                }
                else
                {
                    this.txtAccount.Text = "";
                }
                frm.ShowDialog();
            }
            else
            {
                MessageBox.Show("請重新輸入帳號或密碼", "登入訊息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
        }
Ejemplo n.º 2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                members member = this.member;

                if (string.IsNullOrEmpty(this.txtNum.Text) || this.txtNum.Text == "0")
                {
                    MessageBox.Show("請輸入賣出張數!!");
                    this.txtMoney.Text = "0";
                    return;
                }
                else if (int.Parse(this.txtNum.Text) > int.Parse(buttonRow.Cells[6].Value.ToString()))
                {
                    MessageBox.Show("賣出張數超出庫存張數@@,請重新輸入!!");
                    this.txtNum.Text   = "";
                    this.txtMoney.Text = "0";
                    return;
                }
                else
                {
                    MessageBox.Show("賣出成功!!");
                }

                //賣出張數,修改資料表
                if (int.Parse(this.txtNum.Text) == int.Parse(buttonRow.Cells[6].Value.ToString()))
                {
                    stocksave save = db.stocksave.AsEnumerable().Where(s => s.證券代號 == buttonRow.Cells[3].Value.ToString() && s.account == member.account).FirstOrDefault();
                    datamodel.Delete(save);
                    stockremain remain = db.stockremain.AsEnumerable().Where(r => r.證券代號 == buttonRow.Cells[3].Value.ToString() && r.account == member.account).FirstOrDefault();
                    datamodel.Delete(remain);
                }
                else if (int.Parse(this.txtNum.Text) < int.Parse(buttonRow.Cells[6].Value.ToString()))
                {
                    stocksave save = db.stocksave.AsEnumerable().Where(s => s.證券代號 == buttonRow.Cells[3].Value.ToString() && s.account == member.account).FirstOrDefault();

                    datamodel.Updatestocksave(save, int.Parse(this.txtNum.Text));

                    stockremain remainsave = db.stockremain.AsEnumerable().Where(r => r.證券代號 == buttonRow.Cells[3].Value.ToString() && r.account == member.account).FirstOrDefault();
                    datamodel.Updatestockremain(remainsave, int.Parse(this.txtNum.Text));
                }

                double remainmoney = (double)member.bankmoney + double.Parse(txtMoney.Text);

                member.bankmoney = (int)remainmoney;
                var mem = (from m in db.members
                           where m.account == member.account
                           select m).FirstOrDefault();

                if (mem == null)
                {
                    return;
                }
                mem.bankmoney = member.bankmoney;
                db.SaveChanges();

                //frmHomePage傳值
                FrmHomePage frmHomePage = this.frmHomePage;
                frmHomePage.lblbankmoney.Text = member.bankmoney.ToString();
                frmHomePage.lblmoney.Text     = member.bankmoney.ToString();
                frmHomePage.lblbank.Text      = member.bankmoney.ToString();

                //frmHomePage.dataGridView3.DataSource = null;
                //frmHomePage.dataGridView4.DataSource = null;
                frmHomePage.dataGridView4.DataSource            = db.stockremain.Where(s => s.account == member.account).ToList();
                frmHomePage.dataGridView4.Columns["id"].Visible = false;
                frmHomePage.dataGridView3.DataSource            = db.stocksave.Where(s => s.account == member.account).ToList();
                frmHomePage.dataGridView3.Columns["id"].Visible = false;

                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 3
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                //member傳值
                members member = this.member;

                if (string.IsNullOrEmpty(this.txtNum.Text) || this.txtNum.Text == "0")
                {
                    MessageBox.Show("請輸入購買張數!!");
                    this.txtMoney.Text = "0";
                    return;
                }
                else if (double.Parse(txtMoney.Text) > member.bankmoney)
                {
                    MessageBox.Show("買進總金額超過帳戶金額QQ,請重新輸入!!");
                    this.txtNum.Text   = "";
                    this.txtMoney.Text = "0";
                    return;
                }
                else
                {
                    MessageBox.Show("買入成功!!");
                }

                double remainmoney = (double)member.bankmoney - double.Parse(txtMoney.Text);

                member.bankmoney = (int)remainmoney;
                var mem = (from m in db.members
                           where m.account == member.account
                           select m).FirstOrDefault();

                if (mem == null)
                {
                    return;
                }
                mem.bankmoney = member.bankmoney;
                db.SaveChanges();

                //frmHomePage傳值
                FrmHomePage frmHomePage = this.frmHomePage;
                frmHomePage.lblbankmoney.Text = member.bankmoney.ToString();
                frmHomePage.lblmoney.Text     = member.bankmoney.ToString();
                frmHomePage.lblbank.Text      = member.bankmoney.ToString();

                //存入我的庫存 stocksave
                stock.account = this.txtAccount.Text;
                stock.證券代號    = this.txtStocknum.Text;
                stock.證券名稱    = this.txtStockName.Text;
                stock.買進價格    = this.txtPrice.Text;
                stock.張數      = this.txtNum.Text;
                stock.總金額     = this.txtMoney.Text;

                db.stocksave.Add(stock);

                db.SaveChanges();


                //取得收盤價,存入未實現損益
                var price = (from d in db.data
                             join s in db.stocksave.Where(s => s.account == member.account)
                             on d.證券代號 equals s.證券代號
                             select d.收盤價).ToList();

                stockRemain.account = member.account;
                stockRemain.證券代號    = stock.證券代號;
                stockRemain.證券名稱    = stock.證券名稱;
                stockRemain.成交均價    = stock.買進價格;
                stockRemain.張數      = stock.張數;
                stockRemain.持有成本    = stock.總金額;
                for (int i = 0; i < price.Count(); i++)
                {
                    var code = (from d in db.data
                                join s in db.stocksave.Where(s => s.account == member.account)
                                on d.證券代號 equals s.證券代號
                                select d.證券代號).ToList();
                    if (stockRemain.證券代號 == code[i])
                    {
                        stockRemain.現價 = price[i].ToString();
                    }
                }

                stockRemain.現值    = (double.Parse(stockRemain.現價) * double.Parse(stock.張數.ToString()) * number).ToString();
                stockRemain.預估收入  = (double.Parse(stockRemain.現價) * double.Parse(stock.張數.ToString()) * number).ToString();
                stockRemain.預估損益  = (double.Parse(stockRemain.預估收入) - double.Parse(stockRemain.持有成本)).ToString();
                stockRemain.預估獲利率 = ((double.Parse(stockRemain.預估損益) / double.Parse(stockRemain.持有成本)) * 100).ToString("f2") + "%";

                db.stockremain.Add(stockRemain);
                db.SaveChanges();

                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }