Esempio n. 1
0
        private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            rtxtClass.Clear();
            rtService.Clear();
            rtImplement.Clear();
            rtprocedure.Clear();

            _dtColumns = new DataTable();
            string tableName;

            try
            {
                tableName = listBox2.SelectedItem.ToString();
            }
            catch (NullReferenceException)
            {
                return;
            }

            string dbName = Args.Database;

            Args.InitialCatalog = dbName;
            Args.WheredTable    = tableName;
            Args.WheredDb       = dbName;
            Adapters.LsColumnsDA.Fill(_dtColumns);

            PrimaryKey = Adapters.GetPrimarykey;

            try
            {
                var paths1 = Path.GetFullPath("Templete/" + Argument.FileEntity);
                rtxtClass.LoadFile(paths1, RichTextBoxStreamType.PlainText);

                var paths2 = Path.GetFullPath("Templete/" + Argument.FileService);
                rtService.LoadFile(paths2, RichTextBoxStreamType.PlainText);

                var paths3 = Path.GetFullPath("Templete/" + Argument.FileImpl);
                rtImplement.LoadFile(paths3, RichTextBoxStreamType.PlainText);

                var paths4 = Path.GetFullPath("Templete/" + Argument.FileSproc);
                rtprocedure.LoadFile(paths4, RichTextBoxStreamType.PlainText);
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.ToString());
            }

            //Generator Entity
            Generator.BeginGeneration(rtxtClass.Text);
            Generator.AddTableDbName(tableName, dbName);
            foreach (DataRow row in _dtColumns.Rows)
            {
                Generator.AddField(row["DATA_TYPE"].ToString(), row["COLUMN_NAME"].ToString());
            }
            Generator.EndGeneration();
            rtxtClass.Text = Generator.RawClassText.Replace("[namespace]", Args.NameSpaceName);

            //Generator Service
            Generator.BeginGeneration(rtService.Text);
            Generator.AddTableDbName(tableName, dbName);
            Generator.EndGeneration();
            rtService.Text = Generator.RawClassText.Replace("[namespace]", Args.NameSpaceName);

            //Generator Implement
            Generator.BeginGeneration(rtImplement.Text);
            Generator.AddTableDbName(tableName, dbName);
            int c = _dtColumns.Rows.Count;

            for (int i = 0; i < _dtColumns.Rows.Count; i++)
            {
                DataRow row     = _dtColumns.Rows[i];
                var     colname = row["COLUMN_NAME"].ToString();
                var     pmkey   = false;
                if (colname == PrimaryKey)
                {
                    pmkey = true;
                }

                bool end = false;
                if (i == c - 1)
                {
                    end = true;
                }
                Generator.AddParameterSql(colname, end, pmkey);
                Generator.AddReaderSql(row["DATA_TYPE"].ToString(), colname);
            }
            Generator.EndGeneration();
            rtImplement.Text = Generator.RawClassText.Replace("<column_name>", "").Replace("[namespace]", Args.NameSpaceName);

            //Generator Storeprocedure
            Generator.BeginGeneration(rtprocedure.Text);
            Generator.AddTableDbName(tableName, dbName);

            for (int i = 0; i < c; i++)
            {
                DataRow row     = _dtColumns.Rows[i];
                var     colname = row["COLUMN_NAME"].ToString();
                var     pmkey   = false;
                if (colname == PrimaryKey)
                {
                    pmkey = true;
                }
                bool end = false;
                if (i == c - 1)
                {
                    end = true;
                }

                Generator.AddParamSql(row["DATA_TYPE"].ToString(), colname, ToInt32(row["CHARACTER_MAXIMUM_LENGTH"].ToString()), end, pmkey);
                Generator.AddFileData(colname, end, pmkey);
                Generator.AddFileParamInsert(colname, end, pmkey);
                Generator.AddParamSqlUpdate(row["DATA_TYPE"].ToString(), colname, ToInt32(row["CHARACTER_MAXIMUM_LENGTH"].ToString()), end, pmkey);
                Generator.AddFileParamUpdate(colname, end, pmkey);
            }

            Generator.EndGeneration();
            rtprocedure.Text = Generator.RawClassText.Replace("[column_name]", "").Replace("$column_name$", "").Replace("!column_name!", "").Replace("#column_name#", "");
        }
Esempio n. 2
0
        private string GetValue(string tableNames)
        {
            _dtColumns = new DataTable();
            if (tableNames.Equals(""))
            {
                return("");
            }
            string dbName = Args.Database;

            Args.InitialCatalog = dbName;
            Args.WheredTable    = tableNames;
            Args.WheredDb       = dbName;
            Adapters.LsColumnsDA.Fill(_dtColumns);

            PrimaryKey = Adapters.GetPrimarykey;

            try
            {
                string paths = Path.GetFullPath("Templete/" + Argument.FileEntity);
                rtxtClass.LoadFile(paths, RichTextBoxStreamType.PlainText);

                paths = Path.GetFullPath("Templete/" + Argument.FileData);
                rtData.LoadFile(paths, RichTextBoxStreamType.PlainText);

                paths = Path.GetFullPath("Templete/" + Argument.FileSproc);
                rtprocedure.LoadFile(paths, RichTextBoxStreamType.PlainText);
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.ToString());
            }

            //Generator Entity
            Generator.BeginGeneration(rtxtClass.Text);
            Generator.AddTableDbName(tableNames, dbName);
            foreach (DataRow row in _dtColumns.Rows)
            {
                Generator.AddField(row["DATA_TYPE"].ToString(), row["COLUMN_NAME"].ToString());
            }
            Generator.EndGeneration();
            string textEntity = Generator.RawClassText.Replace("[namespace]", Args.NameSpaceName);

            GetValue(tableNames.Replace("tbl_", ""), textEntity.Replace("tbl_", ""), "Entity", "Info");

            ////Generator Service
            //Generator.BeginGeneration(rtService.Text);
            //Generator.AddTableDbName(tableNames, dbName);
            //Generator.EndGeneration();
            //string textService = Generator.RawClassText.Replace("[namespace]", Args.NameSpaceName);
            //GetValue("I" + tableNames.Replace("tbl_", ""), textService.Replace("tbl_", ""), "Services", "");

            ////Generator Implement
            //Generator.BeginGeneration(rtImplement.Text);
            //Generator.AddTableDbName(tableNames, dbName);
            //int c = _dtColumns.Rows.Count;
            //for (int i = 0; i < _dtColumns.Rows.Count; i++)
            //{
            //    DataRow row = _dtColumns.Rows[i];
            //    string colname = row["COLUMN_NAME"].ToString();
            //    bool pmkey = false;
            //    if (colname == PrimaryKey)
            //    {
            //        pmkey = true;
            //    }

            //    bool end = false;
            //    if (i == c - 1)
            //        end = true;
            //    Generator.AddParameterSql(colname, end, pmkey);
            //    Generator.AddReaderSql(row["DATA_TYPE"].ToString(), colname);
            //}
            //Generator.EndGeneration();
            //string textImpl = Generator.RawClassText.Replace("<column_name>", "").Replace("[namespace]",
            //                                                                              Args.NameSpaceName);
            //GetValue(tableNames.Replace("tbl_", ""), textImpl.Replace("tbl_", ""), "Impl", "Impl");

            //Generator Data
            Generator.BeginGeneration(rtData.Text);
            Generator.AddTableDbName(tableNames, dbName);
            int c = _dtColumns.Rows.Count;

            for (int i = 0; i < _dtColumns.Rows.Count; i++)
            {
                DataRow row     = _dtColumns.Rows[i];
                string  colname = row["COLUMN_NAME"].ToString();
                bool    pmkey   = false;
                if (colname == PrimaryKey)
                {
                    pmkey = true;
                }

                bool end = false;
                if (i == c - 1)
                {
                    end = true;
                }
                Generator.AddParameterSql(colname, end, pmkey);
                Generator.AddReaderSql(row["DATA_TYPE"].ToString(), colname);
            }
            Generator.EndGeneration();
            string textData = Generator.RawClassText.Replace("<column_name>", "").Replace("[namespace]", Args.NameSpaceName);

            GetValue(tableNames.Replace("tbl_", ""), textData.Replace("tbl_", ""), "Data", "Data");

            //Generator Storeprocedure
            Generator.BeginGeneration(rtprocedure.Text);
            Generator.AddTableDbName(tableNames, dbName);

            for (int i = 0; i < c; i++)
            {
                DataRow row     = _dtColumns.Rows[i];
                string  colname = row["COLUMN_NAME"].ToString();
                bool    pmkey   = false;
                if (colname == PrimaryKey)
                {
                    pmkey = true;
                }
                bool end = false;
                if (i == c - 1)
                {
                    end = true;
                }

                Generator.AddParamSql(row["DATA_TYPE"].ToString(), colname, ToInt32(row["CHARACTER_MAXIMUM_LENGTH"].ToString()), end, pmkey);
                Generator.AddFileData(colname, end, pmkey);
                Generator.AddFileParamInsert(colname, end, pmkey);
                Generator.AddParamSqlUpdate(row["DATA_TYPE"].ToString(), colname, ToInt32(row["CHARACTER_MAXIMUM_LENGTH"].ToString()), end, pmkey);
                Generator.AddFileParamUpdate(colname, end, pmkey);
            }

            Generator.EndGeneration();
            return(Generator.RawClassText.Replace("[column_name]", "").Replace("$column_name$", "").Replace(
                       "!column_name!", "").
                   Replace("#column_name#", ""));
        }