Exemple #1
0
 public ISqlProfile GetInfoSQL(string path)
 {
     try
     {
         StreamReader reader = new StreamReader(path);
         string       info   = reader.ReadLine();
         reader.Close();
         string[]    vs     = info.Split(',');
         ISqlProfile output = new SqlProfile(vs[0], vs[1], vs[3], vs[2]);
         return(output);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
        public ISqlProfile Login(string ip, string databaseName, string userName, string password)
        {
            SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();

            builder.DataSource     = ip;
            builder.Password       = password;
            builder.InitialCatalog = databaseName;
            builder.UserID         = userName;

            using (SqlConnection cnn = new SqlConnection(builder.ToString()))
            {
                try
                {
                    cnn.Open();
                    SortedSet <string> curr = new SortedSet <string> {
                        "KsiążkiAutorzy", "Users", "Autorzy", "Czytelnicy", "Wypożyczenia", "GetCzytelnicy", "GetCategories", "Kategorie", "Książki"
                    };
                    DataTable     schema = cnn.GetSchema("Tables");
                    StringBuilder s      = new StringBuilder();
                    foreach (DataRow row in schema.Rows)
                    {
                        s.Append(row[2].ToString());
                        s.Append(",");
                    }
                    //Console.WriteLine(s);

                    foreach (var a in curr)
                    {
                        if (!(s.ToString().Contains(a)))
                        {
                            throw new Exception();
                        }
                    }
                    ISqlProfile profile = new SqlProfile(userName, password, databaseName, ip);
                    return(profile);
                }
                catch (Exception exc)
                {
                    throw exc;
                }
            }
        }