Ejemplo n.º 1
0
        /// <summary>
        /// Runs the menu for removing a ware.
        /// </summary>
        private void WareRemoveMenu()
        {
            string ID = CollectID();

            if (Support.IDExist(ID, SQLCode.SQLControl.DatabaseInUse))
            {
                if (WareModifier.RemoveWare(ID))
                {
                    ProgressInformer("{0} was removed.", ID);
                }
                else
                {
                    ProgressInformer("{0} was not removed.", ID);
                }
            }
            else
            {
                OutPut.DisplayMessage("ID does not exist");
                Support.WaitOnKeyInput();
            }

            void ProgressInformer(string message, string part)
            {
                OutPut.FullScreenClear();
                string text = String.Format(message, part);

                OutPut.DisplayMessage(text);
                Support.WaitOnKeyInput();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Collects a value via Console.ReadLine and returns it as variable of <paramref name="type"/> wrapped in an object.
        /// </summary>
        /// <param name="type">The type the input should be converted too.</param>
        /// <param name="oldValue">The old value that will be displayed.</param>
        /// <returns></returns>
        /// <exception cref="TargetException"></exception>
        /// <exception cref="ArgumentException"></exception>
        /// <exception cref="TargetInvocationException"></exception>
        /// <exception cref="TargetParameterCountException"></exception>
        /// <exception cref="MethodAccessException"></exception>
        /// <exception cref="InvalidOperationException"></exception>
        /// <exception cref="NotSupportedException"></exception>
        private static object CollectValue(Type type, object oldValue)
        {
            Type       support        = typeof(Support);
            MethodInfo foundMethod    = support.GetMethod("ConvertStringToVariableType", BindingFlags.NonPublic | BindingFlags.Static);
            MethodInfo genericVersion = foundMethod.MakeGenericMethod(type);

            tryAgain :;
            try
            {
                OutPut.FullScreenClear();
                OutPut.DisplayMessage(String.Format($"Old Value was {oldValue ?? "Null"}. Enter new Value: "), true);
                string value    = Input.GetString();
                object newValue = genericVersion.Invoke(null, new object[] { value });
                return(newValue);
            }
            catch (Exception e)
            {
                if (e.InnerException.Message == "Input string was not in a correct format.")
                {
                    Reporter.Report(e);
                    OutPut.FullScreenClear();
                    OutPut.DisplayMessage("Could not convert. Reenter value.", true);
                    goto tryAgain;
                }
                else
                {
                    throw e;
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Displays the visual part of the menu.
        /// </summary>
        /// <param name="options">The options to display.</param>
        /// <param name="currentHoveredOver">The option to highlight.</param>
        /// <param name="title">Title to display.</param>
        private static void MenuDisplay(string[] options, byte currentHoveredOver = 0, string title = null)
        {
            OutPut.FullScreenClear();
            if (title != null)
            {
                OutPut.DisplayColouredMessage(title, Colours.White);
            }
            Colours colour;
            byte    indent;

            for (int n = 0; n < options.Length; n++)
            {
                if (n == currentHoveredOver)
                {
                    colour = Colours.Red;
                    indent = 2;
                }
                else
                {
                    colour = Colours.White;
                    indent = 1;
                }
                OutPut.DisplayColouredMessageAtLocation(options[n], indent, n + 1, colour, true);
            }
        }
Ejemplo n.º 4
0
        private static void RunNonBasicInformationDisplay(string[,] textToDisplay, string[] columnNames, int[] columnStartLocation, int totalLength) //rename
        {
            byte maxLength = (byte)textToDisplay.GetLength(0);

            while (columnStartLocation[maxLength - 1] > OutPut.UIWidth())
            {
                maxLength--;
            }

            OutPut.FullScreenClear();
            string underscore = "|".PadRight(totalLength, '-');
            int    y          = 1;

            OutPut.DisplayColouredMessageAtLocation(underscore, 0, y, Colours.White);
            for (int n = 0; n < maxLength; n++) //displays all information in the 2D array textToDisplay
            {
                y = 0;
                OutPut.DisplayColouredMessageAtLocation("|" + columnNames[n], columnStartLocation[n], y, Colours.White);
                for (int m = 0; m < textToDisplay.GetLength(1); m++)
                {
                    OutPut.DisplayColouredMessageAtLocation("|" + textToDisplay[n, m], columnStartLocation[n], m + 2, Colours.White);
                }
            }

            Support.WaitOnKeyInput();
            Support.ActiveCursor();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Ask the user to enter a string and returns it if it is not null or empty.
        /// </summary>
        /// <param name="message">Message that should be displayed.</param>
        /// <returns>Returns the user's input as a string.</returns>
        public static string CollectString(string message)
        {
            string name;

            OutPut.FullScreenClear();
            OutPut.DisplayMessage(message, true);
            ActiveCursor();
            do
            {
                name = Input.GetString().Trim();
            } while (name == null || name == "");
            DeactiveCursor();
            return(name);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Runs the menu for removing any amount from a ware.
        /// </summary>
        private void WareRemoveAmountMenu()
        {
            string ID = CollectID();

            if (Support.IDExist(ID, SQLCode.SQLControl.DatabaseInUse))
            {
                WareModifier.RemoveFromWare(ID, CollectAmount());
            }
            else
            {
                OutPut.DisplayMessage("ID does not exist");
                Support.WaitOnKeyInput();
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Ask the user to enter a value and returns it if it is not null or empty.
        /// </summary>
        /// <param name="message">Message that should be displayed.</param>
        /// <returns>Returns the user's input as an int.</returns>
        public static int CollectValue(string message)
        {
            int    value;
            string valueString;

            OutPut.FullScreenClear();
            OutPut.DisplayMessage(message, true);
            ActiveCursor();
            do
            {
                valueString = Input.GetString();
            } while (!int.TryParse(valueString, out value));
            DeactiveCursor();
            return(value);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Ensures only the part of the menu that should be changed is updated.
        /// </summary>
        /// <param name="options">The options of the menu.</param>
        /// <param name="oldHoveredOver">The currently highlighted option's index.</param>
        /// <param name="currentHoveredOver">The last highlighted option's index.</param>
        private static void MenuDisplayUpdater(string[] options, ref byte oldHoveredOver, byte currentHoveredOver = 0)
        {
            if (oldHoveredOver != currentHoveredOver)
            {
                Paint(2, currentHoveredOver, Colours.Red, options[currentHoveredOver]);
                Paint(1, oldHoveredOver, Colours.White, options[oldHoveredOver]);
                oldHoveredOver = currentHoveredOver;
            }

            void Paint(byte indent, byte y, Colours colour, string text)
            {
                byte length = (byte)text.Length;

                OutPut.ClearPart((byte)(length + indent + 2), y + optionDisplayLowering);
                OutPut.DisplayColouredMessageAtLocation(text, indent, y + optionDisplayLowering, colour);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Displays the basic information listen in <paramref name="information"/>.
        /// </summary>
        /// <param name="information">Contains the information to display. Each string[] should be a seperate object</param>
        public static void WareDisplay(List <string[]> information)
        {
            OutPut.FullScreenClear();
            Support.DeactiveCursor();
            int y = 0;

            string[] titles       = new string[] { "Name", "ID", "Amount", "Type" };
            int[]    xLocation    = new int[titles.Length];
            byte     increasement = 20;

            for (int n = 1; n < xLocation.Length; n++) //calculates the start location of each column
            {
                xLocation[n] = increasement * n;
            }
            for (int n = 0; n < titles.Length; n++) //displays the titles and '|'
            {
                OutPut.DisplayColouredMessageAtLocation("| " + titles[n], xLocation[n], 0, Colours.White);
            }
            y += 2;
            string underline = "|";

            foreach (int xloc in xLocation) //calculates the line seperator
            {
                underline += Pad(increasement, '-', "|");
            }
            OutPut.DisplayMessage(Pad(increasement - titles[titles.Length - 1].Length - 2, ' ') + "|" + Environment.NewLine + underline, true); //Console.WriteLine(Pad(increasement - titles[titles.Length-1].Length-2,' ') + "|" + Environment.NewLine + underline);
            for (int n = 0; n < information.Count; n++)                                                                                         //writes out the information of each string array
            {
                string[] wareInfo = information[n];
                for (int m = 0; m < wareInfo.Length; m++)
                {
                    OutPut.DisplayColouredMessageAtLocation("| " + wareInfo[m], xLocation[m], y, Colours.White);
                }
                y++;
                OutPut.DisplayMessage(Pad(increasement - wareInfo[wareInfo.Length - 1].Length - 2) + "|");;
                OutPut.DisplayColouredMessageAtLocation(underline, 0, y++, Colours.White);
            }
            Support.ActiveCursor();

            string Pad(int value, char padding = ' ', string addToo = "")
            {
                value = value < 0 ? 0 : value;
                return(addToo.PadLeft(value, padding));
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Allows for the modifcation of one or more values of the ware with <paramref name="ID"/>.
        ///
        /// </summary>
        /// <param name="ID"></param>
        public static void ModifyWare(string ID)
        {
            if (!SQLCode.SQLControl.DatabaseInUse)
            {
                string[] options = null;
                try
                {
                    options = GenerateOptions(ID, SQLCode.SQLControl.DatabaseInUse);
                }
                catch (Exception e)
                {
                    Support.ErrorHandling(e, $"Encounted an error: {e.Message}");
                }
                if (options != null)
                {
                    Dictionary <string, object> informations = WareInformation.GetWareInformation(ID, out List <Type> valueTypes);
                    byte?answer;
                    do
                    {
                        answer = VisualCalculator.MenuRun(options, "Select entry to modify");
                        if (answer != options.Length - 1)
                        {
                            object oldValue = informations[options[(byte)answer]];
                            if (valueTypes[(byte)answer].IsValueType)
                            {
                                try
                                {
                                    object newValue = CollectValue(valueTypes[(byte)answer], oldValue);
                                    Publisher.PubWare.AlterWare(ID, newValue, options[(byte)answer]);
                                }
                                catch (Exception e)
                                {
                                    ErrorHandling(e);
                                }
                            }
                            else
                            { //string and arrays goes here.
                                if (valueTypes[(byte)answer].FullName == "System.String")
                                {
                                    FillOutString(options, answer, oldValue);
                                }
                                else if (valueTypes[(byte)answer].BaseType.Name == "Array")
                                {
                                    FillOutArray(options, answer, valueTypes, oldValue);
                                }
                            }
                        }
                    } while (answer != options.Length - 1);
                }
            }
            else //SQL
            { //get the type of the ID, find the attributes of that ID
                string[] options        = GenerateOptions(ID, SQLCode.SQLControl.DatabaseInUse);
                string[] columns        = new string[options.Length - 1];
                string[] allColumns     = null;
                string[] allColumnTypes = null;
                try {
                    allColumns = SQLCode.StoredProcedures.GetColumnNamesAndTypesSP(out allColumnTypes);
                }
                catch (Exception e)
                {
                    Support.ErrorHandling(e, $"Could not retrive column names and types: {e.Message}");
                }
                if (allColumns != null && allColumnTypes != null)
                {
                    for (int i = 0; i < columns.Length; i++)
                    {
                        columns[i] = options[i];
                    }
                    List <string> values = SQLCode.SQLControl.GetValuesSingleWare(columns, $"'{ID}'");
                    byte?         answer;
                    do
                    {
                        answer = VisualCalculator.MenuRun(options, "Select entry to modify");
                        if (answer != options.Length - 1)
                        {
                            string oldValue = values[(byte)answer] != "" ? values[(byte)answer] : "Null";
                            OutPut.FullScreenClear();
                            OutPut.DisplayMessage($"Old Value was {oldValue}. Enter new Value: ", true);
                            string newValue = Console.ReadLine(); //MSSQL does not seem like it has arrays as a datatype
                            for (int i = 0; i < allColumns.Length; i++)
                            {
                                if (allColumns[i] == options[(byte)answer])
                                {
                                    if (allColumnTypes[i] == "nvarchar")
                                    {
                                        newValue = $"'{newValue}'";
                                        break;
                                    }
                                }
                            }
                            try
                            {
                                SQLCode.SQLControl.ModifyWare("Inventory", new string[] { options[(byte)answer] }, new string[] { newValue }, $"id = '{ID}'");
                            }
                            catch (Exception e)
                            {
                                Reporter.Report(e);
                                OutPut.FullScreenClear();
                                OutPut.DisplayMessage($"Could not create the ware: {e.Message}", true);
                                Support.WaitOnKeyInput();
                            }
                        }
                    } while (answer != options.Length - 1);
                }
            }

            void ErrorHandling(Exception e)
            {
                Reporter.Report(e);
                OutPut.FullScreenClear();
                OutPut.DisplayMessage(String.Format("Could not convert: {0}", e.InnerException.Message), true);
                Support.WaitOnKeyInput();
            }

            void FillOutString(string[] options, byte?answer, object oldValue)
            {
                OutPut.FullScreenClear();
                OutPut.DisplayMessage($"Old Value was {oldValue ?? "Null"}. Enter new Value: ", true);
                string newValue = Input.GetString();

                try
                {
                    Publisher.PubWare.AlterWare(ID, newValue, options[(byte)answer]);
                }
                catch (Exception e)
                {
                    Support.ErrorHandling(e, $"Encountered an error: {e.Message}");
                }
            }

            void FillOutArray(string[] options, byte?answer, List <Type> valueTypes, object oldValue)
            {
                List <object> objectList = new List <object>();

                string[] addValueOptions = new string[] { "Enter Value", "Done" };
                byte?    valueAnswer;

                do
                {
                    valueAnswer = VisualCalculator.MenuRun(addValueOptions, "Add Data Entry");
                    if (valueAnswer == 0)
                    {
                        if (!valueTypes[(byte)answer].Name.Contains("String"))
                        { //non-string
                            try
                            {
                                objectList.Add(CollectValue(Type.GetType(valueTypes[(byte)answer].FullName.Remove(valueTypes[(byte)answer].FullName.Length - 2, 2)), oldValue)); //code inside of Type.GetType(...) converts an array type to a non-array type
                            }
                            catch (Exception e)
                            {
                                ErrorHandling(e);
                            }
                        }
                        else
                        { //string
                            OutPut.FullScreenClear();
                            objectList.Add(Input.GetString());
                        }
                    }
                } while (valueAnswer != addValueOptions.Length - 1);
                object[] objectArray = objectList.ToArray();
                try
                {
                    Publisher.PubWare.AlterWare(ID, objectArray, options[(byte)answer]);
                }
                catch (Exception e)
                {
                    Support.ErrorHandling(e, $"Encountered an erorr: {e.Message}");
                }
            }
        }