Windows Form File /DBCommander/MainForm.cs (C#)
using System;  
using System.Drawing;  
using System.Collections;  
using System.ComponentModel;  
using System.Windows.Forms;  
using System.Data;  
using System.Threading;  
using System.Runtime.InteropServices;  
using YariSoft.Utils;  
  
namespace YariSoft.DBCommander  
{  
    public class MainForm : System.Windows.Forms.Form  
    {  
        #region Private variables declaration  
        private const string applicationName    = "Database Commander";  
        private const string optionsFileName    = "Options.xml";  
  
        private YariSoft.DBCommander.Misc.OptionsInfo options          
                                                = null;  
        private YariSoft.DBCommander.Misc.ConfigInfo  config          
                                                = null;  
        private DataPanel        focusPanel        = null;  
        private YariSoft.Utils.AgentManager  
                                agent            = new YariSoft.Utils.AgentManager();                  
  
        private System.Windows.Forms.MainMenu mainMenu;  
        private System.Windows.Forms.MenuItem fileMenuItem;  
        private System.Windows.Forms.MenuItem aboutMenuItem;  
        private System.Windows.Forms.MenuItem operationMenuItem;  
        private System.Windows.Forms.MenuItem connectionMenuItem;  
        private System.Windows.Forms.MenuItem viewMenuItem;  
        private System.Windows.Forms.MenuItem editMenuItem;  
        private System.Windows.Forms.MenuItem copyMenuItem;  
        private System.Windows.Forms.MenuItem moveMenuItem;  
        private System.Windows.Forms.MenuItem createMenuItem;  
        private System.Windows.Forms.MenuItem deleteMenuItem;  
        private System.Windows.Forms.MenuItem downMenuItem;  
        private System.Windows.Forms.MenuItem upMenuItem;  
        private System.Windows.Forms.Splitter splitter;  
        private YariSoft.DBCommander.DataPanel leftDataPanel;  
        private YariSoft.DBCommander.DataPanel rightDataPanel;  
        private System.Windows.Forms.ToolBar operationBar;  
        private System.Windows.Forms.ToolBarButton botViewButton;  
        private System.Windows.Forms.ToolBarButton botEditButton;  
        private System.Windows.Forms.ToolBarButton botCopyButton;  
        private System.Windows.Forms.ToolBarButton botMoveButton;  
        private System.Windows.Forms.ToolBarButton botCreateButton;  
        private System.Windows.Forms.ToolBarButton botDeleteButton;  
        private System.Windows.Forms.ToolBarButton botConnectionButton;  
        private System.Windows.Forms.ToolBarButton botUpButton;  
        private System.Windows.Forms.ToolBarButton botDownButton;  
        private System.Windows.Forms.MenuItem menuItem7;  
        private System.Windows.Forms.MenuItem exitMenuItem;  
        private System.Windows.Forms.MenuItem newMenuItem;  
        private System.Windows.Forms.MenuItem openMenuItem;  
        private System.Windows.Forms.MenuItem menuSeparator0;  
        private System.Windows.Forms.MenuItem saveMenuItem;  
        private System.Windows.Forms.MenuItem saveAsmenuItem;  
        private System.Windows.Forms.MenuItem menuSeparator1;  
        private System.Windows.Forms.MenuItem optionsMenuItem;  
        private System.Windows.Forms.MenuItem menuSeparator2;  
        private System.Windows.Forms.ToolBar toolBar;  
        private System.Windows.Forms.ImageList imageList;  
        private System.Windows.Forms.ToolBarButton toolSep0;  
        private System.Windows.Forms.ToolBarButton toolNewButton;  
        private System.Windows.Forms.ToolBarButton toolOpenButton;  
        private System.Windows.Forms.ToolBarButton toolSaveButton;  
        private System.Windows.Forms.ToolBarButton toolSep1;  
        private System.Windows.Forms.ToolBarButton toolConnectionButton;  
        private System.Windows.Forms.ToolBarButton toolUpButton;  
        private System.Windows.Forms.ToolBarButton toolDownButton;  
        private System.Windows.Forms.ToolBarButton toolSep2;  
        private System.Windows.Forms.ToolBarButton toolOptionsButton;  
        private System.Windows.Forms.MenuItem helpMenuItem;  
        private System.Windows.Forms.MenuItem genaralMenuItem;  
        private System.Windows.Forms.MenuItem chanegPanelMenuItem;  
        private System.Windows.Forms.MenuItem selectMenuItem;  
        private System.Windows.Forms.MenuItem unselectMenuItem;  
        private System.Windows.Forms.MenuItem menuSeparator3;  
        private System.Windows.Forms.MenuItem menuSeparator4;  
        private System.Windows.Forms.MenuItem refreshMenuItem;  
        private System.Windows.Forms.ToolBarButton toolRefreshButton;  
        private System.Windows.Forms.MenuItem hideLeftPanelMenuItem;  
        private System.Windows.Forms.MenuItem hideRightPanelMenuItem;  
        private System.Windows.Forms.MenuItem menuSeparator5;  
        private System.Windows.Forms.MenuItem menuSeparator6;  
        private System.Windows.Forms.MenuItem filterMenuItem;  
        private System.Windows.Forms.MenuItem clearFilterMenuItem;  
        private System.ComponentModel.IContainer components = null;  
        #endregion  
  
        #region Constructor/destructor  
        [STAThread]  
        static void Main()  
        {  
            YariSoft.Exceptions.YSExceptionHandler exceptionHandler = new YariSoft.Exceptions.YSExceptionHandler();  
            Application.ThreadException += new ThreadExceptionEventHandler ( exceptionHandler.OnThreadException );          
            Application.Run(new MainForm());  
        }  
  
        public MainForm()  
        {  
            InitializeComponent();  
            this.leftDataPanel.OnGridClick += new DataPanel.OnGridClickEventHandler( this.OnPanelGridClick );  
            this.rightDataPanel.OnGridClick += new DataPanel.OnGridClickEventHandler( this.OnPanelGridClick );  
        }  
  
        protected override void Dispose( bool disposing )  
        {  
            if( disposing ){  
                if (components != null) {  
                    components.Dispose();  
                }  
            }  
            base.Dispose( disposing );  
        }  
        #endregion  
  
        #region Windows Form Designer generated code  
        /// <summary>  
        /// Required method for Designer support - do not modify  
        /// the contents of this method with the code editor.  
        /// </summary>  
        private void InitializeComponent()  
        {  
            this.components = new System.ComponentModel.Container();  
            System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MainForm));  
            this.mainMenu = new System.Windows.Forms.MainMenu();  
            this.fileMenuItem = new System.Windows.Forms.MenuItem();  
            this.newMenuItem = new System.Windows.Forms.MenuItem();  
            this.openMenuItem = new System.Windows.Forms.MenuItem();  
            this.menuSeparator0 = new System.Windows.Forms.MenuItem();  
            this.saveMenuItem = new System.Windows.Forms.MenuItem();  
            this.saveAsmenuItem = new System.Windows.Forms.MenuItem();  
            this.menuSeparator1 = new System.Windows.Forms.MenuItem();  
            this.optionsMenuItem = new System.Windows.Forms.MenuItem();  
            this.menuSeparator2 = new System.Windows.Forms.MenuItem();  
            this.exitMenuItem = new System.Windows.Forms.MenuItem();  
            this.operationMenuItem = new System.Windows.Forms.MenuItem();  
            this.genaralMenuItem = new System.Windows.Forms.MenuItem();  
            this.connectionMenuItem = new System.Windows.Forms.MenuItem();  
            this.viewMenuItem = new System.Windows.Forms.MenuItem();  
            this.editMenuItem = new System.Windows.Forms.MenuItem();  
            this.copyMenuItem = new System.Windows.Forms.MenuItem();  
            this.moveMenuItem = new System.Windows.Forms.MenuItem();  
            this.createMenuItem = new System.Windows.Forms.MenuItem();  
            this.deleteMenuItem = new System.Windows.Forms.MenuItem();  
            this.downMenuItem = new System.Windows.Forms.MenuItem();  
            this.upMenuItem = new System.Windows.Forms.MenuItem();  
            this.chanegPanelMenuItem = new System.Windows.Forms.MenuItem();  
            this.menuSeparator3 = new System.Windows.Forms.MenuItem();  
            this.selectMenuItem = new System.Windows.Forms.MenuItem();  
            this.unselectMenuItem = new System.Windows.Forms.MenuItem();  
            this.menuSeparator6 = new System.Windows.Forms.MenuItem();  
            this.filterMenuItem = new System.Windows.Forms.MenuItem();  
            this.clearFilterMenuItem = new System.Windows.Forms.MenuItem();  
            this.menuSeparator4 = new System.Windows.Forms.MenuItem();  
            this.hideLeftPanelMenuItem = new System.Windows.Forms.MenuItem();  
            this.hideRightPanelMenuItem = new System.Windows.Forms.MenuItem();  
            this.menuSeparator5 = new System.Windows.Forms.MenuItem();  
            this.refreshMenuItem = new System.Windows.Forms.MenuItem();  
            this.helpMenuItem = new System.Windows.Forms.MenuItem();  
            this.aboutMenuItem = new System.Windows.Forms.MenuItem();  
            this.leftDataPanel = new YariSoft.DBCommander.DataPanel();  
            this.splitter = new System.Windows.Forms.Splitter();  
            this.rightDataPanel = new YariSoft.DBCommander.DataPanel();  
            this.operationBar = new System.Windows.Forms.ToolBar();  
            this.botConnectionButton = new System.Windows.Forms.ToolBarButton();  
            this.botViewButton = new System.Windows.Forms.ToolBarButton();  
            this.botEditButton = new System.Windows.Forms.ToolBarButton();  
            this.botCopyButton = new System.Windows.Forms.ToolBarButton();  
            this.botMoveButton = new System.Windows.Forms.ToolBarButton();  
            this.botCreateButton = new System.Windows.Forms.ToolBarButton();  
            this.botDeleteButton = new System.Windows.Forms.ToolBarButton();  
            this.botDownButton = new System.Windows.Forms.ToolBarButton();  
            this.botUpButton = new System.Windows.Forms.ToolBarButton();  
            this.menuItem7 = new System.Windows.Forms.MenuItem();  
            this.toolBar = new System.Windows.Forms.ToolBar();  
            this.toolSep0 = new System.Windows.Forms.ToolBarButton();  
            this.toolNewButton = new System.Windows.Forms.ToolBarButton();  
            this.toolOpenButton = new System.Windows.Forms.ToolBarButton();  
            this.toolSaveButton = new System.Windows.Forms.ToolBarButton();  
            this.toolSep1 = new System.Windows.Forms.ToolBarButton();  
            this.toolConnectionButton = new System.Windows.Forms.ToolBarButton();  
            this.toolDownButton = new System.Windows.Forms.ToolBarButton();  
            this.toolUpButton = new System.Windows.Forms.ToolBarButton();  
            this.toolRefreshButton = new System.Windows.Forms.ToolBarButton();  
            this.toolSep2 = new System.Windows.Forms.ToolBarButton();  
            this.toolOptionsButton = new System.Windows.Forms.ToolBarButton();  
            this.imageList = new System.Windows.Forms.ImageList(this.components);  
            this.SuspendLayout();  
            //    
            // mainMenu  
            //    
            this.mainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {  
                                                                                     this.fileMenuItem,  
                                                                                     this.operationMenuItem,  
                                                                                     this.helpMenuItem});  
            //    
            // fileMenuItem  
            //    
            this.fileMenuItem.Index = 0;  
            this.fileMenuItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {  
                                                                                         this.newMenuItem,  
                                                                                         this.openMenuItem,  
                                                                                         this.menuSeparator0,  
                                                                                         this.saveMenuItem,  
                                                                                         this.saveAsmenuItem,  
                                                                                         this.menuSeparator1,  
                                                                                         this.optionsMenuItem,  
                                                                                         this.menuSeparator2,  
                                                                                         this.exitMenuItem});  
            this.fileMenuItem.Text = "&File";  
            //    
            // newMenuItem  
            //    
            this.newMenuItem.Index = 0;  
            this.newMenuItem.Text = "&New";  
            this.newMenuItem.Click += new System.EventHandler(this.newMenuItem_Click);  
            //    
            // openMenuItem  
            //    
            this.openMenuItem.Index = 1;  
            this.openMenuItem.Text = "&Open";  
            this.openMenuItem.Click += new System.EventHandler(this.openMenuItem_Click);  
            //    
            // menuSeparator0  
            //    
            this.menuSeparator0.Index = 2;  
            this.menuSeparator0.Text = "-";  
            //    
            // saveMenuItem  
            //    
            this.saveMenuItem.Index = 3;  
            this.saveMenuItem.Text = "&Save";  
            this.saveMenuItem.Click += new System.EventHandler(this.saveMenuItem_Click);  
            //    
            // saveAsmenuItem  
            //    
            this.saveAsmenuItem.Index = 4;  
            this.saveAsmenuItem.Text = "Save &as...";  
            this.saveAsmenuItem.Click += new System.EventHandler(this.saveAsmenuItem_Click);  
            //    
            // menuSeparator1  
            //    
            this.menuSeparator1.Index = 5;  
            this.menuSeparator1.Text = "-";  
            //    
            // optionsMenuItem  
            //    
            this.optionsMenuItem.Index = 6;  
            this.optionsMenuItem.Text = "Op&tions";  
            this.optionsMenuItem.Click += new System.EventHandler(this.optionsMenuItem_Click);  
            //    
            // menuSeparator2  
            //    
            this.menuSeparator2.Index = 7;  
            this.menuSeparator2.Text = "-";  
            //    
            // exitMenuItem  
            //    
            this.exitMenuItem.Index = 8;  
            this.exitMenuItem.Shortcut = System.Windows.Forms.Shortcut.AltF4;  
            this.exitMenuItem.Text = "&Exit";  
            this.exitMenuItem.Click += new System.EventHandler(this.exitMenuItem_Click);  
            //    
            // operationMenuItem  
            //    
            this.operationMenuItem.Index = 1;  
            this.operationMenuItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {  
                                                                                              this.genaralMenuItem,  
                                                                                              this.chanegPanelMenuItem,  
                                                                                              this.menuSeparator3,  
                                                                                              this.selectMenuItem,  
                                                                                              this.unselectMenuItem,  
                                                                                              this.menuSeparator6,  
                                                                                              this.filterMenuItem,  
                                                                                              this.clearFilterMenuItem,  
                                                                                              this.menuSeparator4,  
                                                                                              this.hideLeftPanelMenuItem,  
                                                                                              this.hideRightPanelMenuItem,  
                                                                                              this.menuSeparator5,  
                                                                                              this.refreshMenuItem});  
            this.operationMenuItem.Text = "&Operations";  
            //    
            // genaralMenuItem  
            //    
            this.genaralMenuItem.Index = 0;  
            this.genaralMenuItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {  
                                                                                            this.connectionMenuItem,  
                                                                                            this.viewMenuItem,  
                                                                                            this.editMenuItem,  
                                                                                            this.copyMenuItem,  
                                                                                            this.moveMenuItem,  
                                                                                            this.createMenuItem,  
                                                                                            this.deleteMenuItem,  
                                                                                            this.downMenuItem,  
                                                                                            this.upMenuItem});  
            this.genaralMenuItem.Text = "&General";  
            //    
            // connectionMenuItem  
            //    
            this.connectionMenuItem.Index = 0;  
            this.connectionMenuItem.Shortcut = System.Windows.Forms.Shortcut.F2;  
            this.connectionMenuItem.Text = "Connection";  
            this.connectionMenuItem.Click += new System.EventHandler(this.connectionMenuItem_Click);  
            //    
            // viewMenuItem  
            //    
            this.viewMenuItem.Enabled = false;  
            this.viewMenuItem.Index = 1;  
            this.viewMenuItem.Shortcut = System.Windows.Forms.Shortcut.F3;  
            this.viewMenuItem.Text = "View";  
            this.viewMenuItem.Click += new System.EventHandler(this.viewMenuItem_Click);  
            //    
            // editMenuItem  
            //    
            this.editMenuItem.Enabled = false;  
            this.editMenuItem.Index = 2;  
            this.editMenuItem.Shortcut = System.Windows.Forms.Shortcut.F4;  
            this.editMenuItem.Text = "Edit";  
            this.editMenuItem.Click += new System.EventHandler(this.editMenuItem_Click);  
            //    
            // copyMenuItem  
            //    
            this.copyMenuItem.Index = 3;  
            this.copyMenuItem.Shortcut = System.Windows.Forms.Shortcut.F5;  
            this.copyMenuItem.Text = "Copy";  
            this.copyMenuItem.Click += new System.EventHandler(this.copyMenuItem_Click);  
            //    
            // moveMenuItem  
            //    
            this.moveMenuItem.Index = 4;  
            this.moveMenuItem.Shortcut = System.Windows.Forms.Shortcut.F6;  
            this.moveMenuItem.Text = "Move";  
            this.moveMenuItem.Click += new System.EventHandler(this.moveMenuItem_Click);  
            //    
            // createMenuItem  
            //    
            this.createMenuItem.Enabled = false;  
            this.createMenuItem.Index = 5;  
            this.createMenuItem.Shortcut = System.Windows.Forms.Shortcut.F7;  
            this.createMenuItem.Text = "Create";  
            this.createMenuItem.Click += new System.EventHandler(this.createMenuItem_Click);  
            //    
            // deleteMenuItem  
            //    
            this.deleteMenuItem.Index = 6;  
            this.deleteMenuItem.Shortcut = System.Windows.Forms.Shortcut.F8;  
            this.deleteMenuItem.Text = "Delete";  
            this.deleteMenuItem.Click += new System.EventHandler(this.deleteMenuItem_Click);  
            //    
            // downMenuItem  
            //    
            this.downMenuItem.Index = 7;  
            this.downMenuItem.Shortcut = System.Windows.Forms.Shortcut.F9;  
            this.downMenuItem.Text = "Down";  
            this.downMenuItem.Click += new System.EventHandler(this.downMenuItem_Click);  
            //    
            // upMenuItem  
            //    
            this.upMenuItem.Index = 8;  
            this.upMenuItem.Shortcut = System.Windows.Forms.Shortcut.F10;  
            this.upMenuItem.Text = "Up";  
            this.upMenuItem.Click += new System.EventHandler(this.upMenuItem_Click);  
            //    
            // chanegPanelMenuItem  
            //    
            this.chanegPanelMenuItem.Index = 1;  
            this.chanegPanelMenuItem.Text = "&Change panel         Ctrl+Tab";  
            this.chanegPanelMenuItem.Click += new System.EventHandler(this.chanegPanelMenuItem_Click);  
            //    
            // menuSeparator3  
            //    
            this.menuSeparator3.Index = 2;  
            this.menuSeparator3.Text = "-";  
            //    
            // selectMenuItem  
            //    
            this.selectMenuItem.Index = 3;  
            this.selectMenuItem.Text = "&Select                     +";  
            this.selectMenuItem.Click += new System.EventHandler(this.selectMenuItem_Click);  
            //    
            // unselectMenuItem  
            //    
            this.unselectMenuItem.Index = 4;  
            this.unselectMenuItem.Text = "&Unselect                 -";  
            this.unselectMenuItem.Click += new System.EventHandler(this.unselectMenuItem_Click);  
            //    
            // menuSeparator6  
            //    
            this.menuSeparator6.Index = 5;  
            this.menuSeparator6.Text = "-";  
            //    
            // filterMenuItem  
            //    
            this.filterMenuItem.Index = 6;  
            this.filterMenuItem.Text = "&Filter                       *";  
            this.filterMenuItem.Click += new System.EventHandler(this.filterMenuItem_Click);  
            //    
            // clearFilterMenuItem  
            //    
            this.clearFilterMenuItem.Index = 7;  
            this.clearFilterMenuItem.Text = "&Clear Filter              /";  
            this.clearFilterMenuItem.Click += new System.EventHandler(this.clearFilterMenuItem_Click);  
            //    
            // menuSeparator4  
            //    
            this.menuSeparator4.Index = 8;  
            this.menuSeparator4.Text = "-";  
            //    
            // hideLeftPanelMenuItem  
            //    
            this.hideLeftPanelMenuItem.Index = 9;  
            this.hideLeftPanelMenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlF1;  
            this.hideLeftPanelMenuItem.ShowShortcut = false;  
            this.hideLeftPanelMenuItem.Text = "&Left panel on/off    Ctrl+F1";  
            this.hideLeftPanelMenuItem.Click += new System.EventHandler(this.hideLeftPanelMenuItem_Click);  
            //    
            // hideRightPanelMenuItem  
            //    
            this.hideRightPanelMenuItem.Index = 10;  
            this.hideRightPanelMenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlF2;  
            this.hideRightPanelMenuItem.ShowShortcut = false;  
            this.hideRightPanelMenuItem.Text = "R&ight panel on/off  Ctrl+F2";  
            this.hideRightPanelMenuItem.Click += new System.EventHandler(this.hideRightPanelMenuItem_Click);  
            //    
            // menuSeparator5  
            //    
            this.menuSeparator5.Index = 11;  
            this.menuSeparator5.Text = "-";  
            //    
            // refreshMenuItem  
            //    
            this.refreshMenuItem.Index = 12;  
            this.refreshMenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlR;  
            this.refreshMenuItem.ShowShortcut = false;  
            this.refreshMenuItem.Text = "&Refresh                  Ctrl+R";  
            this.refreshMenuItem.Click += new System.EventHandler(this.refreshMenuItem_Click);  
            //    
            // helpMenuItem  
            //    
            this.helpMenuItem.Index = 2;  
            this.helpMenuItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {  
                                                                                         this.aboutMenuItem});  
            this.helpMenuItem.Text = "&Help";  
            //    
            // aboutMenuItem  
            //    
            this.aboutMenuItem.Index = 0;  
            this.aboutMenuItem.Text = "&About";  
            this.aboutMenuItem.Click += new System.EventHandler(this.aboutMenuItem_Click);  
            //    
            // leftDataPanel  
            //    
            this.leftDataPanel.Dock = System.Windows.Forms.DockStyle.Left;  
            this.leftDataPanel.Location = new System.Drawing.Point(0, 25);  
            this.leftDataPanel.Name = "leftDataPanel";  
            this.leftDataPanel.Size = new System.Drawing.Size(396, 516);  
            this.leftDataPanel.TabIndex = 1;  
            //    
            // splitter  
            //    
            this.splitter.Location = new System.Drawing.Point(396, 25);  
            this.splitter.Name = "splitter";  
            this.splitter.Size = new System.Drawing.Size(3, 516);  
            this.splitter.TabIndex = 11;  
            this.splitter.TabStop = false;  
            //    
            // rightDataPanel  
            //    
            this.rightDataPanel.Dock = System.Windows.Forms.DockStyle.Fill;  
            this.rightDataPanel.Location = new System.Drawing.Point(399, 25);  
            this.rightDataPanel.Name = "rightDataPanel";  
            this.rightDataPanel.Size = new System.Drawing.Size(393, 516);  
            this.rightDataPanel.TabIndex = 2;  
            //    
            // operationBar  
            //    
            this.operationBar.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {  
                                                                                            this.botConnectionButton,  
                                                                                            this.botViewButton,  
                                                                                            this.botEditButton,  
                                                                                            this.botCopyButton,  
                                                                                            this.botMoveButton,  
                                                                                            this.botCreateButton,  
                                                                                            this.botDeleteButton,  
                                                                                            this.botDownButton,  
                                                                                            this.botUpButton});  
            this.operationBar.ButtonSize = new System.Drawing.Size(100, 22);  
            this.operationBar.Dock = System.Windows.Forms.DockStyle.Bottom;  
            this.operationBar.DropDownArrows = true;  
            this.operationBar.Font = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));  
            this.operationBar.Location = new System.Drawing.Point(0, 541);  
            this.operationBar.Name = "operationBar";  
            this.operationBar.ShowToolTips = true;  
            this.operationBar.Size = new System.Drawing.Size(792, 25);  
            this.operationBar.TabIndex = 3;  
            this.operationBar.TextAlign = System.Windows.Forms.ToolBarTextAlign.Right;  
            this.operationBar.Wrappable = false;  
            this.operationBar.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.operationBar_ButtonClick);  
            //    
            // botConnectionButton  
            //    
            this.botConnectionButton.Text = "F2 Connect";  
            //    
            // botViewButton  
            //    
            this.botViewButton.Enabled = false;  
            this.botViewButton.Text = "F3 View";  
            //    
            // botEditButton  
            //    
            this.botEditButton.Enabled = false;  
            this.botEditButton.Text = "F4 Edit";  
            //    
            // botCopyButton  
            //    
            this.botCopyButton.Text = "F5 Copy";  
            //    
            // botMoveButton  
            //    
            this.botMoveButton.Text = "F6 Move";  
            //    
            // botCreateButton  
            //    
            this.botCreateButton.Enabled = false;  
            this.botCreateButton.Text = "F7 Create";  
            //    
            // botDeleteButton  
            //    
            this.botDeleteButton.Text = "F8 Delete";  
            //    
            // botDownButton  
            //    
            this.botDownButton.Text = "F9 Down";  
            //    
            // botUpButton  
            //    
            this.botUpButton.Text = "F10 Up";  
            //    
            // menuItem7  
            //    
            this.menuItem7.Index = -1;  
            this.menuItem7.Text = "";  
            //    
            // toolBar  
            //    
            this.toolBar.Appearance = System.Windows.Forms.ToolBarAppearance.Flat;  
            this.toolBar.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {  
                                                                                       this.toolSep0,  
                                                                                       this.toolNewButton,  
                                                                                       this.toolOpenButton,  
                                                                                       this.toolSaveButton,  
                                                                                       this.toolSep1,  
                                                                                       this.toolConnectionButton,  
                                                                                       this.toolDownButton,  
                                                                                       this.toolUpButton,  
                                                                                       this.toolRefreshButton,  
                                                                                       this.toolSep2,  
                                                                                       this.toolOptionsButton});  
            this.toolBar.ButtonSize = new System.Drawing.Size(24, 23);  
            this.toolBar.DropDownArrows = true;  
            this.toolBar.ImageList = this.imageList;  
            this.toolBar.Name = "toolBar";  
            this.toolBar.ShowToolTips = true;  
            this.toolBar.Size = new System.Drawing.Size(792, 25);  
            this.toolBar.TabIndex = 12;  
            this.toolBar.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar_ButtonClick);  
            //    
            // toolSep0  
            //    
            this.toolSep0.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;  
            //    
            // toolNewButton  
            //    
            this.toolNewButton.ImageIndex = 0;  
            this.toolNewButton.ToolTipText = "New";  
            //    
            // toolOpenButton  
            //    
            this.toolOpenButton.ImageIndex = 1;  
            this.toolOpenButton.ToolTipText = "Open";  
            //    
            // toolSaveButton  
            //    
            this.toolSaveButton.ImageIndex = 2;  
            this.toolSaveButton.ToolTipText = "Save";  
            //    
            // toolSep1  
            //    
            this.toolSep1.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;  
            //    
            // toolConnectionButton  
            //    
            this.toolConnectionButton.ImageIndex = 7;  
            this.toolConnectionButton.ToolTipText = "Connection";  
            //    
            // toolDownButton  
            //    
            this.toolDownButton.ImageIndex = 5;  
            this.toolDownButton.ToolTipText = "Down";  
            //    
            // toolUpButton  
            //    
            this.toolUpButton.ImageIndex = 4;  
            this.toolUpButton.ToolTipText = "Up";  
            //    
            // toolRefreshButton  
            //    
            this.toolRefreshButton.ImageIndex = 8;  
            this.toolRefreshButton.ToolTipText = "Refresh";  
            //    
            // toolSep2  
            //    
            this.toolSep2.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;  
            //    
            // toolOptionsButton  
            //    
            this.toolOptionsButton.ImageIndex = 3;  
            this.toolOptionsButton.ToolTipText = "Options";  
            //    
            // imageList  
            //    
            this.imageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;  
            this.imageList.ImageSize = new System.Drawing.Size(16, 16);  
            this.imageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList.ImageStream")));  
            this.imageList.TransparentColor = System.Drawing.Color.Red;  
            //    
            // MainForm  
            //    
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);  
            this.ClientSize = new System.Drawing.Size(792, 566);  
            this.Controls.AddRange(new System.Windows.Forms.Control[] {  
                                                                          this.rightDataPanel,  
                                                                          this.splitter,  
                                                                          this.leftDataPanel,  
                                                                          this.operationBar,  
                                                                          this.toolBar});  
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));  
            this.KeyPreview = true;  
            this.Menu = this.mainMenu;  
            this.Name = "MainForm";  
            this.Text = "Database Commander";  
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;  
            this.Closing += new System.ComponentModel.CancelEventHandler(this.MainForm_Closing);  
            this.Load += new System.EventHandler(this.MainForm_Load);  
            this.ResumeLayout(false);  
  
        }  
        #endregion  
  
        #region MainForm events  
        protected override bool ProcessCmdKey( ref Message msg, Keys keyData )  
        {  
            if( msg.Msg == 0x100 || msg.Msg == 0x104 ){  
                if( keyData == ( Keys.Control | Keys.Tab ) ){  
                    this.ChangeActivePanel();  
                    return true;  
                }  
  
                if( keyData == ( Keys.Alt | Keys.F1 ) ){  
                    if( this.focusPanel != this.leftDataPanel ){  
                        this.ChangeActivePanel();  
                    }  
                    this.leftDataPanel.OpenTableComboBox();  
                    return true;  
                }  
  
                if( keyData == ( Keys.Alt | Keys.F2 ) ){  
                    if( this.focusPanel != this.rightDataPanel ){  
                        this.ChangeActivePanel();  
                    }  
  
                    this.rightDataPanel.OpenTableComboBox();  
                    return true;  
                }  
            }  
      
            return base.ProcessCmdKey(ref msg, keyData);  
        }  
  
        protected override void WndProc(ref System.Windows.Forms.Message m)  
        {  
            if ( (WinMessages)m.Msg == WinMessages.WM_AGENT_ACTION) {  
                Utils.AgentPlayer.MovieTypeEnum movieType = ( Utils.AgentPlayer.MovieTypeEnum )(int)m.LParam;  
                this.agent.Play( movieType );  
            }  
            base.WndProc(ref m);  
        }  
  
        private void MainForm_Load(object sender, System.EventArgs e)  
        {  
            this.Refresh();  
            this.leftDataPanel.Width = this.Width / 2;  
            this.operationBar.ButtonSize = new Size ( ( this.Width - 6 ) / this.operationBar.Buttons.Count, this.operationBar.ButtonSize.Height );  
            this.Refresh();  
  
            this.options = YariSoft.DBCommander.Misc.OptionsInfo.LoadFromFile( Application.StartupPath + "\\" + optionsFileName );  
            this.RefreshToolBars();  
              
            this.config = YariSoft.DBCommander.Misc.ConfigInfo.LoadFromFile ( this.options.PreviousConfigFileName );  
  
            this.rightDataPanel.OnNeedSetGridStyle      += new DataPanel.OnNeedSetGridStyleEventHandler        ( this.OnNeedSetGridStyle );  
            this.leftDataPanel.OnNeedSetGridStyle       += new DataPanel.OnNeedSetGridStyleEventHandler        ( this.OnNeedSetGridStyle );  
  
            this.InitConnections();  
            this.ChangeActivePanel();          
            this.Refresh();  
  
            this.leftDataPanel.OnChangeDetailLevel        += new DataPanel.OnChangeDetailLevelEventHandler    ( this.RefreshButtons );  
            this.leftDataPanel.OnNeedSelectionMasks        += new DataPanel.OnNeedSelectionMasksEventHandler    ( this.OnNeedSelectionMasks );  
            this.rightDataPanel.OnChangeDetailLevel      += new DataPanel.OnChangeDetailLevelEventHandler    ( this.RefreshButtons );  
            this.rightDataPanel.OnNeedSelectionMasks    += new DataPanel.OnNeedSelectionMasksEventHandler    ( this.OnNeedSelectionMasks );          
            this.rightDataPanel.OnColumnResize            += new DataPanel.OnColumnResizeEventHandler            ( this.OnColumnResize );  
            this.leftDataPanel.OnColumnResize            += new DataPanel.OnColumnResizeEventHandler            ( this.OnColumnResize );  
  
            this.SetIdentityState();  
            this.agent.Init ( this.options.AgentOptions, true );  
        }  
  
        private void MainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)  
        {  
            if( ! this.CheckChanges() ){  
                e.Cancel = true;  
                return;  
            }  
            this.options.PreviousConfigFileName = this.config.FileName;  
            this.options.SaveToFile();  
  
            if( this.options.AgentOptions.AgentActive ){  
                agent.Hide();  
            }  
        }  
  
        private void OnPanelGridClick( object owner, object sender, System.EventArgs e)  
        {  
            if( owner != this.focusPanel ){  
                this.ChangeActivePanel();  
            }  
        }  
  
        private void SetFormCaption()  
        {  
            this.Text =  applicationName + " - " + this.config.FileName;  
        }  
  
        private void InitConnections()  
        {  
            this.SetFormCaption();  
            this.Refresh();  
            this.leftDataPanel.Init    ( this.config.LeftConnection );  
            this.rightDataPanel.Init( this.config.RightConnection );  
        }  
        #endregion  
  
        #region Toolbars operations  
        private void RefreshToolBars()  
        {  
            if( this.options != null ){  
                this.operationBar.Visible    = this.options.ShowFuncBar;  
                this.toolBar.Visible        = this.options.ShowToolBar;  
            }  
        }  
  
        private void toolBar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)  
        {  
            if( e.Button == this.toolConnectionButton ){  
                this.connectionMenuItem_Click( sender, null );  
            } else if( e.Button == this.toolUpButton  ){  
                this.upMenuItem_Click( sender, null );  
            } else if( e.Button == this.toolDownButton  ){  
                this.downMenuItem_Click( sender, null );  
            } else if( e.Button == this.toolOptionsButton ){  
                this.optionsMenuItem_Click( sender, null );  
            } else if( e.Button == this.toolNewButton ){  
                this.newMenuItem_Click( sender, null );  
            } else if( e.Button == this.toolOpenButton ){  
                this.openMenuItem_Click( sender, null );  
            } else if( e.Button == this.toolSaveButton ){  
                this.saveMenuItem_Click( sender, null );  
            } else if( e.Button == this.toolRefreshButton ){  
                this.refreshMenuItem_Click( sender, null );  
            }  
        }  
  
        private void operationBar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)  
        {  
            if( e.Button == this.botConnectionButton ){  
                this.connectionMenuItem_Click( sender, null );  
            } else if( e.Button == this.botCopyButton ){  
                this.copyMenuItem_Click( sender, null );  
            } else if ( e.Button == this.botDeleteButton ){  
                this.deleteMenuItem_Click( sender, null );  
            } else if ( e.Button == this.botMoveButton ){  
                this.moveMenuItem_Click( sender, null );  
            } else if ( e.Button == this.botDownButton ){  
                this.downMenuItem_Click( sender, null );  
            } else if ( e.Button == this.botUpButton ){  
                this.upMenuItem_Click( sender, null );  
            }  
        }  
  
        private void newMenuItem_Click(object sender, System.EventArgs e)  
        {  
            if( ! this.CheckChanges() ){  
                return;  
            }  
            this.config = new YariSoft.DBCommander.Misc.ConfigInfo();  
            this.InitConnections();  
        }  
  
        private void openMenuItem_Click(object sender, System.EventArgs e)  
        {  
            if( ! this.CheckChanges() ){  
                return;  
            }  
  
            OpenFileDialog Dialog = new OpenFileDialog();  
            if( Dialog.ShowDialog() == DialogResult.Cancel ){  
                return;  
            }  
            string fileName = Dialog.FileName;  
            Dialog.Dispose();  
  
            this.config = YariSoft.DBCommander.Misc.ConfigInfo.LoadFromFile ( fileName );  
            this.InitConnections();  
        }  
  
        private void saveMenuItem_Click(object sender, System.EventArgs e)  
        {  
            this.UpdateGridStyles();  
            this.config.SaveToFile();  
            this.RefreshButtons();  
        }  
  
        private void saveAsmenuItem_Click(object sender, System.EventArgs e)  
        {  
            this.UpdateGridStyles();  
            this.config.SaveAsToFile();  
            this.SetFormCaption();  
            this.RefreshButtons();  
        }  
  
        private void optionsMenuItem_Click(object sender, System.EventArgs e)  
        {  
            Modals.OptionsForm options = new Modals.OptionsForm( this.options );  
            if( options.ShowDialog() == DialogResult.OK ){  
                this.RefreshToolBars();  
                this.SetIdentityState();  
                this.agent.Init ( this.options.AgentOptions, true );  
            }  
            options.Dispose();  
        }  
  
        private void exitMenuItem_Click(object sender, System.EventArgs e)  
        {  
            this.Close();  
        }  
  
        private void connectionMenuItem_Click(object sender, System.EventArgs e)  
        {  
            this.focusPanel.PrepareConnection();  
            if( this.focusPanel == this.leftDataPanel ){  
                this.config.LeftConnection  = this.leftDataPanel.Connection.ConnectionString;  
            }else{  
                this.config.RightConnection = this.rightDataPanel.Connection.ConnectionString;  
            }  
            this.RefreshButtons();  
        }  
  
        private void viewMenuItem_Click(object sender, System.EventArgs e)  
        {  
          
        }  
  
        private void editMenuItem_Click(object sender, System.EventArgs e)  
        {  
          
        }  
  
        private void copyMenuItem_Click(object sender, System.EventArgs e)  
        {  
            string Question = "Do you wish to copy selected row";  
            if( this.focusPanel.SelectedRows.Count > 1  ){  
                Question += "s";  
            }  
            Question += "?";  
            if( ! this.ShowQuestionToUser( Question, "Copy"  ) ){  
                return;  
            }  
  
            DataPanel previousFocusPanel = this.focusPanel;  
            this.focusPanel.CopyData( this.GetDestinationPanel() );          
            if( previousFocusPanel != this.focusPanel ){  
                this.ChangeActivePanel();  
            }  
        }  
  
        private void moveMenuItem_Click(object sender, System.EventArgs e)  
        {  
            string Question = "Do you wish to move selected row";  
            if( this.focusPanel.SelectedRows.Count > 1  ){  
                Question += "s";  
            }  
            Question += "?";  
            if( ! this.ShowQuestionToUser( Question, "Move"  ) ){  
                return;  
            }  
  
            if( this.focusPanel.CopyData( this.GetDestinationPanel() ) ){  
                this.focusPanel.DeleteData();  
            }  
        }  
  
        private void createMenuItem_Click(object sender, System.EventArgs e)  
        {  
  
        }  
  
        private void deleteMenuItem_Click(object sender, System.EventArgs e)  
        {  
            string Question = "Do you wish to delete selected row";  
            if( this.focusPanel.SelectedRows.Count > 1  ){  
                Question += "s";  
            }  
            Question += "?";  
            if( ! this.ShowQuestionToUser( Question, "Delete"  ) ){  
                return;  
            }  
  
            this.focusPanel.DeleteData();  
        }  
  
        private void downMenuItem_Click(object sender, System.EventArgs e)  
        {  
            this.focusPanel.MoveDown();          
        }  
  
        private void upMenuItem_Click(object sender, System.EventArgs e)  
        {  
            this.focusPanel.MoveUp();  
        }  
  
        private void aboutMenuItem_Click(object sender, System.EventArgs e)  
        {  
            YariSoft.DBCommander.Modals.AboutForm about = new YariSoft.DBCommander.Modals.AboutForm();  
            about.ShowDialog();  
            about.Dispose();  
        }  
        private void chanegPanelMenuItem_Click(object sender, System.EventArgs e)  
        {  
            this.ChangeActivePanel();          
        }  
  
        private void selectMenuItem_Click(object sender, System.EventArgs e)  
        {  
            SendKeys.Send( "{ADD}" );  
        }  
  
        private void unselectMenuItem_Click(object sender, System.EventArgs e)  
        {  
            SendKeys.Send( "{SUBTRACT}" );  
        }  
  
        private void filterMenuItem_Click(object sender, System.EventArgs e)  
        {  
            SendKeys.Send( "{MULTIPLY}" );  
        }  
  
        private void clearFilterMenuItem_Click(object sender, System.EventArgs e)  
        {  
            SendKeys.Send( "{DIVIDE}" );  
        }  
  
        private void refreshMenuItem_Click(object sender, System.EventArgs e)  
        {  
            this.focusPanel.RefreshData();  
        }  
  
        private void hideLeftPanelMenuItem_Click(object sender, System.EventArgs e)  
        {  
            this.ShowHidePanel( this.leftDataPanel );  
        }  
  
        private void hideRightPanelMenuItem_Click(object sender, System.EventArgs e)  
        {  
            this.ShowHidePanel( this.rightDataPanel );  
        }  
  
        #endregion  
  
        #region Other functions  
        private void ChangeActivePanel()  
        {  
            if( ! this.leftDataPanel.Visible || ! this.rightDataPanel.Visible ){  
                return;  
            }          
            this.ForceChangeActivePanel();  
        }  
  
        private void ForceChangeActivePanel()  
        {  
            if( this.focusPanel == this.leftDataPanel ){  
                this.focusPanel = this.rightDataPanel;  
                this.leftDataPanel.Active = false;  
            } else {  
                this.focusPanel = this.leftDataPanel;  
                this.rightDataPanel.Active = false;  
            }  
  
            this.RefreshButtons();  
            this.focusPanel.Focus();  
            this.focusPanel.Active = true;  
        }  
  
        private YariSoft.DBCommander.DataPanel GetDestinationPanel()  
        {  
            if( this.focusPanel == this.leftDataPanel ){  
                return this.rightDataPanel;  
            } else {  
                return this.leftDataPanel;  
            }  
        }  
  
        private void RefreshButtons()  
        {  
            this.RefreshUpDownButtons();  
            this.RefreshSaveButtons();  
            this.RefreshCopyButtons();  
        }  
  
        private void RefreshUpDownButtons()  
        {  
            bool editEnable = true;  
            if( this.focusPanel.Connection.ConnectionString == "" ){  
                editEnable = false;  
                this.upMenuItem.Enabled            = editEnable;  
                this.toolUpButton.Enabled        = editEnable;  
                this.botUpButton.Enabled        = editEnable;  
                this.downMenuItem.Enabled        = editEnable;  
                this.toolDownButton.Enabled        = editEnable;  
                this.botDownButton.Enabled        = editEnable;  
                return;  
            }  
  
            if( this.focusPanel.DetailLevel == YariSoft.DBCommander.DetailLevel.TableLevel ){  
                this.upMenuItem.Enabled            = !editEnable;  
                this.toolUpButton.Enabled        = !editEnable;  
                this.botUpButton.Enabled        = !editEnable;  
                this.downMenuItem.Enabled        = editEnable;  
                this.toolDownButton.Enabled        = editEnable;  
                this.botDownButton.Enabled        = editEnable;  
                this.selectMenuItem.Enabled        = !editEnable;  
                this.unselectMenuItem.Enabled    = !editEnable;  
            } else {  
                this.upMenuItem.Enabled            = editEnable;  
                this.toolUpButton.Enabled        = editEnable;  
                this.botUpButton.Enabled        = editEnable;  
                this.downMenuItem.Enabled        = !editEnable;  
                this.toolDownButton.Enabled        = !editEnable;  
                this.botDownButton.Enabled        = !editEnable;  
                this.selectMenuItem.Enabled        = editEnable;  
                this.unselectMenuItem.Enabled    = editEnable;  
            }  
        }  
  
        private void RefreshSaveButtons()  
        {  
            bool editEnable = true;  
            if( ! this.config.HasChanges ){  
                editEnable = false;  
            }  
  
            this.toolSaveButton.Enabled = editEnable;  
            this.saveMenuItem.Enabled = editEnable;  
        }  
  
        private void RefreshCopyButtons()  
        {  
            bool editEnable = true;  
            if( this.focusPanel.Connection.ConnectionString == "" ){  
                editEnable = false;  
            }  
              
            this.deleteMenuItem.Enabled        = editEnable;  
            this.botDeleteButton.Enabled    = editEnable;          
  
            if( editEnable && this.GetDestinationPanel().Connection.ConnectionString == "" ){  
                editEnable = false;  
            }  
  
            if( editEnable && this.focusPanel.DetailLevel != this.GetDestinationPanel().DetailLevel ){  
                editEnable = false;  
            }  
                  
            this.copyMenuItem.Enabled        = editEnable;  
            this.moveMenuItem.Enabled        = editEnable;  
            this.botCopyButton.Enabled        = editEnable;  
            this.botMoveButton.Enabled        = editEnable;          
        }  
  
        private bool ShowQuestionToUser( string Question, string Caption ){  
  
            if( YariSoft.Utils.YMessages.Show( Question, Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question ) == DialogResult.No ){  
                return false;  
            }  
            return true;  
        }  
  
        private bool CheckChanges(){  
            if( this.config.HasChanges ){  
                DialogResult res = YariSoft.Utils.YMessages.Show( "Do you want to save changes to file '" + this.config.FileName + "'?", applicationName, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question );  
                if( res == DialogResult.Cancel ){  
                    return false;  
                } else if( res == DialogResult.Yes ){  
                    this.UpdateGridStyles();  
                    this.config.SaveToFile();  
                }  
            }  
            return true;  
        }  
  
        private void OnNeedSelectionMasks( ref ArrayList Selections )  
        {  
            Selections = this.options.Selections;  
        }  
  
        private void OnNeedSetGridStyle( object Sender, DataGridTableStyle style )  
        {  
            bool status;  
            if( Sender == this.leftDataPanel ){  
                status = this.config.LeftGridStyles.SetStyleToGrid ( style );  
            } else {  
                status = this.config.RightGridStyles.SetStyleToGrid ( style );  
            }  
        }  
  
        private void ShowHidePanel( DataPanel Panel )  
        {  
            if( Panel == this.leftDataPanel ){  
                if( ! this.rightDataPanel.Visible ){  
                    this.ShowHidePanel( this.rightDataPanel );  
                }  
            } else {  
                if( ! this.leftDataPanel.Visible ){  
                    this.ShowHidePanel( this.leftDataPanel );  
                }  
            }  
  
            bool visible = !Panel.Visible;  
            Panel.Visible = visible;  
            this.splitter.Visible = visible;  
  
            if( visible ){  
                if( Panel == this.rightDataPanel ){  
                    this.leftDataPanel.Dock = DockStyle.Left;  
                }  
                if( this.focusPanel != Panel ){  
                    this.ForceChangeActivePanel();  
                }  
  
            } else {  
                if( Panel == this.rightDataPanel ){  
                    this.leftDataPanel.Dock = DockStyle.Fill;  
                }  
                if( this.focusPanel == Panel ){  
                    this.ForceChangeActivePanel();  
                }  
            }  
            this.RefreshButtons();  
        }  
  
        private void SetIdentityState()  
        {  
            this.leftDataPanel.IdentityOff  = this.options.TableOptions.IdentityOff;  
            this.rightDataPanel.IdentityOff = this.options.TableOptions.IdentityOff;  
        }  
  
        private void UpdateGridStyles()  
        {  
            this.config.RightGridStyles.Update( this.rightDataPanel.PanelGrid.TableStyles );  
            this.config.LeftGridStyles.Update( this.leftDataPanel.PanelGrid.TableStyles );  
        }  
  
        private void OnColumnResize( object Sender, DataGrid.HitTestInfo Info )  
        {  
            this.config.HasChanges = true;  
            this.RefreshButtons();  
        }  
          
        #endregion  
    }  
}