private void button1_Click(object sender, EventArgs e) { DbTreatments db = new DbTreatments(); try { WindowsFormsApplication1.Treatment w = new WindowsFormsApplication1.Treatment(); if (comboBox1.SelectedIndex == 0) { dataGridView1.DataSource = db.searchTreatmentById(int.Parse(textBox1.Text)).Tables[0]; } else if (comboBox1.SelectedIndex == 1) { dataGridView1.DataSource = db.searchTreatmentByClientName(textBox1.Text).Tables[0]; } else { dataGridView1.DataSource = db.searchTreatmentByCarId(int.Parse(textBox1.Text)).Tables[0]; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } }
private void button2_Click(object sender, EventArgs e) { DbTreatments db = new DbTreatments(); foreach (DataGridViewRow r in dataGridView1.Rows) { if (r.Selected) { int id = int.Parse(r.Cells["Idtreatment"].Value.ToString()); dataGridView2.DataSource = db.searchInvoiceByTreatmentId(id).Tables[0]; } } }
private void button4_Click(object sender, EventArgs e) { DbTreatments db = new DbTreatments(); WindowsFormsApplication1.Treatment w = new WindowsFormsApplication1.Treatment(); try { w.Id = int.Parse(textBox1.Text); w.CustometId = int.Parse(comboBox2.Text); w.CustomerName = textBox6.Text; w.WorkerId = int.Parse(comboBox3.Text); w.WorkerName = textBox7.Text; w.Date = dateTimePicker2.Text; w.Time = ""; w.CarId = int.Parse(comboBox4.Text); w.CarKind = textBox4.Text; w.Total = int.Parse(textBox9.Text); } catch (Exception exception) { MessageBox.Show("Invalid parameters", "Error"); return; } if (db.TreatmentExist(w.Id)) { MessageBox.Show("Treatment ID already exist , pick other ID", "Error"); return; } db.insertTreatment(w); WindowsFormsApplication1.InvoiceDetails invoice = new WindowsFormsApplication1.InvoiceDetails(); invoice.CodeTreatment = w.Id; invoice.InvoiceNumber = w.Id; invoice.ClientId = w.CustometId; invoice.Kind = w.CarKind; invoice.Price = w.Total; db.insertInvoice(invoice); MessageBox.Show("add Treatment Success"); }