namespace ITMBA.BusinessRules.CommonBaseClassBR.Dock
{
using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data.SqlClient;
/// <summary>
/// DataGridBR重写了DataGrid组件
/// </summary>
public class DataGridBR : System.Windows.Forms.DataGrid
{
//创建数组
private System.Windows.Forms.DataGrid [] _DataGrid;
private System.Windows.Forms.Form tempForm;
//DataGrid索引
private int _index = 0;
//设置当前操作DataGrid索引
private int _CurrentIndex=0;
//当前选择值
private DataView _ParentDV;//操作的父DataGrid的视图
private int _ParentRow;//操作的父DataGrid的行索引
private int _ParentColumn;//操作的父DataGrid的列索引
/// <summary>
/// 操作的父DataGrid的视图
/// </summary>
public DataView ParentDV
{
get
{
return _ParentDV;
}
set
{
_ParentDV = value;
}
}
/// <summary>
/// 操作的父DataGrid的行索引
/// </summary>
public int ParentRow
{
get
{
return _ParentRow;
}
set
{
_ParentRow = value;
}
}
/// <summary>
/// 操作的父DataGrid的列索引
/// </summary>
public int ParentColumn
{
get
{
return _ParentColumn;
}
set
{
_ParentColumn = value;
}
}
/// <summary>
/// 构造函数
/// </summary>
/// <param name="owner">容器窗口</param>
/// <param name="dv">当前操作的视图</param>
/// <param name="row">选择的行索引</param>
/// <param name="column">选择的列索引</param>
/// <param name="Num">将创建DataGrid数目</param>
public DataGridBR(System.Windows.Forms.Form owner,DataView dv,int row,int column, int Num)
{
_DataGrid = new DataGrid[Num];
for(int i=0;i<Num;i++){
_DataGrid[i] = new DataGrid();
}
tempForm = owner;
ParentDV = dv;
ParentRow = row;
ParentColumn = column;
}
/// <summary>
/// 当前操作DataGrid索引
/// </summary>
public int CurrentIndex{
set{
_CurrentIndex = value;
}
get{
return _CurrentIndex;
}
}
/// <summary>
/// 初始化数据源
/// </summary>
/// <param name="dv">数据源</param>
public void AddSource(System.Data.DataView dv){
if(dv.Count>0){
_DataGrid[_index++].DataSource = dv;
}
}
/// <summary>
/// 取得已创建的DataGrid数目
/// </summary>
/// <returns></returns>
public int GetNumEntries(){
return _index;
}
/// <summary>
/// 允许数组式访问
/// </summary>
public System.Windows.Forms.DataGrid this[int index]{
get{
_DataGrid[index].Dock = DockStyle.Fill;
_DataGrid[index].RowHeadersVisible = true;
_DataGrid[index].CaptionVisible = false;
_DataGrid[index].DoubleClick += new System.EventHandler(this.DataGridBR_DoubleClick);
return _DataGrid[index];
}
set{
_DataGrid[index] = value;
}
}
/// <summary>
/// 选择事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DataGridBR_DoubleClick(object sender, System.EventArgs e)
{
DataView tempDV = (DataView)_DataGrid[CurrentIndex].DataSource;
int Count = tempDV.Count;
if(Count != 0)
{
//MessageBox.Show(_DataGrid[CurrentIndex].CurrentRowIndex.ToString());
int tempNo = _DataGrid[CurrentIndex].CurrentRowIndex;
DataSet ds = tempDV.Table.DataSet;
//MessageBox.Show(ds.Tables[0].Rows[tempNo][0].ToString());
DataSet ds0 = ParentDV.Table.DataSet;
ds0.Tables[0].Rows[ParentRow][ParentColumn] = ds.Tables[0].Rows[tempNo][0].ToString();
//MessageBox.Show("row:"+ParentRow.ToString()+",column:"+ParentColumn.ToString());
tempForm.Close();
}
else
{
MessageBox.Show("没有记录被选中","信息提示",MessageBoxButtons.OK);
}
}
}
}