public void Listahozad(Feladat feladat, User user) //Újraírva { string queryString = "INSERT INTO FeladatTable VALUES(@FeladatCim, @FeladatLeiras, @FeladatDate) "; using (SqlConnection connection = new SqlConnection(connectionString)) using (SqlCommand command = new SqlCommand(queryString, connection)) { connection.Open(); command.Parameters.AddWithValue("@FeladatCim", feladat.Cim); command.Parameters.AddWithValue("@FeladatLeiras", feladat.Leiras); command.Parameters.AddWithValue("@FeladatDate", feladat.Datum); command.ExecuteNonQuery(); } string queryStringosszerendel = "DECLARE @FelId as int; " + "DECLARE @UserId as int; " + "SET @FelId = (SELECT FeladatTable.Id FROM FeladatTable WHERE FeladatTable.FeladatCim = @FeladatCim); " + "SET @UserId = (SELECT UserTable.Id FROM UserTable WHERE UserTable.UserName = @Username); " + "INSERT INTO FeladatKiosztasTable VALUES(@FelId, @UserId); "; using (SqlConnection connection = new SqlConnection(connectionString)) using (SqlCommand command = new SqlCommand(queryStringosszerendel, connection)) { connection.Open(); command.Parameters.AddWithValue("@FeladatCim", feladat.Cim); command.Parameters.AddWithValue("@Username", user.UserName); command.ExecuteNonQuery(); } }
public void Listahozad_old(Feladat feladat, User user) //RÉGI METODUS { string queryString = "INSERT INTO FeladatTable VALUES(@FeladatCim, @FeladatLeiras, @FeladatDate) "; //Feladat aktfeladat = new Feladat(TextBoxCim.,); using (SqlConnection connection = new SqlConnection(connectionString)) using (SqlCommand command = new SqlCommand(queryString, connection)) { connection.Open(); command.Parameters.AddWithValue("@FeladatCim", feladat.Cim); command.Parameters.AddWithValue("@FeladatLeiras", feladat.Leiras); command.Parameters.AddWithValue("@FeladatDate", feladat.Datum); command.ExecuteNonQuery(); } string queryString2 = "SELECT a.Id FROM UserTable a WHERE UserName=@user"; DataTable dt1 = new DataTable(); DataTable dt2 = new DataTable(); using (SqlConnection connection = new SqlConnection(connectionString)) using (SqlCommand command = new SqlCommand(queryString2, connection)) using (SqlDataAdapter adapter = new SqlDataAdapter(command)) { command.Parameters.AddWithValue("@user", user.UserName); adapter.Fill(dt1); } string queryString3 = "SELECT b.Id FROM FeladatTable b WHERE FeladatCim=@FeladatCim AND FeladatLeiras=@FeladatLeiras AND FeladatDate=@FeladatDate"; using (SqlConnection connection = new SqlConnection(connectionString)) using (SqlCommand command = new SqlCommand(queryString3, connection)) using (SqlDataAdapter adapter = new SqlDataAdapter(command)) { connection.Open(); command.Parameters.AddWithValue("@FeladatCim", feladat.Cim); command.Parameters.AddWithValue("@FeladatLeiras", feladat.Leiras); command.Parameters.AddWithValue("@FeladatDate", feladat.Datum); command.ExecuteNonQuery(); adapter.Fill(dt2); } int userTableId = dt1.Rows[0].Field <int>(0); int feladatTableId = dt2.Rows[0].Field <int>(0); string queryStringFeladatKiosztas = "INSERT INTO FeladatKiosztasTable VALUES(@FeladatId, @UserId) "; //Feladat aktfeladat = new Feladat(TextBoxCim.,); using (SqlConnection connection = new SqlConnection(connectionString)) using (SqlCommand command = new SqlCommand(queryStringFeladatKiosztas, connection)) { connection.Open(); command.Parameters.AddWithValue("@FeladatId", feladatTableId); command.Parameters.AddWithValue("@UserId", userTableId); command.ExecuteNonQuery(); } }
private void ButtonHozzaad_Click(object sender, RoutedEventArgs e) { string cim = TextBoxCim.Text; string leiras = TextBoxLeiras.Text; DateTime date = DatePicklerDatum.SelectedDate.Value; Feladat ujfeladat = new Feladat(cim, leiras, date); User selecteduser = new User(ListBoxTulajdonos.SelectedItem.ToString()); feladatRepository.Listahozad(ujfeladat, selecteduser); PopulateFeladatok(); PopulateCCB(); PopulateFeladatokCCBoxFa(); }