/// <summary>
        /// 分红
        /// </summary>
        /// <param name="StockCode"></param>
        /// <param name="Market"></param>
        /// <param name="Quotiety"></param>
        /// <returns></returns>
        public RemotingInterface.RI_Result SetBonus(string StockCode, TradingSystem.StockMarket Market, double Quotiety)
        {
            bool bConn = false;
            try
            {
                if (StockCode == null || Market == TradingSystem.StockMarket.Unknown)
                    return RemotingInterface.RI_Result.Banned_Stock;
                else if (Quotiety <= 1)
                    return RemotingInterface.RI_Result.Illegal_Quotiety;
                else if (!Common.IsWeekend
                    && DateTime.Now.TimeOfDay >= Common.BeginAMTS
                    && DateTime.Now.TimeOfDay <= Common.EndPMTS.Add(new TimeSpan(0, 15, 0)))
                    return RemotingInterface.RI_Result.Out_Of_Maintain_Time;
                bConn = true;

                // 盘后方可分红
                if (sqlConn_Adm.State == ConnectionState.Closed)
                    sqlConn_Adm.Open();
                sqlTrans_Adm = sqlConn_Adm.BeginTransaction();

                List<FundHistory> listFunds = new List<FundHistory>();
                sqlCmd_Adm = new SqlCommand("SELECT * FROM [UserStocks] WHERE (StockCode = @StockCode) AND (Market = @Market", sqlConn_Adm, sqlTrans_Adm);
                sqlCmd_Adm.Parameters.Add("@StockCode", SqlDbType.NVarChar, 6); sqlCmd_Adm.Parameters["@StockCode"].Value = StockCode.Trim();
                sqlCmd_Adm.Parameters.Add("@Market", SqlDbType.TinyInt); sqlCmd_Adm.Parameters["@Market"].Value = (byte)Market;
                sqlReader_Adm = sqlCmd_Adm.ExecuteReader();
                while (sqlReader_Adm.Read())
                {
                    FundHistory data = new FundHistory();
                    data.Initialize();
                    data.ChangedCash = (double)((int)sqlReader_Adm["Volume"]) * Quotiety;
                    data.ChangedTime = DateTime.Now;
                    data.Curr = (TradingSystem.Currency)Convert.ToByte(sqlReader_Adm["Currency"].ToString().Trim());
                    data.OrderID = (int)Special_OrderID.Bonus;
                    data.UserID = (int)sqlReader_Adm["UserID"];
                    listFunds.Add(data);
                }
                sqlReader_Adm.Close();

                for (int i = 0; i < listFunds.Count; i++)
                {
                    sqlCmd_Adm = new SqlCommand("SELECT Cash FROM [UserFund] WHERE (UserID = @UserID) AND (Currency = @Currency)", sqlConn_Adm, sqlTrans_Adm);
                    sqlCmd_Adm.Parameters.Add("@UserID", SqlDbType.Int); sqlCmd_Adm.Parameters["@UserID"].Value = listFunds[i].UserID;
                    sqlCmd_Adm.Parameters.Add("@Currency", SqlDbType.TinyInt); sqlCmd_Adm.Parameters["@Currency"].Value = (byte)listFunds[i].Curr;
                    sqlReader_Adm = sqlCmd_Adm.ExecuteReader();
                    if (sqlReader_Adm.Read())
                    {
                        FundHistory data = listFunds[i];
                        data.OriginalCash = Convert.ToDouble(sqlReader_Adm["Cash"].ToString().Trim());
                        listFunds[i] = data;
                    }
                    sqlReader_Adm.Close();

                    sqlCmd_Adm = new SqlCommand("UPDATE [UserFund] SET Cash = Cash + @Add WHERE " +
                        "(UserID = @UserID) AND (Currency = @Currency)", sqlConn_Adm, sqlTrans_Adm);
                    sqlCmd_Adm.Parameters.Add("@Add", SqlDbType.Money); sqlCmd_Adm.Parameters["@Add"].Value = listFunds[i].ChangedCash;
                    sqlCmd_Adm.Parameters.Add("@UserID", SqlDbType.Int); sqlCmd_Adm.Parameters["@UserID"].Value = listFunds[i].UserID;
                    sqlCmd_Adm.Parameters.Add("@Currency", SqlDbType.TinyInt); sqlCmd_Adm.Parameters["@Currency"].Value = (byte)listFunds[i].Curr;
                    sqlCmd_Adm.ExecuteNonQuery();

                    sqlCmd_Adm = new SqlCommand("INSERT INTO [FundHistory] (UserID,OriginalCash,ChangedCash,Currency,ChangedTime,OrderID) " +
                        "VALUES (@UserID,@OriginalCash,@ChangedCash,@Currency,@ChangedTime,@OrderID)", sqlConn_Adm, sqlTrans_Adm);
                    sqlCmd_Adm.Parameters.Add("@UserID", SqlDbType.Int); sqlCmd_Adm.Parameters["@UserID"].Value = listFunds[i].UserID;
                    sqlCmd_Adm.Parameters.Add("@OriginalCash", SqlDbType.Money); sqlCmd_Adm.Parameters["@OriginalCash"].Value = listFunds[i].OriginalCash;
                    sqlCmd_Adm.Parameters.Add("@ChangedCash", SqlDbType.Money); sqlCmd_Adm.Parameters["@ChangedCash"].Value = listFunds[i].ChangedCash;
                    sqlCmd_Adm.Parameters.Add("@Currency", SqlDbType.TinyInt); sqlCmd_Adm.Parameters["@Currency"].Value = (byte)listFunds[i].Curr;
                    sqlCmd_Adm.Parameters.Add("@ChangedTime", SqlDbType.DateTime); sqlCmd_Adm.Parameters["@ChangedTime"].Value = listFunds[i].ChangedTime.ToString("yyyy-MM-dd HH:mm:ss");
                    sqlCmd_Adm.Parameters.Add("@OrderID", SqlDbType.Int); sqlCmd_Adm.Parameters["@OrderID"].Value = listFunds[i].OrderID;
                    sqlCmd_Adm.ExecuteNonQuery();
                }

                sqlCmd_Adm = new SqlCommand("UPDATE [UserFund] SET UsableCash = Cash", sqlConn_Adm, sqlTrans_Adm);
                sqlCmd_Adm.ExecuteNonQuery();

                sqlTrans_Adm.Commit();
                return RemotingInterface.RI_Result.Success;
            }
            catch (Exception err)
            {
                Common.DBLog(err, ReplaceSqlPara(sqlCmd_Adm), false);
                Common.Log(err);
                if (sqlReader_Adm != null && !sqlReader_Adm.IsClosed)
                    sqlReader_Adm.Close();
                if (sqlTrans_Adm != null && sqlTrans_Adm.Connection != null && sqlTrans_Adm.Connection.State == ConnectionState.Open)
                    sqlTrans_Adm.Rollback();
                return RemotingInterface.RI_Result.Internal_Error;
            }
            finally
            {
                if (bConn && sqlConn_Adm.State != ConnectionState.Closed)
                    sqlConn_Adm.Close();
            }
        }
        /// <summary>
        /// 分红
        /// </summary>
        /// <param name="StockCode"></param>
        /// <param name="Market"></param>
        /// <param name="Quotiety"></param>
        /// <returns></returns>
        public RemotingInterface.RI_Result SetBonus(string StockCode, TradingSystem.StockMarket Market, double Quotiety)
        {
            bool bConn = false;
            try
            {
                if (StockCode == null || Market == TradingSystem.StockMarket.Unknown)
                    return RemotingInterface.RI_Result.Banned_Stock;
                else if (Quotiety <= 1)
                    return RemotingInterface.RI_Result.Illegal_Quotiety;
                else if (!Common.IsWeekend
                    && DateTime.Now.TimeOfDay >= Common.BeginAMTS
                    && DateTime.Now.TimeOfDay <= Common.EndPMTS.Add(new TimeSpan(0, 15, 0)))
                    return RemotingInterface.RI_Result.Out_Of_Maintain_Time;
                bConn = true;

                // 盘后方可分红
                if (sqlConn_Adm.State == ConnectionState.Closed)
                    sqlConn_Adm.Open();
                sqlTrans_Adm = sqlConn_Adm.BeginTransaction();

                List<FundHistory> listFunds = new List<FundHistory>();
                sqlCmd_Adm = new SqlCommand("SELECT * FROM [UserStocks] WHERE (StockCode = @StockCode) AND (Market = @Market", sqlConn_Adm, sqlTrans_Adm);
                sqlCmd_Adm.Parameters.Add("@StockCode", SqlDbType.NVarChar, 6); sqlCmd_Adm.Parameters["@StockCode"].Value = StockCode.Trim();
                sqlCmd_Adm.Parameters.Add("@Market", SqlDbType.TinyInt); sqlCmd_Adm.Parameters["@Market"].Value = (byte)Market;
                sqlReader_Adm = sqlCmd_Adm.ExecuteReader();
                while (sqlReader_Adm.Read())
                {
                    FundHistory data = new FundHistory();
                    data.Initialize();
                    data.ChangedCash = (double)((int)sqlReader_Adm["Volume"]) * Quotiety;
                    data.ChangedTime = DateTime.Now;
                    data.Curr = (TradingSystem.Currency)Convert.ToByte(sqlReader_Adm["Currency"].ToString().Trim());
                    data.OrderID = (int)Special_OrderID.Bonus;
                    data.UserID = (int)sqlReader_Adm["UserID"];
                    listFunds.Add(data);
                }
                sqlReader_Adm.Close();

                for (int i = 0; i < listFunds.Count; i++)
                {
                    sqlCmd_Adm = new SqlCommand("SELECT Cash FROM [UserFund] WHERE (UserID = @UserID) AND (Currency = @Currency)", sqlConn_Adm, sqlTrans_Adm);
                    sqlCmd_Adm.Parameters.Add("@UserID", SqlDbType.Int); sqlCmd_Adm.Parameters["@UserID"].Value = listFunds[i].UserID;
                    sqlCmd_Adm.Parameters.Add("@Currency", SqlDbType.TinyInt); sqlCmd_Adm.Parameters["@Currency"].Value = (byte)listFunds[i].Curr;
                    sqlReader_Adm = sqlCmd_Adm.ExecuteReader();
                    if (sqlReader_Adm.Read())
                    {
                        FundHistory data = listFunds[i];
                        data.OriginalCash = Convert.ToDouble(sqlReader_Adm["Cash"].ToString().Trim());
                        listFunds[i] = data;
                    }
                    sqlReader_Adm.Close();

                    sqlCmd_Adm = new SqlCommand("UPDATE [UserFund] SET Cash = Cash + @Add WHERE " +
                        "(UserID = @UserID) AND (Currency = @Currency)", sqlConn_Adm, sqlTrans_Adm);
                    sqlCmd_Adm.Parameters.Add("@Add", SqlDbType.Money); sqlCmd_Adm.Parameters["@Add"].Value = listFunds[i].ChangedCash;
                    sqlCmd_Adm.Parameters.Add("@UserID", SqlDbType.Int); sqlCmd_Adm.Parameters["@UserID"].Value = listFunds[i].UserID;
                    sqlCmd_Adm.Parameters.Add("@Currency", SqlDbType.TinyInt); sqlCmd_Adm.Parameters["@Currency"].Value = (byte)listFunds[i].Curr;
                    sqlCmd_Adm.ExecuteNonQuery();

                    sqlCmd_Adm = new SqlCommand("INSERT INTO [FundHistory] (UserID,OriginalCash,ChangedCash,Currency,ChangedTime,OrderID) " +
                        "VALUES (@UserID,@OriginalCash,@ChangedCash,@Currency,@ChangedTime,@OrderID)", sqlConn_Adm, sqlTrans_Adm);
                    sqlCmd_Adm.Parameters.Add("@UserID", SqlDbType.Int); sqlCmd_Adm.Parameters["@UserID"].Value = listFunds[i].UserID;
                    sqlCmd_Adm.Parameters.Add("@OriginalCash", SqlDbType.Money); sqlCmd_Adm.Parameters["@OriginalCash"].Value = listFunds[i].OriginalCash;
                    sqlCmd_Adm.Parameters.Add("@ChangedCash", SqlDbType.Money); sqlCmd_Adm.Parameters["@ChangedCash"].Value = listFunds[i].ChangedCash;
                    sqlCmd_Adm.Parameters.Add("@Currency", SqlDbType.TinyInt); sqlCmd_Adm.Parameters["@Currency"].Value = (byte)listFunds[i].Curr;
                    sqlCmd_Adm.Parameters.Add("@ChangedTime", SqlDbType.DateTime); sqlCmd_Adm.Parameters["@ChangedTime"].Value = listFunds[i].ChangedTime.ToString("yyyy-MM-dd HH:mm:ss");
                    sqlCmd_Adm.Parameters.Add("@OrderID", SqlDbType.Int); sqlCmd_Adm.Parameters["@OrderID"].Value = listFunds[i].OrderID;
                    sqlCmd_Adm.ExecuteNonQuery();
                }

                sqlCmd_Adm = new SqlCommand("UPDATE [UserFund] SET UsableCash = Cash", sqlConn_Adm, sqlTrans_Adm);
                sqlCmd_Adm.ExecuteNonQuery();

                sqlTrans_Adm.Commit();
                return RemotingInterface.RI_Result.Success;
            }
            catch (Exception err)
            {
                Common.DBLog(err, ReplaceSqlPara(sqlCmd_Adm), false);
                Common.Log(err);
                if (sqlReader_Adm != null && !sqlReader_Adm.IsClosed)
                    sqlReader_Adm.Close();
                if (sqlTrans_Adm != null && sqlTrans_Adm.Connection != null && sqlTrans_Adm.Connection.State == ConnectionState.Open)
                    sqlTrans_Adm.Rollback();
                return RemotingInterface.RI_Result.Internal_Error;
            }
            finally
            {
                if (bConn && sqlConn_Adm.State != ConnectionState.Closed)
                    sqlConn_Adm.Close();
            }
        }
