Пример #1
0
        private void HandleMessage(String msg, NetworkStream clientStream)
        {
            String[] commandParams = msg.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            switch (commandParams[0])
            {
            case "reasons":
                string reasons = CommandExecutor.ExecuteReasonsCommand();
                if (reasons != null)
                {
                    Echo(reasons, clientStream);
                }
                else
                {
                    Echo("No such User", clientStream);
                }
                break;

            case "login":
                string result = CommandExecutor.ExecuteLoginCommand(commandParams[1], commandParams[2]);
                if (result != null)
                {
                    Echo(result, clientStream);
                }
                else
                {
                    Echo("No such User", clientStream);
                }
                break;

            case "add":
                if (CommandExecutor.ExecuteAddCommand(commandParams[1], commandParams[2], commandParams[3], commandParams[4]))
                {
                    Echo("Adding Successful!", clientStream);
                }
                else
                {
                    Echo("Error.Failed enter the record!", clientStream);
                }
                break;

            case "getday":
                double resultDay = 0;
                try
                {
                    resultDay = CommandExecutor.ExecuteGetDayCommand(commandParams[1], commandParams[2]);
                }
                catch (ArgumentException)
                {
                    Echo("Wrong Input!", clientStream);
                    break;
                }

                if (resultDay >= 0)
                {
                    Echo(resultDay.ToString(), clientStream);
                }
                break;

            case "getmonth":
                double totalForMonth = 0;
                try
                {
                    totalForMonth = CommandExecutor.ExecuteTotalForMonthCommand(commandParams[1], commandParams[2]);
                }
                catch (ArgumentException)
                {
                    Echo("Wrong Input!", clientStream);
                    break;
                }
                Echo(totalForMonth.ToString(), clientStream);
                break;

            case "getyear":
                double totalForYear = 0;
                try
                {
                    totalForYear = CommandExecutor.ExecuteTotalForYearCommand(commandParams[1], commandParams[2]);
                }
                catch (ArgumentException)
                {
                    Echo("Wrong Input!", clientStream);
                    break;
                }
                Echo(totalForYear.ToString(), clientStream);
                break;

            case "getreason":
                String recordsForReason;
                try
                {
                    recordsForReason = CommandExecutor.ExecuteCostsForReasonCommand(commandParams[1], commandParams[2]);
                }
                catch (ArgumentException)
                {
                    Echo("Wrong Input!", clientStream);
                    break;
                }
                Echo(recordsForReason, clientStream);
                break;

            default:
                Echo("Wrong command:" + msg, clientStream);
                break;
            }
        }