public customer_class Select_Cust(int cust_ref)
        {
            //cust_ref = Int32.Parse(txtBox_select_cust.Text); //sets the value of variable cust ref to what is in the select text box
            bool custExists = false;

            sql             = "SELECT * FROM customer WHERE cust_ref = " + cust_ref + ";"; //Sql query to set the value of the sql variable in the database_facade
            cmd.CommandText = sql;                                                         //set the cmd command text to the sql statement
            sdr             = cmd.ExecuteReader();                                         // set the data reader equal tot the execute reader method
            customer_class cust = new customer_class();

            while (sdr.Read())
            {
                if (sdr.GetString(0) == cust_ref.ToString()) //if the value of the first column of the database table is equal to the customer reference
                {
                    custExists     = true;
                    cust.Ref       = Int32.Parse(sdr.GetString(0)); //Get the value of the first column from the database table
                    cust.LastName  = sdr.GetString(1);              //Get the value of the second column from the database table
                    cust.Firstname = sdr.GetString(2);
                    cust.Address   = sdr.GetString(3);
                }
            }

            if (custExists == false) //if the customer does not exist
            {
                MessageBox.Show("Customer does not exist. Try a diffrent customer reference");
            }
            else
            {
                Cur_customer_Singleton cur_cust = Cur_customer_Singleton.Instance(cust);
                Customer cust_Win = new Customer(); //create a new customer window
                //cust_Win.Owner = this;
                cust_Win.Show();

                /*
                 * The next lines will set the value of the text boxes to the previously save values
                 * This will make the text boxes fill in with their correct values
                 */
                cust_Win.txtBox_cust_ref.Text     = cust.Ref.ToString();
                cust_Win.txtBox_cust_last.Text    = cust.LastName;
                cust_Win.txtBox_cust_first.Text   = cust.Firstname;
                cust_Win.txtBox_cust_address.Text = cust.Address;
            }
            sdr.Close(); //closes the data reader - prevents leaks
            return(cust);
        }
예제 #2
0
 public static Cur_customer_Singleton Instance(customer_class cust)
 //Instance of customer where the customer data exists
 //a new instance of customer will be made, calling the previous method
 //if the customer instance is already non-existant
 {
     if (instance == null)
     {
         instance      = new Cur_customer_Singleton();
         instance.cust = cust;
         return(instance);
     }
     else
     //otherwise the existing instance of customer will be called
     {
         instance.cust = cust;
         return(instance);
     }
 }
        public int place_cust_ref()
        {
            int result = 0;

            sql             = "SELECT MAX(cust_ref) FROM customer;"; //ovverides the sql cariable contents
            cmd.CommandText = sql;                                   //set command text equal to the sql variable
            sdr             = cmd.ExecuteReader();
            while (sdr.Read())
            {
                result = Int32.Parse(sdr.GetString(0)); //set variable equal to the first column of the table
            }
            sdr.Close();

            //creating a new instance of the customer singelton
            customer_class         cust     = Select_Cust(result);
            Cur_customer_Singleton cust_sin = Cur_customer_Singleton.Instance(cust);

            return(result);
        }