예제 #1
0
        internal static void AddTable(string tabName)
        {
            string error = GenericFunct.ValidateNameInput(tabName);

            if (error == "")
            {
                if (!currentData.Keys.Contains(tabName))
                {
                    //add dictionary with empty rowEntry database
                    currentData.Add(tabName, new Dictionary <string, dynamic>()
                    {
                        { RowEntryRefrence, new Dictionary <int, Dictionary <string, dynamic> >() }, { ColumnOrderRefrence, new List <string>() }
                    });

                    Program.mainForm.tabControl1.TabPages.Add(tabName, tabName);

                    Program.mainForm.label1.Visible = false;

                    //change color of tab
                    Program.mainForm.tabControl1.TabPages[Program.mainForm.tabControl1.TabPages.IndexOfKey(tabName)].BackColor = ColorThemes.Themes[ColorThemes.currentTheme]["ElseBack"];
                    Program.mainForm.tabControl1.TabPages[Program.mainForm.tabControl1.TabPages.IndexOfKey(tabName)].ForeColor = ColorThemes.Themes[ColorThemes.currentTheme]["ElseFore"];



                    //select new tab
                    Program.mainForm.tabControl1.SelectedTab = Program.mainForm.tabControl1.TabPages[Program.mainForm.tabControl1.TabPages.IndexOfKey(tabName)];
                    ChangeMainTable(tabName);
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("that table already exists!");
                }
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("table name entered " + error);
            }
        }
예제 #2
0
        internal static void ChangeTableName(string tabName, string newTabName)
        {
            if (currentData.Keys.Contains(tabName))
            {
                string error = GenericFunct.ValidateNameInput(newTabName);


                if (error == "")
                {
                    if (!currentData.Keys.Contains(newTabName))
                    {
                        List <string> keysToRemove = new List <string>();
                        SortedDictionary <string, dynamic> renamedEntries = new SortedDictionary <string, dynamic>();
                        List <dynamic[]> refrenceEntries = new List <dynamic[]>();

                        foreach (string key in currentData.Keys)
                        {
                            //for all table data
                            if (key.StartsWith(tabName + "/") || key == tabName)
                            {
                                string newKey = newTabName + key.Remove(0, tabName.Length);
                                //old keys to be removed
                                keysToRemove.Add(key);
                                //re-implement under new name
                                renamedEntries[newKey] = currentData[key];
                            }

                            //change refrences to renamed table
                            foreach (string subKey in currentData[key].Keys)
                            {
                                //foreign key refrence to this table
                                if (subKey.EndsWith(RefrenceColumnKeyExt) && currentData[key][subKey] == tabName)
                                {
                                    refrenceEntries.Add(new dynamic[] { key, subKey, newTabName });
                                }
                                //change subtable refrences with this as the main table
                                if (subKey.EndsWith(ParentSubTableRefrenceColumnKeyExt) && currentData[key][subKey].StartsWith(tabName + "/"))
                                {
                                    string refAlt = newTabName + currentData[key][subKey].Remove(0, tabName.Length);
                                    refrenceEntries.Add(new dynamic[] { key, subKey, refAlt });
                                }
                            }
                        }

                        //----------------------------------------------------------------------
                        //make changes to currentData

                        //apply altered refrence entries (this should also change entries within renamedEntries)
                        foreach (dynamic[] refEnt in refrenceEntries)
                        {
                            string key    = refEnt[0];
                            string subKey = refEnt[1];
                            string refAlt = refEnt[2];

                            currentData[key][subKey] = refAlt;
                        }

                        //
                        foreach (string key in keysToRemove)
                        {
                            //remove old keys
                            currentData.Remove(key);
                        }

                        //concat current data with renamed entries
                        foreach (KeyValuePair <string, dynamic> KV in renamedEntries)
                        {
                            currentData.Add(KV.Key, KV.Value);
                        }

                        if (Program.mainForm.tabControl1.TabPages.ContainsKey(tabName))
                        {
                            //change tabcontrol data
                            Program.mainForm.tabControl1.TabPages[tabName].Text = newTabName;
                            Program.mainForm.tabControl1.TabPages[tabName].Name = newTabName;
                        }

                        //refresh table if it is the currently selected table (so that DGVs are renamed)
                        if (Program.mainForm.tabControl1.SelectedTab.Name == newTabName)
                        {
                            ChangeMainTable(newTabName);
                        }
                    }
                    else
                    {
                        System.Windows.Forms.MessageBox.Show("that table name already exists");
                    }
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("table entered " + error);
                }
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("table entered doesn't exist!");
            }
        }