Exemplo n.º 1
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public LPWeb.Model.ContactUsers GetModel(int UserId, int ContactId)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 UserId,ContactId,Enabled,Created from ContactUsers ");
            strSql.Append(" where UserId=@UserId and ContactId=@ContactId ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserId",    SqlDbType.Int, 4),
                new SqlParameter("@ContactId", SqlDbType.Int, 4)
            };
            parameters[0].Value = UserId;
            parameters[1].Value = ContactId;

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

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["UserId"].ToString() != "")
                {
                    model.UserId = int.Parse(ds.Tables[0].Rows[0]["UserId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ContactId"].ToString() != "")
                {
                    model.ContactId = int.Parse(ds.Tables[0].Rows[0]["ContactId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Enabled"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["Enabled"].ToString() == "1") || (ds.Tables[0].Rows[0]["Enabled"].ToString().ToLower() == "true"))
                    {
                        model.Enabled = true;
                    }
                    else
                    {
                        model.Enabled = false;
                    }
                }
                if (ds.Tables[0].Rows[0]["Created"].ToString() != "")
                {
                    model.Created = DateTime.Parse(ds.Tables[0].Rows[0]["Created"].ToString());
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(LPWeb.Model.ContactUsers model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into ContactUsers(");
            strSql.Append("UserId,ContactId,Enabled,Created)");
            strSql.Append(" values (");
            strSql.Append("@UserId,@ContactId,@Enabled,@Created)");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserId",    SqlDbType.Int, 4),
                new SqlParameter("@ContactId", SqlDbType.Int, 4),
                new SqlParameter("@Enabled",   SqlDbType.Bit, 1),
                new SqlParameter("@Created",   SqlDbType.DateTime)
            };
            parameters[0].Value = model.UserId;
            parameters[1].Value = model.ContactId;
            parameters[2].Value = model.Enabled;
            parameters[3].Value = model.Created;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(LPWeb.Model.ContactUsers model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update ContactUsers set ");
            strSql.Append("UserId=@UserId,");
            strSql.Append("ContactId=@ContactId,");
            strSql.Append("Enabled=@Enabled,");
            strSql.Append("Created=@Created");
            strSql.Append(" where UserId=@UserId and ContactId=@ContactId ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserId",    SqlDbType.Int, 4),
                new SqlParameter("@ContactId", SqlDbType.Int, 4),
                new SqlParameter("@Enabled",   SqlDbType.Bit, 1),
                new SqlParameter("@Created",   SqlDbType.DateTime)
            };
            parameters[0].Value = model.UserId;
            parameters[1].Value = model.ContactId;
            parameters[2].Value = model.Enabled;
            parameters[3].Value = model.Created;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }