📄 frmritongji.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
namespace 机房计费系统
{
/// <summary>
/// frmritongji 的摘要说明。
/// </summary>
public class frmritongji : System.Windows.Forms.Form
{
private String sql6;
private String sql7;
private String sql9;
private string str_teacher;
private string str_starttime;
private string str_endtime;
private String str_rishi;
private String str_rizhi;
private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
private System.Data.SqlClient.SqlCommand sqlInsertCommand1;
private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
private System.Data.SqlClient.SqlConnection sqlConnection1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.DateTimePicker dateTimePicker1;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label17;
private System.Windows.Forms.TextBox textBox8;
private System.Windows.Forms.Label label15;
private System.Windows.Forms.DateTimePicker dateTimePicker2;
private System.Windows.Forms.Label label13;
private System.Windows.Forms.TextBox textBox5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Label label7;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public frmritongji()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
this.label5 = new System.Windows.Forms.Label();
this.label17 = new System.Windows.Forms.Label();
this.textBox8 = new System.Windows.Forms.TextBox();
this.label15 = new System.Windows.Forms.Label();
this.dateTimePicker2 = new System.Windows.Forms.DateTimePicker();
this.label13 = new System.Windows.Forms.Label();
this.textBox5 = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.textBox3 = new System.Windows.Forms.TextBox();
this.label7 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "操作员表", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("姓名", "姓名")})});
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO 操作员表(姓名) VALUES (@姓名); SELECT 姓名 FROM 操作员表";
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@姓名", System.Data.SqlDbType.VarChar, 50, "姓名"));
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT 姓名 FROM 操作员表";
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=\"TJPU-A7P821CK8J\";packet size=4096;integrated security=SSPI;data s" +
"ource=\"(local)\";persist security info=False;initial catalog=jifei";
//
// label1
//
this.label1.Font = new System.Drawing.Font("宋体", 12F);
this.label1.Location = new System.Drawing.Point(24, 160);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(248, 24);
this.label1.TabIndex = 0;
this.label1.Text = "该段时间515上机共消费:";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(280, 160);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(184, 25);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "textBox1";
//
// label2
//
this.label2.Font = new System.Drawing.Font("宋体", 12F);
this.label2.Location = new System.Drawing.Point(480, 160);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(88, 24);
this.label2.TabIndex = 2;
this.label2.Text = "元";
//
// label3
//
this.label3.Font = new System.Drawing.Font("宋体", 12F);
this.label3.Location = new System.Drawing.Point(112, 344);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(176, 32);
this.label3.TabIndex = 3;
this.label3.Text = "目前库存余额为:";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(288, 344);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(184, 25);
this.textBox2.TabIndex = 4;
this.textBox2.Text = "textBox2";
//
// label4
//
this.label4.Font = new System.Drawing.Font("宋体", 12F);
this.label4.Location = new System.Drawing.Point(488, 344);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(96, 32);
this.label4.TabIndex = 5;
this.label4.Text = "元";
//
// button1
//
this.button1.Font = new System.Drawing.Font("宋体", 12F);
this.button1.Location = new System.Drawing.Point(624, 136);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(104, 32);
this.button1.TabIndex = 6;
this.button1.Text = "统计";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// dateTimePicker1
//
this.dateTimePicker1.Location = new System.Drawing.Point(208, 88);
this.dateTimePicker1.Name = "dateTimePicker1";
this.dateTimePicker1.Size = new System.Drawing.Size(152, 25);
this.dateTimePicker1.TabIndex = 7;
//
// label5
//
this.label5.Font = new System.Drawing.Font("宋体", 12F);
this.label5.Location = new System.Drawing.Point(24, 88);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(184, 32);
this.label5.TabIndex = 8;
this.label5.Text = "请输入日期及时间:";
//
// label17
//
this.label17.Font = new System.Drawing.Font("宋体", 12F);
this.label17.Location = new System.Drawing.Point(688, 88);
this.label17.Name = "label17";
this.label17.Size = new System.Drawing.Size(24, 24);
this.label17.TabIndex = 15;
this.label17.Text = "时";
//
// textBox8
//
this.textBox8.Location = new System.Drawing.Point(640, 88);
this.textBox8.Name = "textBox8";
this.textBox8.Size = new System.Drawing.Size(40, 25);
this.textBox8.TabIndex = 14;
this.textBox8.Text = "23";
//
// label15
//
this.label15.Font = new System.Drawing.Font("宋体", 12F);
this.label15.Location = new System.Drawing.Point(440, 88);
this.label15.Name = "label15";
this.label15.Size = new System.Drawing.Size(32, 24);
this.label15.TabIndex = 13;
this.label15.Text = "到";
//
// dateTimePicker2
//
this.dateTimePicker2.Location = new System.Drawing.Point(480, 88);
this.dateTimePicker2.Name = "dateTimePicker2";
this.dateTimePicker2.Size = new System.Drawing.Size(152, 25);
this.dateTimePicker2.TabIndex = 12;
//
// label13
//
this.label13.Font = new System.Drawing.Font("宋体", 12F);
this.label13.Location = new System.Drawing.Point(416, 88);
this.label13.Name = "label13";
this.label13.Size = new System.Drawing.Size(48, 24);
this.label13.TabIndex = 11;
this.label13.Text = "时";
//
// textBox5
//
this.textBox5.Location = new System.Drawing.Point(368, 88);
this.textBox5.Name = "textBox5";
this.textBox5.Size = new System.Drawing.Size(40, 25);
this.textBox5.TabIndex = 10;
this.textBox5.Text = "7";
//
// label6
//
this.label6.Font = new System.Drawing.Font("宋体", 12F);
this.label6.Location = new System.Drawing.Point(24, 224);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(248, 24);
this.label6.TabIndex = 16;
this.label6.Text = "该段时间615上机共消费:";
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(280, 224);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(184, 25);
this.textBox3.TabIndex = 17;
this.textBox3.Text = "textBox3";
//
// label7
//
this.label7.Font = new System.Drawing.Font("宋体", 12F);
this.label7.Location = new System.Drawing.Point(480, 224);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(88, 24);
this.label7.TabIndex = 18;
this.label7.Text = "元";
//
// frmritongji
//
this.AutoScaleBaseSize = new System.Drawing.Size(8, 18);
this.ClientSize = new System.Drawing.Size(792, 544);
this.Controls.Add(this.label7);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.label6);
this.Controls.Add(this.label17);
this.Controls.Add(this.textBox8);
this.Controls.Add(this.label15);
this.Controls.Add(this.dateTimePicker2);
this.Controls.Add(this.label13);
this.Controls.Add(this.textBox5);
this.Controls.Add(this.label5);
this.Controls.Add(this.dateTimePicker1);
this.Controls.Add(this.button1);
this.Controls.Add(this.label4);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "frmritongji";
this.Text = "日统计信息";
this.Load += new System.EventHandler(this.frmritongji_Load);
this.ResumeLayout(false);
}
#endregion
private void button1_Click(object sender, System.EventArgs e)
{
str_rishi=this.textBox5.Text;
str_rizhi=this.textBox8.Text;
str_starttime=dateTimePicker1.Text +" "+ str_rishi + ":00:00 ";
str_endtime=dateTimePicker2.Text +" "+ str_rizhi + ":00:00 ";
sql6="select sum(花费) from 流水帐表 where 上机区域='515' and 上机时间 >'" + str_starttime + "' and 下机时间 <'" + str_endtime + "' ";
SqlCommand cmd6=new SqlCommand(sql6,this.sqlConnection1);
this.sqlConnection1.Open();
SqlDataReader reader6=cmd6.ExecuteReader();
try
{
if(reader6.Read())
{
this.textBox1.Text=reader6.GetSqlDecimal(0).ToString();
}
else
{
reader6.Close();
this.sqlConnection1.Close();
goto Finish;
}
}
catch(SqlNullValueException exe)
{
reader6.Close();
this.sqlConnection1.Close();
textBox1.Text="0";
goto Finish;
}
catch(SqlException exe)
{
MessageBox.Show("您输入的数据有误1,请重新输入!");
reader6.Close();
this.sqlConnection1.Close();
goto Finish;
}
finally
{
reader6.Close();
this.sqlConnection1.Close();
}
sql9="select sum(花费) from 流水帐表 where 上机时间 >'" + str_starttime + "' and 下机时间 <'" + str_endtime + "' and 上机区域='615'";
SqlCommand cmd9=new SqlCommand(sql9,this.sqlConnection1);
this.sqlConnection1.Open();
SqlDataReader reader9=cmd9.ExecuteReader();
try
{
if(reader9.Read())
{
this.textBox3.Text=reader9.GetSqlDecimal(0).ToString();
}
else
{
reader9.Close();
this.sqlConnection1.Close();
goto Finish;
}
}
catch(SqlNullValueException exe)
{
reader9.Close();
this.sqlConnection1.Close();
textBox3.Text="0";
goto Finish;
}
catch(SqlException exe)
{
MessageBox.Show("您输入的数据有误2,请重新输入!");
reader9.Close();
this.sqlConnection1.Close();
goto Finish;
}
finally
{
reader9.Close();
this.sqlConnection1.Close();
}
sql7="select sum(余额) from 帐户表 ";
SqlCommand cmd7=new SqlCommand(sql7,this.sqlConnection1);
this.sqlConnection1.Open();
SqlDataReader reader7=cmd7.ExecuteReader();
try
{
if(reader7.Read())
{
this.textBox2.Text=reader7.GetSqlDecimal(0).ToString();
}
else
{
reader7.Close();
this.sqlConnection1.Close();
goto Finish;
}
}
catch(SqlNullValueException exe)
{
reader7.Close();
this.sqlConnection1.Close();
textBox2.Text="0";
goto Finish;
}
catch(SqlException exe)
{
MessageBox.Show("您输入的数据有误3,请重新输入!");
reader7.Close();
this.sqlConnection1.Close();
goto Finish;
}
finally
{
reader7.Close();
this.sqlConnection1.Close();
}
Finish:;
}
private void frmritongji_Load(object sender, System.EventArgs e)
{
dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = "yyyy-MM-dd";
dateTimePicker2.Format = DateTimePickerFormat.Custom;
dateTimePicker2.CustomFormat = "yyyy-MM-dd";
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -