Click here to Skip to main content
15,885,546 members
Articles / Web Development / ASP.NET

Creating Code for Coding

Rate me:
Please Sign up or sign in to vote.
4.56/5 (9 votes)
18 Sep 2011GPL33 min read 32.7K   559   33  
Creating code to create code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace AspNetBasics
{
    public partial class Interface : Form
    {
        public Interface()
        {
            InitializeComponent();
            textBox1.Text = (string)Application.CommonAppDataRegistry.GetValue("ApplicationName");
            textBox2.Text = (string)Application.CommonAppDataRegistry.GetValue("ConnectionString");

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Application.CommonAppDataRegistry.SetValue("ApplicationName", textBox1.Text);
            Application.CommonAppDataRegistry.SetValue("ConnectionString", textBox2.Text);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Application.CommonAppDataRegistry.SetValue("ApplicationName", textBox1.Text);
            Application.CommonAppDataRegistry.SetValue("ConnectionString", textBox2.Text);

            string dbname = "DB" + textBox1.Text.ToUpper();
            DBHelper.CreateDB(textBox2.Text, dbname);
            DBHelper.AddDBFeatures(textBox2.Text, dbname);

            string path;
            path = System.IO.Path.GetDirectoryName(
               System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase).Replace("file:\\", "");
            Directory.CreateDirectory(path + "\\Output\\" + textBox1.Text);
            Directory.CreateDirectory(path + "\\Output\\" + textBox1.Text + "\\App_Code\\");
            Directory.CreateDirectory(path + "\\Output\\" + textBox1.Text + "\\css\\");

            string webconfig = TextFileHelper.ReadTextFile(path + "\\templates\\web_config.txt");

            webconfig = webconfig.Replace("@CONNECTIONSTRING@", textBox2.Text);
            webconfig = webconfig.Replace("@APPLICATIONNAME@", textBox1.Text);
            webconfig = webconfig.Replace("@INITIALCATALOG@", dbname);

            TextFileHelper.WriteTextFile(webconfig, path + "\\Output\\" + textBox1.Text + "\\web.config");

            string loginaspx = TextFileHelper.ReadTextFile(path + "\\templates\\login_aspx.txt");
            TextFileHelper.WriteTextFile(loginaspx, path + "\\Output\\" + textBox1.Text + "\\login.aspx");

            string loginaspxcs = TextFileHelper.ReadTextFile(path + "\\templates\\login_aspx_cs.txt");
            loginaspxcs = loginaspxcs.Replace("@ROLE1URL@", "admin");
            loginaspxcs = loginaspxcs.Replace("@GENERICUSERURL@", "/default.aspx");
            TextFileHelper.WriteTextFile(loginaspxcs, path + "\\Output\\" + textBox1.Text + "\\login.aspx.cs");

            string configureaspx = TextFileHelper.ReadTextFile(path + "\\templates\\configure_aspx.txt");
            TextFileHelper.WriteTextFile(configureaspx, path + "\\Output\\" + textBox1.Text + "\\configure.aspx");

            string configureaspxcs = TextFileHelper.ReadTextFile(path + "\\templates\\configure_aspx_cs.txt");
            configureaspxcs = configureaspxcs.Replace("@ROLE1@", "Administrators");
            configureaspxcs = configureaspxcs.Replace("@ROLE2@", "Users");
            configureaspxcs = configureaspxcs.Replace("@GENERICUSERURL@", "/default.aspx");
            TextFileHelper.WriteTextFile(configureaspxcs, path + "\\Output\\" + textBox1.Text + "\\configure.aspx.cs");

            string userhelpercs = TextFileHelper.ReadTextFile(path + "\\templates\\userhelper.txt");
            TextFileHelper.WriteTextFile(userhelpercs, path + "\\Output\\" + textBox1.Text + "\\App_Code\\" + "UserHelper.cs");

            string stylesheet = TextFileHelper.ReadTextFile(path + "\\templates\\stylesheet.txt");
            TextFileHelper.WriteTextFile(stylesheet, path + "\\Output\\" + textBox1.Text + "\\css\\" + "StyleSheet.css");

            string defaultaspx = TextFileHelper.ReadTextFile(path + "\\templates\\default_aspx.txt");
            TextFileHelper.WriteTextFile(defaultaspx, path + "\\Output\\" + textBox1.Text + "\\Default.aspx");

            string defaultaspxcs = TextFileHelper.ReadTextFile(path + "\\templates\\default_aspx_cs.txt");
            TextFileHelper.WriteTextFile(defaultaspxcs, path + "\\Output\\" + textBox1.Text + "\\Default.aspx.cs");
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
CEO
Brazil Brazil
"A well written code is self explanatory" - Anonymous Programmer
"The number of meetings is directly proportional to the bad management" - Another Anonymous Programmer
Founder @TIHUNTER.COM.BR
Linkedin Profile

Comments and Discussions