private void saveBTN_Click(object sender, EventArgs e) { //sprawdzamy czy klient został wybrany if (klientTXT.Text == "") { var result = MessageBox.Show("Przed zapisem musisz wybrać klient!"); if (result == DialogResult.OK) { formsy.klients form = new formsy.klients(this); form.Show(); } } else { //zapis do bazy danych var MyIni = new INIFile("WektorSettings.ini"); server = MyIni.Read("server", "Okna"); database = MyIni.Read("database", "Okna"); uid = MyIni.Read("login", "Okna"); password = Decrypt(MyIni.Read("pass", "Okna")); string MyConnectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD="******";"; MySqlConnection connection = new MySqlConnection(MyConnectionString); foreach (DataGridViewRow row in metroGrid1.Rows) { try { int id_user = Convert.ToInt32(userID.Text); string klient = Form1.logged.Text; int nr = Convert.ToInt32(numberBAZA.Text); int numer = nr + 1; string str = numer.ToString(); MySqlCommand cmd = new MySqlCommand(); cmd = connection.CreateCommand(); if (row.IsNewRow) { continue; } cmd.Parameters.AddWithValue("@id", numerek.Text); cmd.Parameters.AddWithValue("@indeks", row.Cells[0].Value); cmd.Parameters.AddWithValue("@rabat", row.Cells[3].Value.ToString().Replace("%", "").Replace(",", ".")); cmd.Parameters.AddWithValue("@ilosc", row.Cells[5].Value); cmd.Parameters.AddWithValue("@cena", row.Cells[4].Value.ToString().Replace("zł", "").Replace(",", ".")); cmd.Parameters.AddWithValue("@data", DateTime.Now); cmd.Parameters.AddWithValue("@kwota", sumaTXT.Text.Replace("zł", "").Replace(",", ".")); cmd.CommandText = $"INSERT IGNORE INTO wyceny (nrw,user_id,wycena_user,numer,klient,kwota,data) VALUES (@id,'{id_user}','{nr}','{wycena_nr.Text}',(SELECT id FROM klienci WHERE nazwa = '{klientTXT.Text}'),@kwota,@data); " + $"INSERT INTO wyceny_detail (id,user_id,wycena_user,id_product,id_klient,rabat,ilosc,cena) VALUES (@id,'{id_user}','{nr}',(SELECT id FROM cenniki WHERE reference = @indeks),(SELECT id FROM klienci WHERE nazwa ='{klientTXT.Text}'),@rabat,@ilosc,@cena);" + $"UPDATE uzytkownicy SET wycena = '{str}' WHERE username = '******';"; connection.Open(); cmd.ExecuteNonQuery(); connection.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } var result = MessageBox.Show("Wycena została zapisana pod numerem " + wycena_nr.Text); if (result == DialogResult.OK) { Close(); } } }
private void userBTN_Click(object sender, EventArgs e) { formsy.klients form = new formsy.klients(this); form.Show(); }