Пример #1
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Demo.SQLServerModelQuery.Model.SysUserModel GetModel(int ID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select * ");
            strSql.Append("  from SysUser ");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID", SqlDbType.Int, 4)
            };
            parameters[0].Value = ID;


            Demo.SQLServerModelQuery.Model.SysUserModel model = new Demo.SQLServerModelQuery.Model.SysUserModel();
            DataSet ds = SQLServerHelper.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataTableToList(ds.Tables[0])[0]);
            }
            else
            {
                return(null);
            }
        }
Пример #2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Demo.SQLServerModelQuery.Model.SysUserModel model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update SysUser set ");

            strSql.Append(" [dr] = @dr , ");
            strSql.Append(" [ts] = @ts , ");
            strSql.Append(" [UserName] = @UserName , ");
            strSql.Append(" [Password] = @Password , ");
            strSql.Append(" [RealName] = @RealName , ");
            strSql.Append(" [Phone] = @Phone , ");
            strSql.Append(" [Mobile] = @Mobile , ");
            strSql.Append(" [Email] = @Email , ");
            strSql.Append(" [Status] = @Status , ");
            strSql.Append(" [Description] = @Description  ");
            strSql.Append(" where ID=@ID ");

            SqlParameter[] parameters =
            {
                new SqlParameter("@ID",          SqlDbType.Int,         4),
                new SqlParameter("@dr",          SqlDbType.Bit,         1),
                new SqlParameter("@ts",          SqlDbType.DateTime),
                new SqlParameter("@UserName",    SqlDbType.NVarChar,   20),
                new SqlParameter("@Password",    SqlDbType.VarChar,   100),
                new SqlParameter("@RealName",    SqlDbType.NVarChar,   50),
                new SqlParameter("@Phone",       SqlDbType.VarChar,    20),
                new SqlParameter("@Mobile",      SqlDbType.VarChar,    20),
                new SqlParameter("@Email",       SqlDbType.VarChar,    80),
                new SqlParameter("@Status",      SqlDbType.Int,         4),
                new SqlParameter("@Description", SqlDbType.NVarChar, 200)
            };

            parameters[0].Value  = model.ID;
            parameters[1].Value  = model.dr;
            parameters[2].Value  = model.ts;
            parameters[3].Value  = model.UserName;
            parameters[4].Value  = model.Password;
            parameters[5].Value  = model.RealName;
            parameters[6].Value  = model.Phone;
            parameters[7].Value  = model.Mobile;
            parameters[8].Value  = model.Email;
            parameters[9].Value  = model.Status;
            parameters[10].Value = model.Description;
            int rows = SQLServerHelper.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #3
0
        /// <summary>
        /// 获得数据列表
        /// </summary>
        private List <Demo.SQLServerModelQuery.Model.SysUserModel> DataTableToList(DataTable dt)
        {
            List <Demo.SQLServerModelQuery.Model.SysUserModel> modelList = new List <Demo.SQLServerModelQuery.Model.SysUserModel>();
            int rowsCount = dt.Rows.Count;

            if (rowsCount > 0)
            {
                Demo.SQLServerModelQuery.Model.SysUserModel model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Demo.SQLServerModelQuery.Model.SysUserModel();
                    if (dt.Rows[n]["ID"].ToString() != "")
                    {
                        model.ID = int.Parse(dt.Rows[n]["ID"].ToString());
                    }
                    if (dt.Rows[n]["dr"].ToString() != "")
                    {
                        if ((dt.Rows[n]["dr"].ToString() == "1") || (dt.Rows[n]["dr"].ToString().ToLower() == "true"))
                        {
                            model.dr = true;
                        }
                        else
                        {
                            model.dr = false;
                        }
                    }
                    if (dt.Rows[n]["ts"].ToString() != "")
                    {
                        model.ts = DateTime.Parse(dt.Rows[n]["ts"].ToString());
                    }
                    model.UserName = dt.Rows[n]["UserName"].ToString();
                    model.Password = dt.Rows[n]["Password"].ToString();
                    model.RealName = dt.Rows[n]["RealName"].ToString();
                    model.Phone    = dt.Rows[n]["Phone"].ToString();
                    model.Mobile   = dt.Rows[n]["Mobile"].ToString();
                    model.Email    = dt.Rows[n]["Email"].ToString();
                    if (dt.Rows[n]["Status"].ToString() != "")
                    {
                        model.Status = int.Parse(dt.Rows[n]["Status"].ToString());
                    }
                    model.Description = dt.Rows[n]["Description"].ToString();


                    modelList.Add(model);
                }
            }
            return(modelList);
        }
Пример #4
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Demo.SQLServerModelQuery.Model.SysUserModel model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into SysUser(");
            strSql.Append("[dr],[ts],[UserName],[Password],[RealName],[Phone],[Mobile],[Email],[Status],[Description]");
            strSql.Append(") values (");
            strSql.Append("@dr,@ts,@UserName,@Password,@RealName,@Phone,@Mobile,@Email,@Status,@Description");
            strSql.Append(") ");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@dr",          SqlDbType.Bit,         1),
                new SqlParameter("@ts",          SqlDbType.DateTime),
                new SqlParameter("@UserName",    SqlDbType.NVarChar,   20),
                new SqlParameter("@Password",    SqlDbType.VarChar,   100),
                new SqlParameter("@RealName",    SqlDbType.NVarChar,   50),
                new SqlParameter("@Phone",       SqlDbType.VarChar,    20),
                new SqlParameter("@Mobile",      SqlDbType.VarChar,    20),
                new SqlParameter("@Email",       SqlDbType.VarChar,    80),
                new SqlParameter("@Status",      SqlDbType.Int,         4),
                new SqlParameter("@Description", SqlDbType.NVarChar, 200)
            };

            parameters[0].Value = model.dr;
            parameters[1].Value = model.ts;
            parameters[2].Value = model.UserName;
            parameters[3].Value = model.Password;
            parameters[4].Value = model.RealName;
            parameters[5].Value = model.Phone;
            parameters[6].Value = model.Mobile;
            parameters[7].Value = model.Email;
            parameters[8].Value = model.Status;
            parameters[9].Value = model.Description;

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

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