private void SaveBtn_Click(object sender, EventArgs e) { try { if (kashf_rdiobtn.Checked) { visit_type = "كشف"; } else { visit_type = "استشارة"; } BL.SelectData sel = new BL.SelectData(); DataTable dt = new DataTable(); //dtp = selpat.get_Patientss(); //if (dtp.Rows.Count < 50) //{ BL.InsertData insert_patientdata = new BL.InsertData(); dt = sel.get_Patientss(); DataRow dr = dt.Rows[0]; if (Idtxt.Text == dr["patientID"].ToString()) { insert_patientdata.register_isteshara(Convert.ToInt32(Idtxt.Text), dateTimePicker1.Value.Date, visit_type); MessageBox.Show("add successfuly"); } else { insert_patientdata.add_patient( Convert.ToInt32(Idtxt.Text), Nametxt.Text, Convert.ToInt32(Agetxt.Text), gendercompobox.SelectedItem.ToString(), phonenum.Text, emailtxt.Text, dateTimePicker1.Value.Date, visit_type, Convert.ToInt32(reversnum.Value.ToString()), Convert.ToDecimal(costtxt.Text) ); MessageBox.Show("add successfuly"); ////////////////////////////////////////////////////// Idtxt.Clear(); Nametxt.Clear(); Agetxt.Clear(); phonenum.Clear(); emailtxt.Clear(); } // costtxt.Clear(); //} //else // MessageBox.Show("error =D"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void Insertbtn_Click(object sender, EventArgs e) { if (nameTxt.Text == "") { nameTxt.BackColor = Color.LightPink; MessageBox.Show("Name is required", "validation error", MessageBoxButtons.OK, MessageBoxIcon.Information); nameTxt.Focus(); return; } if (dtmtxt.Text == "") { dtmtxt.BackColor = Color.LightPink; MessageBox.Show("Name is required", "validation error", MessageBoxButtons.OK, MessageBoxIcon.Information); dtmtxt.Focus(); return; } if (ConNumtxt.Text == "") { ConNumtxt.BackColor = Color.LightPink; MessageBox.Show("Name is required", "validation error", MessageBoxButtons.OK, MessageBoxIcon.Information); ConNumtxt.Focus(); return; } if (Addresstxt.Text == "") { Addresstxt.BackColor = Color.LightPink; MessageBox.Show("Name is required", "validation error", MessageBoxButtons.OK, MessageBoxIcon.Information); Addresstxt.Focus(); return; } if (Agetxt.Text == "") { Agetxt.BackColor = Color.LightPink; MessageBox.Show("Name is required", "validation error", MessageBoxButtons.OK, MessageBoxIcon.Information); Agetxt.Focus(); return; } if (HosChartxt.Text == "") { HosChartxt.BackColor = Color.LightPink; MessageBox.Show("Name is required", "validation error", MessageBoxButtons.OK, MessageBoxIcon.Information); HosChartxt.Focus(); return; } if (ProfChartxt.Text == "") { ProfChartxt.BackColor = Color.LightPink; MessageBox.Show("Name is required", "validation error", MessageBoxButtons.OK, MessageBoxIcon.Information); ProfChartxt.Focus(); return; } try { if (con.State == ConnectionState.Closed) { con.Open(); } if (Insertbtn.Text == "Insert") { SqlCommand sqlCmd = new SqlCommand("OutPBill", con); sqlCmd.CommandType = CommandType.StoredProcedure; sqlCmd.Parameters.AddWithValue("@mode", "Add"); sqlCmd.Parameters.AddWithValue("@PatientId", 0); sqlCmd.Parameters.AddWithValue("@Name", nameTxt.Text.Trim()); sqlCmd.Parameters.AddWithValue("@Date", dtmtxt.Value.Date); sqlCmd.Parameters.AddWithValue("@Contact_Number", ConNumtxt.Text.Trim()); sqlCmd.Parameters.AddWithValue("@Address", Addresstxt.Text.Trim()); sqlCmd.Parameters.AddWithValue("@Age", Agetxt.Text.Trim()); sqlCmd.Parameters.AddWithValue("@Hospital_Charge", HosChartxt.Text.Trim()); sqlCmd.Parameters.AddWithValue("@profs_Charge", ProfChartxt.Text.Trim()); sqlCmd.ExecuteNonQuery(); MessageBox.Show("Data inserted successfully"); } Reset(); FillDataGridView(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error Message"); } finally { con.Close(); } try { if (con.State == ConnectionState.Closed) { con.Open(); } if (Insertbtn.Text == "Insert") { SqlCommand sqlCmd = new SqlCommand("OutPDProc", con); sqlCmd.CommandType = CommandType.StoredProcedure; sqlCmd.Parameters.AddWithValue("@mode", "Add"); sqlCmd.Parameters.AddWithValue("@PatientId", 0); sqlCmd.Parameters.AddWithValue("@Name", nameTxt.Text.Trim()); sqlCmd.Parameters.AddWithValue("@Contact_Number", ConNumtxt.Text.Trim()); sqlCmd.Parameters.AddWithValue("@Address", Addresstxt.Text.Trim()); sqlCmd.Parameters.AddWithValue("@Age", Agetxt.Text.Trim()); } Reset1(); FillDataGridView1(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error Message"); } finally { con.Close(); } }