📄 detailquery.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace 财务管理系统
{
/// <summary>
/// DetailQuery 的摘要说明。
/// </summary>
public class DetailQuery : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Button btnSearch;
private System.Windows.Forms.TextBox txt1;
private System.Windows.Forms.Label label2;
private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
private 财务管理系统.DataSet1 dataSet11;
private System.Data.DataView dataView1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.ComboBox comboBox1;
private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
private System.Data.SqlClient.SqlConnection sqlConnection1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public DetailQuery()
{
//
// 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(DetailQuery));
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.dataView1 = new System.Data.DataView();
this.dataSet11 = new 财务管理系统.DataSet1();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.btnSearch = new System.Windows.Forms.Button();
this.txt1 = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dataView1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.SuspendLayout();
//
// dataGrid1
//
this.dataGrid1.CaptionVisible = false;
this.dataGrid1.DataMember = "";
this.dataGrid1.DataSource = this.dataView1;
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(-8, 69);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.ReadOnly = true;
this.dataGrid1.Size = new System.Drawing.Size(720, 416);
this.dataGrid1.TabIndex = 33;
//
// dataView1
//
this.dataView1.Table = this.dataSet11.本期明细账簿;
//
// dataSet11
//
this.dataSet11.DataSetName = "DataSet1";
this.dataSet11.Locale = new System.Globalization.CultureInfo("zh-CN");
//
// groupBox1
//
this.groupBox1.Controls.Add(this.btnSearch);
this.groupBox1.Controls.Add(this.txt1);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Location = new System.Drawing.Point(0, 2);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(360, 64);
this.groupBox1.TabIndex = 32;
this.groupBox1.TabStop = false;
//
// btnSearch
//
this.btnSearch.Image = ((System.Drawing.Image)(resources.GetObject("btnSearch.Image")));
this.btnSearch.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnSearch.Location = new System.Drawing.Point(40, 28);
this.btnSearch.Name = "btnSearch";
this.btnSearch.Size = new System.Drawing.Size(72, 23);
this.btnSearch.TabIndex = 6;
this.btnSearch.Text = " 搜索";
this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
//
// txt1
//
this.txt1.Location = new System.Drawing.Point(224, 28);
this.txt1.Name = "txt1";
this.txt1.TabIndex = 8;
this.txt1.Text = "";
//
// label2
//
this.label2.Location = new System.Drawing.Point(144, 32);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(56, 16);
this.label2.TabIndex = 7;
this.label2.Text = "科目代码";
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "本期明细账簿", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("科目名称", "科目名称"),
new System.Data.Common.DataColumnMapping("会计期间", "会计期间"),
new System.Data.Common.DataColumnMapping("凭证字号", "凭证字号"),
new System.Data.Common.DataColumnMapping("凭证编号", "凭证编号"),
new System.Data.Common.DataColumnMapping("科目代码", "科目代码"),
new System.Data.Common.DataColumnMapping("借方", "借方"),
new System.Data.Common.DataColumnMapping("贷方", "贷方"),
new System.Data.Common.DataColumnMapping("余额方向", "余额方向"),
new System.Data.Common.DataColumnMapping("余额", "余额")})});
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT b.科目名称, a.会计期间, a.凭证字号, a.凭证编号, a.科目代码, a.借方, a.贷方, a.余额方向, a.余额 FROM 本期明细" +
"账簿 a INNER JOIN 科目表 b ON a.科目代码 = b.科目代码 WHERE (a.科目代码 LIKE @Param2)";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param2", System.Data.SqlDbType.VarChar, 20, "科目代码"));
//
// groupBox2
//
this.groupBox2.Controls.Add(this.comboBox1);
this.groupBox2.Location = new System.Drawing.Point(360, 1);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(344, 63);
this.groupBox2.TabIndex = 34;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "选择要显示在表中的项目";
//
// comboBox1
//
this.comboBox1.Location = new System.Drawing.Point(120, 32);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(121, 20);
this.comboBox1.TabIndex = 0;
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=localhost;packet size=4096;integrated security=SSPI;initial catalo" +
"g=caiwubook;persist security info=False";
//
// DetailQuery
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(704, 485);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.groupBox1);
this.Name = "DetailQuery";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "【明细帐查询】";
this.Load += new System.EventHandler(this.DetailQuery_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataView1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
//----------显示窗口时读入全部数据--------------
private void DetailQuery_Load(object sender, System.EventArgs e)
{
sqlDataAdapter1.SelectCommand.Parameters[0].Value="%%";
sqlDataAdapter1.Fill(dataSet11);
comboBox1.Items.Add("全部数据");//添加选择显示全部数据的选项
foreach(DataRow aRow in dataSet11.本期明细账簿.Rows)//根据明细表中的科目名称,设置下拉字典
{
string newStr=aRow["科目名称"].ToString().Trim();
comboBox1.Items.Add(newStr);
}
}
//------------根据科目代码选择数据------------
private void btnSearch_Click(object sender, System.EventArgs e)
{
sqlDataAdapter1.SelectCommand.Parameters[0].Value="%%";
if(txt1.Text.Trim()!=null)
{
sqlDataAdapter1.SelectCommand.Parameters[0].Value="%"+txt1.Text.Trim()+"%";
dataSet11.Clear();
sqlDataAdapter1.Fill(dataSet11);
//重新设置下拉选项
comboBox1.Items.Clear();
comboBox1.Items.Add("全部数据");
foreach(DataRow aRow in dataSet11.本期明细账簿.Rows)
{
string newStr=aRow["科目名称"].ToString().Trim();
comboBox1.Items.Add(newStr);
}
}
}
//------------筛选在表中显示的项目------------
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
if(comboBox1.SelectedIndex==0)//若选中显示全部数据则全部显示
{
dataView1.RowFilter="";
}
else
{
dataView1.RowFilter="科目名称='"+comboBox1.Text+"'";//否则根据选中的科目名称进行选择
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -