Exemple #1
0
        public IEnumerable <ReferenceType> Read(SqlConnection connection, Version platformVersion)
        {
            var components = new Dictionary <string, ReferenceType>();
            var query      = this.GetReferenceTypeQuery(platformVersion);

            if (string.IsNullOrEmpty(query))
            {
                return(components.Values.ToList());
            }

            var command = new SqlCommand(query, connection);

            using (var reader = command.ExecuteReader())
            {
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        var referenceType = new ReferenceType
                        {
                            Name  = reader["Name"] as string,
                            Title = reader["Title"] as string
                        };

                        if (reader["State"] is string stateValue &&
                            StateValues.ContainsKey(stateValue))
                        {
                            referenceType.State = StateValues[stateValue];
                        }

                        if (reader["NumerationMethod"] is string numerationMethodValue &&
                            NumerationMethodValues.ContainsKey(numerationMethodValue))
                        {
                            referenceType.NumerationMethod = NumerationMethodValues[numerationMethodValue];
                        }

                        if (reader["DisplayRequisite"] is string displayRequisiteValue &&
                            DisplayRequisiteValues.ContainsKey(displayRequisiteValue))
                        {
                            referenceType.DisplayRequisite = DisplayRequisiteValues[displayRequisiteValue];
                        }

                        referenceType.LeadingReference     = reader["LeadingReference"] as string;
                        referenceType.HasLongRecordNames   = YesValue.Equals(reader["HasLongRecordNames"] as string);
                        referenceType.HasUniqueRecordNames = YesValue.Equals(reader["HasUniqueRecordNames"] as string);

                        var eventsValue = reader["Events"] as string;
                        if (!string.IsNullOrEmpty(eventsValue))
                        {
                            var events = EventTextParser.Parse(eventsValue);
                            foreach (var @event in events)
                            {
                                referenceType.Events.Add(@event);
                            }
                        }

                        components.Add(referenceType.Name, referenceType);
                    }
                }
            }

            query = this.GetMethodsQuery(platformVersion);
            if (!string.IsNullOrEmpty(query))
            {
                command = new SqlCommand(query, connection);
                using (var reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var referenceTypeName = reader["ReferenceTypeName"] as string;
                            if (!components.TryGetValue(referenceTypeName, out ReferenceType referenceType))
                            {
                                continue;
                            }

                            var method = new Method
                            {
                                Name            = reader["Name"] as string,
                                CalculationText = reader["CalculationText"] as string ?? string.Empty
                            };

                            referenceType.Methods.Add(method);
                        }
                    }
                }
            }

            query = this.GetMethodParamsQuery(platformVersion);
            if (!string.IsNullOrEmpty(query))
            {
                command = new SqlCommand(query, connection);
                using (var reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var referenceTypeName = reader["ReferenceTypeName"] as string;
                            if (!components.TryGetValue(referenceTypeName, out ReferenceType referenceType))
                            {
                                continue;
                            }

                            var methodName = reader["MethodName"] as string;
                            var method     = referenceType.Methods
                                             .FirstOrDefault(m => m.Name == methodName);
                            if (method == null)
                            {
                                continue;
                            }

                            var parameter = new MethodParam
                            {
                                Number = (int)reader["Number"],
                                Name   = reader["Name"] as string
                            };

                            var typeValue = reader["Type"] as string;
                            if (TypeValues.TryGetValue(typeValue, out MethodParamType methodParamType))
                            {
                                parameter.Type = methodParamType;
                            }
                            parameter.DefaultValue    = reader["DefaultValue"] as string;
                            parameter.HasDefaultValue = !string.IsNullOrEmpty(parameter.DefaultValue);

                            method.Params.Add(parameter);
                        }
                    }
                }
            }

            query = this.GetActionQuery(platformVersion);
            if (!string.IsNullOrEmpty(query))
            {
                command = new SqlCommand(query, connection);
                using (var reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var referenceTypeName = reader["ReferenceTypeName"] as string;
                            if (!components.TryGetValue(referenceTypeName, out ReferenceType referenceType))
                            {
                                continue;
                            }

                            var action = new ActionWithHandler {
                                Name = reader["Name"] as string
                            };

                            var calculationText  = reader["CalculationText"] as string;
                            var executionHandler = referenceType.Methods
                                                   .FirstOrDefault(m => m.Name == calculationText);
                            if (executionHandler != null)
                            {
                                action.ExecutionHandler = executionHandler;
                            }
                            else
                            {
                                action.CalculationText = calculationText ?? string.Empty;
                            }

                            referenceType.Actions.Add(action);
                        }
                    }
                }
            }

            query = this.GetRequisiteQuery(platformVersion);
            if (!string.IsNullOrEmpty(query))
            {
                command = new SqlCommand(query, connection);
                using (var reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var referenceTypeName = reader["ReferenceTypeName"] as string;
                            if (!components.TryGetValue(referenceTypeName, out ReferenceType referenceType))
                            {
                                continue;
                            }

                            var cardRequisite = new CardRequisite {
                                Number = (int)reader["Number"]
                            };

                            if (reader["Section"] is string sectionValue &&
                                RequisiteSectionValues.ContainsKey(sectionValue))
                            {
                                cardRequisite.Section = RequisiteSectionValues[sectionValue];
                            }

                            cardRequisite.Name       = reader["Name"] as string;
                            cardRequisite.IsRequired = RuYesValue.Equals(reader["IsRequired"] as string);
                            cardRequisite.IsFilter   = RuYesValue.Equals(reader["IsFilter"] as string);
                            cardRequisite.IsLeading  = RuYesValue.Equals(reader["IsLeading"] as string);
                            cardRequisite.IsControl  = RuYesValue.Equals(reader["IsControl"] as string);

                            var changeEventValue = reader["ChangeEvent"] as string;
                            if (!string.IsNullOrEmpty(changeEventValue))
                            {
                                var @event = new Event
                                {
                                    EventType       = EventType.Change,
                                    CalculationText = changeEventValue
                                };
                                cardRequisite.Events.Add(@event);
                            }

                            var selectEventsValue = reader["SelectEvents"] as string;
                            if (!string.IsNullOrEmpty(selectEventsValue))
                            {
                                var events = EventTextParser.Parse(selectEventsValue);
                                foreach (var @event in events)
                                {
                                    if (@event.EventType == EventType.Unknown)
                                    {
                                        @event.EventType = EventType.Select;
                                    }
                                    cardRequisite.Events.Add(@event);
                                }
                            }

                            referenceType.Requisites.Add(cardRequisite);
                        }
                    }
                }
            }

            query = this.GetViewQuery(platformVersion);
            if (!string.IsNullOrEmpty(query))
            {
                command = new SqlCommand(query, connection);
                using (var reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var referenceTypeName = reader["ReferenceTypeName"] as string;
                            if (!components.TryGetValue(referenceTypeName, out ReferenceType referenceType))
                            {
                                continue;
                            }

                            var view = new View
                            {
                                Name     = reader["Name"] as string,
                                IsMain   = RuYesValue.Equals(reader["IsMain"] as string),
                                ListForm = reader["ListForm"] as string,
                                CardForm = reader["CardForm"] as string
                            };
                            referenceType.Views.Add(view);

                            referenceType.Views.Add(view);
                        }
                    }
                }
            }

            return(components.Values.ToList());
        }
Exemple #2
0
        public IEnumerable <ReferenceRequisite> Read(SqlConnection connection, Version platformVersion)
        {
            var components = new List <ReferenceRequisite>();
            var query      = this.GetReferenceRequisiteQuery(platformVersion);

            if (string.IsNullOrEmpty(query))
            {
                return(components);
            }

            var command = new SqlCommand(query, connection);

            using (var reader = command.ExecuteReader())
            {
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        var referenceRequisite = new ReferenceRequisite
                        {
                            Name  = reader["Name"] as string,
                            Title = reader["Title"] as string
                        };

                        if (reader["Section"] is string requisiteSectionValue &&
                            RequisiteSectionValues.ContainsKey(requisiteSectionValue))
                        {
                            referenceRequisite.Section = RequisiteSectionValues[requisiteSectionValue];
                        }

                        if (reader["Type"] is string requisiteTypeValue &&
                            RequisiteTypeValues.ContainsKey(requisiteTypeValue))
                        {
                            referenceRequisite.Type = RequisiteTypeValues[requisiteTypeValue];
                        }


                        if (reader["Format"] is string requisiteFormatValue &&
                            RequisiteFormatValues.ContainsKey(requisiteFormatValue))
                        {
                            referenceRequisite.Format = RequisiteFormatValues[requisiteFormatValue];
                        }

                        var lengthValue = reader["Length"];
                        if (lengthValue is int)
                        {
                            referenceRequisite.Length = (int)lengthValue;
                        }

                        var precissionValue = reader["Precission"];
                        if (precissionValue is int)
                        {
                            referenceRequisite.Precission = (int)precissionValue;
                        }

                        referenceRequisite.ReferenceType = reader["ReferenceType"] as string;
                        referenceRequisite.ReferenceView = reader["ReferenceView"] as string;

                        if (reader["PickValues"] is string pickValuesValue)
                        {
                            var pickValues = pickValuesValue.Split(';');
                            foreach (var pickValue in pickValues)
                            {
                                var pickValueParts = pickValue.Split('=', '|');
                                var reqPickValue   = new RequisitePickValue
                                {
                                    Id    = pickValueParts[0][0],
                                    Value = pickValueParts[1]
                                };
                                referenceRequisite.PickValues.Add(reqPickValue);
                            }
                        }

                        referenceRequisite.Field       = reader["Field"] as string;
                        referenceRequisite.IsStored    = IsStoredValue.Equals(reader["IsStored"] as string);
                        referenceRequisite.IsGenerated = IsGeneratedValue.Equals(reader["IsGenerated"] as string);

                        components.Add(referenceRequisite);
                    }
                }
            }
            return(components);
        }
Exemple #3
0
        public IEnumerable <Dialog> Read(SqlConnection connection, Version platformVersion)
        {
            var components = new Dictionary <string, Dialog>();
            var query      = this.GetDialogQuery(platformVersion);

            if (string.IsNullOrEmpty(query))
            {
                return(components.Values.ToList());
            }

            var command = new SqlCommand(query, connection);

            using (var reader = command.ExecuteReader())
            {
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        var dialog = new Dialog
                        {
                            Name     = reader["Name"] as string,
                            Title    = reader["Title"] as string,
                            CardForm = reader["CardForm"] as string
                        };

                        var eventsValue = reader["Events"] as string;
                        if (!string.IsNullOrEmpty(eventsValue))
                        {
                            var events = EventTextParser.Parse(eventsValue);
                            foreach (var @event in events)
                            {
                                dialog.Events.Add(@event);
                            }
                        }

                        components.Add(dialog.Name, dialog);
                    }
                }
            }

            query = this.GetMethodsQuery(platformVersion);
            if (!string.IsNullOrEmpty(query))
            {
                command = new SqlCommand(query, connection);
                using (var reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var dialogName = reader["DialogName"] as string;
                            if (!components.TryGetValue(dialogName, out Dialog dialog))
                            {
                                continue;
                            }

                            var method = new Method
                            {
                                Name            = reader["Name"] as string,
                                CalculationText = reader["CalculationText"] as string ?? string.Empty
                            };

                            dialog.Methods.Add(method);
                        }
                    }
                }
            }

            query = this.GetMethodParamsQuery(platformVersion);
            if (!string.IsNullOrEmpty(query))
            {
                command = new SqlCommand(query, connection);
                using (var reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var dialogName = reader["DialogName"] as string;
                            if (!components.TryGetValue(dialogName, out Dialog dialog))
                            {
                                continue;
                            }

                            var methodName = reader["MethodName"] as string;
                            var method     = dialog.Methods
                                             .FirstOrDefault(m => m.Name == methodName);
                            if (method == null)
                            {
                                continue;
                            }

                            var parameter = new MethodParam
                            {
                                Number = (int)reader["Number"],
                                Name   = reader["Name"] as string
                            };

                            var typeValue = reader["Type"] as string;
                            if (TypeValues.TryGetValue(typeValue, out MethodParamType methodParamType))
                            {
                                parameter.Type = methodParamType;
                            }
                            parameter.DefaultValue    = reader["DefaultValue"] as string;
                            parameter.HasDefaultValue = !string.IsNullOrEmpty(parameter.DefaultValue);

                            method.Params.Add(parameter);
                        }
                    }
                }
            }

            query = this.GetActionQuery(platformVersion);
            if (!string.IsNullOrEmpty(query))
            {
                command = new SqlCommand(query, connection);
                using (var reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var dialogName = reader["DialogName"] as string;
                            if (!components.TryGetValue(dialogName, out Dialog dialog))
                            {
                                continue;
                            }

                            var action = new ActionWithHandler {
                                Name = reader["Name"] as string
                            };

                            var calculationText  = reader["CalculationText"] as string;
                            var executionHandler = dialog.Methods
                                                   .FirstOrDefault(m => m.Name == calculationText);
                            if (executionHandler != null)
                            {
                                action.ExecutionHandler = executionHandler;
                            }
                            else
                            {
                                action.CalculationText = calculationText ?? string.Empty;
                            }

                            dialog.Actions.Add(action);
                        }
                    }
                }
            }

            query = this.GetRequisiteQuery(platformVersion);
            if (!string.IsNullOrEmpty(query))
            {
                command = new SqlCommand(query, connection);
                using (var reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var dialogName = reader["DialogName"] as string;
                            if (!components.TryGetValue(dialogName, out Dialog dialog))
                            {
                                continue;
                            }

                            var cardRequisite = new CardRequisite {
                                Number = (int)reader["Number"]
                            };

                            if (reader["Section"] is string sectionValue &&
                                RequisiteSectionValues.ContainsKey(sectionValue))
                            {
                                cardRequisite.Section = RequisiteSectionValues[sectionValue];
                            }

                            cardRequisite.Name                   = reader["Name"] as string;
                            cardRequisite.IsRequired             = YesValue.Equals(reader["IsRequired"] as string);
                            cardRequisite.IsLastValueSaved       = YesValue.Equals(reader["IsLastValueSaved"] as string);
                            cardRequisite.IsSelectionConstrained = YesValue.Equals(reader["IsSelectionConstrained"] as string);

                            var changeEventValue = reader["ChangeEvent"] as string;
                            if (!string.IsNullOrEmpty(changeEventValue))
                            {
                                var @event = new Event
                                {
                                    EventType       = EventType.Change,
                                    CalculationText = changeEventValue
                                };
                                cardRequisite.Events.Add(@event);
                            }

                            var selectEventsValue = reader["SelectEvents"] as string;
                            if (!string.IsNullOrEmpty(selectEventsValue))
                            {
                                var events = EventTextParser.Parse(selectEventsValue);
                                foreach (var @event in events)
                                {
                                    if (@event.EventType == EventType.Unknown)
                                    {
                                        @event.EventType = EventType.Select;
                                    }
                                    cardRequisite.Events.Add(@event);
                                }
                            }

                            dialog.Requisites.Add(cardRequisite);
                        }
                    }
                }
            }

            return(components.Values.ToList());
        }