📄 wgsf.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
namespace WindowsApplication1
{
/// <summary>
/// wgsf 的摘要说明。
/// </summary>
public class wgsf : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.StatusBar statusBar1;
private System.Windows.Forms.StatusBarPanel statusBarPanel1;
private System.Windows.Forms.StatusBarPanel statusBarPanel2;
private System.Windows.Forms.StatusBarPanel statusBarPanel3;
private System.Windows.Forms.StatusBarPanel statusBarPanel4;
private System.Windows.Forms.StatusBarPanel statusBarPanel5;
private System.Windows.Forms.StatusBarPanel statusBarPanel6;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.ComboBox comboBox2;
private BindingManagerBase MyBind;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public wgsf()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(wgsf));
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.statusBar1 = new System.Windows.Forms.StatusBar();
this.statusBarPanel1 = new System.Windows.Forms.StatusBarPanel();
this.statusBarPanel2 = new System.Windows.Forms.StatusBarPanel();
this.statusBarPanel3 = new System.Windows.Forms.StatusBarPanel();
this.statusBarPanel4 = new System.Windows.Forms.StatusBarPanel();
this.statusBarPanel5 = new System.Windows.Forms.StatusBarPanel();
this.statusBarPanel6 = new System.Windows.Forms.StatusBarPanel();
this.label2 = new System.Windows.Forms.Label();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.comboBox2 = new System.Windows.Forms.ComboBox();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel3)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel4)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel5)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel6)).BeginInit();
this.SuspendLayout();
//
// dataGrid1
//
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(32, 48);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(432, 320);
this.dataGrid1.TabIndex = 4;
//
// statusBar1
//
this.statusBar1.Location = new System.Drawing.Point(0, 392);
this.statusBar1.Name = "statusBar1";
this.statusBar1.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
this.statusBarPanel1,
this.statusBarPanel2,
this.statusBarPanel3,
this.statusBarPanel4,
this.statusBarPanel5,
this.statusBarPanel6});
this.statusBar1.ShowPanels = true;
this.statusBar1.Size = new System.Drawing.Size(504, 24);
this.statusBar1.TabIndex = 5;
this.statusBar1.Text = "statusBar1";
//
// statusBarPanel1
//
this.statusBarPanel1.Text = "水费";
//
// statusBarPanel2
//
this.statusBarPanel2.Text = "电费";
//
// statusBarPanel3
//
this.statusBarPanel3.Text = "气费";
//
// statusBarPanel4
//
this.statusBarPanel4.Text = "物管费";
//
// statusBarPanel5
//
this.statusBarPanel5.Text = "其他费";
//
// statusBarPanel6
//
this.statusBarPanel6.Text = "合计";
//
// label2
//
this.label2.BackColor = System.Drawing.Color.Transparent;
this.label2.Location = new System.Drawing.Point(232, 8);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(96, 16);
this.label2.TabIndex = 9;
this.label2.Text = "设置查询时间:";
//
// comboBox1
//
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox1.Items.AddRange(new object[] {
"Bh"});
this.comboBox1.Location = new System.Drawing.Point(48, 24);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(88, 20);
this.comboBox1.TabIndex = 8;
//
// label1
//
this.label1.BackColor = System.Drawing.Color.Transparent;
this.label1.Location = new System.Drawing.Point(40, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(96, 16);
this.label1.TabIndex = 7;
this.label1.Text = "选择查询条件:";
this.label1.Click += new System.EventHandler(this.label1_Click);
//
// button1
//
this.button1.BackColor = System.Drawing.Color.Transparent;
this.button1.Location = new System.Drawing.Point(416, 16);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 24);
this.button1.TabIndex = 6;
this.button1.Text = "开始查询";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// comboBox2
//
this.comboBox2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox2.Location = new System.Drawing.Point(232, 24);
this.comboBox2.Name = "comboBox2";
this.comboBox2.Size = new System.Drawing.Size(136, 20);
this.comboBox2.TabIndex = 10;
//
// wgsf
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(504, 416);
this.Controls.Add(this.comboBox2);
this.Controls.Add(this.label2);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.label1);
this.Controls.Add(this.button1);
this.Controls.Add(this.statusBar1);
this.Controls.Add(this.dataGrid1);
this.Name = "wgsf";
this.Load += new System.EventHandler(this.wgsf_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel3)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel4)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel5)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel6)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void wgsf_Load(object sender, System.EventArgs e)
{
string connstr,selectcmd;
connstr="Provider=Microsoft.jet.oledb.4.0;data source="+Application.StartupPath+"\\xqwy.mdb";
selectcmd="select * from sfb";
OleDbConnection conn=new OleDbConnection(connstr);
conn.Open();
OleDbDataAdapter da=new OleDbDataAdapter(selectcmd,conn);
//OleDbDataAdapter oleDbDataAdapter1=new OleDbDataAdapter(selectcmd,conn);
DataSet ds=new DataSet();
//DataSet dataSet1=new DataSet();
da.Fill(ds,"sfb");
DataTable mytable=new DataTable();
mytable=ds.Tables[0];
this.dataGrid1.DataSource=mytable;
this.comboBox2.DataBindings.Add("Text",mytable,"Sfsj");
zairu();
}
public void zairu()
{
string sqlstr;
string connstr="Provider=Microsoft.jet.oledb.4.0;data source="+Application.StartupPath+"\\xqwy.mdb";
sqlstr="select Bh from sfb";
OleDbConnection conn=new OleDbConnection(connstr);
conn.Open();
OleDbDataAdapter da=new OleDbDataAdapter(sqlstr,conn);
DataSet ds=new DataSet();
da.Fill(ds,"sfb");
DataTable mytable=new DataTable();
mytable=ds.Tables[0];
DataRow myrow;
for(int i=0;i<mytable.Rows.Count;i++)
{
myrow=mytable.Rows[i];
this.comboBox2.Items.Add(myrow[0]);
}
}
public void button1_Click(object sender, System.EventArgs e)
{
try
{
string connstr,StrSQL;
connstr="Provider=Microsoft.jet.oledb.4.0;data source="+Application.StartupPath+"\\xqwy.mdb";
if(this.comboBox1.Text=="所有记录")
StrSQL="SELECT * FROM Sfb";
StrSQL="SELECT * FROM Sfb WHERE "+this.comboBox1.Text+"='"+this.comboBox2.Text.Trim()+"'";
OleDbConnection conn=new OleDbConnection(connstr);
conn.Open();
OleDbDataAdapter da=new OleDbDataAdapter(StrSQL,conn);
DataSet ds=new DataSet();
da.Fill(ds,"sfb");
DataTable mytable=new DataTable();
mytable=ds.Tables[0];
this.dataGrid1.DataSource=mytable;
//OleDbCommandBuilder cmdbld=new OleDbCommandBuilder(da);
//da.Update(mytable);
}
catch(Exception Err)
{
MessageBox.Show("查询数据集记录操作失败:"+Err.Message,"信息提示",
MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
private void label1_Click(object sender, System.EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -