📄 overwritetableform.cs
字号:
using System;using System.Collections;using System.ComponentModel;using System.Drawing;using System.Windows.Forms;using System.Data;namespace YariSoft.DBUtil{ public class ChangeTableForm : YariSoft.DBUtil.OverwriteBaseForm {
#region Local variables
private System.Windows.Forms.DataGridTableStyle dataGridTableStyle;
private YariSoft.Windows.Conrols.YDataGridColorTextBoxColumn nameColumn;
private YariSoft.Windows.Conrols.YDataGridColorTextBoxColumn typeColumn;
private YariSoft.Windows.Conrols.YDataGridColorBoolBoxColumn nullColumn;
private YariSoft.Windows.Conrols.YDataGridColorBoolBoxColumn readColumn;
private System.Windows.Forms.Panel insertColorPanel;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Panel panel2;
private System.ComponentModel.IContainer components = null; #endregion #region Constructor/Destructor public ChangeTableForm() { InitializeComponent(); this.readColumn.OnPaint += new YariSoft.Windows.Conrols.OnDataGridColumnPainEventHandler ( this.OnNeedCellColor ); this.nameColumn.OnPaint += new YariSoft.Windows.Conrols.OnDataGridColumnPainEventHandler ( this.OnNeedCellColor ); this.typeColumn.OnPaint += new YariSoft.Windows.Conrols.OnDataGridColumnPainEventHandler ( this.OnNeedCellColor ); this.nullColumn.OnPaint += new YariSoft.Windows.Conrols.OnDataGridColumnPainEventHandler ( this.OnNeedCellColor ); } protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #endregion #region 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() { System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(ChangeTableForm));
this.dataGridTableStyle = new System.Windows.Forms.DataGridTableStyle();
this.nameColumn = new YariSoft.Windows.Conrols.YDataGridColorTextBoxColumn();
this.typeColumn = new YariSoft.Windows.Conrols.YDataGridColorTextBoxColumn();
this.nullColumn = new YariSoft.Windows.Conrols.YDataGridColorBoolBoxColumn();
this.readColumn = new YariSoft.Windows.Conrols.YDataGridColorBoolBoxColumn();
this.insertColorPanel = new System.Windows.Forms.Panel();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.panel1 = new System.Windows.Forms.Panel();
this.label4 = new System.Windows.Forms.Label();
this.panel2 = new System.Windows.Forms.Panel();
((System.ComponentModel.ISupportInitialize)(this.dataGrid)).BeginInit();
this.SuspendLayout();
//
// overwriteButtonAll
//
this.overwriteButtonAll.Text = "Change &All";
this.overwriteButtonAll.Visible = true;
//
// overwriteButton
//
this.overwriteButton.Text = "&Change";
this.overwriteButton.Visible = true;
//
// dataGrid
//
this.dataGrid.AccessibleName = "DataGrid";
this.dataGrid.AccessibleRole = System.Windows.Forms.AccessibleRole.Table;
this.dataGrid.Size = new System.Drawing.Size(442, 200);
this.dataGrid.TableStyles.AddRange(new System.Windows.Forms.DataGridTableStyle[] {
this.dataGridTableStyle});
this.dataGrid.Visible = true;
//
// infoLabel
//
this.infoLabel.Size = new System.Drawing.Size(227, 13);
this.infoLabel.Text = "Table already exists in destination database.";
this.infoLabel.Visible = true;
//
// label1
//
this.infoLabel2.Size = new System.Drawing.Size(193, 13);
this.infoLabel2.Text = "Would you like change existing table?";
this.infoLabel2.Visible = true;
//
// dataGridTableStyle
//
this.dataGridTableStyle.DataGrid = this.dataGrid;
this.dataGridTableStyle.GridColumnStyles.AddRange(new System.Windows.Forms.DataGridColumnStyle[] {
this.nameColumn,
this.typeColumn,
this.nullColumn,
this.readColumn});
this.dataGridTableStyle.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGridTableStyle.MappingName = "TableChanges";
//
// nameColumn
//
this.nameColumn.Format = "";
this.nameColumn.FormatInfo = null;
this.nameColumn.HeaderText = "Name";
this.nameColumn.MappingName = "ColumnName";
this.nameColumn.ReadOnly = true;
this.nameColumn.Width = 186;
//
// typeColumn
//
this.typeColumn.Format = "";
this.typeColumn.FormatInfo = null;
this.typeColumn.HeaderText = "Type";
this.typeColumn.MappingName = "ColumnType";
this.typeColumn.ReadOnly = true;
this.typeColumn.Width = 110;
//
// nullColumn
//
this.nullColumn.FalseValue = false;
this.nullColumn.HeaderText = "Null ";
this.nullColumn.MappingName = "AllowNull";
this.nullColumn.NullValue = ((System.DBNull)(resources.GetObject("nullColumn.NullValue")));
this.nullColumn.ReadOnly = true;
this.nullColumn.TrueValue = true;
this.nullColumn.Width = 50;
//
// readColumn
//
this.readColumn.FalseValue = false;
this.readColumn.HeaderText = "Read only";
this.readColumn.MappingName = "ReadOnly";
this.readColumn.NullValue = ((System.DBNull)(resources.GetObject("readColumn.NullValue")));
this.readColumn.ReadOnly = true;
this.readColumn.TrueValue = true;
this.readColumn.Width = 60;
//
// insertColorPanel
//
this.insertColorPanel.BackColor = System.Drawing.Color.Aquamarine;
this.insertColorPanel.Location = new System.Drawing.Point(16, 248);
this.insertColorPanel.Name = "insertColorPanel";
this.insertColorPanel.Size = new System.Drawing.Size(13, 13);
this.insertColorPanel.TabIndex = 9;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(32, 248);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(32, 13);
this.label2.TabIndex = 10;
this.label2.Text = "Insert";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(100, 248);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(41, 13);
this.label3.TabIndex = 12;
this.label3.Text = "Update";
//
// panel1
//
this.panel1.BackColor = System.Drawing.Color.LightGoldenrodYellow;
this.panel1.Location = new System.Drawing.Point(85, 248);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(13, 13);
this.panel1.TabIndex = 11;
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(170, 248);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(37, 13);
this.label4.TabIndex = 14;
this.label4.Text = "Delete";
//
// panel2
//
this.panel2.BackColor = System.Drawing.Color.Pink;
this.panel2.Location = new System.Drawing.Point(154, 248);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(13, 13);
this.panel2.TabIndex = 13;
//
// ChangeTableForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(456, 312);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.label4,
this.panel2,
this.label3,
this.panel1,
this.dataGrid,
this.infoLabel2,
this.infoLabel,
this.label2,
this.insertColorPanel});
this.Name = "ChangeTableForm";
this.Text = "Change table";
((System.ComponentModel.ISupportInitialize)(this.dataGrid)).EndInit();
this.ResumeLayout(false);
} #endregion
#region Public functions
public YariSoft.DBUtil.RowOperation ShowDialog( DataTable Source, ref DataTable Destination )
{
DataTable table = this.PrepareDataTable();
foreach( DataColumn srcColumn in Source.Columns ){
bool found = false;
string srcName = srcColumn.ColumnName.ToLower();
foreach( DataColumn destColumn in Destination.Columns ){
if( srcName == destColumn.ColumnName.ToLower() ){
if( ! Util.CompareColumns ( srcColumn, destColumn )){
this.AddNewRow( table, srcColumn, 2 );
} else {
this.AddNewRow( table, srcColumn, 0 );
}
found = true;
break;
}
}
if( ! found ){
this.AddNewRow( table, srcColumn, 1 );
}
}
foreach( DataColumn destColumn in Destination.Columns ){
bool found = false;
string destName = destColumn.ColumnName.ToLower();
foreach( DataColumn srcColumn in Source.Columns ){
if( destName == srcColumn.ColumnName.ToLower() ){
found = true;
break;
}
}
if( ! found ){
this.AddNewRow( table, destColumn, 3 );
}
}
this.dataGrid.DataSource = table.DefaultView;
((DataView)this.dataGrid.DataSource).AllowNew = false;
this.ShowDialog();
return this.result;
}
#endregion
#region Private functions
private DataTable PrepareDataTable()
{
DataTable table = new DataTable("TableChanges");
DataColumn column = new DataColumn("Change",System.Type.GetType("System.Boolean"));
table.Columns.Add( column );
column = new DataColumn("ColumnName",System.Type.GetType("System.String"));
table.Columns.Add( column );
column = new DataColumn("ColumnType",System.Type.GetType("System.String"));
table.Columns.Add( column );
column = new DataColumn("AllowNull",System.Type.GetType("System.Boolean"));
table.Columns.Add( column );
column = new DataColumn("Color",System.Type.GetType("System.Int32"));
table.Columns.Add( column );
column = new DataColumn("ReadOnly",System.Type.GetType("System.Boolean"));
table.Columns.Add( column );
return table;
}
private void AddNewRow( DataTable Table, DataColumn Column, int Color )
{
DataRow row = Table.NewRow();
if( Color == 0 ){
row[0] = false;
} else {
row[0] = true;
}
row[1] = Column.ColumnName;
row[2] = Column.DataType.ToString();
row[3] = Column.AllowDBNull;
row[4] = Color;
row[5] = Column.ReadOnly;
Table.Rows.Add( row );
}
private void OnNeedCellColor( ref System.Drawing.Graphics g,
ref System.Drawing.Rectangle bounds,
ref System.Windows.Forms.CurrencyManager source,
ref int rowNum,
ref System.Drawing.Brush backBrush,
ref System.Drawing.Brush foreBrush,
ref bool alignToRight)
{
DataView view = ( DataView )this.dataGrid.DataSource ;
switch( ( int )view[rowNum][4] ){
case 1:
backBrush = new SolidBrush(Color.Aquamarine);
break;
case 2:
backBrush = new SolidBrush(Color.LightGoldenrodYellow);
break;
case 3:
backBrush = new SolidBrush(Color.Pink);
break;
}
}
#endregion
}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -