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

            strSql.Append("update Account set ");
            strSql.Append("AccountName=@AccountName,");
            strSql.Append("AccountPwd=@AccountPwd,");
            strSql.Append("AType=@AType,");
            strSql.Append("RoleId=@RoleId,");
            strSql.Append("CompanyId=@CompanyId,");
            strSql.Append("AccessToken=@AccessToken");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@AccountName", SqlDbType.VarChar,  50),
                new SqlParameter("@AccountPwd",  SqlDbType.VarChar, 255),
                new SqlParameter("@AType",       SqlDbType.Int,       4),
                new SqlParameter("@RoleId",      SqlDbType.Int,       4),
                new SqlParameter("@CompanyId",   SqlDbType.Int,       4),
                new SqlParameter("@AccessToken", SqlDbType.VarChar,  50),
                new SqlParameter("@Id",          SqlDbType.Int, 4)
            };
            parameters[0].Value = model.AccountName;
            parameters[1].Value = model.AccountPwd;
            parameters[2].Value = model.AType;
            parameters[3].Value = model.RoleId;
            parameters[4].Value = model.CompanyId;
            parameters[5].Value = model.AccessToken;
            parameters[6].Value = model.Id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(guanbingking.Model.Account model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Account(");
            strSql.Append("AccountName,AccountPwd,AType,RoleId,CompanyId,AccessToken)");
            strSql.Append(" values (");
            strSql.Append("@AccountName,@AccountPwd,@AType,@RoleId,@CompanyId,@AccessToken)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@AccountName", SqlDbType.VarChar,  50),
                new SqlParameter("@AccountPwd",  SqlDbType.VarChar, 255),
                new SqlParameter("@AType",       SqlDbType.Int,       4),
                new SqlParameter("@RoleId",      SqlDbType.Int,       4),
                new SqlParameter("@CompanyId",   SqlDbType.Int,       4),
                new SqlParameter("@AccessToken", SqlDbType.VarChar, 50)
            };
            parameters[0].Value = model.AccountName;
            parameters[1].Value = model.AccountPwd;
            parameters[2].Value = model.AType;
            parameters[3].Value = model.RoleId;
            parameters[4].Value = model.CompanyId;
            parameters[5].Value = model.AccessToken;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Example #3
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public guanbingking.Model.Account DataRowToModel(DataRow row)
 {
     guanbingking.Model.Account model = new guanbingking.Model.Account();
     if (row != null)
     {
         if (row["Id"] != null && row["Id"].ToString() != "")
         {
             model.Id = int.Parse(row["Id"].ToString());
         }
         if (row["AccountName"] != null)
         {
             model.AccountName = row["AccountName"].ToString();
         }
         if (row["AccountPwd"] != null)
         {
             model.AccountPwd = row["AccountPwd"].ToString();
         }
         if (row["AType"] != null && row["AType"].ToString() != "")
         {
             model.AType = int.Parse(row["AType"].ToString());
         }
         if (row["RoleId"] != null && row["RoleId"].ToString() != "")
         {
             model.RoleId = int.Parse(row["RoleId"].ToString());
         }
         if (row["CompanyId"] != null && row["CompanyId"].ToString() != "")
         {
             model.CompanyId = int.Parse(row["CompanyId"].ToString());
         }
         if (row["AccessToken"] != null)
         {
             model.AccessToken = row["AccessToken"].ToString();
         }
     }
     return(model);
 }
Example #4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public guanbingking.Model.Account GetModel(int Id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 Id,AccountName,AccountPwd,AType,RoleId,CompanyId,AccessToken from Account ");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Id", SqlDbType.Int, 4)
            };
            parameters[0].Value = Id;

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

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }