Different Namespaces

seahna
seahna used Ask the Experts™
on
How do I get a nessage that is created in one namespace to display on a form in another namespace. The code that creates the messages is attached below. I am trying to get the messages to display in the statusstrip1 in the form through ConnectionStatus.Text, labelAlphaNetStatus.Text, and label_configIP.Text .
private void Form1_Paint(object sender, PaintEventArgs e)
        {

            if ((_alphaNetClient == null) || (!_alphaNetClient.IsConnected))
            {
                ConnectionStatus.Text = string.Format("No Connection");
                labelAlphaNetStatus.Text = String.Format("Registred Nodes 0, Registred Stations 0");
            }
            else
            {
                ConnectionStatus.Text = String.Format("Connected to AlphaCom E on {0}:{1}", Global2.Global2.IPAddressGlobal,
                                                     Global3.Global3.IPPortGlobal);

                labelAlphaNetStatus.Text = String.Format("Registred Nodes {0}, Registred Stations {1}",
                                                         _registeredNodeCounter, _registeredStationCounter);
            }
        }

        private void MainWin1_Load(object sender, EventArgs e)
        {
            label_configIP.Text = Global2.Global2.IPAddressGlobal;
        }

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Lets assume the code stated above is in namespace 'A' and you have to use Text set in the function  Form1_Paint and MainWin1_Load in namespace B.

Check if the class Form1 is Singleton.
If Yes, follow the below mentioned approach:
Make Getter Properties for all the messages you want to access.in Form1 Class
like
Public Class Form1 : Form
{
  //Singleton Class Implementation
 /******************************************/
  private static Form1 frm1;
  private Form1()
  {    
  }
  public Form1 GetInstance()
  {
      if (frm1 == null)
      {
           frm1 = new Form1()
      }
      return frm1;
  }
 /******************************************/
  public string ConnectionStatusString
  {
    get { return ConnectionStatus.Text; }
  }
  public string AlphaNetStatusString
  {
    get { return labelAlphaNetStatus.Text; }
  }
...
...
}

From Namespace B you can then access the string by simply writing the following code
string statusstripString = A.Form1.GetInstance().ConnectionStatusString + " - "  A.Form1.GetInstance().AlphaNetStatusString + ....;
__________________________________________________________________

On the Other hand if Form1 is not Singleton class.
Define Static variables and static properties for all the strings which you want you get

Public Class Form1 : Form
{
  public Form1()
  {    
  }
  private static string _connectionStatusString
  public static string ConnectionStatusString
  {
    get { return _connectionStatusString; }
  }
  private static string _alphaNetStatusString
  public string AlphaNetStatusString
  {
    get { return _alphaNetStatusString; }
  }
...
...
// Set the static strings in function Form1_Paint and Form1_Load
   private void Form1_Paint(object sender, PaintEventArgs e)
   {
     // Stuff already implemented..
...
...
      //At the end
      _connectionStatusString = ConnectionStatus.Text;
      _alphaNetStatusString = labelAlphaNetStatus.Text;
   }
   // do the same in Form1_load
}

From Namespace B you can then access the string by simply writing the following code
string statusstripString = A.Form1.ConnectionStatusString + " - "  A.Form1.AlphaNetStatusString + ....;
__________________________________________________________

Few Suggestion for your code:
1. I would preffer you to go with Approach #1. If your class is not singleton make it singleton as shown. I beleive only one instance on this class should present throughout the application
2. Try shifting the code in Form1_Paint event to some other event like labelAlphaNetStatus.TextChanged and ConnectionStatus.TextChanged. As paint will be called very frequently (while resizing, moving and many more) event if it is not required.

Thx!
Swaps...
If you decide to make your Form1 singleton then instead of creating the Form1 object by new, you will access its instance by Form1.GetInstance().

Simply You will be removing
From1 frm1 = new Form1();
every where in your application with
Form1 frm1 = Form1.GetInstance();

Thx!
Swaps...

Author

Commented:
So basically you suggesting to create a global variable that will capture the output and then to call that varaible to display it.
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

Yes...one single instance will be present of from1...
In your application, if you can open more than one instance of form1 which can have different data then only I will advice you to follow approach #2

Thx!
Swaps...

Author

Commented:
Sorry this might be a long post...

Ok I created the global variables 3 in all.

namespace Global4
{//Stores the Exchange Connection Status
    static class Global4
    {
        private static string Status_globalVar;

        public static string ConnectionStatusGlobal
        {
            get { return Status_globalVar; }
            set { Status_globalVar = value; }
        }
    }
}
namespace Global5
{//Stores the number of nodes and dir number
    static class Global5
    {
        private static string NumNodeDirNum_globalVar;

        public static string NumNodeDirNum
        {
            get { return NumNodeDirNum_globalVar; }
            set { NumNodeDirNum_globalVar = value; }
        }
    }
}
namespace Global6
{//Store the IP Address status
    static class Global6
    {
        private static string IPAddressStatus_globalVar = "";

        public static string IPAddressStatusGlobal
        {
            get { return IPAddressStatus_globalVar; }
            set { IPAddressStatus_globalVar = value; }
        }
    }
}

After that in the main form where the status labels are located I did this:

            ConnectionStatus.Text = ConnStat;
            labelAlphaNetStatus.Text = NodeDirNum;
            label_configIP.Text = IPConnStat;

& I also tried it this way:

            ConnectionStatus.Text = Global4.Global4.ConnectionStatusGlobal;
            labelAlphaNetStatus.Text = Global5.Global5.NumNodeDirNum;
            label_configIP.Text = Global6.Global6.IPAddressStatusGlobal;

and the label were still blank as you can see in the screen shot. i zoomed in on the statusbar so you could see what it is that I was talking about.
Connection code
---------------------------------------------------------------------
namespace ExchangeConnection
{
    public static class ActiveConnection
    {
        public static Connect my_connect = null;
        public static void MakeConnection(string ConfigFileName)
        {
            ActiveConnection.my_connect = new Connect();
            ActiveConnection.my_connect.exchange_Connect(ConfigFileName);
        }
    }


    public class Connect
    {
        private AlphaComState _stateStorage;
        private AlphaNetClient _alphaNetClient;
        private int _registeredNodeCounter;
        private int _registeredStationCounter;
        private bool _callRequestListUpdated;
        private bool _callRequestSynchronized;

        private static string ConfigFileName = ConfigurationManager.AppSettings["ConfigFileName"];
    #region Exchange Connect
        public bool exchange_Connect(string ConfigFileName)
        {
            string message;

            XmlDocument myDoc = new XmlDocument();
            myDoc.Load(ConfigFileName);

            string ipAddress = string.Format("Setup/ACSP/Primary/IPAddress");
            string ipPort = string.Format("Setup/ACSP/Primary/IPPort");

            string alphaComIP = ReadValueFromXmlDocumentAtXPath(myDoc, ipAddress);
            string ipPortString = ReadValueFromXmlDocumentAtXPath(myDoc, ipPort);
            int alphaComPort = int.Parse(ipPortString);
            var initialiazed = true;
            try
            {
                // Initialiaze inMemory State Data Storage
                _stateStorage = new AlphaComState(AlphaComStateStorages.IN_MEMORY);

                // Do Get node info and station information for all nodes in AlphaNet.
                _alphaNetClient = new AlphaNetClient(alphaComIP, alphaComPort)
                {
                    AutoDiscoverAllNodes = true,
                    AutoGetStationState = true,
                    AutoSyncCallRequests = true,
                    VerboseLevel = VerboseLevel.NONE,
                };
                Global2.Global2.IPAddressGlobal = alphaComIP;
                Global3.Global3.IPPortGlobal = ipPortString;

                // Register for TCP connection Down event
                _alphaNetClient.OnNodeConnectionDown += HandleOnNodeConnectionDown;
                _alphaNetClient.OnStationConnect += HandleOnStationConnect;
                _alphaNetClient.OnCallRequest += HandleOnCallRequeest;

                _alphaNetClient.StartListening();
                _alphaNetClient.StartMonitorThread();

                message = "Init OK";

            }
            catch (Exception ex)
            {
                message = ex.Message;
                initialiazed = false;
            }

            return initialiazed;

        }

        public bool GetConnected(string message)
        {
            var connected = true;
            try
            {
                // Start listening on the AlphaCOm socket
                _alphaNetClient.StartListening();
                // The Monitor Thread will monitor the TCP connection, and connections with all discovered nodes (DEVICE_INFO)
                // By default all nodes will be AutoDiscovered (can be turned of with the AutoDiscoverAllNodes Flag)
                // The monitor process will Register to all discovered nodes (RESET_TAKEN) 
                // If the AutoDiscoverAllNodes is not used, the AlphaNetClient method RegisterToAlphaComNode(node) has to be used for each node,
                // in order to receive broadcast messages
                _alphaNetClient.StartMonitorThread();

                message = "Connect OK";
            }
            catch (Exception ex)
            {
                message = ex.Message;
                connected = false;
            }
            return connected;
        } 
    #endregion

        public void ConnectionStatus(object sender, EventArgs e)
        {
            if ((_alphaNetClient == null) || (!_alphaNetClient.IsConnected))
            {
                Global4.Global4.ConnectionStatusGlobal = string.Format("No Connection");
                Global5.Global5.NumNodeDirNum = String.Format("Registred Nodes 0, Registred Stations 0");

                Global6.Global6.IPAddressStatusGlobal = string.Format("No IP Address connected");
            }
            else
            {
                Global4.Global4.ConnectionStatusGlobal = String.Format("Connected to AlphaCom E on {0}:{1}", Global2.Global2.IPAddressGlobal,
                                                     Global3.Global3.IPPortGlobal);

                Global5.Global5.NumNodeDirNum = String.Format("Registred Nodes {0}, Registred Stations {1}",
                                                         _registeredNodeCounter, _registeredStationCounter);

                Global6.Global6.IPAddressStatusGlobal = Global2.Global2.IPAddressGlobal;

            }
        }

        #region XML Read
        public string ReadValueFromXmlDocumentAtXPath(XmlDocument configFile, string xpath)
        {
            string value = string.Empty;
            XmlNode myNode = configFile.SelectSingleNode(xpath);
            if (myNode != null && myNode.InnerText != null)
            {
                value = myNode.InnerText;
            }
            return value;
        }
        #endregion

        #region Evenet Handlers
        //method for handling event above
        private void HandleOnNodeConnectionDown(int node, int status)
        {

        }

        private void HandleOnStationConnect(StationConnect sc)
        {

        }

        private void HandleOnCallRequeest(CallRequest cr)
        {
            _stateStorage.AddCallRequest(cr);
            _callRequestListUpdated = true;

            if (cr.ReceivingStation.GetLocalNodeNo().Equals("1"))
            {
                if (cr.ReceivingStation.GetDirNo().Equals("101"))
                {
//                    cr.SendingStation.GetDirNo();
                }
            }

        }
        private void HandleCallRequestRemoved(CallRequest cr)
        {
            if (_stateStorage.RemoveCallRequest(cr))
                _callRequestListUpdated = true;

        }

        private void HandleCallRequestReceived(CallRequest cr)
        {
            _stateStorage.AddCallRequest(cr);
            _callRequestListUpdated = true;
        }
        #endregion
    }
}

-------------------------------------------------------------------
Where I cll the global variables
-------------------------------------------------------------------
namespace AV4._1_ClientTool.Dialogs1
{
    public partial class MainWin1 : Form
    {
        private int _registeredNodeCounter;
        private int _registeredStationCounter;


        private static string ConfigFileName = ConfigurationManager.AppSettings["ConfigFileName"];
        private string UserID = Global1.Global1.UserGlobal; // recalls user ID from Login screeen stored as not so much global variable
        private string ConnStat = Global4.Global4.ConnectionStatusGlobal;
        private string NodeDirNum = Global5.Global5.NumNodeDirNum;
        private string IPConnStat = Global6.Global6.IPAddressStatusGlobal;
        private XmlDocument myDoc = new XmlDocument();

        public MainWin1()
        {
            InitializeComponent();

        }

        //I have other code here that doesn't matter to this issue.
        
  
        private void Start_load(object sender, EventArgs e)
        {//defines the permissions of the user for the application depending upon who is loged in.

            myDoc.Load(ConfigFileName);
            XmlNode Loginnode = myDoc.SelectSingleNode("Setup/LoginFile");
            XmlDocument loginDoc = new XmlDocument();
            loginDoc.Load(Loginnode.InnerXml);
            string permissionXPath = string.Format("UsersProfile/Logins/User[UserID='{0}']/Permissions", UserID);

            string permission = ReadValueFromXmlDocumentAtXPath(loginDoc, permissionXPath);

            if (permission == "admin")
            {
                ShowRequiredMenus(true);
            }
            else if (permission == "user")
            {
                ShowRequiredMenus(false);
            }

            ConnectionStatus.Text = ConnStat;
            labelAlphaNetStatus.Text = NodeDirNum;
            label_configIP.Text = IPConnStat;

        }
        
	#region Permissions
        private void ShowRequiredMenus(bool visible)
        {//all other menu items here.
            configToolStripMenuItem.Visible = visible;
            helpToolStripMenuItem.Visible = visible;
        }
        #endregion

        public string ReadValueFromXmlDocumentAtXPath(XmlDocument configFile, string xpath)
        {
            string value = string.Empty;
            XmlNode myNode = configFile.SelectSingleNode(xpath);
            if (myNode != null && myNode.InnerText != null)
            {
                value = myNode.InnerText;
            }
            return value;
        }
    }
}

Open in new window

Untitled.png
I am not able to understand the code structure you are following. Could you send me the code?
if you don't want to send it on expert-exchage, you can mail it to me at swapnil.karoo@gmail.com
Access the properties after you have created the object of connect.

Author

Commented:
Ok I will try to explain this a little better. I have created an application that has several different forms and namespaces. In addition I have a couple variable that must be share between forms and namespaces. but as we all know technically C# doesn't have global variables so I did the following to hold the need information and share it globally (you may also see attached zip file for code):

namespace Global4
{//Stores the Exchange Connection Status
    static class Global4
    {
        private static string Status_globalVar;

        public static string ConnectionStatusGlobal
        {
            get { return Status_globalVar; }
            set { Status_globalVar = value; }
        }
    }
}
namespace Global5
{//Stores the number of nodes and dir number
    static class Global5
    {
        private static string NumNodeDirNum_globalVar;

        public static string NumNodeDirNum
        {
            get { return NumNodeDirNum_globalVar; }
            set { NumNodeDirNum_globalVar = value; }
        }
    }
}
namespace Global6
{//Store the IP Address status
    static class Global6
    {
        private static string IPAddressStatus_globalVar = "";

        public static string IPAddressStatusGlobal
        {
            get { return IPAddressStatus_globalVar; }
            set { IPAddressStatus_globalVar = value; }
        }
    }
}

These global varaibles hold the text value to the text string that are created in this namespace:

namespace ExchangeConnection
{
    public static class ActiveConnection
    {
        public static Connect my_connect = null;
        public static void MakeConnection(string ConfigFileName)
        {
            ActiveConnection.my_connect = new Connect();
            ActiveConnection.my_connect.exchange_Connect(ConfigFileName);
        }
    }


    public class Connect
    {
        private AlphaComState _stateStorage;
        private AlphaNetClient _alphaNetClient;
        private int _registeredNodeCounter;
        private int _registeredStationCounter;
        private bool _callRequestListUpdated;
        private bool _callRequestSynchronized;

        private static string ConfigFileName = ConfigurationManager.AppSettings["ConfigFileName"];
    #region Exchange Connect
        public bool exchange_Connect(string ConfigFileName)
        {
            string message;

            XmlDocument myDoc = new XmlDocument();
            myDoc.Load(ConfigFileName);

            string ipAddress = string.Format("Setup/ACSP/Primary/IPAddress");
            string ipPort = string.Format("Setup/ACSP/Primary/IPPort");

            string alphaComIP = ReadValueFromXmlDocumentAtXPath(myDoc, ipAddress);
            string ipPortString = ReadValueFromXmlDocumentAtXPath(myDoc, ipPort);
            int alphaComPort = int.Parse(ipPortString);
            var initialiazed = true;
            try
            {
                // Initialiaze inMemory State Data Storage
                _stateStorage = new AlphaComState(AlphaComStateStorages.IN_MEMORY);

                // Do Get node info and station information for all nodes in AlphaNet.
                _alphaNetClient = new AlphaNetClient(alphaComIP, alphaComPort)
                {
                    AutoDiscoverAllNodes = true,
                    AutoGetStationState = true,
                    AutoSyncCallRequests = true,
                    VerboseLevel = VerboseLevel.NONE,
                };
                Global2.Global2.IPAddressGlobal = alphaComIP;
                Global3.Global3.IPPortGlobal = ipPortString;

                // Register for TCP connection Down event
                _alphaNetClient.OnNodeConnectionDown += HandleOnNodeConnectionDown;
                _alphaNetClient.OnStationConnect += HandleOnStationConnect;
                _alphaNetClient.OnCallRequest += HandleOnCallRequeest;

                _alphaNetClient.StartListening();
                _alphaNetClient.StartMonitorThread();

                message = "Init OK";

            }
            catch (Exception ex)
            {
                message = ex.Message;
                initialiazed = false;
            }

            return initialiazed;

        }

        public bool GetConnected(string message)
        {
            var connected = true;
            try
            {
                // Start listening on the AlphaCOm socket
                _alphaNetClient.StartListening();
                // The Monitor Thread will monitor the TCP connection, and connections with all discovered nodes (DEVICE_INFO)
                // By default all nodes will be AutoDiscovered (can be turned of with the AutoDiscoverAllNodes Flag)
                // The monitor process will Register to all discovered nodes (RESET_TAKEN)
                // If the AutoDiscoverAllNodes is not used, the AlphaNetClient method RegisterToAlphaComNode(node) has to be used for each node,
                // in order to receive broadcast messages
                _alphaNetClient.StartMonitorThread();

                message = "Connect OK";
            }
            catch (Exception ex)
            {
                message = ex.Message;
                connected = false;
            }
            return connected;
        }
    #endregion

        public void ConnectionStatus(object sender, EventArgs e)
        {
            if ((_alphaNetClient == null) || (!_alphaNetClient.IsConnected))
            {
                Global4.Global4.ConnectionStatusGlobal = string.Format("No Connection");
                Global5.Global5.NumNodeDirNum = String.Format("Registred Nodes 0, Registred Stations 0");

                Global6.Global6.IPAddressStatusGlobal = string.Format("No IP Address connected");
            }
            else
            {
                Global4.Global4.ConnectionStatusGlobal = String.Format("Connected to AlphaCom E on {0}:{1}", Global2.Global2.IPAddressGlobal,
                                                     Global3.Global3.IPPortGlobal);

                Global5.Global5.NumNodeDirNum = String.Format("Registred Nodes {0}, Registred Stations {1}",
                                                         _registeredNodeCounter, _registeredStationCounter);

                Global6.Global6.IPAddressStatusGlobal = Global2.Global2.IPAddressGlobal;

            }
        }

        #region XML Read
        public string ReadValueFromXmlDocumentAtXPath(XmlDocument configFile, string xpath)
        {
            string value = string.Empty;
            XmlNode myNode = configFile.SelectSingleNode(xpath);
            if (myNode != null && myNode.InnerText != null)
            {
                value = myNode.InnerText;
            }
            return value;
        }
        #endregion

        #region Evenet Handlers
        //method for handling event above
        private void HandleOnNodeConnectionDown(int node, int status)
        {

        }

        private void HandleOnStationConnect(StationConnect sc)
        {

        }

        private void HandleOnCallRequeest(CallRequest cr)
        {
            _stateStorage.AddCallRequest(cr);
            _callRequestListUpdated = true;

            if (cr.ReceivingStation.GetLocalNodeNo().Equals("1"))
            {
                if (cr.ReceivingStation.GetDirNo().Equals("101"))
                {
//                    cr.SendingStation.GetDirNo();
                }
            }

        }
        private void HandleCallRequestRemoved(CallRequest cr)
        {
            if (_stateStorage.RemoveCallRequest(cr))
                _callRequestListUpdated = true;

        }

        private void HandleCallRequestReceived(CallRequest cr)
        {
            _stateStorage.AddCallRequest(cr);
            _callRequestListUpdated = true;
        }
        #endregion
    }
}

Then after those text strings are created above they are displayed in another form via this information (All this code can also be found in the attached zip):

namespace AV4._1_ClientTool.Dialogs1
{
    public partial class MainWin1 : Form
    {
        private int _registeredNodeCounter;
        private int _registeredStationCounter;


        private static string ConfigFileName = ConfigurationManager.AppSettings["ConfigFileName"];
        private string UserID = Global1.Global1.UserGlobal; // recalls user ID from Login screeen stored as not so much global variable
        private string ConnStat = Global4.Global4.ConnectionStatusGlobal;
        private string NodeDirNum = Global5.Global5.NumNodeDirNum;
        private string IPConnStat = Global6.Global6.IPAddressStatusGlobal;
        private XmlDocument myDoc = new XmlDocument();

        public MainWin1()
        {
            InitializeComponent();

        }

        //I have other code here that doesn't matter to this issue.
       
 
        private void Start_load(object sender, EventArgs e)
        {//defines the permissions of the user for the application depending upon who is loged in.

            myDoc.Load(ConfigFileName);
            XmlNode Loginnode = myDoc.SelectSingleNode("Setup/LoginFile");
            XmlDocument loginDoc = new XmlDocument();
            loginDoc.Load(Loginnode.InnerXml);
            string permissionXPath = string.Format("UsersProfile/Logins/User[UserID='{0}']/Permissions", UserID);

            string permission = ReadValueFromXmlDocumentAtXPath(loginDoc, permissionXPath);

            if (permission == "admin")
            {
                ShowRequiredMenus(true);
            }
            else if (permission == "user")
            {
                ShowRequiredMenus(false);
            }
********************************below is were I make the call to display text string*******************************
            ConnectionStatus.Text = ConnStat;
            labelAlphaNetStatus.Text = NodeDirNum;
            label_configIP.Text = IPConnStat;

        }
       
      #region Permissions
        private void ShowRequiredMenus(bool visible)
        {//all other menu items here.
            configToolStripMenuItem.Visible = visible;
            helpToolStripMenuItem.Visible = visible;
        }
        #endregion

        public string ReadValueFromXmlDocumentAtXPath(XmlDocument configFile, string xpath)
        {
            string value = string.Empty;
            XmlNode myNode = configFile.SelectSingleNode(xpath);
            if (myNode != null && myNode.InnerText != null)
            {
                value = myNode.InnerText;
            }
            return value;
        }
    }
}

Now the problem is this when I make the call to display the text strings in my form the information doesn't display. Any ideas why or how to fix this error?
Code.zip
You have not used the ActiveConnection...So connection is never activated...hence strings will be empty at every time

Author

Commented:
I do use it in another form that actually calls it and even if it is not called I should still get the not connected message and not nothing. the form I call it in the attached code is below.
namespace AV4._1_ClientTool.Dialogs1
{
    public partial class Login1 : Form
    {
        public Login1()
        {
            InitializeComponent();
        }

        private int no_of_attempts = 0; //must be defined outside scope of event handler
        private static string ConfigFileName = ConfigurationManager.AppSettings["ConfigFileName"]; 
        private static int maxLoginAttempts = 2;
        private static XmlDocument myDoc = new XmlDocument(); 


        private void evLoginOk1_Click(object sender, EventArgs e)
        {
            no_of_attempts++;               //Variable to count the number of attempts made by the user

            bool valid = IsLoginValid(ConfigFileName, LoginIDTextBox1.Text, LoginPWTextBox1.Text);

            Global1.Global1.UserGlobal = LoginIDTextBox1.Text;
            //If information is validated the login window will close and the application main window will diplay.
             //If the incorrect information is input then the error message will display if the incorrect informaiton
             //is input more then three time then the exceed login attempt window will display and the application will close. 
            if (valid)
            {
                ExchangeConnection.ActiveConnection.MakeConnection(ConfigFileName);

                AV4._1_ClientTool.Dialogs1.MainWin1 mainWin1 = new AV4._1_ClientTool.Dialogs1.MainWin1();
                mainWin1.Show();

                AV4._1_ClientTool.Dialogs1.View.CallRequest viewSub3 = new AV4._1_ClientTool.Dialogs1.View.CallRequest();
                viewSub3.Show();
 
                this.Hide();
            }
            else
            {//if the user and password come back invalid the error message will appear on the screen
                //and the user will need to click ok to try again. 
                if (no_of_attempts <= maxLoginAttempts)            //tracks the number of attempts made by the user to login to the system.
                {
                    AV4._1_ClientTool.Dialogs1.Error errorWin1 = new AV4._1_ClientTool.Dialogs1.Error();
                    errorWin1.Show();
                }
                else
                {
                    AV4._1_ClientTool.Dialogs1.ExceedsAttempts exceedWin1 = new AV4._1_ClientTool.Dialogs1.ExceedsAttempts();
                    exceedWin1.Show();
                }
            }
        }

