/// <summary> /// Método para salvar os emails que vem da tela. /// </summary> /// <param name="id_contato"></param> /// <param name="oConn"></param> private void salvaEmails(int id_contato, IDbPersist oConn) { DataRow dr_email = ConnAccess.getNewRow(oConn, "contato_email"); int qtde_emails = RendLibrary.Helper.RequestValue <int>("qtde_emails").Value; string str_ids = "0"; int ordem = 0; string emails = ""; for (int i = 0; i <= qtde_emails; i++) { string email = RendLibrary.Helper.RequestString("email" + i.ToString()); if (email.Trim() != String.Empty) { ordem++; if (emails != String.Empty) { emails += ", "; } emails += email.Trim(); dr_email["email"] = email; dr_email["id_contato"] = id_contato; dr_email["ordem_cadastro"] = ordem; string sql_item = " select id from contato_email where email='" + email + "' and id_contato=" + id_contato.ToString(); object id_tmp = ConnAccess.executeScalar(oConn, sql_item); if (id_tmp != null && id_tmp != DBNull.Value) { dr_email["id"] = id_tmp; ConnAccess.Update(oConn, dr_email, "id"); } else { ConnAccess.Insert(oConn, dr_email, "id", true); dr_email["id"] = ConnAccess.getMax(oConn, "id", dr_email.Table.TableName, " where id_contato = " + id_contato.ToString()); } str_ids += "," + dr_email["id"].ToString(); } } ConnAccess.executeCommand(oConn, " delete from contato_email where id_contato = " + id_contato.ToString() + " and id not in ( " + str_ids + " ) "); ConnAccess.executeCommand(oConn, " update contato set emails = '" + emails + "' where id = " + id_contato.ToString()); }