/// <summary>
/// Load sql string from *.sql File into active TabPage with TextBox inside.
/// <para/>- Update and save the list of sql files
/// </summary>
public void LoadTabPagePerFileDialog()
{
TabPage tabPage;
// no tab page exists
if (_tabControl.TabPages.Count == 0)
{
tabPage = AddTab();
}
else
{
// get TabPage
if (_tabControl.SelectedIndex < 0) return;
tabPage = _tabControl.TabPages[_tabControl.SelectedIndex];
// If contend changed: Store first
SqlFile sqlFile = (SqlFile)tabPage.Tag;
if (sqlFile.IsChanged)
{
DialogResult result = MessageBox.Show($"Old File: '{sqlFile.FullName}'",
@"First store old File? ", MessageBoxButtons.YesNoCancel);
if (result == DialogResult.Cancel) return;
if (result == DialogResult.Yes)
{
Save(tabPage);
sqlFile.IsChanged = false;
tabPage.ToolTipText = ((SqlFile)tabPage.Tag).FullName;
}
}
}
OpenFileDialog openFileDialog = new OpenFileDialog
{
InitialDirectory = @"c:\temp\sql",
RestoreDirectory = true,
Filter = @"sql files (*.sql)|*.sql|All files (*.*)|*.*",
FilterIndex = 1
};
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
string fileName = openFileDialog.FileName;
if (!string.IsNullOrEmpty(fileName))
{
// get TextBox
var textBox = (TextBoxUndo)tabPage.Controls[0];
SqlFile sqlFile = new SqlFile(this, fileName, isChanged: false);
tabPage.Tag = sqlFile;
sqlFile.IsChanged = false;
tabPage.Text = sqlFile.DisplayName;
textBox.Text = sqlFile.Load();
sqlFile.IsChanged = false;
// store the complete filename in settings
InsertRecentFileLists(openFileDialog.FileName);
Settings.Save();
// Load recent files into ToolStripMenu
LoadRecentFilesIntoToolStripItems();
}
}
// update Tab Caption
tabPage.ToolTipText = ((SqlFile)tabPage.Tag).FullName;
tabPage.Text = ((SqlFile)tabPage.Tag).DisplayName;
}