コード例 #1
0
ファイル: StockDAL.cs プロジェクト: AillsonWei/niusouyixia
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(StockWebApp.Model.Stock model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into T_STOCK(");
            strSql.Append("CREATED,TRADE_DATE,STOCK_CODE,STOCK_NAME,REMAINING,PURCHASES,PAYMENTS,REMAIN_SUM,REMAIN_QUANTITY,SELL_QUANTITY,REIMBURSED_FLOAT,SECURITIES_BALANCES)");
            strSql.Append(" values (");
            strSql.Append("@CREATED,@TRADE_DATE,@STOCK_CODE,@STOCK_NAME,@REMAINING,@PURCHASES,@PAYMENTS,@REMAIN_SUM,@REMAIN_QUANTITY,@SELL_QUANTITY,@REIMBURSED_FLOAT,@SECURITIES_BALANCES)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
                    new SqlParameter("@CREATED", SqlDbType.DateTime),
                    new SqlParameter("@TRADE_DATE", SqlDbType.DateTime),
                    new SqlParameter("@STOCK_CODE", SqlDbType.VarChar,100),
                    new SqlParameter("@STOCK_NAME", SqlDbType.VarChar,100),
                    new SqlParameter("@REMAINING", SqlDbType.Money,8),
                    new SqlParameter("@PURCHASES", SqlDbType.Money,8),
                    new SqlParameter("@PAYMENTS", SqlDbType.Money,8),
                    new SqlParameter("@REMAIN_SUM", SqlDbType.Money,8),
                    new SqlParameter("@REMAIN_QUANTITY", SqlDbType.Int,4),
                    new SqlParameter("@SELL_QUANTITY", SqlDbType.Int,4),
                    new SqlParameter("@REIMBURSED_FLOAT", SqlDbType.Int,4),
                    new SqlParameter("@SECURITIES_BALANCES", SqlDbType.Money,8)};
            parameters[0].Value = model.CREATED;
            parameters[1].Value = model.TRADE_DATE;
            parameters[2].Value = model.STOCK_CODE;
            parameters[3].Value = model.STOCK_NAME;
            parameters[4].Value = model.REMAINING;
            parameters[5].Value = model.PURCHASES;
            parameters[6].Value = model.PAYMENTS;
            parameters[7].Value = model.REMAIN_SUM;
            parameters[8].Value = model.REMAIN_QUANTITY;
            parameters[9].Value = model.SELL_QUANTITY;
            parameters[10].Value = model.REIMBURSED_FLOAT;
            parameters[11].Value = model.SECURITIES_BALANCES;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
コード例 #2
0
ファイル: StockDAL.cs プロジェクト: AillsonWei/niusouyixia
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(StockWebApp.Model.Stock model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_STOCK set ");
            strSql.Append("CREATED=@CREATED,");
            strSql.Append("TRADE_DATE=@TRADE_DATE,");
            strSql.Append("STOCK_CODE=@STOCK_CODE,");
            strSql.Append("STOCK_NAME=@STOCK_NAME,");
            strSql.Append("REMAINING=@REMAINING,");
            strSql.Append("PURCHASES=@PURCHASES,");
            strSql.Append("PAYMENTS=@PAYMENTS,");
            strSql.Append("REMAIN_SUM=@REMAIN_SUM,");
            strSql.Append("REMAIN_QUANTITY=@REMAIN_QUANTITY,");
            strSql.Append("SELL_QUANTITY=@SELL_QUANTITY,");
            strSql.Append("REIMBURSED_FLOAT=@REIMBURSED_FLOAT,");
            strSql.Append("SECURITIES_BALANCES=@SECURITIES_BALANCES");
            strSql.Append(" where ROW_ID=@ROW_ID");
            SqlParameter[] parameters = {
                    new SqlParameter("@CREATED", SqlDbType.DateTime),
                    new SqlParameter("@TRADE_DATE", SqlDbType.DateTime),
                    new SqlParameter("@STOCK_CODE", SqlDbType.VarChar,100),
                    new SqlParameter("@STOCK_NAME", SqlDbType.VarChar,100),
                    new SqlParameter("@REMAINING", SqlDbType.Money,8),
                    new SqlParameter("@PURCHASES", SqlDbType.Money,8),
                    new SqlParameter("@PAYMENTS", SqlDbType.Money,8),
                    new SqlParameter("@REMAIN_SUM", SqlDbType.Money,8),
                    new SqlParameter("@REMAIN_QUANTITY", SqlDbType.Int,4),
                    new SqlParameter("@SELL_QUANTITY", SqlDbType.Int,4),
                    new SqlParameter("@REIMBURSED_FLOAT", SqlDbType.Int,4),
                    new SqlParameter("@SECURITIES_BALANCES", SqlDbType.Money,8),
                    new SqlParameter("@ROW_ID", SqlDbType.Int,4)};
            parameters[0].Value = model.CREATED;
            parameters[1].Value = model.TRADE_DATE;
            parameters[2].Value = model.STOCK_CODE;
            parameters[3].Value = model.STOCK_NAME;
            parameters[4].Value = model.REMAINING;
            parameters[5].Value = model.PURCHASES;
            parameters[6].Value = model.PAYMENTS;
            parameters[7].Value = model.REMAIN_SUM;
            parameters[8].Value = model.REMAIN_QUANTITY;
            parameters[9].Value = model.SELL_QUANTITY;
            parameters[10].Value = model.REIMBURSED_FLOAT;
            parameters[11].Value = model.SECURITIES_BALANCES;
            parameters[12].Value = model.ROW_ID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }