Esempio n. 1
0
 // Create an empty initialized template
 public Template()
 {
     head = new node();
     addedHead = new node();
     addedTail = addedHead;
     firstSection = new section();
     tpl = this;
     fields = new Object[MAX_FIELDS];
     sections = new Object[MAX_FIELDS];
 }
Esempio n. 2
0
 // Create using template file
 public Template(string filename)
 {
     head = new node();
     addedHead = new node();
     addedTail = addedHead;
     firstSection = new section();
     tpl = this;
     fields = new Object[MAX_FIELDS];
     sections = new Object[MAX_FIELDS];
     StreamReader re = new StreamReader(filename, System.Text.Encoding.Default);
     string data = SECTIONTAG_HEAD + re.ReadToEnd() + SECTIONTAG_TAIL;
     re.Close();
     construct(data, SECTIONTAG_HEAD_LEN, data.Length - SECTIONTAG_TAIL_LEN);
 }
Esempio n. 3
0
        public static string PrepareGetListStoredProcedure(Table table)
        {
            Template template = new Template(TemplatesPath + "dalSPGetList.tpl");

            template.selectSection("DAL_SP");
            template.setField("DB_NAME", table.Catalog);
            template.setField("SP_NAME", string.Format("[{0}].[dal_{1}_getlist]", table.Schema, table.Name));
            template.setField("TABLE_NAME", string.Format("[{0}].[{1}]", table.Schema, table.Name));
            template.setField("SELECT_FIELD_NAMES", table.FieldNames);
            template.appendSection();
            template.deselectSection();

            return template.getContent();
        }
Esempio n. 4
0
        public static string PrepareDeleteStoredProcedure(Table table)
        {
            Template template = new Template(TemplatesPath + "dalSPDelete.tpl");

            template.selectSection("DAL_SP");
            template.setField("DB_NAME", table.Catalog);
            template.setField("SP_NAME", string.Format("[{0}].[dal_{1}_deletebyid]", table.Schema, table.Name));
            template.setField("TABLE_NAME", string.Format("[{0}].[{1}]", table.Schema, table.Name));
            template.setField("TABLE_PKFIELD_NAME", table.PKField.ColumnName);
            template.setField("TABLE_PKFIELD_PARAMNAME", "@" + table.PKField.ColumnName);
            template.setField("TABLE_PKFIELD_TYPE", table.PKField.DataTypeFull);
            template.appendSection();
            template.deselectSection();

            return template.getContent();
        }
Esempio n. 5
0
        public static string PrepareInsertStoredProcedure(Table table)
        {
            Template template = new Template(TemplatesPath + "dalSPInsert.tpl");

            template.selectSection("DAL_SP");
            template.setField("DB_NAME", table.Catalog);
            template.setField("SP_NAME", string.Format("[{0}].[dal_{1}_insert]", table.Schema, table.Name));
            template.setField("TABLE_NAME", string.Format("[{0}].[{1}]", table.Schema, table.Name));
            template.setField("INSERT_FIELD_NAMES", table.FieldNames);
            //template.setField("INSERT_FIELD_VALUES", "@" + table.FieldNames.Trim().Replace(", \n", ", \n@"));

            template.setField("INSERT_FIELD_NAMES_WITHOUT_PKFIELD", table.FieldNames_WithoutPK);
            //template.setField("INSERT_FIELD_VALUES_WITHOUT_PKFIELD", "@" + table.FieldNames_WithoutPK.Trim().Replace(", \n", ", \n@"));

            string spParams = string.Empty;
            string insertStatements = string.Empty;
            string insertStatements_withoutpk = string.Empty;
            foreach (KeyValuePair<string, Column> col in table.Columns)
            {
                spParams += string.Format("@{0} {1}, \n", col.Value.ColumnName, col.Value.DataTypeFull);
                insertStatements += string.Format("@{0}, \n", col.Value.ColumnName);

                if (col.Value.Key != ConstraintKey.Primary)
                    insertStatements_withoutpk += string.Format("@{0}, \n", col.Value.ColumnName);
            }
            spParams = spParams.TrimEnd(new char[] { ',', ' ', '\n' });
            insertStatements = insertStatements.TrimEnd(new char[] { ',', ' ', '\n' });
            insertStatements_withoutpk = insertStatements_withoutpk.TrimEnd(new char[] { ',', ' ', '\n' });

            template.setField("TABLE_PKFIELD_PARAMNAME", "@"+table.PKField.ColumnName);
            template.setField("TABLE_PKFIELD_DBTYPE", "int"); //table.PKField.DataTypeFull
            template.setField("SP_PARAMS", spParams);
            template.setField("INSERT_FIELD_VALUES", insertStatements);
            template.setField("INSERT_FIELD_VALUES_WITHOUT_PKFIELD", insertStatements_withoutpk);

            template.appendSection();
            template.deselectSection();

            return template.getContent();
        }
Esempio n. 6
0
        // Copy ctor
        public Template(Template srctpl)
        {
            tpl = this;
            fields = new Object[MAX_FIELDS];
            sections = new Object[MAX_FIELDS];

            head = new node();
            addedHead = new node();
            addedTail = addedHead;
            firstSection = new section();

            node tail = head;
            node currNode = srctpl.head;
            section lastSection = firstSection;
            section currSection = srctpl.firstSection.nextSection;

            for (; currSection != null; currSection = currSection.nextSection)
            {
                // Copy part before section
                while (currNode != currSection.preceding)
                {
                    currNode = currNode.next;
                    tail.next = new node();
                    tail = tail.next;
                    if (currNode.val.shared)
                        tail.val = _produceField(((field)currNode.val).key);
                    else
                        tail.val = new cell();
                    tail.val.val = currNode.val.val;
                }

                // Create section entry
                lastSection.nextSection = _produceSection(currSection.key);
                lastSection = lastSection.nextSection;
                lastSection.preceding = tail;
                lastSection.tpl = new Template(currSection.tpl);
                lastSection.tpl.parent = this;

                // Copy added content
                if (currSection.tpl.addedHead.next != null)
                {
                    int len = 0;
                    for (node n = currSection.tpl.addedHead.next; n != null; n = n.next)
                        len += n.val.val.Length;
                    lastSection.tpl.addedTail.next = new node();
                    lastSection.tpl.addedTail = lastSection.tpl.addedTail.next;
                    lastSection.tpl.addedTail.val = new cell();

                    // Make content string
                    StringBuilder sb = new StringBuilder(len);
                    for (node n = currSection.tpl.addedHead.next; n != null; n = n.next)
                        sb.Append(n.val.val);

                    lastSection.tpl.addedTail.val.val = sb.ToString();
                }
            }
            // Copy rest
            while ((currNode = currNode.next) != null)
            {
                tail.next = new node();
                tail = tail.next;
                if (currNode.val.shared)
                    tail.val = _produceField(((field)currNode.val).key);
                else
                    tail.val = new cell();
                tail.val.val = currNode.val.val;
            }
        }
Esempio n. 7
0
 public void selectSection(string key)
 {
     section s = tpl._getSection(key);
     if (s == null)
         fail("selectSection: Cannot find section " + key);
     tpl.tpl = s.tpl;
     tpl = tpl.tpl;
 }
Esempio n. 8
0
 public void deselectSection()
 {
     if (tpl == this)
         fail("deselectSection: No section selected");
     tpl = tpl.parent;
 }
Esempio n. 9
0
        public static string PrepareUserTableClass(Table table)
        {
            Template template = new Template(TemplatesPath + "dalUserTable.tpl");
            template.selectSection("DAL_TABLE");

            template.setField("PROJECT_NAMESPACE", string.Format("{0}.DataAccessLayer", table.Catalog));
            template.setField("TABLE_NAME", table.Name);
            template.setField("TABLE_PKFIELD_NAME", table.PKField.ColumnName);

            template.appendSection();
            template.deselectSection();

            return template.getContent();
        }
Esempio n. 10
0
        public static string PrepareUpdateStoredProcedure(Table table)
        {
            Template template = new Template(TemplatesPath + "dalSPUpdate.tpl");

            template.selectSection("DAL_SP");
            template.setField("DB_NAME", table.Catalog);
            template.setField("SP_NAME", string.Format("[{0}].[dal_{1}_updatebyid]", table.Schema, table.Name));
            template.setField("TABLE_NAME", string.Format("[{0}].[{1}]", table.Schema, table.Name));
            template.setField("TABLE_PKFIELD_NAME", table.PKField.ColumnName);
            template.setField("TABLE_PKFIELD_PARAMNAME", "@" + table.PKField.ColumnName);

            string spParams = string.Empty;
            string setStatements = string.Empty;
            foreach(KeyValuePair<string, Column> col in table.Columns)
            {
                spParams += string.Format("@{0} {1}, \n", col.Value.ColumnName, col.Value.DataTypeFull);
                setStatements += string.Format("[{0}].[{1}].[{2}] = @{2}, \n", table.Schema, table.Name, col.Value.ColumnName);
            }
            spParams = spParams.TrimEnd(new char[] { ',', ' ', '\n' });
            setStatements = setStatements.TrimEnd(new char[] { ',', ' ', '\n' });

            template.setField("SP_PARAMS", spParams);
            template.setField("SP_SET_STATEMENT", setStatements);

            template.appendSection();
            template.deselectSection();

            return template.getContent();
        }
Esempio n. 11
0
        public static string PrepareTableClass(Table table)
        {
            Template template = new Template(TemplatesPath+"dalTable.tpl");
            template.selectSection("DAL_TABLE");
            template.setField("PROJECT_NAMESPACE", string.Format("{0}.DataAccessLayer", table.Catalog));
            template.setField("TABLE_NAME", table.Name);
            template.setField("TABLE_PKFIELD_NAME", table.PKField.ColumnName);
            template.setField("TABLE_PKFIELD_TYPE", table.PKField.DataType4Code);

            template.selectSection("TABLE_STRING_FIELDS");
            foreach (KeyValuePair<string, Column> columnItem in table.Columns)
            {
                template.setField("TABLE_FIELD_TYPE", columnItem.Value.DataType4Code);
                template.setField("TABLE_FIELD_NAME", columnItem.Value.ColumnName);
                template.appendSection();
            }
            template.deselectSection();

            template.selectSection("TABLE_FIELDS");
            foreach (KeyValuePair<string, Column> columnItem in table.Columns)
            {
                template.setField("TABLE_FIELD_TYPE", columnItem.Value.DataType4Code);
                template.setField("TABLE_FIELD_NAME", columnItem.Value.ColumnName);
                template.appendSection();
            }
            template.deselectSection();

            template.selectSection("SAVE_TABLE_FIELDS");
            foreach (KeyValuePair<string, Column> columnItem in table.Columns)
            {
                template.setField("TABLE_DBFIELD_NAME", "@" + columnItem.Value.ColumnName);
                template.setField("TABLE_FIELD_NAME", columnItem.Value.ColumnName);
                template.appendSection();
            }
            template.deselectSection();

            template.selectSection("GETLIST_TABLE_FIELDS");
            foreach (KeyValuePair<string, Column> columnItem in table.Columns)
            {
                template.setField("TABLE_FIELD_TYPE", columnItem.Value.DataType4Code);
                template.setField("TABLE_FIELD_NAME", columnItem.Value.ColumnName);
                template.appendSection();
            }
            template.deselectSection();

            template.selectSection("INIT_TABLE_FIELDS");
            foreach (KeyValuePair<string, Column> columnItem in table.Columns)
            {
                template.setField("TABLE_FIELD_TYPE", columnItem.Value.DataType4Code);
                template.setField("TABLE_FIELD_NAME", columnItem.Value.ColumnName);
                template.appendSection();
            }
            template.deselectSection();

            template.appendSection();
            template.deselectSection();

            return template.getContent();
        }