private void 确认充值_Click(object sender, EventArgs e)
{
try
{
string sql;
string connString = @"Server=LAPTOP-8DBAVB04;Database=keke;Trusted_Connection=Yes;";
SqlConnection myconn = new SqlConnection(connString);
myconn.Open();
SqlCommand mycomm = new SqlCommand();
mycomm.Connection = myconn;
sql = "insert into Recharge_record(userNo,boadminPwd,rechargeTime) values(@userNo,@boadminPwd,@rechargeTime)";
mycomm.CommandText = sql;
mycomm.Parameters.AddRange(
new SqlParameter[]
{
new SqlParameter("@userNo",SqlDbType.VarChar){Value=this.卡No.Text},
new SqlParameter("@boadminPwd",SqlDbType.Float){Value=this.money.Text},
new SqlParameter("@rechargeTime",SqlDbType.VarChar){Value=DateTime.Now.ToString("yyyy-MM-dd") },
});
int cnt;
cnt = mycomm.ExecuteNonQuery();
if (cnt > 0)
MessageBox.Show("充值成功!");
else
MessageBox.Show("充值失败!");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void 确认查询_Click(object sender, EventArgs e)
{
try
{
string sql;
string connString = @"Server=LAPTOP-8DBAVB04;Database=keke;Trusted_Connection=Yes;";
SqlConnection myconn = new SqlConnection(connString);
myconn.Open();
SqlCommand mycomm = new SqlCommand();
mycomm.Connection = myconn;
sql = "select * from Recharge_record where userNo like '%@userNo%'";
sql = sql.Replace("@userNo", 输入框_查询.Text.Trim());
mycomm.CommandText = sql;
SqlDataAdapter dr = new SqlDataAdapter(mycomm);
DataTable table = new DataTable();
dr.Fill(table);
this.查询框_充值记录.DataSource = table.DefaultView;
myconn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void 查询全部_Click(object sender, EventArgs e)
{
try
{
string sql;
string connString = @"Server=LAPTOP-8DBAVB04;Database=keke;Trusted_Connection=Yes;";
SqlConnection myconn = new SqlConnection(connString);
myconn.Open();
SqlCommand mycomm = new SqlCommand();
mycomm.Connection = myconn;
sql = "select userNo,boadminPwd,rechargeTime from Recharge_record";
mycomm.CommandText = sql;
SqlDataAdapter dr = new SqlDataAdapter(mycomm);
DataTable table = new DataTable();
dr.Fill(table);
this.查询框_充值记录.DataSource = table.DefaultView;
myconn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void 卡No_TextChanged(object sender, EventArgs e)
{
int count = 卡No.Text.Length;
if (count == 8)
{
try
{
int.Parse(卡No.Text);
}
catch
{
MessageBox.Show("只能输入数字!");
卡No.Text = null;
}
}
}
private void 充值金额_TextChanged(object sender, EventArgs e)
{
int imax = 200;
if(money.Text !=null && money.Text != "")
{
if (int.Parse(money.Text) > imax)
{
MessageBox.Show("充值金额不能大于200!");
money.Text = (0).ToString();
}
}
}