3 Replies - 746 Views - Last Post: 16 October 2013 - 05:56 AM Rate Topic: -----

#1 smogsy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 04-September 13

Talking to main part of the form from a Class/Construct

Posted 15 October 2013 - 08:57 AM

So I created this Request annoyance program.
ive having a small but very annoying issue and got the point where I just want to break my keyboard :helpsmilie: from the amount of annoyance it has given me for such a simple task.

I want to access MessageUser() from my class/construct but when I use:
DatabaseAnnoy DBA = new DatabaseAnnoy(); in the top of DBconnect it just does not carry out any action. if I comment this (with dba.messageuser()) out it runs correctly. but I need to access messageuser()

ive tried many way to initialise DatabaseAnnoy so I can use MessageUser()every one has failed.
ive tried event handlers intalising database annoy intalising DBconnect.

I don't know what to do. Please help me :wheelchair:



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

using MySql.Data.MySqlClient;
using System.Text.RegularExpressions;

namespace TRAnnoy
{
    public partial class DatabaseAnnoy : Form
    {
        
        public DatabaseAnnoy()
        {

            
            InitializeComponent();
            
            //hides to tray most important
            this.WindowState = FormWindowState.Minimized;
            this.Hide();
            this.ShowInTaskbar = false;
            DBConnect obj = new DBConnect();
          }


        private void DatabaseAnnoy_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = true; // cannot close me your cheating....
        }
        private void DatabaseAnnoy_Deactivate_1(object sender, EventArgs e)
        {

            this.Activate();
        }
        public void DatabaseAnnoy_Load(object sender, EventArgs e)
        {
            DatabaseTimerSlow.Interval = 1500000;
            DatabaseTimerSlow.Start();
        }

        private void DatabaseTimerSlow_Tick(object sender, EventArgs e)
        {
            DatabaseTimerSlow.Stop();
           MessageUser(); 
        }
        
        private void DatabaseTimerFast_Tick(object sender, EventArgs e)
        {
             DatabaseTimerFast.Stop();
            MessageUser();
            
        }

        //start of the real app
        public void MessageUser()
        {
            
            MessagePopup.Icon = SystemIcons.Exclamation;
            MessagePopup.BalloonTipTitle = "Test Request Not Assigned!";
            MessagePopup.BalloonTipText = "Make a New Test Request Now";
            MessagePopup.BalloonTipIcon = ToolTipIcon.Error;
            MessagePopup.Visible = true;
            MessagePopup.ShowBalloonTip(90000000);
            if (MessageBox.Show(new Form() { WindowState = FormWindowState.Maximized, TopMost = true }, "Make a Test Request Now", "Test Request Not Assigned!") == DialogResult.OK)
            //if (MessageBox.Show("Make a Test Request Now", "Test Request Not Assigned!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1) == DialogResult.OK)
            {
                DatabaseTimerFast.Start();
                DatabaseTimerFast.Interval = 5000;
            }
            else
            {
                DatabaseTimerSlow.Start();
            }
        }



        public class DBConnect
        {
            
            private MySqlConnection connection;
            private string server;
            private string database;
            private string uid;
            private string password;
            DatabaseAnnoy DBA = new DatabaseAnnoy();
            
            
            
            //Constructor
            public DBConnect()
            {
               
           
                Initialize();
                
            }
           

            //Initialize values
            public void Initialize()
            {                 
                server = "hidden";
                database = "hidden";
                uid = "hidden";
                password = "hidden";
                string connectionString;
                connectionString = "SERVER=" + server + ";" + "DATABASE=" +
                database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
                connection = new MySqlConnection(connectionString);
                TROpen();
             }


            public bool OpenConnection()
            {
                
                
                try
                {   
                    connection.Open();
                    
                    return true;
                   
                }

                catch (MySqlException ex)
                {
                    //When handling errors
                    //The two most common error numbers when connecting are as follows:
                    //0: Cannot connect to server.
                    //1045: Invalid user name and/or password.
                    switch (ex.Number)
                    {
                        case 0:
                            MessageBox.Show("Cannot connect to server.  Contact Mammuel");
                            break;

                        case 1045:
                            MessageBox.Show("Invalid username/password, please try again");
                            break;
                    }
                    
                    return false;
                    
                }
                
            }



            //Retrieve Test Requests
            public void TROpen()
            {
                string TROpen = "";
                string FullPCName = "6";
                string RackNumber = Regex.Replace(FullPCName, "[^0-9]", "");
                MessageBox.Show(RackNumber);


                string query = "hidden for security reasons";

                //Open Connection
                if (this.OpenConnection() == true)
                {
                    //Create Mysql Command
                    MySqlCommand cmd = new MySqlCommand(query, connection);

                    //ExecuteScalar will return the CTTest number
                    TROpen = cmd.ExecuteScalar() as string;
                    MessageBox.Show(TROpen);
                   if (TROpen == null)
                   {

                      DBA.MessageUser();
                       
                       
                       
                   }
                   else
                   {
                       MessageBox.Show("TR Found");
                   }
                    
                    //close Connection
                    this.CloseConnection();

                    return;
                }
                else
                {
                    return;
                }
            }

                   
                    
            private bool CloseConnection()
            {
                
                try
                {
                    connection.Close();
                    return true;
                }
                catch (MySqlException ex)
                {
                    MessageBox.Show(ex.Message);
                    return false;
                }
            }









            
        }









           
           


        }
    }

         
       
    
    
    
    

    




Is This A Good Question/Topic? 0
  • +

Replies To: Talking to main part of the form from a Class/Construct

#2 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7105
  • View blog
  • Posts: 24,123
  • Joined: 05-May 12

Re: Talking to main part of the form from a Class/Construct

Posted 15 October 2013 - 03:33 PM

What exactly is failing? Is an exception being thrown?
Was This Post Helpful? 0
  • +
  • -

#3 smogsy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 04-September 13

Re: Talking to main part of the form from a Class/Construct

Posted 16 October 2013 - 12:37 AM

View PostSkydiver, on 15 October 2013 - 03:33 PM, said:

What exactly is failing? Is an exception being thrown?

no error messages are shown it just does not actually run through my code.

without DatabaseAnnoy DBA = new DatabaseAnnoy & DBA.MessageUser() lines

the program popups with all the Message boxes in the code showing me what its found. so i know its running through giving me results.

example:
MessageBox.Show(RackNumber);
MessageBox.Show(TROpen);

with those lines It does nothing at all. no Message boxes
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7105
  • View blog
  • Posts: 24,123
  • Joined: 05-May 12

Re: Talking to main part of the form from a Class/Construct

Posted 16 October 2013 - 05:56 AM

Set breakpoints in your DatabaseAnnoy constructor and Load events. Step through the code when these breakpoints get hit to see if any exceptions are thrown, or if the code is hanging someplace with them.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1