how can I call a procedure stored in a form from a different form?

I have this procedure in patient_dashborad:

public void get_visits()

{

this.Cursor = Cursors.WaitCursor;

data_table = new DataTable();

sql_connection = new SqlConnection("Data Source=.\\SQLEXPRESS;initial catalog=shefa;integrated security=true");

sql_command = new SqlCommand("sp_get_patient_visits", sql_connection);

sql_command.CommandType = CommandType.StoredProcedure;

sql_command.Parameters.Add("@file_no", SqlDbType.Int).Value = file_no;

sql_adapter = new SqlDataAdapter(sql_command);

sql_adapter.Fill(data_table);

dataVisits.DataSource = data_table;

dataVisits.Columns["visit_id"].HeaderText = "insurance id";

dataVisits.Columns["visit_id"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopRight;

dataVisits.Columns["visit_id"].Visible = false;

dataVisits.Columns["created_date"].HeaderText = "Visit Created";

dataVisits.Columns["created_date"].DefaultCellStyle.Format = "ddd dd MMM yyyy HH:mm";

dataVisits.Columns["created_date"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopCenter;

dataVisits.Columns["created_date"].Width = 160;

dataVisits.Columns["direct_or_insurance"].HeaderText = "Payment";

dataVisits.Columns["direct_or_insurance"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopCenter;

dataVisits.Columns["direct_or_insurance"].Width = 120;

dataVisits.Columns["visit_total_amount"].HeaderText = "Total Amount";

dataVisits.Columns["visit_total_amount"].DefaultCellStyle.Format = "BD #,###,0.000";

dataVisits.Columns["visit_total_amount"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopCenter;

dataVisits.Columns["visit_total_amount"].Width = 120;

dataVisits.Columns["visit_closing_paid"].HeaderText = "Paid Amount";

dataVisits.Columns["visit_closing_paid"].DefaultCellStyle.Format = "BD #,###,0.000";

dataVisits.Columns["visit_closing_paid"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopCenter;

dataVisits.Columns["visit_closing_paid"].Width = 120;

dataVisits.Columns["visit_is_open"].HeaderText = "Open ";

dataVisits.Columns["visit_is_open"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopCenter;

dataVisits.Columns["visit_is_open"].Width = 120;

dataVisits.Refresh();

}

and I am calling it from the open_file form like this:

PatientDashboardForm.get_visits();

but the dataVisits dosn't get refresh with the new records.. but when I close the patient_dashboard and open it again i can see my new records




Answer this question

how can I call a procedure stored in a form from a different form?

  • Padmaja T Chavali

    thank you very much.. that's what i wanted exactly..

    but i have one more question please..

    what if I am openning frmVisit using ShowDialog and then from frmVisit I open another form (frmPayment) using ShowDialog

    when closing frmPayment it will close the frmPayment and frmVisit and will update the patient_dashboard using get_visit



  • Siggy01

    this can be accomplished by the same technique that i just told you.

    here is an example:

    pathient_dashboard form:

    FrmVisit frmVisit = new FrmVisit();

    DialogResult dl_patient = frmVisit.ShowDialog();

    if (dl_Result == DialogResult.OK)

    {

    // ur code to refresh records

    get_visit();

    }

    frmVisit form:

    FrmPayment frmPayment = new FrmPayment();

    DialogResult dl_Visit = frmPayment.ShowDialog();

    if(dl_Visit == DialogResult.OK)

    {

    this.DialogResult = DialogResult.OK

    this.Close()

    }


  • Lionb

    I dont understand the scenario completely and i dont know how u've opened the form frmVisit, but if you've opened it in modal form, like this:

    frmVisit.ShowDialog()

    you can use its DialogResult property to update the main form.

    this is how you should open the frmVisit

    DialogResult dlr = frmVisit.ShowDialog()

    Now suppose the user makes some kind of changes in the record (we're in frmVisit right now)

    when the user does that, set the dialogresult property of the form to lets say OK...u can do that this way

    //user makes changes

    this.DialogResult = DialogResult.OK

    now when the user will close that form, you will get a DialogResult value in 'dlr' that i declared before. Now since we've set the DialogResult property to OK if the user had made changes, you can put it in an if(condition) like this

    if(dlr==DialogResult.OK)

    {

    //call the function to refresh records

    RefreshRecords();

    }

    hope this helps


  • AllahIsGook

    Hi,

    Could you pls make it clearer, what is dataVisit, PatientDashboardForm, patient_dashborad

    What is the senario

    Thank you



  • giftgirls

    the senario is the following:

    I have a main form called patient_dashboard which list all patient's visit with visit's details in a datagrid called dataVisit

    In the main form I have get_visits which populate visits into the dataVisit on the main form (patientDashboard)

    when the user opens the visit details for, let's call it frmVisit and make any changes, i want to run the module get_visits (on the patientDashoboard) to refresh the data on the dataVisits.



  • ackermsb

    plz help..



  • how can I call a procedure stored in a form from a different form?