public void createControl(string projectName)
        {
            DataTable dat = new Connectoperations().showDatabaseTables();

            foreach (DataRow row in dat.Rows)
            {
                string tableName = row[0].ToString();
                //string namespc = new general.ClassGeneral().getNameSpaces(".control", tableName + "Control", projectName);
                //string str = "";
                //str += "\n";
                //str += namespc;
                //str += generatethem(projectName, tableName, "Before", "Update");
                //str += generatethem(projectName, tableName, "Before", "Insert");
                //str += generatethem(projectName, tableName, "Before", "Delete");
                //str += generatethem(projectName, tableName, "Before", "Select");

                //str += generatethem(projectName, tableName, "After", "Update");
                //str += generatethem(projectName, tableName, "After", "Insert");
                //str += generatethem(projectName, tableName, "After", "Delete");
                //str += generatethem(projectName, tableName, "After", "Select");

                //str += new general.ClassGeneral().closeClassBrace();
                //string path = "";
                //path = Directory.GetCurrentDirectory() + "\\" + projectName + "\\" + projectName + "\\control\\Class" + tableName + "Control.cs";
                //File.WriteAllText(path, str);
                createControlTable(projectName, tableName);
            }
        }
        public void createControlResume(string projectName,int numCompletedTables)
        {
            DataTable dat = new Connectoperations().showDatabaseTables();

            for (int i=numCompletedTables;i<dat.Rows.Count;i++)
            {
                string tableName = dat.Rows[i][0].ToString();

                createControlTable(projectName, tableName);
            }
        }
Пример #3
0
        public List<ClassRelations> loadRelations(string SProject, string SPlatform, string SType, string SLanguage, string STable)
        {
            //intialise project
            myproject.language = SLanguage;
            myproject.platform = SPlatform;
            myproject.selectedProject = SProject;
            myproject.type = SType;
            myproject.selectedTable = STable;

            relations.Clear();
            switch (myproject.platform)
            {
                case ".NET":
                    if (myproject.language == "" || myproject.selectedProject == "" || myproject.type == "")
                    {
                        MessageBox.Show("For .NET,please select Type as well as langauge");
                    }
                    else
                    {
                    }
                    break;
                case "PHP":
                    break;
            }

            //counter to keep the names of the database tables
            int tableCounter = 0;
            //get all database table
            DataTable dat = new Connectoperations().showDatabaseTables();
            //loop for counter
            for (int y = 0; y < dat.Rows.Count; y++)
            {
                // create relation class
                ClassRelations cr = new ClassRelations();
                cr.belongsTo = new List<string>();
                cr.has = new List<string>();
                cr.name = dat.Rows[tableCounter][0].ToString();

                //loop through each table
                for (int i = 0; i < dat.Rows.Count; i++)
                {
                    //prevent double deal
                    if (dat.Rows[i][0].ToString() != cr.name)
                    {
                        //get attributes of the table
                        string tabname = dat.Rows[i][0].ToString();
                        DataTable tab = new Connectoperations().describeTable(tabname);

                        string hasrel = tabname + "_id";
                        string relationshipField = cr.name + "_id";

                        DataTable tabb = new Connectoperations().describeTable(cr.name);

                        //go throuh each table check if the current table has 'has' relations with others
                        foreach (DataRow drow in tab.Rows)
                        {
                            //field from other table
                            string comp = drow[0].ToString();
                            //adding has relationship
                            if (relationshipField == comp)
                            {
                                cr.has.Add(dat.Rows[i][0].ToString() + "#" + comp);
                            }

                        }//end for each

                        //belongs to
                        foreach (DataRow myrow in tabb.Rows)
                        {
                            string c = myrow[0].ToString();
                            //add belongs to
                            if (c == hasrel)
                            {
                                // if(cr.belongsTo.Contains(row[0].ToString().Split('_')[0] + "#" + hasrel )==false )
                                cr.belongsTo.Add(c.Split('_')[0] + "#" + hasrel);
                            }

                        }//end foreach

                    }//end double deal

                }//end for loop
                tableCounter++;
                //add list or relations
                relations.Add(cr);
            }//end counter for loop

            return relations;
        }
Пример #4
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);
        }
Пример #5
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);
        }
Пример #6
0
        private void generateCustomConrolDesigner(string projectName, string tableName, List<ClassTableControls> lctc)
        {
            controls.Clear();
            defaultInsertattribute = "\"";
            defaultInservalues = "";

            string customeControlDesigner = "";
            string initiallizer = "";
            string privateString = "";
            //string groupBox = "";
            initiallizer += "\n";
            privateString += "\n";

            //get table attributes
            DataTable dtab = new Connectoperations().describeTable(tableName);
            int i = 0;

            int heightControls = 13;
            int heightlabels = 16;
            string insertvalues = "";
            string insertattributes = "";
            string delimiter = "+\",\"+";
            string delimiter1 = ",";
            foreach (DataRow row in dtab.Rows)
            {
                string attribute = row[0].ToString();
                string dataType = row[1].ToString();

                //label
                privateString += "        private System.Windows.Forms.Label label" + attribute + ";\n";
                initiallizer += "            this.label" + attribute + " = new System.Windows.Forms.Label();\n";
                initiallizer += "            this.groupBox1.Controls.Add(this.label" + attribute + ");\n";
                initiallizer += "            // \n";
                initiallizer += "            // label" + attribute + "\n";
                initiallizer += "            // \n";
                initiallizer += "            this.label" + attribute + ".AutoSize = true;\n";
                initiallizer += "            this.label" + attribute + ".Location = new System.Drawing.Point(6, " + heightlabels + ");\n";
                initiallizer += "            this.label" + attribute + ".Name = \"label" + attribute + "\";\n";
                initiallizer += "            this.label" + attribute + ".Size = new System.Drawing.Size(35, 13);\n";
                initiallizer += "            this.label" + attribute + ".TabIndex = 8;\n";
                initiallizer += "            this.label" + attribute + ".Text =\"" + attribute + "\";\n";

                foreach (ClassTableControls ctc in lctc)
                {
                    if (ctc.tablename == tableName)
                    {
                        if (ctc.controls.Count - 1 == i)
                        {
                            delimiter1 = "";
                            delimiter = "";
                        }

                        insertattributes += attribute + delimiter1;

                        switch (ctc.controls[i])
                        {

                            case "TextBox":
                                //textbox
                                privateString += "        private System.Windows.Forms.TextBox textBox" + attribute + ";\n";
                                initiallizer += "            this.textBox" + attribute + " = new System.Windows.Forms.TextBox();\n";
                                initiallizer += "            this.groupBox1.Controls.Add(this.textBox" + attribute + ");\n";
                                initiallizer += "            // \n";
                                initiallizer += "            // textBox" + attribute + "\n";
                                initiallizer += "            // \n";
                                initiallizer += "            this.textBox" + attribute + ".Location = new System.Drawing.Point(187, " + heightControls + ");\n";
                                initiallizer += "            this.textBox" + attribute + ".Name = \"textBox" + attribute + "\";\n";
                                initiallizer += "            this.textBox" + attribute + ".Size = new System.Drawing.Size(273, 20);\n";
                                initiallizer += "            this.textBox" + attribute + ".TabIndex = 1;\n";

                                insertvalues += create_i_attribute("textBox" + attribute + ".Text", dataType) + delimiter;

                                controls.Add("textBox" + attribute + ".Text");

                                break;
                            case "ComboBox":
                                //combobox
                                privateString += "       private System.Windows.Forms.ComboBox comboBox" + attribute + ";\n";
                                initiallizer += "            this.comboBox" + attribute + " = new System.Windows.Forms.ComboBox();\n";
                                initiallizer += "            this.groupBox1.Controls.Add(this.comboBox" + attribute + ");\n";

                                initiallizer += "            // \n";
                                initiallizer += "            // comboBox" + attribute + "\n";
                                initiallizer += "            // \n";
                                initiallizer += "            this.comboBox" + attribute + ".FormattingEnabled = true;\n";
                                initiallizer += "            this.comboBox" + attribute + ".Location = new System.Drawing.Point(187, " + heightControls + ");\n";
                                initiallizer += "            this.comboBox" + attribute + ".Name = \"comboBox" + attribute + "\";\n";
                                initiallizer += "            this.comboBox" + attribute + ".Size = new System.Drawing.Size(273, 21);\n";
                                initiallizer += "            this.comboBox" + attribute + ".TabIndex = 4;\n";
                                insertvalues += create_i_attribute("comboBox" + attribute + ".Text", dataType) + delimiter;

                                controls.Add("comboBox" + attribute + ".Text");

                                break;
                            case "DateTimePicker":
                                //datetimepicker
                                privateString += "       private System.Windows.Forms.DateTimePicker dateTimePicker" + attribute + ";\n";
                                initiallizer += "            this.dateTimePicker" + attribute + " = new System.Windows.Forms.DateTimePicker();\n";
                                initiallizer += "            this.groupBox1.Controls.Add(this.dateTimePicker" + attribute + ");\n";

                                initiallizer += "            // \n";
                                initiallizer += "            // dateTimePicker" + attribute + "\n";
                                initiallizer += "            // \n";
                                initiallizer += "            this.dateTimePicker" + attribute + ".Location = new System.Drawing.Point(187, " + heightControls + ");\n";
                                initiallizer += "            this.dateTimePicker" + attribute + ".Name = \"dateTimePicker" + attribute + "\";\n";
                                initiallizer += "            this.dateTimePicker" + attribute + ".Size = new System.Drawing.Size(273, 20);\n";
                                initiallizer += "            this.dateTimePicker" + attribute + ".TabIndex = 7;\n";
                                //take care of mysql date
                                //insertvalues += create_i_attribute("dateTimePicker" + attribute + ".Value", dataType) + delimiter;
                                insertvalues += "\"'\"+mymodel.getmysqldate(dateTimePicker" + attribute + ")+\"'\"" + delimiter;
                                controls.Add("dateTimePicker" + attribute + ".Value");
                                break;
                            case "CheckBox":
                                //checkbox
                                privateString += "       private System.Windows.Forms.CheckBox checkBox" + attribute + ";\n";
                                initiallizer += "            this.checkBox" + attribute + " = new System.Windows.Forms.CheckBox();\n";
                                initiallizer += "            this.groupBox1.Controls.Add(this.checkBox" + attribute + ");\n";
                                initiallizer += "            // \n";
                                initiallizer += "            // checkBox" + attribute + "\n";
                                initiallizer += "            // \n";
                                initiallizer += "            this.checkBox" + attribute + ".AutoSize = true;\n";
                                initiallizer += "            this.checkBox" + attribute + ".Location = new System.Drawing.Point(187, " + heightControls + ");\n";
                                initiallizer += "            this.checkBox" + attribute + ".Name = \"checkBox1\";\n";
                                initiallizer += "            this.checkBox" + attribute + ".Size = new System.Drawing.Size(80, 17);\n";
                                initiallizer += "            this.checkBox" + attribute + ".TabIndex = 6;\n";
                                initiallizer += "            this.checkBox" + attribute + ".Text = \"checkBox1\";\n";
                                initiallizer += "            this.checkBox" + attribute + ".UseVisualStyleBackColor = true;\n";
                                insertvalues += create_i_attribute("checkBox" + attribute + ".Text", dataType) + delimiter;

                                controls.Add("checkBox" + attribute + ".Text");

                                break;
                            case "RadioButton":
                                //radiobutton
                                privateString += "      private System.Windows.Forms.RadioButton radioButton" + attribute + ";\n";
                                initiallizer += "            this.radioButton" + attribute + " = new System.Windows.Forms.RadioButton();\n";
                                initiallizer += "            this.groupBox1.Controls.Add(this.radioButton" + attribute + ");\n";

                                initiallizer += "            // \n";
                                initiallizer += "            // radioButton" + attribute + "\n";
                                initiallizer += "            // \n";
                                initiallizer += "            this.radioButton" + attribute + ".AutoSize = true;\n";
                                initiallizer += "            this.radioButton" + attribute + ".Location = new System.Drawing.Point(187, " + heightControls + ");\n";
                                initiallizer += "            this.radioButton" + attribute + ".Name = \"radioButton" + attribute + "\";\n";
                                initiallizer += "            this.radioButton" + attribute + ".Size = new System.Drawing.Size(85, 17);\n";
                                initiallizer += "            this.radioButton" + attribute + ".TabIndex = 11;\n";
                                initiallizer += "            this.radioButton" + attribute + ".TabStop = true;\n";
                                initiallizer += "            this.radioButton" + attribute + ".Text = \"radioButton" + attribute + "\";\n";
                                initiallizer += "            this.radioButton" + attribute + ".UseVisualStyleBackColor = true;\n";
                                insertvalues += create_i_attribute("radioButton" + attribute + ".Text", dataType) + delimiter;

                                controls.Add("radioButton" + attribute + ".Text");

                                break;
                            case "PictureBox":
                                //picturebox
                                privateString += "       private System.Windows.Forms.PictureBox pictureBox" + attribute + ";\n";
                                initiallizer += "            this.pictureBox" + attribute + " = new System.Windows.Forms.PictureBox();\n";
                                initiallizer += "            this.groupBox1.Controls.Add(this.pictureBox" + attribute + ");\n";

                                initiallizer += "            // \n";
                                initiallizer += "            // pictureBox" + attribute + "\n";
                                initiallizer += "            // \n";
                                initiallizer += "            this.pictureBox" + attribute + ".Location = new System.Drawing.Point(493, " + heightControls + ");\n";
                                initiallizer += "            this.pictureBox" + attribute + ".Name = \"pictureBox1\";\n";
                                initiallizer += "            this.pictureBox" + attribute + ".Size = new System.Drawing.Size(101, 89);\n";
                                initiallizer += "            this.pictureBox" + attribute + ".TabIndex = 12;\n";
                                initiallizer += "            this.pictureBox" + attribute + ".TabStop = false;\n";
                                initiallizer += "            ((System.ComponentModel.ISupportInitialize)(this.pictureBox" + attribute + ")).BeginInit();\n";

                                insertvalues += create_i_attribute("pictureBox" + attribute + ".Image", dataType) + delimiter;

                                controls.Add("pictureBox" + attribute + ".Image");

                                break;
                            case "NumericUp":
                                //numeric updown
                                privateString += "        private System.Windows.Forms.NumericUpDown numericUpDown" + attribute + ";\n";
                                initiallizer += "            this.numericUpDown" + attribute + " = new System.Windows.Forms.NumericUpDown();\n";
                                initiallizer += "            this.groupBox1.Controls.Add(this.numericUpDown" + attribute + ");\n";
                                initiallizer += "            // \n";
                                initiallizer += "            // numericUpDown" + attribute + "\n";
                                initiallizer += "            // \n";
                                initiallizer += "            this.numericUpDown" + attribute + ".Location = new System.Drawing.Point(187, " + heightControls + ");\n";
                                initiallizer += "            this.numericUpDown" + attribute + ".Name = \"numericUpDown1\";\n";
                                initiallizer += "            this.numericUpDown" + attribute + ".Size = new System.Drawing.Size(273, 20);\n";
                                initiallizer += "            this.numericUpDown" + attribute + ".TabIndex = 5;\n";
                                initiallizer += "            ((System.ComponentModel.ISupportInitialize)(this.numericUpDown" + attribute + ")).BeginInit();\n";
                                insertvalues += create_i_attribute("numericUpDown" + attribute + ".Value", dataType) + delimiter;

                                controls.Add("numericUpDown" + attribute + ".Value");

                                break;
                            case "CheckedLisBox":

                                //richtextbox
                                // initiallizer += "       private System.Windows.Forms.RichTextBox richTextBox1;\n";
                                break;
                            case "RichTextBox":

                                //richtextbox
                                privateString += "       private System.Windows.Forms.RichTextBox richTextBox" + attribute + ";\n";
                                initiallizer += "            this.richTextBox" + attribute + " = new System.Windows.Forms.RichTextBox();\n";
                                initiallizer += "            this.groupBox1.Controls.Add(this.richTextBox" + attribute + ");\n";

                                initiallizer += "           // \n";
                                initiallizer += "          // richTextBox" + attribute + "\n";
                                initiallizer += "           // \n";
                                initiallizer += "           this.richTextBox" + attribute + ".Location = new System.Drawing.Point(187, " + heightControls + ");\n";
                                initiallizer += "            this.richTextBox" + attribute + ".Name = \"richTextBox1\";\n";
                                initiallizer += "            this.richTextBox" + attribute + ".Size = new System.Drawing.Size(273, 31);\n";
                                initiallizer += "            this.richTextBox" + attribute + ".TabIndex = 13;\n";
                                initiallizer += "            this.richTextBox" + attribute + ".Text = \"\";\n";
                                insertvalues += create_i_attribute("richTextBox" + attribute + ".Text", dataType) + delimiter;

                                controls.Add("richTextBox" + attribute + ".Text");
                                break;
                        }
                    }//end if check
                }//end lctc
                i++;
                heightControls = heightControls + 26;
                heightlabels = heightlabels + 26;

            }
            defaultInsertattribute += insertattributes + "\"";
            defaultInservalues += insertvalues;

            customeControlDesigner += "\n";
            customeControlDesigner += "namespace " + projectName + ".view\n";
            customeControlDesigner += "{\n";
            customeControlDesigner += "    partial class UserControl" + tableName + "insert\n";
            customeControlDesigner += "    {\n";

            customeControlDesigner += "        private System.ComponentModel.IContainer components = null;\n";

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

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

            customeControlDesigner += "        private void InitializeComponent()\n";
            customeControlDesigner += "        {\n";
            customeControlDesigner += "            this.groupBox1 = new System.Windows.Forms.GroupBox();\n";

            //all controls come here
            customeControlDesigner += initiallizer + "\n";

            // customeControlDesigner += "            this.progressBar1 = new System.Windows.Forms.ProgressBar();\n";

            customeControlDesigner += "            this.groupBox2 = new System.Windows.Forms.GroupBox();\n";
            customeControlDesigner += "            this.buttonDelete = new System.Windows.Forms.Button();\n";
            customeControlDesigner += "            this.buttonSave = new System.Windows.Forms.Button();\n";
            customeControlDesigner += "            this.buttonNew = new System.Windows.Forms.Button();\n";
            customeControlDesigner += "            this.labelNext = new System.Windows.Forms.Label();\n";
            customeControlDesigner += "            this.labelprev = new System.Windows.Forms.Label();\n";
            customeControlDesigner += "            this.groupBox1.SuspendLayout();\n";

            customeControlDesigner += "            this.groupBox2.SuspendLayout();\n";
            customeControlDesigner += "            this.SuspendLayout();\n";
            customeControlDesigner += "            // \n";
            customeControlDesigner += "            // groupBox1\n";
            customeControlDesigner += "            // \n";
            customeControlDesigner += "            this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)\n";
            customeControlDesigner += "                        | System.Windows.Forms.AnchorStyles.Left)\n";
            customeControlDesigner += "                        | System.Windows.Forms.AnchorStyles.Right)));\n";
            //customeControlDesigner += "            this.groupBox1.Controls.Add(this.progressBar1);\n";
            customeControlDesigner += "            this.groupBox1.Controls.Add(this.labelprev);\n";
            customeControlDesigner += "            this.groupBox1.Controls.Add(this.labelNext);\n";

            customeControlDesigner += "            this.groupBox1.Controls.Add(this.groupBox2);\n";
            customeControlDesigner += "            this.groupBox1.Location = new System.Drawing.Point(3, 3);\n";
            customeControlDesigner += "            this.groupBox1.Name = \"groupBox1\";\n";
            customeControlDesigner += "            this.groupBox1.Size = new System.Drawing.Size(697, 332);\n";
            customeControlDesigner += "            this.groupBox1.TabIndex = 0;\n";
            customeControlDesigner += "           this.groupBox1.TabStop = false;\n";
            customeControlDesigner += "           this.groupBox1.Text =\"\";\n";
            customeControlDesigner += "            // \n";
            // customeControlDesigner += "            // progressBar1\n";
            // customeControlDesigner += "            // \n";
            // customeControlDesigner += "            this.progressBar1.Location = new System.Drawing.Point(187, 311);\n";
            // customeControlDesigner += "            this.progressBar1.Name = \"progressBar1\";\n";
            // customeControlDesigner += "            this.progressBar1.Size = new System.Drawing.Size(273, 13);\n";
            // customeControlDesigner += "            this.progressBar1.TabIndex = 10;\n";

            customeControlDesigner += "            // \n";
            customeControlDesigner += "            // groupBox2\n";
            customeControlDesigner += "            // \n";
            customeControlDesigner += "            this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)\n";
            customeControlDesigner += "                        | System.Windows.Forms.AnchorStyles.Right)));\n";
            customeControlDesigner += "            this.groupBox2.Controls.Add(this.buttonDelete);\n";
            customeControlDesigner += "            this.groupBox2.Controls.Add(this.buttonSave);\n";
            customeControlDesigner += "            this.groupBox2.Controls.Add(this.buttonNew);\n";
            customeControlDesigner += "            this.groupBox2.Location = new System.Drawing.Point(6, 267);\n";
            customeControlDesigner += "            this.groupBox2.Name = \"groupBox2\";\n";
            customeControlDesigner += "            this.groupBox2.Size = new System.Drawing.Size(685, 43);\n";
            customeControlDesigner += "            this.groupBox2.TabIndex = 0;\n";
            customeControlDesigner += "            this.groupBox2.TabStop = false;\n";
            customeControlDesigner += "            this.groupBox2.Text = \"\";\n";
            customeControlDesigner += "            // \n";
            customeControlDesigner += "            // buttonDelete\n";
            customeControlDesigner += "            // \n";
            customeControlDesigner += "           this.buttonDelete.FlatAppearance.BorderColor = System.Drawing.Color.Blue;\n";
            customeControlDesigner += "           this.buttonDelete.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Red;\n";
            customeControlDesigner += "           this.buttonDelete.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Lime;\n";
            customeControlDesigner += "            this.buttonDelete.FlatStyle = System.Windows.Forms.FlatStyle.Popup;\n";
            customeControlDesigner += "            this.buttonDelete.Location = new System.Drawing.Point(181, 10);\n";
            customeControlDesigner += "            this.buttonDelete.Name = \"buttonDelete\";\n";
            customeControlDesigner += "            this.buttonDelete.Size = new System.Drawing.Size(87, 28);\n";
            customeControlDesigner += "            this.buttonDelete.TabIndex = 2;\n";
            customeControlDesigner += "            this.buttonDelete.Text = \"Delete\";\n";
            customeControlDesigner += "            this.buttonDelete.UseVisualStyleBackColor = true;\n";
            customeControlDesigner += "            // \n";
            customeControlDesigner += "            // buttonSave\n";
            customeControlDesigner += "            // \n";
            customeControlDesigner += "            this.buttonSave.FlatAppearance.BorderColor = System.Drawing.Color.Blue;\n";
            customeControlDesigner += "            this.buttonSave.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Red;\n";
            customeControlDesigner += "            this.buttonSave.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Lime;\n";
            customeControlDesigner += "            this.buttonSave.FlatStyle = System.Windows.Forms.FlatStyle.Popup;\n";
            customeControlDesigner += "            this.buttonSave.Location = new System.Drawing.Point(367, 10);\n";
            customeControlDesigner += "            this.buttonSave.Name = \"buttonSave\";\n";
            customeControlDesigner += "            this.buttonSave.Size = new System.Drawing.Size(87, 28);\n";
            customeControlDesigner += "            this.buttonSave.TabIndex = 1;\n";
            customeControlDesigner += "            this.buttonSave.Text = \"Save\";\n";
            customeControlDesigner += "            this.buttonSave.UseVisualStyleBackColor = true;\n";
            customeControlDesigner += "            this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);\n";
            customeControlDesigner += "            // \n";
            customeControlDesigner += "            // buttonNew\n";
            customeControlDesigner += "            // \n";
            customeControlDesigner += "            this.buttonNew.FlatAppearance.BorderColor = System.Drawing.Color.Blue;\n";
            customeControlDesigner += "            this.buttonNew.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Red;\n";
            customeControlDesigner += "            this.buttonNew.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Lime;\n";
            customeControlDesigner += "            this.buttonNew.FlatStyle = System.Windows.Forms.FlatStyle.Popup;\n";
            customeControlDesigner += "            this.buttonNew.Location = new System.Drawing.Point(274, 10);\n";
            customeControlDesigner += "            this.buttonNew.Name = \"buttonNew\";\n";
            customeControlDesigner += "            this.buttonNew.Size = new System.Drawing.Size(87, 28);\n";
            customeControlDesigner += "            this.buttonNew.TabIndex = 0;\n";
            customeControlDesigner += "            this.buttonNew.Text = \"New*\";\n";
            customeControlDesigner += "            this.buttonNew.UseVisualStyleBackColor = true;\n";
            customeControlDesigner += "            // \n";
            customeControlDesigner += "            // labelNext\n";
            customeControlDesigner += "            // \n";
            customeControlDesigner += "            this.labelNext.AutoSize = true;\n";
            customeControlDesigner += "            this.labelNext.Location = new System.Drawing.Point(566, 0);\n";
            customeControlDesigner += "            this.labelNext.Name = \"labelNext\";\n";
            customeControlDesigner += "            this.labelNext.Size = new System.Drawing.Size(25, 13);\n";
            customeControlDesigner += "            this.labelNext.TabIndex = 11;\n";
            customeControlDesigner += "            this.labelNext.Text = \">>+\";\n";
            customeControlDesigner += "            this.labelNext.Click += new System.EventHandler(this.labelNext_Click);\n";
            customeControlDesigner += "            // \n";
            customeControlDesigner += "            // labelprev\n";
            customeControlDesigner += "            // \n";
            customeControlDesigner += "            this.labelprev.AutoSize = true;\n";
            customeControlDesigner += "            this.labelprev.Location = new System.Drawing.Point(523, 0);\n";
            customeControlDesigner += "            this.labelprev.Name = \"labelprev\";\n";
            customeControlDesigner += "            this.labelprev.Size = new System.Drawing.Size(22, 13);\n";
            customeControlDesigner += "            this.labelprev.TabIndex = 12;\n";
            customeControlDesigner += "            this.labelprev.Text = \"-<<\";\n";
            customeControlDesigner += "            this.labelprev.Click += new System.EventHandler(this.labelprev_Click);\n";
            customeControlDesigner += "            // \n";
            customeControlDesigner += "            // UserControlinsert\n";
            customeControlDesigner += "            // \n";
            customeControlDesigner += "            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);\n";
            customeControlDesigner += "            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;\n";
            customeControlDesigner += "            this.AutoScroll = true;\n";
            customeControlDesigner += "            this.Controls.Add(this.groupBox1);\n";
            customeControlDesigner += "            this.Name = \"UserControl" + tableName + "insert\";\n";
            customeControlDesigner += "            this.Size = new System.Drawing.Size(700, 338);\n";
            customeControlDesigner += "            this.groupBox1.ResumeLayout(false);\n";
            customeControlDesigner += "            this.groupBox1.PerformLayout();\n";
            //customeControlDesigner += "            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();\n";
            //customeControlDesigner += "            ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();\n";
            customeControlDesigner += "            this.groupBox2.ResumeLayout(false);\n";
            customeControlDesigner += "            this.ResumeLayout(false);\n";

            customeControlDesigner += "        }\n";

            customeControlDesigner += "        #endregion\n";

            customeControlDesigner += "        private System.Windows.Forms.GroupBox groupBox1;\n";
            customeControlDesigner += "        private System.Windows.Forms.GroupBox groupBox2;\n";
            customeControlDesigner += "        private System.Windows.Forms.Button buttonNew;\n";
            customeControlDesigner += "        private System.Windows.Forms.Button buttonDelete;\n";
            customeControlDesigner += "        private System.Windows.Forms.Button buttonSave;\n";
            //customeControlDesigner += "        private System.Windows.Forms.ProgressBar progressBar1;\n";
            customeControlDesigner += "        private System.Windows.Forms.Label labelNext;\n";
            customeControlDesigner += "        private System.Windows.Forms.Label labelprev;\n";
            customeControlDesigner += privateString + "\n";
            customeControlDesigner += "     }\n";
            customeControlDesigner += "  }\n";
            string path = "";
            path = Directory.GetCurrentDirectory() + "\\" + projectName + "\\" + projectName + "\\view\\UserControl" + tableName + "insert.Designer.cs";
            File.WriteAllText(path, customeControlDesigner);
        }
Пример #7
0
        //this class should build the class for the custome control designer muidinsert
        private void generateCustomeControlClass(string tableName, string projectName)
        {
            validationString.Clear();
            string customeControlClass = "";
            customeControlClass += "\n";
            customeControlClass += "using System;\n";
            customeControlClass += "using System.Collections.Generic;\n";
            customeControlClass += "using System.ComponentModel;\n";
            customeControlClass += "using System.Drawing;\n";
            customeControlClass += "using System.Data;\n";
            customeControlClass += "using System.Linq;\n";
            customeControlClass += "using System.Text;\n";
            customeControlClass += "using " + projectName + ".model;\n";
            customeControlClass += "using System.Windows.Forms;\nusing " + projectName + ".control;\n";

            customeControlClass += "namespace " + projectName + ".view\n";
            customeControlClass += "{\n";
            customeControlClass += "    public partial class UserControl" + tableName + "insert : UserControl\n";
            customeControlClass += "    {\n";
            customeControlClass += "        public UserControl" + tableName + "insert()\n";
            customeControlClass += "        {\n";
            customeControlClass += "            InitializeComponent();\n";
            customeControlClass += "        }\n";
            customeControlClass += "        ListView mylv = new ListView();\n";
            customeControlClass += "        int selectedInd = 0;\n";
            customeControlClass += "        int myflag = 0;\n";
            customeControlClass += "   private void buttonSave_Click(object sender, EventArgs e)\n";
            customeControlClass += " {\n";
            customeControlClass += " " + tableName + "muid mymodel= new " + tableName + "muid();" + "\n";

            DataTable table = new Connectoperations().describeTable(tableName);
            int i = 0;
            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":
                        validationString.Add("mymodel.validate_int(" + controls[i] + ")");
                        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":
                        break;
                    case "char":
                        break;
                    case "float":
                    case "double":
                    case "decimal":
                    case "real":
                        validationString.Add("mymodel.validate_floatpoints(" + controls[i] + ")");
                        break;
                    case "date":
                    case "datetime":
                    case "year":
                        validationString.Add("mymodel.validate_date(" + controls[i] + ".ToString())");
                        break;
                    case "longblob":
                    case "blob":
                    case "mediumblob":
                    case "tinyblob":
                        break;
                }//end switch
                i++;

            }//end attributes
            if (validationString.Count > 0)
            {
                customeControlClass += " if (myflag < 1)\n";
                customeControlClass += "{\n";
                customeControlClass += " if(";
                int j = 0;
                string greenapple = "&&";
                foreach (string str in validationString)
                {
                    if (j < validationString.Count - 1)
                    {
                    }
                    else
                    {
                        greenapple = "";
                    }
                    customeControlClass += str + "==true" + greenapple;
                    j++;
                }
                customeControlClass += "){\n";
                customeControlClass += "   mymodel.insert" + tableName + "(" + defaultInsertattribute + "," + defaultInservalues + ");\n";
                customeControlClass += " }\n";
                customeControlClass += " else{\n";
                customeControlClass += " MessageBox.Show(\"Validation Failed!\");\n";
                customeControlClass += " }\n";
                customeControlClass += "}\n";
                customeControlClass += " else\n";
                customeControlClass += "{\n";
                //update data
                customeControlClass += " if(";
                j = 0;
                greenapple = "&&";
                foreach (string str in validationString)
                {
                    if (j < validationString.Count - 1)
                    {
                    }
                    else
                    {
                        greenapple = "";
                    }
                    customeControlClass += str + "==true" + greenapple;
                    j++;
                }
                customeControlClass += "){\n";
                customeControlClass += "   mymodel.update" + tableName + "(" + defaultInsertattribute + "," + defaultInservalues + ",\"where id=\"+textBoxid.Text);\n";
                customeControlClass += " }\n";
                customeControlClass += " else{\n";
                customeControlClass += " MessageBox.Show(\"Validation Failed!\");\n";
                customeControlClass += " }\n";
                customeControlClass += "}\n";
            }
            else
            {
                customeControlClass += "   mymodel.insert" + tableName + "(" + defaultInsertattribute + "," + defaultInservalues + ");\n";
            }
            customeControlClass += " }\n";

            customeControlClass += "public void loaddata(ListView lv,int selectedIndex,int flag)\n";
            customeControlClass += "{\n";
            customeControlClass += "try{";
            customeControlClass += "mylv = lv;\n";
            customeControlClass += "selectedInd = selectedIndex;\n";
            customeControlClass += "myflag = flag;\n";
            //all textboxes go here
            i = 0;
            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":
                        customeControlClass += controls[i] + "=lv.Items[selectedIndex].SubItems[" + (i + 1) + "].Text;\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":
                        customeControlClass += controls[i] + "=lv.Items[selectedIndex].SubItems[" + (i + 1) + "].Text;\n";
                        break;

                    case "char":
                        customeControlClass += controls[i] + "=lv.Items[selectedIndex].SubItems[" + (i + 1) + "].Text;\n";
                        break;
                    case "float":
                    case "double":
                    case "decimal":
                    case "real":
                        customeControlClass += controls[i] + "=lv.Items[selectedIndex].SubItems[" + (i + 1) + "].Text;\n";
                        break;
                    case "date":
                    case "datetime":
                    case "year":
                        customeControlClass += controls[i] + "=Convert.ToDateTime(lv.Items[selectedIndex].SubItems[" + (i + 1) + "].Text);\n";
                        break;
                    case "longblob":
                    case "blob":
                    case "mediumblob":
                    case "tinyblob":
                        break;
                }//end switch
                i++;

            }//end attributes
            //////////////////
            customeControlClass += "}\n";
            customeControlClass += "catch{}\n";
            customeControlClass += "}\n";

            customeControlClass += "private void labelprev_Click(object sender, EventArgs e)\n";
            customeControlClass += "{\n";
            customeControlClass += "     if (selectedInd > 0)\n";
            customeControlClass += "        {\n";
            customeControlClass += "          loaddata(mylv, --selectedInd, 3);\n";
            customeControlClass += "        }\n";

            customeControlClass += "}\n";

            customeControlClass += "private void labelNext_Click(object sender, EventArgs e)\n";
            customeControlClass += "{\n";
            customeControlClass += "      if (mylv.Items.Count-1 != selectedInd)\n";
            customeControlClass += "         {\n";
            customeControlClass += "           loaddata(mylv, ++selectedInd, 3);\n";
            customeControlClass += "         }\n";
            customeControlClass += "}\n";

            customeControlClass += "    }\n";
            customeControlClass += "}\n";

            string path = "";
            path = Directory.GetCurrentDirectory() + "\\" + projectName + "\\" + projectName + "\\view\\UserControl" + tableName + "insert.cs";
            File.WriteAllText(path, customeControlClass);
        }
Пример #8
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;
            }
        }