コード例 #1
0
        private void Initialize()
        {
            // MySQL version
            // MySQL version
            // MySQL version
            //
            ////server = "localhost";
            ////database = "new_schema";
            ////uid = "root";
            ////password = "******";
            //
            //server = "localhost";
            //database = "world";
            //uid = "root";
            //password = "******";
            //
            //
            //string connectionString;
            //connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD="******";";
            //
            //connection = new MySqlConnection(connectionString);


            // to set this up for microsoft's SQL
            // Solution Explorer:  right-click on project > Add > Item > C# > data > Service-based Database
            // project>properties   > security >  set "This is a full trust application"

            MyDebug.DPrint(Global.sprintf("Started"));

            sqlConnection = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\dprin\TMA\__Jacobs\wapp\wappDB\myDB.mdf;Integrated Security=True");
            //sqlConnection.Open();
        }
コード例 #2
0
        public bool sqlNonQuery(string sql)
        {
            try
            {
                MyDebug.DPrint(Global.sprintf("sql: {0}", sql));

                if (this.OpenConnection() == true)
                {
                    #if __MYSQL__
                    MySqlCommand cmd = new MySqlCommand(sql, sqlConnection);
                    #else
                    SqlCommand cmd = new SqlCommand(sql, sqlConnection);
                    #endif
                    cmd.CommandText = sql;
                    cmd.Connection  = sqlConnection;
                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception e)
            {
                dumpException(e);
                return(false);
            }
            return(true);
        }
コード例 #3
0
        public List <User> GetUsers()
        {
            MyDebug.DPrint(Global.sprintf("ShowUsers"));

            string query = "";

            query += @" select x.id,      ";
            query += @"        x.fname,   ";
            query += @"        x.lname,   ";
            query += @"        x.company, ";
            query += @"        x.phone    ";
            query += @" from _User as x   ";
            query += @" ORDER BY x.lname ;";

            List <User> list = new List <User>();

            if (this.OpenConnection() == true)
            {
                var dataReader = executSQL(query);
                while (dataReader.Read())
                {
                    User user = new User();
                    user.ID      = (int)dataReader["ID"];
                    user.FName   = (string)dataReader["FName"] + "";
                    user.LName   = (string)dataReader["LName"] + "";
                    user.Company = (string)dataReader["Company"] + "";
                    user.Phone   = (string)dataReader["Phone"];
                    list.Add(user);
                }
                dataReader.Close();
                this.CloseConnection();
            }
            return(list);
        }
コード例 #4
0
        void Click_ListUsers(object sender, RoutedEventArgs e)
        {
            var list = myDB.GetUsers();
            int i    = 0;

            foreach (var item in list)
            {
                MyDebug.DPrint(Global.sprintf("List[{0}]: {1}", i++, item.ToString()));
                TBOutput.Text += item.ToString();
                TBOutput.Text += "\r\n";
            }
        }
コード例 #5
0
        void gallery_clk(object sender, RoutedEventArgs e)
        {
            NavigationService ns = NavigationService.GetNavigationService(this);

            ns.Source = new Uri("Page2.xaml", UriKind.Relative);

            MyDebug.DPrint(Global.sprintf("navigate to gallery"));
            //// Instantiate page to navigate to
            //PageWithNonDefaultConstructor page =
            //    new PageWithNonDefaultConstructor(DateTime.Now);
            //// Get navigation service
            //this.NavigationService.Navigate(page);
        }
コード例 #6
0
 private bool CloseConnection()
 {
     if (isClosed)
     {
         return(true);
     }
     try
     {
         sqlConnection.Close();
         isConnected = false;
         isClosed    = true;
         return(true);
     }
     catch (MySqlException ex)
     {
         MyDebug.DPrint(Global.sprintf("Exp: {0}", ex.Message));
         MyDebug.DPrint(Global.sprintf("Exp: {0}", ex.StackTrace));
         return(false);
     }
 }
コード例 #7
0
 public void dumpException(Exception e)
 {
     MyDebug.DPrint(Global.sprintf("Exception: {0}", e.HResult));
     MyDebug.DPrint(Global.sprintf("Exception: {0}", e.Message));
     MyDebug.DPrint(Global.sprintf("Exception: {0}", e.StackTrace));
 }
コード例 #8
0
 void contact_clk(object sender, RoutedEventArgs e)
 {
     MyDebug.DPrint(Global.sprintf("navigate to contacts"));
 }
コード例 #9
0
 void home_clk(object sender, RoutedEventArgs e)
 {
     MyDebug.DPrint(Global.sprintf("navigate to home"));
 }