📄 datapanel.cs
字号:
if( status ){
this.dataManager.MoveUp();
this.FillData();
}
this.Cursor = Cursors.Default;
if( this.OnChangeDetailLevel != null ){
this.OnChangeDetailLevel();
}
}
}
private DataView PrepareOperation( DataPanel Panel )
{
DataView view = this.GetActiveDataView( Panel.PanelGrid );
if( Panel.PanelGrid.DataMember == "" ){
Panel.BackgroundImage = Panel.PanelGrid.GetGridImage();
Panel.PanelGrid.DataSource = null;
Panel.PanelGrid.Visible = false;
}
return view;
}
public bool CopyData( DataPanel Destination )
{
bool status = false;
switch ( this.dataManager.DetailLevel ){
case DetailLevel.TableLevel:
status = this.dataManager.CopyData ( null, null, this.SelectedRows, Destination.Manager );
Destination.RefreshDataBaseData();
break;
case DetailLevel.DataLevel:
DataView view = this.PrepareOperation ( Destination );
status = this.dataManager.CopyData ( this.GetActiveDataView ( this.grid ),view, this.SelectedRows, Destination.Manager );
if( Destination.PanelGrid.DataSource == null ){
Destination.PanelGrid.DataSource = view;
Destination.PanelGrid.Visible = true;
}
break;
}
this.ScrollToRow ( Destination.PanelGrid );
this.CheckDataState( Destination );
return status;
}
public bool DeleteData()
{
bool status = false;
ArrayList selected = this.SelectedRows;
switch ( this.dataManager.DetailLevel ){
case DetailLevel.TableLevel:
status = this.dataManager.DeleteData( null, selected );
this.RefreshDataBaseData();
break;
case DetailLevel.DataLevel:
DataView view = this.PrepareOperation ( this );
status = this.dataManager.DeleteData ( view, selected );
if( this.grid.DataSource == null ){
this.grid.DataSource = view;
this.grid.Visible = true;
}
break;
}
this.ScrollToRow ( this.grid );
this.CheckDataState( this );
return status;
}
public void OpenTableComboBox()
{
this.tablesCombo2.DroppedDown = true;
this.tablesCombo2.Focus();
}
public void RefreshData()
{
DataGridCell previousPosition = this.grid.CurrentCell;
switch ( this.dataManager.DetailLevel ){
case DetailLevel.TableLevel:
this.RefreshDataBaseData();
break;
case DetailLevel.DataLevel:
this.RefreshTableData();
break;
}
this.grid.CurrentCell = previousPosition;
if( this.grid.CurrentRowIndex > -1 ){
this.grid.Select( this.grid.CurrentRowIndex );
}
}
#endregion
#region Private functions
private void RefreshTableData()
{
if( this.grid.DataSource == null ){
return;
}
this.Cursor = Cursors.WaitCursor;
YariSoft.Utils.YMessages.ChangeCursor ( this.Cursor );
this.grid.DataSource = null;
this.grid.DataSource = this.dataManager.RefreshData( this.tablesCombo2.Text );
this.Cursor = Cursors.Default;
YariSoft.Utils.YMessages.ChangeCursor ( this.Cursor );
}
private void RefreshDataBaseData()
{
this.dataManager.Clear();
this.MoveDown();
this.tablesCombo2.DataSource = this.grid.DataSource;
if( this.tablesCombo2.DataSource != null ){
this.tablesCombo2.DisplayMember = "TABLE_NAME";
} else {
this.tablesCombo2.Items.Clear();
}
this.serverLabel.Text = this.dataManager.ServerCaption;
this.serverLabel.Size = new Size ( this.serverLabel.PreferredWidth, this.serverLabel.PreferredHeight );
this.grid.CaptionText = this.dataManager.ServerCaption;
this.tablesCombo2.Left = this.serverLabel.PreferredWidth;
}
private void grid_Click(object sender, System.EventArgs e)
{
if( this.OnGridClick != null ){
this.OnGridClick( this, sender, e );
}
this.RefreshCaptions();
}
private void grid_Navigate(object sender, System.Windows.Forms.NavigateEventArgs ne)
{
if( ne.Forward ){
this.dataManager.FillTableDataByFK ( this.grid.DataMember );
}
this.RefreshCaptions();
}
private void FillData()
{
DataView view = this.dataManager.FillData( this.tablesCombo2.Text );
this.grid.DataSource = view;
if( view != null ){
DataGridTableStyle style = grid.TableStyles[ view.Table.TableName ];
if( style == null ){
style = new DataGridTableStyle();
style.MappingName = view.Table.TableName;
this.grid.TableStyles.Add( style );
}
if( this.OnNeedSetGridStyle != null ){
this.OnNeedSetGridStyle ( this, style );
}
}
}
private void DownClick(object sender, System.EventArgs e)
{
this.MoveDown();
}
private void UpClick(object sender, System.EventArgs e)
{
this.MoveUp();
}
private void tablesCombo_SelectedIndexChanged(object sender, System.EventArgs e)
{
if( this.dataManager.DetailLevel > YariSoft.DBCommander.DetailLevel.TableLevel ){
this.Cursor = Cursors.WaitCursor;
YariSoft.Utils.YMessages.ChangeCursor ( this.Cursor );
this.FillData();
this.Cursor = Cursors.Default;
YariSoft.Utils.YMessages.ChangeCursor ( this.Cursor );
}
this.grid_Click(sender, e);
}
private void ShowSelectionForm( Modals.SelectionForm.SelectOperationType SelectType )
{
/*
if( this.dataManager.DetailLevel != YariSoft.DBCommander.DetailLevel.DataLevel ){
return;
}
*/
if( this.grid.DataSource == null ){
return;
}
ArrayList selections = null;
if( this.OnNeedSelectionMasks != null ){
this.OnNeedSelectionMasks ( ref selections );
}
Modals.SelectionForm selection = new Modals.SelectionForm();
if( selection.Init ( this.grid,
this.GetActiveDataView( this.grid ),
SelectType,
selections ) ){
selection.ShowDialog();
}
selection.Dispose();
this.grid.Focus();
this.RefreshCaptions();
}
private bool grid_YOnKeyDown( ref Message msg, Keys keyData )
{
if( msg.Msg == 0x100 ){
if( keyData == ( Keys.Add ) ){
this.ShowSelectionForm( Modals.SelectionForm.SelectOperationType.Select );
return true;
}
if( keyData == ( Keys.Subtract ) ){
this.ShowSelectionForm( Modals.SelectionForm.SelectOperationType.Unselect );
return true;
}
if( keyData == ( Keys.Multiply ) ){
this.ShowSelectionForm( Modals.SelectionForm.SelectOperationType.Filter );
return true;
}
if( keyData == ( Keys.Divide ) ){
this.GetActiveDataView( this.grid ).RowFilter = "";
this.RefreshCaptions();
return true;
}
if ( keyData == Keys.Enter ){
if( this.dataManager.DetailLevel < YariSoft.DBCommander.DetailLevel.DataLevel ){
this.MoveDown();
return true;
}
}
if ( keyData == Keys.Delete ){
if( this.grid.IsSelected ( this.grid.CurrentRowIndex ) ){
return true;
}
}
}
return false;
}
private void tablesCombo_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
if( e.KeyData == Keys.Enter ){
this.grid.Focus();
}
}
private void grid_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if( e.Button == MouseButtons.Left ){
this.grid_Click ( sender, null );
}
}
private void grid_CurrentCellChanged(object sender, System.EventArgs e)
{
DataView view = this.GetActiveDataView( this.grid );
if( view != null ){
this.dataManager.UpdateData( view.Table );
this.CheckDataState( this );
}
}
private void CheckDataState( DataPanel Panel )
{
if( Manager.NeedRefresh ){
if( YariSoft.Utils.YMessages.Show( "Current state of data in the grid has expired. Do you want refresh data?",
"Refresh data",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question ) == DialogResult.Yes ) {
Panel.RefreshData();
}
}
}
private DataView GetActiveDataView( DataGrid Grid )
{
if( Grid == null || Grid.DataSource == null ){
return null;
}
return ( DataView )(( CurrencyManager )BindingContext[ Grid.DataSource, Grid.DataMember ]).List;
}
private void RefreshCaptions()
{
int rowCount = 0;
int selCount = 0;
DataView view = this.GetActiveDataView( this.grid );
if( view != null ){
rowCount = this.grid.BindingContext[this.grid.DataSource, this.grid.DataMember].Count;
for( int i = 0; i < rowCount; i++ ){
if( this.grid.IsSelected ( i ) ){
selCount ++;
}
}
}
this.rowsLabel.Text = "Rows: " + rowCount.ToString() + " ";
this.rowsLabel.Text += "Selected: " + selCount.ToString();
}
private void grid_DataSourceChanged(object sender, System.EventArgs e)
{
this.RefreshCaptions();
}
private void ScrollToRow( YariSoft.Windows.Conrols.YDataGrid Grid )
{
if( Grid.DataSource != null &&
Grid.CurrentRowIndex > -1 &&
Grid.BindingContext[Grid.DataSource, Grid.DataMember].Count > 0 &&
Grid.CurrentRowIndex < Grid.BindingContext[Grid.DataSource, Grid.DataMember].Count ){
Grid.ScrollToRow( Grid.CurrentRowIndex );
Grid.Select( Grid.CurrentRowIndex );
}
}
private void grid_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if( e.Button == MouseButtons.Left ){
System.Drawing.Point pt = new Point(e.X, e.Y);
DataGrid.HitTestInfo hti = this.grid.HitTest(pt);
if(hti.Type == DataGrid.HitTestType.ColumnHeader) {
if( this.OnColumnResize != null ){
this.OnColumnResize( this, hti );
}
}
}
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -