private void btnTaswaya_Click(object sender, EventArgs e) { try { if (id != -1) { if (comSupplier.SelectedValue != null && txtMoney.Text != "" && (radioButtonAdd.Checked || radioButtonDiscount.Checked) && txtSupplierAccount.Text != "") { double paidMoney = 0; if (double.TryParse(txtMoney.Text, out paidMoney)) { dbconnection.Open(); string query = "update supplier_taswaya set Supplier_ID=@Supplier_ID,Taswaya_Type=@Taswaya_Type,Money_Paid=@Money_Paid,Info=@Info,Date=@Date where SupplierTaswaya_ID=" + id; MySqlCommand com = new MySqlCommand(query, dbconnection); com.Parameters.Add("@Supplier_ID", MySqlDbType.Int16); com.Parameters["@Supplier_ID"].Value = Convert.ToInt32(txtSupplierID.Text); if (radioButtonDiscount.Checked) { com.Parameters.Add("@Taswaya_Type", MySqlDbType.VarChar); com.Parameters["@Taswaya_Type"].Value = radioButtonDiscount.Text; } else { com.Parameters.Add("@Taswaya_Type", MySqlDbType.VarChar); com.Parameters["@Taswaya_Type"].Value = radioButtonAdd.Text; } com.Parameters.Add("@Money_Paid", MySqlDbType.Decimal); com.Parameters["@Money_Paid"].Value = Convert.ToDouble(txtMoney.Text); com.Parameters.Add("@Info", MySqlDbType.VarChar); com.Parameters["@Info"].Value = txtInfo.Text; com.Parameters.Add("@Date", MySqlDbType.Date); com.Parameters["@Date"].Value = dateTimeFrom.Value.Date; com.ExecuteNonQuery(); UserControl.ItemRecord("supplier_taswaya", "تعديل", id, DateTime.Now, "", dbconnection); query = "select Money from supplier_rest_money where Supplier_ID=" + comSupplier.SelectedValue.ToString(); com = new MySqlCommand(query, dbconnection); if (com.ExecuteScalar() != null) { double restMoney = Convert.ToDouble(com.ExecuteScalar()); if (row1["نوع التسوية"].ToString() == "خصم") { restMoney = restMoney + Convert.ToDouble(row1["قيمة التسوية"].ToString()); } else { restMoney = restMoney - Convert.ToDouble(row1["قيمة التسوية"].ToString()); } if (radioButtonDiscount.Checked) { query = "update supplier_rest_money set Money=" + (restMoney - paidMoney) + " where Supplier_ID=" + comSupplier.SelectedValue.ToString(); } else { query = "update supplier_rest_money set Money=" + (restMoney + paidMoney) + " where Supplier_ID=" + comSupplier.SelectedValue.ToString(); } com = new MySqlCommand(query, dbconnection); com.ExecuteNonQuery(); } supplierTaswayaReport.DisplaySupplierTaswaya(); clear(); XtraTabPage xtraTabPage = getTabPage("تعديل تسوية مورد"); xtraTabControl.TabPages.Remove(xtraTabPage); } else { MessageBox.Show("المبلغ يجب ان يكون عدد"); } } else { MessageBox.Show("تاكد من ادخال البيانات المطلوبة"); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } dbconnection.Close(); }