コード例 #1
0
ファイル: Form1.cs プロジェクト: hermsdorff/LabAgeis1
        private void button3_Click(object sender, EventArgs e)
        {
            Periferica peri = new Periferica();

            ddlTabelas.DataSource    = peri.BuscaTabelasBanco(txtConn.Text, txtBanco.Text);
            ddlTabelas.DisplayMember = "table_name";
            ddlTabelas.ValueMember   = "table_name";
            //if (ddlTabelas.Items.Count > 0)
            //{
            //     MessageBox.Show("Banco de Dados Inexiste ou não possui tabelas!\nCheque a string de conexão e\ou o Nome do Banco de Dados", "Aviso!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //}
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: hermsdorff/LabAgeis1
        public void CriarClasses(string pNomeProjeto, string pCaminhoProjeto, string pConexao, string pTabela)
        {
            try
            {
                Periferica peri = new Periferica();
                //Entidade ent = new Entidade();
                //Constantes constantes = new Constantes();
                DTO        dto        = new DTO();
                DAOs       daos       = new DAOs();
                Controller controller = new Controller();
                //Mapper mappers = new Mapper();
                List <string> listLocalSalv = new List <string>();
                string        retDTO        = String.Empty;
                string        retDAO        = String.Empty;
                string        retCT         = String.Empty;

                string nomeProjeto = pNomeProjeto != string.Empty ? pNomeProjeto : comboBox1.SelectedItem.ToString();
                //nomeProjeto = nomeProjeto;

                //string retEnt = ent.GerarClasseEntidade(pConexao, pTabela, nomeProjeto);
                //string retConstantes = constantes.GerarClasseConstantesDB(pConexao, pTabela, nomeProjeto);
                if (cbDTO.Checked == true)
                {
                    retDTO = dto.GerarClasseDTO(pConexao, pTabela, nomeProjeto);
                }

                if (cbDAO.Checked == true)
                {
                    retDAO = daos.GerarClasseDAOs(pConexao, pTabela, nomeProjeto);
                }

                if (cbController.Checked == true)
                {
                    retCT = controller.GerarClasseCTs(pConexao, pTabela, nomeProjeto);
                }

                //string retMAPPER = mappers.GerarClasseConstantesDB(pConexao, pTabela, nomeProjeto);
                string path = string.Empty;

                //nomeArquivoEntidade = peri.RetiraLixoNomeTabela(pTabela) + "Entidade.cs";
                nomeArquivoDAO = peri.RetiraLixoNomeTabela(pTabela) + "DAO.cs";
                nomeArquivoDTO = peri.RetiraLixoNomeTabela(pTabela) + "DTO.cs";
                nomeArquivoCT  = peri.RetiraLixoNomeTabela(pTabela) + "CT.cs";
                //nomeArquivoMAPPER = peri.RetiraLixoNomeTabela(pTabela) + "Mapper.cs";

                if (!Directory.Exists(pCaminhoProjeto))
                {
                    Directory.CreateDirectory("D:\\GeradorClasses");
                }

                if (pCaminhoProjeto == "D:\\GeradorClasses" || pCaminhoProjeto == string.Empty)
                {
                    path = "D:\\GeradorClasses\\";
                }
                else
                {
                    path = pCaminhoProjeto + "\\";
                }

                //if (File.Exists(path + nomeProjeto + ".Entidades\\" + nomeArquivoEntidade))
                //    nomeArquivoEntidade = DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Year.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + nomeArquivoEntidade + "Entidade.cs";

                if (File.Exists(path + nomeProjeto + ".DAO\\" + nomeArquivoDAO))
                {
                    nomeArquivoDAO = DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Year.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + pTabela + "DAO.cs";
                }

                if (File.Exists(path + nomeProjeto + ".DTO\\" + nomeArquivoDTO))
                {
                    nomeArquivoDTO = DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Year.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + pTabela + "DTO.cs";
                }

                if (File.Exists(path + nomeProjeto + ".Controller\\" + nomeArquivoCT))
                {
                    nomeArquivoCT = DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Year.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + pTabela + "CT.cs";
                }



                StreamWriter stre;

                if (Directory.Exists(path + nomeProjeto + ".DAO\\"))
                {
                    stre = new StreamWriter(path + nomeProjeto + ".DAO\\" + nomeArquivoDAO);
                    listLocalSalv.Add(path + nomeProjeto + ".DAO\\" + nomeArquivoDAO);
                }
                else
                {
                    stre = new StreamWriter(path + nomeArquivoDAO);
                    listLocalSalv.Add(path + nomeProjeto + ".DAO\\" + nomeArquivoDAO);
                }

                if (cbDAO.Checked == true)
                {
                    stre.Write(retDAO);
                }

                stre.Close();


                if (Directory.Exists(path + nomeProjeto + ".DTO\\"))
                {
                    stre = new StreamWriter(path + nomeProjeto + ".DTO\\" + nomeArquivoDTO);
                    listLocalSalv.Add(path + nomeProjeto + ".DTO\\" + nomeArquivoDTO);
                }
                else
                {
                    stre = new StreamWriter(path + nomeArquivoDTO);
                    listLocalSalv.Add(path + nomeArquivoDTO);
                }


                if (cbDTO.Checked == true)
                {
                    stre.Write(retDTO);
                }

                stre.Close();


                if (Directory.Exists(path + nomeProjeto + ".Controller\\"))
                {
                    stre = new StreamWriter(path + nomeProjeto + ".Controller\\" + nomeArquivoCT);
                    listLocalSalv.Add(path + nomeProjeto + ".Controller\\" + nomeArquivoCT);
                }
                else
                {
                    stre = new StreamWriter(path + nomeArquivoDAO);
                    listLocalSalv.Add(path + nomeProjeto + ".Controller\\" + nomeArquivoCT);
                }

                if (cbController.Checked == true)
                {
                    stre.Write(retCT);
                }


                stre.Close();


                //if (Directory.Exists(path + nomeProjeto + ".Mappers\\"))
                //{
                //    stre = new StreamWriter(path + nomeProjeto + ".Mappers\\" + nomeArquivoMAPPER);
                //    listLocalSalv.Add(path + nomeProjeto + ".Mappers\\" + nomeArquivoMAPPER);
                //}
                //else
                //{
                //    stre = new StreamWriter(path + nomeArquivoMAPPER);
                //    listLocalSalv.Add(path + nomeArquivoMAPPER);
                //}

                //stre.Write(retMAPPER);

                //stre.Close();

                //if (Directory.Exists(path + nomeProjeto + ".DAOs\\"))
                //{
                //    stre = new StreamWriter(path + nomeProjeto + ".DAOs\\" + nomeArquivoDAO);
                //    listLocalSalv.Add(path + nomeProjeto + ".DAOs\\" + nomeArquivoDAO);
                //}
                //else
                //{
                //    stre = new StreamWriter(path + nomeArquivoDAO);
                //    listLocalSalv.Add(path + nomeArquivoDAO);
                //}

                //stre.Write(retDAO);

                //stre.Close();

                string msg = string.Empty;


                for (int i = 0; i < listLocalSalv.Count; i++)
                {
                    msg += Environment.NewLine + listLocalSalv[i].ToString();
                }

                //MsgBox msgB = new MsgBox(listLocalSalv, false, string.Empty);
                //msgB.Show();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }