}                                                           // DO NOT USE: Only here because it's an abstract function

        public new void Read()
        {
            using (var conn = AccessDB.Connect())
            {
                conn.Open();
                using (var reader = SQLDB.Read(conn, "SELECT " + AttributeName + " FROM " + HostDBTable + " WHERE " + HostDBTable + "_ID = " + HostId + ";"))
                {
                    reader.Read();
                    StringList = reader[AttributeName].ToString();
                }
                conn.Close();
            }
            if (StringList == "")
            {
                return;
            }
            string[] items = StringList.Split('_');
            int      inc   = isDual() ? 2 : 1;

            for (int i = 1; i < items.Length; i += inc)
            {
                int listId = int.Parse(items[i - 1]);
                if (listId >= TargetTypeListData.OptionsListNames.Count)
                {
                    continue;
                }
                AddRow(null, null);
                Elements[Count - 1].Add(TargetTypeListData.CreateInput(Count, 1, listId - 1));
                if (isDual())
                {
                    AddSecondInput(int.Parse(items[i]).ToString());
                }
                AddRangeToTable();
            }
        }
Beispiel #2
0
        public void Update()
        {
            LinkedFooter.RemoveOperationMessage();
            string err = ValidateInputs();

            if (err != "")
            {
                MessageBox.Show(err, "Could not update " + SQLDB.CurrentTable);
            }
            else
            {
                using (var conn = AccessDB.Connect())
                {
                    conn.Open();
                    using (var transaction = conn.BeginTransaction())
                    {
                        OnUpdate(conn);
                        transaction.Commit();
                    }
                    conn.Close();
                }
                LinkedTableList.SetupTable(true);
                LinkedFooter.SetOperationMessage(SQLDB.CurrentTable + " Updated", Colors.SkyBlue);
            }
        }
Beispiel #3
0
        public void Clone()
        {
            LinkedFooter.RemoveOperationMessage();
            string err = ValidateInputs();

            if (err != "")
            {
                MessageBox.Show("Could not clone " + SQLDB.CurrentTable + ":\n\n" + err);
            }
            else
            {
                SQLDB.CurrentId = SQLDB.MaxIdPlusOne(SQLDB.CurrentTable);
                using (var conn = AccessDB.Connect())
                {
                    conn.Open();
                    using (var transaction = conn.BeginTransaction())
                    {
                        OnClone(conn);
                        OnCreate(conn);
                        transaction.Commit();
                    }
                    conn.Close();
                }
                LinkedTableList.SetupTable(true);
                LinkedFooter.SetOperationMessage(SQLDB.CurrentTable + " Cloned", Colors.DarkTurquoise);
            }
        }
        // Heavily relies on the BaseObject table: Lists the rows of the selected table in the navbar
        public void SetupTable(bool keepHighlightedButton)
        {
            AddNew.Background = Color(StandardNewColor);
            Title.Text        = SQLDB.CurrentTable;
            CurrentlySelected = null;
            TableSetup(RowsTable);
            int count = 0;

            using (var conn = AccessDB.Connect())
            {
                conn.Open();
                string query = "SELECT * FROM BaseObject JOIN " + SQLDB.CurrentTable + " WHERE BaseObject_ID = BaseObjectID ORDER BY Name ASC";
                using (SQLiteDataReader reader = SQLDB.Read(conn, query))
                {
                    if (keepHighlightedButton)
                    {
                        while (reader.Read())
                        {
                            CreateRowWithHighlighted(reader, RowsTable, count++);
                        }
                    }
                    else
                    {
                        while (reader.Read())
                        {
                            CreateRow(reader, RowsTable, count++);
                        }
                    }
                }
                Count.Text = "Total: " + count;
                conn.Close();
            }
        }
Beispiel #5
0
 // Sets up the list that will be added to the combobox input
 public ComboBoxInputData(string idAttribute, string nameAttribute, string queryTables,
                          string queryCondition, string sortAttributes, bool addNullInput = false)
 {
     SelectedIds    = new List <int>();
     OptionsListIds = addNullInput ? new List <int> {
         0
     } : new List <int>();
     OptionsListNames = addNullInput ? new List <string> {
         "None"
     } : new List <string>();
     using (var conn = AccessDB.Connect())
     {
         conn.Open();
         string select = "SELECT " + idAttribute + ", " + nameAttribute + " FROM " + queryTables;
         using (var reader = SQLDB.Read(conn, select + " WHERE " + queryCondition + " ORDER BY " + sortAttributes + " ASC;"))
         {
             while (reader.Read())
             {
                 OptionsListIds.Add(int.Parse(reader[idAttribute].ToString()));
                 OptionsListNames.Add(reader[nameAttribute].ToString());
             }
         }
         conn.Close();
     }
 }
Beispiel #6
0
        public void Clone()
        {
            string err = ValidateInputs();

            if (err != "")
            {
                MessageBox.Show("Could not clone " + SQLDB.CurrentTable + ":\n\n" + err);
            }
            else
            {
                SQLDB.CurrentId = SQLDB.MaxIdPlusOne(SQLDB.CurrentTable);
                using (var conn = AccessDB.Connect())
                {
                    conn.Open();
                    using (var transaction = conn.BeginTransaction())
                    {
                        OnClone(conn);
                        OnCreate(conn);
                        transaction.Commit();
                    }
                    conn.Close();
                }
                MessageBox.Show(SQLDB.CurrentTable + " cloned");
            }
        }
Beispiel #7
0
 public void Read()
 {
     using (var conn = AccessDB.Connect())
     {
         conn.Open();
         using (var reader = SQLDB.Read(conn, "SELECT * FROM " + SQLDB.CurrentTable + " WHERE " + SQLDB.CurrentTable + "_ID = " + SQLDB.CurrentId.ToString()))
         {
             SetupTableData();
             reader.Read();
             OnRead(reader);
         }
         conn.Close();
     }
 }
 public void Read()
 {
     using (var conn = AccessDB.Connect())
     {
         conn.Open();
         using (var reader = SQLDB.Read(conn, "SELECT * FROM " + ClassTemplateTable + " WHERE " + ClassTemplateTable + "_ID = " + ClassTemplateId + ";"))
         {
             reader.Read();
             SetupTableData();
             OnRead(reader);
         }
         conn.Close();
     }
 }
 private void CBChangedEnemy(object sender, SelectionChangedEventArgs e)
 {
     using (var conn = AccessDB.Connect())
     {
         conn.Open();
         using (var reader = SQLDB.Read(conn, "SELECT Image FROM Enemy JOIN BaseObject " +
                                        "WHERE BaseObject_ID = BaseObjectID AND Enemy_ID = " + EnemyData.SelectedInput(EnemyInput) + ";"))
         {
             reader.Read();
             try { EnemyImage.Source = ImageManager.BytesToImage(ImageManager.BlobToBytes(reader, 0)); }
             catch (Exception) { EnemyImage.Source = null; }
         }
         conn.Close();
     }
 }
Beispiel #10
0
 public void Read()
 {
     LinkedFooter.ApplyReadSettings();
     LinkedFooter.RemoveOperationMessage();
     using (var conn = AccessDB.Connect())
     {
         conn.Open();
         using (var reader = SQLDB.Read(conn, "SELECT * FROM " + SQLDB.CurrentTable + " WHERE " + SQLDB.CurrentTable + "_ID = " + SQLDB.CurrentId + ";"))
         {
             reader.Read();
             SetupTableData();
             OnRead(reader);
         }
         conn.Close();
     }
 }
Beispiel #11
0
        // When a new item is going to be created, the currentId gets set to a value +1 value higher than the max Id of the table
        public static int MaxIdPlusOne(string table)
        {
            int maxIdPlusOne;

            using (var conn = AccessDB.Connect())
            {
                conn.Open();
                using (var comm = new SQLiteCommand("SELECT MAX(" + table + "_ID) FROM " + table, conn))
                {
                    try { maxIdPlusOne = (int)((long)comm.ExecuteScalar()) + 1; }
                    catch (InvalidCastException) { maxIdPlusOne = 1; }
                }
                conn.Close();
            }
            return(maxIdPlusOne);
        }
Beispiel #12
0
        // Returns a scalar value, such as COUNT(*): This function is rarely ever used, if not at all
        public static int Scalar(string sqlCommand)
        {
            int val = 0;

            using (var conn = AccessDB.Connect())
            {
                conn.Open();
                using (var comm = new SQLiteCommand(sqlCommand, conn))
                {
                    try { val = (int)((long)comm.ExecuteScalar()); }
                    catch (Exception e) { MessageBox.Show(e.Message + "\nReturning default value 0", "Could not convert into a scalar"); }
                }
                conn.Close();
            }
            return(val);
        }
Beispiel #13
0
 public void Delete()
 {
     if (!Utils.Confirm("Are you sure?", "Deleting " + SQLDB.CurrentTable))
     {
         return;
     }
     using (var conn = AccessDB.Connect())
     {
         conn.Open();
         using (var transaction = conn.BeginTransaction())
         {
             OnDelete(conn);
             transaction.Commit();
         }
         conn.Close();
     }
     MessageBox.Show("Deleting successful");
     InitializeNew();
 }
Beispiel #14
0
 public void Delete()
 {
     if (!Utils.Confirm("Are you sure?", "Deleting " + SQLDB.CurrentTable))
     {
         return;
     }
     using (var conn = AccessDB.Connect())
     {
         conn.Open();
         using (var transaction = conn.BeginTransaction())
         {
             OnDelete(conn);
             transaction.Commit();
         }
         conn.Close();
     }
     InitializeNew();
     LinkedFooter.SetOperationMessage(SQLDB.CurrentTable + " Deleted", Colors.PaleVioletRed);
 }
 public void Read()
 {
     if (Table.ColumnDefinitions.Count <= 0)
     {
         return;
     }
     using (var conn = AccessDB.Connect())
     {
         conn.Open();
         string[] readStr = OnReadCommands();
         using (var reader = SQLDB.Read(conn, "SELECT * FROM " + readStr[0] + " WHERE " + readStr[1] + ";"))
         {
             while (reader.Read())
             {
                 AddRow(null, null);
                 OnRead(reader);
                 AddRangeToTable();
             }
         }
         conn.Close();
     }
 }
Beispiel #16
0
        public void Update()
        {
            string err = ValidateInputs();

            if (err != "")
            {
                MessageBox.Show("Could not update due to the following:\n\n" + err);
            }
            else
            {
                using (var conn = AccessDB.Connect())
                {
                    conn.Open();
                    using (var transaction = conn.BeginTransaction())
                    {
                        OnUpdate(conn);
                        transaction.Commit();
                    }
                    conn.Close();
                }
                MessageBox.Show("Updating successful");
            }
        }
        // Helper method of Setup: Get Id of the host DB table that matches the current DB table the user is currently viewing
        protected virtual int GetHostId()
        {
            if (SQLDB.CurrentTable == HostDBTable)
            {
                return(SQLDB.CurrentId);
            }
            int id;

            using (var conn = AccessDB.Connect())
            {
                conn.Open();
                string select = "SELECT  " + HostDBTable + "_ID FROM " + SQLDB.CurrentTable + " JOIN " + HostDBTable;
                string where = "WHERE " + HostDBTable + "_ID = " + HostDBTable + "ID AND " + SQLDB.CurrentTable + "_ID = " + SQLDB.CurrentId;
                using (var reader = SQLDB.Read(conn, select + " " + where + ";"))
                {
                    reader.Read();
                    try { id = int.Parse(reader[HostDBTable + "_ID"].ToString()); }
                    catch (InvalidOperationException) { id = SQLDB.CurrentId; }
                }
                conn.Close();
            }
            return(id);
        }