예제 #1
0
        public void OnSelectNumber(object sender, EventArgs e)
        {
            if (CurrentState < 0)
            {
                CurrentState = CurrentState * -1;
            }

            Button clicked = (Button)sender;
            string number;

            if (CurrentState == 1)
            {
                number          = FirstNumber.ToString();
                number          = number + clicked.Text;
                FirstNumber     = double.Parse(number);
                ResultText.Text = FirstNumber.ToString();
            }
            else
            {
                number          = SecondNumber.ToString();
                number          = number + clicked.Text;
                SecondNumber    = double.Parse(number);
                ResultText.Text = SecondNumber.ToString();
            }
        }
예제 #2
0
        /// <summary>Генерирует случайное число.</summary>
        private void GenerateRandomNumber()
        {
            FirstNumber.GenerateRandomValue();

            while (FirstNumber.Value == 0)
            {
                FirstNumber.GenerateRandomValue();
            }

            SecondNumber.GenerateRandomValue();

            while (SecondNumber.Value == FirstNumber.Value)
            {
                SecondNumber.GenerateRandomValue();
            }

            ThirdNumber.GenerateRandomValue();

            while (ThirdNumber.Value == FirstNumber.Value || ThirdNumber.Value == SecondNumber.Value)
            {
                ThirdNumber.GenerateRandomValue();
            }

            FourthNumber.GenerateRandomValue();

            while (FourthNumber.Value == FirstNumber.Value ||
                   FourthNumber.Value == SecondNumber.Value ||
                   FourthNumber.Value == ThirdNumber.Value)
            {
                FourthNumber.GenerateRandomValue();
            }
        }
예제 #3
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (FirstNumber != 0)
            {
                hash ^= FirstNumber.GetHashCode();
            }
            if (SecondNumber != 0)
            {
                hash ^= SecondNumber.GetHashCode();
            }
            if (ThirdNumber != 0)
            {
                hash ^= ThirdNumber.GetHashCode();
            }
            if (FourthNumber != 0)
            {
                hash ^= FourthNumber.GetHashCode();
            }
            if (FifthNumber != 0)
            {
                hash ^= FifthNumber.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
        protected override void Execute(CodeActivityContext context)
        {
            FirstNumber.Set(context, 0);
            SecondNumber.Set(context, 0);
            Operation.Set(context, CalculatorOperation.Unknown);

            String line = Expression.Get(context);

            if (!String.IsNullOrEmpty(line))
            {
                String[] arguments = line.Split(' ');
                if (arguments.Length == 3)
                {
                    Double number = 0;
                    if (Double.TryParse(arguments[0], out number))
                    {
                        FirstNumber.Set(context, number);
                    }

                    CalculatorOperation op = CalculatorOperation.Unknown;
                    Enum.TryParse <CalculatorOperation>(arguments[1], out op);
                    Operation.Set(context, op);

                    if (Double.TryParse(arguments[2], out number))
                    {
                        SecondNumber.Set(context, number);
                    }
                }
            }
        }
예제 #5
0
 void MaindataGrid_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
 {
     try
     {
         if (датаToolStripMenuItem.Checked)
         {
             DateTime FirstDate;
             DateTime SecondDate;
             DateTime.TryParse(e.CellValue1.ToString(), out FirstDate);
             DateTime.TryParse(e.CellValue2.ToString(), out SecondDate);
             e.SortResult = DateTime.Compare(FirstDate, SecondDate);
         }
         if (числоToolStripMenuItem.Checked)
         {
             int FirstNumber;
             int SecondNumber;
             int.TryParse(e.CellValue1.ToString(), out FirstNumber);
             int.TryParse(e.CellValue2.ToString(), out SecondNumber);
             e.SortResult = String.Compare(FirstNumber.ToString("00000000000"), SecondNumber.ToString("00000000000"), StringComparison.Ordinal);
         }
         if (текстпоУмолчаниюToolStripMenuItem.Checked)
         {
             e.SortResult = String.Compare(e.CellValue1.ToString(), e.CellValue2.ToString(), StringComparison.Ordinal);
         }
         e.Handled = true;
     }
     catch (Exception exc)
     {
         MessageBox.Show(exc.Message);
         LogManager.Log.AddToLog(AppDir, exc);
     }
 }
예제 #6
0
 public override void WriterAddAttribute(XmlWriter writer)
 {
     writer.WriteAttributeString("FirstNumber", FirstNumber.ToString());
     writer.WriteAttributeString("LastNumber", LastNumber.ToString());
     writer.WriteAttributeString("StepNumber", StepNumber.ToString());
     base.WriterAddAttribute(writer);
 }
예제 #7
0
        protected override void Execute(CodeActivityContext context)
        {
            FirstNumber.Set(context, 0);
            SecondNumber.Set(context, 0);
            Operation.Set(context, "error");

            String line = Expression.Get(context);

            if (!String.IsNullOrEmpty(line))
            {
                String[] arguments = line.Split(' ');
                if (arguments.Length == 3)
                {
                    Double number = 0;
                    if (Double.TryParse(arguments[0], out number))
                    {
                        FirstNumber.Set(context, number);
                    }
                    Operation.Set(context, arguments[1]);
                    if (Double.TryParse(arguments[2], out number))
                    {
                        SecondNumber.Set(context, number);
                    }
                }
            }
        }
예제 #8
0
        /// <summary>
        /// Run backward counter on valid arguments
        /// </summary>
        /// <returns>Counter result if valid else return error</returns>
        public string PrintBackwardCount()
        {
            // List of backwardCount
            List <string> bakcwardCount = new List <string>();

            // Check if valid
            if (IsValid)
            {
                // First number is greater than 1 and First number is divisible by Second Number
                while ((FirstNumber > 1) && (FirstNumber % SecondNumber == 0))
                {
                    // Add First number to list
                    bakcwardCount.Add(FirstNumber.ToString());
                    // Deduct FirstNumber By SecondNumber
                    FirstNumber -= SecondNumber;
                }
            }
            else
            {
                // Return Error
                return("Error: " + Status);
            }
            // Join the list by space
            return(string.Join(" ", bakcwardCount));
        }
예제 #9
0
        protected override void Execute(CodeActivityContext context)
        {
            var firstNumber  = FirstNumber.Get(context);
            var secondNumber = SecondNumber.Get(context);
            var result       = System.Math.Pow(firstNumber + secondNumber, 2);

            ResultNumber.Set(context, result);
        }
예제 #10
0
        protected override void Execute(CodeActivityContext context)
        {
            double firstNumber  = FirstNumber.Get(context);
            double secondNumber = SecondNumber.Get(context);

            HelperMethod method = new HelperMethod();
            var          result = method.sumTwoNumber(firstNumber, secondNumber);

            ResultNumber.Set(context, result);
        }
예제 #11
0
        /// <summary>
        /// Runs the main logic of the activity. Has access to the context,
        /// which holds the values of properties for this activity and those from the parent scope.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            var property = context.DataContext.GetProperties()[ParentScope.ApplicationTag];
            var app      = property.GetValue(context.DataContext) as Application;

            var firstValue  = FirstNumber.Get(context);
            var secondValue = SecondNumber.Get(context);

            var sum = app.Sum(firstValue, secondValue);

            return(ctx =>
            {
                Sum.Set(ctx, sum);
            });
        }
예제 #12
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (FirstNumber.Length != 0)
            {
                hash ^= FirstNumber.GetHashCode();
            }
            if (LastNumber.Length != 0)
            {
                hash ^= LastNumber.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
        void OnSelectNumber(object sender, EventArgs e)
        {
            Button button  = (Button)sender;
            string pressed = button.Text;

            if (Contador > 0)
            {
                acumulador.Append(pressed);
                SecondNumber           = Convert.ToDouble(acumulador.ToString());
                this.txtAcumulado.Text = this.txtAcumulado.Text + acumulador[acumulador.Length - 1];
            }
            else
            {
                acumulador.Append(pressed);
                FirstNumber            = Convert.ToDouble(acumulador.ToString());
                this.txtAcumulado.Text = FirstNumber.ToString();
            }
        }
예제 #14
0
        public Questions(Difficulty difficulty)
        {
            this.Sign = User.operations;
            var x = GeneraterRandomNumber(difficulty);
            var y = GeneraterRandomNumber(difficulty);

            int[] arr = new int[2];

            arr = CheckIfEqual(x, y, difficulty);



            if (CheckAdd())
            {
                this.FirstNumber  = arr[0];
                this.SecondNumber = arr[1];
                this.QuestionAdd  = FirstNumber.ToString() + "+" + SecondNumber.ToString() + "=";
                this.Answer       = GetAnswer(Sign[0], FirstNumber, SecondNumber);
            }
            else if (CheckSubtract())
            {
                this.FirstNumber      = arr[0];
                this.SecondNumber     = arr[1];
                this.QuestionSubtract = FirstNumber.ToString() + "-" + SecondNumber.ToString() + "=";
                this.Answer           = GetAnswer(Sign[0], FirstNumber, SecondNumber);
            }
            else if (CheckMultiply())
            {
                //arr = CheckForDivide(arr, difficulty);
                this.FirstNumber      = arr[0];
                this.SecondNumber     = arr[1];
                this.QuestionMultiply = FirstNumber.ToString() + "X" + SecondNumber.ToString() + "=";
                this.Answer           = GetAnswer(Sign[0], FirstNumber, SecondNumber);
            }
            else if (CheckDivide())
            {
                arr = CheckForDivide(arr, difficulty);
                this.FirstNumber   = arr[0];
                this.SecondNumber  = arr[1];
                this.QuestionDivde = FirstNumber.ToString() + "÷" + SecondNumber.ToString() + "=";
                this.Answer        = GetAnswer(Sign[0], FirstNumber, SecondNumber);
            }
        }
예제 #15
0
        static void Main(string[] args)
        {
            const double MAGIC_NUMBER = 7.777; // local variable that is a constant

            // Can't do this because it is a cosntant value MAGIC_NUMBER = 8;
            ClassLevelVariable = 8;

            double FirstNumber;
            double SecondNumber;
            double ThirdNumber;

            Console.WriteLine("Please enter first number");
            string answer1 = Console.ReadLine();

            FirstNumber = Convert.ToDouble(answer1);

            Console.WriteLine("Please enter second number");
            string answer2 = Console.ReadLine();

            SecondNumber = Convert.ToDouble(answer2);

            Console.WriteLine("Please enter third number");
            string answer3 = Console.ReadLine();

            ThirdNumber = Convert.ToDouble(answer3);



            double sum = FirstNumber + SecondNumber + ThirdNumber;

            Console.WriteLine("The result of " + FirstNumber.ToString("N3") + " + " +
                              SecondNumber.ToString("N3") + " + " + ThirdNumber.ToString("N3") + " = " + sum.ToString("N3"));


            double product = sum * MAGIC_NUMBER;

            Console.WriteLine("The result of " + sum.ToString("N") + " * " + MAGIC_NUMBER + " = " + product.ToString("N3"));
        }
예제 #16
0
 // Function to return addition expression (in string) for the quiz
 public string Expression()
 {
     return(String.Format(EXPRESSION_FORMAT, FirstNumber.ToString(),
                          SecondNumber.ToString(), Output.ToString()));
 }
예제 #17
0
 static void UpdateFirstNumber(this FirstNumber firstNumber, FirstNumberViewModel firstNumberViewModel)
 {
     firstNumber.ID        = firstNumberViewModel.ID;
     firstNumber.NetworkID = firstNumberViewModel.NetworkID;
     firstNumber.Number    = firstNumberViewModel.Number;
 }
예제 #18
0
        public string NumberToThaiWord(double InputNumber)
        {
            string result;

            if (InputNumber == 0)
            {
                result = "ศูนย์บาทถ้วน";
                return(result);
            }

            string NewInputNumber;

            NewInputNumber = InputNumber.ToString("###0.00");
            if (Convert.ToDouble(NewInputNumber) >= 10000000000000)
            {
                result = "";
                return(result);
            }

            string[] tmpNumber = new string[2];
            string   FirstNumber;
            string   LastNumber;

            tmpNumber   = NewInputNumber.Split(Convert.ToChar("."));
            FirstNumber = tmpNumber[0];
            LastNumber  = tmpNumber[1];

            int nLength = 0;

            nLength = Convert.ToInt32(FirstNumber.Length);

            int    CNumber     = 0;
            int    CNumberBak  = 0;
            string strNumber   = "";
            string strPosition = "";
            string FinalWord   = "";
            int    CountPos    = 0;

            for (int i = nLength; i >= 1; i--)
            {
                CNumberBak = CNumber;
                CNumber    = Convert.ToInt32(FirstNumber.Substring(CountPos, 1));

                if (CNumber == 0 && i == 7)
                {
                    strPosition = "ล้าน";
                }
                else if (CNumber == 0)
                {
                    strPosition = "";
                }
                else
                {
                    strPosition = PositionToText(i);
                }

                if (CNumber == 2 && strPosition == "สิบ")
                {
                    strNumber = "ยี่";
                }
                else if (CNumber == 1 && strPosition == "สิบ")
                {
                    strNumber = "";
                }
                else if (CNumber == 1 && strPosition == "ล้าน" && nLength >= 8)
                {
                    if (CNumberBak == 0)
                    {
                        strNumber = "หนึ่ง";
                    }
                    else
                    {
                        strNumber = "เอ็ด";
                    }
                }
                else if (CNumber == 1 && strPosition == "" && nLength > 1)
                {
                    strNumber = "เอ็ด";
                }
                else
                {
                    strNumber = NumberToText(CNumber);
                }

                CountPos  = CountPos + 1;
                FinalWord = FinalWord + strNumber + strPosition;
            }

            CountPos   = 0;
            CNumberBak = 0;
            nLength    = Convert.ToInt32(LastNumber.Length);

            string Stang      = "";
            string FinalStang = "";

            if (Convert.ToDouble(LastNumber) > 0)
            {
                for (int i = nLength; i >= 1; i--)
                {
                    CNumberBak = CNumber;
                    CNumber    = Convert.ToInt32(LastNumber.Substring(CountPos, 1));
                    if (CNumber == 1 && i == 2)
                    {
                        strPosition = "สิบ";
                    }
                    else if (CNumber == 0)
                    {
                        strPosition = "";
                    }
                    else
                    {
                        strPosition = PositionToText(i);
                    }

                    if (CNumber == 2 && strPosition == "สิบ")
                    {
                        Stang = "ยี่";
                    }
                    else if (CNumber == 1 && i == 2)
                    {
                        Stang = "";
                    }
                    else if (CNumber == 1 && strPosition == "" && nLength > 1)
                    {
                        if (CNumberBak == 0)
                        {
                            Stang = "หนึ่ง";
                        }
                        else
                        {
                            Stang = "เอ็ด";
                        }
                    }
                    else
                    {
                        Stang = NumberToText(CNumber);
                    }

                    CountPos   = CountPos + 1;
                    FinalStang = FinalStang + Stang + strPosition;
                }

                FinalStang = FinalStang + "สตางค์";
            }
            else
            {
                FinalStang = "";
            }

            string SubUnit;

            if (FinalStang == "")
            {
                SubUnit = "บาทถ้วน";
            }
            else
            {
                if (Convert.ToDouble(FirstNumber) != 0)
                {
                    SubUnit = "บาท";
                }
                else
                {
                    SubUnit = "";
                }
            }

            result = FinalWord + SubUnit + FinalStang;
            return(result);
        }
예제 #19
0
 public FirstNumber Add(FirstNumber firstNumber)
 {
     return(_firstNumberRepository.Add(firstNumber));
 }
예제 #20
0
 public void Update(FirstNumber firstNumber)
 {
     _firstNumberRepository.Update(firstNumber);
 }
예제 #21
0
 private void Clear_Click(object sender, EventArgs e)
 {
     FirstNumber.Clear();
     SecondNumber.Clear();
     Sum.Text = "Sum";
 }
예제 #22
0
 /// <summary>
 /// Validates the result.
 /// </summary>
 /// <returns></returns>
 protected override bool ValidateResult()
 {
     return(FirstNumber.CompareTo(SecondNumber) == Result);
 }
예제 #23
0
 /// <summary>
 /// Provides a <see cref="string"/> representation of this instance.
 /// </summary>
 /// <returns><see cref="String"/> representation of this instance.</returns>
 public override string ToString() =>
 string.Format("{0} - {1}", Family,
               (IsWind ? Tiles.First().Wind.Value.ToString() :
                (IsDragon ? Tiles.First().Dragon.Value.ToString() :
                 FirstNumber.ToString())));
예제 #24
0
 public override string ToString()
 {
     return("First number: " + FirstNumber.ToString() + "\n" +
            "Second number: " + SecondNumber.ToString() + "\n" +
            "Number in memory: " + NumberInMemory.ToString());
 }
예제 #25
0
 private void Button2_Click(object sender, RoutedEventArgs e)
 {
     FirstNumber.Clear();
     SecondNumber.Clear();
     ResultsNumber.Clear();
 }
예제 #26
0
 public static bool operator !=(FractionalNumber FirstNumber, FractionalNumber SecondNumber)
 {
     return(FirstNumber.CompareTo(SecondNumber) != 0);
 }