Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 4.0 aka C# 2010 > C# 4.0 aka C# 2010 General Discussion
|
C# 4.0 aka C# 2010 General Discussion Discussions about the C# 4.0, C# 4, Visual C# 2010 language and tool not related to any specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 4.0 aka C# 2010 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 21st, 2013, 01:17 AM
Registered User
 
Join Date: Nov 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default calling a method or function declared in mdi parent form in a child form?

Hi my name is vishal. I am a novice in c#. I am at task of converting vb6 with ms access project to C# with sql server 2008. In my project I have a mdi parent form,child form.
Now i do not know how to call a method/function which declared in mdi parent form in child form.
Anyone please help me.

My mdi parent form name: MDIParent1.cs
my child form name: Patient.cs

the method/function name declared in mdi parent form: public string updateUserActivities().

below i have attached my code. Any help would be appreciated.

Code:
MDIParent1 code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace DRRS_in_Csharp
{
    public partial class MDIParent1 : Form
    {
        private int childFormNumber = 0;
        long pUserID;
        public MDIParent1()
        {
            InitializeComponent();
        }

        private void ShowNewForm(object sender, EventArgs e)
        {
            Form childForm = new Form();
            childForm.MdiParent = this;
            childForm.Text = "Window " + childFormNumber++;
            childForm.Show();
        }

        private void OpenFile(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            openFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
            if (openFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = openFileDialog.FileName;
            }
        }

        private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            saveFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
            if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = saveFileDialog.FileName;
            }
        }

        private void ExitToolsStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void CutToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void CopyToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void PasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void ToolBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.IsMdiContainer = true;
            Form Patient = new Form();
            Patient.MdiParent = this;
            Patient.Show();
        }

        private void StatusBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            statusStrip.Visible = statusBarToolStripMenuItem.Checked;
        }

        private void CascadeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.Cascade);
        }

        private void TileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical);
        }

        private void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.ArrangeIcons);
        }

        private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form childForm in MdiChildren)
            {
                childForm.Close();
            }
        }
        public SqlConnectionStringBuilder connBuilder;
        public SqlConnection conn;

        private void initializeDB()
        {

            connBuilder = new SqlConnectionStringBuilder();
            connBuilder.InitialCatalog = "TusDB";
            connBuilder.DataSource = "NPD-4\\SQLEXPRESS";
            connBuilder.IntegratedSecurity = true;
            connBuilder.AsynchronousProcessing = true;

            conn = new SqlConnection(connBuilder.ToString());
            conn.Open();
        }

         public string updateUserActivities(long refID, int ActType, string ActivityStr)
        {
      
            SqlDataAdapter da = new SqlDataAdapter();
            int b;
            da.InsertCommand = new SqlCommand("Insert into user_activities2(user_id,row_upd_date,activity,type,ref_id)" + "Values(@user_id,@row_upd_date,@activity,@type,@ref_id)", conn);
            da.InsertCommand.Parameters.Add("@user_id", SqlDbType.VarChar).Value = pUserID;
            da.InsertCommand.Parameters.Add("@row_upd_date", SqlDbType.DateTime).Value = Convert.ToDateTime(this);
            da.InsertCommand.Parameters.Add("@activity", SqlDbType.VarChar).Value = ActivityStr;
            da.InsertCommand.Parameters.Add("@type", SqlDbType.Int).Value = ActType;
            da.InsertCommand.Parameters.Add("@ref_id", SqlDbType.VarChar).Value = refID;
            b = da.InsertCommand.ExecuteNonQuery();
            conn.Close();

        }
        private void MDIParent1_Load(object sender, EventArgs e)
        {
            initializeDB();
        }

        private void patientToolStripMenuItem_Click(object sender, EventArgs e)
        {
           

        }
    }
}
Code:
Patient.cs code:

 private void button1_Click(object sender, EventArgs e)
        {   
            long PatientID;
            string dFieldName = "";
            if (txtFname.Text.ToString().Trim() == "")
            {
                dFieldName = "First Name should not be empty";
            }
            else if (cboSex.Text.ToString().Trim() == "")
            {
                dFieldName = "************ should not be empty";
            }
            else if (cboVirology.Text.ToString().Trim() == "")
            {
                dFieldName = "Virology state of patient should not be empty";
            }
            else if (txtHnumber.Text.ToString().Trim() == "")
            {
                dFieldName = "Home number of patient should not be empty";
            }
            else if (txtCity.Text.ToString().Trim() == "")
            {
                dFieldName = "City of patient should not be empty";
            }
            else if (txtCountry.Text.ToString().Trim() == "")
            {
                dFieldName = "Country of patient should not be empty";
            }
            else if (cboDoctor.Text.ToString().Trim() == "")
            {
                dFieldName = "Doctor Name should not be empty";
            }
            if (dFieldName.ToString().Trim() != "")
            {
                MessageBox.Show(dFieldName);
            }
           long pUserID;
            long patientID;
            long patient;
            SqlConnection conn=new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=Tuscan7;Persist Security Info=true");
            SqlDataAdapter da=new SqlDataAdapter();
            SqlCommand cmd=new SqlCommand();
            cmd.Connection=conn;
            cmd.CommandType=CommandType.Text;

            conn.Open();
            
            if(patientID==0)
                conn.Open();
            object selecteditem=cboSex.SelectedIndex;
               int x;
            da.InsertCommand=new SqlCommand("Insert into Patient_id(patient_id,patient_************,patient_dOB,row_upd_date,user_id)" + " Values(@patient_id,@patient_************,@patient_dOB,@row_upd_date,@user_id)",conn);
            da.InsertCommand.Parameters.Add("@patient_************",SqlDbType.Int).Value=selecteditem;
            da.InsertCommand.Parameters.Add("@patient_dOB",SqlDbType.DateTime).Value=dtDOB.Value;
            da.InsertCommand.Parameters.Add("@row_upd_date",SqlDbType.DateTime).Value=Convert.ToDateTime(this);
            da.InsertCommand.Parameters.Add("@user_id",SqlDbType.VarChar).Value=pUserID;
            x=da.InsertCommand.ExecuteNonQuery();
           
            long vPatientID;
            if(patientID==0)
                vPatientID=da.InsertCommand.Parameters.Add("@patient_id",SqlDbType.Int).Value=patient;
            else
                vPatientID=patientID;
            if(patientID>0)
                cmd=new SqlCommand("update Patient_name set status=false where patient_id="+patientID);
            da.InsertCommand=new SqlCommand("Insert into Patient_name(patient_id,patient_first_name,patient_middle_name,patient_last_name,virology,row_upd_date,status,user_id)"+"Values(@patient_id,@patient_first_name,@patient_middle_name,@patient_last_name,@virology,@row_upd_date,@status,@user_id)",conn);
            conn.Open();
            object selecteditema=cboVirology.SelectedIndex;
            da.InsertCommand.Parameters.Add("@patient_id",SqlDbType.Int).Value=vPatientID;
            da.InsertCommand.Parameters.Add("@patient_first_name",SqlDbType.VarChar).Value=txtFname.Text;
            da.InsertCommand.Parameters.Add("@patient_middle_name",SqlDbType.VarChar).Value=txtMname.Text;
            da.InsertCommand.Parameters.Add("@patient_last_name",SqlDbType.VarChar).Value=txtLname.Text;
            da.InsertCommand.Parameters.Add("@virology",SqlDbType.Int).Value=selecteditema;
            da.InsertCommand.Parameters.Add("@row_upd_date",SqlDbType.DateTime).Value=Convert.ToDateTime(this);
            da.InsertCommand.Parameters.Add("@status",SqlDbType.Bit).Value=true;
            da.InsertCommand.Parameters.Add("@user_id",SqlDbType.VarChar).Value=pUserID;
            x=da.InsertCommand.ExecuteNonQuery();
            
            if((txtHnumber.Text!="")|| (txtMnumber.Text!=""))
                if(patientID>0)
                    cmd=new SqlCommand("update patient_contact set status=false where patient_id="+patientID);
            da.InsertCommand=new SqlCommand("Insert into patient_contact(patient_id,homenumber,mobilenumber,row_upd_date,status,user_id)"+"Values(@patient_id,@homenumber,@mobilenumber,@row_upd_date,@status,@user_id)",conn);
            conn.Open();
            da.InsertCommand.Parameters.Add("@patient_id",SqlDbType.Int).Value=vPatientID;
            da.InsertCommand.Parameters.Add("@homenumber",SqlDbType.NVarChar).Value=txtHnumber.Text;
            da.InsertCommand.Parameters.Add("@mobilenumber",SqlDbType.NVarChar).Value=txtMnumber.Text;
            da.InsertCommand.Parameters.Add("@row_upd_date",SqlDbType.DateTime).Value=Convert.ToDateTime(this);
            da.InsertCommand.Parameters.Add("@status",SqlDbType.Bit).Value=true;
            da.InsertCommand.Parameters.Add("@user_id",SqlDbType.VarChar).Value=pUserID;
            x=da.InsertCommand.ExecuteNonQuery();

            if(patientID>0)
                cmd=new SqlCommand("update Address9 set status=false where patient_id="+patientID);
            da.InsertCommand=new SqlCommand("Insert into Address9(apartment_name,door_number,street_name_1,street_name_2,street_name_3,village,city,state,country,row_upd_date,apartment_number,patient_id,status,user_id,pcode)"+"Values(@apartment_name,@door_number,@street_name_1,@street_name_2,@street_name_3,@village,@city,@state,@country,@row_upd_date,@apartment_number,@patient_id,@status,@user_id,@pcode)",conn);
            da.InsertCommand.Parameters.Add("@apartment_name",SqlDbType.NVarChar).Value=txtApartmentName.Text;
            da.InsertCommand.Parameters.Add("@door_number",SqlDbType.NVarChar).Value=txtDoorNo.Text;
            da.InsertCommand.Parameters.Add("@street_name_1",SqlDbType.VarChar).Value=txtStreet1.Text;
            da.InsertCommand.Parameters.Add("@street_name_2",SqlDbType.VarChar).Value=txtStreet2.Text;
            da.InsertCommand.Parameters.Add("@street_name_3",SqlDbType.VarChar).Value=txtStreet3.Text;
            da.InsertCommand.Parameters.Add("@village",SqlDbType.NVarChar).Value=txtVillageArea.Text;
            da.InsertCommand.Parameters.Add("@city",SqlDbType.NVarChar).Value=txtCity.Text;
            da.InsertCommand.Parameters.Add("@state",SqlDbType.VarChar).Value=txtState.Text;
            da.InsertCommand.Parameters.Add("@country",SqlDbType.NVarChar).Value=txtCountry.Text;
            da.InsertCommand.Parameters.Add("@row_upd_date",SqlDbType.DateTime).Value=Convert.ToDateTime(this);
            da.InsertCommand.Parameters.Add("@apartment_number",SqlDbType.NVarChar).Value=txtApartmentNo.Text;
            da.InsertCommand.Parameters.Add("@patient_id",SqlDbType.Int).Value=vPatientID;
            da.InsertCommand.Parameters.Add("@status",SqlDbType.Bit).Value=true;
            da.InsertCommand.Parameters.Add("@user_id",SqlDbType.VarChar).Value=pUserID;
            da.InsertCommand.Parameters.Add("@pcode",SqlDbType.VarChar).Value=txtPostalCode.Text;
 
            x=da.InsertCommand.ExecuteNonQuery();

            if(patientID>0)
                cmd=new SqlCommand("update doctorpatient2 set status=false where patient_id="+patientID);
            da.InsertCommand=new SqlCommand("Insert into doctorpatient2(patient_id,doctor_id,row_upd_date,status,user_id)"+"Values(@patient_id,@doctor_id,@row_upd_date,@status,@user_id)",conn);
            da.InsertCommand.Parameters.Add("@patient_id",SqlDbType.Int).Value=vPatientID;
            da.InsertCommand.Parameters.Add("@doctor_id",SqlDbType.Int).Value=cboDoctor.Items.Contains(cboDoctor.SelectedItem);
            da.InsertCommand.Parameters.Add("@status",SqlDbType.Bit).Value=true;
            da.InsertCommand.Parameters.Add("@row_upd_date",SqlDbType.DateTime).Value=Convert.ToDateTime(this);
            da.InsertCommand.Parameters.Add("@user_id",SqlDbType.VarChar).Value=pUserID;
            x=da.InsertCommand.ExecuteNonQuery();





Similar Threads
Thread Thread Starter Forum Replies Last Post
Displaying MDI Child Form Menus with MDI Parent ashu_from_india Pro VB 6 3 June 10th, 2008 11:01 PM
Controlling MDI child form from MDI parent panel LuxCoder Pro Visual Basic 2005 1 May 25th, 2007 12:20 PM
Controlling MDI child form from MDI parent panel LuxCoder VB.NET 2002/2003 Basics 7 April 11th, 2007 02:38 PM
Controlling MDI child form from MDI parent panel LuxCoder VB How-To 1 April 9th, 2007 03:25 PM
Controlling MDI child form from MDI parent panel LuxCoder Visual Basic 2005 Basics 2 April 9th, 2007 03:24 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.