Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 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 January 18th, 2007, 12:07 PM
Registered User
 
Join Date: Oct 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Mibble Send a message via Yahoo to Mibble
Default trying to create simple windows app, help please

the program is to loop through until someone pushes the exit, else there is a box to allow input, set as string, which is converted later on. while entering the only other button, (add) is to be greyed out until value entered. this is what i have thus far, am i going in the right direction? or should this be in the form1.designer.cs?

Code:
// Using Directives
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace SalesCalc
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());

            string txtSaleAmt;
            int txtNumSales = 0;
            double addingSales;
            double txtTtlSales = 0.00;
            double txtAvgSale;
            double txtCommDue = 0.00;
            double txtCommRate = 0.035;
            bool txtBonus = false;
            double txtBonusAmt = 0.00;
            double ttlCommDue;

            Console.WriteLine("enter amt");
            txtSaleAmt = Console.ReadLine();

            //Validation to perform
            if (validateInput(txtSaleAmt))
            {
                // convert string
                addingSales = Convert.ToInt32(Convert.ToDouble(txtSaleAmt));
                Console.WriteLine("amount is {0}", txtSaleAmt);
                txtTtlSales += addingSales;
                txtNumSales++;
                Console.WriteLine(" totalsales = {0}, adding = {1}, number sales = {2}", txtTtlSales, addingSales, txtNumSales);
                txtAvgSale = (txtTtlSales / txtNumSales);
                Console.WriteLine("average is {0}", txtAvgSale);
                if (txtTtlSales <= 500.00)
                {
                    txtCommRate = 0.035;
                }
                else if (txtTtlSales <= 999.99)
                {
                    txtCommRate = 0.04;
                }
                else
                {
                    txtCommRate = 0.05;
                }

                txtCommDue += (txtCommRate * addingSales);
                Console.WriteLine("commission due is {0} and rate is {1} and average is {2}", txtCommDue, txtCommRate, txtAvgSale);

                if (txtCommRate == 0.04)
                {
                    txtBonus = true;
                    txtBonusAmt = 25.00;
                    ttlCommDue = (txtCommDue + txtBonusAmt);
                }

                else if (txtCommRate == 0.05)
                {
                    txtBonus = true;
                    txtBonusAmt = 200.00;
                    ttlCommDue = (txtCommDue + txtBonusAmt);
                }
                else
                {
                    txtBonus = false;
                    ttlCommDue = txtCommDue;
                }
                txtCommDue += txtBonusAmt;
                Console.WriteLine("commission due is {0}", txtCommDue);

            }
        }

        // Function to Test for Positive Number both Integer & Real

        private static bool validateInput(string s)
        {
            Regex r = new Regex(@"^\d+(\.\d{1,2})?$");
            return r.IsMatch(s);
        }

    }

}





Similar Threads
Thread Thread Starter Forum Replies Last Post
implementing more than one windows in an app helloise C# 4 November 10th, 2008 12:42 PM
Beginner needs simple App Launcher jazzak Intro Programming 3 April 4th, 2008 03:16 PM
Windows Standalone app echovue Visual Basic 2005 Basics 3 March 12th, 2007 03:27 PM
Accessing Windows service from a windows app sajid08 C# 1 October 6th, 2006 10:25 AM
links in a windows app jeffruth VB.NET 2002/2003 Basics 1 April 26th, 2004 04:08 PM





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