public bool DeleteRecord(Promotor_Fields oPromotor) { //************** //* Declarações //************** DBManager oDBManager = new DBManager(ConnectionString); string SQL = string.Empty; //********************************* //* O código do promotor é válido? //********************************* if (oPromotor.PK_CodPromotor != 0) { //****************** //* Exclui registro //****************** SQL = "DELETE FROM promotor WHERE CodPromotor = " + oPromotor.PK_CodPromotor; oDBManager.ExecuteCommand(SQL); //***************************** //* Retorna estado de execução //***************************** if (!oDBManager.Error) { //************* //* Retorna OK //************* _ErrorText = string.Empty; _Error = false; return(true); } else { //*************** //* Retorna erro //*************** _ErrorText = oDBManager.ErrorMessage; _Error = oDBManager.Error; return(false); } } else { //*************** //* Retorna erro //*************** _ErrorText = "Informe o código do promotor."; _Error = true; return(false); } }
public Int32 ApplyRecord(Promotor_Fields oPromotor, bool Import = false) { //************** //* Declarações //************** DBManager oDBManager = new DBManager(ConnectionString); string SQL = string.Empty; //**************** //* Cria registro //**************** SQL = "REPLACE INTO promotor ("; SQL += "CodPromotor,"; SQL += "NomePromotor,"; SQL += "End,"; SQL += "Fone1,"; SQL += "RamalFone1,"; SQL += "Fone2,"; SQL += "RamalFone2,"; SQL += "Fax,"; SQL += "RamalFax,"; SQL += "CEP,"; SQL += "CodCidade,"; SQL += "Tipo,"; SQL += "EMail,"; SQL += "HTTP,"; SQL += "Obs,"; SQL += "Status,"; SQL += "CodRestrito"; SQL += ") VALUES ("; SQL += oPromotor.PK_CodPromotor.ToString() + ","; SQL += "'" + oPromotor.NomePromotor.SQLFilter() + "',"; SQL += "'" + oPromotor.End.SQLFilter() + "',"; SQL += "'" + oPromotor.Fone1.SQLFilter() + "',"; SQL += "'" + oPromotor.RamalFone1.SQLFilter() + "',"; SQL += "'" + oPromotor.Fone2.SQLFilter() + "',"; SQL += "'" + oPromotor.RamalFone2.SQLFilter() + "',"; SQL += "'" + oPromotor.Fax.SQLFilter() + "',"; SQL += "'" + oPromotor.RamalFax.SQLFilter() + "',"; SQL += "'" + oPromotor.CEP.SQLFilter() + "',"; SQL += oPromotor.CodCidade.ToString() + ","; SQL += "'" + oPromotor.Tipo.SQLFilter() + "',"; SQL += "'" + oPromotor.EMail.SQLFilter() + "',"; SQL += "'" + oPromotor.HTTP.SQLFilter() + "',"; SQL += "'" + oPromotor.Obs.SQLFilter() + "',"; SQL += "'" + oPromotor.Status.SQLFilter() + "',"; SQL += oPromotor.CodRestrito.ToString() + ")"; //**************************** //* Controla erro de execução //**************************** try { //************************** //* Executa comando formado //************************** oPromotor.PK_CodPromotor = oDBManager.ExecuteCommand(SQL, Import); //************************************ //* Devolve status e mensagem de erro //************************************ _ErrorText = oDBManager.ErrorMessage; _Error = oDBManager.Error; } catch (Exception oException) { //************************************ //* Devolve status e mensagem de erro //************************************ _ErrorText = oException.Message; _Error = true; } //************************* //* Retorna chave primária //************************* return(oPromotor.PK_CodPromotor); }
public List <Promotor_Fields> Get_NomePromotor_Like(string NomePromotor) { //************** //* Declarações //************** DBManager oDBManager = new DBManager(ConnectionString); List <Promotor_Fields> oPromotores = new List <Promotor_Fields>(); Promotor_Fields oPromotor = new Promotor_Fields(); //******************* //* Proteção de erro //******************* try { //**************************** //* Obtem lista de promotores //**************************** string SQL = "SELECT * FROM promotor WHERE "; SQL += "nomepromotor LIKE '%" + NomePromotor + "%' AND "; SQL += "codpromotor<>0 ORDER BY nomepromotor"; DataTable oTable = oDBManager.ExecuteQuery(SQL); //************************************ //* Devolve status e mensagem de erro //************************************ _ErrorText = oDBManager.ErrorMessage; _Error = oDBManager.Error; //*********************************** //* Devolve resultado nulo como erro //*********************************** if (oTable != null) { //***************************** //* Copia registros para array //***************************** foreach (DataRow oRow in oTable.Rows) { oPromotor = new Promotor_Fields(); oPromotor.PK_CodPromotor = !DBNull.Value.Equals(oRow["codpromotor"]) ? Convert.ToInt32("0" + oRow["codpromotor"]) : 0; oPromotor.NomePromotor = !DBNull.Value.Equals(oRow["nomepromotor"]) ? oRow["nomepromotor"].ToString() : string.Empty; oPromotor.End = !DBNull.Value.Equals(oRow["end"]) ? oRow["end"].ToString() : string.Empty; oPromotor.Fone1 = !DBNull.Value.Equals(oRow["fone1"]) ? oRow["fone1"].ToString() : string.Empty; oPromotor.RamalFone1 = !DBNull.Value.Equals(oRow["ramalfone1"]) ? oRow["ramalfone1"].ToString() : string.Empty; oPromotor.Fone2 = !DBNull.Value.Equals(oRow["fone2"]) ? oRow["fone2"].ToString() : string.Empty; oPromotor.RamalFone2 = !DBNull.Value.Equals(oRow["ramalfone2"]) ? oRow["ramalfone2"].ToString() : string.Empty; oPromotor.Fax = !DBNull.Value.Equals(oRow["fax"]) ? oRow["fax"].ToString() : string.Empty; oPromotor.RamalFax = !DBNull.Value.Equals(oRow["ramalfax"]) ? oRow["ramalfax"].ToString() : string.Empty; oPromotor.CEP = !DBNull.Value.Equals(oRow["cep"]) ? oRow["cep"].ToString() : string.Empty; oPromotor.CodCidade = !DBNull.Value.Equals(oRow["codcidade"]) ? Convert.ToInt32("0" + oRow["codcidade"]) : 0; oPromotor.Tipo = !DBNull.Value.Equals(oRow["tipo"]) ? oRow["tipo"].ToString() : string.Empty; oPromotor.EMail = !DBNull.Value.Equals(oRow["email"]) ? oRow["email"].ToString() : string.Empty; oPromotor.HTTP = !DBNull.Value.Equals(oRow["http"]) ? oRow["http"].ToString() : string.Empty; oPromotor.Obs = !DBNull.Value.Equals(oRow["obs"]) ? oRow["obs"].ToString() : string.Empty; oPromotor.Status = !DBNull.Value.Equals(oRow["status"]) ? oRow["status"].ToString() : string.Empty; oPromotor.CodRestrito = !DBNull.Value.Equals(oRow["codrestrito"]) ? Convert.ToInt32("0" + oRow["codrestrito"]) : 0; oPromotores.Add(oPromotor); } } else { //*********************************** //* Devolve resultado nulo como erro //*********************************** _ErrorText = "O Resultado da pesquisa retornou nulo"; _Error = true; } } catch (Exception oException) { //**************** //* Devolve falha //**************** _ErrorText = oException.Message; _Error = true; } //**************** //* Devolve lista //**************** return(oPromotores); }