一、新建,和删除文件夹
private void button4_Click(object sender, EventArgs e)
{
Directory.Delete(@"F:\", true); //删除文件,true直接格式化
MessageBox.Show("格式化成功!");
}
private void button5_Click(object sender, EventArgs e)
{
for (int i = ; i >=; i--)
{
Directory.CreateDirectory(@"D:\第"+i+"个"); //新建文件夹
}
MessageBox.Show("创建成功!");
}
二、注册,登陆
private void btnchuce_Click(object sender, EventArgs e)
{
int zhanghao = int.Parse(textzhanghao.Text); //也就是要判断两次输入的密码是否一致,一致则允许注册
string mima = this.textmima.Text;
string sql = string.Format("insert into sut select {0},'{1}'", zhanghao, mima);
int i = dahsql.ZCG(sql);
if (i > )
{
MessageBox.Show("注册成功!");
}
}
private void btndenglu_Click(object sender, EventArgs e)
{
DataTable a = new DataTable(); //创建一张新表,用来接收数据库查到的表
int zhanghao = int.Parse(textzhanghao.Text);
string mima = this.textmima.Text;
//将用户名和密码传到数据库里查询,查得到就说明登陆成功了
string sql = string.Format("select * from sut where id={0} and mima={1}", zhanghao, mima);
a=dahsql.CHA(sql); //查到的表
if (a.Rows.Count>0) //rows.cout 表示查到的表有几行
{
MessageBox.Show("登录成功!");
}
else
{
MessageBox.Show("您输入的帐号或密码不正确!");
}
}
三、Textbot框中只能输入数字
/// 数量和价格框中只能输入数字
/// 价格可以输入小数点,而数量不能输入
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
byte[] arry = System.Text.Encoding.Default.GetBytes(e.KeyChar.ToString());
if (!char.IsDigit(e.KeyChar) || arry.LongLength == ) e.Handled = true;
if (e.KeyChar == '\b' || e.KeyChar == '.') e.Handled = false;
}
四、从dataGridView表中,点击取值
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
int i = e.RowIndex; //获取鼠标点击时的行数
DataGridViewRow row=this.dataGridView1.Rows[i]; //将row赋值为点击的行数,便于后面的取值
this.textBox1.Text = row.Cells[].Value.ToString(); //Cells[0]为列,从确定坐标位置
this.textBox2.Text = row.Cells[].Value.ToString(); //Cells[0]也可写成Cells["字段名"]
this.textBox3.Text = row.Cells[].Value.ToString();
this.textBox4.Text = row.Cells[].Value.ToString();
this.dateTimePicker1.Text = row.Cells[].Value.ToString();
int id = int.Parse(this.textBox1.Text);
}