📄 浏览.cs
字号:
#region Using directives
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlServerCe;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
#endregion
namespace AIFACE
{
public partial class 浏览 : Form
{
private SqlCeConnection connection = null;
private SqlCeCommand command = null;
private SqlCeResultSet resultSet = null;
private ResultSetView view1 = null;
private ResultSetView view2 = null;
private ResultSetView view3 = null;
private ResultSetView view4 = null;
private ResultSetView view5 = null;
private ResultSetView view6 = null;
public 浏览()
{
InitializeComponent();
if (null == this.connection)
{
string strCon = GetConnectionString();
this.connection = new SqlCeConnection(strCon);
this.connection.Open();
}
}
private string GetConnectionString()
{
return String.Format(System.Globalization.CultureInfo.InvariantCulture,
@"Data Source = {0}\AIFACE.sdf;password=wiseyes", Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase));
}
private void 浏览_Load(object sender, EventArgs e)
{
try
{
if (null != this.view1)
((IDisposable)view1).Dispose();
if (null != this.view2)
((IDisposable)view2).Dispose();
if (null != this.view3)
((IDisposable)view3).Dispose();
if (null != this.view4)
((IDisposable)view4).Dispose();
if (null != this.view5)
((IDisposable)view5).Dispose();
if (null != this.view6)
((IDisposable)view6).Dispose();
if (null != this.command)
this.command.Dispose();
if (null != this.resultSet)
this.resultSet.Dispose(); //释放Dataset
this.command = this.connection.CreateCommand();
String query = "Select 仪器编号,仪器名称,分类号,分类名称,使用部门,安置地点,单价,数量,总价 from sb_zjk where 盘点 = 1";
this.command.CommandText = query;
ResultSetOptions options = ResultSetOptions.Scrollable | ResultSetOptions.Sensitive ;
this.resultSet = this.command.ExecuteResultSet(options);
int m = 0;
while (resultSet.Read())
m++;
view1 = this.resultSet.ResultSetView;
this.dataGrid1.DataSource = view1;
query = "Select 仪器编号,仪器名称,分类号,分类名称,使用部门,安置地点,单价,数量,总价 from sb_zjk where 盘点 = 0";
this.command.CommandText = query;
this.resultSet = this.command.ExecuteResultSet(options);
int n = 0;
while (resultSet.Read())
n++;
view2 = this.resultSet.ResultSetView;
this.dataGrid2.DataSource = view2;
StringBuilder sDisp = new StringBuilder();
sDisp.Append("已盘点资产 ");
sDisp.Append(m);
sDisp.Append(" 件;未盘点资产 ");
sDisp.Append(n);
sDisp.Append(" 件");
statusBar1.Text = sDisp.ToString();
tabControl1.SelectedIndex = 0;
tabControl2.SelectedIndex = 0;
tabControl3.SelectedIndex = 0;
}
catch (InvalidOperationException ex)
{
MessageBox.Show(String.Format(System.Globalization.CultureInfo.CurrentCulture,
"连接数据库发生错误: \n {0}", ex.ToString()));
}
catch (SqlCeException ex)
{
MessageBox.Show(String.Format(System.Globalization.CultureInfo.CurrentCulture,
"连接数据库发生错误: \n {0}", ex.ToString()));
}
}
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
if (tabControl1.SelectedIndex == 2)
{
if (this.view3 == null)
{
tabControl2.SelectedIndex = 0;
tabControl3.SelectedIndex = 0;
comboBox1.Items.Clear();
String query = "Select * from dm_sydw where 部门代码 <> '0000' order by 部门代码";
this.command.CommandText = query;
ResultSetOptions options = ResultSetOptions.Scrollable | ResultSetOptions.Sensitive;
this.resultSet = this.command.ExecuteResultSet(options);
String s = "";
while (this.resultSet.Read())
{
comboBox1.Items.Add(this.resultSet.GetString(0) + " " + this.resultSet.GetString(1));
if (s == "")
{
s = this.resultSet.GetString(0) + " " + this.resultSet.GetString(1);
}
}
comboBox1.Text = s;
}
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
String CurrentUnit = comboBox1.Text.Substring(0, 4);
ResultSetOptions options = ResultSetOptions.Scrollable | ResultSetOptions.Sensitive;
String query = "Select 仪器编号,仪器名称,分类号,分类名称,安置地点,单价,数量,总价 "
+ "from sb_zjk "
+ "where 盘点 = 1 and 部门代码 = '" + CurrentUnit + "' and 盘点部门 = '" + CurrentUnit + "'";
this.command.CommandText = query;
this.resultSet = this.command.ExecuteResultSet(options);
view3 = this.resultSet.ResultSetView;
this.dataGrid3.DataSource = view3;
query = "Select 仪器编号,仪器名称,分类号,分类名称,安置地点,单价,数量,总价 "
+ "from sb_zjk "
+ "where 盘点 = 0 and 部门代码 = '" + CurrentUnit + "'";
this.command.CommandText = query;
this.resultSet = this.command.ExecuteResultSet(options);
view4 = this.resultSet.ResultSetView;
this.dataGrid4.DataSource = view4;
query = "Select 仪器编号,仪器名称,分类号,分类名称,dm_sydw.使用部门,安置地点,单价,数量,总价 "
+ "from sb_zjk inner join dm_sydw "
+ "on sb_zjk.盘点部门 = dm_sydw.部门代码 where 盘点 = 1 and sb_zjk.部门代码 = '" + CurrentUnit + "' and 盘点部门 <> '" + CurrentUnit + "'";
this.command.CommandText = query;
this.resultSet = this.command.ExecuteResultSet(options);
view5 = this.resultSet.ResultSetView;
this.dataGrid5.DataSource = view5;
query = "Select 仪器编号,仪器名称,分类号,分类名称,使用部门 所属部门,安置地点,单价,数量,总价 "
+ "from sb_zjk "
+ "where 盘点 = 1 and 部门代码 <> '" + CurrentUnit + "' and 盘点部门 = '" + CurrentUnit + "'";
this.command.CommandText = query;
this.resultSet = this.command.ExecuteResultSet(options);
view6 = this.resultSet.ResultSetView;
this.dataGrid6.DataSource = view6;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -