📄 账户管理.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 + -