/// <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); }
/// <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: " }); } }