VS
程序员文章站
2022-07-02 19:19:44
...
DB.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using System.Data.SqlClient; using System.Threading.Tasks; namespace SCNT1 { class DB :IDisposable { private SqlConnection sqlConnection; public DB()//私有无参构造函数 { sqlConnection = new SqlConnection(@"server=.\SQLEXPRESS;database=SCNT;Trusted_Connection=SSPI;"); sqlConnection.Open(); } public DataTable getBySql(string sql) {//查询 SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(new SqlCommand(sql, sqlConnection)); DataTable dataTable = new DataTable(); sqlDataAdapter.Fill(dataTable); return dataTable; } public void setBySql(string sql) { //修改 new SqlCommand(sql, sqlConnection).ExecuteNonQuery(); } public void Dispose() {//相当于析构函数 sqlConnection.Close(); //在C#中关闭数据库连接不能在类的析构函数中关,否则会抛“内部 .Net Framework 数据提供程序错误 1”的异常 //通过实现C#中IDisposable接口中的Dispose()方法主要用途是释放非托管资源。 } } }
Intent.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SCNT1
{
class Intent
{
public static Dictionary<string, Object> dict = new Dictionary<string, Object>();
}
}
可根据大科室名称,小科室名称,病人姓名在一个界面实现单条件,组合条件查询,
病人姓名可提供模糊查询,得到的结果按大科室(降序),小科室(升序),病人(降序)顺序排列。
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace scnt2_2
{
public partial class Form1 : Form
{
DB db;
public Form1()
{
InitializeComponent();
db = new DB();
}
private void button1_Click(object sender, EventArgs e)
{
listView1.Clear();
listView1.Columns.Add("大科室名称", listView1.Width / 3 - 1);
listView1.Columns.Add("小科室名称", listView1.Width / 3 - 1);
listView1.Columns.Add("病人姓名", listView1.Width / 3 - 1);
StringBuilder sql = new StringBuilder("select [Group].[DeptNo],[Group].[GroupNo],[Patient].[PName] from [Group],[Patient] where [Group].[GroupNo]=[Patient].[GroupNo]");
if (radioButton1.Checked == true)
sql.AppendLine("and [Group].[DeptNo]='" + textBox1.Text + "'");
if (radioButton2.Checked == true)
sql.AppendLine("and [Group].[GroupNo]='" + textBox2.Text + "'");
if (radioButton3.Checked == true)
sql.AppendLine("and [Patient].[PName] like '%" + textBox3.Text + "%'");
sql.AppendLine("order by [Group].[DeptNo] desc,[Group].[GroupNo],[Patient].[PName] desc");
DataTable table = db.getBySql(sql+"");
listView1.BeginUpdate();//数据更新,UI暂时挂起,直到EndUpdate绘制控件,可以有效避免闪烁并大大提高加载速度
for (int i = 0; i < table.Rows.Count; i++)
{
ListViewItem listViewItem = new ListViewItem();//生成每一列
for (int j = 0; j < table.Columns.Count; j++)
{
if (j <= 0)
{
listViewItem.Text = table.Rows[i][j] + "";
}
else
{
listViewItem.SubItems.Add(table.Rows[i][j] + "");
}
}
listView1.Items.Add(listViewItem);
}
listView1.EndUpdate();//结束数据处理,UI界面一次性
radioButton1.Checked = false;
radioButton2.Checked = false;
radioButton3.Checked = false;
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
}
}
}
加载现有的员工号
table = db.getBySql(@"select [EmpNo] from [EMPLOYEE]");
for (int i = 0; i < table.Rows.Count; i++)
{
for (int j = 0; j < table.Columns.Count; j++)
{
comboBox1.Items.Add(table.Rows[i][j] + "");
}
}
comboBox1.SelectedIndex = 0;
文档
1,在 D:\复试复习\机试\数据库\SCNT1 文件夹中打开 SCUT1.sln 这个文件,进入解决方案,再点击左侧的各个 .cs 文件,能够读到我的源代码。
2,直接运行的 .exe 在 D:\复试复习\机试\数据库\SCNT1\SCNT1\bin\Debug 文件夹的 SCNT1.exe(窗体用的 .NET Framework4.5)
3,数据库在 D:\复试复习\机试\数据库 文件夹下,备份也在这个文件夹下。数据库直接负载于Sql Server 中,不设密码,开放权限,直接通过Windows身份登录就能够查看。
推荐阅读
-
C# VS2019 WebService创建与发布,并部署到Windows Server 2012R
-
vs2010 中文版下载地址及可用CDKEY 多个地址打包下载
-
VS2010破解版迅雷电驴下载 visual studio2010简体中文正式旗舰版破解版下载(附序列号)
-
vs2010 MSDN文档安装图文方法
-
VS2010执行剪贴、复制时,提示内存不足的官方补丁
-
使用VS2019在WSL中开发调试.NET Core
-
VS中模仿WPF模板创建最简单的WPF程序
-
消除VS中动态申请二维数组C6011,C6385,C6386的警告
-
vs2019安装和使用详细图文教程
-
dictionary vs Hashtables