Пример #1
0
        public List <UsersData> GetUserdata(string username)
        {
            MyInvestEntities db = new MyInvestEntities();
            var userdata        = db.UsersData.Where(c => c.UserName == username).ToList();

            return(userdata);
        }
Пример #2
0
        //
        public JsonResult Getmoney()
        {
            var db  = new MyInvestEntities();
            var ret = from c in db.CurrencyRate
                      select c;
            dynamic retObject = new { data = ret.ToList() };

            return(Json(retObject, JsonRequestBehavior.AllowGet));
        }
Пример #3
0
        //public IHttpActionResult Getlist()
        public object Getmoney()
        {
            var db  = new MyInvestEntities();
            var ret = from c in db.CurrencyRate
                      select c;
            dynamic retObject = new { data = ret.ToList() };

            return(retObject);
        }
Пример #4
0
        public JsonResult Getnowfc()
        {
            var rec = this.Request.QueryString.ToString();
            var db  = new MyInvestEntities();
            var ret = db.CurrencyRate.Where(c => c.CurrencyClass == rec).Select(c => c.OnlineSell);

            //var ret = from c in db.CurrencyRate
            //          where c.CurrencyClass.Contains(rec)
            //          select c.OnlineSell;
            return(Json(ret, JsonRequestBehavior.AllowGet));
        }
Пример #5
0
        public ActionResult Login(LoginViewModel model)
        {
            //if (String.IsNullOrEmpty(model.UserName))
            //{
            //    ModelState.AddModelError("UserName", "不可為空");
            //}

            //if (String.IsNullOrEmpty(model.Password))
            //{
            //    ModelState.AddModelError("Password", "不可為空");
            //}

            MyInvestEntities db = new MyInvestEntities();

            //登入密碼雜湊
            byte[]        enc = System.Text.Encoding.Default.GetBytes(model.Password);
            HashAlgorithm ha  = HashAlgorithm.Create("SHA256");

            byte[] ans = ha.ComputeHash(enc);

            model.Password = BitConverter.ToString(ans);

            var loginer = db.UsersData.Where(c => model.UserName == c.UserName && model.Password == c.Password).FirstOrDefault();

            var inputcc = model.CheckCode.ToUpper();

            if (Session["cc"].ToString() != inputcc)
            {
                TempData["status"] = "登入碼輸入錯誤";
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                if (loginer != null)
                {
                    if (model.UserName == "msit119")
                    {
                        Session["User"] = model.UserName;
                        return(RedirectToRoute("BStage_default", new { Controller = "BS", Action = "Index" }));
                    }
                    else
                    {
                        Session["User"] = model.UserName;
                        //return RedirectToAction("About","Home", new { Area = "Main"});
                        return(RedirectToRoute("Main_default", new { Controller = "Home", Action = "Index" }));
                    }
                }
                else
                {
                    TempData["status"] = "登入失敗";
                    return(RedirectToAction("Index", "Home"));
                }
            }
        }
Пример #6
0
        public decimal GetAvg(string username, string searchid, int invchange, int cashflow)
        {
            MyInvestEntities db = new MyInvestEntities();
            //var username = stockHistory.SummaryTable.UserName;
            //var searchid = stockHistory.stockID;
            //var invchange = (int)stockHistory.stockAmount;
            decimal avg = 0;
            //計算總剩餘庫存量
            //假設invsum+invchange !=0 (賣出數量一定不會超過庫存量)
            var Invsum = db.StockHistory.Where(m => m.stockID == searchid & m.SummaryTable.UserName == username).Sum(s => s.stockAmount);
            var _sum   = Invsum + invchange;

            Invsum = (_sum != null) ? (_sum) : (invchange);   //(結果:0、大於0)
            if (Invsum > 0)
            {
                if (Invsum > invchange)   //過去有該檔股票,且就算賣出也不會賣到光
                {
                    //買進記錄按日期排序
                    var     BuyList   = db.StockHistory.Where(m => m.stockID == searchid & m.stockAmount > 0).OrderByDescending(t => t.SummaryTable.TradeDate).ToArray();
                    Decimal TotalCost = 0;
                    TotalCost = (invchange >= 0) ? (decimal)(cashflow * (-1)) : 0;  //如果買進則初始值為此筆成本,如果為賣出則初始值為0
                    int _tempinv = 0;
                    _tempinv = (invchange >= 0) ? (int)(Invsum - invchange) : (int)Invsum;

                    foreach (var item in BuyList)
                    {
                        int iteminv = (int)item.stockAmount;
                        if (iteminv <= _tempinv)
                        {
                            TotalCost = (Decimal)(TotalCost + item.stockNetincome * (-1));
                            _tempinv  = _tempinv - iteminv;
                        }
                        else
                        {
                            TotalCost = TotalCost + (Decimal)(_tempinv * (item.stockNetincome / item.stockAmount) * (-1));
                            break;
                        }
                    }
                    avg = (decimal)(TotalCost / Invsum);
                    return(avg);
                }
                else //新增持股
                {
                    avg = (decimal)(cashflow * (-1) / invchange);
                    return(avg);
                }
            }
            else    //賣出持股後庫存為0
            {
                avg = 0;
                return(avg);
            }
        }
Пример #7
0
        public IHttpActionResult Getnowfc()
        {
            //取得前端傳來的body內容
            var body = Request.Content.ReadAsStringAsync().Result;
            //將字串的JSON轉為rec物件
            var rec = Newtonsoft.Json.JsonConvert.DeserializeObject <String>(body);
            //新增資料庫資料
            var db  = new MyInvestEntities();
            var ret = from c in db.CurrencyRate
                      where c.CurrencyClass.Contains(rec)
                      select c.OnlineSell;

            return(Ok(ret));
        }
Пример #8
0
        public ActionResult Register(UsersData model)
        {
            MyInvestEntities db = new MyInvestEntities();

            var member = db.UsersData.Where(c => c.UserName == model.UserName || c.Email == model.Email).FirstOrDefault();

            //if (member == null)
            //{
            //雜湊
            byte[]        enc = System.Text.Encoding.Default.GetBytes(model.Password);
            HashAlgorithm ha  = HashAlgorithm.Create("SHA256");

            byte[] ans = ha.ComputeHash(enc);

            model.Password = BitConverter.ToString(ans);

            model.CashValue      = 0;
            model.StockValue     = 0;
            model.FXValue        = 0;
            model.InsuranceValue = 0;
            model.FundValue      = 0;

            //將會員記錄新增到Users資料表
            db.UsersData.Add(model);

            //儲存資料庫變更
            try
            {
                db.SaveChanges();
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException ex)
            {
                throw ex;
            }

            Session["User"] = model.UserName;

            if (Session["User"].ToString() == "msit119")
            {
                return(RedirectToRoute("BStage_default", new { Controller = "BS", Action = "Index" }));
            }

            //執行Home控制器的Login動作方法
            return(RedirectToRoute("Main_default", new { Controller = "Home", Action = "Index" }));
        }
Пример #9
0
        public ActionResult ChangePasswordAdmin(ChangePasswordViewModel model)
        {
            //if (ModelState.IsValid)
            //{
            MyInvestEntities db = new MyInvestEntities();

            byte[]        enc = System.Text.Encoding.Default.GetBytes(model.OPassword);
            HashAlgorithm ha  = HashAlgorithm.Create("SHA256");

            byte[] ans = ha.ComputeHash(enc);

            model.OPassword = BitConverter.ToString(ans);

            var item = db.UsersData.Where(c => c.Password == model.OPassword).FirstOrDefault();


            if (item != null)
            {
                byte[] nenc = System.Text.Encoding.Default.GetBytes(model.Password);
                byte[] nans = ha.ComputeHash(nenc);

                model.Password = BitConverter.ToString(nans);

                item.Password   = model.Password;
                item.RememberMe = true;

                try
                {
                    db.SaveChanges();
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException ex)
                {
                    throw ex;
                }

                return(RedirectToAction("Admin", "Account"));
            }
            else
            {
                ViewBag.Message = "原密碼錯誤";
                return(View("Index2"));
            }
        }
Пример #10
0
        public decimal GetAvg2(string username, string searchid)
        {
            MyInvestEntities db = new MyInvestEntities();
            var Invsum          = db.StockHistory.Where(m => m.stockID == searchid & m.SummaryTable.UserName == username).Sum(s => s.stockAmount);

            Invsum = (Invsum != null) ? Invsum : 0;

            //買進記錄按日期排序
            var BuyList = db.StockHistory.Where(m => m.stockID == searchid & m.stockAmount > 0).OrderByDescending(t => t.SummaryTable.TradeDate).ToArray();

            Decimal TotalCost = 0;
            Decimal _tempinv  = (Decimal)Invsum;

            if (Invsum > 0)
            {
                //從近一筆開始累加
                foreach (var item in BuyList)
                {
                    Decimal iteminv = (Decimal)item.stockAmount;
                    if (iteminv <= _tempinv)
                    {
                        TotalCost = (Decimal)(TotalCost + item.stockNetincome * (-1));
                        _tempinv  = _tempinv - iteminv;
                    }
                    else
                    {
                        TotalCost = TotalCost + (Decimal)(_tempinv * (item.stockNetincome / item.stockAmount) * (-1));
                        break;
                    }
                }
                Decimal Avgcost = (Decimal)(TotalCost / (Invsum));

                return(Avgcost);
            }
            else
            {
                Decimal Avgcost = 0;

                //回傳無庫存

                return(Avgcost);
            }
        }
Пример #11
0
        public ActionResult Create([Bind(Include = "TradeType,date,userID")] SummaryTable summaryTable, [Bind(Include = "stockID,stockPrice,stockAmount,stockTP,stockFee,stockTax,stockNetincome,stockNote")] StockHistory stockHistory)
        // public ActionResult Create([Bind(Include = "TradeType,userID,date")]SummaryTable summaryTable)
        {
            MyInvestEntities db = new MyInvestEntities();

            if (ModelState.IsValid)
            {
                summaryTable.UserName = Session["User"].ToString();

                db.SummaryTable.Add(summaryTable);
                db.SaveChanges();

                var id = db.SummaryTable.Select(c => c.STId).ToList().LastOrDefault();
                stockHistory.STId = id;
                db.StockHistory.Add(stockHistory);
                db.SaveChanges();
                ViewBag.state = "ok";
                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("Index"));
        }
Пример #12
0
        public decimal getPVsum(string username)
        {
            MyInvestEntities db = new MyInvestEntities();
            var InvList         = db.StockHistory.Where(c => c.SummaryTable.UserName == username).GroupBy(c => c.stockID, c => new InvViewModel
            {
                amount = c.stockAmount,
                pv     = c.Stock_data.收盤價
            }, (id, invVM) => new
            {
                stockamount = invVM.Select(c => c.amount).Sum(),
                stockpv     = invVM.Select(c => c.pv).FirstOrDefault(),
            });
            decimal totalpv = 0;

            foreach (var item in InvList)
            {
                totalpv = (Convert.ToDecimal(item.stockamount)) * (Convert.ToDecimal(item.stockpv));
            }


            return(totalpv);
        }
Пример #13
0
        public ActionResult ForgotPassword(ForgotPasswordViewModel model)
        {
            //if (ModelState.IsValid)
            //{
            MyInvestEntities db = new MyInvestEntities();

            var item = db.UsersData.Where(c => (c.UserName == model.UserName && c.Email == model.Email)).FirstOrDefault();

            if (item != null)
            {
                Random r = new Random();

                string code = "";

                for (int i = 0; i < 10; ++i)
                {
                    switch (r.Next(0, 3))
                    {
                    //數字0~9
                    case 0: code += r.Next(0, 10); break;

                    //小寫a-z
                    case 1: code += (char)r.Next(65, 91); break;

                    //大寫A-Z
                    case 2: code += (char)r.Next(97, 122); break;
                    }
                }

                System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
                msg.To.Add(model.Email);
                //msg.CC.Add("*****@*****.**");可以抄送副本給多人
                //這裡可以隨便填,不是很重要
                msg.From = new MailAddress("*****@*****.**", "$$$", System.Text.Encoding.UTF8);
                /* 上面3個參數分別是發件人地址(可以隨便寫),發件人姓名,編碼*/
                msg.Subject         = "測試標題";                    //郵件標題
                msg.SubjectEncoding = System.Text.Encoding.UTF8; //郵件標題編碼
                msg.Body            = $"新密碼為:<span style='color:red'>{code}</span><br> 請依此登入重新設定密碼!";
                //郵件內容
                msg.BodyEncoding = System.Text.Encoding.UTF8; //郵件內容編碼
                                                              //msg.Attachments.Add(new Attachment(@"D:\test2.docx"));  //附件
                msg.IsBodyHtml = true;                        //是否是HTML郵件
                                                              //msg.Priority = MailPriority.High;//郵件優先級

                SmtpClient client = new SmtpClient();
                client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "msit1199"); //這裡要填正確的帳號跟密碼
                client.Host        = "smtp.gmail.com";                                                            //設定smtp Server
                client.Port        = 25;                                                                          //設定Port
                client.EnableSsl   = true;                                                                        //gmail預設開啟驗證
                client.Send(msg);                                                                                 //寄出信件
                client.Dispose();
                msg.Dispose();

                //System.Timers.Timer timer = new System.Timers.Timer();

                //timer.Enabled = true;
                //timer.Interval = 3000000; // 5分鐘後驗證碼失效
                //timer.Start();
                //timer.Elapsed += Timer_Elapsed;
                //timer.AutoReset = false;

                //return RedirectToAction("ConfirmEmail","Account");

                byte[]        enc = System.Text.Encoding.Default.GetBytes(code);
                HashAlgorithm ha  = HashAlgorithm.Create("SHA256");
                byte[]        ans = ha.ComputeHash(enc);

                item.Password = BitConverter.ToString(ans);

                //item.Password = code;

                try
                {
                    db.SaveChanges();
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException ex)
                {
                    throw ex;
                }
                TempData["Request"]  = "已於Email寄出新密碼";
                TempData["Request2"] = "請以新密碼登入並修改密碼";
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                ViewBag.Message = "查無此人,請確認使用者名稱或Email正確";
                //return View("Index2");
                return(View());
            }
        }
Пример #14
0
        public ActionResult ConfirmEmail(RegisterViewModel model)
        {
            MyInvestEntities db = new MyInvestEntities();

            var nr = db.UsersData.Where(c => model.UserName == c.UserName || model.Email == c.Email);

            if (nr.Count() > 0)
            {
                return(Content("Existed"));
            }
            else
            {
                Random r = new Random();

                string code = "";

                for (int i = 0; i < 5; ++i)
                {
                    switch (r.Next(0, 3))
                    {
                    //數字0~9
                    case 0: code += r.Next(0, 10); break;

                    //小寫a-z
                    case 1: code += (char)r.Next(65, 91); break;

                    //大寫A-Z
                    case 2: code += (char)r.Next(97, 122); break;
                    }
                }

                cCode = code;

                System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
                msg.To.Add(model.Email);
                //msg.CC.Add("*****@*****.**");可以抄送副本給多人
                //這裡可以隨便填,不是很重要
                msg.From = new MailAddress("*****@*****.**", "$$$", System.Text.Encoding.UTF8);
                /* 上面3個參數分別是發件人地址(可以隨便寫),發件人姓名,編碼*/
                msg.Subject         = "測試標題";                    //郵件標題
                msg.SubjectEncoding = System.Text.Encoding.UTF8; //郵件標題編碼
                msg.Body            = "驗證碼為:" + "<span style='color:red'>" + code + "</span>";
                //郵件內容
                msg.BodyEncoding = System.Text.Encoding.UTF8; //郵件內容編碼
                                                              //msg.Attachments.Add(new Attachment(@"D:\test2.docx"));  //附件
                msg.IsBodyHtml = true;                        //是否是HTML郵件
                                                              //msg.Priority = MailPriority.High;//郵件優先級

                SmtpClient client = new SmtpClient();
                client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "msit1199"); //這裡要填正確的帳號跟密碼
                client.Host        = "smtp.gmail.com";                                                            //設定smtp Server
                client.Port        = 25;                                                                          //設定Port
                client.EnableSsl   = true;                                                                        //gmail預設開啟驗證
                client.Send(msg);                                                                                 //寄出信件
                client.Dispose();
                msg.Dispose();


                System.Timers.Timer timer = new System.Timers.Timer();

                timer.Enabled  = true;
                timer.Interval = 3000000; // 5分鐘後驗證碼失效
                timer.Start();
                timer.Elapsed  += Timer_Elapsed;
                timer.AutoReset = false;

                //return RedirectToAction("ConfirmEmail", "Account");

                return(Content(code));
            }
        }
Пример #15
0
        public ActionResult IndexFund()
        {
            MyInvestEntities db = new MyInvestEntities();

            return(View());
        }