        public static bool IsLoginValid(string ConfigFileName, string username, string password)
        {
            myDoc.Load(ConfigFileName);
            XmlNode Loginnode = myDoc.SelectSingleNode("Setup/LoginFile");

            // Load the Login.xml 
            XmlDocument loginDoc = new XmlDocument();
            loginDoc.Load(Loginnode.InnerXml);

            string passwordXPath = string.Format("UsersProfile/Logins/User[UserID='{0}']/UserPW", username);

            // Get the password node fom logindoc. 
            XmlNode passwordNode = loginDoc.SelectSingleNode(passwordXPath);

            if (passwordNode == null)
            {
                return false;
            }

            if (passwordNode.InnerText.Equals(password)) //username and password match!  
            {
                return true;
            }
            return false;
        } 

        public void Language(string ConfigFileName)
        {
            
        }
      
        //cancel entery into application
        private void evCancel1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}

Open in new window

When is the function ConnectionStatus(object sender, EventArgs e) called?
If it is called from some where else then try this:
        private void Start_load(object sender, EventArgs e)
        {//defines the permissions of the user for the application depending upon who is loged in.

            myDoc.Load(ConfigFileName);
            XmlNode Loginnode = myDoc.SelectSingleNode("Setup/LoginFile");
            XmlDocument loginDoc = new XmlDocument();
            loginDoc.Load(Loginnode.InnerXml);
            string permissionXPath = string.Format("UsersProfile/Logins/User[UserID='{0}']/Permissions", UserID);

            string permission = ReadValueFromXmlDocumentAtXPath(loginDoc, permissionXPath);

            if (permission == "admin")
            {
                ShowRequiredMenus(true);
            }
            else if (permission == "user")
            {
                ShowRequiredMenus(false);
            }
           
            UserID = Global1.Global1.UserGlobal; // recalls user
            ConnStat = Global4.Global4.ConnectionStatusGlobal;
            NodeDirNum = Global5.Global5.NumNodeDirNum;
            IPConnStat = Global6.Global6.IPAddressStatusGlobal;

            ConnectionStatus.Text = ConnStat;
            labelAlphaNetStatus.Text = NodeDirNum;
            label_configIP.Text = IPConnStat;

        }

Author

Commented:
now that you mention that I don't know that it is...When or where should I call it?
Also, instead of maintaining global variables in different namespaces you can define them in a single namespace.....
I will suggest to move them to ActiveConnection class. Its static and it can maintain all the things...
you can access the vvariables like ExchangeConnection.ActiveConnection.UserGlobal and so on....
ConnectionStatus is an event handler...you must have registered it someehere in the code...if not you should register it....I think its an eventhandler for _alphaNetClient.

You can also try this: (A hack but still...)
.......
.......
ConnectionStatus(null, null);
UserID = Global1.Global1.UserGlobal; // recalls user
ConnStat = Global4.Global4.ConnectionStatusGlobal;
NodeDirNum = Global5.Global5.NumNodeDirNum;
IPConnStat = Global6.Global6.IPAddressStatusGlobal;

ConnectionStatus.Text = ConnStat;
labelAlphaNetStatus.Text = NodeDirNum;
label_configIP.Text = IPConnStat;

Author

Commented:
I tried what you said and it didn't work I just got an error but you got my brian thinking so I changed one part of my code to:

    public static class ActiveConnection
    {
        public static Connect my_connect = null;
        public static void MakeConnection(string ConfigFileName)
        {
            ActiveConnection.my_connect = new Connect();
            ActiveConnection.my_connect.exchange_Connect(ConfigFileName);
            ActiveConnection.my_connect.ConnectionStatus(null, null);  <-- added this
        }
    }

then ran my code and now instead of getting a blank status bar I get one that says no connection is being made even though one is being made. Any ideas?
its an event handler that you have not registered...try to figure out how will it be used....it will be called auomatically whenever the connection changes....try looking into documentation of   AlphaComState or AlphaNetClient

Author

Commented:
Ok thanks you not sure what I did exactly but I got it to work with your help.
You are most welcome...:)
Thx!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial