private void button1_Click(object sender, EventArgs e) { if (txt_UserName.Text == "" || txt_Password.Text == "") { MessageBox.Show("Wpisz nazwę użytkownia i hasło"); return; } try { //Create SqlConnection SqlConnection con = new SqlConnection(cs); SqlCommand cmd = new SqlCommand("Select * from login where UserName=@username and Password=@password", con); cmd.Parameters.AddWithValue("@username", txt_UserName.Text); cmd.Parameters.AddWithValue("@password", txt_Password.Text); con.Open(); SqlDataAdapter adapt = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); adapt.Fill(ds); con.Close(); int count = ds.Tables[0].Rows.Count; if (count == 1) { MessageBox.Show("Logowanie się powiodło!"); int id = Convert.ToInt32(ds.Tables[0].Rows[0]["id"]); Boolean mod = Convert.ToBoolean(ds.Tables[0].Rows[0]["modpermission"]); String name = Convert.ToString(ds.Tables[0].Rows[0]["username"]); User user = new User(name, mod, id); this.Hide(); if (!Convert.ToBoolean(ds.Tables[0].Rows[0]["modpermission"])) { MainUserPage fm = new MainUserPage(); fm.user = user; fm.Show(); } if (Convert.ToBoolean(ds.Tables[0].Rows[0]["modpermission"])) { ManagerPage fm = new ManagerPage(); fm.user = user; fm.Show(); } } else { MessageBox.Show("Logowanie nieudane!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void yesbtn_Click(object sender, EventArgs e) { using (SqlConnection con = new SqlConnection(cs)) { con.Open(); int car_id = Convert.ToInt32(cartobuygrid.Rows[0].Cells["id"].Value); int value = Convert.ToInt32(cartobuygrid.Rows[0].Cells["price"].Value); DateTime date = DateTime.Today; SqlCommand cmd = new SqlCommand("INSERT INTO [transaction] (client_id, car_id, date, value, accepted) VALUES (@client_id, @car_id, @date, @value, 1)", con); cmd.Parameters.AddWithValue("@client_id", user.id); cmd.Parameters.AddWithValue("@car_id", car_id); cmd.Parameters.AddWithValue("@value", value); cmd.Parameters.AddWithValue("@date", date.ToString("d")); try { cmd.ExecuteNonQuery(); MessageBox.Show("Zakup przebiegł pomyślnie!"); } catch (Exception ex) { MessageBox.Show("Zakup się nie powiódł!"); MessageBox.Show(ex.Message); } //SqlCommand cmds = new SqlCommand("DELETE FROM car WHERE id = CONVERT(int, @car_id)", con); SqlCommand cmds = new SqlCommand("UPDATE car SET available = 0 WHERE id = @car_id;", con); cmds.Parameters.AddWithValue("@car_id", car_id); try { cmds.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } if (user.mod == true) { ManagerPage menu = new ManagerPage(); menu.user = user; menu.Show(); this.Close(); } if (user.mod == false) { MainUserPage menu = new MainUserPage(); menu.user = user; menu.Show(); this.Close(); } } }
private void backtbn_Click(object sender, EventArgs e) { if (user.mod == true) { ManagerPage menu = new ManagerPage(); menu.user = user; menu.Show(); this.Close(); } if (user.mod == false) { MainUserPage menu = new MainUserPage(); menu.user = user; menu.Show(); this.Close(); } }
private void backbtn_Click(object sender, EventArgs e) { clientgrid.CancelEdit(); if (user.mod == true) { ManagerPage menu = new ManagerPage(); menu.user = user; menu.Show(); this.Close(); } if (user.mod == false) { MainUserPage menu = new MainUserPage(); menu.user = user; menu.Show(); this.Close(); } }