Example #1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(Tunnel.Model.Tunnel_Chat model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Tunnel_Chat set ");
            strSql.Append("Chat_UserID=@Chat_UserID,");
            strSql.Append("Chat_UserName=@Chat_UserName,");
            strSql.Append("Chat_Content=@Chat_Content,");
            strSql.Append("Chat_Date=@Chat_Date,");
            strSql.Append("Chat_State=@Chat_State,");
            strSql.Append("Chat_ToUserID=@Chat_ToUserID");
            strSql.Append(" where Chat_ID=@Chat_ID ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Chat_ID",       SqlDbType.BigInt,      8),
                new SqlParameter("@Chat_UserID",   SqlDbType.BigInt,      8),
                new SqlParameter("@Chat_UserName", SqlDbType.VarChar,    50),
                new SqlParameter("@Chat_Content",  SqlDbType.VarChar,   200),
                new SqlParameter("@Chat_Date",     SqlDbType.DateTime),
                new SqlParameter("@Chat_State",    SqlDbType.Int,         4),
                new SqlParameter("@Chat_ToUserID", SqlDbType.BigInt, 8)
            };
            parameters[0].Value = model.Chat_ID;
            parameters[1].Value = model.Chat_UserID;
            parameters[2].Value = model.Chat_UserName;
            parameters[3].Value = model.Chat_Content;
            parameters[4].Value = model.Chat_Date;
            parameters[5].Value = model.Chat_State;
            parameters[6].Value = model.Chat_ToUserID;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }
Example #2
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Tunnel.Model.Tunnel_Chat GetModel(long Chat_ID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 Chat_ID,Chat_UserID,Chat_UserName,Chat_Content,Chat_Date,Chat_State,Chat_ToUserID from Tunnel_Chat ");
            strSql.Append(" where Chat_ID=@Chat_ID ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Chat_ID", SqlDbType.BigInt)
            };
            parameters[0].Value = Chat_ID;

            Tunnel.Model.Tunnel_Chat model = new Tunnel.Model.Tunnel_Chat();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["Chat_ID"].ToString() != "")
                {
                    model.Chat_ID = long.Parse(ds.Tables[0].Rows[0]["Chat_ID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Chat_UserID"].ToString() != "")
                {
                    model.Chat_UserID = long.Parse(ds.Tables[0].Rows[0]["Chat_UserID"].ToString());
                }
                model.Chat_UserName = ds.Tables[0].Rows[0]["Chat_UserName"].ToString();
                model.Chat_Content  = ds.Tables[0].Rows[0]["Chat_Content"].ToString();
                if (ds.Tables[0].Rows[0]["Chat_Date"].ToString() != "")
                {
                    model.Chat_Date = DateTime.Parse(ds.Tables[0].Rows[0]["Chat_Date"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Chat_State"].ToString() != "")
                {
                    model.Chat_State = int.Parse(ds.Tables[0].Rows[0]["Chat_State"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Chat_ToUserID"].ToString() != "")
                {
                    model.Chat_ToUserID = long.Parse(ds.Tables[0].Rows[0]["Chat_ToUserID"].ToString());
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
Example #3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Tunnel.Model.Tunnel_Chat model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Tunnel_Chat(");
            strSql.Append("Chat_UserID,Chat_UserName,Chat_Content,Chat_Date,Chat_State,Chat_ToUserID)");
            strSql.Append(" values (");
            strSql.Append("@Chat_UserID,@Chat_UserName,@Chat_Content,@Chat_Date,@Chat_State,@Chat_ToUserID)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Chat_UserID",   SqlDbType.BigInt,      8),
                new SqlParameter("@Chat_UserName", SqlDbType.VarChar,    50),
                new SqlParameter("@Chat_Content",  SqlDbType.VarChar,   200),
                new SqlParameter("@Chat_Date",     SqlDbType.DateTime),
                new SqlParameter("@Chat_State",    SqlDbType.Int,         4),
                new SqlParameter("@Chat_ToUserID", SqlDbType.BigInt, 8)
            };
            parameters[0].Value = model.Chat_UserID;
            parameters[1].Value = model.Chat_UserName;
            parameters[2].Value = model.Chat_Content;
            parameters[3].Value = model.Chat_Date;
            parameters[4].Value = model.Chat_State;
            parameters[5].Value = model.Chat_ToUserID;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(1);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }