public AddCheckForm(AddPaymentForm payment, Check_Class ch) { InitializeComponent(); db = new SqlConnectionDB(); note_combo.SelectedIndex = 0; cases = 1; this.payment = payment; this.ch = ch; }
private void add_Click(object sender, EventArgs e) { { if (cases == 1) { try { if (id_txt.Text.Length > 0 && bank_txt.Text.Length > 0 && owner_txt.Text.Length > 0 && price_txt.Text.Length > 0) { string id = id_txt.Text; double price = Convert.ToDouble(price_txt.Text); Check_Class checks = new Check_Class(id, bank_txt.Text, owner_txt.Text, date_pic.Value, price, note_combo.SelectedItem.ToString(), img); payment.SetCheck(checks); this.Close(); } else { MessageBox.Show("يجب ملئ جميع الخانات"); } } catch (FormatException) { MessageBox.Show("لقد ادخلت قيمه خاظئه"); } } else if (cases == 2) { try { if (id_txt.Text.Length > 0 && bank_txt.Text.Length > 0 && owner_txt.Text.Length > 0 && price_txt.Text.Length > 0) { string id = id_txt.Text; double price = Convert.ToDouble(price_txt.Text); if (img == null) { string query = "INSERT INTO checks (ch_id,bill_id,ch_bank,ch_owner,ch_date,ch_price,ch_notes) VALUES('" + id + "','" + Payment_id + "' ,'" + bank_txt.Text + "'" + ",'" + owner_txt.Text + "','" + FormatDate(date_pic.Value) + "' ," + price + " ,'" + note_combo.SelectedItem + "')"; if (db.insertDB(query)) { MessageBox.Show("تم اضافه الشيك"); form2.RefreshCheck(); this.Close(); } } else { string query = "INSERT INTO checks VALUES('" + id + "','" + Payment_id + "' ,'" + bank_txt.Text + "'" + ",'" + owner_txt.Text + "','" + FormatDate(date_pic.Value) + "' ," + price + " ,'" + note_combo.SelectedItem + "',@picture)"; Thread th = new Thread(() => { if (InvokeRequired) { this.Invoke(new MethodInvoker(delegate { if (db.insertImg(query, img)) { MessageBox.Show("تم اضافه الشيك"); form2.RefreshCheck(); this.Close(); } })); } }); th.Start(); } } else { MessageBox.Show("يجب ملئ جميع الخانات"); } } catch (FormatException) { MessageBox.Show("لقد ادخلت قيمه خاظئه"); } } else if (cases == 3) { try { if (id_txt.Text.Length > 0 && bank_txt.Text.Length > 0 && owner_txt.Text.Length > 0 && price_txt.Text.Length > 0) { int id = Convert.ToInt32(id_txt.Text); double price = Convert.ToDouble(price_txt.Text); string query = "UPDATE checks SET ch_bank='" + bank_txt.Text + "'" + ",ch_owner='" + owner_txt.Text + "',ch_date='" + FormatDate(date_pic.Value) + "' ,ch_price=" + price + " ,ch_notes='" + note_combo.SelectedItem + "' WHERE ch_id=" + ch_id; if (db.updateDB(query)) { this.Close(); form2.RefreshCheck(); } } else { MessageBox.Show("يجب ملئ جميع الخانات"); } } catch (FormatException) { MessageBox.Show("لقد ادخلت قيمه خاظئه"); } } } }
public void SetCheck(Check_Class checks) { ch = checks; }