protected void Button1_Click1(object sender, EventArgs e) { var username = TextBox1.Text; var password = TextBox2.Text; var repswd = TextBox3.Text; if (password != repswd) { Label1.Text = "password and retype password did not match"; } else { using (var context = new BlackJackOnlineEntities()) { var res = (from r in context.Users where r.UserName == username && r.Password == password select r).FirstOrDefault(); if (res != null) { Label1.Text = "Account already exist."; } else { var userprofile = new User(); userprofile.UserName = username; userprofile.Password = password; var gamerec = new GameRecord(); gamerec.UserName = username; gamerec.Win = 0; gamerec.Loss = 0; gamerec.Draw = 0; var initfund = new UserFund(); initfund.Funds = 300; initfund.UserName = username; context.Users.Add(userprofile); context.GameRecords.Add(gamerec); context.UserFunds.Add(initfund); context.SaveChanges(); Response.Redirect("Login.aspx"); } } } }
public static UserDetalis UserDetalis(int id) { List <User_in_fund> fundList; UserDetalis detalis = new UserDetalis(); using (SuperGmachEntities db = new SuperGmachEntities()) { fundList = db.UserInFunds.Where(uif => uif.UserId == id).ToList(); foreach (var User_in_fund in fundList) { UserFund userFund = new UserFund(); userFund.Balance = (int)User_in_fund.balance; userFund.DateJoin = (DateTime)User_in_fund.date_join; userFund.FundName = (db.Funds.FirstOrDefault(fund => fund.FundId == User_in_fund.FundId)).fund_name; } } //detalis.User = GetUserById(id); return(detalis); }
/// <summary> /// �����Ƿ���Ч(��֤���Ʊ) /// </summary> /// <param name="SZRate"></param> /// <param name="userFund"></param> /// <param name="userOrder"></param> /// <returns></returns> private bool IsOrderValid(ref SjshqDBFRecord SZRate, ref UserFund userFund, ref UserOrders userOrder) { try { if (userOrder.OrdType == OrderType.ImmediateOrder) return true; else if (userOrder.ExpiredDate.Date > DateTime.Now.Date) return true; else if (SZRate.StockCode == null || SZRate.StockName == null) return false; else if (GetStockType(SZRate.StockCode.Trim(), StockMarket.Shenzhen) != StockType.SZ_A) return true; if (userOrder.Side) { if (SZRate.PreClosePrice < 0.01) { userOrder.OrdStatus = OrderStatus.Failure; userOrder.UpdatedDate = DateTime.Now; userFund.UsableCash += Common.ConvertPrice((userOrder.OrderPrice * userOrder.OrderVolume) * (1 + defaultBuyTax)); return false; } else if (SZRate.StockName.ToUpper().Contains("ST")) { if (Common.ComparePrice(userOrder.OrderPrice, SZRate.PreClosePrice * 0.95) < 0) { userOrder.OrdStatus = OrderStatus.Failure; userOrder.UpdatedDate = DateTime.Now; userFund.UsableCash += Common.ConvertPrice((userOrder.OrderPrice * userOrder.OrderVolume) * (1 + defaultBuyTax)); return false; } else return true; } else if (!SZRate.StockName.ToUpper().Contains("N")) { if (Common.ComparePrice(userOrder.OrderPrice, SZRate.PreClosePrice * 0.9) < 0) { userOrder.OrdStatus = OrderStatus.Failure; userOrder.UpdatedDate = DateTime.Now; userFund.UsableCash += Common.ConvertPrice((userOrder.OrderPrice * userOrder.OrderVolume) * (1 + defaultBuyTax)); return false; } else return true; } } else { if (SZRate.PreClosePrice < 0.01) { userOrder.OrdStatus = OrderStatus.Failure; userOrder.UpdatedDate = DateTime.Now; return false; } else if (SZRate.StockName.ToUpper().Contains("ST")) { if (Common.ComparePrice(userOrder.OrderPrice, SZRate.PreClosePrice * 1.05) > 0) { userOrder.OrdStatus = OrderStatus.Failure; userOrder.UpdatedDate = DateTime.Now; return false; } else return true; } else if (!SZRate.StockName.ToUpper().Contains("N")) { if (Common.ComparePrice(userOrder.OrderPrice, SZRate.PreClosePrice * 1.1) > 0) { userOrder.OrdStatus = OrderStatus.Failure; userOrder.UpdatedDate = DateTime.Now; return false; } else return true; } } return true; } catch { return false; } }
/// <summary> /// ������֤���Ʊ /// </summary> /// <param name="SZRate"></param> /// <param name="userFund"></param> /// <param name="userOrder"></param> /// <param name="userStock"></param> /// <param name="dBoughtAmount"></param> /// <returns></returns> private bool BuySZ(ref SjshqDBFRecord SZRate, ref UserFund userFund, ref UserOrders userOrder, ref UserStocks userStock, out double dBoughtAmount) { try { dBoughtAmount = 0; if (userOrder.UserID != userFund.UserID || userStock.UserID != userFund.UserID) return false; else if (!userOrder.Side || userOrder.OrdStatus != OrderStatus.Waiting || userFund.UserID != userOrder.UserID) return false; else if (userOrder.OrderVolume < 0) return false; else if (SZRate.SellingVal1 < 0.001 || SZRate.LatestPrice < 0.001) return false; UserFund tmpFund = userFund; UserOrders tmpOrder = userOrder; UserStocks tmpStock = userStock; dBoughtAmount = Common.ConvertPrice((tmpOrder.OrderVolume * SZRate.SellingVal1) * (1 + defaultBuyTax)); if (Common.ComparePrice(userFund.Cash, dBoughtAmount) >= 0) { tmpFund.UsableCash += Common.ConvertPrice((tmpOrder.OrderVolume * tmpOrder.OrderPrice) * (1 + defaultBuyTax)); tmpFund.UsableCash -= Common.ConvertPrice(dBoughtAmount); Synchronizer.FundHistory fundHistory = new Synchronizer.FundHistory(); fundHistory.Initialize(); fundHistory.UserID = userFund.UserID; fundHistory.OrderID = userOrder.OrderID; fundHistory.OriginalCash = Common.ConvertPrice(userFund.Cash); tmpFund.Cash -= Common.ConvertPrice(dBoughtAmount); fundHistory.ChangedCash = Common.ConvertPrice(tmpFund.Cash - fundHistory.OriginalCash); fundHistory.Curr = tmpOrder.Curr; Common.DBSync.FundChanged(fundHistory, userFund.UserID); if (tmpStock.Volume + tmpOrder.OrderVolume > 0) tmpStock.AveragePrice = Common.ConvertPrice( ((tmpStock.AveragePrice * tmpStock.Volume) + (SZRate.SellingVal1 * tmpOrder.OrderVolume)) / (tmpStock.Volume + tmpOrder.OrderVolume) * (1 + defaultBuyTax)); else tmpStock.AveragePrice = 0; tmpStock.Volume += tmpOrder.OrderVolume; tmpStock.Curr = tmpOrder.Curr; if (GetStockType(tmpOrder.StockCode, StockMarket.Shenzhen) == StockType.SZ_Warrant) tmpStock.Sellable = true; else tmpStock.Sellable = false; if (tmpFund.UsableCash < 0) tmpFund.UsableCash = 0; } else { tmpOrder.UpdatedDate = DateTime.Now; tmpOrder.OrdStatus = OrderStatus.Failure; Common.DBSync.RecordError(tmpOrder, "(SZ)���㣺Currency-" + userFund.Curr.ToString().Trim() + "/Cash-" + userFund.Cash.ToString("f3").Trim() + "/Cost-" + dBoughtAmount.ToString("f3").Trim()); } if (tmpOrder.OrdStatus != OrderStatus.Failure) { tmpOrder.TradePrice = Common.ConvertPrice(SZRate.SellingVal1); if (tmpOrder.OrdType == OrderType.ImmediateOrder) tmpOrder.OrderPrice = 0; tmpOrder.UpdatedDate = DateTime.Now; tmpOrder.OrdStatus = OrderStatus.Finished; userFund = tmpFund; userStock = tmpStock; } userOrder = tmpOrder; if (userOrder.OrdStatus == OrderStatus.Finished) return true; else return false; } catch { dBoughtAmount = 0; return false; } }
/// <summary> /// �����û��ʽ� /// </summary> /// <param name="UserID"></param> /// <param name="usableFund"></param> /// <returns></returns> public bool SetUserFund(int UserID, UserFund usableFund) { try { if (UserID <= 0 || mapUserFund == null || !mapUserFund.ContainsKey(UserID)) return false; if (usableFund.UserID != UserID || usableFund.UsableCash < 0 || usableFund.Cash < 0 || usableFund.Curr == Currency.Unknown) return false; lock (mapUserFund) { Dictionary<byte, UserFund> mapCurrFund = mapUserFund[UserID]; mapCurrFund[(byte)usableFund.Curr] = usableFund; mapUserFund[UserID] = mapCurrFund; } return true; } catch { return false; } }
/// <summary> /// �����֤���Ʊ /// </summary> /// <param name="SZRate"></param> /// <param name="userFund"></param> /// <param name="userOrder"></param> /// <param name="userStock"></param> /// <param name="dSoldAmount"></param> /// <returns></returns> private bool SellSZ(ref SjshqDBFRecord SZRate, ref UserFund userFund, ref UserOrders userOrder, ref UserStocks userStock, out double dSoldAmount) { try { dSoldAmount = 0; if (userOrder.UserID != userFund.UserID || userStock.UserID != userFund.UserID) return false; else if (userOrder.Side || userOrder.OrdStatus != OrderStatus.Waiting || userFund.UserID != userOrder.UserID) return false; else if (userOrder.OrderVolume < 0) return false; else if (SZRate.BuyingVal1 < 0.001 || SZRate.LatestPrice < 0.001) return false; UserFund tmpFund = userFund; UserOrders tmpOrder = userOrder; UserStocks tmpStock = userStock; dSoldAmount = Common.ConvertPrice((tmpOrder.OrderVolume * SZRate.BuyingVal1) * (1 - defaultSellTax)); if (tmpStock.Volume >= tmpOrder.OrderVolume) { tmpStock.Volume -= tmpOrder.OrderVolume; Synchronizer.FundHistory fundHistory = new Synchronizer.FundHistory(); fundHistory.Initialize(); fundHistory.UserID = userFund.UserID; fundHistory.OrderID = userOrder.OrderID; fundHistory.OriginalCash = Common.ConvertPrice(userFund.Cash); tmpFund.Cash += Common.ConvertPrice(dSoldAmount); fundHistory.ChangedCash = Common.ConvertPrice(tmpFund.Cash - fundHistory.OriginalCash); fundHistory.Curr = tmpOrder.Curr; Common.DBSync.FundChanged(fundHistory, userFund.UserID); tmpFund.UsableCash += Common.ConvertPrice(dSoldAmount); if (tmpStock.Volume > 0) tmpStock.AveragePrice = Common.ConvertPrice( ((tmpStock.AveragePrice * tmpStock.Volume) + (SZRate.BuyingVal1 * tmpOrder.OrderVolume)) / (tmpStock.Volume + tmpOrder.OrderVolume) * (1 + defaultSellTax)); else tmpStock.AveragePrice = 0; if (tmpFund.Cash < 0) tmpFund.Cash = 0; if (tmpFund.UsableCash < 0) tmpFund.UsableCash = 0; } else { tmpOrder.UpdatedDate = DateTime.Now; tmpOrder.OrdStatus = OrderStatus.Failure; Common.DBSync.RecordError(tmpOrder, "(SZ)��ɲ��㣺Volume" + tmpStock.Volume.ToString().Trim() + "/Cost-" + tmpOrder.OrderVolume.ToString().Trim()); } if (tmpOrder.OrdStatus != OrderStatus.Failure) { tmpOrder.TradePrice = Common.ConvertPrice(SZRate.BuyingVal1); if (tmpOrder.OrdType == OrderType.ImmediateOrder) tmpOrder.OrderPrice = 0; tmpOrder.UpdatedDate = DateTime.Now; tmpOrder.OrdStatus = OrderStatus.Finished; userFund = tmpFund; userStock = tmpStock; } userOrder = tmpOrder; if (userOrder.OrdStatus == OrderStatus.Finished) return true; else return false; } catch { dSoldAmount = 0; return false; } }