⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmsdftj.cs

📁 学生宿舍管理系统 学生宿舍管理系统
💻 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 FrmSDFTJ : Form
    {
        public FrmSDFTJ()
        {
            InitializeComponent();
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }
        MyData mydate = new MyData();
        private void button1_Click(object sender, EventArgs e)
        {
          
                if (textBox1.Text == "")
                {
                    MessageBox.Show("请输入栋号", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (textBox2.Text == "")
                {
                    MessageBox.Show("请输入房间号", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                
            try
                {
                string s1 = "select * from 房间基本信息表 WHERE 栋号='" + textBox1.Text + "' AND 房间号码 ='" + textBox2.Text + "'";
                string str1 = "select * from 水电费查询 WHERE 栋号='" + textBox1.Text + "' AND 房间号码 ='" + textBox2.Text + "'  AND  抄表日期  Between # " + dateTimePicker1.Value + "# And # " + dateTimePicker2.Value + "# ";
                OleDbDataReader drr = mydate.getDataReader(s1);
                OleDbDataReader dr1 = mydate.getDataReader(str1);
                double s = 0;
                if (drr.HasRows == true)
                {
                    while (dr1.Read())
                    {
                        s = s + (Convert.ToDouble(dr1["水表现数"]) - Convert.ToDouble(dr1["水表底数"]));

                    }
                    string str = "select * from 超额查询 WHERE 栋号='" + textBox1.Text + "' AND 房间号码 ='" + textBox2.Text + "'  AND  抄表日期  Between # " + dateTimePicker1.Value + "# And # " + dateTimePicker2.Value + "# ";
                    OleDbDataReader dr = mydate.getDataReader(str);
                    double c = 0;
                    while (dr.Read())
                    {
                        c = c + Convert.ToDouble(dr["水超额吨数"]);
                    }
                    dr1.Close();
                    dr.Close();
                    string k = "update 用水量表 set 栋号='" + textBox1.Text + "',房间号码='" + textBox2.Text + "',开始时间=# " + dateTimePicker1.Value + "#,结束时间=# " + dateTimePicker2.Value + "# ,用水总吨数=" + s + ",超额用水总吨数=" + c + "";
                    mydate.updateSql(k);
                    DataSet ds = mydate.getDataSet("select 栋号,房间号码,开始时间,结束时间,用水总吨数,超额用水总吨数 from 用水量表 where 栋号='" + textBox1.Text + "'and 房间号码='" + textBox2.Text + "'", "用水量表");
                    dataGridView1.DataSource = ds;
                    dataGridView1.DataMember = "用水量表";
                }
                else
                {

                    MessageBox.Show("该宿舍没有被初始化(请先初始化该宿舍)!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    dataGridView1.DataSource = null;
                }
            }
                
            catch
            {
                MessageBox.Show("该宿舍没有被初始化(请先初始化该宿舍)或还没有输入电,水表读数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
           
        }

        private void button2_Click(object sender, EventArgs e)
        {
           
                if (textBox1.Text == "")
                {
                    MessageBox.Show("请输入栋号", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (textBox2.Text == "")
                {
                    MessageBox.Show("请输入房间号", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                try
                {
                string str1 = "select * from 水电费查询 WHERE 栋号='" + textBox1.Text + "' AND 房间号码 ='" + textBox2.Text + "'  AND  抄表日期  Between # " + dateTimePicker1.Value + "# And # " + dateTimePicker2.Value + "# ";
                OleDbDataReader dr1 = mydate.getDataReader(str1);
                double  s = 0;
                while (dr1.Read())
                {
                    s = s + (Convert.ToDouble(dr1["电表现数"]) - Convert.ToDouble(dr1["电表底数"]));
                }
                string str = "select * from 超额查询 WHERE 栋号='" + textBox1.Text + "' AND 房间号码 ='" + textBox2.Text + "'  AND  抄表日期  Between # " + dateTimePicker1.Value + "# And # " + dateTimePicker2.Value + "# ";
                OleDbDataReader dr = mydate.getDataReader(str);
                double  c = 0;
                while (dr.Read())
                {
                    c = c + Convert.ToDouble(dr["电超额度数"]);
                }
                dr1.Close();
                dr.Close();
                string k = "update 用电量表 set 栋号='" + textBox1.Text + "',房间号码='" + textBox2.Text + "',开始时间=# " + dateTimePicker1.Value + "#,结束时间=# " + dateTimePicker2.Value + "# ,用电总度数=" + s + ",超额用电总度数=" + c + "";
                mydate.updateSql(k);
                DataSet ds = mydate.getDataSet("select 栋号,房间号码,开始时间,结束时间,用电总度数,超额用电总度数 from 用电量表 where 栋号='" + textBox1.Text + "'and 房间号码='" + textBox2.Text + "'", "用电量表");
                dataGridView1.DataSource = ds;
                dataGridView1.DataMember = "用电量表";
            }

            catch
            {
                MessageBox.Show("该宿舍没有被初始化(请先初始化该宿舍)或还没有输入电,水表读数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -