Ejemplo n.º 1
0
        //create listview on user control
        private void generateCustomcontrolListviewClass(string tableName, string projectName)
        {
            string customeFormClass = "";
            customeFormClass += "\n";

            customeFormClass += "using System;\n";
            customeFormClass += "using System.Collections.Generic;\n";
            customeFormClass += "using System.ComponentModel;\n";
            customeFormClass += "using System.Drawing;\n";
            customeFormClass += "using System.Data;\n";
            customeFormClass += "using System.Linq;\n";
            customeFormClass += "using System.Text;\n";
            customeFormClass += "using System.Windows.Forms;\n";
            customeFormClass += "using " + projectName + ".model;\n";

            customeFormClass += "namespace " + projectName;
            customeFormClass += "{\n";
            customeFormClass += "   public partial class UserControl" + tableName + "view : UserControl\n";
            customeFormClass += "   {\n";
            customeFormClass += "       public UserControl" + tableName + "view()\n";
            customeFormClass += "       {\n";
            customeFormClass += "           InitializeComponent();\n";
            customeFormClass += "       }\n";
            customeFormClass += "       int selectedIndex = 0;\n";
            customeFormClass += "       private void UserControl" + tableName + "view_Load(object sender, EventArgs e)\n";
            customeFormClass += "       {\n";

            customeFormClass += " loaddata" + tableName + "(\"\");\n";
            customeFormClass += "       }\n";

            customeFormClass += "//this function is used for search\n";
            customeFormClass += "  public void loaddata" + tableName + "(string whereclause)\n";
            customeFormClass += "  {\n";
            customeFormClass += " listView1.Columns.Clear();\n";
            DataTable dat = new Connectoperations().describeTable(tableName);
            customeFormClass += "           listView1.Columns.Add(\"No\", 50, HorizontalAlignment.Left);\n";
            bool setidwith = true;
            int columnWidth=100;
            foreach (DataRow row in dat.Rows)
            {
                //set id column width to 0 id
                if (setidwith)
                {
                    columnWidth = 0;
                    setidwith = false;
                }
                else
                {
                    columnWidth = 100;
                }

                string attribute = row[0].ToString();
                customeFormClass += "           listView1.Columns.Add(\"" + attribute + "\", "+columnWidth+", HorizontalAlignment.Left);\n";

            }
            customeFormClass += "       DataTable dat = new " + tableName + "muid().selecttable" + tableName + "(\"*\", whereclause);\n";
            customeFormClass += "    listView1.Items.Clear();\n";
            customeFormClass += "    int counter = 1;\n";
            customeFormClass += "    foreach (DataRow row in dat.Rows)\n";
            customeFormClass += "     {\n";
            customeFormClass += "        ListViewItem lv = new ListViewItem(counter.ToString());\n";
            for (int i = 0; i < dat.Rows.Count; i++)
            {
                customeFormClass += "        lv.SubItems.Add(row[" + i + "].ToString());\n";
            }
            customeFormClass += "        counter++;\n";
            customeFormClass += "        listView1.Items.Add(lv);\n";
            customeFormClass += "    }\n";
            customeFormClass += "}\n";

            //hasMany functions
            customeFormClass += "//has many functions\n";
            //create associations
            List<ClassRelations> lcr = new List<ClassRelations>();
            lcr = new ClassGenerateRelation().loadRelations(projectName, ".NET", "Forms", "C#", tableName);
            for (int x = 0; x < lcr.Count; x++)
            {
                if (lcr[x].name == tableName)
                {
                    //create has class methods

                    //create field name for the hastables

                    for (int y = 0; y < lcr[x].has.Count; y++)
                    {
                        string[] hasString = lcr[x].has[y].Split('#');
                        string hasTableName = hasString[0];
                        string hasField = hasString[1];
                        //create fieldname for the current table
                        customeFormClass += "  private void loaddata" + tableName + hasTableName + "hasMany(string andorclause)\n";
                        customeFormClass += "  {\n";
                        customeFormClass += "listView1.Columns.Clear();\n";
                       DataTable datparent = new Connectoperations().describeTable(tableName);
                        customeFormClass += "           listView1.Columns.Add(\"No\", 50, HorizontalAlignment.Left);\n";

                        foreach (DataRow row in datparent.Rows)
                        {

                                string attribute =tableName+ row[0].ToString();

                                    attribute = tableName +":"+ row[0].ToString();

                                customeFormClass += "           listView1.Columns.Add(\"" + attribute + "\", 100, HorizontalAlignment.Left);\n";

                        }
                       DataTable datchild = new Connectoperations().describeTable(hasTableName);

                        foreach (DataRow row in datchild.Rows)
                        {

                                string attribute = row[0].ToString();

                                    attribute = hasTableName +":"+ row[0].ToString();

                                customeFormClass += "           listView1.Columns.Add(\"" + attribute + "\", 100, HorizontalAlignment.Left);\n";

                        }
                        customeFormClass += "       DataTable dat = new " + tableName + "muid()." + tableName + hasTableName + "hasMany(andorclause);\n";
                        customeFormClass += "    listView1.Items.Clear();\n";
                        customeFormClass += "    int counter = 1;\n";
                        customeFormClass += "    foreach (DataRow row in dat.Rows)\n";
                        customeFormClass += "     {\n";
                        customeFormClass += "        ListViewItem lv = new ListViewItem(counter.ToString());\n";
                       //get the fields

                        for (int i = 0; i < (datparent.Rows.Count+datchild.Rows.Count); i++)
                        {
                            customeFormClass += "        lv.SubItems.Add(row[" + i + "].ToString());\n";
                        }
                        customeFormClass += "        counter++;\n";
                        customeFormClass += "        listView1.Items.Add(lv);\n";
                        customeFormClass += "    }\n";
                        customeFormClass += "}\n";
                    }//end has to

                    //create field name for the belongs

                    //for (int y = 0; y < lcr[x].belongsTo.Count; y++)
                    //{
                    //    string[] belongsToString = lcr[x].belongsTo[y].Split('#');
                    //    string belongsToTableName = belongsToString[0];
                    //    string belongsToField = belongsToString[1];
                    //    //create fieldname for the current table
                    //    customeFormClass += "  private void loaddata" + tableName + belongsToTableName + "(string andorclause)\n";
                    //    customeFormClass += "  {\n";
                    //    customeFormClass += "listView1.Columns.Clear();\n";
                    //    DataTable datparent = new Connectoperations().describeTable(tableName);
                    //    customeFormClass += "           listView1.Columns.Add(\"No\", 50, HorizontalAlignment.Left);\n";

                    //    foreach (DataRow row in datparent.Rows)
                    //    {

                    //        string attribute = tableName + row[0].ToString();

                    //        attribute = tableName + ":" + row[0].ToString();

                    //        customeFormClass += "           listView1.Columns.Add(\"" + attribute + "\", 100, HorizontalAlignment.Left);\n";

                    //    }
                    //    DataTable datchild = new Connectoperations().describeTable(belongsToTableName);

                    //    foreach (DataRow row in datchild.Rows)
                    //    {

                    //        string attribute = row[0].ToString();

                    //        attribute = belongsToTableName + ":" + row[0].ToString();

                    //        customeFormClass += "           listView1.Columns.Add(\"" + attribute + "\", 100, HorizontalAlignment.Left);\n";

                    //    }
                    //    customeFormClass += "       DataTable dat = new " + tableName + "muid()." + tableName + belongsToTableName + "(andorclause);\n";
                    //    customeFormClass += "    listView1.Items.Clear();\n";
                    //    customeFormClass += "    int counter = 1;\n";
                    //    customeFormClass += "    foreach (DataRow row in dat.Rows)\n";
                    //    customeFormClass += "     {\n";
                    //    customeFormClass += "        ListViewItem lv = new ListViewItem(counter.ToString());\n";
                    //    //get the fields

                    //    for (int i = 0; i < (datparent.Rows.Count + datchild.Rows.Count); i++)
                    //    {
                    //        customeFormClass += "        lv.SubItems.Add(row[" + i + "].ToString());\n";
                    //    }
                    //    customeFormClass += "        counter++;\n";
                    //    customeFormClass += "        listView1.Items.Add(lv);\n";
                    //    customeFormClass += "    }\n";
                    //    customeFormClass += "}\n";
                    //}//end belongs to

                }
            }
            //events for assoc
              // List<ClassRelations> lcr = new List<ClassRelations>();
            lcr = new ClassGenerateRelation().loadRelations(projectName, ".NET", "Forms", "C#", tableName);
            for (int x = 0; x < lcr.Count; x++)
            {
                if (lcr[x].name == tableName)
                {
                    //create has class methods

                    //create field name for the hastables

                    for (int y = 0; y < lcr[x].has.Count; y++)
                    {
                        string[] hasString = lcr[x].has[y].Split('#');
                        string hasTableName = hasString[0];
                        string hasField = hasString[1];
                        customeFormClass += " private void "+tableName+hasTableName+"ToolStripMenuItem_Click(object sender, EventArgs e)\n";
                       customeFormClass += "  {\n";
                       customeFormClass += "       loaddata" + tableName + hasTableName + "hasMany(\" and \" + toolStripComboBox1.Text + \" like '%\" + toolStripTextBox1.Text + \"%'\");  \n";
                        customeFormClass += " }\n";
                    }//end has

                    //create field name for the hastables

                    //for (int y = 0; y < lcr[x].belongsTo.Count; y++)
                    //{
                    //    string[] belongsToString = lcr[x].belongsTo[y].Split('#');
                    //    string belongsToTableName = belongsToString[0];
                    //    string belongsToField = belongsToString[1];
                    //    customeFormClass += " private void " + tableName + belongsToTableName + "ToolStripMenuItem_Click(object sender, EventArgs e)\n";
                    //    customeFormClass += "  {\n";
                    //    customeFormClass += "       loaddata" + tableName + belongsToTableName + "(\" and \" + toolStripComboBox1.Text + \" like '%\" + toolStripTextBox1.Text + \"%'\");  \n";
                    //    customeFormClass += " }\n";
                    //}
                }
            }
            customeFormClass += " private void " + tableName + "ToolStripMenuItem_Click(object sender, EventArgs e)\n";
            customeFormClass += "  {\n";
            customeFormClass += "       loaddata" + tableName + "(\"where \" + toolStripComboBox1.Text + \" like '%\" + toolStripTextBox1.Text + \"%'\");  \n";
            customeFormClass += " }\n";
            customeFormClass += "//search any record in the listview\n";
            customeFormClass += " private void toolStripMenuItemSearch_Click(object sender, EventArgs e)\n";
            customeFormClass += "{\n";
            customeFormClass += " loaddata"+tableName+"(\"where \" + toolStripComboBox1.Text + \" like '%\" + toolStripTextBox1.Text + \"%'\");\n";
            customeFormClass += "}\n";
            customeFormClass += " private void updateToolStripMenuItem_Click(object sender, EventArgs e)\n";
            customeFormClass += "{\n";
            //customeFormClass += " new Form" + tableName + "muid().Show();\n";
            customeFormClass += ("Form" + tableName + "muid " + tableName + "muid = new Form" + tableName + "muid();\n");
            //link to the MUID Form/user control
            customeFormClass += (tableName + "muid.userControl" + tableName + "insert1.loaddata(listView1, selectedIndex, 1);\n");
            customeFormClass += (tableName + "muid.Show();\n");
            customeFormClass += "}\n";
            //TODO implement Clearing of input fields
            customeFormClass += " private void newToolStripMenuItem_Click(object sender, EventArgs e)\n";
            customeFormClass += "{\n";
            //customeFormClass += " new Form" + tableName + "muid().Show();\n";
            customeFormClass += ("Form" + tableName + "muid " + tableName + "muid = new Form" + tableName + "muid();\n");
            //link to the MUID Form/user control
            customeFormClass += (tableName + "muid.userControl" + tableName + "insert1.loaddata(listView1, selectedIndex, 0);\n");
            customeFormClass += (tableName + "muid.Show();\n");
            customeFormClass += "}\n";

            customeFormClass += "private void deleteToolStripMenuItem_Click(object sender, EventArgs e)\n";
            customeFormClass += "{\n";

            customeFormClass += "}\n";
            customeFormClass += "private void listView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)\n";
            customeFormClass += "{\n";
            customeFormClass += "selectedIndex = e.ItemIndex;\n";
            customeFormClass += "}\n";
            customeFormClass += "   }\n";
            customeFormClass += "}\n";

            string path = "";
            path = Directory.GetCurrentDirectory() + "\\" + projectName + "\\" + projectName + "\\view\\UserControl" + tableName + "view.cs";
            File.WriteAllText(path, customeFormClass);
        }
Ejemplo n.º 2
0
        private void generateCustomcontrolListviewDesigner(string tableName, string projectName, List<string> mycontrols)
        {
            string customeFormDesigner = "";
            customeFormDesigner += "\n";

            customeFormDesigner += "  namespace " + projectName + "\n";
            customeFormDesigner += "{\n";
            customeFormDesigner += "partial class UserControl" + tableName + "view\n";
            customeFormDesigner += "{\n";
            customeFormDesigner += "    private System.ComponentModel.IContainer components = null;\n";

            customeFormDesigner += " protected override void Dispose(bool disposing)\n";
            customeFormDesigner += "        {\n";
            customeFormDesigner += "           if (disposing && (components != null))\n";
            customeFormDesigner += "           {\n";
            customeFormDesigner += "              components.Dispose();\n";
            customeFormDesigner += "          }\n";
            customeFormDesigner += "           base.Dispose(disposing);\n";
            customeFormDesigner += "       }\n";

            customeFormDesigner += "        #region Component Designer generated code\n";

            customeFormDesigner += "        private void InitializeComponent()\n";
            customeFormDesigner += "       {\n";
            customeFormDesigner += "          this.components = new System.ComponentModel.Container();\n";
            customeFormDesigner += "           this.groupBox1 = new System.Windows.Forms.GroupBox();\n";
            customeFormDesigner += "           this.listView1 = new System.Windows.Forms.ListView();\n";
            customeFormDesigner += "           this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);\n";
            customeFormDesigner += "           this.toolStripMenuItemView = new System.Windows.Forms.ToolStripMenuItem();\n";
            //view toolstripmenuitem go here

            customeFormDesigner += "           this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();\n";
            //edit toolstripmenuitem go here
            customeFormDesigner += "           this.updateToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();\n";
            customeFormDesigner += "           this.newToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();\n";
            customeFormDesigner += "           this.deleteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();\n";

            customeFormDesigner += "           this.menuStrip1 = new System.Windows.Forms.MenuStrip();\n";
            customeFormDesigner += "           this.toolStripComboBox1 = new System.Windows.Forms.ToolStripComboBox();\n";
            customeFormDesigner += "           this.toolStripTextBox1 = new System.Windows.Forms.ToolStripTextBox();\n";
            customeFormDesigner += "           this.toolStripMenuItemSearch = new System.Windows.Forms.ToolStripMenuItem();\n";
            //association
             //create associations
            List<ClassRelations> lcr = new List<ClassRelations>();
            lcr = new ClassGenerateRelation().loadRelations(projectName, ".NET", "Forms", "C#", tableName);
            for (int x = 0; x < lcr.Count; x++)
            {
                if (lcr[x].name == tableName)
                {
                    //create has class methods

                    //create field name for the hastables

                    for (int y = 0; y < lcr[x].has.Count; y++)
                    {
                        string[] hasString = lcr[x].has[y].Split('#');
                        string hasTableName = hasString[0];
                        string hasField = hasString[1];
                        customeFormDesigner += " this."+tableName+hasTableName+"ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();\n";
                    }

                    //create field name for the belongstables

                    //for (int y = 0; y < lcr[x].belongsTo.Count; y++)
                    //{
                    //    string[] belongsToString = lcr[x].belongsTo[y].Split('#');
                    //    string belongsToTableName = belongsToString[0];
                    //    string belongsToField = belongsToString[1];
                    //    customeFormDesigner += " this." + tableName + belongsToTableName + "ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();\n";
                    //}
                }
            }
            customeFormDesigner += " this." + tableName+ "ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();\n";

            customeFormDesigner += "          this.groupBox1.SuspendLayout();\n";
            customeFormDesigner += "          this.contextMenuStrip1.SuspendLayout();\n";
            customeFormDesigner += "          this.menuStrip1.SuspendLayout();\n";
            customeFormDesigner += "          this.SuspendLayout();\n";
            customeFormDesigner += "         // \n";
            customeFormDesigner += "           // groupBox1\n";
            customeFormDesigner += "            // \n";
            customeFormDesigner += "            this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)\n";
            customeFormDesigner += "                       | System.Windows.Forms.AnchorStyles.Left)\n";
            customeFormDesigner += "                       | System.Windows.Forms.AnchorStyles.Right)));\n";
            customeFormDesigner += "           this.groupBox1.Controls.Add(this.listView1);\n";
            customeFormDesigner += "           this.groupBox1.Location = new System.Drawing.Point(3, 28);\n";
            customeFormDesigner += "          this.groupBox1.Name = \"groupBox1\";\n";
            customeFormDesigner += "          this.groupBox1.Size = new System.Drawing.Size(694, 348);\n";
            customeFormDesigner += "          this.groupBox1.TabIndex = 0;\n";
            customeFormDesigner += "          this.groupBox1.TabStop = false;\n";
            customeFormDesigner += "           this.groupBox1.Text = \"\";\n";
            customeFormDesigner += "          // \n";
            customeFormDesigner += "          // listView1\n";
            customeFormDesigner += "          // \n";
            customeFormDesigner += "          this.listView1.ContextMenuStrip = this.contextMenuStrip1;\n";
            customeFormDesigner += "           this.listView1.Dock = System.Windows.Forms.DockStyle.Fill;\n";
            customeFormDesigner += "          this.listView1.FullRowSelect = true;\n";
            customeFormDesigner += "          this.listView1.GridLines = true;\n";
            customeFormDesigner += "           this.listView1.Location = new System.Drawing.Point(3, 16);\n";
            customeFormDesigner += "           this.listView1.Name = \"listView1\";\n";
            customeFormDesigner += "           this.listView1.Size = new System.Drawing.Size(688, 329);\n";
            customeFormDesigner += "           this.listView1.TabIndex = 0;\n";
            customeFormDesigner += "           this.listView1.UseCompatibleStateImageBehavior = false;\n";
            customeFormDesigner += "           this.listView1.View = System.Windows.Forms.View.Details;\n";
            customeFormDesigner += "           this.listView1.ItemSelectionChanged += new System.Windows.Forms.ListViewItemSelectionChangedEventHandler(this.listView1_ItemSelectionChanged);\n";
            customeFormDesigner += "           // \n";
            customeFormDesigner += "           // contextMenuStrip1\n";
            customeFormDesigner += "           // \n";
            customeFormDesigner += "           this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {\n";
            customeFormDesigner += "           this.toolStripMenuItemView,\n";
            customeFormDesigner += "           this.editToolStripMenuItem});\n";
            customeFormDesigner += "           this.contextMenuStrip1.Name = \"contextMenuStrip1\";\n";
            customeFormDesigner += "          this.contextMenuStrip1.RenderMode = System.Windows.Forms.ToolStripRenderMode.System;\n";
            customeFormDesigner += "           this.contextMenuStrip1.Size = new System.Drawing.Size(100, 26);\n";
            customeFormDesigner += "          // \n";
            customeFormDesigner += "          // toolStripMenuItemView\n";
            customeFormDesigner += "           // \n";
            customeFormDesigner += "           this.toolStripMenuItemView.Name = \"toolStripMenuItemView\";\n";
            customeFormDesigner += "           this.toolStripMenuItemView.Size = new System.Drawing.Size(99, 22);\n";
            customeFormDesigner += "           this.toolStripMenuItemView.Text = \"View\";\n";
            customeFormDesigner += "          // \n";
            customeFormDesigner += "           // menuStrip1\n";
            customeFormDesigner += "           // \n";
            customeFormDesigner += "          this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {\n";
            customeFormDesigner += "          this.toolStripComboBox1,\n";
            customeFormDesigner += "          this.toolStripTextBox1,\n";
            customeFormDesigner += "          this.toolStripMenuItemSearch});\n";
            customeFormDesigner += "           this.menuStrip1.Location = new System.Drawing.Point(0, 0);\n";
            customeFormDesigner += "           this.menuStrip1.Name = \"menuStrip1\";\n";
            customeFormDesigner += "           this.menuStrip1.Size = new System.Drawing.Size(700, 27);\n";
            customeFormDesigner += "          this.menuStrip1.TabIndex = 1;\n";
            customeFormDesigner += "          this.menuStrip1.Text = \"menuStrip1\";\n";
            customeFormDesigner += "         // \n";
            customeFormDesigner += "         // toolStripComboBox1\n";
            customeFormDesigner += "         // \n";
            customeFormDesigner += "          this.toolStripComboBox1.Items.AddRange(new object[] {\n";
            DataTable dat = new Connectoperations().describeTable(tableName);
            string delimeter = ",";
            string str = "";
            int i = 0;
            foreach (DataRow row in dat.Rows)
            {
                if (i++ > dat.Rows.Count - 2)
                    delimeter = "";
                str += "\"" + row[0].ToString() + "\"" + delimeter;
            }
            customeFormDesigner += str;

            //hasmany search fields
             //List<ClassRelations> lcr = new List<ClassRelations>();
            lcr = new ClassGenerateRelation().loadRelations(projectName, ".NET", "Forms", "C#", tableName);
            for (int x = 0; x < lcr.Count; x++)
            {
                if (lcr[x].name == tableName)
                {
                    //create has class methods

                    //create field name for the hastables

                    for (int y = 0; y < lcr[x].has.Count; y++)
                    {
                        string mydelim = ",\n";
                        string[] hasString = lcr[x].has[y].Split('#');
                        string hasTableName = hasString[0];
                        dat = new Connectoperations().describeTable(hasTableName);
                        customeFormDesigner += ",";
                        string hasField = hasString[1];

                        for(int a=1;a<dat.Rows.Count;a++)
                        {
                            if (a > dat.Rows.Count - 2)
                            {
                                mydelim = "";
                            }
                        customeFormDesigner +="\""+dat.Rows[a][0].ToString()+"\""+mydelim+"\n";
                        }
                    }

                    //create field name for the hastables

                    //for (int y = 0; y < lcr[x].belongsTo.Count; y++)
                    //{
                    //    string mydelim = ",\n";
                    //    string[] belongsToString = lcr[x].belongsTo[y].Split('#');
                    //    string belongsToTableName = belongsToString[0];
                    //    dat = new Connectoperations().describeTable(belongsToTableName);
                    //    customeFormDesigner += ",";
                    //    string belongsToField = belongsToString[1];

                    //    for (int a = 1; a < dat.Rows.Count; a++)
                    //    {
                    //        if (a > dat.Rows.Count - 2)
                    //        {
                    //            mydelim = "";
                    //        }
                    //        customeFormDesigner += "\"" + dat.Rows[a][0].ToString() + "\"" + mydelim + "\n";
                    //    }
                    //}

                }
            }

            customeFormDesigner += " });\n";
            customeFormDesigner += "         this.toolStripComboBox1.Name = \"toolStripComboBox1\";\n";
            customeFormDesigner += "         this.toolStripComboBox1.Size = new System.Drawing.Size(121, 23);\n";
            customeFormDesigner += "         // \n";
            customeFormDesigner += "          // toolStripTextBox1\n";
            customeFormDesigner += "          // \n";
            customeFormDesigner += "          this.toolStripTextBox1.Name = \"toolStripTextBox1\";\n";
            customeFormDesigner += "          this.toolStripTextBox1.Size = new System.Drawing.Size(200, 23);\n";
            customeFormDesigner += "           // \n";
            customeFormDesigner += "          // toolStripMenuItemSearch\n";
            customeFormDesigner += "          // \n";
             //create associations
            //List<ClassRelations> lcr = new List<ClassRelations>();
            lcr = new ClassGenerateRelation().loadRelations(projectName, ".NET", "Forms", "C#", tableName);
            //create field name for the hastables
            customeFormDesigner += " this.toolStripMenuItemSearch.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {\n";
            customeFormDesigner += "this." + tableName + "ToolStripMenuItem\n";
            for (int x = 0; x < lcr.Count; x++)
            {
                if (lcr[x].name == tableName)
                {
                    //create has class methods

                    if (lcr[x].has.Count> 0)
                    {
                        customeFormDesigner += ",";
                    }

                    for (int y = 0; y < lcr[x].has.Count; y++)
                    {
                        string mydelim = ",";

                        string[] hasString = lcr[x].has[y].Split('#');
                        string hasTableName = hasString[0];
                        string hasField = hasString[1];
                        if (y > lcr[x].has.Count - 2)
                        {
                            mydelim = "";
                        }
                        customeFormDesigner += "this."+tableName+hasTableName+"ToolStripMenuItem" + mydelim +"\n";

                    }

                    //create has class methods

                    //if (lcr[x].belongsTo.Count > 0)
                    //{
                    //    customeFormDesigner += ",";
                    //}

                    //for (int y = 0; y < lcr[x].belongsTo.Count; y++)
                    //{
                    //    string mydelim = ",";

                    //    string[] belongsToString = lcr[x].belongsTo[y].Split('#');
                    //    string belongsToTableName = belongsToString[0];
                    //    string belongsToField = belongsToString[1];
                    //    if (y > lcr[x].has.Count - 2)
                    //    {
                    //        mydelim = "";
                    //    }
                    //    customeFormDesigner += "this." + tableName + belongsToTableName + "ToolStripMenuItem" + mydelim + "\n";

                    //}

                }
            }
            customeFormDesigner += "});\n";
             customeFormDesigner += "          this.toolStripMenuItemSearch.Name = \"toolStripMenuItemSearch\";\n";
             customeFormDesigner += "          this.toolStripMenuItemSearch.Size = new System.Drawing.Size(54, 23);\n";
             customeFormDesigner += "          this.toolStripMenuItemSearch.Text = \"View&Search\";\n";

             customeFormDesigner += "          // \n";

              //assoc

            //create associations
               // List<ClassRelations> lcr = new List<ClassRelations>();
            lcr = new ClassGenerateRelation().loadRelations(projectName, ".NET", "Forms", "C#", tableName);
            for (int x = 0; x < lcr.Count; x++)
            {
                if (lcr[x].name == tableName)
                {
                    //create has class methods

                    //create field name for the hastables

                    for (int y = 0; y < lcr[x].has.Count; y++)
                    {
                        string[] hasString = lcr[x].has[y].Split('#');
                        string hasTableName = hasString[0];
                        string hasField = hasString[1];
                        customeFormDesigner += "  this."+tableName+hasTableName+"ToolStripMenuItem.Name = \"studentToolStripMenuItem\";\n";
                        customeFormDesigner += "  this."+tableName+hasTableName+"ToolStripMenuItem.Size = new System.Drawing.Size(152, 22);\n";
                        customeFormDesigner += "  this."+tableName+hasTableName+"ToolStripMenuItem.Text = \""+tableName+"->"+hasTableName+"\";\n";
                        customeFormDesigner += "  this." + tableName + hasTableName + "ToolStripMenuItem.Click += new System.EventHandler(this." + tableName + hasTableName + "ToolStripMenuItem_Click);\n";

                    }

                    //create field name for the hastables

                    //for (int y = 0; y < lcr[x].belongsTo.Count; y++)
                    //{
                    //    string[] belongsToString = lcr[x].belongsTo[y].Split('#');
                    //    string belongsToTableName = belongsToString[0];
                    //    string belongsToField = belongsToString[1];
                    //    customeFormDesigner += "  this." + tableName + belongsToTableName + "ToolStripMenuItem.Name = \"studentToolStripMenuItem\";\n";
                    //    customeFormDesigner += "  this." + tableName + belongsToTableName + "ToolStripMenuItem.Size = new System.Drawing.Size(152, 22);\n";
                    //    customeFormDesigner += "  this." + tableName + belongsToTableName + "ToolStripMenuItem.Text = \"" + tableName + "->" + belongsToTableName + "\";\n";
                    //    customeFormDesigner += "  this." + tableName + belongsToTableName + "ToolStripMenuItem.Click += new System.EventHandler(this." + tableName + belongsToTableName + "ToolStripMenuItem_Click);\n";

                    //}
                }
            }
            //default table
            customeFormDesigner += "  this." + tableName + "ToolStripMenuItem.Name = \"studentToolStripMenuItem\";\n";
            customeFormDesigner += "  this." + tableName + "ToolStripMenuItem.Size = new System.Drawing.Size(152, 22);\n";
            customeFormDesigner += "  this." + tableName + "ToolStripMenuItem.Text = \"" + tableName + "->" + "\";\n";
            customeFormDesigner += "  this." + tableName + "ToolStripMenuItem.Click += new System.EventHandler(this." + tableName+"ToolStripMenuItem_Click);\n";

            //view items go here
            customeFormDesigner += "           // \n";
            customeFormDesigner += "           // editToolStripMenuItem\n";
            customeFormDesigner += "           // \n";
            customeFormDesigner += "          this.editToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {\n";
            customeFormDesigner += "          this.updateToolStripMenuItem,\n";
            customeFormDesigner += "          this.newToolStripMenuItem,\n";
            customeFormDesigner += "          this.deleteToolStripMenuItem});\n";
            customeFormDesigner += "          this.editToolStripMenuItem.Name = \"editToolStripMenuItem\";\n";
            customeFormDesigner += "          this.editToolStripMenuItem.Size = new System.Drawing.Size(152, 22);\n";
            customeFormDesigner += "          this.editToolStripMenuItem.Text = \"Edit\";\n";
            customeFormDesigner += "          // \n";
            customeFormDesigner += "          // updateToolStripMenuItem\n";
            customeFormDesigner += "          // \n";
            customeFormDesigner += "          this.updateToolStripMenuItem.Name = \"updateToolStripMenuItem\";\n";
            customeFormDesigner += "          this.updateToolStripMenuItem.Size = new System.Drawing.Size(152, 22);\n";
            customeFormDesigner += "          this.updateToolStripMenuItem.Text = \"Update\";\n";
            customeFormDesigner += "          this.updateToolStripMenuItem.Click += new System.EventHandler(this.updateToolStripMenuItem_Click);\n";
            customeFormDesigner += "          // \n";
            customeFormDesigner += "          // newToolStripMenuItem\n";
            customeFormDesigner += "          // \n";
            customeFormDesigner += "          this.newToolStripMenuItem.Name = \"newToolStripMenuItem\";\n";
            customeFormDesigner += "          this.newToolStripMenuItem.Size = new System.Drawing.Size(152, 22);\n";
            customeFormDesigner += "          this.newToolStripMenuItem.Text = \"New\";\n";
            customeFormDesigner += "          this.newToolStripMenuItem.Click += new System.EventHandler(this.newToolStripMenuItem_Click);\n";
            customeFormDesigner += "          // \n";
            customeFormDesigner += "          // deleteToolStripMenuItem\n";
            customeFormDesigner += "          // \n";
            customeFormDesigner += "          this.deleteToolStripMenuItem.Name = \"deleteToolStripMenuItem\";\n";
            customeFormDesigner += "          this.deleteToolStripMenuItem.Size = new System.Drawing.Size(152, 22);\n";
            customeFormDesigner += "          this.deleteToolStripMenuItem.Text = \"Delete\";\n";
            customeFormDesigner += "          this.deleteToolStripMenuItem.Click += new System.EventHandler(this.deleteToolStripMenuItem_Click);\n";
            customeFormDesigner += "          // UserControlgreenapple\n";
            customeFormDesigner += "          // \n";
            customeFormDesigner += "           this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);\n";
            customeFormDesigner += "          this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;\n";
            customeFormDesigner += "         this.Controls.Add(this.groupBox1);\n";
            customeFormDesigner += "         this.Controls.Add(this.menuStrip1);\n";
            customeFormDesigner += "         this.Name = \"UserControl" + tableName + "view\";\n";
            customeFormDesigner += "         this.Size = new System.Drawing.Size(700, 379);\n";
            customeFormDesigner += "         this.Load += new System.EventHandler(this.UserControl" + tableName + "view_Load);\n";
            customeFormDesigner += "         this.groupBox1.ResumeLayout(false);\n";
            customeFormDesigner += "         this.contextMenuStrip1.ResumeLayout(false);\n";
            customeFormDesigner += "         this.menuStrip1.ResumeLayout(false);\n";
            customeFormDesigner += "         this.menuStrip1.PerformLayout();\n";
            customeFormDesigner += "         this.ResumeLayout(false);\n";
            customeFormDesigner += "         this.PerformLayout();\n";

            customeFormDesigner += "      }\n";

            customeFormDesigner += "      #endregion\n";

            customeFormDesigner += "      private System.Windows.Forms.GroupBox groupBox1;\n";
            customeFormDesigner += "      private System.Windows.Forms.MenuStrip menuStrip1;\n";
            customeFormDesigner += "       private System.Windows.Forms.ToolStripComboBox toolStripComboBox1;\n";
            customeFormDesigner += "       private System.Windows.Forms.ToolStripTextBox toolStripTextBox1;\n";
            customeFormDesigner += "       private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemSearch;\n";
            customeFormDesigner += "        private System.Windows.Forms.ListView listView1;\n";
            customeFormDesigner += "        private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;\n";
            customeFormDesigner += "       private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemView;\n";
            //view toolstripmenuitem go here

            customeFormDesigner += " private System.Windows.Forms.ToolStripMenuItem editToolStripMenuItem;\n";
            //edit toolstripmenuitem go here
            customeFormDesigner += " private System.Windows.Forms.ToolStripMenuItem updateToolStripMenuItem;\n";
            customeFormDesigner += " private System.Windows.Forms.ToolStripMenuItem newToolStripMenuItem;\n";
            customeFormDesigner += " private System.Windows.Forms.ToolStripMenuItem deleteToolStripMenuItem;\n";
            //add table association menus

            //create associations
            //List<ClassRelations> lcr = new List<ClassRelations>();
            lcr = new ClassGenerateRelation().loadRelations(projectName, ".NET", "Forms", "C#", tableName);
            for (int x = 0; x < lcr.Count; x++)
            {
                if (lcr[x].name == tableName)
                {
                    //create has class methods

                    //create field name for the hastables

                    for (int y = 0; y < lcr[x].has.Count; y++)
                    {
                        string[] hasString = lcr[x].has[y].Split('#');
                        string hasTableName = hasString[0];
                        string hasField = hasString[1];
                        customeFormDesigner += " private System.Windows.Forms.ToolStripMenuItem "+tableName+hasTableName+"ToolStripMenuItem;\n";
                    }

                    //create field name for the belong to

                    //for (int y = 0; y < lcr[x].belongsTo.Count; y++)
                    //{
                    //    string[] belongsToString = lcr[x].belongsTo[y].Split('#');
                    //    string belongsToTableName = belongsToString[0];
                    //    string belongsToField = belongsToString[1];
                    //    customeFormDesigner += " private System.Windows.Forms.ToolStripMenuItem " + tableName + belongsToTableName + "ToolStripMenuItem;\n";
                    //}
                }
            }
            //create for current table
            customeFormDesigner += " private System.Windows.Forms.ToolStripMenuItem " + tableName + "ToolStripMenuItem;\n";

            customeFormDesigner += "   }\n";
            customeFormDesigner += "}\n";

            string path = "";
            path = Directory.GetCurrentDirectory() + "\\" + projectName + "\\" + projectName + "\\view\\UserControl" + tableName + "view.Designer.cs";
            File.WriteAllText(path, customeFormDesigner);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// genereates muid ie merge,update,insert and delete methods
        /// </summary>
        /// <param name="tableName">the name of the table for which muid is being generated</param>
        /// <returns>string</returns>
        public string generateMUID(string tableName,string projectName)
        {
            string muidString = "";
            try
            {
                muidString += "\n";
                //create insert
                muidString += "public bool insert" + tableName + " (string attributes,string values){\n";
                muidString += "if(new " + tableName + "Control().BeforeInsert()==true){\n";
                muidString += "if(new Connectoperations().insert(\"" + tableName + "\",attributes,values)>0){\n";
                muidString += "MessageBox.Show(\"captured!\");\n";
                muidString += "if(new " + tableName + "Control().AfterInsert()==true){\n";
                muidString += "return true;\n";
                muidString += "}\n";
                muidString += "else{\n";
                muidString += "return false;\n";
                muidString += "}\n";
                muidString += "}\n";
                muidString += "else{\n";
                muidString += "MessageBox.Show(\"Failed!\");\n";
                muidString += "return false;\n";
                muidString += "}\n";
                muidString += "}\n";
                muidString += "else{\n";
                muidString += "MessageBox.Show(\"Failed!\");\n";
                muidString += "return false;\n";
                muidString += "}\n";
                muidString += "}\n";
                //create update
                muidString += "public bool update" + tableName + " (string attributes,string values,string where){\n";
                muidString += "if(new " + tableName + "Control().BeforeUpdate()==true){\n";
                muidString += "if(new Connectoperations().update(\"" + tableName + "\",attributes,values,where)>0){\n";
                muidString += "MessageBox.Show(\"updated!\");\n";
                muidString += "if(new " + tableName + "Control().AfterUpdate()==true){\n";
                muidString += "return true;\n";
                muidString += "}\n";
                muidString += "else{\n";
                muidString += "return false;\n";
                muidString += "}\n";
                muidString += "}\n";
                muidString += "else{\n";
                muidString += "MessageBox.Show(\"Failed!\");\n";
                muidString += "return false;\n";
                muidString += "}\n";
                muidString += "}\n";
                muidString += "else{\n";
                muidString += "MessageBox.Show(\"Failed!\");\n";
                muidString += "return false;\n";
                muidString += "}\n";
                muidString += "}\n";
                //create select

                muidString += "public DataTable selecttable" + tableName + "(string attributes,string where){\n";
                muidString += "DataTable dt= new DataTable();\n";
                muidString += "if(new " + tableName + "Control().BeforeSelect()==true){\n";
                muidString += "dt=new Connectoperations().selectdatable(\"" + tableName + "\",attributes,where);\n";
                muidString += "if(new " + tableName + "Control().AfterSelect()==true){\n";
                muidString += "return dt;\n";
                muidString += "}\n";
                muidString += "else\n";
                muidString += "{\n";
                muidString += "return new DataTable();\n";
                muidString += "}\n";
                muidString += "}\n";
                muidString += "return dt;\n";
                muidString += "}\n";
                //create select single

                muidString += "public string selectsinglevalue" + tableName + "(string attribute,string where){\n";
                muidString += "string str= \"\";\n";
                muidString += "if(new " + tableName + "Control().BeforeSelect()==true){\n";
                muidString += "str=new Connectoperations().singleval(\"" + tableName + "\",attribute,where);\n";
                muidString += "if(new " + tableName + "Control().AfterSelect()==true){\n";
                muidString += "return str;\n";
                muidString += "}\n";
                muidString += "else\n";
                muidString += "{\n";
                muidString += "return \"\";\n";
                muidString += "}\n";
                muidString += "}\n";
                muidString += "return str;\n";
                muidString += "}\n";
                //create delete
                muidString += "public bool delete" + tableName + " (string where){\n";
                muidString += "if(new " + tableName + "Control().BeforeDelete()==true){\n";
                muidString += "if(new Connectoperations().delete(\"" + tableName + "\",where)>0){\n";
                muidString += "MessageBox.Show(\"deleted!\");\n";
                muidString += "if(new " + tableName + "Control().AfterDelete()==true){\n";
                muidString += "return true;\n";
                muidString += "}\n";
                muidString += "else{\n";
                muidString += "return false;\n";
                muidString += "}\n";
                muidString += "}\n";
                muidString += "else{\n";
                muidString += "MessageBox.Show(\"Failed!\");\n";
                muidString += "return false;\n";
                muidString += "}\n";
                muidString += "}\n";
                muidString += "else{\n";
                muidString += "MessageBox.Show(\"Failed!\");\n";
                muidString += "return false;\n";
                muidString += "}\n";
                muidString += "}\n";
                //generateProjectProperty list of property
                muidString += "public List<" + tableName + "Property> listOf" + tableName + "(){\n";
                muidString += "List<" + tableName + "Property> mylistOf" + tableName + "=new List<" + tableName + "Property>();\n";
                muidString += "if(new " + tableName + "Control().BeforeSelect()==true){\n";
                muidString += "DataTable dat= selecttable" + tableName + "(\"*\",\"\");\n";
                //loop for attributes
                int i = 0;
                DataTable table = new Connectoperations().describeTable(tableName);
                muidString += "foreach(DataRow row in dat.Rows){\n";
                muidString += tableName + "Property mylist= new " + tableName + "Property();\n";
                foreach (DataRow drow in table.Rows)
                {
                    string dataType = drow[1].ToString();//.Substring(0, 3);
                    string attributeName = drow[0].ToString();
                    int count = 0;

                    count = dataType.IndexOf('(');
                    try
                    {
                        dataType = dataType.Substring(0, count);
                    }
                    catch
                    {
                        dataType = drow[1].ToString();
                    }

                    switch (dataType)
                    {
                        case "int":
                        case "tinyint":
                        case "smallint":
                        case "bigint":
                        case "mediumint":
                            muidString += ("mylist." + attributeName + "=Convert.ToInt32(row[" + (i++) + "].ToString());\n");

                            break;
                        case "varchar":
                        case "text":
                        case "time":
                        case "timestamp":
                        case "bit":
                        case "bool":
                        case "enum":
                        case "set":
                        case "serial":
                        case "tinytext":
                        case "mediumtext":
                        case "longtext":
                            muidString += ("mylist." + attributeName + "=Convert.ToString(row[" + (i++) + "].ToString());\n");
                            break;
                        case "char":

                            muidString += ("mylist." + attributeName + "=Convert.ToChar(row[" + (i++) + "].ToString());\n");
                            break;
                        case "float":

                            muidString += ("mylist." + attributeName + "= Convert.ToSingle(row[" + (i++) + "].ToString());\n");
                            break;
                        case "double":
                        case "decimal":
                        case "real":

                            muidString += ("mylist." + attributeName + "= Convert.ToDouble(row[" + (i++) + "].ToString());\n");
                            break;
                        case "date":
                        case "datetime":
                        case "year":

                            muidString += ("mylist." + attributeName + "=Convert.ToDateTime(row[" + (i++) + "].ToString());\n");
                            break;
                        case "longblob":
                        case "blob":
                        case "mediumblob":
                        case "tinyblob":
                            muidString += ("mylist." + attributeName + "=(byte[])row[" + (i++) + "];\n");
                            break;
                    }//end switch

                }//end attributes
                muidString += "mylistOf" + tableName + ".Add(mylist);\n";
                muidString += "if(new " + tableName + "Control().AfterSelect()==true){\n";
                muidString += "return mylistOf" + tableName + ";\n";
                muidString += "}\n";
                muidString += "else\n";
                muidString += "{\n";
                muidString += "return new List<" + tableName + "Property>();\n";
                muidString += "}\n";
                muidString += "}\n";
                muidString += "}\n";
                muidString += "return mylistOf" + tableName + ";\n";
                muidString += "}\n";
                muidString += " public string getmysqldate(DateTimePicker dt)\n";
                muidString += "{\n";
                muidString += "dt.Format = DateTimePickerFormat.Long;\n";
                muidString += "return new Connectoperations().mysqldate(Convert.ToDateTime(dt.Value));\n";
                muidString += "}\n";
                muidString += "//Validation methods\n";
                muidString += "public bool validate_int(string val){\n";
                muidString += "return Regex.IsMatch(val, @\"[0-9]+\");\n";

                muidString += "}\n";
                muidString += "public bool validate_floatpoints(string val){\n";
                muidString += "return Regex.IsMatch(val, @\"[0-9]+\\.\\[0-9]+\");\n";
                muidString += "}\n";
                muidString += "public bool validate_date(string val){\n";
                muidString += "// Return true if val is valid mysql date format.\n";
                muidString += "return true;\n";
                muidString += "}\n";
                muidString += "public bool validate_email(string val){\n";
                muidString += "// Return true if val is in valid e-mail format.\n";
                muidString += "return Regex.IsMatch(val, @\"\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*([,;]\\s*\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*)*\");\n";
                muidString += "}\n";
               //create associations
                List<ClassRelations> lcr = new List<ClassRelations>();
                lcr = new ClassGenerateRelation().loadRelations(projectName, ".NET", "Forms", "C#", tableName);
                for (int x = 0; x < lcr.Count; x++)
                {
                    if (lcr[x].name == tableName)
                    {
                        //create has class methods
                        for (int y = 0; y < lcr[x].has.Count; y++)
                        {
                            string[] hasString = lcr[x].has[y].Split('#');
                            string hasTableName = hasString[0];
                            string hasField = hasString[1];
                            //create a specific method
                            muidString += "public DataTable " + tableName +hasTableName+ "hasMany(string andorclause){\n";
                            muidString += "DataTable dt= new DataTable();\n";
                            muidString += "if(new " + tableName + "Control().BeforeSelect()==true){\n";
                            muidString += "dt=new Connectoperations().selectdatable(\"" + tableName+","+hasTableName + "\",\"*\",\"where "+tableName+".id="+hasTableName+"."+hasField+" \"+ andorclause);\n";
                            muidString += "if(new " + tableName + "Control().AfterSelect()==true){\n";
                            muidString += "return dt;\n";
                            muidString += "}\n";
                            muidString += "else\n";
                            muidString += "{\n";
                            muidString += "return new DataTable();\n";
                            muidString += "}\n";
                            muidString += "}\n";
                            muidString += "return dt;\n";
                            muidString += "}\n";
                        }//end for

                        //create has class methods
                        for (int y = 0; y < lcr[x].belongsTo.Count; y++)
                        {
                            string[] belongToString = lcr[x].belongsTo[y].Split('#');
                            string belongsToTableName = belongToString[0];
                            string belongsToField = belongToString[1];
                            //create a specific method
                            muidString += "public DataTable " + tableName + belongsToTableName + "belongsTo(string andorclause){\n";
                            muidString += "DataTable dt= new DataTable();\n";
                            muidString += "if(new " + tableName + "Control().BeforeSelect()==true){\n";
                            muidString += "dt=new Connectoperations().selectdatable(\"" + tableName + "," + belongsToTableName + "\",\"*\",\"where " + tableName + ".id=" + tableName + "." + belongsToField + " \"+ andorclause);\n";
                            muidString += "if(new " + tableName + "Control().AfterSelect()==true){\n";
                            muidString += "return dt;\n";
                            muidString += "}\n";
                            muidString += "else\n";
                            muidString += "{\n";
                            muidString += "return new DataTable();\n";
                            muidString += "}\n";
                            muidString += "}\n";
                            muidString += "return dt;\n";
                            muidString += "}\n";
                        }//end for
                    }
                }
                return muidString;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return muidString;
            }
        }