物资管理系统
本实例采用datagridview绑定Oracle数据源来显示相关的数据信息。物资管理系统实现了4大管理和3大查询功能,分别是入库管理、领用管理、归还管理、人员管理、领用查询、资产查询、人员查询,1.0版只是大概实现了简单的功能,程序还有待改进。由于数据库装在了另外一台服务器上,所以就不对数据库表结构进行说明了,下面讲一下所用到的sql语句。
- 入库管理
1 private void button1_Click(object sender, EventArgs e) 2 { 3 try 4 { 5 OracleConnection conn = new OracleConnection(@"Data Source=数据库名称;User ID=用户名;Password=密码;Unicode=true"); 6 conn.Open(); 7 OracleCommand cmd = new OracleCommand(); 8 cmd.Connection = conn; 9 10 cmd.CommandText = "insert into 表名(DATA,CODE,NAME,QUANTITY,PRICE,ACCOUNTING,OWENER,CHECKING,TOUCHING,REMARKS) values(sysdate,'" + textBox3.Text + "','" + textBox6.Text + "','" + textBox8.Text + "','" + textBox9.Text + "','" + textBox2.Text + "','" + comboBox2.Text + "','" + comboBox1.Text + "','" + textBox7.Text + "','" + textBox10.Text + "')"; 11 cmd.CommandType = CommandType.Text; 12 cmd.ExecuteNonQuery(); 13 conn.Close(); 14 15 } 16 catch(OracleException ex) 17 { 18 MessageBox.Show("数据库连接异常,请检查网络连接!"); 19 } 20 finally 21 { 22 this.Close(); 23 24 } 25 }
1 private void button1_Click(object sender, EventArgs e) 2 { 3 try 4 { 5 OracleConnection conn = new OracleConnection(@"Data Source=数据库名称;User ID=用户名;Password=密码;Unicode=true"); 6 conn.Open(); 7 OracleCommand cmd = new OracleCommand(); 8 cmd.Connection = conn; 9 cmd.CommandText = "insert into EBD_ENTER(DATA,CODE,NAME,QUANTITY,PRICE,ACCOUNTING,OWENER,CHECKING,TOUCHING,REMARKS) values(sysdate,'" + textBox3.Text + "','" + textBox6.Text + "','" + textBox8.Text + "','" + textBox9.Text + "','" + textBox2.Text + "','" + comboBox2.Text + "','" + comboBox1.Text + "','" + textBox7.Text + "','" + textBox10.Text + "')"; 10 cmd.CommandType = CommandType.Text; 11 cmd.ExecuteNonQuery(); 12 conn.Close(); 13 } 14 catch(OracleException ex) 15 { 16 MessageBox.Show("数据库连接异常,请检查网络连接!"); 17 } 18 finally 19 { 20 this.Close(); 21 }
- 领用管理
1 private void button1_Click(object sender, EventArgs e) 2 { 3 try 4 { 5 OracleConnection conn = new OracleConnection(@"Data Source=数据库名称;User ID=用户名;Password=密码;Unicode=true"); 6 conn.Open(); 7 OracleCommand cmd = new OracleCommand(); 8 cmd.Connection = conn; 9 //string aa = DateTime.Now.ToString(); 10 cmd.CommandText = "insert into 表名(OUTDATE,PRONAME,QUANTITY,OUTUSER,REMARKS,NO,STATUS) values(sysdate,'" + textBox1.Text + "','" + textBox2.Text + "','" + comboBox2.Text + "','" + textBox3.Text + "','"+textBox4.Text+"','"+comboBox1.Text+"')"; 11 cmd.CommandType = CommandType.Text; 12 cmd.ExecuteNonQuery(); 13 conn.Close(); 14 } 15 catch (OracleException ex) 16 { 17 MessageBox.Show("数据库连接异常,请检查网络连接!"); 18 } 19 finally 20 { 21 this.Close(); 22 } 23 }
- 归还管理
1 private void button1_Click(object sender, EventArgs e) 2 { 3 try 4 { 5 OracleConnection conn = new OracleConnection(@"Data Source=数据库名称;User ID=用户名;Password=密码;Unicode=true"); 6 conn.Open(); 7 OracleCommand cmd = new OracleCommand(); 8 cmd.Connection = conn; 9 cmd.CommandText="update 表名 set STATUS='已还' where NO='"+textBox1.Text+"'"; 10 cmd.CommandType=CommandType.Text; 11 cmd.ExecuteNonQuery(); 12 conn.Close(); 13 this.Close(); 14 } 15 catch (OracleException ex) 16 { 17 MessageBox.Show("数据库连接出错!"); 18 } 19 }
- 人员管理
1 private void button2_Click(object sender, EventArgs e) 2 { 3 try 4 { 5 OracleConnection conn = new OracleConnection(@"Data Source=数据库名称;User ID=用户名;Password=密码;Unicode=true"); 6 conn.Open(); 7 OracleCommand cmd = new OracleCommand(); 8 cmd.Connection = conn; 9 cmd.CommandText = "insert into 表名(NAME,AGE,SEX,UNIVERSITY,NATIVE,COMPANY,ENTRYTIME,SPECIALSKILL,HOBBY,QQ,PHONENUMBER,PROFILE,REMARKS) values('" + textBox2.Text + "','" + textBox4.Text + "','" + textBox3.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','"+textBox13+"','" +textBox7.Text + "','" + textBox8.Text + "','" + textBox9.Text + "','"+textBox10.Text+"','"+textBox11.Text+"','"+textBox12.Text+"','"+textBox1+"')"; 10 cmd.CommandType = CommandType.Text; 11 cmd.ExecuteNonQuery(); 12 conn.Close(); 13 } 14 catch (OracleException ex) 15 { 16 MessageBox.Show("数据库连接异常,请检查网络连接!"); 17 } 18 finally 19 { 20 this.Close(); 21 } 22 }
- 领用查询
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Windows.Forms; 9 using System.Data.OracleClient; 10 11 namespace 物资管理系统 12 { 13 public partial class 领用查询 : Form 14 { 15 public 领用查询() 16 { 17 18 InitializeComponent(); 19 } 20 21 private void button1_Click(object sender, EventArgs e) 22 { 23 if (this.comboBox1.Text != null) 24 { 25 //首先判断数据库中是否存在记录数,如果有的话再执行try里的语句,否则的话执行catch的语句。 26 string str = "select count(*) from 表名"; 27 using (OracleConnection conn = new OracleConnection(@"Data Source=数据库名称;User ID=用户名;Password=密码;Unicode=true")) 28 { 29 OracleCommand cmd = new OracleCommand(str, conn); 30 conn.Open(); 31 OracleDataReader reader; 32 reader = cmd.ExecuteReader(); 33 int count = 0; 34 if (reader.Read()) 35 { 36 count = Convert.ToInt32(reader[0].ToString()); 37 } 38 if (count > 0) 39 { 40 try 41 { 42 OracleDataAdapter da = new OracleDataAdapter("select * from 表名 where OUTUSER='" + this.comboBox1.SelectedItem.ToString() + "'", conn); 43 DataSet ds1 = new DataSet(); 44 da.Fill(ds1, "gza"); 45 this.dataGridView1.DataSource = ds1.Tables["gza"].DefaultView; 46 for (int i = 0; i < dataGridView1.Rows.Count; i++) 47 { 48 if (dataGridView1["STATUS", i].Value != null && dataGridView1["STATUS", i].Value.ToString().Trim() == "已还") 49 { 50 this.dataGridView1["STATUS", i].Style.BackColor = System.Drawing.Color.White; 51 this.dataGridView1["STATUS", i].Style.ForeColor = System.Drawing.Color.Blue; 52 } 53 else 54 { 55 this.dataGridView1.Columns[6].DefaultCellStyle.BackColor = Color.Red; 56 this.dataGridView1.BackgroundColor = Color.PapayaWhip; 57 } 58 } 59 conn.Close(); 60 } 61 catch (OracleException ex) 62 { 63 MessageBox.Show("数据库连接异常,请检查网络连接!"); 64 } 65 66 } 67 else 68 { 69 MessageBox.Show("没有该记录!"); 70 } 71 } 72 } 73 else 74 { 75 MessageBox.Show("请先选择领用人!"); 76 } 77 78 } 79 } 80 }
- 资产查询
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using System.Data.OracleClient;
10
11 namespace 物资管理系统
12 {
13 public partial class 资产查询 : Form
14 {
15 public 资产查询()
16 {
17 InitializeComponent();
18 }
19
20 private void 资产查询_Load(object sender, EventArgs e)
21 {
22 try
23 {
24 OracleConnection conn = new OracleConnection(@"Data Source=数据库名称;User ID=用户名;Password=密码;Unicode=true");
25 OracleDataAdapter da = new OracleDataAdapter("select * from 表名", conn);
26 DataSet ds = new DataSet();
27 da.Fill(ds, "test");
28 BindingSource bs = new BindingSource();
29 bs.DataSource = ds.Tables["test"];
30 comboBox1.DataSource = ds.Tables["test"];
31 comboBox1.DisplayMember = "OBJNAME";
32 comboBox1.ValueMember = "OBJNAME";
33 }
34 catch (OracleException ex)
35 {
36 MessageBox.Show("数据库连接失败!");
37 }
38 }
39 private void button1_Click(object sender, EventArgs e)
40 {
41
42 try
43 {
44 OracleConnection conn = new OracleConnection(@"Data Source=数据库名称;User ID=表名;Password=密码;Unicode=true");
45 OracleDataAdapter da = new OracleDataAdapter("select * from 表名 where OBJNAME='"+comboBox1.Text+"'", conn);
46 DataSet ds = new DataSet();
47 da.Fill(ds, "test");
48 BindingSource bs = new BindingSource();
49 bs.DataSource = ds.Tables["test"];
50 bindingNavigator1.BindingSource = bs;
51 this.dataGridView1.DataSource = ds.Tables["test"].DefaultView;
52 }
53 catch (OracleException ex)
54 {
55 MessageBox.Show("数据库连接失败!");
56 }
57 }
58 private void button3_Click(object sender, EventArgs e)
59 {
60 try
61 {
62 OracleConnection conn = new OracleConnection(@"Data Source=数据库名称;User ID=用户名;Password=密码;Unicode=true");
63 OracleDataAdapter da = new OracleDataAdapter("select * from 表名", conn);
64 DataSet ds = new DataSet();
65 da.Fill(ds, "test");
66 BindingSource bs = new BindingSource();
67 bs.DataSource = ds.Tables["test"];
68 bindingNavigator1.BindingSource = bs;
69 this.dataGridView1.DataSource = ds.Tables["test"].DefaultView;
70 }
71 catch (OracleException ex)
72 {
73 MessageBox.Show("数据库连接失败!");
74 }
75 }
76 private void button2_Click(object sender, EventArgs e)
77 {
78 double money = 0;
79 for (int i = 0; i < dataGridView1.Rows.Count; i++)
80 {
81 money += Convert.ToDouble(dataGridView1.Rows[i].Cells["OBJPRICE"].Value);
82
83 }
84 MessageBox.Show("共计"+money+"元");
85 }
86 }
87 }
- 人员查询
手动修改dv里的值后保存,同时更新到数据库中。
详细画面如下: