Пример #1
0
        /// <summary>
        /// delete o channel SQLite table mychannels
        /// </summary>
        /// <param name="channel">channel deleted</param>
        internal void DeleteChanne(string channel)
        {
            string file = AppDomain.CurrentDomain.BaseDirectory +
                          "Database\\Shamia.db";

            if (Connection.State != ConnectionState.Closed)
            {
                Connection.Close();
            }
            Connection = new SQLiteConnection("Data Source=" + file + ";Version=3" +
                                              ";New=False;Compress=True");

            try
            {
                Connection.Open();
                C             = Connection.CreateCommand();
                C.CommandText = "DELETE from mychannels WHERE channel='" + channel + "'";
                C.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MyDelegates.OnDebugMessageCallBack(ex.StackTrace);
            }
            finally
            {
                if (Connection.State != ConnectionState.Closed)
                {
                    Connection.Close();
                }
            }
        }
Пример #2
0
        /// <summary>
        /// adciona o usuario lista temp de kick
        /// </summary>
        /// <param name="user"></param>
        public static void AddUser(string user)
        {
            if (user == MainWindow.Configuration.StConfiguration.Owner || user == @"system" || user == @"azubu")
            {
                return;
            }
            foreach (Kick i in Kicks)
            {
                if (i.User == user)
                {
                    return;
                }
            }

            Kick k = new Kick()
            {
                User = user
            };

            Kicks.Add(k);

            Application.Current.Dispatcher.Invoke(
                DispatcherPriority.Normal, (Action) delegate
            {
                MyDelegates.OnChatCallBack(@"system :", @"AddUser => " + user);
            });
            //Console.WriteLine(@"add " + user);
        }
Пример #3
0
        /// <summary>
        /// update table config channel used and por
        /// </summary>
        internal void UpdateServerUsedAndPort()
        {
            string file = AppDomain.CurrentDomain.BaseDirectory +
                          "Database\\Shamia.db";

            if (Connection.State != ConnectionState.Closed)
            {
                Connection.Close();
            }
            Connection = new SQLiteConnection("Data Source=" + file + ";Version=3" +
                                              ";New=False;Compress=True");

            try
            {
                Connection.Open();
                C             = Connection.CreateCommand();
                C.CommandText = "UPDATE config SET port='" + MainWindow.Configuration.StConfiguration.Port + "'," +
                                "server='" + MainWindow.Configuration.StConfiguration.Server + "'";

                C.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MyDelegates.OnDebugMessageCallBack(ex.StackTrace);
            }
            finally
            {
                if (Connection.State != ConnectionState.Closed)
                {
                    Connection.Close();
                }
            }
        }
Пример #4
0
        /// <summary>
        /// delete all users in database
        /// </summary>
        public void DeleteAllUsers()
        {
            string file = AppDomain.CurrentDomain.BaseDirectory +
                          "Database\\Shamia.db";

            if (Connection.State != ConnectionState.Closed)
            {
                Connection.Close();
            }
            Connection = new SQLiteConnection("Data Source=" + file + ";Version=3" +
                                              ";New=False;Compress=True");
            try
            {
                Connection.Open();
                C             = Connection.CreateCommand();
                C.CommandText = @"delete from myusers";
                C.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MyDelegates.OnDebugMessageCallBack(ex.StackTrace);
            }
            finally
            {
                if (Connection.State != ConnectionState.Closed)
                {
                    Connection.Close();
                }
            }
        }
Пример #5
0
        /// <summary>
        /// remove o usuario da lista temp kick
        /// </summary>
        /// <param name="user"></param>
        public static void RemoveUser(string user)
        {
            if (user == MainWindow.Configuration.StConfiguration.Owner || user == @"system" || user == @"azubu" || Kicks.Count == 0)
            {
                return;
            }

            try
            {
                Kick us = new Kick();
                foreach (Kick k in Kicks)
                {
                    if (k.User == user)
                    {
                        us = k;
                        //Console.WriteLine(@"remove " + user);
                    }
                }
                Kicks.Remove(us);

                Application.Current.Dispatcher.Invoke(
                    DispatcherPriority.Normal, (Action) delegate
                {
                    MyDelegates.OnChatCallBack(@"system :", @"RemoveUser => " + user);
                });
            }
            catch (Exception ex)
            {
                Console.Clear();
                Console.WriteLine(ex.ToString());
            }
        }
Пример #6
0
        /// <summary>
        /// update user
        /// </summary>
        /// <param name="user"></param>
        /// <param name="password"></param>
        /// <param name="owner"></param>
        /// <param name="oldnick"></param>
        internal void UpdateUserIn(string user, string password, string owner, string oldnick)
        {
            string file = AppDomain.CurrentDomain.BaseDirectory +
                          "Database\\Shamia.db";

            if (Connection.State != ConnectionState.Closed)
            {
                Connection.Close();
            }
            Connection = new SQLiteConnection("Data Source=" + file + ";Version=3" +
                                              ";New=False;Compress=True");

            try
            {
                Connection.Open();
                C             = Connection.CreateCommand();
                C.CommandText = "UPDATE myusers SET user ='******'," +
                                "password='******'," +
                                "owner='" + owner + "'" +
                                " WHERE user='******'";
                C.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MyDelegates.OnDebugMessageCallBack(ex.StackTrace);
            }
            finally
            {
                if (Connection.State != ConnectionState.Closed)
                {
                    Connection.Close();
                }
            }
        }
Пример #7
0
        /// <summary>
        /// adciona jogo
        /// </summary>
        /// <param name="game">jogo</param>
        public void AddGame(string game)
        {
            string file = AppDomain.CurrentDomain.BaseDirectory +
                          "Database\\Shamia.db";

            if (Connection.State != ConnectionState.Closed)
            {
                Connection.Close();
            }
            Connection = new SQLiteConnection("Data Source=" + file + ";Version=3" +
                                              ";New=False;Compress=True");
            try
            {
                Connection.Open();
                C             = Connection.CreateCommand();
                C.CommandText = @"INSERT INTO Games VALUES('" + game + "','false')";
                C.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MyDelegates.OnDebugMessageCallBack(ex.StackTrace);
            }
            finally
            {
                if (Connection.State != ConnectionState.Closed)
                {
                    Connection.Close();
                }
            }
        }
Пример #8
0
 /// <summary>
 /// remove todos os usuarios da lista
 /// </summary>
 public static void ClearAll()
 {
     Kicks.Clear();
     //Console.WriteLine(@"clear");
     Application.Current.Dispatcher.Invoke(
         DispatcherPriority.Normal, (Action) delegate
     {
         MyDelegates.OnChatCallBack(@"system :", @"ClearAllKick");
     });
 }
Пример #9
0
        /// <summary>
        /// retorna enum games in database
        /// </summary>
        /// <returns></returns>
        public List <Games> EnumGamesSaved()
        {
            List <Games> t    = new List <Games>();
            string       file = AppDomain.CurrentDomain.BaseDirectory +
                                "Database\\Shamia.db";

            if (Connection.State != ConnectionState.Closed)
            {
                Connection.Close();
            }
            Connection = new SQLiteConnection("Data Source=" + file + ";Version=3" +
                                              ";New=False;Compress=True");

            try
            {
                Connection.Open();
                C             = Connection.CreateCommand();
                C.CommandText = @"select * from games";
                DataReader    = C.ExecuteReader();


                while (DataReader.Read())
                {
                    if (DataReader["IsEnabled"].ToString() == @"true")
                    {
                        Enabled = true;
                    }
                    else
                    {
                        Enabled = false;
                    }
                    Games g = new Games()
                    {
                        Name = DataReader["Name"].ToString(),
                        //DisplayMessageCount = Convert.ToInt32(DataReader["DisplayMessaCount"].ToString()),
                        IsEnabled = Enabled
                    };
                    t.Add(g);
                }
            }
            catch (Exception ex)
            {
                MyDelegates.OnDebugMessageCallBack(ex.StackTrace);
            }
            finally
            {
                if (Connection.State != ConnectionState.Closed)
                {
                    Connection.Close();
                }
            }
            return(t);
        }
Пример #10
0
        /// <summary>
        /// return if exist config in SQLite
        /// </summary>
        /// <returns></returns>
        public List <UiFontConf> EnumUiFont()
        {
            List <UiFontConf> t = new List <UiFontConf>();

            string file = AppDomain.CurrentDomain.BaseDirectory +
                          "Database\\Shamia.db";

            if (Connection.State != ConnectionState.Closed)
            {
                Connection.Close();
            }
            Connection = new SQLiteConnection("Data Source=" + file + ";Version=3" +
                                              ";New=False;Compress=True");
            try
            {
                Connection.Open();
                C             = Connection.CreateCommand();
                C.CommandText = @"select * from uifontconf top1";
                DataReader    = C.ExecuteReader();
                while (DataReader.Read())
                {
                    UiFontConf f = new UiFontConf()
                    {
                        Fontname  = DataReader["fontname"].ToString(),
                        FontSize  = Convert.ToInt32(DataReader["fontsize"].ToString()),
                        Isbold    = Convert.ToBoolean(DataReader["isbold"].ToString()),
                        Isitalic  = Convert.ToBoolean(DataReader["isitalic"].ToString()),
                        ColorName = DataReader["fontcolor"].ToString()
                    };
                    t.Add(f);
                }
            }
            catch (Exception ex)
            {
                MyDelegates.OnDebugMessageCallBack(ex.StackTrace);
                return(null);
            }
            finally
            {
                if (Connection.State != ConnectionState.Closed)
                {
                    Connection.Close();
                }
            }
            return(t);
        }
Пример #11
0
        /// <summary>
        /// list top 1 user => used for Shamia connect
        /// </summary>
        /// <returns></returns>
        public List <TemplateUserDataBase> EnumUserDataBase()
        {
            string file = AppDomain.CurrentDomain.BaseDirectory +
                          "Database\\Shamia.db";

            if (Connection.State != ConnectionState.Closed)
            {
                Connection.Close();
            }
            Connection = new SQLiteConnection("Data Source=" + file + ";Version=3" +
                                              ";New=False;Compress=True");
            List <TemplateUserDataBase> t = new List <TemplateUserDataBase>();

            try
            {
                Connection.Open();
                C             = Connection.CreateCommand();
                C.CommandText = @"SELECT *FROM users TOP1";
                DataReader    = C.ExecuteReader();
                while (DataReader.Read())
                {
                    TemplateUserDataBase temp = new TemplateUserDataBase()
                    {
                        Nick     = DataReader["nick"].ToString(),
                        Password = DataReader["password"].ToString(),
                        Auth     = DataReader["auth"].ToString(),
                        Owner    = DataReader["owner"].ToString(),
                        Port     = Convert.ToInt32(DataReader["port"].ToString())
                    };
                    t.Add(temp);
                }
            }
            catch (Exception ex)
            {
                MyDelegates.OnDebugMessageCallBack(ex.ToString());
            }
            finally
            {
                if (Connection.State != ConnectionState.Closed)
                {
                    Connection.Close();
                }
            }
            return(t);
        }
Пример #12
0
        /// <summary>
        /// retorna bandeira de idioma usado
        /// </summary>
        /// <returns></returns>
        public string GetLang()
        {
            Clanguage._ListLangs();
            string file = AppDomain.CurrentDomain.BaseDirectory +
                          "Database\\Shamia.db";

            if (Connection.State != ConnectionState.Closed)
            {
                Connection.Close();
            }
            Connection = new SQLiteConnection("Data Source=" + file + ";Version=3" +
                                              ";New=False;Compress=True");
            try
            {
                Connection.Open();
                C             = Connection.CreateCommand();
                C.CommandText = @"SELECT language FROM config LIMIT 1";
                DataReader    = C.ExecuteReader();

                while (DataReader.Read())
                {
                    foreach (TemplateLang i in Clanguage.Langs)
                    {
                        if (i.Lang == DataReader["language"].ToString())
                        {
                            return(i.Flag);
                        }
                    }
                    //return DataReader["language"].ToString();
                }
            }
            catch (Exception ex)
            {
                MyDelegates.OnDebugMessageCallBack(ex.ToString());
                return(string.Empty);
            }
            finally
            {
                if (Connection.State != ConnectionState.Closed)
                {
                    Connection.Close();
                }
            }
            return(string.Empty);
        }
Пример #13
0
        /// <summary>
        /// list all users in database
        /// </summary>
        /// <returns></returns>
        public List <TemplateMyUsersDataBase> GetListMyUsersDataBase()
        {
            List <TemplateMyUsersDataBase> myUsersDataBases = new List <TemplateMyUsersDataBase>();
            string file = AppDomain.CurrentDomain.BaseDirectory +
                          "Database\\Shamia.db";

            if (Connection.State != ConnectionState.Closed)
            {
                Connection.Close();
            }
            Connection = new SQLiteConnection("Data Source=" + file + ";Version=3" +
                                              ";New=False;Compress=True");
            try
            {
                Connection.Open();
                C             = Connection.CreateCommand();
                C.CommandText = @"SELECT user , password , owner FROM myusers";
                DataReader    = C.ExecuteReader();
                while (DataReader.Read())
                {
                    TemplateMyUsersDataBase t = new TemplateMyUsersDataBase()
                    {
                        User     = DataReader["user"].ToString(),
                        Password = DataReader["password"].ToString(),
                        Owner    = DataReader["owner"].ToString()
                    };
                    myUsersDataBases.Add(t);
                }
            }
            catch (Exception ex)
            {
                MyDelegates.OnDebugMessageCallBack(ex.StackTrace);
            }
            finally
            {
                if (Connection.State != ConnectionState.Closed)
                {
                    Connection.Close();
                }
            }
            return(myUsersDataBases);
        }
Пример #14
0
        /// <summary>
        /// retorna o usuario para ser editado ou deletado
        /// </summary>
        /// <returns></returns>
        /// <param name="user">user nick</param>
        internal TemplateMyUsersDataBase GetUserEdit(string user)
        {
            TemplateMyUsersDataBase t = new TemplateMyUsersDataBase();

            string file = AppDomain.CurrentDomain.BaseDirectory +
                          "Database\\Shamia.db";

            if (Connection.State != ConnectionState.Closed)
            {
                Connection.Close();
            }
            Connection = new SQLiteConnection("Data Source=" + file + ";Version=3" +
                                              ";New=False;Compress=True");
            try
            {
                Connection.Open();
                C             = Connection.CreateCommand();
                C.CommandText = @"SELECT user, password , owner FROM myusers WHERE user ='******'";
                DataReader    = C.ExecuteReader();
                while (DataReader.Read())
                {
                    t.User     = DataReader["user"].ToString();
                    t.Password = DataReader["password"].ToString();
                    t.Owner    = DataReader["owner"].ToString();
                }
            }
            catch (Exception ex)
            {
                MyDelegates.OnDebugMessageCallBack(ex.StackTrace);
                return(null);
            }
            finally
            {
                if (Connection.State != ConnectionState.Closed)
                {
                    Connection.Close();
                }
            }

            return(t);
        }
Пример #15
0
        /// <summary>
        /// creat user
        /// </summary>
        /// <param name="user"> user name</param>
        /// <param name="password">password</param>
        /// <param name="owner"></param>
        public void CreatUser(string user, string password, string owner)
        {
            string file = AppDomain.CurrentDomain.BaseDirectory +
                          "Database\\Shamia.db";

            if (Connection.State != ConnectionState.Closed)
            {
                Connection.Close();
            }
            Connection = new SQLiteConnection("Data Source=" + file + ";Version=3" +
                                              ";New=False;Compress=True");

            try
            {
                Connection.Open();
                C             = Connection.CreateCommand();
                C.CommandText = @"INSERT INTO myusers (user,password,owner) VALUES ('" + user + "','" + password + "','" + owner + "')";
                C.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                // chave duplicada
                if (ex.HResult == -2146233088)
                {
                    MyDelegates.OnDebugMessageCallBack(ex.StackTrace);
                    ((MainWindow)Application.Current.MainWindow).ShowMessageAsync(((MainWindow)Application.Current.MainWindow).Resources.MergedDictionaries[0]["ErroKeyDuplicateTitle"].ToString(),
                                                                                  ((MainWindow)Application.Current.MainWindow).Resources.MergedDictionaries[0]["ErroKeyDuplicate"].ToString());
                }
                else
                {
                    MyDelegates.OnDebugMessageCallBack(ex.StackTrace);
                }
            }
            finally
            {
                if (Connection.State != ConnectionState.Closed)
                {
                    Connection.Close();
                }
            }
        }
