예제 #1
0
        private void btnEqual_Click(object sender, EventArgs e)
        {
            if ((txtOutput.Text != "") && (bEnableEquals == true)) // Only take an action if txtOutput is not empty and
            {                                                      // Button Equals is enabled
                bEnableEquals = false;
                try
                {
                    decimal dTemp = 0;
                    dTemp = Convert.ToDecimal(txtOutput.Text);
                    Calc.Equals(dTemp);                         // Calc.Equals will take dTemp as Operand2 and perform the calculus previously set
                    txtOutput.Text  = Calc.Operand1.ToString(); // The result of the calculus is stored in Operand1.
                    bClearTxtOutput = true;                     // Next digit will requires txtOutput to be cleared

                    // Save the LOG into History file
                    HistoryGen Historic = new HistoryGen(Application.StartupPath);
                    Historic.UpdateLog("CalculatorLog.txt", Calc.Log);
                }
                catch (Exception ex1)
                {
                    MessageBox.Show("Invalid number format\n" + ex1.Message, "Wrong number format", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtOutput.Text  = "";       // Clear txtOutput content
                    bClearTxtOutput = false;    // Next digit does not requires an empty content in txtOutput
                    Calc.Clear();               // Set all variables in Calc object to their default values
                }
            }
        }
예제 #2
0
        private void btnConvert_Click(object sender, EventArgs e)
        {
            labelMsg.Text  = "";
            txtOutput.Text = "";

            MoneyExchange MoneyEx  = new MoneyExchange();
            HistoryGen    Historic = new HistoryGen(Application.StartupPath);

            if ((txtInput.Text.Length > 0) && (labelFrom.Text != "") && (labelTo.Text != ""))    // Only take an action if the txtInput is not empt
            {
                if ((labelFrom.Text == labelTo.Text))
                {
                    txtOutput.Text = txtInput.Text;
                    return;
                }
                decimal inputValue = 0;
                try
                {
                    inputValue     = Convert.ToDecimal(txtInput.Text); // Convert to decimal the value entered by user
                    txtOutput.Text = MoneyEx.CurrencyConversion(inputValue, labelFrom.Text, labelTo.Text);
                    labelMsg.Text  = MoneyEx.SourceLastConversion;

                    // Add the string log generated by the MeneyEx object to the historic file
                    Historic.UpdateLog("MoneyExchange.txt", MoneyEx.MsgLog);
                }
                catch (Exception ex1)
                {
                    MessageBox.Show("Invalid Currency Format\n" + ex1.Message, "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtInput.Text = "";
                    return;
                }
            }
        }
예제 #3
0
        private void logToolStripMenuItem_Click(object sender, EventArgs e)
        {
            HistoryGen Historic      = new HistoryGen(Application.StartupPath);
            string     CalculatorLog = Historic.ReadLog("CalculatorLog.txt");
            frmLog     formLog       = new frmLog(CalculatorLog, "CalculatorLog");

            formLog.ShowDialog();
        }
예제 #4
0
        private void btnReadFile_Click(object sender, EventArgs e)
        {
            HistoryGen Historic         = new HistoryGen(Application.StartupPath);
            string     MoneyExchangeLog = Historic.ReadLog("MoneyExchange.txt");
            frmLog     formLog          = new frmLog(MoneyExchangeLog, "MoneyExchangeLog");

            formLog.ShowDialog();
        }
        private void btnConvert_Click(object sender, EventArgs e)
        {
            DateTime CurrentDateTime = DateTime.Now;                        // Get current date and time for the Log string

            if (txtInput.Text != "")                                        // Only take an action if txtInput is not empty
            {
                TemperatureConverter TempConv = new TemperatureConverter(); // Create and object TempConv of the class TemepratureConverter
                try
                {
                    TempConv.ValueToConvert = Convert.ToDouble(txtInput.Text); // Get the value to be converted
                    string strLog = txtInput.Text;                             // strLog will hold the log of current conversion
                    if (rdrCtoF.Checked == true)                               // Is it set to convert from Celsius to Fahrenheit?

                    {
                        txtOutput.Text = Convert.ToString(TempConv.ToFahrenheint());  // Call convertion method ToFahrenheit
                        // Add to Log string the convertion the date and time
                        strLog = strLog + " C = " + txtOutput.Text + " F,    " + CurrentDateTime.ToString();
                    }
                    else                                                         // Convert from Celsius to Fahrenheit?
                    {
                        txtOutput.Text = Convert.ToString(TempConv.ToCelsius()); //Call conversion Method ToCelsius
                        // Add to Log string the convertion the date and time
                        strLog = strLog + " F = " + txtOutput.Text + " C,    " + CurrentDateTime.ToString();
                    }
                    string stemp = TempConv.GetMessage();                                       // Get Class Message from Last conversion
                    if (TempConv.bIsExactValue == true)                                         // If the result is an exactValue, the txtMessage will be writen in bold.
                    {
                        txtMessage.Font = new Font("Microsoft Sans Serif ", 9, FontStyle.Bold); //Set font to Bold
                    }
                    else
                    {
                        txtMessage.Font = new Font("Microsoft Sans Serif", 9, FontStyle.Regular); // Set font to regular
                    }
                    txtMessage.Text = stemp;


                    // Save the LOG into History file
                    HistoryGen Historic = new HistoryGen(Application.StartupPath);
                    Historic.UpdateLog("TemperatureLog.txt", strLog);
                }
                catch (Exception ex1)
                {  // User has entered an invalid data format
                    MessageBox.Show("Please enter a numerical value to be converted \n" + ex1.Message, "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtInput.Text  = "";
                    txtOutput.Text = "";
                }
            }
        }
예제 #6
0
        private void brnGenerate_Click(object sender, EventArgs e)
        {
            int      numOfNUmbers    = 7; // Default number of numbers to be generated (will be used in Loto949)
            Random   random          = new Random();
            int      randomNumber    = 0;
            string   log             = "Lotto 649, "; //Default Name of Lotto to be inserted in the Historic Log = Lotto 649
            DateTime CurrentDateTime = DateTime.Now;

            //===============================================================================================
            // The current Text of this form will be set by the calling button in DashBoard form.
            // if this form were called by Lotto Max button, the text of the form will be set as "Lotto Max"
            // if this form were called by Lotto 649 button, the text of the form will be set as "Lotto 649"
            // The form icon, will also be set likewise.
            //===============================================================================================
            if (this.Text == "Lotto Max - Leandro Fortunato") //Check if it is generating Lotto Max numbers.
            {
                //"Max,7 / 21 / 2017 2:17:36 PM, 40,33,12,06,36,04,18 Extra 29"
                log          = "Lotto Max, ";
                numOfNUmbers = 8;
            }

            List <int> randomList = new List <int>();         // create a list to hold the random numbers

            for (int counter = 0; counter < numOfNUmbers;)    // This for loop generate 7 or 8 random number
            {
                randomNumber = random.Next(1, 49);
                if (!randomList.Contains(randomNumber))                    // Check if the generated number is already in the list.
                {
                    randomList.Add(randomNumber);                          // If its not in the list add it to the list
                    textBox1.Text = textBox1.Text + "\r\n" + randomNumber; // Show the sorted number in the output textbox
                    counter++;                                             // Only increment the counter in for loop if a new number was inserted into the list
                }
            }

            // Add a line to make easier to user to find out the new set of numbers
            textBox1.Text = textBox1.Text + "\r\n" + "==================================\n";

            //The following lines, scroll down the text box in order to show the  new set of numbers...
            textBox1.SelectionStart = textBox1.Text.Length;
            textBox1.ScrollToCaret();

            string sNumbers = "";  // This temporary string variable will hold the numbers to be saved in the historic file

            for (int counter = 0; counter < (numOfNUmbers); counter++)
            {
                if (counter == (numOfNUmbers - 1))  // if it is the last number add the "Extra "
                {
                    sNumbers = sNumbers + "Extra " + randomList[counter].ToString();
                }
                else  // Insert the number in the list to the log string
                {
                    sNumbers = sNumbers + randomList[counter].ToString() + ", ";
                }
            }
            // Build up the Log string adding current date and time and the generated numbers
            log = log + CurrentDateTime.ToString() + ", " + sNumbers;


            // Save the LOG into History file
            HistoryGen Historic = new HistoryGen(Application.StartupPath);

            Historic.UpdateLog("LottoLog.txt", log);
        }