📄 入库查询.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Drawing.Printing;
namespace WindowsApplication1
{
public partial class 入库查询 : Form
{
SqlCommand cmd;
DataSet ds = new DataSet();
SqlDataReader dr;
SqlDataAdapter da;
SqlConnection cn = new SqlConnection();
PrintDialog pdlg = new PrintDialog();
internal PrintDocument PDoc = new PrintDocument();
internal PrintDocument PDoc2 = new PrintDocument();
public 入库查询()
{
InitializeComponent();
}
private void groupBox1_Enter(object sender, EventArgs e)
{}
private void Form4_Load(object sender, EventArgs e)
{
PDoc.PrintPage += new PrintPageEventHandler(PDoc_PrintPage);
cn.ConnectionString = "Data Source=sclab76\\SQLEXPRESS;Initial Catalog=医院管理系统;User id=sa;Password=niit#1234";
cn.Open();
cmd = new SqlCommand("Select MedicineIn_Code,MedicineIn_Date from Medicine_In", cn);
dr = cmd.ExecuteReader();
while (dr.Read())
{
comboBox1.Items.Add(dr["MedicineIn_Code"].ToString());
comboBox2.Items.Add(dr["MedicineIn_Date"].ToString());
}
cn.Close();
}
private void button1_Click(object sender, EventArgs e)
{
cn.ConnectionString = "Data Source=sclab76\\SQLEXPRESS;Initial Catalog=医院管理系统;User id=sa;Password=niit#1234";
cn.Open();
ds = new DataSet();
da = new SqlDataAdapter();
if ((comboBox1.Text == "") && (comboBox2.Text == ""))
{
cmd = new SqlCommand("Select * from Medicine_In", cn);
}
else
{
if (comboBox1.Text != "")
{
cmd = new SqlCommand("Select * from Medicine_In where MedicineIn_Code=@code", cn);
cmd.Parameters.Add(new SqlParameter("@code", comboBox1.Text));
}
else
{
cmd = new SqlCommand("Select * from Medicine_In where MedicineIn_Date=@date", cn);
cmd.Parameters.Add(new SqlParameter("@date", comboBox2.Text));
}
}
da.SelectCommand = cmd;
da.Fill(ds, "MedicineIn");
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "MedicineIn";
dataGridView1.Columns[0].HeaderText = "票号";
dataGridView1.Columns[1].HeaderText = "供应商编号";
dataGridView1.Columns[2].HeaderText = "供应商名称";
dataGridView1.Columns[3].HeaderText = "药品编号";
dataGridView1.Columns[4].HeaderText = "数量";
dataGridView1.Columns[5].HeaderText = "总价";
dataGridView1.Columns[6].HeaderText = "入库日期";
dataGridView1.Columns[7].HeaderText = "经办人";
dataGridView1.Columns[8].HeaderText = "备注";
cn.Close();
}
//------------------------------------------------------------------------------------------------------------
private void PDoc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
int x = 20;
int y = 20;
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
for (int j = 0; j < dataGridView1.Columns.Count; j++)
{
y += 20;
if (y >= e.PageBounds.Height - 80)
{
e.HasMorePages = true;
}
e.HasMorePages = false;
e.Graphics.DrawString(dataGridView1.Rows[i].Cells[j].Value.ToString(), new Font("Arial", 10, FontStyle.Bold), Brushes.Black, x, y);
}
}
}
private void button3_Click(object sender, EventArgs e)
{
PrintPreviewDialog ob = new PrintPreviewDialog();
ob.Document = PDoc;
ob.ShowDialog();
}
private void button2_Click_1(object sender, EventArgs e)
{
pdlg.Document = PDoc;
DialogResult result = pdlg.ShowDialog();
if (result == DialogResult.OK)
PDoc.Print();
}
private void button4_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -