Beispiel #1
0
        public IEnumerable <Constant> Read(SqlConnection connection, Version platformVersion)
        {
            var components = new List <Constant>();
            var query      = this.GetConstantQuery(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 constant = new Constant
                        {
                            Name         = reader["Name"] as string,
                            Title        = reader["Title"] as string,
                            IsCommon     = YesValue.Equals(reader["IsCommon"] as string),
                            IsReplicated = YesValue.Equals(reader["IsReplicated"] as string)
                        };

                        components.Add(constant);
                    }
                }
            }
            return(components);
        }
Beispiel #2
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());
        }
Beispiel #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());
        }