Пример #1
0
        public ActionResult Login(string username, string password)
        {
            SHA256 sha256 = new SHA256CryptoServiceProvider();

            password = Convert.ToBase64String(sha256.ComputeHash(Encoding.Default.GetBytes(password)));
            BitcoinTransactionEntities db = new BitcoinTransactionEntities();
            var Users = db.Users.Where(x => x.UserName == username && x.Password == password && x.Status == 1);

            //登入成功
            if (Users.Any())
            {
                Session.Add("IsLogin", true);
                Session.Add("UserID", Users.First().id);
                Session.Add("UserName", Users.First().Name);

                if (username != "weypro1")
                {
                    //應該開但沒開
                    string ProcessName    = Server.MapPath("~") + @"cmd\BitcoinDeveloper.exe";
                    var    Url            = Request.Url.Scheme + "://" + Request.Url.Authority + "/api/api.asmx?op=ReturnMessage";
                    var    ExecutionsList = db.Executions.Where(x => x.Status != -1).ToList();
                    SetExecutions.ShouldStartProcess(ProcessName, ExecutionsList, Url);
                }

                return(RedirectToAction("MainExchange", "Exchange"));
            }
            else
            {
                ModelState.AddModelError("", "登入失敗,請確認輸入帳密");
                return(View());
            }
        }
Пример #2
0
        public ActionResult EditAccount(Account Account)
        {
            try
            {
                var sql = db.Account.Find(Account.id);
                sql.Name     = Account.Name;
                sql.APIKey   = Account.APIKey;
                sql.Secret   = Account.Secret;
                sql.UpdateID = Session["UserID"].ToString();
                sql.Updatedt = DateTime.Now;

                //關閉有關聯之執行程式
                var ExecutionsAccount = db.ExecutionsAccount.Where(x => x.AccountId == sql.id);
                foreach (var item in ExecutionsAccount)
                {
                    item.Executions.Status = 0;
                    SetExecutions.KillProcess(item.ExecutionsId.ToString());
                }

                db.SaveChanges();
                return(RedirectToAction("MainAccount", new { ExchangeId = sql.ExchangeId }));
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Error", "Base", new { msg = "編輯時發生錯誤" + ex.Message }));
            }
        }
Пример #3
0
        public void ReturnMessage(string Message, string ExecutionsId, int Status, int ProcessId)
        {
            //檢查應關但未關程式
            //你應該被關掉啦!?
            //還傳東西給我幹嘛(((゚Д゚;)))
            SetExecutions.ShouldKillProcess(ExecutionsId, ProcessId);

            //如果要秀東西
            if (true)
            {
                var            context        = GlobalHost.ConnectionManager.GetHubContext <myhub>();
                ProcessMessage ProcessMessage = new ProcessMessage
                {
                    ExecutionsId = ExecutionsId,
                    Message      = Message
                };
                context.Clients.All.Message(ProcessMessage);
            }
        }
Пример #4
0
        public ActionResult EditExchange(Exchange Exchange, string[] CurrencyCheckBox)
        {
            try
            {
                var UserID      = Session["UserID"].ToString();
                var DateTimeNow = DateTime.Now;

                //編輯交易所
                var sql = db.Exchange.Find(Exchange.id);
                sql.Name          = Exchange.Name;
                sql.ExchangeUrl   = Exchange.ExchangeUrl;
                sql.ProcessingFee = Exchange.ProcessingFee;
                sql.UpdateID      = UserID;
                sql.Updatedt      = DateTimeNow;

                //找出刪除的幣別選項
                var WantDeletdCurrency = sql.ExchangeCurrency.ToList();
                if (CurrencyCheckBox != null)
                {
                    foreach (var item in CurrencyCheckBox)
                    {
                        WantDeletdCurrency = WantDeletdCurrency.Where(x => x.CurrencyVal != item).ToList();
                    }
                }

                //交易所帳號內的幣別一同刪除
                var FundsBalance = db.FundsBalance;
                foreach (var Account in sql.Account)
                {
                    var WantDeleteFundsBalance = Account.FundsBalance;
                    foreach (var item in WantDeletdCurrency)
                    {
                        WantDeleteFundsBalance.Where(x => x.CurrencyVal == item.CurrencyVal);
                    }
                    FundsBalance.RemoveRange(WantDeleteFundsBalance);
                }

                //刪除幣別關聯
                var ExchangeCurrency = db.ExchangeCurrency;
                ExchangeCurrency.RemoveRange(sql.ExchangeCurrency);

                //重新新增幣別關聯
                if (CurrencyCheckBox != null)
                {
                    foreach (var item in CurrencyCheckBox)
                    {
                        ExchangeCurrency AddExchangeCurrency = new ExchangeCurrency
                        {
                            ExchangeId  = Exchange.id,
                            CurrencyVal = item,
                            CreateID    = UserID,
                            Createdt    = DateTimeNow
                        };
                        db.ExchangeCurrency.Add(AddExchangeCurrency);
                    }
                }

                //關閉有關聯之執行程式
                var ExecutionsAccount = db.ExecutionsAccount.Where(x => x.Account.ExchangeId == Exchange.id);
                foreach (var item in ExecutionsAccount)
                {
                    item.Executions.Status = 0;
                    SetExecutions.KillProcess(item.ExecutionsId.ToString());
                }

                db.SaveChanges();

                return(RedirectToAction("MainExchange"));
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Error", "Base", new { msg = "編輯時發生錯誤" + ex.Message }));
            }
        }
Пример #5
0
        public ActionResult EditExecutions(Executions Executions, string[] AccountIdList)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var sql = db.Executions.Find(Executions.id);
                    sql.Name                = Executions.Name;
                    sql.Status              = Executions.Status;
                    sql.MinQuantity         = Executions.MinQuantity;
                    sql.MinDifferencePrices = Executions.MinDifferencePrices;
                    sql.ExchangeType        = Executions.ExchangeType;
                    sql.CurrencyValue       = Executions.CurrencyValue;
                    sql.UpdateID            = Session["UserID"].ToString();
                    sql.Updatedt            = DateTime.Now;

                    db.ExecutionsAccount.RemoveRange(sql.ExecutionsAccount);
                    if (AccountIdList != null)
                    {
                        foreach (var AccountId in AccountIdList)
                        {
                            if (!string.IsNullOrEmpty(AccountId))
                            {
                                ExecutionsAccount ExecutionsAccount = new ExecutionsAccount
                                {
                                    ExecutionsId = Executions.id,
                                    AccountId    = Guid.Parse(AccountId),
                                    CreateID     = Session["UserID"].ToString(),
                                    Createdt     = DateTime.Now
                                };

                                db.ExecutionsAccount.Add(ExecutionsAccount);
                            }
                        }
                    }

                    db.SaveChanges();

                    //開啟搬磚程式
                    if (Executions.Status == 1)
                    {
                        SetExecutions.KillProcess(Executions.id.ToString());
                        string ProcessName = Server.MapPath("~") + @"cmd\BitcoinDeveloper.exe";
                        var    Url         = Request.Url.Scheme + "://" + Request.Url.Authority + "/api/api.asmx?op=ReturnMessage";
                        SetExecutions.StartProcess(ProcessName, Executions.id.ToString(), Url);
                    }
                    else if (Executions.Status == 0)
                    {
                        SetExecutions.KillProcess(Executions.id.ToString());
                    }

                    return(Json(new { success = true }));
                }
                catch (Exception)
                {
                    return(Json(new { success = false }));
                }
            }
            else
            {
                return(Json(new { success = false }));
            }
        }