Exemple #1
0
        //this method should to DataAccess project like the GetConnection method too
        private void GetOpenDataConnection(string server, string database, string security)
        {
            string builder = BuildConnectionString(server, database, security);

            try
            {
                OpenDatabaseConnection.GetConnection(builder);
                //if (successConnect != null && successConnect.State == System.Data.ConnectionState.Open)

                ConnectionStringButtonColor  = new SolidColorBrush(Color.FromRgb(0, 255, 0));
                IsEnabled_GetAllFromDatabase = true;
                IsEnabled_SaveToDatabase     = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Wrong connection String" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                ConnectionStringButtonColor      = new SolidColorBrush(Color.FromRgb(250, 0, 0));
                IsEnabled_GetAllFromDatabase     = false;
                IsEnabled_SaveToDatabase         = false;
                IsEnabled_UpdatePersonInDatabase = false;
                IsEnabled_RemovePersonInDatabase = false;
            }
        }
Exemple #2
0
        private void OnSaveToDB()
        {
            if (!PersonList.Count.Equals(0))
            {
                if (MessageBox.Show("Do you want to save changes in the list to database?", "Question",
                                    MessageBoxButton.YesNo,
                                    MessageBoxImage.Warning) == MessageBoxResult.No)
                {
                    var conn = OpenDatabaseConnection.GetConnection("ConnectionString");
                    if (conn == null ? IsEnabled_SaveToDatabase = false : IsEnabled_SaveToDatabase = true)
                    {
                        //TODO

                        //var dbContext = new PersonModelDataContext();
                        //dbContext.InsertToDb(conn, PersonList.ToList());
                    }
                }
                else
                {
                    excelSave.SaveToExcel(PersonList.ToList());
                    return;
                }
            }
        }