?? 機房管理.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 + -