http://pan.baidu.com/s/1hqu332c
网盘奉上
主要问题:
缴费界面上 合计药费这个按钮不会写
可以给我具体源代码吗?
采纳,回头给你代码。
太大了。请帖核心代码。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace 专科医院门诊系统_眼科_
{
public partial class 缴费界面 : Form
{
OleDbDataAdapter adapter;
DataTable table = new DataTable();
OleDbConnection con = new OleDbConnection();
string str = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\design\vc\project\专科医院门诊系统(眼科)\db1.accdb";
public 缴费界面()
{
InitializeComponent();
con.ConnectionString = str;
button1.Click += new EventHandler(button1_Click);
button2.Click += new EventHandler(button2_Click);
button3.Click += new EventHandler(button3_Click);
button4.Click += new EventHandler(button4_Click);
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
挂号缴费选择界面 frm = new 挂号缴费选择界面();
frm.Show();
Hide();
}
private void button2_Click(object sender, EventArgs e)
{
adapter.SelectCommand.CommandText = "select * from [patient] where ID ='" + textBox1.Text + "'";
table.Clear();
adapter.Fill(table);
dataGridView1.DataSource = table;
}
private void button3_Click(object sender, EventArgs e)
{
//查询药品界面 frm = new 查询药品界面();
//frm.Show();
//Hide();
}
private void button4_Click(object sender, EventArgs e)
{
if (textBox2.Text != "")
{
string a = "是";
OleDbCommand cmd = new OleDbCommand(@"update patient set 药费 = '"+textBox2 .Text +"',是否已收费='"+a +"' where ID ='"+textBox1 .Text +"'" );
con.Open();
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("写入数据库成功");
}
else
{
MessageBox.Show("请输入药费");
}
}
private void 缴费界面_Load(object sender, EventArgs e)
{
string sql = "select * from [patient]";
adapter = new OleDbDataAdapter(sql, str);
}
}
}
手头没有vs.
给你方法:
利用dataGridView的Rows来遍历这个控件
伪代码如下:
//这个方法用来合计药费
private int sum() {
double s = 0.0d;
var g = this.dataGridView;
for(int i = 0 ; i < g.Rows.Count;i++) {
var row = g.Rows[i];
var cells = row.Cells;
//j就是你药费那列的索引,实际应用中,你要注意Null的判断哦
var cell = cells[j];
//这个就是药费了
var val = cell.Value;
//你需要做个类型转换,比如转为double,实际应用中,你要注意用户是否输错了药费格式
double fee = Convert.toDoule(val);
s += fee;
}
return s;
}
看到这个中文类名我醉了
private void button3_Click(object sender, EventArgs e)
{
OleDbCommand cmd = new OleDbCommand(@"select 处方 from patient where ID ='" + textBox1.Text + "'");
con.Open();
cmd.Connection = con;
string[] m = cmd.ExecuteScalar().ToString().Trim(';').Split(';');
int total = 0;
foreach (var item in m)
{
cmd = new OleDbCommand(@"select 单价 from drug where 药名 ='" + item + "'");
if (con.State != ConnectionState.Open)
con.Open();
cmd.Connection = con;
int x = int.Parse(cmd.ExecuteScalar().ToString());
total += x;
}
textBox2.Text = total.ToString();
con.Close();
cmd.Clone();
}