private void Button2_Click(object sender, EventArgs e) { if (ValidateController.validateItem(labelIDCity.Text)) { sqlConnection = new SqlConnection(con); commandString = $@"DELETE FROM [dbo].[City] WHERE IdCity = '{labelIDCity.Text}'" ; try { sqlConnection.Open(); } catch (Exception) { MessageBox.Show("Не удалось подключиться"); } command = new SqlCommand(commandString, sqlConnection); command.ExecuteNonQuery(); this.cityTableAdapter.Fill(this.phoneCallDataSet19.City); labelIDCity.Text = ""; ValidateController.CleanerTextBox(textBoxCity); ValidateController.CleanerNumeric(numericDiscount, numericRateDay, numericRateNight); } else { MessageBox.Show("Выберите строку для удаления"); } }
private void Button1_Click(object sender, EventArgs e) { conversationModel = new ConversationModel( comboBoxIdCity.Text, comboBoxIdSubscriber.Text, textBoxMinute.Value, comboBoxRDay.Text, comboBoxRDay.Text ); if (conversationModel.validate(errorCity, errorSubscribe, errorMinute)) { commandString = $@" INSERT INTO [dbo].[Conversation] ([IdSubScriber] ,[IdCity] ,[Date] ,[CountMinutes] ,[TimesOfDay] ,[PriceConverstation]) VALUES ( '{conversationModel.IDSubscriber}', '{conversationModel.IDCity}', '{conversationModel.date.ToShortDateString()}', '{conversationModel.CountMinutes}', '{conversationModel.date.ToShortTimeString()}', '{conversationModel.PriceConverstation}' )" ; sqlConnection = new SqlConnection(con); try { sqlConnection.Open(); } catch (Exception) { MessageBox.Show("Не удалось подключиться"); } command = new SqlCommand(commandString, sqlConnection); command.ExecuteNonQuery(); sqlConnection.Close(); DataTable DT = dataGridView1.DataSource as DataTable; DT.Clear(); adapter.Fill(tableConversation); ValidateController.CleanerNumeric(textBoxMinute); } else { MessageBox.Show("Заполните данные"); } }
private void Button1_Click(object sender, EventArgs e) { cityModel = new CityModel(textBoxCity.Text, numericRateDay.Value, numericRateNight.Value, numericDiscount.Value); if (cityModel.validate(errorCity, errorRDay, errorRNight)) { Cursor.Current = Cursors.WaitCursor; sqlConnection = new SqlConnection(con); if (ValidateController.validateItem(labelIDCity.Text)) { commandString = $@"UPDATE [dbo].[City] SET [NameCity] = '{cityModel.CityName}' ,[RateDay] = '{cityModel.RateDay}' ,[RateNigth] = '{cityModel.RateNight}' ,[Discount] = '{cityModel.Discount}' WHERE IdCity = '{labelIDCity.Text}'" ; } else { commandString = $@"INSERT INTO [dbo].[City] ([NameCity] ,[RateDay] ,[RateNigth] ,[Discount]) VALUES( '{cityModel.CityName}', '{cityModel.RateDay.ToString()}', '{cityModel.RateNight}', '{cityModel.Discount}')" ; } try { sqlConnection.Open(); } catch (Exception) { MessageBox.Show("Не удалось подключиться"); } command = new SqlCommand(commandString, sqlConnection); command.ExecuteNonQuery(); this.cityTableAdapter.Fill(this.phoneCallDataSet19.City); labelIDCity.Text = ""; ValidateController.CleanerTextBox(textBoxCity); ValidateController.CleanerNumeric(numericDiscount, numericRateDay, numericRateNight); } }