Пример #1
0
        private SectionFields GetAssociatedField(string fieldId)
        {
            bool          found = false;
            SectionFields field = null;

            foreach (var section in ParentForm.Sections)
            {
                foreach (var sectionField in section.Fields)
                {
                    if (sectionField.FieldId.Equals(fieldId))
                    {
                        field = sectionField;
                        found = true;
                    }
                    if (found)
                    {
                        break;
                    }
                }
                if (found)
                {
                    break;
                }
            }

            if (!found)
            {
                throw new Exception("Field Not Found in the JSON supplied");
            }
            return(field);
        }
Пример #2
0
        private List <SQLParameter> InitilizeSQLParameters()
        {
            var parameterList = new List <SQLParameter>();

            for (int i = 0; i < DestinationValues.Length; i++)
            {
                string value          = DestinationValues[i].Split(":").GetValue(1).ToString();
                string valueType      = DestinationValues[i].Split(":").GetValue(0).ToString();
                object parameterValue = null;

                switch (valueType)
                {
                case DestinationValueType.CONSTANT:
                    parameterValue = value;
                    parameterList.Add(new SQLParameter
                    {
                        Name  = "@" + DestinationAttributes[i],
                        Value = parameterValue
                    });
                    break;

                case DestinationValueType.COMPUTABLE:
                    parameterValue = GetComputableValue(value);
                    parameterList.Add(new SQLParameter
                    {
                        Name  = "@" + DestinationAttributes[i],
                        Value = parameterValue
                    });
                    if (!string.IsNullOrWhiteSpace(OutID))
                    {
                        var parameter = ParentForm.FormParameters.Where(item => item.ParameterKey.Equals(OutID.Split(":").GetValue(1).ToString())).FirstOrDefault();
                        if (string.IsNullOrEmpty(parameter.ParameterValue))
                        {
                            parameter.ParameterValue = parameterValue as string;
                        }
                    }
                    break;

                case DestinationValueType.PARAMETER:
                    parameterValue = ParentForm.FormParameters.Where(item => item.ParameterKey.Equals(value)).FirstOrDefault().ParameterValue;
                    parameterList.Add(new SQLParameter
                    {
                        Name  = "@" + DestinationAttributes[i],
                        Value = parameterValue
                    });
                    break;

                case DestinationValueType.FIELD:
                    if (!AssociatedFieldType.Equals("chkbl"))
                    {
                        SectionFields fld = GetAssociatedField(value);
                        parameterValue = fld.FieldData[fld.FieldData.Count - 1].Text;
                        parameterList.Add(new SQLParameter
                        {
                            Name  = "@" + DestinationAttributes[i],
                            Value = parameterValue
                        });
                    }
                    else
                    {
                        int count = 0;
                        for (int j = 0; j < AssociatedField.FieldData.Count; j++)
                        {
                            parameterValue = AssociatedField.FieldData[j].Text;
                            parameterList.Add(new SQLParameter
                            {
                                Name  = "@" + DestinationAttributes[i] + count++,
                                Value = parameterValue
                            });
                        }
                    }
                    break;
                }
            }

            if (WhereData != null)
            {
                for (int i = 0; i < WhereData.Length; i++)
                {
                    string value          = WhereData[i].Split(":").GetValue(1).ToString();
                    string valueType      = WhereData[i].Split(":").GetValue(0).ToString();
                    object parameterValue = null;

                    switch (valueType)
                    {
                    case DestinationValueType.CONSTANT:
                        parameterValue = value;
                        break;

                    case DestinationValueType.COMPUTABLE:
                        parameterValue = GetComputableValue(value);
                        break;

                    case DestinationValueType.PARAMETER:
                        parameterValue = ParentForm.FormParameters.Where(item => item.ParameterKey.Equals(value)).FirstOrDefault().ParameterValue;
                        break;

                    case DestinationValueType.FIELD:
                        parameterValue = GetAssociatedField(value).FieldData[0].Text;
                        break;
                    }

                    parameterList.Add(new SQLParameter
                    {
                        Name  = "@" + WhereCols[i],
                        Value = parameterValue
                    });
                }
            }

            return(parameterList);
        }