public void createControlTable(string projectName,string tableName)
        {
            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);
        }
예제 #2
0
        /// <summary>
        /// Creates the mysql connection class that is to used by the application
        /// </summary>
        /// <param name="projectName">name of the application being generated</param>
        /// <returns>bool</returns>
        public bool generateDBConnection(string projectName)
        {
            try
            {
                string dbcon = "";
                dbcon += "\n";
                string namespc = new general.ClassGeneral().getNameSpaces(".model", "Conner", projectName);
                dbcon += namespc;
                dbcon += "public Conner()\n";
                dbcon += " {\n";
                dbcon += "myConners();\n";
                dbcon += "}\n";
                dbcon += " MySqlConnection conn;\n";
                dbcon += "MySqlDataAdapter adapt;\n";
                dbcon += "MySqlCommand comm;\n";
                dbcon += "        string conString = \"Data Source=\" + " + projectName + ".Properties.Settings.Default.server + \";Database=\"+" + projectName + ".Properties.Settings.Default.database+\";User ID=\" + " + projectName + ".Properties.Settings.Default.user + \";Password=\" + " + projectName + ".Properties.Settings.Default.password + \";\";\n";
                dbcon += "public void myConners()\n";
                dbcon += "{\n";
                dbcon += "try            {\n";
                dbcon += "conn = new MySqlConnection(conString);\n";
                dbcon += "adapt = new MySqlDataAdapter();\n";
                dbcon += "comm = new MySqlCommand();\n";
                dbcon += "}\n";
                dbcon += "catch(Exception ex)            {\n";
                dbcon += "MessageBox.Show(ex.Message);\n";
                dbcon += "     }        }\n";
                dbcon += "public DataTable Filling(string sqlstr)        {          \n";
                dbcon += "DataTable table = new DataTable();\n";
                dbcon += "try            {\n";
                dbcon += "if (conn.State == ConnectionState.Open){ }\n";
                dbcon += "else\n                    conn.Open();\n";
                dbcon += " table.Clear();\n";
                dbcon += "comm.CommandText = sqlstr;\n";
                dbcon += "comm.Connection = conn;\n";
                dbcon += "adapt.SelectCommand = comm;\n";
                dbcon += "adapt.Fill(table);\n";
                dbcon += "conn.Close();\n";

                dbcon += "          }\n";
                dbcon += " catch (Exception ex)\n";
                dbcon += "  {\n";
                dbcon += "      MessageBox.Show(ex.Message+\"SQL:\"+sqlstr);\n";
                dbcon += "  }\n";
                dbcon += "  return table;\n";

                dbcon += "}\n";
                dbcon += " public int nonqry(string sqlstr)\n";
                dbcon += "  {\n";

                dbcon += "   int se = 0;\n";
                dbcon += "    try\n";
                dbcon += "    {\n";
                dbcon += "        if (conn.State == ConnectionState.Open)\n";
                dbcon += "       { }\n";
                dbcon += "      else\n";
                dbcon += "          conn.Open();\n";

                dbcon += "     comm = conn.CreateCommand();\n";
                dbcon += "     comm.CommandText = sqlstr;\n";
                dbcon += "    se = comm.ExecuteNonQuery();\n";
                dbcon += "     conn.Close();\n";
                dbcon += " }\n";
                dbcon += "  catch (Exception ex)\n";
                dbcon += "  {\n";
                dbcon += "       MessageBox.Show(ex.Message + \"SQL:\" + sqlstr);\n";
                dbcon += "   }\n";
                dbcon += "   return se;\n";

                dbcon += " }\n";

                dbcon += "  public string scalar(string sqlstr)\n";
                dbcon += "   {\n";
                dbcon += "       string se = \"\";\n";
                dbcon += "      try\n";
                dbcon += "       {\n";
                dbcon += "           if (conn.State == ConnectionState.Open)\n";
                dbcon += "          { }\n";
                dbcon += "          else\n";
                dbcon += "              conn.Open();\n";

                dbcon += "           comm = conn.CreateCommand();\n";
                dbcon += "           comm.CommandText = sqlstr;\n";
                dbcon += "          se = Convert.ToString(comm.ExecuteScalar());\n";
                dbcon += "          conn.Close();\n";
                dbcon += "    }\n";
                dbcon += "     catch(Exception ex)\n";
                dbcon += "     {\n";
                dbcon += "          MessageBox.Show(ex.Message + \"SQL:\" + sqlstr);\n";
                dbcon += "      }\n";
                dbcon += "      return se;\n";
                dbcon += "  }\n";

                dbcon += new general.ClassGeneral().closeClassBrace();
                string path = "";
                path = Directory.GetCurrentDirectory() + "\\" + projectName + "\\" + projectName + "\\model\\Connect.cs";
                File.WriteAllText(path, dbcon);

                dbcon = "";
                dbcon += "\n";
                namespc = new general.ClassGeneral().getNameSpaces(".model", "Connectoperations", projectName);
                dbcon += namespc;

                dbcon += "        Conner mycon = new Conner();\n";

                dbcon += "  public int insert(string table,string attributes,string values)\n";
                dbcon += "   {\n";
                dbcon += "       return mycon.nonqry(\"INSERT INTO \"+ table +\"(\"+ attributes +\")VALUES(\"+ values +\")\");\n";
                dbcon += "   }\n";

                dbcon += "   public int update(string table,string attributes, string values,string where)\n";
                dbcon += "{\n";
                dbcon += "   string statement = \"\";\n";
                dbcon += "   string[] _attributes = attributes.Split(','); \n";
                dbcon += "   string[] _values = values.Split(',');\n";
                dbcon += "   string delimer = \",\";\n";

                dbcon += "   if (_attributes.Length != _values.Length)\n";
                dbcon += "   {\n";
                dbcon += "     MessageBox.Show(\"Attributes and Values Must Match!\");\n";
                dbcon += "  }\n";
                dbcon += "    else\n";
                dbcon += "     {\n";
                dbcon += "         for (int i = 0; i < _attributes.Length; i++)\n";
                dbcon += "        {\n";
                dbcon += "            if (i == _attributes.Length - 1)\n";
                dbcon += "            {\n";
                dbcon += "               delimer = \"\";\n";
                dbcon += "          }\n";
                dbcon += "       statement +=(_attributes[i]+\"=\"+_values[i]+delimer);\n";
                dbcon += "      }\n";
                dbcon += "  }\n";
                dbcon += "  statement +=\" \"+ where;\n";
                dbcon += "   return mycon.nonqry(\"UPDATE \" + table +\" SET \"+ statement);\n";
                dbcon += " }\n";

                dbcon += "  public DataTable  selectdatable(string table, string attributes, string  where)\n";
                dbcon += "  {\n";
                dbcon += "       return mycon.Filling(\"SELECT \" + attributes +\" FROM \" + table+\" \"+where );\n";
                dbcon += "   }\n";

                dbcon += "   public string mysqldate(DateTime dat)\n";
                dbcon += "   {\n";

                dbcon += "      return dat.Year +\"-\"+dat.Month+\"-\"+dat.Day+\" \"+dat.Hour+\":\"+dat.Minute+\":\"+dat.Second;\n";
                dbcon += "  }\n";

                dbcon += " public string  singleval(string table, string attribute, string where)\n";
                dbcon += "  {\n";
                dbcon += "      return mycon.scalar(\"SELECT \" + attribute + \" FROM \" + table + \" \" + where);\n";
                dbcon += "  }\n";
                dbcon += "   public int delete(string table,string where)\n";
                dbcon += "   {\n";
                dbcon += "       return mycon.nonqry(\"DELETE FROM \" + table +\" \" + where);\n";
                dbcon += "   }\n";
                dbcon += "  public DataTable  describeTable(string table)\n";
                dbcon += "  {\n";
                dbcon += "     return mycon.Filling(\"describe \" + table);\n";
                dbcon += " }\n";
                dbcon += "  public DataTable showDatabaseTables()\n";
                dbcon += "  {\n";
                dbcon += "      return mycon.Filling(\"Show tables\" );\n";
                dbcon += "  }\n";
                dbcon += new general.ClassGeneral().closeClassBrace();
                path = Directory.GetCurrentDirectory() + "\\" + projectName + "\\" + projectName + "\\model\\Connectoperations.cs";
                File.WriteAllText(path, dbcon);

                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
        }