📄 frmsdfgl.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.OleDb;
namespace 学生宿舍管理系统
{
public partial class FrmSDFGL : Form
{
public FrmSDFGL()
{
InitializeComponent();
}
private void Form3_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox2.Text == "")
{
MessageBox.Show("请输入栋号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (textBox4.Text == "")
{
MessageBox.Show("请输入房间号码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (textBox1.Text == "")
{
MessageBox.Show("请输入本月水表读数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (textBox3.Text == "")
{
MessageBox.Show("请输入本月电表读数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
try
{
MyData mydate = new MyData();
string str = "select 栋号,房间号码 from 房间基本信息表 where 栋号='" + textBox2.Text + "'and 房间号码='" + textBox4.Text + "'";
OleDbDataReader dr = mydate.getDataReader(str);
if (dr.Read())
{
double i = 0, j = 0;
mydate = new MyData();
str = "select * from 房间基本信息表 where 栋号='" + textBox2.Text + "'and 房间号码='" + textBox4.Text + "'";
dr = mydate.getDataReader(str);
while (dr.Read())
{
i = Convert.ToDouble(dr["水表底数"]);//水
j = Convert.ToDouble(dr["电表底数"]);//电
}
string str1 = "select * from 标准费用表";// 计算时候用到的数据单价和用量标准等
OleDbDataReader dr1 = mydate.getDataReader(str1);
double a = 0, b = 0, c = 0, d = 0;
while (dr1.Read())
{
a = Convert.ToDouble(dr1[1]);//水费单价
b = Convert.ToDouble(dr1[2]);//电费单价
c = Convert.ToDouble(dr1[3]);//标准用水量
d = Convert.ToDouble(dr1[4]);//标准用电量
}
//判断输入的实际性
if (i >= double.Parse(textBox1.Text))
{
MessageBox.Show("本月输入水表读数小于等于上月水表的读数");
return;
}
else if (j >= double.Parse(textBox3.Text))
{
MessageBox.Show("本月输入电表读数小于等于上月电表的读数");
return;
}
else
{
double wcf; double wcd; double pcf; double pcd;
double water = Convert.ToDouble(textBox1.Text);//水表现数
double power = Convert.ToDouble(textBox3.Text);//电表现数
double shuifei = a * (water - i);//水费
double dianfei = b * (power - j);//电费
if (water - i - c > 0)///////////////////////////////////////超额的计算
{
wcf = a * (water - i - c);
wcd = water - i - c;
}
else
{
wcf = 0;
wcd = 0;
}
if (power - j - d > 0)
{
pcf = b * (power - j - d);
pcd = power - j - d;
}
else
{
pcf = 0;
pcd = 0;
}
double hj1 = dianfei + shuifei;//费用合计
double hj2 = wcf + pcf;//超额合计
string strSQL = "insert into 水电费表(房间号码,栋号,抄表日期,水表现数,电表现数,电表底数,水表底数,水费,电费,费用合计,水超额吨数,电超额度数,超额水费,超额电费,超额合计)values('" + textBox4.Text + "','" + textBox2.Text + "','" + dateTimePicker1.Text + "'," + textBox1.Text + "," + textBox3.Text + "," + j + "," + i + "," + shuifei + "," + dianfei + "," + hj1 + "," + wcd + "," + pcd + "," + wcf + "," + pcf + "," + hj2 + ")";
mydate.updateSql(strSQL);
string k = "update 房间基本信息表 set 电表底数=" + textBox1.Text + ",水表底数= " + textBox3.Text + "";
mydate.updateSql(k);
MessageBox.Show("提交结算成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
else
{
MessageBox.Show("该宿舍没有被初始化(请先初始化宿舍)");
}
}
catch
{
MessageBox.Show("请输入有效的电,水表读数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void button2_Click(object sender, EventArgs e)
{
if (textBox5.Text == "" || textBox6.Text == "")
{
if (textBox5.Text == "")
{
MessageBox.Show("请输入栋号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (textBox6.Text == "")
{
MessageBox.Show("请输入房间号码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
}
else
{
MyData mydate = new MyData();
string str = "select 栋号,房间号码 from 房间基本信息表 where 栋号='" + textBox5.Text + "'and 房间号码='" + textBox6.Text + "'";
OleDbDataReader dr = mydate.getDataReader(str);
if (dr.Read())
{
mydate = new MyData();
DataSet ds = mydate.getDataSet("select * from 水电费查询 where 栋号='" + textBox5.Text + "'and 房间号码='" + textBox6.Text + "'", "水电费查询");
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "水电费查询";
}
else
MessageBox.Show("该宿舍没有被初始化(请先初始化宿舍)");
}
}
private void button3_Click(object sender, EventArgs e)
{
if (textBox7.Text == "" || textBox8.Text == "")
{
if (textBox7.Text == "")
{
MessageBox.Show("请输入栋号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
if (textBox8.Text == "")
{
MessageBox.Show("请输入房间号码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
else
{
MyData mydate = new MyData();
string str = "select 栋号,房间号码 from 房间基本信息表 where 栋号='" + textBox7.Text + "'and 房间号码='" + textBox8.Text + "'";
OleDbDataReader dr = mydate.getDataReader(str);
if (dr.Read())
{
mydate = new MyData();
DataSet ds = mydate.getDataSet("select * from 超额查询 where 栋号='" + textBox7.Text + "'and 房间号码='" + textBox8.Text + "'", "超额查询");
dataGridView2.DataSource = ds;
dataGridView2.DataMember = "超额查询";
}
else
{
MessageBox.Show("该宿舍没有被初始化(请先初始化宿舍)");
}
}
}
private void button4_Click(object sender, EventArgs e)
{
this.Close();
}
private void button5_Click(object sender, EventArgs e)
{
this.Close();
}
private void button6_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -