source grid 4.0.0.3 是个好东西!

介绍:
SourceGrid 是一个的完全地用C#开发的Windows窗体控件;想实现excel或者word表格的样式的话,这是最好的选择.

官方网址: http://sourceforge.net/projects/sourcegrid

下面的代码可以详细的说明如何运用这个好控件.(代码是不能直接运行的,仅做参考).
其中也包含了access数据库操作的常用方法.
还顺便加了DockPanel的演练.
DockPanel是一个可以做到vs2003工具栏,属性窗口样式的控件.

官网:http://sourceforge.net/projects/dockpanelsuite/

DockPanel suite is designed to achieve docking capability for MDI forms. It can be used to develop applications with Visual Studio .Net style user interface.

DockPanel suite is a 100%-native .Net windows forms control, written in C#

 

Features of DockPanel suite:

·         Complex hierarchies

·         Auto-hide

·         Free drag-and-drop

·         Nested docking

·         Integration with .Net Framework and VS .Net

·         Persistent to XML file


ContractedBlock.gif ExpandedBlockStart.gif
None.gifusing System;
None.gif
using System.Collections.Generic;
None.gif
using System.ComponentModel;
None.gif
using System.Data;
None.gif
using System.Drawing;
None.gif
using System.Text;
None.gif
using System.Windows.Forms;
None.gif
using WeifenLuo.WinFormsUI;
None.gif
using System.Collections;
None.gif
using System.IO;
None.gif
using System.Data.OleDb;
None.gif
None.gif
namespace docktest
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif    
InBlock.gif    
public partial class Document3 : DockContent//Form 就可以了,这儿是从Dockpannel继承的
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif      
InBlock.gif        
string path;
InBlock.gif        
public Datas datas = new Datas();
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 数据库路径
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        string data_base = "\\goodcity.mdb";
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 表名:指标索引
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        string data_name = "原件目录";
InBlock.gif        
public bool runing = false;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 分页数量
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private int pages = 1;//分页数量
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <summary>
InBlock.gif        
/// 当前页次
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private int pageat = 1;//当前页次
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <summary>
InBlock.gif        
/// 每页行数
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        int pageline = 15;//每页行数
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <summary>
InBlock.gif        
/// 总行数
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private int rcount;//行数
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <summary>
InBlock.gif        
/// 总列数
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private int mcount;//列数
InBlock.gif
        private string caption;//测评内容
InBlock.gif
        private string cetotal;//datas.cecis.Length.ToString();//册数
InBlock.gif
        private string ceindex;//册次
InBlock.gif
        private string bianhao;//标题
InBlock.gif
        SourceGrid.Cells.Controllers.Button mController_Link;//连接事件  
InBlock.gif
InBlock.gif        
//Font font1 = new Font("楷体_GB2312", 18, FontStyle.Regular);
InBlock.gif
        Font font1 = new Font(FontFamily.GenericSerif,14,FontStyle.Regular);
InBlock.gif        Font font2 
= new Font(FontFamily.GenericSerif, 11f, FontStyle.Regular);
InBlock.gif        Font font3 
= new Font(FontFamily.GenericSerif, 9f, FontStyle.Regular);
InBlock.gif
InBlock.gif        
public Document3()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            InitializeComponent();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void Form1_Load(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            path 
= Application.StartupPath;
InBlock.gif            
this.runing = true;
InBlock.gif            
//this.timer1.Interval = 500;
InBlock.gif            
//this.timer1.Start();
ExpandedSubBlockEnd.gif
        }

InBlock.gif        
private void timer1_Tick(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.timer1.Stop();
InBlock.gif                
if (this.runing)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.init();                    
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.init2();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (System.Exception op)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//MessageBox.Show("init " + op.Message);
ExpandedSubBlockEnd.gif
            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
public void init()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
string key = this.datas.flags + " AND 册次=" + this.datas.n + " ORDER BY 原件顺序号";//
InBlock.gif
            this.searchdata(path + data_base, data_name, key, "search3");
InBlock.gif            rcount 
= this.dataSet1.Tables["search3"].Rows.Count;
InBlock.gif            mcount 
= this.dataSet1.Tables["search3"].Columns.Count;
InBlock.gif
InBlock.gif            caption 
= datas.caption;//测评内容
InBlock.gif
            cetotal = this.dataSet1.Tables["search3"].Rows[0].ItemArray[3].ToString();//总册数
InBlock.gif
            ceindex = datas.n.ToString();//册次,            
InBlock.gif
            bianhao = datas.subtitle;//标题
InBlock.gif

InBlock.gif            
if (rcount > this.pageline)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (rcount % pageline == 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.pages = (int)Math.Floor((double)(rcount / pageline));
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.pages = (int)Math.Floor((double)(rcount / pageline)) + 1;//分页数量
ExpandedSubBlockEnd.gif
                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.pages = 1;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
this.pageat = 1;
InBlock.gif            
this.numer_n.Value = this.pageat;
InBlock.gif            
this.textBox_n.Text = this.pages.ToString();
InBlock.gif            
this.numer_n.Maximum = this.pages;
InBlock.gif            
this.numer_n.Minimum = 1;
InBlock.gif            
this.drawgird();
ExpandedSubBlockEnd.gif         }

InBlock.gif     
InBlock.gif        
public void init2()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.searchdata(path + data_base, data_name, this.datas.flags, "search3");
InBlock.gif            rcount 
= this.dataSet1.Tables["search3"].Rows.Count;
InBlock.gif            mcount 
= this.dataSet1.Tables["search3"].Columns.Count;
InBlock.gif
InBlock.gif            caption 
= "";//测评内容
InBlock.gif
            cetotal = "";//册数
InBlock.gif
            ceindex = "";//册次,
InBlock.gif

InBlock.gif            ceindex 
= "";
InBlock.gif            bianhao 
= "";//标题
InBlock.gif

InBlock.gif            
if (rcount > this.pageline)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (rcount % pageline == 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.pages = (int)Math.Floor((double)(rcount / pageline));
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.pages = (int)Math.Floor((double)(rcount / pageline)) + 1;//分页数量
ExpandedSubBlockEnd.gif
                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.pages = 1;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
this.pageat = 1;
InBlock.gif            
this.numer_n.Value = this.pageat;
InBlock.gif            
this.textBox_n.Text = this.pages.ToString();
InBlock.gif            
this.numer_n.Maximum = this.pages;
InBlock.gif            
this.numer_n.Minimum = 1;
InBlock.gif            
this.drawgird();
ExpandedSubBlockEnd.gif        }

InBlock.gif      
InBlock.gif        
private void drawgird()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
int begin = 0;
InBlock.gif            
if (this.pageat > 1)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                begin 
= (this.pageat - 1* this.pageline;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
int end =  pageline;
InBlock.gif            
if (pageat == pages)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                end 
= this.rcount % pageline;
InBlock.gif                
if (end == 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    end 
= pageline;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }
 
InBlock.gif            
//this.grid1 = new SourceGrid.Grid();
InBlock.gif
            mController_Link = new SourceGrid.Cells.Controllers.Button();
InBlock.gif            mController_Link.Executed 
+= new EventHandler(mController_Link_Click);      
ContractedSubBlock.gifExpandedSubBlockStart.gif            
绘制表格#region 绘制表格
InBlock.gif
InBlock.gif            grid1.Redim(
this.pageline + 7 , 10);
InBlock.gif          
InBlock.gif            
int xx = 0;//行号
InBlock.gif
            int yy = 0;//列号
InBlock.gif            
//1 Header Row   
InBlock.gif
            grid1[00= new MyHeader(" ");
InBlock.gif            grid1[
01= new MyHeader(" ");
InBlock.gif            grid1[
02= new MyHeader(" ");
InBlock.gif            grid1[
03= new MyHeader(" ");
InBlock.gif            grid1[
04= new MyHeader(" ");
InBlock.gif            grid1[
05= new MyHeader(" ");
InBlock.gif            grid1[
06= new MyHeader(" ");
InBlock.gif            grid1[
07= new MyHeader(" ");
InBlock.gif            grid1[
08= new MyHeader(" ");
InBlock.gif            grid1[
09= new MyHeader(" ");
InBlock.gif            
InBlock.gif            SourceGrid.Cells.Views.Cell viewImage 
= new SourceGrid.Cells.Views.Cell();
InBlock.gif            SourceGrid.Cells.Controllers.CustomEvents clickEvent 
= new SourceGrid.Cells.Controllers.CustomEvents();
InBlock.gif            clickEvent.Click 
+= new EventHandler(clickEvent_Click);
InBlock.gif
InBlock.gif            
// 0
InBlock.gif
            xx = 1;
InBlock.gif            grid1[xx, 
0= new SourceGrid.Cells.RowHeader();
InBlock.gif            
//grid1[xx, 0].Measure(new Size(100, 50));
InBlock.gif
InBlock.gif            
// 1
InBlock.gif
            xx = 1;
InBlock.gif            SourceGrid.Cells.Editors.EditorBase edits 
= new SourceGrid.Cells.Editors.EditorBase(typeof(string));
InBlock.gif            grid1[xx, 
1= new SourceGrid.Cells.Cell("卷内目录", edits);
InBlock.gif            grid1[xx, 
1].ColumnSpan = 9;
ExpandedSubBlockStart.gifContractedSubBlock.gif            
/**////
InBlock.gif            //视图样式
InBlock.gif
            SourceGrid.Cells.Views.Cell cview = new SourceGrid.Cells.Views.Cell();
InBlock.gif            cview.Font 
= font1;
InBlock.gif            cview.TextAlignment 
= DevAge.Drawing.ContentAlignment.MiddleCenter;
InBlock.gif            
//cview.AnchorArea = new DevAge.Drawing.AnchorArea(0f, 0f, 300f, 50f, true, true);
InBlock.gif            
//cview.AnchorArea = new DevAge.Drawing.AnchorArea(DevAge.Drawing.ContentAlignment.TopCenter, true);
InBlock.gif            
//DevAge.Drawing.Border border = new DevAge.Drawing.Border(Color.Red, 1);
InBlock.gif            
//cview.Border = new DevAge.Drawing.RectangleBorder(border);//边框
InBlock.gif            
//cview.Border = new DevAge.Drawing.RectangleBorder(DevAge.Drawing.Border.Black1Width);//边框
InBlock.gif            
//模型
InBlock.gif            
//SourceGrid.Cells.Models.ModelContainer models = new SourceGrid.Cells.Models.ModelContainer();
InBlock.gif            
//编辑器
InBlock.gif            
//SourceGrid.Cells.Editors.EditorBase editors = new SourceGrid.Cells.Editors.EditorBase(typeof(string));
InBlock.gif            
//虚拟表格
InBlock.gif            
//SourceGrid.Cells.Virtual.CellVirtual cellvirtral = new SourceGrid.Cells.Virtual.CellVirtual();
ExpandedSubBlockStart.gifContractedSubBlock.gif
            /**///
InBlock.gif            cview.WordWrap = true;
InBlock.gif            grid1[xx, 
1].View = cview;
InBlock.gif
InBlock.gif            
// 2
InBlock.gif
            xx = 2;
InBlock.gif            grid1[xx, 
0= new SourceGrid.Cells.RowHeader();
InBlock.gif            grid1[xx, 
1= new SourceGrid.Cells.Cell("评测内容");
InBlock.gif            grid1[xx, 
1].RowSpan = 2;
InBlock.gif            cview 
= new SourceGrid.Cells.Views.Cell();
InBlock.gif            cview.Font 
= font2;
InBlock.gif            cview.TextAlignment 
= DevAge.Drawing.ContentAlignment.MiddleCenter;
InBlock.gif            cview.WordWrap 
= true;
InBlock.gif            grid1[xx, 
1].View = cview;
InBlock.gif
InBlock.gif            grid1[xx, 
2= new SourceGrid.Cells.Cell(caption);
InBlock.gif            grid1[xx, 
2].RowSpan = 2;
InBlock.gif            grid1[xx, 
2].ColumnSpan = 3;
InBlock.gif            cview 
= new SourceGrid.Cells.Views.Cell();
InBlock.gif            cview.Font 
= font2;
InBlock.gif            cview.TextAlignment 
= DevAge.Drawing.ContentAlignment.MiddleLeft;
InBlock.gif            cview.AnchorArea 
= new DevAge.Drawing.AnchorArea(DevAge.Drawing.ContentAlignment.TopCenter, true);
InBlock.gif            cview.WordWrap 
= true;
InBlock.gif            grid1[xx, 
2].View = cview;
InBlock.gif
InBlock.gif            grid1[xx, 
5= new SourceGrid.Cells.Cell("编号");
InBlock.gif            
//grid1[xx, 5].RowSpan = 1;
InBlock.gif
            grid1[xx, 5].ColumnSpan = 2;
InBlock.gif            cview 
= new SourceGrid.Cells.Views.Cell();
InBlock.gif            cview.Font 
= font2;
InBlock.gif            cview.TextAlignment 
= DevAge.Drawing.ContentAlignment.MiddleCenter;
InBlock.gif            cview.WordWrap 
= true;
InBlock.gif            grid1[xx, 
5].View = cview;
InBlock.gif
InBlock.gif            grid1[xx, 
7= new SourceGrid.Cells.Cell(bianhao);
InBlock.gif            
//grid1[xx, 7].RowSpan = 1;
InBlock.gif
            grid1[xx, 7].ColumnSpan = 3;
InBlock.gif            cview 
= new SourceGrid.Cells.Views.Cell();
InBlock.gif            cview.Font 
= font2;
InBlock.gif            cview.TextAlignment 
= DevAge.Drawing.ContentAlignment.MiddleLeft;
InBlock.gif            cview.WordWrap 
= true;
InBlock.gif            grid1[xx, 
7].View = cview;
InBlock.gif
InBlock.gif            
// 3
InBlock.gif
            xx = 3;
InBlock.gif            grid1[xx, 
0= new SourceGrid.Cells.RowHeader();
InBlock.gif
InBlock.gif            grid1[xx, 
5= new SourceGrid.Cells.Cell("共  " + cetotal + "  册    第  " + ceindex + "  册");
InBlock.gif            grid1[xx, 
5].ColumnSpan = 5;
InBlock.gif            cview 
= new SourceGrid.Cells.Views.Cell();
InBlock.gif            cview.Font 
= font2;
InBlock.gif            cview.TextAlignment 
= DevAge.Drawing.ContentAlignment.MiddleCenter;
InBlock.gif            cview.WordWrap 
= true;
InBlock.gif            grid1[xx, 
5].View = cview;
InBlock.gif
InBlock.gif            
// 4
InBlock.gif
            xx = 4;
InBlock.gif            grid1[xx, 
0= new SourceGrid.Cells.RowHeader();
InBlock.gif
InBlock.gif            grid1[xx, 
1= new SourceGrid.Cells.Cell("顺序号");
InBlock.gif            grid1[xx, 
1].RowSpan = 2;
InBlock.gif            grid1[xx, 
1].ColumnSpan = 1;
InBlock.gif            cview 
= new SourceGrid.Cells.Views.Cell();
InBlock.gif            cview.Font 
= font2;
InBlock.gif            cview.TextAlignment 
= DevAge.Drawing.ContentAlignment.MiddleCenter;
InBlock.gif            cview.WordWrap 
= true;
InBlock.gif            grid1[xx, 
1].View = cview;
InBlock.gif
InBlock.gif            grid1[xx, 
2= new SourceGrid.Cells.Cell("文号");
InBlock.gif            grid1[xx, 
2].RowSpan = 2;
InBlock.gif            grid1[xx, 
2].ColumnSpan = 1;
InBlock.gif            cview 
= new SourceGrid.Cells.Views.Cell();
InBlock.gif            cview.Font 
= font2;
InBlock.gif            cview.TextAlignment 
= DevAge.Drawing.ContentAlignment.MiddleCenter;
InBlock.gif            cview.WordWrap 
= true;
InBlock.gif            grid1[xx, 
2].View = cview;
InBlock.gif
InBlock.gif            grid1[xx, 
3= new SourceGrid.Cells.Cell("责任人");
InBlock.gif            grid1[xx, 
3].RowSpan = 2;
InBlock.gif            grid1[xx, 
3].ColumnSpan = 1;
InBlock.gif            cview 
= new SourceGrid.Cells.Views.Cell();
InBlock.gif            cview.Font 
= font2;
InBlock.gif            cview.TextAlignment 
= DevAge.Drawing.ContentAlignment.MiddleCenter;
InBlock.gif            cview.WordWrap 
= true;
InBlock.gif            grid1[xx, 
3].View = cview;
InBlock.gif
InBlock.gif            grid1[xx, 
4= new SourceGrid.Cells.Cell("文件题名");
InBlock.gif            grid1[xx, 
4].RowSpan = 2;
InBlock.gif            grid1[xx, 
4].ColumnSpan = 1;
InBlock.gif            cview 
= new SourceGrid.Cells.Views.Cell();
InBlock.gif            cview.Font 
= font2;
InBlock.gif            cview.TextAlignment 
= DevAge.Drawing.ContentAlignment.MiddleCenter;
InBlock.gif            cview.WordWrap 
= true;
InBlock.gif            grid1[xx, 
4].View = cview;
InBlock.gif
InBlock.gif            grid1[xx, 
5= new SourceGrid.Cells.Cell("日期");
InBlock.gif            grid1[xx, 
5].RowSpan = 2;
InBlock.gif            grid1[xx, 
5].ColumnSpan = 1;
InBlock.gif            cview 
= new SourceGrid.Cells.Views.Cell();
InBlock.gif            cview.Font 
= font2;
InBlock.gif            cview.TextAlignment 
= DevAge.Drawing.ContentAlignment.MiddleCenter;
InBlock.gif            cview.WordWrap 
= true;
InBlock.gif            grid1[xx, 
5].View = cview;
InBlock.gif
InBlock.gif            grid1[xx, 
6= new SourceGrid.Cells.Cell("页号");
InBlock.gif            grid1[xx, 
6].RowSpan = 2;
InBlock.gif            grid1[xx, 
6].ColumnSpan = 1;
InBlock.gif            cview 
= new SourceGrid.Cells.Views.Cell();
InBlock.gif            cview.Font 
= font2;
InBlock.gif            cview.TextAlignment 
= DevAge.Drawing.ContentAlignment.MiddleCenter;
InBlock.gif            cview.WordWrap 
= true;
InBlock.gif            grid1[xx, 
6].View = cview;
InBlock.gif
InBlock.gif            grid1[xx, 
7= new SourceGrid.Cells.Cell("相关载体");
InBlock.gif            grid1[xx, 
7].RowSpan = 1;
InBlock.gif            grid1[xx, 
7].ColumnSpan = 3;
InBlock.gif            cview 
= new SourceGrid.Cells.Views.Cell();
InBlock.gif            cview.Font 
= font2;
InBlock.gif            cview.TextAlignment 
= DevAge.Drawing.ContentAlignment.MiddleCenter;
InBlock.gif            cview.WordWrap 
= true;
InBlock.gif            grid1[xx, 
7].View = cview;
InBlock.gif
InBlock.gif            
// 5
InBlock.gif
            xx = 5;
InBlock.gif            grid1[xx, 
0= new SourceGrid.Cells.RowHeader();
InBlock.gif
InBlock.gif            grid1[xx, 
7= new SourceGrid.Cells.Cell("照片(张)");
InBlock.gif            grid1[xx, 
7].RowSpan = 1;
InBlock.gif            grid1[xx, 
7].ColumnSpan = 1;
InBlock.gif            cview 
= new SourceGrid.Cells.Views.Cell();
InBlock.gif            cview.Font 
= font3;
InBlock.gif            cview.TextAlignment 
= DevAge.Drawing.ContentAlignment.MiddleCenter;
InBlock.gif            cview.WordWrap 
= true;
InBlock.gif            grid1[xx, 
7].View = cview;
InBlock.gif
InBlock.gif            grid1[xx, 
8= new SourceGrid.Cells.Cell("录像(盘)");
InBlock.gif            grid1[xx, 
8].RowSpan = 1;
InBlock.gif            grid1[xx, 
8].ColumnSpan = 1;
InBlock.gif            cview 
= new SourceGrid.Cells.Views.Cell();
InBlock.gif            cview.Font 
= font3;
InBlock.gif            cview.TextAlignment 
= DevAge.Drawing.ContentAlignment.MiddleCenter;
InBlock.gif            cview.WordWrap 
= true;
InBlock.gif            grid1[xx, 
8].View = cview;
InBlock.gif
InBlock.gif            grid1[xx, 
9= new SourceGrid.Cells.Cell("媒体报道(条)");
InBlock.gif            grid1[xx, 
9].RowSpan = 1;
InBlock.gif            grid1[xx, 
9].ColumnSpan = 1;
InBlock.gif            cview 
= new SourceGrid.Cells.Views.Cell();
InBlock.gif            cview.Font 
= font3;
InBlock.gif            cview.TextAlignment 
= DevAge.Drawing.ContentAlignment.MiddleCenter;
InBlock.gif            cview.WordWrap 
= true;
InBlock.gif            grid1[xx, 
9].View = cview;
InBlock.gif
InBlock.gif            
object[] items = new object[mcount];
InBlock.gif            
for (int kl = 0; kl < mcount; kl++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                items[kl] 
= "";
ExpandedSubBlockEnd.gif            }

InBlock.gif            
for (int i = 0; i <pageline ; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                items 
= new object[mcount];
InBlock.gif                
if (i + begin >= rcount)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    items 
=new object[mcount];
InBlock.gif                    
for (int kl = 0; kl < mcount;kl++ )
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        items[kl] 
= "";
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.dataSet1.Tables["search3"].Rows[i + begin].ItemArray.CopyTo(items, 0);
ExpandedSubBlockEnd.gif                }
                
ContractedSubBlock.gifExpandedSubBlockStart.gif
循环表格内容#region 循环表格内容
InBlock.gif
InBlock.gif                xx 
= i + 6;
InBlock.gif                
//行头
InBlock.gif
                grid1[xx, 0= new SourceGrid.Cells.RowHeader();
InBlock.gif                
//顺序号
InBlock.gif
                grid1[xx, 1= new SourceGrid.Cells.Cell(items[5].ToString());
InBlock.gif                cview 
= new SourceGrid.Cells.Views.Cell();
InBlock.gif                cview.Font 
= font3;
InBlock.gif                cview.TextAlignment 
= DevAge.Drawing.ContentAlignment.MiddleCenter;
InBlock.gif                cview.WordWrap 
= true;
InBlock.gif                grid1[xx, 
1].View = cview;
InBlock.gif                
//文号
InBlock.gif
                grid1[xx, 2= new SourceGrid.Cells.Cell(items[6].ToString());
InBlock.gif                cview 
= new SourceGrid.Cells.Views.Cell();
InBlock.gif                cview.Font 
= font3;
InBlock.gif                cview.TextAlignment 
= DevAge.Drawing.ContentAlignment.MiddleLeft;
InBlock.gif                cview.WordWrap 
= true;
InBlock.gif                grid1[xx, 
2].View = cview;
InBlock.gif                
//责任人,linklabel
InBlock.gif
                grid1[xx, 3= new SourceGrid.Cells.Cell(items[7].ToString());
InBlock.gif                cview 
= new SourceGrid.Cells.Views.Cell();
InBlock.gif                cview.Font 
= font3;
InBlock.gif                cview.TextAlignment 
= DevAge.Drawing.ContentAlignment.MiddleLeft;
InBlock.gif                cview.WordWrap 
= true;
InBlock.gif                grid1[xx, 
3].View = cview;
InBlock.gif                
//文件题名,linklabel
InBlock.gif
                grid1[xx, 4= new SourceGrid.Cells.Link(items[8].ToString());
InBlock.gif                grid1[xx, 
4].ToolTipText = items[14].ToString();
InBlock.gif                cview 
= new SourceGrid.Cells.Views.Link();
InBlock.gif                cview.Font 
= font3;
InBlock.gif                cview.TextAlignment 
= DevAge.Drawing.ContentAlignment.MiddleLeft;
InBlock.gif                cview.WordWrap 
= true;
InBlock.gif                grid1[xx, 
4].View = cview;
InBlock.gif
InBlock.gif                grid1[xx, 
4].AddController(mController_Link);
InBlock.gif
InBlock.gif                
//日期
InBlock.gif
                grid1[xx, 5= new SourceGrid.Cells.Cell(items[9].ToString());
InBlock.gif                cview 
= new SourceGrid.Cells.Views.Cell();
InBlock.gif                cview.Font 
= font3;
InBlock.gif                cview.TextAlignment 
= DevAge.Drawing.ContentAlignment.MiddleLeft;
InBlock.gif                cview.WordWrap 
= true;
InBlock.gif                grid1[xx, 
5].View = cview;
InBlock.gif                
//页号
InBlock.gif
                grid1[xx, 6= new SourceGrid.Cells.Cell(items[10].ToString());
InBlock.gif                cview 
= new SourceGrid.Cells.Views.Cell();
InBlock.gif                cview.Font 
= font3;
InBlock.gif                cview.TextAlignment 
= DevAge.Drawing.ContentAlignment.MiddleLeft;
InBlock.gif                cview.WordWrap 
= true;
InBlock.gif                grid1[xx, 
6].View = cview;
InBlock.gif                
//相关载体--照片,linklable
InBlock.gif
                grid1[xx, 7= new SourceGrid.Cells.Link(items[11].ToString());
InBlock.gif                grid1[xx, 
7].ToolTipText = items[15].ToString();
InBlock.gif                cview 
= new SourceGrid.Cells.Views.Link();
InBlock.gif                cview.Font 
= font3;
InBlock.gif                cview.TextAlignment 
= DevAge.Drawing.ContentAlignment.MiddleLeft;
InBlock.gif                cview.WordWrap 
= true;
InBlock.gif                grid1[xx, 
7].View = cview;
InBlock.gif
InBlock.gif                grid1[xx, 
7].AddController(mController_Link);
InBlock.gif
InBlock.gif                
//相关载体--录像
InBlock.gif
                grid1[xx, 8= new SourceGrid.Cells.Link(items[12].ToString());
InBlock.gif                grid1[xx, 
8].ToolTipText = items[16].ToString();
InBlock.gif                cview 
= new SourceGrid.Cells.Views.Link();
InBlock.gif                cview.Font 
= font3;
InBlock.gif                cview.TextAlignment 
= DevAge.Drawing.ContentAlignment.MiddleLeft;
InBlock.gif                cview.WordWrap 
= true;
InBlock.gif                grid1[xx, 
8].View = cview;
InBlock.gif
InBlock.gif                grid1[xx, 
8].AddController(mController_Link);
InBlock.gif
InBlock.gif                
//相关载体--媒体报道
InBlock.gif
                grid1[xx, 9= new SourceGrid.Cells.Cell(items[13].ToString());
InBlock.gif                cview 
= new SourceGrid.Cells.Views.Cell();
InBlock.gif                cview.Font 
= font3;
InBlock.gif                cview.TextAlignment 
= DevAge.Drawing.ContentAlignment.MiddleLeft;
InBlock.gif                cview.WordWrap 
= true;
InBlock.gif                grid1[xx, 
9].View = cview;
InBlock.gif
ExpandedSubBlockEnd.gif                
#endregion

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif            
#endregion

InBlock.gif
InBlock.gif            resize();
ExpandedSubBlockEnd.gif        }

InBlock.gif       
InBlock.gif        
private class MyHeader : SourceGrid.Cells.ColumnHeader
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
public MyHeader(object value) : base(value)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//1 Header Row
InBlock.gif
                SourceGrid.Cells.Views.ColumnHeader view = new SourceGrid.Cells.Views.ColumnHeader();
InBlock.gif                view.Font 
= new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold);
InBlock.gif                view.TextAlignment 
= DevAge.Drawing.ContentAlignment.MiddleCenter;
InBlock.gif                View 
= view;
InBlock.gif
InBlock.gif                AutomaticSortEnabled 
= false;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif      
InBlock.gif        
private void Form1_Resize(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            resize();
ExpandedSubBlockEnd.gif        }

InBlock.gif        
private void resize()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (this.Visible)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
//grid1.AutoSizeCells();
InBlock.gif

InBlock.gif                    grid1.Columns[
0].Width = 20;
InBlock.gif                    grid1.Rows[
0].Height = 20;
InBlock.gif
InBlock.gif                    grid1.Columns[
1].Width = 40;
InBlock.gif                    grid1.Columns[
2].Width = 60;
InBlock.gif                    grid1.Columns[
3].Width = 120;
InBlock.gif                    grid1.Columns[
4].Width = 320;
InBlock.gif                    grid1.Columns[
5].Width = 80;
InBlock.gif                    grid1.Columns[
6].Width = 60;
InBlock.gif                    grid1.Columns[
7].Width = 60;
InBlock.gif                    grid1.Columns[
8].Width = 60;
InBlock.gif                    grid1.Columns[
9].Width = 60;
InBlock.gif
InBlock.gif                    grid1.Rows[
1].Height = 60;
InBlock.gif                    grid1.Rows[
2].Height = 60;
InBlock.gif                    grid1.Rows[
3].Height = 30;
InBlock.gif                    grid1.Rows[
4].Height = 30;
InBlock.gif                    grid1.Rows[
5].Height = 40;
InBlock.gif
InBlock.gif                    grid1.Rows[
6].Height = 40;
InBlock.gif                    grid1.Rows[
7].Height = 40;
InBlock.gif                    grid1.Rows[
8].Height = 40;
InBlock.gif                    grid1.Rows[
9].Height = 40;
InBlock.gif                    grid1.Rows[
10].Height = 40;
InBlock.gif                    grid1.Rows[
11].Height = 40;
InBlock.gif                    grid1.Rows[
12].Height = 40;
InBlock.gif                    grid1.Rows[
13].Height = 40;
InBlock.gif                    grid1.Rows[
14].Height = 40;
InBlock.gif                    grid1.Rows[
15].Height = 40;
InBlock.gif                    grid1.Rows[
16].Height = 40;
InBlock.gif                    grid1.Rows[
17].Height = 40;
InBlock.gif                    grid1.Rows[
18].Height = 40;
InBlock.gif                    grid1.Rows[
19].Height = 40;
InBlock.gif                    grid1.Rows[
20].Height = 40;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{ }
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private SourceGrid.Cells.Views.Cell cviews(Font font)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//视图样式
InBlock.gif
            SourceGrid.Cells.Views.Cell cview = new SourceGrid.Cells.Views.Cell();
InBlock.gif            
//cview.Font = new Font("宋体", 22, FontStyle.Regular);
InBlock.gif
            cview.Font = font;
InBlock.gif            cview.TextAlignment 
= DevAge.Drawing.ContentAlignment.MiddleCenter;
InBlock.gif            
//cview.AnchorArea = new DevAge.Drawing.AnchorArea(0f, 0f, 300f, 50f, true, true);
InBlock.gif            
//cview.AnchorArea = new DevAge.Drawing.AnchorArea(DevAge.Drawing.ContentAlignment.TopCenter, true);
InBlock.gif            
//DevAge.Drawing.Border border = new DevAge.Drawing.Border(Color.Red, 1);
InBlock.gif            
//cview.Border = new DevAge.Drawing.RectangleBorder(border);//边框
InBlock.gif            
//cview.Border = new DevAge.Drawing.RectangleBorder(DevAge.Drawing.Border.Black1Width);//边框
InBlock.gif            
//模型
InBlock.gif            
//SourceGrid.Cells.Models.ModelContainer models = new SourceGrid.Cells.Models.ModelContainer();
InBlock.gif            
//编辑器
InBlock.gif            
//SourceGrid.Cells.Editors.EditorBase editors = new SourceGrid.Cells.Editors.EditorBase(typeof(string));
InBlock.gif            
//虚拟表格
InBlock.gif            
//SourceGrid.Cells.Virtual.CellVirtual cellvirtral = new SourceGrid.Cells.Virtual.CellVirtual();
InBlock.gif

InBlock.gif            
return cview;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        
private void clickEvent_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//SourceGrid.CellContext context = (SourceGrid.CellContext)sender;
InBlock.gif            
//MessageBox.Show(this, context.Position.ToString());
ExpandedSubBlockEnd.gif
        }

InBlock.gif        
private void mController_Link_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                SourceGrid.CellContext context 
= (SourceGrid.CellContext)sender;
InBlock.gif
InBlock.gif                
string ss = context.Position.Column.ToString();
InBlock.gif                
string str = ((SourceGrid.Cells.Link)context.Cell).ToolTipText.ToString();
InBlock.gif                
string str1 = ((SourceGrid.Cells.Link)context.Cell).Value.ToString();
InBlock.gif                
if ((str == ""|| (str == null))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
return;
ExpandedSubBlockEnd.gif                }
                      
InBlock.gif                
switch (ss)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
case "4":
InBlock.gif                        
if (!Directory.Exists(path + str))
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            MessageBox.Show(
"图像路径不存在! " + path + str, "系统信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
InBlock.gif                            
return;
ExpandedSubBlockEnd.gif                        }
    
InBlock.gif                        Photo photo 
= new Photo();
InBlock.gif                        photo.filepath 
= str;
InBlock.gif                        photo.ShowDialog();
InBlock.gif                        photo.Dispose();
InBlock.gif                        
break;
InBlock.gif                    
case "7":
InBlock.gif                        
if (!Directory.Exists(path + str))
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            MessageBox.Show(
"图像路径不存在! " + path + str, "系统信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
InBlock.gif                            
return;
ExpandedSubBlockEnd.gif                        }
    
InBlock.gif                        Photo photo2 
= new Photo();
InBlock.gif                        photo2.filepath 
= str;
InBlock.gif                        photo2.ShowDialog();
InBlock.gif                        photo2.Dispose();
InBlock.gif                        
break;
InBlock.gif                    
case "8":
InBlock.gif                        
if (!File.Exists(path + str))
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            MessageBox.Show(
"录像文件不存在! " + path + str, "系统信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
InBlock.gif                            
return;
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        DevAge.Shell.Utilities.OpenFile(path 
+ str);
InBlock.gif                        
break;
InBlock.gif                    
default:
InBlock.gif                        
break;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (Exception op)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//MessageBox.Show(op.Message,"系统信息Doc");
ExpandedSubBlockEnd.gif
            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
private void button1_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//this.Text = this.grid1.Width.ToString()+" "+this.grid1.Height.ToString();
InBlock.gif            
//Form2 form2 = new Form2();
InBlock.gif            
//form2.Show();
ExpandedSubBlockEnd.gif
        }

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
access 数据库操作#region access 数据库操作
InBlock.gif       
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 打开数据库,建立新的表和字段
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="spath">数据库全路径</param>
InBlock.gif        
/// <param name="dataname">表名</param>
ExpandedSubBlockEnd.gif        
/// <param name="items">字段数组</param>

InBlock.gif        private void newdatatable(string spath, string dataname, string[] items)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//连接到一个数据库
InBlock.gif
                string strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = " + spath;
InBlock.gif                OleDbConnection myConn 
= new OleDbConnection(strCon);
InBlock.gif                myConn.Open();
InBlock.gif                
// string strnew = " CREATE TABLE " + dataname + "( "
InBlock.gif                
//     + items[0] + " TEXT(100) CONSTRAINT PK_tblCustomers PRIMARY KEY , ";
InBlock.gif
                string strnew = " CREATE TABLE [" + dataname + "] ( "
InBlock.gif                     
+ items[0+ " TEXT(255) , ";
InBlock.gif                
for (int i = 1; i < items.Length - 1; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    strnew 
+= items[i] + " TEXT(255) , ";
ExpandedSubBlockEnd.gif                }

InBlock.gif                strnew 
+= items[items.Length - 1+ " TEXT(255) )";
ExpandedSubBlockStart.gifContractedSubBlock.gif                
/**//*
InBlock.gif            string strnew = " CREATE TABLE "+ dataname +"("
InBlock.gif                + " CustomerID INTEGER CONSTRAINT PK_tblCustomers PRIMARY KEY,"
InBlock.gif                + " [Last Name] TEXT(50) NOT NULL,"
InBlock.gif                + " [First Name] TEXT(50) NOT NULL,"
InBlock.gif            + " Phone TEXT(10),"
InBlock.gif            + " Email TEXT(50),"
InBlock.gif            + " Address TEXT(40) DEFAULT Unknown)";
ExpandedSubBlockEnd.gif                
*/

InBlock.gif                OleDbCommand myCommand 
= new OleDbCommand(strnew, myConn);
InBlock.gif                myCommand.ExecuteNonQuery();
InBlock.gif                myConn.Close();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (Exception ed)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                MessageBox.Show(
"新建表错误信息: " + ed.ToString(), "错误!", MessageBoxButtons.OK, MessageBoxIcon.Error);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 打开数据库,建立新的表和字段
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="spath">数据库全路径</param>
InBlock.gif        
/// <param name="dataname">表名</param>
ExpandedSubBlockEnd.gif        
/// <param name="items">字段集合</param>

InBlock.gif        private void newdatatable(string spath, string dataname, ArrayList items)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//连接到一个数据库
InBlock.gif
                string strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = " + spath;
InBlock.gif                OleDbConnection myConn 
= new OleDbConnection(strCon);
InBlock.gif                myConn.Open();
InBlock.gif                
// string strnew = " CREATE TABLE [" + dataname + "] ( "
InBlock.gif                
//    + items[0] + " TEXT(100) CONSTRAINT PK_tblCustomers PRIMARY KEY , ";
InBlock.gif
                string strnew = " CREATE TABLE [" + dataname + "] ( "
InBlock.gif                    
+ items[0+ " TEXT(255) , ";
InBlock.gif                
for (int i = 1; i < items.Count - 1; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    strnew 
+= items[i].ToString() + " TEXT(255) , ";
ExpandedSubBlockEnd.gif                }

InBlock.gif                strnew 
+= items[items.Count - 1].ToString() + " TEXT(255) )";
ExpandedSubBlockStart.gifContractedSubBlock.gif                
/**//*
InBlock.gif            string strnew = " CREATE TABLE "+ dataname +"("
InBlock.gif                + " CustomerID INTEGER CONSTRAINT PK_tblCustomers PRIMARY KEY,"
InBlock.gif                + " [Last Name] TEXT(50) NOT NULL,"
InBlock.gif                + " [First Name] TEXT(50) NOT NULL,"
InBlock.gif            + " Phone TEXT(10),"
InBlock.gif            + " Email TEXT(50),"
InBlock.gif            + " Address TEXT(40) DEFAULT Unknown)";
ExpandedSubBlockEnd.gif                
*/

InBlock.gif                OleDbCommand myCommand 
= new OleDbCommand(strnew, myConn);
InBlock.gif                myCommand.ExecuteNonQuery();
InBlock.gif                myConn.Close();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (Exception ed)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                MessageBox.Show(
"新建表错误信息: " + ed.ToString(), "错误!", MessageBoxButtons.OK, MessageBoxIcon.Error);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 删除数据库中的表,有则删除,无则忽略错误返回
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="spath">数据库全名</param>
ExpandedSubBlockEnd.gif        
/// <param name="dataname">表名</param>

InBlock.gif        private void deletetable(string spath, string dataname)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//连接到一个数据库
InBlock.gif
                string strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = " + spath;
InBlock.gif                OleDbConnection myConn 
= new OleDbConnection(strCon);
InBlock.gif                myConn.Open();
InBlock.gif                
string strnew = " DROP TABLE " + dataname;
InBlock.gif                OleDbCommand myCommand 
= new OleDbCommand(strnew, myConn);
InBlock.gif                myCommand.ExecuteNonQuery();
InBlock.gif                myConn.Close();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch// (Exception ed)
ExpandedSubBlockStart.gifContractedSubBlock.gif
            dot.gif{
InBlock.gif                
//MessageBox.Show("删除表错误信息: " + ed.ToString(), "错误!", MessageBoxButtons.OK, MessageBoxIcon.Error);
ExpandedSubBlockEnd.gif
            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 修改表的字段(有错误,sql语法错误)
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="spath">数据库全路径</param>
InBlock.gif        
/// <param name="dataname">表名</param>
InBlock.gif        
/// <param name="s1">原字段名</param>
ExpandedSubBlockEnd.gif        
/// <param name="s2">新字段名</param>

InBlock.gif        private void rename_column(string spath, string dataname, string s1, string s2)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//连接到一个数据库
InBlock.gif
                string strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = " + spath;
InBlock.gif                OleDbConnection myConn 
= new OleDbConnection(strCon);
InBlock.gif                myConn.Open();
InBlock.gif                
string strnew = " ALTER TABLE  " + dataname + " ALTER COLUMN " + s1 + " TO " + s2 + "";
InBlock.gif                OleDbCommand myCommand 
= new OleDbCommand(strnew, myConn);
InBlock.gif                myCommand.ExecuteNonQuery();
InBlock.gif                myConn.Close();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (Exception ed)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                MessageBox.Show(
"修改字段错误信息: " + ed.ToString(), "错误!", MessageBoxButtons.OK, MessageBoxIcon.Error);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 获取数据库中的表名(不用,有错误)
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="spath">数据库全名</param>

InBlock.gif        private void gettablename2(string spath)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//连接到一个数据库
InBlock.gif
                string strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = " + spath;
InBlock.gif                OleDbConnection myConn 
= new OleDbConnection(strCon);
InBlock.gif                myConn.Open();
InBlock.gif                
string strnew = "SELECT MSysObjects.Name FROM MsysObjects WHERE (Left([Name],1)<>'~') AND (Left$([Name],4) <> 'Msys') AND (MSysObjects.Type)=1 ORDER BY MSysObjects.Name";
InBlock.gif                OleDbCommand myCommand 
= new OleDbCommand(strnew, myConn);
InBlock.gif                OleDbDataReader reader 
= myCommand.ExecuteReader();
InBlock.gif
InBlock.gif                
while (reader.Read())
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    MessageBox.Show(reader.GetInt32(
0+ "" + reader.GetString(1));
ExpandedSubBlockEnd.gif                }

InBlock.gif                reader.Close();
InBlock.gif                myConn.Close();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (Exception ed)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                MessageBox.Show(
"删除表错误信息: " + ed.ToString(), "错误!", MessageBoxButtons.OK, MessageBoxIcon.Error);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 打开指定的access数据库
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="spath">access数据库名</param>
ExpandedSubBlockEnd.gif        
/// <param name="dataname">access数据库中的表名</param>    

InBlock.gif        public bool readdata(string spath, string dataname)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//创建一个 OleDbConnection对象
InBlock.gif
                string strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = " + spath;
InBlock.gif                OleDbConnection myConn 
= new OleDbConnection(strCon);
InBlock.gif                
// string strCom = " SELECT * FROM " + dataname + " ORDER BY  id";
InBlock.gif
                string strCom = "SELECT [" + dataname + "].* FROM [" + dataname + "]";
InBlock.gif                
//string strCom = " SELECT * FROM " + dataname;
InBlock.gif                
//创建一个 DataSet对象
InBlock.gif
                myConn.Open();
InBlock.gif                OleDbDataAdapter myCommand 
= new OleDbDataAdapter(strCom, myConn);
InBlock.gif                
if (this.dataSet1.Tables.Contains(dataname))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.dataSet1.Tables.Remove(dataname);
ExpandedSubBlockEnd.gif                }

InBlock.gif                myCommand.Fill(
this.dataSet1, dataname);
InBlock.gif                myConn.Close();
InBlock.gif                
return true;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch// (Exception e)
ExpandedSubBlockStart.gifContractedSubBlock.gif
            dot.gif{
InBlock.gif                
// MessageBox.Show("连接数据库发生错误:" + e.ToString(), "错误!", MessageBoxButtons.OK, MessageBoxIcon.Error);
InBlock.gif
                return false;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 新增记录
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="spath">数据库全名</param>
InBlock.gif        
/// <param name="dataname">表名</param>
InBlock.gif        
/// <param name="captions">字段名</param>
ExpandedSubBlockEnd.gif        
/// <param name="items">添加的纪录内容</param>     

InBlock.gif        public void newdata(string spath, string dataname, string[] captions, object[] items)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//连接到一个数据库
InBlock.gif
                string strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = " + spath;
InBlock.gif                OleDbConnection myConn 
= new OleDbConnection(strCon);
InBlock.gif                myConn.Open();
InBlock.gif                
string strInsert;
InBlock.gif                
int tt = captions.Length;
InBlock.gif                
int sign = -1;//记录日期字段所在索引号,用来格式化日期格式(只要日期,不要时间)
InBlock.gif

InBlock.gif                strInsert 
= " INSERT INTO [" + dataname + "] ( "
InBlock.gif                     
+ captions[0+ " , ";
InBlock.gif
InBlock.gif                
for (int i = 1; i < tt - 1; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
if (captions[i].Contains("日期"))
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        sign 
= i;
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    strInsert 
+= captions[i] + " , ";
ExpandedSubBlockEnd.gif                }

InBlock.gif                strInsert 
+= captions[tt - 1+ " ) VALUES ( '";
InBlock.gif
InBlock.gif                
for (int i = 0; i < tt - 1; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
if (i == sign)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
string[] ss = items[i].ToString().Split(' ');
InBlock.gif                        strInsert 
+= ss[0+ "','";
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        strInsert 
+= items[i].ToString() + "','";
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif                strInsert 
+= items[tt - 1].ToString() + "')";
ExpandedSubBlockStart.gifContractedSubBlock.gif                
/**//*
InBlock.gif                strInsert = " INSERT INTO " + dataname
InBlock.gif                   + " ( id,date,dirid,fileid,name,pid,gjjid,bgjjid,why,pages,oldid,bak ) VALUES ( ' "
InBlock.gif                   + items[0].ToString() + "' , '"
InBlock.gif                   + items[1].ToString() + "' , '"
InBlock.gif                   + items[2].ToString() + "' , '"
InBlock.gif                   + items[3].ToString() + "' , '"
InBlock.gif                   + items[4].ToString() + "' , '"
InBlock.gif                   + items[5].ToString() + "' , '"
InBlock.gif                   + items[6].ToString() + "' , '"
InBlock.gif                   + items[7].ToString() + "' , '"
InBlock.gif                   + items[8].ToString() + "' , '"
InBlock.gif                   + items[9].ToString() + "' , '"
InBlock.gif                   + items[10].ToString() + "' , '"
InBlock.gif                   + items[11].ToString() + " ')";
ExpandedSubBlockEnd.gif                 
*/

InBlock.gif                OleDbCommand myCommand 
= new OleDbCommand(strInsert, myConn);
InBlock.gif                myCommand.ExecuteNonQuery();
InBlock.gif                myConn.Close();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (Exception ed)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                MessageBox.Show(
"新增记录错误信息: " + ed.ToString(), "错误!", MessageBoxButtons.OK, MessageBoxIcon.Error);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 搜索access数据库
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="spath">access数据库名</param>
InBlock.gif        
/// <param name="dataname">access数据库中的表名</param>
InBlock.gif        
/// <param name="keyword">搜索关键字</param>
InBlock.gif        
/// <param name="tablename">填充到dataset中的表名</param>
ExpandedSubBlockEnd.gif        
/// <returns></returns>

InBlock.gif        public bool searchdata(string spath, string dataname, string keyword, string tablename)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//string str = "";
InBlock.gif
            bool yn = false;
InBlock.gif            
//创建一个 OleDbConnection对象
InBlock.gif
            string strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = " + spath;
InBlock.gif            OleDbConnection myConn 
= new OleDbConnection(strCon);
InBlock.gif            
string strCom = "SELECT [" + dataname + "].* FROM [" + dataname + "] WHERE " + keyword;
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                myConn.Open();
InBlock.gif                OleDbDataAdapter myCommand 
= new OleDbDataAdapter(strCom, myConn);
InBlock.gif                
if (this.dataSet1.Tables.Contains(tablename))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.dataSet1.Tables.Remove(tablename);
ExpandedSubBlockEnd.gif                }

InBlock.gif                myCommand.Fill(
this.dataSet1, tablename);
InBlock.gif                yn 
= true;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (Exception e)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//MessageBox.Show(dataname + " 数据库中不包含搜索的字段!\n" + e.ToString(), "错误!", MessageBoxButtons.OK, MessageBoxIcon.Error);
InBlock.gif
                MessageBox.Show(dataname + " 数据库中不包含搜索的字段!\n""错误!", MessageBoxButtons.OK, MessageBoxIcon.Information);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                myConn.Close();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return yn;
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
InBlock.gif        
private void button_head_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.pageat = 1;
InBlock.gif            
this.drawgird();
InBlock.gif            
this.numer_n.Value = this.pageat;
InBlock.gif            
this.textBox_n.Text = this.pages.ToString();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void button_prv_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.pageat--;
InBlock.gif            
if (this.pageat < 1)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.pageat = 1;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
this.drawgird();
InBlock.gif            
this.numer_n.Value = this.pageat;
InBlock.gif            
this.textBox_n.Text = this.pages.ToString();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void button_next_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.pageat++;
InBlock.gif            
if (this.pageat >this.pages)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.pageat = this.pages;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
this.drawgird();
InBlock.gif            
this.numer_n.Value = this.pageat;
InBlock.gif            
this.textBox_n.Text = this.pages.ToString();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void button_end_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.pageat = this.pages;
InBlock.gif            
this.drawgird();
InBlock.gif            
this.numer_n.Value = this.pageat;
InBlock.gif            
this.textBox_n.Text = this.pages.ToString();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void numer_n_ValueChanged(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.pageat = (int)this.numer_n.Value;
InBlock.gif            
this.drawgird();
InBlock.gif            
this.numer_n.Value = this.pageat;
InBlock.gif            
this.textBox_n.Text = this.pages.ToString();
InBlock.gif      
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void pictureBox1_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            About about 
= new About();
InBlock.gif            about.ShowDialog();
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

转载于:https://www.cnblogs.com/dreign/archive/2006/11/20/566267.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值