private void B_unsub_sub_Click(object sender, RoutedEventArgs e) { try { GroupList group = dg_grunlist.SelectedItem as GroupList; string sql = "INSERT INTO \"customer-customer_group\"(id_group, id_customer) VALUES(" + group.id + ", " + user_id + ");"; NpgsqlCommand comm = new NpgsqlCommand(sql, conn); conn.Open(); comm.ExecuteNonQuery(); conn.Close(); UpdateSubTable(); UpdateUnsubTable(); } catch (NpgsqlException ex) { MessageBox.Show(ex.Message, "Ошибка на сервере", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); } finally { conn.Close(); } }
public Group_win(Main_win super, GroupList group) { InitializeComponent(); this.super = super; this.group = group; Title = "Тренер: " + group.trainer; NpgsqlCommand comm = new NpgsqlCommand("select * from customer_group where id = " + group.id, super.conn); try { super.conn.Open(); NpgsqlDataReader reader = comm.ExecuteReader(); reader.Read(); var timestamps = (TimeSpan[])reader.GetValue(5); week = (bool[])reader.GetValue(6); for (int i = 0; i < timestamps.Length; i++) { if (week[i]) { timetable[i] = timestamps[i].Hours.ToString() + ":" + (timestamps[i].Minutes.ToString().Length == 1 ? "0" + timestamps[i].Minutes.ToString() : timestamps[i].Minutes.ToString()); } } int min_age_db; int max_age_db; try { min_age_db = reader.GetInt32(3); } catch { min_age_db = 0; } try { max_age_db = reader.GetInt32(4); } catch { max_age_db = 0; } num_cost.Text = reader.GetInt32(2).ToString(); num_minage.Text = min_age_db.ToString(); num_maxage.Text = max_age_db.ToString(); cb_minage.IsChecked = !num_minage.Text.Equals("0"); cb_maxage.IsChecked = !num_maxage.Text.Equals("0"); super.conn.Close(); comm.CommandText = "select exercise.id, exercise.name " + "from exercise, \"customer_group-exercise\" " + "where \"customer_group-exercise\".id_exercise = exercise.id and \"customer_group-exercise\".id_group = " + group.id; super.conn.Open(); reader = comm.ExecuteReader(); for (int i = 0; reader.Read(); i++) { exerciseList.Add(new ExerciseList(reader.GetInt32(0), reader.GetString(1))); } super.conn.Close(); UpdateList(); cb_mon.IsChecked = week[0]; cb_tue.IsChecked = week[1]; cb_wed.IsChecked = week[2]; cb_thu.IsChecked = week[3]; cb_fri.IsChecked = week[4]; cb_sat.IsChecked = week[5]; cb_sun.IsChecked = week[6]; tp_mon.Text = timetable[0]; tp_tue.Text = timetable[1]; tp_wed.Text = timetable[2]; tp_thu.Text = timetable[3]; tp_fri.Text = timetable[4]; tp_sat.Text = timetable[5]; tp_sun.Text = timetable[6]; } catch (NpgsqlException ex) { MessageBox.Show(ex.Message, "Ошибка на сервере", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); } finally { super.conn.Close(); } }