예제 #1
0
 public bool UpdateUs(QPS.NEW.Model.Users us)
 {
     return(Update(us));
 }
예제 #2
0
        public int Add(QPS.NEW.Model.Users model)
        {
            int checkUsername = -1;
            int res           = -1;

            user_         = model;
            checkUsername = Convert.ToInt32(
                sqlHelper_.GetSingle("select count(*) from TUsers where UserName=@username",
                                     CommandType.Text,
                                     new System.Data.SqlClient.SqlParameter[] {
                new System.Data.SqlClient.SqlParameter("@username", user_.Username)
            }
                                     )
                );
            if (checkUsername != 0)
            {
                return(-1);
            }
            else
            {
                string[]       filedName = new string[50];
                string[]       paramName = new string[50];
                SqlParameter[] sqlParams = new SqlParameter[50];
                int            Count     = 0;

                int userId = Convert.ToInt32(sqlHelper_.GetSingle(
                                                 "select Max(UserID) from TUsers",
                                                 CommandType.Text,
                                                 new SqlParameter[]
                {
                    new SqlParameter("@username", model.Username)
                }
                                                 )) + 1;

                filedName[Count] = "UserID";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], userId);
                Count++;

                if (model.Username != null)
                {
                    filedName[Count] = "UserName";
                    paramName[Count] = "@" + filedName[Count];

                    sqlParams[Count] = new SqlParameter(paramName[Count], model.Username);
                    Count++;
                }
                if (model.Password != null)
                {
                    filedName[Count] = "Pass";
                    paramName[Count] = "@" + filedName[Count];
                    string md5Pwd = MD5Helper.Encode(model.Password);
                    sqlParams[Count] = new SqlParameter(paramName[Count], md5Pwd);
                    Count++;
                }
                if (model.Nickname != null)
                {
                    filedName[Count] = "NickName";
                    paramName[Count] = "@" + filedName[Count];
                    sqlParams[Count] = new SqlParameter(paramName[Count], model.Nickname);
                    Count++;
                }

                StringBuilder strSql = new StringBuilder();
                strSql.Append("insert into TUsers(");
                for (int i = 0; i < Count; i++)
                {
                    strSql.Append(filedName[i]);
                    if (i != Count - 1)
                    {
                        strSql.Append(",");
                    }
                }
                strSql.Append(")values(");
                for (int i = 0; i < Count; i++)
                {
                    strSql.Append(paramName[i]);
                    if (i != Count - 1)
                    {
                        strSql.Append(",");
                    }
                }
                strSql.Append(")");

                res = sqlHelper_.ExecuteCommand(
                    strSql.ToString(),
                    CommandType.Text,
                    sqlParams
                    );

                if (res != 1)
                {
                    return(-2);
                }
                else
                {
                    // 初始化数组
                    for (int i = 0; i < 50; i++)
                    {
                        filedName[i] = null;
                        paramName[i] = null;
                        sqlParams[i] = null;
                    }
                    Count = 0;

                    filedName[Count] = "UserID";
                    paramName[Count] = "@" + filedName[Count];
                    sqlParams[Count] = new SqlParameter(paramName[Count], userId);
                    Count++;

                    if (model.Phone != null)
                    {
                        filedName[Count] = "PhoneNum";
                        paramName[Count] = "@" + filedName[Count];
                        sqlParams[Count] = new SqlParameter(paramName[Count], model.Phone);
                        Count++;
                    }

                    if (model.Usertype != -999)
                    {
                        filedName[Count] = "UserType";
                        paramName[Count] = "@" + filedName[Count];
                        sqlParams[Count] = new SqlParameter(paramName[Count], model.Usertype);
                        Count++;
                    }

                    strSql = new StringBuilder();
                    strSql.Append("insert into TUserInfo(");
                    for (int i = 0; i < Count; i++)
                    {
                        strSql.Append(filedName[i]);
                        if (i != Count - 1)
                        {
                            strSql.Append(",");
                        }
                    }
                    strSql.Append(")values(");
                    for (int i = 0; i < Count; i++)
                    {
                        strSql.Append(paramName[i]);
                        if (i != Count - 1)
                        {
                            strSql.Append(",");
                        }
                    }
                    strSql.Append(")");



                    res = -1;
                    res = sqlHelper_.ExecuteCommand(
                        strSql.ToString(),
                        CommandType.Text,
                        sqlParams
                        );

                    if (res != 1)
                    {
                        return(-2);
                    }

                    if (model.Mail != null)
                    {
                        res = -1;

                        res = sqlHelper_.ExecuteCommand(
                            "insert into Web_Users(UserID,Email,Phone,Address)values(@userid,@email,@phone,@address)",
                            CommandType.Text,
                            new SqlParameter[]
                        {
                            new SqlParameter("@userid", userId),
                            new SqlParameter("@email", model.Mail),
                            new SqlParameter("@phone", model.Phone),
                            new SqlParameter("@address", model.Address)
                        }
                            );
                        if (res != 1)
                        {
                            return(-2);
                        }
                    }
                }
            }
            return(1);
        }
예제 #3
0
        public bool Update(QPS.NEW.Model.Users model)
        {
            string[]       filedName = new string[50];
            string[]       paramName = new string[50];
            SqlParameter[] sqlParams = new SqlParameter[50];
            int            Count     = 0;

            if (model.Id == -999)
            {
                return(false);
            }

            if (model.Id != -999)
            {
                filedName[Count] = "UserID";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], model.Id);
                Count++;
            }
            if (model.Username != null)
            {
                filedName[Count] = "UserName";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], model.Username);
                Count++;
            }
            if (model.Password != null)
            {
                filedName[Count] = "Pass";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], model.Password);
                Count++;
            }
            if (model.Nickname != null)
            {
                filedName[Count] = "NickName";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], model.Nickname);
                Count++;
            }
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update TUsers set ");
            for (int i = 1; i < Count; i++)      // i begin with 0 !!!
            {
                strSql.Append(filedName[i]);
                strSql.Append("=");
                strSql.Append(paramName[i]);
                if (i != Count - 1)
                {
                    strSql.Append(",");
                }
            }
            strSql.Append(" where ");
            strSql.Append(filedName[0] + "=" + paramName[0]);


            int num = Convert.ToInt32(sqlHelper_.ExecuteCommand(
                                          strSql.ToString(),
                                          CommandType.Text,
                                          sqlParams
                                          ));

            if (num != 1)
            {
                return(false);
            }



            strSql = new StringBuilder();
            for (int i = 0; i < 50; i++)
            {
                filedName[i] = null;
                paramName[i] = null;
                sqlParams[i] = null;
            }
            Count = 0;

            filedName[Count] = "UserID";
            paramName[Count] = "@" + filedName[Count];
            sqlParams[Count] = new SqlParameter(paramName[Count], model.Id);
            Count++;

            if (model.Phone != null)
            {
                filedName[Count] = "PhoneNum";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], model.Phone);
                Count++;
            }
            if (model.Usertype != -999)
            {
                filedName[Count] = "Usertype";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], model.Usertype);
                Count++;
            }

            strSql.Append("update TUserinfo set ");
            for (int i = 1; i < Count; i++)      // i begin with 0 !!!
            {
                strSql.Append(filedName[i]);
                strSql.Append("=");
                strSql.Append(paramName[i]);
                if (i != Count - 1)
                {
                    strSql.Append(",");
                }
            }
            strSql.Append(" where ");
            strSql.Append(filedName[0] + "=" + paramName[0]);


            num = Convert.ToInt32(sqlHelper_.ExecuteCommand(
                                      strSql.ToString(),
                                      CommandType.Text,
                                      sqlParams
                                      ));
            if (num != 1)
            {
                return(false);
            }


            strSql = new StringBuilder();
            for (int i = 0; i < 50; i++)
            {
                filedName[i] = null;
                paramName[i] = null;
                sqlParams[i] = null;
            }
            Count = 0;

            filedName[Count] = "UserID";
            paramName[Count] = "@" + filedName[Count];
            sqlParams[Count] = new SqlParameter(paramName[Count], model.Id);
            Count++;

            if (model.Phone != null)
            {
                filedName[Count] = "Phone";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], model.Phone);
                Count++;
            }
            if (model.Address != null)
            {
                filedName[Count] = "Address";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], model.Address);
                Count++;
            }
            if (model.Mail != null)
            {
                filedName[Count] = "Email";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], model.Mail);
                Count++;
            }


            strSql.Append("update Web_Users set ");
            for (int i = 1; i < Count; i++)      // i begin with 0 !!!
            {
                strSql.Append(filedName[i]);
                strSql.Append("=");
                strSql.Append(paramName[i]);
                if (i != Count - 1)
                {
                    strSql.Append(",");
                }
            }
            strSql.Append(" where ");
            strSql.Append(filedName[0] + "=" + paramName[0]);


            num = Convert.ToInt32(sqlHelper_.ExecuteCommand(
                                      strSql.ToString(),
                                      CommandType.Text,
                                      sqlParams
                                      ));

            if (num != 1)
            {
                return(false);
            }

            return(true);
        }
예제 #4
0
파일: Users.cs 프로젝트: lincoln56/robinerp
        public int Add(QPS.NEW.Model.Users model)
        {
            int checkUsername = -1;
            int res = -1;

            user_ = model;
            checkUsername = Convert.ToInt32(
                sqlHelper_.GetSingle("select count(*) from TUsers where UserName=@username",
                CommandType.Text,
                new System.Data.SqlClient.SqlParameter[]{
                    new System.Data.SqlClient.SqlParameter("@username",user_.Username)
                }
                )
                );
            if (checkUsername != 0)
            {
                return -1;
            }
            else
            {

                string[] filedName = new string[50];
                string[] paramName = new string[50];
                SqlParameter[] sqlParams = new SqlParameter[50];
                int Count = 0;

                int userId = Convert.ToInt32(sqlHelper_.GetSingle(
                            "select Max(UserID) from TUsers",
                        CommandType.Text,
                        new SqlParameter[]
                         {
                             new SqlParameter("@username",model.Username)
                         }
                        )) + 1;

                filedName[Count] = "UserID";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], userId);
                Count++;

                if (model.Username != null)
                {
                    filedName[Count] = "UserName";
                    paramName[Count] = "@" + filedName[Count];

                    sqlParams[Count] = new SqlParameter(paramName[Count], model.Username);
                    Count++;
                }
                if (model.Password != null)
                {
                    filedName[Count] = "Pass";
                    paramName[Count] = "@" + filedName[Count];
                    string md5Pwd = MD5Helper.Encode(model.Password);
                    sqlParams[Count] = new SqlParameter(paramName[Count], md5Pwd);
                    Count++;
                }
                if (model.Nickname != null)
                {
                    filedName[Count] = "NickName";
                    paramName[Count] = "@" + filedName[Count];
                    sqlParams[Count] = new SqlParameter(paramName[Count], model.Nickname);
                    Count++;
                }

                StringBuilder strSql = new StringBuilder();
                strSql.Append("insert into TUsers(");
                for (int i = 0; i < Count; i++)
                {
                    strSql.Append(filedName[i]);
                    if (i != Count - 1)
                    {
                        strSql.Append(",");
                    }
                }
                strSql.Append(")values(");
                for (int i = 0; i < Count; i++)
                {
                    strSql.Append(paramName[i]);
                    if (i != Count - 1)
                    {
                        strSql.Append(",");
                    }
                }
                strSql.Append(")");

                res = sqlHelper_.ExecuteCommand(
                    strSql.ToString(),
                    CommandType.Text,
                    sqlParams
                    );

                if (res != 1)
                {
                    return -2;
                }
                else
                {

                    // 初始化数组
                    for (int i = 0; i < 50; i++)
                    {
                        filedName[i] = null;
                        paramName[i] = null;
                        sqlParams[i] = null;
                    }
                    Count = 0;

                    filedName[Count] = "UserID";
                    paramName[Count] = "@" + filedName[Count];
                    sqlParams[Count] = new SqlParameter(paramName[Count], userId);
                    Count++;

                    if (model.Phone != null)
                    {
                        filedName[Count] = "PhoneNum";
                        paramName[Count] = "@" + filedName[Count];
                        sqlParams[Count] = new SqlParameter(paramName[Count], model.Phone);
                        Count++;
                    }

                    if (model.Usertype != -999)
                    {
                        filedName[Count] = "UserType";
                        paramName[Count] = "@" + filedName[Count];
                        sqlParams[Count] = new SqlParameter(paramName[Count], model.Usertype);
                        Count++;
                    }

                    strSql = new StringBuilder();
                    strSql.Append("insert into TUserInfo(");
                    for (int i = 0; i < Count; i++)
                    {
                        strSql.Append(filedName[i]);
                        if (i != Count - 1)
                        {
                            strSql.Append(",");
                        }
                    }
                    strSql.Append(")values(");
                    for (int i = 0; i < Count; i++)
                    {
                        strSql.Append(paramName[i]);
                        if (i != Count - 1)
                        {
                            strSql.Append(",");
                        }
                    }
                    strSql.Append(")");



                    res = -1;
                    res = sqlHelper_.ExecuteCommand(
                        strSql.ToString(),
                        CommandType.Text,
                        sqlParams
                        );

                    if (res != 1)
                    {
                        return -2;
                    }

                    if (model.Mail != null)
                    {
                        res = -1;

                        res = sqlHelper_.ExecuteCommand(
                            "insert into Web_Users(UserID,Email,Phone,Address)values(@userid,@email,@phone,@address)",
                            CommandType.Text,
                            new SqlParameter[]
                            {
                                new SqlParameter("@userid",userId),
                                new SqlParameter("@email",model.Mail),
                                new SqlParameter("@phone",model.Phone),
                                new SqlParameter("@address",model.Address)
                            }
                            );
                        if (res != 1)
                        {
                            return -2;
                        }
                    }


                }
            }
            return 1;
        }