private void button_LOGIN_Click(object sender, EventArgs e) { MY_DB db = new MY_DB(); SqlDataAdapter da = new SqlDataAdapter(); DataTable dt = new DataTable(); SqlCommand cmd = new SqlCommand("select * from LOGIN", db.getConnection); da.SelectCommand = cmd; da.Fill(dt); int count = dt.Rows.Count; if (count > 0) { for (int i = 0; i < count; i++) { if (txtUsername.Text == dt.Rows[i]["username"].ToString().Trim() && txtPassword.Text == dt.Rows[i]["password"].ToString().Trim()) { this.DialogResult = DialogResult.OK; } } if (this.DialogResult != DialogResult.OK) { MessageBox.Show("Invalid Username or Password", "Login error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void ButtonRegister_Click(object sender, EventArgs e) { if (chkAdmin.Checked == true) { MY_DB db = new MY_DB(); SqlCommand cmm = new SqlCommand("select * from LOGIN", db.getConnection); SqlDataAdapter da = new SqlDataAdapter(); DataTable dt = new DataTable(); da.SelectCommand = cmm; da.Fill(dt); int countRow = dt.Rows.Count; SqlCommand cmd = new SqlCommand("insert into Login (id, username, password)" + " values (@id, @user, @pass)", db.getConnection); cmd.Parameters.Add("@id", SqlDbType.Int).Value = countRow; cmd.Parameters.Add("@user", SqlDbType.VarChar).Value = txtUsername.Text; cmd.Parameters.Add("@pass", SqlDbType.VarChar).Value = txtPassword.Text; db.openConnection(); if (cmd.ExecuteNonQuery() == 1) { db.closeConnection(); } else { db.closeConnection(); } da.InsertCommand = cmd; da.Update(dt); MessageBox.Show("Sign up successful", "Adding...", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void BaiXeForm_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'dataSetBaiXe.BAIXE' table. You can move, or remove it, as needed. this.bAIXETableAdapter.Fill(this.dataSetBaiXe.BAIXE); MY_DB db = new MY_DB(); //SqlDataAdapter da = new SqlDataAdapter(); //DataTable dt = new DataTable(); SqlCommand cmd = new SqlCommand("select * from BAIXE", db.getConnection); //da.SelectCommand = cmd; //da.Fill(dt); //for (int i = 0; i < 20; i++) //{ // for (int j = 0; j < 10; j++) // { // if (Convert.ToInt32(dt.Rows[i][j]) == 0) // dgvBaiXe.Rows[i].Cells[j].Value = false; // else dgvBaiXe.Rows[i].Cells[j].Value = true; // } //} }