Example #1
0
        private void btnAcceptAllRows_Click(object sender, EventArgs e)
        {
            // txtTableName.BackColor =
            lblInfo.Visible = false;
            SetCustomRowsBackgroundTransparent();
            if (AreRowsContainsSpecialChars())
            {
                lblInfo.Text    = "Zawartosc pola nazwy nie może być pusta ani zawierać znaków specjalnych";
                lblInfo.Visible = true;
                return;
            }
            if (CustomTableHelper.IsTableNameInUse(txtTableName.Text))
            {
                lblInfo.Text    = "Nazwa zbioru danych jest już zajęta";
                lblInfo.Visible = true;
                return;
            }
            if (listOfColumnTemplates.Count == 0)
            {
                lblInfo.Text    = "Zbiór danych musi posiadac co najmniej jedno pole";
                lblInfo.Visible = true;
                return;
            }

            var tableInfo = new TableInfo(txtTableName.Text);

            foreach (TableTemplate dbColumn in listOfColumnTemplates)
            {
                tableInfo.Add(dbColumn.GetColumnInfo());
            }

            tableInfo.ColumnInfos_Row.Reverse();

            dbHelpers.TableEditors.CustomTableHelper.AddCustomTable(tableInfo);

            MessageBox.Show("Stworzenie nowego zbioru danych powidło się");

            this.Hide();
            //  Owner.Show();
            this.Dispose();
        }
Example #2
0
        public static TableInfo GetTableInfoAboutTable(string tableName)
        {
            // należy dorobić wersję,która udostępni wszystkie wiersze
            List <ColumnInfo> columns   = new List <ColumnInfo>();
            TableInfo         tableInfo = null;
            string            command   = @"SELECT * FROM " + NamesTypes.UserCustomTables_TABLE + " " + @"WHERE TableName = @tablename";
            var query = new MySqlCommand(command, dbAgent.GetConnection());

            query.Parameters.AddWithValue("@tablename", tableName);

            dbAgent.GetConnection().Open();

            try
            {
                var reader = query.ExecuteReader();

                int    id = 0;
                string rawColumns_SingleString = "", rawTableName = "";

                while (reader.Read())
                {
                    id                      = (int)reader["ID"];
                    rawTableName            = reader["TableName"].ToString();
                    rawColumns_SingleString = reader["ColumnsType"].ToString();
                }
                if (rawTableName == "" || rawTableName == null)
                {
                    return(null);
                }
                tableInfo = new TableInfo(rawTableName);
                var rawColumns = rawColumns_SingleString.Split('|');

                for (int i = 0; i < rawColumns.Length; i++)
                {
                    var buff = rawColumns[i].Split('#');

                    tableInfo.Add(new ColumnInfo(
                                      buff[0],
                                      NamesTypes.RawStringColumnTypePairs[buff[1]]
                                      ));
                }
            }

            catch (MySqlException ex)
            {
                MessageBox.Show("Nastąpił błąd połączenia z bazą danych. Jeśli problem będzie się powtrzał skontaktuj się z zarządcą bazy danych", "Błąd połączenia z bazą danych" + Environment.NewLine + ex.ErrorCode, MessageBoxButtons.OK, MessageBoxIcon.Error);

                Debug.WriteLine("Exception Message: " + ex.Message);
                Debug.WriteLine("Exception Error Code: " + ex.ErrorCode);
                Debug.WriteLine("Exception Source: " + ex.Source);
                Debug.WriteLine("ERROR: GetTableInfoAboutTables FIRST VERSION ");
                Debug.WriteLine(ex.TargetSite);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Wystąpił  błąd " + Environment.NewLine + ex.Message + "Operacja nie powiodła się", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Debug.WriteLine("Exception Message: " + ex.Message);
                Debug.WriteLine("Exception Source: " + ex.Source);
                Debug.WriteLine("ERROR: GetTableInfoAboutTables FIRST VERSION ");
                Debug.WriteLine(ex.TargetSite);
            }
            finally
            {
                dbTools.dbAgent.GetConnection().Close();
            }
            return(tableInfo);
        }