using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace InfoTrack { public partial class FormAddRecord : Form { DataBase dataBase = new DataBase(); public FormAddRecord() { InitializeComponent(); panelAddAlbum.Visible = false; panelAddGroup.Visible = false; panelAddTrack.Visible = false; panelAddMusician.Visible = false; switch(GlobalValues.nameOfOpenedTable) { case "Albums": panelAddAlbum.Visible = true; break; case "Groups": panelAddGroup.Visible = true; break; case "Tracks": panelAddTrack.Visible = true; break; case "Musicians": panelAddMusician.Visible = true; break; } } private void buttonAdd_Click(object sender, EventArgs e) { int index = GlobalValues.lastIndex; index++; dataBase.openConnection(); switch(GlobalValues.nameOfOpenedTable) { case "Albums": var NameAlbum = textBoxAddNameAlbum.Text; var CodeGroup = textBoxAddCodeGroup.Text; var DurAlbum = textBoxAddDurAlbum.Text; var Year = textBoxAddYear.Text; var TracksCount = textBoxAddTracksCount.Text; var addQuery = $"insert into Albums (Kod_Album, NameAlbum, Kod_Group, DurationAlbum, YearAlbum, TracksNumbers) values('{index}','{NameAlbum}','{CodeGroup}','{DurAlbum}','{Year}','{TracksCount}')"; var command = new SqlCommand(addQuery, dataBase.getConnection()); command.ExecuteNonQuery(); break; case "Groups": var NameGroup = textBoxAddNameGroup.Text; var YearCreation = textBoxAddYearCreation.Text; var DescriptionGroup = textBoxAddDiscription.Text; var Direction = textBoxAddDirection.Text; var addQuery2 = $"insert into Groups (Kod_Group, NameGroup, YearCreation, DescriptionGroup, Direction) values('{index}','{NameGroup}','{YearCreation}','{DescriptionGroup}','{Direction}')"; var command2 = new SqlCommand(addQuery2, dataBase.getConnection()); command2.ExecuteNonQuery(); break; case "Tracks": var NameTrack = textBoxAddTrackName.Text; var Kod_Album = textBoxAddCodeAlbum_t.Text; var Kod_Group = textBoxAddCodeGroup_t.Text; var TrackDurationTrack = textBoxAddTimeTrack.Text; var addQuery3 = $"insert into Tracks (Kod_Track, NameTrack, Kod_Album, Kod_Group, TrackDurationTrack) values('{index}','{NameTrack}','{Kod_Album}','{Kod_Group}','{TrackDurationTrack}')"; var command3 = new SqlCommand(addQuery3, dataBase.getConnection()); command3.ExecuteNonQuery(); break; case "Musicians": var Kod_Group_m = textBoxAddCodeGroup_m.Text; var NameMusician = textBoxAddNameMus.Text; var Role = textBoxAddRole.Text; var Birthday = textBoxAddbday.Text; var addQuery4 = $"insert into Musicians (Kod_Musician, Kod_Group, NameMusician, Role, Birthday) values('{index}','{Kod_Group_m}','{NameMusician}','{Role}','{Birthday}')"; var command4 = new SqlCommand(addQuery4, dataBase.getConnection()); command4.ExecuteNonQuery(); break; } dataBase.closeConnection(); MessageBox.Show("Запись успешно добавлена!"); } private void buttonBack_Click(object sender, EventArgs e) { this.Hide(); FormMenu form = new FormMenu(); form.Show(); } } }