📄 datapanel.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace YariSoft.DBCommander
{
public class DataPanel : System.Windows.Forms.UserControl
{
#region Events
public delegate void OnGridClickEventHandler(object owner, object sender, System.EventArgs e);
public delegate void OnNeedSelectionMasksEventHandler( ref ArrayList Selections );
public delegate void OnChangeDetailLevelEventHandler();
public delegate void OnNeedSetGridStyleEventHandler( object Sender, DataGridTableStyle style );
public delegate void OnColumnResizeEventHandler( object Sender, DataGrid.HitTestInfo Info );
public event OnGridClickEventHandler OnGridClick = null;
public event OnNeedSelectionMasksEventHandler OnNeedSelectionMasks = null;
public event OnChangeDetailLevelEventHandler OnChangeDetailLevel = null;
public event OnNeedSetGridStyleEventHandler OnNeedSetGridStyle = null;
public event OnColumnResizeEventHandler OnColumnResize = null;
#endregion
#region Local variables
private DataPanelManager dataManager = null;
private System.Windows.Forms.Panel bottomPanel;
private System.Windows.Forms.Panel topPanel;
private YariSoft.Windows.Conrols.YDataGrid grid;
private System.Windows.Forms.Label serverLabel;
private System.Windows.Forms.ComboBox tablesCombo;
private System.Windows.Forms.DataGridTableStyle dataGridTablesInternal;
private System.Windows.Forms.DataGridTextBoxColumn dataGridNameColumn;
private System.Windows.Forms.DataGridTextBoxColumn dataGridDateColumn;
private System.Windows.Forms.DataGridTextBoxColumn dataGridOwnerColumn;
private System.Windows.Forms.ComboBox tablesCombo2;
private System.Windows.Forms.Label rowsLabel;
private System.ComponentModel.IContainer components = null;
#endregion
#region Properties
public System.Data.OleDb.OleDbConnection Connection
{
get{ return this.dataManager.Connection; }
}
public bool Active
{
set{
if( value ){
this.topPanel.BackColor = System.Drawing.SystemColors.ActiveCaption;
this.serverLabel.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
} else {
this.topPanel.BackColor = System.Drawing.SystemColors.Control;
this.serverLabel.ForeColor = System.Drawing.SystemColors.ControlText;
}
this.grid.CaptionBackColor = this.topPanel.BackColor;
}
}
public YariSoft.DBCommander.DetailLevel DetailLevel{
get{ return this.dataManager.DetailLevel; }
}
public YariSoft.Windows.Conrols.YDataGrid PanelGrid {
get{ return this.grid; }
}
public DataPanelManager Manager {
get{ return this.dataManager; }
}
public ArrayList SelectedRows {
get{
ArrayList result = null;
DataView view = this.GetActiveDataView( this.grid );
if( view != null ){
result = new ArrayList();
for( int i = 0; i < view.Count; i++ ){
if( this.grid.IsSelected(i) ){
if( this.DetailLevel == DetailLevel.DataLevel ){
result.Add ( i );
} else if ( this.DetailLevel == DetailLevel.TableLevel ) {
result.Add( view[i]["TABLE_NAME"] );
}
}
}
if( result.Count == 0 && (( CurrencyManager )BindingContext[ this.grid.DataSource, this.grid.DataMember ]).Position >= 0 ){
if( this.DetailLevel == DetailLevel.DataLevel ){
result.Add( (( CurrencyManager )BindingContext[ this.grid.DataSource, this.grid.DataMember ]).Position );
} else if ( this.DetailLevel == DetailLevel.TableLevel ) {
result.Add( view[(( CurrencyManager )BindingContext[ this.grid.DataSource, this.grid.DataMember ]).Position]["TABLE_NAME"] );
}
}
}
return result;
}
}
public bool IdentityOff
{
get{ return this.dataManager.IdentityOff; }
set{ this.dataManager.IdentityOff = value; }
}
#endregion
#region Constructor/Destructor
public DataPanel()
{
InitializeComponent();
this.dataGridNameColumn.TextBox.DoubleClick += new EventHandler( this.DownClick );
this.dataGridDateColumn.TextBox.DoubleClick += new EventHandler( this.DownClick );
this.dataGridOwnerColumn.TextBox.DoubleClick += new EventHandler( this.DownClick );
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
this.dataManager.Dispose();
}
base.Dispose( disposing );
}
#endregion
#region Component 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.bottomPanel = new System.Windows.Forms.Panel();
this.rowsLabel = new System.Windows.Forms.Label();
this.grid = new YariSoft.Windows.Conrols.YDataGrid();
this.dataGridTablesInternal = new System.Windows.Forms.DataGridTableStyle();
this.dataGridNameColumn = new System.Windows.Forms.DataGridTextBoxColumn();
this.dataGridDateColumn = new System.Windows.Forms.DataGridTextBoxColumn();
this.dataGridOwnerColumn = new System.Windows.Forms.DataGridTextBoxColumn();
this.topPanel = new System.Windows.Forms.Panel();
this.tablesCombo = new System.Windows.Forms.ComboBox();
this.serverLabel = new System.Windows.Forms.Label();
this.tablesCombo2 = new System.Windows.Forms.ComboBox();
this.bottomPanel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.grid)).BeginInit();
this.topPanel.SuspendLayout();
this.SuspendLayout();
//
// bottomPanel
//
this.bottomPanel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.bottomPanel.Controls.AddRange(new System.Windows.Forms.Control[] {
this.rowsLabel});
this.bottomPanel.Dock = System.Windows.Forms.DockStyle.Bottom;
this.bottomPanel.Location = new System.Drawing.Point(0, 364);
this.bottomPanel.Name = "bottomPanel";
this.bottomPanel.Size = new System.Drawing.Size(448, 20);
this.bottomPanel.TabIndex = 2;
//
// rowsLabel
//
this.rowsLabel.AutoSize = true;
this.rowsLabel.Dock = System.Windows.Forms.DockStyle.Left;
this.rowsLabel.Font = new System.Drawing.Font("Tahoma", 8.25F);
this.rowsLabel.Name = "rowsLabel";
this.rowsLabel.Size = new System.Drawing.Size(38, 14);
this.rowsLabel.TabIndex = 0;
this.rowsLabel.Text = "Rows: ";
//
// grid
//
this.grid.BackgroundColor = System.Drawing.SystemColors.Window;
this.grid.CaptionFont = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Bold);
this.grid.DataMember = "";
this.grid.Dock = System.Windows.Forms.DockStyle.Fill;
this.grid.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.grid.Location = new System.Drawing.Point(0, 24);
this.grid.Name = "grid";
this.grid.Size = new System.Drawing.Size(448, 340);
this.grid.TabIndex = 1;
this.grid.TableStyles.AddRange(new System.Windows.Forms.DataGridTableStyle[] {
this.dataGridTablesInternal});
this.grid.MouseDown += new System.Windows.Forms.MouseEventHandler(this.grid_MouseDown);
this.grid.DataSourceChanged += new System.EventHandler(this.grid_DataSourceChanged);
this.grid.Navigate += new System.Windows.Forms.NavigateEventHandler(this.grid_Navigate);
this.grid.DoubleClick += new System.EventHandler(this.DownClick);
this.grid.Click += new System.EventHandler(this.grid_Click);
this.grid.MouseMove += new System.Windows.Forms.MouseEventHandler(this.grid_MouseMove);
this.grid.CurrentCellChanged += new System.EventHandler(this.grid_CurrentCellChanged);
this.grid.YOnKeyDown += new YariSoft.Windows.Conrols.YDataGrid.YKeyEventHandler(this.grid_YOnKeyDown);
//
// dataGridTablesInternal
//
this.dataGridTablesInternal.DataGrid = this.grid;
this.dataGridTablesInternal.GridColumnStyles.AddRange(new System.Windows.Forms.DataGridColumnStyle[] {
this.dataGridNameColumn,
this.dataGridDateColumn,
this.dataGridOwnerColumn});
this.dataGridTablesInternal.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGridTablesInternal.MappingName = "__YS_Tables_Internal";
this.dataGridTablesInternal.ReadOnly = true;
//
// dataGridNameColumn
//
this.dataGridNameColumn.Format = "";
this.dataGridNameColumn.FormatInfo = null;
this.dataGridNameColumn.HeaderText = "Name";
this.dataGridNameColumn.MappingName = "Table_Name";
this.dataGridNameColumn.Width = 200;
//
// dataGridDateColumn
//
this.dataGridDateColumn.Format = "";
this.dataGridDateColumn.FormatInfo = null;
this.dataGridDateColumn.HeaderText = "Create Date";
this.dataGridDateColumn.MappingName = "Date_Created";
this.dataGridDateColumn.ReadOnly = true;
this.dataGridDateColumn.Width = 150;
//
// dataGridOwnerColumn
//
this.dataGridOwnerColumn.Format = "";
this.dataGridOwnerColumn.FormatInfo = null;
this.dataGridOwnerColumn.HeaderText = "Owner";
this.dataGridOwnerColumn.MappingName = "Table_Schema";
this.dataGridOwnerColumn.ReadOnly = true;
this.dataGridOwnerColumn.Width = 75;
//
// topPanel
//
this.topPanel.BackColor = System.Drawing.SystemColors.Control;
this.topPanel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.topPanel.Controls.AddRange(new System.Windows.Forms.Control[] {
this.tablesCombo,
this.serverLabel});
this.topPanel.Dock = System.Windows.Forms.DockStyle.Top;
this.topPanel.Name = "topPanel";
this.topPanel.Size = new System.Drawing.Size(448, 24);
this.topPanel.TabIndex = 0;
this.topPanel.Visible = false;
this.topPanel.Click += new System.EventHandler(this.grid_Click);
//
// tablesCombo
//
this.tablesCombo.Dock = System.Windows.Forms.DockStyle.Left;
this.tablesCombo.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.tablesCombo.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F);
this.tablesCombo.Location = new System.Drawing.Point(120, 0);
this.tablesCombo.Name = "tablesCombo";
this.tablesCombo.Size = new System.Drawing.Size(200, 21);
this.tablesCombo.TabIndex = 1;
this.tablesCombo.TabStop = false;
this.tablesCombo.KeyUp += new System.Windows.Forms.KeyEventHandler(this.tablesCombo_KeyUp);
this.tablesCombo.SelectedIndexChanged += new System.EventHandler(this.tablesCombo_SelectedIndexChanged);
//
// serverLabel
//
this.serverLabel.Dock = System.Windows.Forms.DockStyle.Left;
this.serverLabel.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Bold);
this.serverLabel.Name = "serverLabel";
this.serverLabel.Size = new System.Drawing.Size(120, 20);
this.serverLabel.TabIndex = 0;
this.serverLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.serverLabel.Click += new System.EventHandler(this.grid_Click);
//
// tablesCombo2
//
this.tablesCombo2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.tablesCombo2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F);
this.tablesCombo2.Location = new System.Drawing.Point(120, 1);
this.tablesCombo2.Name = "tablesCombo2";
this.tablesCombo2.Size = new System.Drawing.Size(200, 21);
this.tablesCombo2.TabIndex = 5;
this.tablesCombo2.TabStop = false;
this.tablesCombo2.KeyUp += new System.Windows.Forms.KeyEventHandler(this.tablesCombo_KeyUp);
this.tablesCombo2.SelectedIndexChanged += new System.EventHandler(this.tablesCombo_SelectedIndexChanged);
//
// DataPanel
//
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.tablesCombo2,
this.grid,
this.topPanel,
this.bottomPanel});
this.Name = "DataPanel";
this.Size = new System.Drawing.Size(448, 384);
this.bottomPanel.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.grid)).EndInit();
this.topPanel.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
#region Public functions
public bool Init( string ConnectionString )
{
if( this.dataManager != null ){
this.dataManager.Dispose();
}
this.dataManager = new DataPanelManager( ConnectionString );
this.RefreshDataBaseData();
return true;
}
public bool PrepareConnection ()
{
if( this.dataManager.PrepareConnection() ){
this.RefreshDataBaseData();
return true;
}
return false;
}
public void MoveDown()
{
if( this.dataManager.DetailLevel < YariSoft.DBCommander.DetailLevel.DataLevel ){
this.Cursor = Cursors.WaitCursor;
this.dataManager.MoveDown();
this.FillData();
this.Cursor = Cursors.Default;
if( this.OnChangeDetailLevel != null ){
this.OnChangeDetailLevel();
}
}
}
public void MoveUp()
{
if( this.dataManager.DetailLevel > YariSoft.DBCommander.DetailLevel.TableLevel ){
bool status= true;
this.Cursor = Cursors.WaitCursor;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -