3 Replies - 607 Views - Last Post: 05 July 2013 - 08:01 AM Rate Topic: -----

#1 switlovahuno  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 04-July 13

can't access my data in the textbook.

Posted 04 July 2013 - 09:38 PM

Here's my code. i'm trying to display my price and i want the prices to change with the quantity because i'm creating an ordering system
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;

namespace Ordering_system_V._1._1
{
    public partial class Form1 : Form
    {
        
        private String a1 = null;
        private String a2 = null;
        private String a3 = null;
        private String a4 = null;
        private String a5 = null;
        private String a6 = null;
        //2nd column
       
        private String b7 = null;
        private String b8 = null;
        private String b9 = null;
        private String b10 = null;
        private String b11 = null;
        private String b12 = null;
        private String b13 = null;
        private String b14 = null;
        private String b15 = null;        
        private String b16 = null;
//3rd column
        
        private String c17 = null;
        private String c18 = null;
        private String c19 = null;
        private String c20 = null;
        private String c21 = null;
        private String c22 = null;
        //4th column
        
        private String d23 = null;
        private String d24 = null;
        private String d25 = null;
        private String d26= null;
        private String d27= null;
        private String d28 = null;
        private String d29 = null;
        private String d30= null;
        private String d31= null;
        
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = null;
           
            textBox2.Text = null;
            
            checkBox1.Checked = false;

            checkBox2.Checked = false;

            checkBox3.Checked = false;

            checkBox4.Checked = false;

            checkBox5.Checked = false;

            checkBox6.Checked = false;

            checkBox7.Checked = false;

            checkBox8.Checked = false;

            checkBox9.Checked = false;

            checkBox10.Checked = false;

            checkBox11.Checked = false;

            checkBox12.Checked = false;

            checkBox13.Checked = false;

            checkBox14.Checked = false;

            checkBox15.Checked = false;

            checkBox16.Checked = false;

            checkBox17.Checked = false;

            checkBox18.Checked = false;

            checkBox19.Checked = false;

            checkBox20.Checked = false;

            checkBox21.Checked = false;

            checkBox22.Checked = false;

            checkBox23.Checked = false;

            checkBox24.Checked = false;

            checkBox25.Checked = false;

            checkBox26.Checked = false;

            checkBox27.Checked = false;

            checkBox28.Checked = false;

            checkBox29.Checked = false; 

             checkBox30.Checked = false;

             checkBox31.Checked = false;
             textBox3.Text = null;
             textBox4.Text = null;
             textBox5.Text = null;
             textBox6.Text = null;
             textBox7.Text = null;
             textBox8.Text = null;
             textBox9.Text = null;
             textBox10.Text = null;
             textBox11.Text = null;
             textBox12.Text = null;
             textBox13.Text = null;
             textBox14.Text = null; 
            textBox15.Text = null;
             textBox16.Text = null;
             textBox17.Text = null;
             textBox18.Text = null;
             textBox19.Text = null;
             textBox20.Text = null;
             textBox21.Text = null;
             textBox22.Text = null;
             textBox23.Text = null;
             textBox24.Text = null;
             textBox25.Text = null;
             textBox26.Text = null;
             textBox27.Text = null;
             textBox28.Text = null;
             textBox29.Text = null;
             textBox30.Text = null;
             textBox31.Text = null;
             textBox32.Text = null;        
             textBox33.Text = null;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            String name = textBox1.Text;

            String surname = textBox2.Text;

            String q1 = textBox3.Text;
            String q2 = textBox5.Text;
            String q3 = textBox6.Text;
            String q4 = textBox7.Text;
            String q5 = textBox8.Text;
            String q6 = textBox9.Text;
            String q7 = textBox4.Text;
            String q8 = textBox10.Text;
            String q9 = textBox11.Text;
            String q10 = textBox12.Text;
            String q11 = textBox13.Text;
            String q12 = textBox14.Text;
            String q13 = textBox15.Text;
            String q14 = textBox16.Text;
            String q15 = textBox17.Text;
            String q16 = textBox18.Text;
            String q17 = textBox19.Text;
            String q18 = textBox20.Text;
            String q19 = textBox21.Text;
            String q20 = textBox22.Text;
            String q21 = textBox23.Text;
            String q22 = textBox24.Text;
            String q23 = textBox25.Text;
            String q24 = textBox26.Text;
            String q25 = textBox27.Text;
            String q26 = textBox28.Text;
            String q27 = textBox29.Text;
            String q28 = textBox30.Text;
            String q29 = textBox31.Text;
            String q30 = textBox32.Text;
            String q31 = textBox33.Text;
            



            //result window
            MessageBox.Show("Name: " + name + "\nSurname: " + surname + "\norder: " + q1 + a1 + q2 + a2 + q3 + a3 + q4 + a4 + q5 + a5 + q6 + a6 + q7 + b7 + q8 + b8 + q9 + b9 + q10 + b10 + q11 + b11 + q12 + b12 + q13 + b13 + q14 + b14 + q15 + b15 + q16 + b16 + q17 + c17 + q18 + c18 + q19 + c19 + q20 + c20 + q21 + c21 + q22 + c22 + q23 + d23 + q24 + d24 + q25 + d25 + q26 + d26 + q27 + d27 + q28 + d28 + q29 + d29 + q30 + d30 + q31 + d31, "Confirm Your Order!", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);
           

        }
        

        
        
    
    
       

       
        //first column

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked == true)

                {
                    
                a1 = " Beef Burger, ";
                

                }
            else
            {
                a1 = null;
            }

                    
        }
        

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
             if
                (checkBox2.Checked)

                {

                a2 = " Cheese Burger, ";

                }
                
            else
                    {
                        a2 = null;
                    }

                    
        }
        

        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox3.Checked)
            {

                a3 = " Spicy Chicken Burger, ";

            }
            else
            {
                a3 = null;
            }


        }

        private void checkBox4_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox4.Checked)
            {

                a4 = " Double Cheese Burger, ";

            }
            else
            {
                a4 = null;
            }
        }

        private void checkBox5_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox5.Checked)
            {

                a5 = " File-O-Fish, ";

            }
            else
            {
                a5 = null;
            }
        }

        private void checkBox6_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox6.Checked)
            {

                a6 = " 6Pcs Chicken Mc Nugget, ";

            }
            else
            {
                a6 = null;
            }
        }
        //2nd column

        private void checkBox7_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox7.Checked)
            {

                b7 = " McRoyale, ";

            }
            else
            {
                b7 = null;
            }
        }

        private void checkBox8_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox8.Checked)
            {

                b8 = " Quarter pounder with cheese, ";

            }
            else
            {
                b8 = null;
            }
        }
        private void checkBox9_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox9.Checked)
            {

                b9 = " Big Mac, ";

            }
            else
            {
                b9 = null;
            }
        }

        private void checkBox10_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox10.Checked)
            {

                b10 = " 9 Pcs Chicken McNuggets, ";

            }
            else
            {
                b10 = null;
            }
        }

        private void checkBox11_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox11.Checked)
            {

                b11 = " 20 Pcs Chicken McNuggets, ";

            }
            else
            {
                b11 = null;
            }
        }

        private void checkBox12_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox12.Checked)
            {

                b12 = " Spicy McCrispy Chicken Deluxe, ";

            }
            else
            {
                b12 = null;
            }
        }

        private void checkBox13_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox13.Checked)
            {

                b13 = " McArabia Chicken, ";

            }
            else
            {
                b13 = null;
            }
        }

        private void checkBox14_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox14.Checked)
            {

                b14 = " McChicken, ";

            }
            else
            {
                b14 = null;
            }
        }

        private void checkBox15_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox15.Checked)
            {

                b15 = " Chicken Big Mac, ";

            }
            else
            {
                b15 = null;
            }
        }

        private void checkBox16_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox16.Checked)
            {

                b16 = " Big Tasty, ";

            }
            else
            {
                b16 = null;
            }
        }

        
//3rd column
        private void checkBox17_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox17.Checked)
            {

                c17 = " Chicken Sausage Mcmuffin with Egg, ";

            }
            else
            {
                c17 = null;
            }

        }

        private void checkBox18_CheckedChanged(object sender, EventArgs e)
        {

            if (checkBox18.Checked)
            {

                c18 = " Egg McMuffin, ";

            }
            else
            {
                c18 = null;
            }
        }

        private void checkBox19_CheckedChanged(object sender, EventArgs e)
        {

            if (checkBox19.Checked)
            {

                c19 = " Chicken Sausage McMuffin, ";

            }
            else
            {
                c19 = null;
            }
        }

        private void checkBox20_CheckedChanged(object sender, EventArgs e)
        {

            if (checkBox20.Checked)
            {

                c20 = " Egg & Cheese McMuffin, ";

            }
            else
            {
                c20 = null;
            }
        }

        private void checkBox21_CheckedChanged(object sender, EventArgs e)
        {

            if (checkBox21.Checked)
            {

                c21 = " Hash Browns (single), ";

            }
            else
            {
                c21 = null;
            }
        }

        private void checkBox22_CheckedChanged(object sender, EventArgs e)
        {

            if (checkBox22.Checked)
            {

                c22 = "Orange/tropical Juice, ";

            }
            else
            {
                c22 = null;
            }
        }

        //4th column

        private void checkBox23_CheckedChanged(object sender, EventArgs e)
        {

            if (checkBox23.Checked)
            {

                d23 = "Big Breakfast, ";

            }
            else
            {
                d23 = null;
            }
        }

        private void checkBox24_CheckedChanged(object sender, EventArgs e)
        {

            if (checkBox24.Checked)
            {

                d24 = "Chicken Sausage McMuffin with Egg + Hash Browns + Small Cappucino, ";

            }
            else
            {
                d24 = null;
            }
        }

        private void checkBox25_CheckedChanged(object sender, EventArgs e)
        {

            if (checkBox25.Checked)
            {

                d25 = "Egg McMuffin + Hash Browns + Small Cappuccino, ";

            }
            else
            {
                d25 = null;
            }
        }

        private void checkBox26_CheckedChanged(object sender, EventArgs e)
        {

            if (checkBox26.Checked)
            {

                d26 = "Chicken Sausage McMuffin + Hash Browns + Small Cappuccino, ";

            }
            else
            {
                d26 = null;
            }
        }

        private void checkBox27_CheckedChanged(object sender, EventArgs e)
        {

            if (checkBox27.Checked)
            {

                d27 = "Egg & Cheese McMuffin + Hash Browns + Small Cappuccino, ";

            }
            else
            {
                d27 = null;
            }
        }

        private void checkBox28_CheckedChanged(object sender, EventArgs e)
        {

            if (checkBox28.Checked)
            {

                d28 = "Chicken Sausage McMuffin with Egg + Small Cappuccino, ";

            }
            else
            {
                d28 = null;
            }
        }

        private void checkBox29_CheckedChanged(object sender, EventArgs e)
        {

            if (checkBox29.Checked)
            {

                d29 = "Egg McMuffin + Small Cappuccino, ";

            }
            else
            {
                d29 = null;
            }
        }

        private void checkBox30_CheckedChanged(object sender, EventArgs e)
        {

            if (checkBox30.Checked)
            {

                d30 = "Chicken Sausage McMuffin + Small Cappuccino, ";

            }
            else
            {
                d30 = null;
            }
        }

        private void checkBox31_CheckedChanged(object sender, EventArgs e)
        {

            if (checkBox31.Checked)
            {

                d31 = "Egg & Cheese McMuffin + Small Cappuccino, ";

            }
            else
            {
                d31 = null;
            }
        }

        private void textBox14_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox18_TextChanged(object sender, EventArgs e)
        {

        }

    

        }
    
}


This post has been edited by Skydiver: 04 July 2013 - 10:09 PM
Reason for edit:: Put code in code tags. What did you not understand in the instructions?


Is This A Good Question/Topic? 0
  • +

Replies To: can't access my data in the textbook.

#2 MrShoes  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 331
  • View blog
  • Posts: 512
  • Joined: 13-June 12

Re: can't access my data in the textbook.

Posted 05 July 2013 - 12:55 AM

Stop what you're doing. You need to plan the architecture and rebuild the application. Learn object-oriented design and this is going to be a LOT easier to read, understand, debug, and extend.

You need to remove the Form's tight coupling of the data. Consider making an OrderableItem class, so anything (food, drink etc) can be of that type. Give it a name and a price. Have an Order class, and have that hold a collection of OrderableItems, populate based on the user's orders. Then you can add to and remove from that collection. It can have a method to get you the total order price, based on summing every price in the OrderableItems collection. Then go about creating a form to allow user input, that interacts with these objects.

Use a DataGridView for grids of data. I don't know where you picked up this idea of storing them in individually named strings, but even a 2 dimensional array of strings would have been much better.

Name your variables based on their purpose. What is a b7? It tells you nothing about what it is.

What course/tutorials/textbook are you following?
Was This Post Helpful? 2
  • +
  • -

#3 Michael26  Icon User is offline

  • Futurama: Insert funny joke here
  • member icon

Reputation: 414
  • View blog
  • Posts: 1,664
  • Joined: 08-April 09

Re: can't access my data in the textbook.

Posted 05 July 2013 - 01:19 AM

Hehe MrShoes is right, try to come back to this program in 6 months or a year and try to figure out what you were doing, try to remember what b7 is, or actually try and add another functionality to the program and you'll see what we are talking about.
Was This Post Helpful? 1
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6507
  • View blog
  • Posts: 14,379
  • Joined: 02-June 10

Re: can't access my data in the textbook.

Posted 05 July 2013 - 08:01 AM

Some of my common tips (some may apply more than others to your specific style):
  • Take the extra 3 seconds to rename your controls each time you drag them onto a form. The default names of button1, button2... button54 aren't very helpful. If you rename them right away to something like btnOk, btnCancel, btnSend etc. it helps tremendously when you make the methods for them because they are named after the button by the designer.btnSend_Click(object sender, eventargs e) is a lot easier to maintain than button1_click(object sender, eventargs e)

  • You aren't paying for variable names by the byte. So instead of variables names of a, b, c go ahead and use meaningful names like index, timeOut, row, column and so on. You should avoid 'T' for the timer. Amongst other things 'T' is commonly used throughout C# for Type and this will lead to problems. There are naming guidelines you should follow so your code confirms to industry standards. It makes life much easier on everyone around you, including those of us here to help. If you start using the standards from the beginning you don't have to retrain yourself later.
    You might want to look at some of the naming guidelines. Its a lot easier to start with good habits than to break bad habits later and re-learn.



  • Don't use your GUI objects as your variable. In other words don't keep referencing TextBox4.Text everyplace. TextBox4.Text is not a variable or property. The GUI is on its own thread so as soon as you start doing multi-threading you're screwed because your worker thread can't access the GUI elements. Use properties.

  • Try to avoid having work actually take place in GUI control event handlers. It is better to have the GUI handler call other methods so those methods can be reused and make the code more readable. This is also how you can send parameters rather than use excessive global variables. Get in this habit even if you are using WinForms because WPF works a lot under the idea of "commands" and this will get you working towards that. Think of each gester, control click, menu option etc. as a command to do something such as a command to SAVE. It doesn't matter where the command comes from, all sources should point at the same target to do the actual saving.
    Spoiler


  • Don't replace lines of code that don't work. Instead comment them out and put your new attempts below that. This will keep you from re-trying the same ideas over and over. Also, when you come back to us saying "I've tried this 100 different ways and still can't get it", we can actually see what you tried. So often a failed attempt is very very close and just needs a little nudge in the right direction. So if we can say "See what you did in attempt 3... blah blah" it helps a lot

    Spoiler

    If you are using Visual Studio you can select a block of lines and hit control+k control+c (Kode Comment) to comment it out. control+k control+u (Kode Uncomment) to uncomment a selected block.


  • You have to program as if everything breaks, nothing works, the cyberworld is not perfect, the attached hardware is flakey, the network is slow and unreliable, the harddrive is about to fail, every method will return an error and every user will do their best to break your software. Confirm everything. Range check every value. Make no assumptions or presumptions.

  • I strongly suggest installing VMware or some other virtualization technology on your development PC so you can create a couple virtual computers for testing. This would allow you to debug and test inside: WinXP32, XP64, Vista, Win7x32, Win7x64... etc. without having to actually have 5 physical PC's. Visual Studio will let you send the debug directly into one of these virtual machines so you can watch it operate, check its variables, see the crashes and so on just as if it were debugging on your real machine.


Also - Since this is all equally new to you anyway - just skip over WinForms and do this in WPF. You can bind your GUI to object properties... and be using XAML which is the future of design not WinForms which is quickly passing away.

Quote

010 namespace Ordering_system_V._1._1


Don't put version numbers in the name space. Or periods either.

Just make it "Ordering system". Use the properties of the Visual Studio Solution to set the version number.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1