Esempio n. 1
0
        /// <summary>
        /// Find the sum of (x1, y1) and (x2, y2) and insert it into (x3, y3)
        /// </summary>
        /// <param name="sumNumber">SumNumberModel</param>
        public void SumNumbers(SumNumberModel sumNumber)
        {
            uint sum = this.GetNumber(sumNumber.x1, sumNumber.y1) + this.GetNumber(sumNumber.x2, sumNumber.y2);
            InsertNumberModel insert = new InsertNumberModel();

            insert.y      = sumNumber.y3;
            insert.x      = sumNumber.x3;
            insert.Number = sum;
            this.InsertNumber(insert);
        }
Esempio n. 2
0
        /// <summary>
        /// Insert Number
        /// </summary>
        /// <param name="insertnumber">inserternumbermodel</param>
        public void InsertNumber(InsertNumberModel insertnumber)
        {
            uint one = 0, ten = 0, hundred = 0;

            if (insertnumber.Number >= 100)
            {
                one     = insertnumber.Number % 10;
                ten     = (insertnumber.Number / 10) % 10;
                hundred = insertnumber.Number / 100;
                if (insertnumber.x > this.table.ColumnCount || insertnumber.y > this.table.RowCount)
                {
                    throw new System.IndexOutOfRangeException();
                }

                this.table.TableData[insertnumber.y, insertnumber.x * 3]       = char.Parse(hundred.ToString());
                this.table.TableData[insertnumber.y, (insertnumber.x * 3) + 1] = char.Parse(ten.ToString());

                this.table.TableData[insertnumber.y, (insertnumber.x * 3) + 2] = char.Parse(one.ToString());
            }
            else if (insertnumber.Number < 100 && insertnumber.Number >= 10)
            {
                one = insertnumber.Number % 10;
                ten = insertnumber.Number / 10;
                if (insertnumber.x > this.table.ColumnCount || insertnumber.y > this.table.RowCount)
                {
                    throw new System.IndexOutOfRangeException();
                }

                this.table.TableData[insertnumber.y, insertnumber.x * 3]       = char.Parse(ten.ToString());
                this.table.TableData[insertnumber.y, (insertnumber.x * 3) + 1] = char.Parse(one.ToString());
                this.table.TableData[insertnumber.y, (insertnumber.x * 3) + 2] = ' ';
            }
            else
            {
                one = insertnumber.Number;
                if (insertnumber.x > this.table.ColumnCount || insertnumber.y > this.table.RowCount)
                {
                    throw new System.IndexOutOfRangeException();
                }

                this.table.TableData[insertnumber.y, insertnumber.x * 3]       = char.Parse(one.ToString());
                this.table.TableData[insertnumber.y, (insertnumber.x * 3) + 1] = ' ';
                this.table.TableData[insertnumber.y, (insertnumber.x * 3) + 2] = ' ';
            }
        }
Esempio n. 3
0
        /// <summary>
        /// run input command
        /// </summary>
        /// <param name="strCommand">Command</param>
        /// <returns>resturn responsemodel</returns>
        public ResponseModel RunCommand(string strCommand)
        {
            string[] sArray = strCommand.Split(" ");
            if (sArray[0] == "C")
            {
                if (sArray.Length == 3)
                {
                    try
                    {
                        uint rowCount    = uint.Parse(sArray[2]);
                        uint columnCount = uint.Parse(sArray[1]);
                        if (rowCount > 10 || columnCount > 30)
                        {
                            return(new ResponseModel
                            {
                                Code = 0,
                                Result = "Range :   width < 30 and height < 10"
                            });
                        }

                        this.table.RowCount    = rowCount;
                        this.table.ColumnCount = columnCount;
                        this.CreateTable();

                        return(new ResponseModel
                        {
                            Code = 200,
                            Result = "success create table"
                        });
                    }
                    catch
                    {
                        return(new ResponseModel
                        {
                            Code = 0,
                            Result = "example\nN [width] [height]\nS [x1] [y1] [value]\nS x1 y1 x2 y2 x3 y3\nQ"
                        });
                    }
                }
                else
                {
                    return(new ResponseModel
                    {
                        Code = 0,
                        Result = "invalid input,Error: " + strCommand
                    });
                }
            }
            else if (sArray[0] == "N")
            {
                if (sArray.Length == 4)
                {
                    try
                    {
                        InsertNumberModel insert = new InsertNumberModel();
                        insert.y      = uint.Parse(sArray[2]);
                        insert.x      = uint.Parse(sArray[1]);
                        insert.Number = uint.Parse(sArray[3]);
                        this.InsertNumber(insert);
                        return(new ResponseModel
                        {
                            Code = 200,
                            Result = "success"
                        });
                    }
                    catch
                    {
                        return(new ResponseModel
                        {
                            Code = 0,
                            Result = "example\nN [width] [height]\nS [x1] [y1] [value]\nS x1 y1 x2 y2 x3 y3\nQ"
                        });
                    }
                }
                else
                {
                    return(new ResponseModel
                    {
                        Code = 0,
                        Result = "invalid input,Error: " + strCommand
                    });
                }
            }
            else if (sArray[0] == "S")
            {
                if (sArray.Length == 7)
                {
                    try
                    {
                        SumNumberModel sum = new SumNumberModel();
                        sum.x1 = uint.Parse(sArray[1]);
                        sum.y1 = uint.Parse(sArray[2]);
                        sum.x2 = uint.Parse(sArray[3]);
                        sum.y2 = uint.Parse(sArray[4]);
                        sum.x3 = uint.Parse(sArray[5]);
                        sum.y3 = uint.Parse(sArray[6]);
                        this.SumNumbers(sum);
                        return(new ResponseModel
                        {
                            Code = 200,
                            Result = "success"
                        });
                    }
                    catch
                    {
                        return(new ResponseModel
                        {
                            Code = 0,
                            Result = "example\nN [width] [height]\nS [x1] [y1] [value]\nS x1 y1 x2 y2 x3 y3\nQ"
                        });
                    }
                }
                else
                {
                    return(new ResponseModel
                    {
                        Code = 0,
                        Result = "invalid input,Error: " + strCommand
                    });
                }
            }
            else
            {
                return(new ResponseModel
                {
                    Code = 0,
                    Result = "invalid input,Error: "
                });
            }
        }