📄 机房管理.cs
字号:
this.groupBox3.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGrid4)).EndInit();
this.groupBox2.ResumeLayout(false);
this.groupBox1.ResumeLayout(false);
this.groupBox5.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void 机房管理_Load(object sender, System.EventArgs e)
{
this.sqlDataAdapter2.Fill(this.sds,"系统表");
this.dataGrid4.SetDataBinding(this.sds,"系统表");
this.dataGrid4.Refresh();
DataSet dsSysread=new DataSet();
this.sqlDataAdapter1.Fill(dsSysread,"系统表");
this.comboBox1.DataSource=dsSysread.Tables[0];
this.comboBox1.DisplayMember="机房";
this.comboBox1.ValueMember="定价";
//填充优惠信息
string sql="select * from 优惠表 order by ID";
SqlCommand cmdYh=new SqlCommand(sql,this.sqlConnection1);
this.sqlConnection1.Open();
try
{
SqlDataReader rdYh=cmdYh.ExecuteReader();
rdYh.Read();
this.textBox1.Text=rdYh.GetString(0);
this.textBox4.Text=rdYh.GetString(1);
rdYh.Read();
this.textBox2.Text=rdYh.GetString(0);
this.textBox6.Text=rdYh.GetString(1);
rdYh.Close();
}
catch(SqlException exe)
{
MessageBox.Show(exe.Message);
}
catch(SqlNullValueException exe)
{
}
finally
{
this.sqlConnection1.Close();
}
}
private void button7_Click(object sender, System.EventArgs e)
{
try
{
this.sqlDataAdapter2.Update(sds,"系统表");
MessageBox.Show("修改成功!","系统维护",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch(SqlException)
{
MessageBox.Show("修改无效,请检查输入!","系统维护",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
finally
{
//this.sqlConnection2.Close();
}
this.dataGrid4.Refresh();
}
private void button1_Click(object sender, System.EventArgs e)
{
try
{
string sql="update 优惠表 set 金额限='"+ this.textBox1.Text +"',优惠系数='"+ this.textBox4.Text +"' where ID=1";
this.sqlConnection1.Open();
SqlCommand cmdYh1=new SqlCommand(sql,this.sqlConnection1);
cmdYh1.ExecuteNonQuery();
this.sqlConnection1.Close();
sql="update 优惠表 set 金额限='"+ this.textBox2.Text +"',优惠系数='"+ this.textBox6.Text +"' where ID=2";
this.sqlConnection1.Open();
SqlCommand cmdYh2=new SqlCommand(sql,this.sqlConnection1);
cmdYh2.ExecuteNonQuery();
this.sqlConnection1.Close();
MessageBox.Show("修改成功!","优惠信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch(SqlException exe)
{
}
finally
{
}
}
public string Jtxj(DateTime dt,string StuBarcode)//下机操作,本程序中被集体下机按钮调用
{
DateTime timeXj=dt;
//DateTime timeSj;
String strPrice;
float floPrice;
strPrice=comboBox1.SelectedValue.ToString();
floPrice=float.Parse(strPrice);
String strMsg="%下机统计%";
String barCode=StuBarcode;
strMsg+=barCode+" ";
Decimal bal; //余额
Decimal cost;//花费
//读出帐户余额
String sql1="select 余额,姓名 from 帐户表 where 条形码='"+ barCode +"'";
SqlCommand cmd0=new SqlCommand(sql1,this.sqlConnection1);
this.sqlConnection1.Open();
SqlDataReader reader0=cmd0.ExecuteReader();
reader0.Read();
bal=(Decimal)reader0.GetSqlDecimal(0);
strMsg+=reader0.GetString(1);
reader0.Close();
this.sqlConnection1.Close();
//读出上机时间,计算时间差
sql1="select * from 流水帐表 where 条形码='"+ barCode +"' and 上机状态='1'";
SqlCommand cmd=new SqlCommand(sql1,this.sqlConnection1);
this.sqlConnection1.Open();
SqlDataReader reader1=cmd.ExecuteReader();
if(reader1.Read())
{
timeSj=reader1.GetDateTime(2);
}
reader1.Close();
this.sqlConnection1.Close();
TimeSpan ts=timeXj-timeSj;
//计算花费
float cost1=float.Parse(ts.Minutes.ToString())*floPrice/60+float.Parse(ts.Hours.ToString())*floPrice+float.Parse(ts.Days.ToString())*floPrice*24;
cost=(Decimal)cost1;
int intSjHour=ts.Days*24+ts.Hours;
//提示信息
strMsg+="上机"+intSjHour.ToString()+"小时"+ ts.Minutes.ToString() +"分钟,花费"+cost.ToString()+"元 ";
//计算余额
bal=bal-cost;
//更新流水帐表
sql1="update 流水帐表 set 下机时间='"+ timeXj.ToString() +"',花费='"+ cost.ToString() +"',上机状态='0' where 条形码='"+ barCode +"' and 上机状态='1'";
SqlCommand cmd1=new SqlCommand(sql1,this.sqlConnection1);
this.sqlConnection1.Open();
cmd1.ExecuteNonQuery();
this.sqlConnection1.Close();
//更新帐户表
sql1="update 帐户表 set 余额='"+ bal.ToString() +"'where 条形码='"+ barCode +"'";
SqlCommand cmd2=new SqlCommand(sql1,this.sqlConnection1);
this.sqlConnection1.Open();
cmd2.ExecuteNonQuery();
this.sqlConnection1.Close();
//余额不足者,锁定
if(bal<=0)
{
sql1="update 帐户表 set 锁定='1' where 条形码='"+ barCode +"'";
SqlCommand cmd3=new SqlCommand(sql1,this.sqlConnection1);
this.sqlConnection1.Open();
cmd3.ExecuteNonQuery();
this.sqlConnection1.Close();
strMsg+="余额不足,账户锁定!";
}
//提示信息框
//MessageBox.Show(strMsg,"下机",MessageBoxButtons.OK,MessageBoxIcon.Information);
return strMsg;
}
private void button5_Click(object sender, System.EventArgs e)
{
DialogResult result=MessageBox.Show("确定要全部下机吗?","集体下机",MessageBoxButtons.OKCancel,MessageBoxIcon.Question);
if(result==DialogResult.Cancel)
{
goto finish;
}
string strDateTime="";
strDateTime+=this.dateTimePicker1.Text+" ";
strDateTime+=this.textBox3.Text+":";
strDateTime+=this.textBox5.Text+":00";
//MessageBox.Show(strDateTime);
//string s=this.Jtxj(DateTime.Parse(strDateTime),"1");
//MessageBox.Show(s);
string strJtxjMsg="";
//打开上机流水表
string sqlJtxj="select 条形码 from 流水帐表 where 上机状态=1 and 上机区域='"+ this.comboBox1.Text +"'";
SqlCommand cmdJtxj=new SqlCommand(sqlJtxj,this.sqlConnection2);
this.sqlConnection2.Open();
SqlDataReader rdJtxj=cmdJtxj.ExecuteReader();
try
{
try
{
while(rdJtxj.Read())
{
//对每一条记录实施下机操作
DateTime dtNow=DateTime.Now;
string stuBarcode=rdJtxj.GetString(0);
strJtxjMsg+=this.Jtxj(DateTime.Parse(strDateTime),stuBarcode);
strJtxjMsg+="\n";
}
if(strJtxjMsg=="")
strJtxjMsg="机房已空!";
}
catch(SqlException exe)
{
MessageBox.Show("意外中断,请管理员处理!");
}
finally
{
//rdJtxj.Close();
//this.sqlConnection2.Close();
//MessageBox.Show(strJtxjMsg,"计费系统",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
catch(FormatException exe)
{
MessageBox.Show("请输入完整时间!");
}
finally
{
rdJtxj.Close();
this.sqlConnection2.Close();
if(strJtxjMsg!="")
MessageBox.Show(strJtxjMsg,"计费系统",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
finish:;
}
private void button2_Click(object sender, System.EventArgs e)
{
DialogResult result=MessageBox.Show("确定要系统归零吗?","系统重设",MessageBoxButtons.OKCancel,MessageBoxIcon.Question);
if(result==DialogResult.Cancel)
{
goto finish;
}
try
{
string sql="delete from 流水帐表";
this.sqlConnection1.Open();
SqlCommand cmdYh1=new SqlCommand(sql,this.sqlConnection1);
cmdYh1.ExecuteNonQuery();
this.sqlConnection1.Close();
sql="delete from 收费流水表";
this.sqlConnection1.Open();
SqlCommand cmdYh2=new SqlCommand(sql,this.sqlConnection1);
cmdYh2.ExecuteNonQuery();
this.sqlConnection1.Close();
MessageBox.Show("系统重设成功!收费记录、上机记录已被清空。","系统重设",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch(SqlException exe)
{
MessageBox.Show(exe.Message);
}
finally
{
this.sqlConnection1.Close();
}
finish:;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -