void MakeOrder(object sender, EventArgs e) { if (Program.Login == "") { MessageBox.Show("Вы не вошли в систему!"); return; } Button btn = (Button)sender; SQLClass.Insert("INSERT INTO Orders(Login, RunId, Place, CityFrom, CityTo)" + " VALUES('" + Program.Login + "', " + RunId + ", " + btn.Text + ", " + CityFrom + ", " + CityTo + ")"); MessageBox.Show("Сделано"); btn.Enabled = false; }
private void button1_Click(object sender, EventArgs e) { string registered = SQLClass.Select( "SELECT COUNT(*) FROM Users WHERE Login = '******'")[0]; if (registered != "0") { MessageBox.Show("Вы уже зарегистрированы!"); return; } SQLClass.Insert("INSERT INTO Users(Login, Name, Password) VALUES(" + "'" + loginTB.Text + "', '" + fioTB.Text + "', '" + passTB.Text + "')"); MessageBox.Show("Теперь можно входить в систему"); //Close(); }
private void button2_Click(object sender, EventArgs e) { if (MessageBox.Show("Удалить предыдущие рейсы за эти даты и заменить новыми?", "Предупреждение", MessageBoxButtons.YesNo) == DialogResult.No) { return; } DateTime dt1 = dateTimePicker1.Value; DateTime dt2 = dateTimePicker2.Value; List <string> trains = SQLClass.Select("SELECT Id, Days FROM Trains"); SQLClass.Insert("DELETE FROM Orders WHERE RunId IN (SELECT Id FROM Runs WHERE DT BETWEEN STR_TO_DATE('" + dt1.ToShortDateString() + "', '%d.%m.%Y')" + " AND STR_TO_DATE('" + dt2.ToShortDateString() + "', '%d.%m.%Y'))"); SQLClass.Insert("DELETE FROM Runs WHERE DT BETWEEN STR_TO_DATE('" + dt1.ToShortDateString() + "', '%d.%m.%Y')" + " AND STR_TO_DATE('" + dt2.ToShortDateString() + "', '%d.%m.%Y')"); while (dt1 < dt2) { int day = (int)dt1.DayOfWeek; if (day == 0) { day = 7; //Воскресенье } for (int i = 0; i < trains.Count; i += 2) { //В этот день есть поезд if (trains[i + 1].Contains(day.ToString())) { SQLClass.Insert("INSERT INTO Runs(TrainId, DT)" + "VALUES (" + trains[i] + " , STR_TO_DATE('" + dt1.ToShortDateString() + "', '%d.%m.%Y'))"); } } dt1 = dt1.AddDays(1); } MessageBox.Show("Случилось"); }
private void button1_Click(object sender, EventArgs e) { List <string> days = new List <string>(); for (int i = 0; i < checkedListBox1.Items.Count; i++) { if (checkedListBox1.GetItemChecked(i)) { days.Add((i + 1).ToString()); } } string d = String.Join(", ", days); string CityFrom = SQLClass.Select("SELECT Id FROM Cities" + " WHERE Name = '" + fromComboBox.Text + "'")[0]; string CityTo = SQLClass.Select("SELECT Id FROM Cities" + " WHERE Name = '" + toComboBox.Text + "'")[0]; if (trainId == "") { SQLClass.Insert("INSERT INTO Trains(Name, Places, Days, CityFrom, CityTo)" + " VALUES('" + nameTextBox.Text + "', '" + placeTextBox.Text + "', '" + d + "'," + CityFrom + ", " + CityTo + ")"); trainId = SQLClass.Select("SELECT MAX(Id) FROM Trains")[0]; } else { SQLClass.Insert("UPDATE Trains SET" + " Name = '" + nameTextBox.Text + "'," + " Places = '" + placeTextBox.Text + "'," + " Days = '" + d + "'," + " CityFrom = " + CityFrom + ", " + " CityTo = " + CityTo + " WHERE Id = " + trainId); SQLClass.Insert("DELETE FROM Routes WHERE TrainId = " + trainId); } //Город foreach (Control ctrl in Controls) { if (ctrl is ComboBox) { string city = ctrl.Text; //Время, когда поезд там foreach (Control ctrl2 in Controls) { if (ctrl2 is DateTimePicker && ctrl2.Location.Y == ctrl.Location.Y) { string cityTime = ((DateTimePicker)ctrl2).Value.ToLongTimeString(); SQLClass.Insert("INSERT INTO Routes(TrainId, City, TimeStart, TimeFinish)" + " SELECT " + trainId + ", Id, '" + cityTime + "', '" + cityTime + "' FROM Cities WHERE Name = '" + city + "'"); break; } } } } MessageBox.Show("Успешно сохранено"); }