public XmlElement GetResult()
        {
            //TODO
            XmlHelper h = new XmlHelper("<Definition />");

            h.SetAttribute(".", "Type", "DBHelper");
            h.AddElement(".", "Action", ServiceAction.Delete.ToString());

            XmlElement      sqlTmp  = h.AddElement(".", "SQLTemplate");
            XmlCDataSection section = sqlTmp.OwnerDocument.CreateCDataSection(this.txtSQLTemplate.Text);

            sqlTmp.AppendChild(section);

            h.AddElement(".", "RequestRecordElement", txtRequestElement.Text);

            ConditionList conditions = new ConditionList(this.txtConditionName.Text, this.txtConditionSource.Text, chkRequired.Checked);

            foreach (DataGridViewRow row in this.dgConditions.Rows)
            {
                Condition condition = Condition.Parse(row);
                conditions.Conditions.Add(condition);
            }
            h.AddElement(".", conditions.GetXml());

            if (this.Service.Variables.Count > 0)
            {
                XmlElement varElement = h.AddElement(".", "InternalVariable");
                foreach (IVariable v in this.Service.Variables)
                {
                    h.AddElement("InternalVariable", v.GetXml());
                }
            }

            if (this.Service.Converters.Count > 0)
            {
                XmlElement cvElement = h.AddElement(".", "Converters");
                foreach (IConverter c in this.Service.Converters)
                {
                    h.AddElement("Converters", c.Output());
                }
            }

            if (this.dgProcessor.Rows.Count > 0)
            {
                XmlElement proElement = h.AddElement(".", "Preprocesses");
                foreach (DataGridViewRow row in this.dgProcessor.Rows)
                {
                    Preprocess pp = row.Tag as Preprocess;
                    if (pp == null)
                    {
                        continue;
                    }

                    h.AddElement("Preprocesses", pp.GetXml());
                }
            }
            return(h.GetElement("."));
        }
Esempio n. 2
0
        public XmlElement GetResult()
        {
            //TODO
            XmlHelper h = new XmlHelper("<Definition />");

            h.SetAttribute(".", "Type", "DBHelper");
            h.AddElement(".", "Action", ServiceAction.Select.ToString());

            XmlElement      sqlTmp  = h.AddElement(".", "SQLTemplate");
            XmlCDataSection section = sqlTmp.OwnerDocument.CreateCDataSection(this.txtSQLTemplate.Text);

            sqlTmp.AppendChild(section);

            h.AddElement(".", "ResponseRecordElement", txtRequestElement.Text);
            FieldList fields = new FieldList(this.txtFieldListName.Text, this.txtFieldListSource.Text);

            foreach (DataGridViewRow row in this.dgFieldList.Rows)
            {
                Field f = Field.Parse(row);
                fields.Fields.Add(f);
            }
            h.AddElement(".", fields.GetXml(ServiceAction.Select));

            ConditionList conditions = new ConditionList(this.txtConditionName.Text, this.txtConditionSource.Text, chkRequired.Checked);

            foreach (DataGridViewRow row in this.dgConditions.Rows)
            {
                Condition condition = Condition.Parse(row);
                conditions.Conditions.Add(condition);
            }
            h.AddElement(".", conditions.GetXml());

            OrderList orders = new OrderList(txtOrderName.Text, txtOrderSource.Text);

            foreach (DataGridViewRow row in dgOrder.Rows)
            {
                string target = row.Cells[colOrderTarget.Name].Value + string.Empty;
                string source = row.Cells[colOrderSource.Name].Value + string.Empty;
                Order  o      = new Order(target, source);
                orders.Orders.Add(o);
            }
            h.AddElement(".", orders.GetXml());

            int max = 0;

            if (!int.TryParse(txtMaxPageSize.Text, out max))
            {
                max = 0;
            }
            Pagination p = new Pagination(chkAllowPagination.Checked, max);

            h.AddElement(".", p.GetXml());

            if (this.Service.Variables.Count > 0)
            {
                XmlElement varElement = h.AddElement(".", "InternalVariable");
                foreach (IVariable v in this.Service.Variables)
                {
                    h.AddElement("InternalVariable", v.GetXml());
                }
            }

            if (this.Service.Converters.Count > 0)
            {
                XmlElement cvElement = h.AddElement(".", "Converters");
                foreach (IConverter c in this.Service.Converters)
                {
                    h.AddElement("Converters", c.Output());
                }
            }

            if (this.dgProcessor.Rows.Count > 0)
            {
                XmlElement proElement = h.AddElement(".", "Preprocesses");
                foreach (DataGridViewRow row in this.dgProcessor.Rows)
                {
                    Preprocess pp = row.Tag as Preprocess;
                    if (pp == null)
                    {
                        continue;
                    }

                    h.AddElement("Preprocesses", pp.GetXml());
                }
            }
            return(h.GetElement("."));
        }
        public XmlElement GetResult()
        {
            //TODO
            XmlHelper h = new XmlHelper("<Definition />");

            h.SetAttribute(".", "Type", "DBHelper");
            h.AddElement(".", "Action", ServiceAction.Set.ToString());

            h.AddElement(".", "RequestRecordElement", txtRequestElement.Text);
            h.AddElement(".", "TargetTableName", cboTable.Text);
            h.AddElement(".", "Mappings");
            XmlElement    dfmElement = h.AddElement("Mappings", "DefaultMapping");
            StringBuilder sb         = new StringBuilder("select ");

            foreach (DataGridViewRow row in this.dgFieldList.Rows)
            {
                bool autoNumber = this.GetBooleanValue(row.Cells[colAutoNumber.Name]);
                if (autoNumber)
                {
                    string target = row.Cells[colTarget.Name].Value + string.Empty;
                    string source = row.Cells[colSource.Name].Value + string.Empty;
                    sb.Append("\"").Append(target).Append("\" as \"").Append(source).Append("\"");
                    break;
                }
            }
            foreach (DataGridViewRow row in this.dgFieldList.Rows)
            {
                bool identity = this.GetBooleanValue(row.Cells[colIdentity.Name]);
                if (!identity)
                {
                    continue;
                }

                string target = row.Cells[colTarget.Name].Value + string.Empty;
                //string source = row.Cells[colSource.Name].Value + string.Empty;
                sb.Append(", \"").Append(target).Append("\"");
                //sb.Append(", \"").Append(target).Append("\" as \"").Append(source).Append("\"");
            }
            sb.Append(" from ").Append(cboTable.Text);
            XmlNode node = dfmElement.OwnerDocument.CreateCDataSection(sb.ToString());

            dfmElement.AppendChild(node);

            XmlElement fieldListElement = h.AddElement(".", "FieldList");

            fieldListElement.SetAttribute("Source", txtFieldListSource.Text);
            foreach (DataGridViewRow row in this.dgFieldList.Rows)
            {
                XmlElement fieldElement = h.AddElement("FieldList", "Field");
                string     source       = row.Cells[colSource.Name].Value + string.Empty;
                fieldElement.SetAttribute("Source", source);

                string target = row.Cells[colTarget.Name].Value + string.Empty;
                fieldElement.SetAttribute("Target", target);

                bool required = this.GetBooleanValue(row.Cells[colRequired.Name]);
                if (required)
                {
                    fieldElement.SetAttribute("Required", "true");
                }

                bool autoNumber = this.GetBooleanValue(row.Cells[colAutoNumber.Name]);
                if (autoNumber)
                {
                    fieldElement.SetAttribute("AutoNumber", "true");
                }

                bool identity = this.GetBooleanValue(row.Cells[colIdentity.Name]);
                if (identity)
                {
                    fieldElement.SetAttribute("Identity", "true");
                }

                string converter = row.Cells[colConverter.Name].Value + string.Empty;
                if (!string.IsNullOrWhiteSpace(converter))
                {
                    fieldElement.SetAttribute("Converter", converter);
                }

                string sourceType = row.Cells[colSourceType.Name].Value + string.Empty;
                if (!string.Equals(sourceType, "Request", StringComparison.CurrentCultureIgnoreCase))
                {
                    fieldElement.SetAttribute("SourceType", sourceType);
                }

                bool quote = this.GetBooleanValue(row.Cells[colQuote.Name]);
                if (!quote)
                {
                    fieldElement.SetAttribute("Quote", "false");
                }
            }

            if (this.Service.Variables.Count > 0)
            {
                XmlElement varElement = h.AddElement(".", "InternalVariable");
                foreach (IVariable v in this.Service.Variables)
                {
                    h.AddElement("InternalVariable", v.GetXml());
                }
            }

            if (this.dgProcessor.Rows.Count > 0)
            {
                XmlElement proElement = h.AddElement(".", "Preprocesses");
                foreach (DataGridViewRow row in this.dgProcessor.Rows)
                {
                    Preprocess pp = row.Tag as Preprocess;
                    if (pp == null)
                    {
                        continue;
                    }

                    h.AddElement("Preprocesses", pp.GetXml());
                }
            }
            return(h.GetElement("."));
        }