Beispiel #3
0
        /// <summary>
        /// ׷���ʽ���ˮ��¼
        /// </summary>
        /// <param name="fundHistory"></param>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public bool FundChanged(FundHistory fundHistory, int UserID)
        {
            try
            {
                double defaultFund = 0;
                switch (fundHistory.Curr)
                {
                    case TradingSystem.Currency.AUD:
                        defaultFund = Common.stkTrading.defaultAUD;
                        break;
                    case TradingSystem.Currency.CAD:
                        defaultFund = Common.stkTrading.defaultCAD;
                        break;
                    case TradingSystem.Currency.CHF:
                        defaultFund = Common.stkTrading.defaultCHF;
                        break;
                    case TradingSystem.Currency.EUR:
                        defaultFund = Common.stkTrading.defaultEUR;
                        break;
                    case TradingSystem.Currency.GBP:
                        defaultFund = Common.stkTrading.defaultGBP;
                        break;
                    case TradingSystem.Currency.HKD:
                        defaultFund = Common.stkTrading.defaultHKD;
                        break;
                    case TradingSystem.Currency.JPY:
                        defaultFund = Common.stkTrading.defaultJPY;
                        break;
                    case TradingSystem.Currency.NZD:
                        defaultFund = Common.stkTrading.defaultNZD;
                        break;
                    case TradingSystem.Currency.USD:
                        defaultFund = Common.stkTrading.defaultUSD;
                        break;
                    default:
                        defaultFund = Common.stkTrading.defaultRMB;
                        break;
                }
                if (fundHistory.UserID != UserID)
                {
                    Common.Log("Illegal Fund Changing [FundHistory.UserID=" + fundHistory.UserID + ";UserOrder.UserID=" + UserID + "] @ FundChanged.");
                    return false;
                }
                else if (Common.ComparePrice(fundHistory.OriginalCash + fundHistory.ChangedCash, (-0.001 * defaultFund)) < 0)
                {
                    Common.Log("Illegal Fund Changing [FundHistory.UserID=" + fundHistory.UserID + ";UserFund.Currency=" + fundHistory.Curr.ToString().Trim() +
                        ";FundHistory.OriginalCash=" + fundHistory.OriginalCash + ";FundHistory.ChangedCash=" + fundHistory.ChangedCash + "] @ FundChanged.");
                    return false;
                }
                else if (Common.ComparePrice(fundHistory.OriginalCash + fundHistory.ChangedCash, 0) < 0)
                {
                    fundHistory.ChangedCash = (-1 * fundHistory.OriginalCash);
                }
                if (fundHistory.ChangedCash < 0.001 && fundHistory.ChangedCash > -0.001)
                    return false;
                fundHistory.ChangedTime = DateTime.Now;

                if (Common.stkBuffer != null)
                {
                    RemotingInterface.RI_FundChanges stiFundChanges = new RemotingInterface.RI_FundChanges();
                    stiFundChanges.ChangedCash = fundHistory.ChangedCash;
                    stiFundChanges.OrderID = fundHistory.OrderID;
                    stiFundChanges.OriginalCash = fundHistory.OriginalCash;
                    stiFundChanges.Curr = (RemotingInterface.RI_Currency)fundHistory.Curr;
                    stiFundChanges.ChangedDate = fundHistory.ChangedTime;
                    Common.stkBuffer.SetUserFundChanges(fundHistory.UserID, stiFundChanges);
                }
                lock (listFundHistory)
                {
                    listFundHistory.Add(fundHistory);
                }
                return true;
            }
            catch (Exception err)
            {
                Common.Log(err);
                return false;
            }
        }