private void del_bill_Click(object sender, EventArgs e) { if (MessageBox.Show("هل تريد حذف الفاتوره", "حذف فاتوره", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { int index = bill_girdview.SelectedCells[0].RowIndex; if (index >= 0) { int id = Convert.ToInt32(bill_girdview.Rows[index].Cells[0].Value); if (db.deleteDB("DELETE from bill WHERE id=" + id)) { string lastIndex = db.ListOF("select id from bill ORDER BY id").Last(); int i = Convert.ToInt32(lastIndex) + 1; db.ExeQuery("ALTER TABLE bill AUTO_INCREMENT = " + i); RefreshBill(bill_query); MessageBox.Show("تم حذف الفاتوره"); } } } }
private void save_Click(object sender, EventArgs e) { if (cases == 1) { try { int id = Convert.ToInt32(id_txt.Text); string cust_type = cust_type_combo.SelectedItem.ToString(); string cust_name = customer_combo.SelectedItem.ToString(); int teethes_count = Convert.ToInt32(teethes_txt.Text); string color = color_combo.SelectedItem.ToString();; string type = type_combo.SelectedItem.ToString(); string delv_state = delv_state_combo.SelectedItem.ToString(); price = Convert.ToDouble(price_txt.Text); DateTime rec_date = DateTime.Today; DateTime delv_date = DateTime.Today; if (delv_state == "لم يسلم") { delv_date = new DateTime(); } string notes = notes_txt.Text; if (cust_type != "" && cust_name != "" && teethes_count > 0 && color != "" && type != "" && notes != "") { string id_select = "SELECT cust_id from customer where cust_name='" + cust_name + "'"; string insert_query2 = "INSERT INTO bill (bill_id,cust_id,bill_teethes,bill_color,bill_type,bill_delv_state,bill_rec_date,bill_delv_date,bill_price,bill_notes,user_id) VALUES('" + id + "' ,'" + db.SelectID(id_select) + "' ,'" + teethes_count + "','" + color + "','" + type + "','" + delv_state + "','" + FormatDate(rec_date) + "' ,'" + FormatDate(delv_date) + "' ,'" + price + "' , '" + notes + "','" + form.Id + "')"; string select_id = "SELECT * from bill WHERE bill_id='" + id + "' AND year(bill_rec_date)='" + rec_date.Year + "'"; if (!db.DoseExists(select_id)) { if (db.insertDB(insert_query2)) { int TheId = Convert.ToInt32(db.ListOF("SELECT MAX(id) from bill").Last()); if (type != "مثبت" && type != "حارس ليلي") { for (int x = 0; x < teethes_list.Length; x++) { if (teethes_list[x]) { string query = "INSERT INTO teeth VALUES('" + x + "','" + TheId + "')"; db.insertDB(query); } } } if (warr_years > 0) { string query = "INSERT INTO warrnity (warr_patient,bill_id,warr_years) VALUES('" + patient + "','" + TheId + "','" + warr_years + "')"; db.insertDB(query); } MessageBox.Show("تم اضافه الفاتوره"); this.Close(); form.RefreshBill(form.bill_query); if (MessageBox.Show("هل تريد عرض الفاتوره", "تفاصيل الفاتوره", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { new ShowBill(TheId, form.Id).Show(); } } } else { MessageBox.Show("هذه الفاتوره موجوده"); } } else { MessageBox.Show("تاكد من ادخال جميع القيم بشكل صحيح"); } } catch (FormatException) { MessageBox.Show("لقد ادخلت ارقام خاطئه"); } } else if (cases == 2) { try { int id = Convert.ToInt32(id_txt.Text); string cust_type = cust_type_combo.SelectedItem.ToString(); string cust_name = customer_combo.SelectedItem.ToString(); int teethes_count = Convert.ToInt32(teethes_txt.Text); string color = color_combo.SelectedItem.ToString(); string type = type_combo.SelectedItem.ToString(); string delv_state = delv_state_combo.SelectedItem.ToString(); double price = Convert.ToDouble(price_txt.Text); DateTime delv_date = DateTime.Today; if (delv_state == "لم يسلم") { delv_date = new DateTime(); } string notes = notes_txt.Text; if (cust_type != "" && cust_name != "" && teethes_count > 0 && color != "" && type != "" && notes != "") { string update_query = "UPDATE bill set bill_id='" + id + "',cust_id=(SELECT cust_id from customer where cust_name='" + cust_name + "'),bill_teethes='" + teethes_count + "',bill_color='" + color + "',bill_type='" + type + "',bill_delv_state='" + delv_state + "',bill_delv_date='" + FormatDate(delv_date) + "',bill_price='" + price + "',bill_notes='" + notes + "' WHERE id='" + bill_id + "'"; if (db.updateDB(update_query)) { db.deleteDB("delete from teeth where bill_id='" + bill_id + "'"); if (type != "مثبت" && type != "حارس ليلي") { for (int x = 0; x < teethes_list.Length; x++) { if (teethes_list[x]) { string query = "INSERT INTO teeth VALUES('" + x + "','" + bill_id + "')"; db.insertDB(query); } } } MessageBox.Show("تم تعديل الفاتوره"); form2.RefreshTheBill(); this.Close(); } } else { MessageBox.Show("تاكد من ادخال جميع القيم بشكل صحيح"); } } catch (FormatException) { MessageBox.Show("لقد ادخلت ارقام خاطئه"); } } }