private void saveButton_Click(object sender, EventArgs e) { this.hideErrors(); bool error = false; if (numberTextbox.Text.Length <= 0) { numberPictureBox.Visible = true; error = true; } if (dateInDatetime.Value == null) { dateInPictureBox.Visible = true; error = true; } if (carDropdown.SelectedIndex == -1) { carPictureBox.Visible = true; error = true; } if (employeeDropdown.SelectedIndex == -1) { employeePictureBox.Visible = true; error = true; } if (descriptionTextbox.Text.Length <= 0) { descriptionPictureBox.Visible = true; error = true; } if (error) { return; } DateTime?dateOut = null; if (dateOutDatetime.Format != DateTimePickerFormat.Custom) { dateOut = dateOutDatetime.Value; } RepairCard p = new RepairCard(this.id, numberTextbox.Text, dateInDatetime.Value, dateOut, this.cars[carDropdown.SelectedIndex], descriptionTextbox.Text, this.employees[employeeDropdown.SelectedIndex]); if (p.Id == 0) { RepairCardRepository.Add(p); } else { RepairCardRepository.Update(p); } this.Close(); }
private void removePartButton_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("Сигурни ли сте, че искате да изтриете записа?", "Изтриване?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { int index = partsGridView.SelectedCells.Count > 0 ? partsGridView.SelectedCells[0].RowIndex : -1; index = index != -1 ? Int32.Parse(partsGridView.Rows[index].Cells[0].Value.ToString()) : 0; RepairCardRepository.RemovePart(index); this.getParts(); } }
public CardForm(int id = 0) { InitializeComponent(); this.hideErrors(); RepairCard card = null; cars = CarRepository.GetAll(); foreach (Car c in cars) { carDropdown.Items.Add(c.RegistrationNumber); } employees = EmployeeRepository.GetAll(); foreach (Employee e in employees) { employeeDropdown.Items.Add(e.Name); } if (id != 0) { this.id = id; card = RepairCardRepository.Get(id); } dateOutDatetime.CustomFormat = " "; dateOutDatetime.Format = DateTimePickerFormat.Custom; if (card != null) { this.getParts(); dateInDatetime.Value = card.In; if (card.Out != null) { dateOutDatetime.Value = (DateTime)card.Out; } descriptionTextbox.Text = card.Description; numberTextbox.Text = card.Number; carDropdown.Text = card.Car.RegistrationNumber; employeeDropdown.Text = card.Employee.Name; } else { carDropdown.Text = this.cars.Count > 0 ? this.cars[0].RegistrationNumber : ""; employeeDropdown.Text = this.employees.Count > 0 ? this.employees[0].Name : ""; partsGridView.Visible = false; addPartButton.Visible = false; removePartButton.Visible = false; this.Height = 320; } }
private void showButton_Click(object sender, EventArgs e) { DataTable table = new DataTable(); if (typeDropdown.SelectedIndex == 0) { DateTime date = dateTimePicker.Value; SqlDataAdapter adapter = RepairCardRepository.GetAfterStartDate(date); adapter.Fill(table); resultsDataGridView.DataSource = table; int a = table.Rows.Count; } if (typeDropdown.SelectedIndex == 1) { DateTime date = dateTimePicker.Value; SqlDataAdapter adapter = RepairCardRepository.GetBeforeEndDate(date); adapter.Fill(table); resultsDataGridView.DataSource = table; } if (typeDropdown.SelectedIndex == 2) { DateTime date = dateTimePicker.Value; Car car = this.cars[carDropdown.SelectedIndex]; SqlDataAdapter adapter = RepairCardRepository.GetByCar(car); adapter.Fill(table); resultsDataGridView.DataSource = table; } if (typeDropdown.SelectedIndex == 3) { SqlDataAdapter adapter = RepairCardRepository.GetNotReady(); adapter.Fill(table); resultsDataGridView.DataSource = table; } showCardButton.Visible = table.Rows.Count > 0; }
private void SaveButton_Click(object sender, EventArgs e) { RepairCardRepository.AddPart(this.id, this.parts[partsCombobox.SelectedIndex]); this.Close(); }