📄 结账.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;
namespace WindowsApplication1
{
public partial class 结账 : Form
{
public 结账()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
double Pay = 0;
SqlConnection cn = new SqlConnection();
cn.ConnectionString = "Data Source=sclab76\\SQLEXPRESS;Initial Catalog=医院管理系统;MultipleActiveResultSets=True;User id=sa;Password=niit#1234";
cn.Open();
//SqlTransaction tran = null;
//try
//{
//tran = cn.BeginTransaction();
SqlCommand cmd = new SqlCommand("Select * from Account where IPID=@ipid and Date=@date", cn);
cmd.Parameters.Add(new SqlParameter("@ipid", textBox1.Text));
cmd.Parameters.Add(new SqlParameter("@date", dateTimePicker1.Text));
SqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable("Account");
DataSet ds = new DataSet();
dt.Columns.Add("IPID");
dt.Columns.Add("Date");
dt.Columns.Add("Medicine_Code");
dt.Columns.Add("Medicine_Amount");
ds.Tables.Add(dt);
while (dr.Read())
{
DataRow drow = dt.NewRow();
drow["IPID"] = (string)(dr["IPID"]);
drow["Date"] = dr["Date"].ToString();
drow["Medicine_Code"] = dr["Medicine_Code"].ToString();
drow["Medicine_Amount"] = dr["Medicine_Amount"].ToString();
dt.Rows.Add(drow);
SqlCommand cmd1 = new SqlCommand("select Price from Medicine_Store where Medicine_Code = @code", cn);
cmd1.Parameters.Add(new SqlParameter("@code", dr["Medicine_Code"]));
SqlDataReader dr1 = cmd1.ExecuteReader();
while (dr1.Read())
{
Pay += Convert.ToDouble(dr1[0].ToString()) * Convert.ToInt32(dr["Medicine_Amount"]);
}
}
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "Account";
SqlCommand cmd2 = new SqlCommand("insert into calculator(IPID,PriceAll)values(@ipid,@price)", cn);
cmd2.Parameters.Add(new SqlParameter("@ipid", textBox1.Text));
cmd2.Parameters.Add(new SqlParameter("@price", Pay.ToString()));
cmd2.ExecuteNonQuery();
label4.Text = Pay.ToString();
//tran.Commit();
MessageBox.Show("更新成功");
/*}
catch (SqlException ex)
{
tran.Rollback();
MessageBox.Show(ex.Message);
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
cn.Close();
}*/
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -