Пример #1
0
        public Int16 username(int userId, string username)
        {
            Int16 status = 0; //0 user entered it's own username -1 exists before -2 username not valid -3 no special char -4 enter username 1 successful

            //check username valid
            Regex RgxUrl = new Regex("[^a-zA-Z]");

            if (Regex.Matches(username, @"[a-zA-Z]").Count == 0)
            {
                status = -2;
            }
            else
            {
                //special symbols
                RgxUrl = new Regex("[^a-zA-Z0-9]");

                if (RgxUrl.IsMatch(username))
                {
                    status = -3;
                }
                else
                {
                    //empty
                    if (username.Length == 0)
                    {
                        status = -4;
                    }
                    else
                    {
                        //check if it's own username
                        Classes.UserInfo ui = new Classes.UserInfo();
                        string           currentUsername = ui.getUsernameByUserId(userId);

                        if (currentUsername == username)
                        {
                            status = 0;
                        }
                        else
                        {
                            //check username exists
                            bool usernameExists = ui.checkUsernameExists(username);

                            if (usernameExists)
                            {
                                status = -1;
                            }
                            else
                            {
                                status = 1;

                                SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["AppConnectionString"].ConnectionString);
                                SqlCommand    sqlCmd  = new SqlCommand("sp_settingsUsernameSet", sqlConn);
                                sqlCmd.CommandType = CommandType.StoredProcedure;
                                sqlCmd.Parameters.Add("@UserId", SqlDbType.Int).Value       = userId;
                                sqlCmd.Parameters.Add("@Username", SqlDbType.VarChar).Value = username;

                                //try
                                //{
                                sqlConn.Open();
                                sqlCmd.ExecuteNonQuery();
                                //}
                                //catch (Exception ex)
                                //{

                                //}
                                //finally
                                //{
                                sqlConn.Close();
                                sqlCmd.Dispose();
                                sqlConn.Dispose();
                                //}
                            }
                        }
                    }
                }
            }

            return(status);
        }
Пример #2
0
        public Int16 username(int userId, string username)
        {
            Int16 status = 0; //0 user entered it's own username -1 exists before -2 username not valid -3 no special char -4 enter username 1 successful

            //check username valid
            Regex RgxUrl = new Regex("[^a-zA-Z]");
            if (Regex.Matches(username, @"[a-zA-Z]").Count == 0)
            {
                status = -2;
            }
            else
            {
                //special symbols
                RgxUrl = new Regex("[^a-zA-Z0-9]");

                if (RgxUrl.IsMatch(username))
                {
                    status = -3;
                }
                else
                {
                    
                    //empty
                    if (username.Length == 0)
                    {
                        status = -4;
                    }
                    else
                    {
                        //check if it's own username
                        Classes.UserInfo ui = new Classes.UserInfo();
                        string currentUsername = ui.getUsernameByUserId(userId);

                        if (currentUsername == username)
                        {
                            status = 0;
                        }
                        else
                        {
                            //check username exists
                            bool usernameExists = ui.checkUsernameExists(username);

                            if (usernameExists)
                            {
                                status = -1;
                            }
                            else
                            {
                                status = 1;

                                SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["AppConnectionString"].ConnectionString);
                                SqlCommand sqlCmd = new SqlCommand("sp_settingsUsernameSet", sqlConn);
                                sqlCmd.CommandType = CommandType.StoredProcedure;
                                sqlCmd.Parameters.Add("@UserId", SqlDbType.Int).Value = userId;
                                sqlCmd.Parameters.Add("@Username", SqlDbType.VarChar).Value = username;

                                //try
                                //{
                                    sqlConn.Open();
                                    sqlCmd.ExecuteNonQuery();
                                //}
                                //catch (Exception ex)
                                //{

                                //}
                                //finally
                                //{
                                    sqlConn.Close();
                                    sqlCmd.Dispose();
                                    sqlConn.Dispose();
                                //}
                            }
                        }
                    }
                }
            }

            return status;
        }