/// <summary> /// This method is responsible for receiving a control and breaking down the textbox control input which is in the Name,Value /// format and mapping it to the Rules model. The type of component, whether addition or subtraction is also specified in the /// Rules model. /// </summary> /// <param name="component">The component textbox control whose input is to be segregated.</param> /// <param name="typeOfOperation">Whether the control input is an addition component or a subtraction component.</param> /// <param name="userRules">The list which contains the segregated set of components' inputs.</param> /// <returns></returns> public List <Rules> SegregateComponents(Control component, ComputationVariety typeOfOperation, List <Rules> userRules) { StringBuilder componentBuilder = new StringBuilder(); string[] componentParts = componentBuilder.Append(component).ToString().Split('='); componentParts = componentParts[0].Split(','); if ((componentParts != null) && (componentParts.Count() > 0)) { userRules.Add(new Rules() { ComputationName = typeOfOperation, RuleName = componentParts[1].Split(':')[1], RuleValue = Decimal.Round(Convert.ToDecimal(componentParts[2]), 2) } ); } componentBuilder.Clear(); return(userRules); }
/// <summary> /// This method is responsible for receiving a component collection and invoking the SegregateComponents() method to /// segregate the input values of the control collection. /// </summary> /// <param name="componentCollection">The collection of controls whose input is to be segregated.</param> /// <param name="typeOfOperation">Indicates whether the component is an addition component or a subtraction component</param> /// <param name="userRules">A list, initially having only one component input, which is nothing but the main input text box value that further /// generates input text boxes on clicking the "AC" button and "DC" button for addition component and deduction component respectively.</param> /// <returns>A list of components, addition or subtraction at any point of time.</returns> private List <Rules> FetchUserComponents(Control.ControlCollection componentCollection, ComputationVariety typeOfOperation, List <Rules> userRules) { StringBuilder ruleHolder = new StringBuilder(); if (componentCollection != null && componentCollection.Count > 0) { foreach (var component in componentCollection) { userRules = SegregateComponents((Control)component, typeOfOperation, userRules); } } return(userRules); }