Пример #16
0
        /// <summary>
        /// metodo atualiza table users
        /// </summary>
        /// <param name="user"></param>
        public void UpdateSaved()
        {
            // delete users and new insert
            DeleteAllUser();

            string file = AppDomain.CurrentDomain.BaseDirectory +
                          "Database\\Shamia.db";

            if (Connection.State != ConnectionState.Closed)
            {
                Connection.Close();
            }
            Connection = new SQLiteConnection("Data Source=" + file + ";Version=3" +
                                              ";New=False;Compress=True");

            try
            {
                Connection.Open();
                C             = Connection.CreateCommand();
                C.CommandText = "INSERT INTO users VALUES('" + MainWindow.Configuration.StConfiguration.Nick + "','" +
                                MainWindow.Configuration.StConfiguration.Password + "','" +
                                MainWindow.Configuration.StConfiguration.AuthSsl + "','" +
                                MainWindow.Configuration.StConfiguration.Owner + "','" +
                                MainWindow.Configuration.StConfiguration.Port + "','" +
                                MainWindow.Configuration.StConfiguration.Channel + "')";
                C.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MyDelegates.OnDebugMessageCallBack(ex.StackTrace);
            }
            finally
            {
                if (Connection.State != ConnectionState.Closed)
                {
                    Connection.Close();
                }
            }
        }
Пример #17
0
        /// <summary>
        /// retorna a lista de channels no database
        /// </summary>
        /// <returns></returns>
        public List <string> EnumServersDataBase()
        {
            string file = AppDomain.CurrentDomain.BaseDirectory +
                          "Database\\Shamia.db";

            if (Connection.State != ConnectionState.Closed)
            {
                Connection.Close();
            }
            Connection = new SQLiteConnection("Data Source=" + file + ";Version=3" +
                                              ";New=False;Compress=True");
            List <string> temp = new List <string>();

            try
            {
                Connection.Open();
                C             = Connection.CreateCommand();
                C.CommandText = @"SELECT channel FROM channels";
                DataReader    = C.ExecuteReader();
                while (DataReader.Read())
                {
                    temp.Add(DataReader["channel"].ToString());
                }
            }
            catch (Exception ex)
            {
                MyDelegates.OnDebugMessageCallBack(ex.ToString());
            }
            finally
            {
                if (Connection.State != ConnectionState.Closed)
                {
                    Connection.Close();
                }
            }
            return(temp);
        }
Пример #18
0
        public void UpdateUiConf(string fontname, int fontsize, bool isbold, bool isitalic, string color)
        {
            // delete saved
            DeleteUiConf();

            List <UiFontConf> t = new List <UiFontConf>();

            string file = AppDomain.CurrentDomain.BaseDirectory +
                          "Database\\Shamia.db";

            if (Connection.State != ConnectionState.Closed)
            {
                Connection.Close();
            }
            Connection = new SQLiteConnection("Data Source=" + file + ";Version=3" +
                                              ";New=False;Compress=True");

            try
            {
                Connection.Open();
                C             = Connection.CreateCommand();
                C.CommandText = @"INSERT INTO uifontconf VALUES('" + fontname + "','" +
                                fontsize + "','" + isbold + "','" + isitalic + "','" + color + "')";
                C.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MyDelegates.OnDebugMessageCallBack(ex.StackTrace);
            }
            finally
            {
                if (Connection.State != ConnectionState.Closed)
                {
                    Connection.Close();
                }
            }
        }
Пример #19
0
        /// <summary>
        /// check user exist not INSERT
        /// </summary>
        /// <param name="user">user</param>
        /// <returns></returns>
        public bool CheckUserExist(string user)
        {
            string file = AppDomain.CurrentDomain.BaseDirectory +
                          "Database\\Shamia.db";

            if (Connection.State != ConnectionState.Closed)
            {
                Connection.Close();
            }
            Connection = new SQLiteConnection("Data Source=" + file + ";Version=3" +
                                              ";New=False;Compress=True");
            try
            {
                Connection.Open();
                C             = Connection.CreateCommand();
                C.CommandText = @"SELECT user FROM myusers WHERE user ='******'";
                DataReader    = C.ExecuteReader();
                while (DataReader.Read())
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                MyDelegates.OnDebugMessageCallBack(ex.StackTrace);
                return(false);
            }
            finally
            {
                if (Connection.State != ConnectionState.Closed)
                {
                    Connection.Close();
                }
            }
            return(false);
        }
Пример #20
0
        /// <summary>
        /// get last server used to connect
        /// </summary>
        /// <returns></returns>
        public string GetLastServerUsedDataBase()
        {
            string temp = string.Empty;
            string file = AppDomain.CurrentDomain.BaseDirectory +
                          "Database\\Shamia.db";

            if (Connection.State != ConnectionState.Closed)
            {
                Connection.Close();
            }
            Connection = new SQLiteConnection("Data Source=" + file + ";Version=3" +
                                              ";New=False;Compress=True");
            try
            {
                Connection.Open();
                C             = Connection.CreateCommand();
                C.CommandText = @"SELECT server FROM config";
                DataReader    = C.ExecuteReader();
                while (DataReader.Read())
                {
                    temp = DataReader["server"].ToString();
                }
            }
            catch (Exception ex)
            {
                MyDelegates.OnDebugMessageCallBack(ex.ToString());
            }
            finally
            {
                if (Connection.State != ConnectionState.Closed)
                {
                    Connection.Close();
                }
            }
            return(temp);
        }
Пример #21
0
        /// <summary>
        /// metodo cria ou acessa banco de dados sqlite carregar configs
        /// </summary>
        public void CreateOrAccessDataBase()
        {
            try
            {
                string file = AppDomain.CurrentDomain.BaseDirectory +
                              "Database\\Shamia.db";
                if (!ExistDataBase())
                {
                    Connection = new SQLiteConnection("Data Source=" + file + ";Version=3;New=True;Compress=True");
                    Connection.Open();
                    string[] config = new string[] { string.Empty, string.Empty, string.Empty };
                    // create table(s)
                    // config   => contais configurations
                    config[0] = @"create table config (port interger(4)" +
                                @",server varchar(30) primary key" +
                                @",language varchar(20))";
                    // channels => contais channels
                    config[1] = @"create table channels (channel varchar(30) primary key)";
                    // user(s)  => my login accont user(s) used login auth SSL
                    config[2] = @"create table users (nick varchar(20) primary key" +
                                @",password varchar(50))";

                    foreach (string i in config)
                    {
                        SQLiteCommand c = new SQLiteCommand(i, Connection);
                        c.ExecuteNonQuery();
                    }
                    IsDatabase = true;
                }
                else
                {
                    Connection = new SQLiteConnection("Data Source=" + file + ";Version=3" +
                                                      ";New=False;Compress=True");
                    Connection.Open();
                    IsDatabase = true;

                    // select database to list all channels and servers
                    C             = Connection.CreateCommand();
                    C.CommandText = @"SELECT channel FROM channels";
                    DataReader    = C.ExecuteReader();
                    while (DataReader.Read())
                    {
                        MainWindow.Configuration.Channels.Add(new TemplateChannels
                        {
                            Channels = DataReader["channel"].ToString()
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                MyDelegates.OnDebugMessageCallBack(ex.ToString());
                IsDatabase = false;
            }
            finally
            {
                if (Connection.State != ConnectionState.Closed)
                {
                    Connection.Close();
                }
            }
        }