?? 賬戶管理.cs
字號:
else
{
sql="select * from 帳戶表 where 姓名='"+ this.textBox2.Text +"'";
}
this.sqlDataAdapter1.SelectCommand.CommandText=sql;
sds.Tables["帳戶表"].Clear();
this.sqlDataAdapter1.Fill(sds,"帳戶表");
this.dataGrid1.SetDataBinding(sds,"帳戶表");
this.dataGrid1.Refresh();
}
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar==(char)13)
{
sds.Tables["帳戶表"].Clear();
sql="select * from 帳戶表 where 條形碼='"+ this.textBox1.Text +"'";
this.sqlDataAdapter1.SelectCommand.CommandText=sql;
//DataSet sds=new DataSet();
this.sqlDataAdapter1.Fill(sds,"帳戶表");
this.dataGrid1.SetDataBinding(sds,"帳戶表");
this.dataGrid1.Refresh();
}
}
private void button2_Click(object sender, System.EventArgs e)
{
int i=this.dataGrid1.CurrentRowIndex;
MessageBox.Show(i.ToString());
try
{
this.sqlDataAdapter1.Update(sds,"帳戶表");
MessageBox.Show("修改成功!","系統維護",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch(SqlException)
{
MessageBox.Show("修改無效,請檢查輸入!","系統維護",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
finally
{
//this.sqlConnection2.Close();
}
this.dataGrid1.Refresh();
}
private void button4_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.dataGrid2.Refresh();
}
private void button3_Click(object sender, System.EventArgs e)
{
sds.Tables["流水帳表"].Clear();
sql="select * from 流水帳表 where 上機狀態='1'";
this.sqlDataAdapter2.SelectCommand.CommandText=sql;
this.sqlDataAdapter2.Fill(sds,"流水帳表");
this.dataGrid2.SetDataBinding(sds,"流水帳表");
this.dataGrid2.Refresh();
}
private void button11_Click(object sender, System.EventArgs e)
{
sds.Tables["流水帳表"].Clear();
sql="select * from 流水帳表";
this.sqlDataAdapter2.SelectCommand.CommandText=sql;
this.sqlDataAdapter2.Fill(sds,"流水帳表");
this.dataGrid2.SetDataBinding(sds,"流水帳表");
this.dataGrid2.Refresh();
}
private void button5_Click(object sender, System.EventArgs e)
{
sql="select * from 流水帳表 where 條形碼='"+ this.textBox3.Text +"'";
this.sqlDataAdapter2.SelectCommand.CommandText=sql;
sds.Tables["流水帳表"].Clear();
this.sqlDataAdapter2.Fill(sds,"流水帳表");
this.dataGrid2.SetDataBinding(sds,"流水帳表");
this.dataGrid2.Refresh();
}
private void textBox3_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar==(char)13)
{
sql="select * from 流水帳表 where 條形碼='"+ this.textBox3.Text +"'";
this.sqlDataAdapter2.SelectCommand.CommandText=sql;
sds.Tables["流水帳表"].Clear();
this.sqlDataAdapter2.Fill(sds,"流水帳表");
this.dataGrid2.SetDataBinding(sds,"流水帳表");
this.dataGrid2.Refresh();
}
}
private void dateTimePicker1_ValueChanged(object sender, System.EventArgs e)
{
sds.Tables["收費明細表"].Clear();
string sql="SELECT 收費流水表.ID, 帳戶表.姓名, 帳戶表.班級, 收費流水表.時間, 收費流水表.條形碼, 收費流水表.值班教師, 收費流水表.收費, 收費流水表.充值, 帳戶表.余額 FROM 收費流水表 INNER JOIN 帳戶表 ON 收費流水表.條形碼 = 帳戶表.條形碼 and 收費流水表.時間>'"+ this.dateTimePicker1.Value.Date.ToString() +"' and 收費流水表.時間<'"+ this.dateTimePicker1.Value.Date.AddDays(1).Date.ToString() +"' and 值班教師='"+ frmMain.strTeacher +"'";
this.sqlDataAdapter3.SelectCommand.CommandText=sql;
this.sqlDataAdapter3.Fill(this.sds,"收費明細表");
this.dataGrid3.SetDataBinding(this.sds,"收費明細表");
this.dataGrid3.Refresh();
}
private void textBox5_Enter(object sender, System.EventArgs e)
{
}
private void textBox4_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
string strCode=this.textBox4.Text;
this.strCodeOld=strCode;
decimal balance;
if(e.KeyChar == (char)13)
{
if(!this.sjzt())
{
sql="select * from 帳戶表 where 條形碼='"+ strCode +"'";
SqlCommand cmd=new SqlCommand(sql,this.sqlConnection1);
this.sqlConnection1.Open();
SqlDataReader reader=cmd.ExecuteReader();
try
{
if(reader.Read())
{
this.richTextBox1.Text=reader.GetString(1);
this.richTextBox1.Text+="\n";
this.richTextBox1.Text+=reader.GetString(2)+"\n";
balance=(Decimal)reader.GetSqlDecimal(3);
this.richTextBox1.Text+=balance.ToString();
this.textBox5.Focus();
this.button6.Enabled=true;
}
else
{
reader.Close();
this.sqlConnection1.Close();
MessageBox.Show("無此用戶!","轉賬",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox4.Clear();
this.richTextBox1.Clear();
}
}
catch(SqlException exe)
{
MessageBox.Show("數據庫出現錯誤!","轉賬",MessageBoxButtons.OK,MessageBoxIcon.Error);
reader.Close();
this.sqlConnection1.Close();
this.textBox4.Clear();
this.richTextBox1.Clear();
}
finally
{
reader.Close();
this.sqlConnection1.Close();
}
}
else
{
MessageBox.Show("此用戶正在上機,不能轉賬!","轉賬",MessageBoxButtons.OK,MessageBoxIcon.Error);
this.textBox4.Clear();
this.textBox4.Focus();
}
}
}
private void button6_Click(object sender, System.EventArgs e)
{
if(this.textBox5.Text.Length!=0)
{
string strSql="update 帳戶表 set 條形碼='"+ this.textBox5.Text +"'where 條形碼='"+ this.strCodeOld +"'";
SqlCommand cmdZZ=new SqlCommand(strSql,this.sqlConnection1);
this.sqlConnection1.Open();
try
{
cmdZZ.ExecuteNonQuery();
MessageBox.Show("修改成功!\n新賬戶標識為"+this.textBox5.Text,"轉賬",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch(SqlException exe)
{
MessageBox.Show("數據庫出現錯誤,轉賬不成功!","轉賬",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
finally
{
this.sqlConnection1.Close();
this.textBox4.Clear();
this.textBox5.Clear();
this.richTextBox1.Clear();
}
}
else
{
MessageBox.Show("請輸入完整條形碼!","轉賬",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox5.Focus();
}
}
private bool sjzt()
{
//返回上機人的狀態
bool m;
String sql1="select * from 流水帳表 where 條形碼='"+ this.textBox4.Text +"' and 上機狀態='1'";
SqlCommand cmd=new SqlCommand(sql1,this.sqlConnection1);
this.sqlConnection1.Open();
SqlDataReader reader1=cmd.ExecuteReader();
m=reader1.Read();
reader1.Close();
this.sqlConnection1.Close();
if(m)
{
return true;
}
else
{
return false;
}
}
private void dataGrid2_Navigate(object sender, System.Windows.Forms.NavigateEventArgs ne)
{
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -