public ResultList <RubricaEntita> LoadEntitaByMailDomain(IList <EntitaType> tEnt, string mail, int da, int per) { ResultList <RubricaEntita> r = new ResultList <RubricaEntita>(); string query = null; if (tEnt != null) { tEnt = tEnt.Where(e => e != EntitaType.ALL).ToList(); } if (tEnt == null || tEnt.Count == 0) { query = selectEntitaByMailDomain; } else { query = "SELECT * FROM ("; query += selectEntitaByMailDomain; query += ") WHERE REFERRAL_TYPE IN ('" + String.Join("','", tEnt.Select(x => x.ToString()).ToArray()) + "')"; } string queryCnt = "SELECT COUNT(*) FROM (" + query + ")"; using (OracleCommand ocmd = base.CurrentConnection.CreateCommand()) { ocmd.CommandText = queryCnt; ocmd.BindByName = true; ocmd.Parameters.Add("p_mailDomain", mail); ocmd.CommandText = queryCnt; try { int tot = Convert.ToInt32(ocmd.ExecuteScalar()); r.Da = ((da == 0) ? ++da : da); r.Per = ((tot < per) ? tot : per); r.Totale = tot; } catch { throw; } if (r.Totale > 0) { ocmd.CommandText = OrderedTOracleDB.GetOrderedQuery(query, da, per); try { using (OracleDataReader rr = ocmd.ExecuteReader()) { if (rr.HasRows) { r.List = new List <RubricaEntita>(); while (rr.Read()) { r.List.Add(DaoOracleDbHelper.MapToRubricaEntita(rr)); } } } } catch (Exception excp) { r.List = null; if (excp.GetType() != typeof(ManagedException)) { //Allineamento log - Ciro ManagedException mEx = new ManagedException(excp.Message, "RUB_ORA001", string.Empty, string.Empty, excp); ErrorLogInfo er = new ErrorLogInfo(mEx); log.Error(er); throw mEx; } else { throw excp; } } } } return(r); }
public ResultList <RubricaEntita> LoadEntitaIPAByMailDomain(string mail, int da, int per) { ResultList <RubricaEntita> re = new ResultList <RubricaEntita>(); string query = selectEntitaIPAByMailDomain; string queryCnt = "SELECT COUNT(*) FROM (" + query + ")"; using (OracleCommand oCmd = base.CurrentConnection.CreateCommand()) { oCmd.CommandText = queryCnt; oCmd.BindByName = true; oCmd.Parameters.Add("p_mailDomain", OracleDbType.Varchar2, mail, ParameterDirection.Input); try { int tot = Convert.ToInt32(oCmd.ExecuteScalar()); re.Da = ((da == 0) ? ++da : da); re.Per = ((tot < per) ? tot : per); re.Totale = tot; } catch { throw; } if (re.Totale > 0) { oCmd.CommandText = OrderedTOracleDB.GetOrderedQuery(query, da, per); try { using (OracleDataReader rr = oCmd.ExecuteReader()) { if (rr.HasRows) { re.List = new List <RubricaEntita>(); while (rr.Read()) { re.List.Add(DaoOracleDbHelper.MapIPAToRubricaEntita(rr)); } } } if (re.List != null && re.List.Count > 0) { ((List <RubricaEntita>)re.List).ForEach(e => { if (e.ReferralType == EntitaType.UNKNOWN) { if (String.IsNullOrEmpty(e.Ufficio)) { e.ReferralType = EntitaType.PA; } else { e.ReferralType = EntitaType.PA_UFF; } } }); } } catch (Exception excp) { re.List = null; if (excp.GetType() != typeof(ManagedException)) { //Allineamento log - Ciro ManagedException mEx = new ManagedException(excp.Message, "RUB_ORA002", string.Empty, string.Empty, excp); ErrorLogInfo er = new ErrorLogInfo(mEx); log.Error(er); throw mEx; } else { throw excp; } } } } return(re); }
public ResultList <RubricaEntita> LoadSimilarityEntitaByParams(IList <SendMail.Model.EntitaType> tEnt, IDictionary <SendMail.Model.FastIndexedAttributes, IList <string> > pars, int da, int per) { if (pars == null || pars.Count == 0) { return(null); } if (tEnt == null) { tEnt = new List <SendMail.Model.EntitaType>(); } if (tEnt.Count == 0) { tEnt.Add(SendMail.Model.EntitaType.ALL); } if (pars.Any(x => x.Value == null)) { throw new ArgumentException("Parametri non validi"); } ResultList <RubricaEntita> res = new ResultList <RubricaEntita>(); res.Da = da; res.Per = per; int tot = pars.SelectMany(c => c.Value).Count(); string[] matchPars = new string[tot]; string utlBase = "utl_match.jaro_winkler_similarity('{0}', {1})"; string orderby = null; for (int i = 0; i < pars.Count; i++) { KeyValuePair <SendMail.Model.FastIndexedAttributes, IList <string> > p = pars.ElementAt(i); if (p.Value == null || p.Value.Count == 0) { throw new ArgumentException("Parametri non validi"); } string qPar = null; switch (p.Key) { case SendMail.Model.FastIndexedAttributes.COGNOME: qPar = "nvl2(cognome, lower(cognome||' '||nome), lower(nome))"; break; case SendMail.Model.FastIndexedAttributes.RAGIONE_SOCIALE: qPar = "nvl2(disamb_pre, lower(disamb_pre||' '||ragione_sociale||' '||disamb_post), lower(ragione_sociale))"; break; case SendMail.Model.FastIndexedAttributes.UFFICIO: qPar = "ufficio"; break; default: throw new NotImplementedException("Tipo di rircerca non implementato"); } for (int j = 0; j < p.Value.Count; j++) { int idx = Array.FindIndex <string>(matchPars, x => String.IsNullOrEmpty(x)); if (idx != -1) { matchPars[idx] = String.Format(utlBase, p.Value[j], qPar); if (String.IsNullOrEmpty(orderby)) { orderby += String.Format("{0} desc", (idx + 1)); } else { orderby += String.Format(", {0} desc", (idx + 1)); } } } } string where = null; if (!(tEnt.Contains(SendMail.Model.EntitaType.UNKNOWN))) { where = "WHERE REFERRAL_TYPE IN (" + String.Join(", ", tEnt.Select(c => String.Format("'{0}'", c.ToString())).ToArray()) + ")"; } string query = String.Format(selectSimilarityEntitaBaseQuery, String.Join(", ", matchPars), where, orderby); string complOrderBy = null; switch (tEnt[0]) { case SendMail.Model.EntitaType.ALL: case SendMail.Model.EntitaType.PA: case SendMail.Model.EntitaType.PA_SUB: case SendMail.Model.EntitaType.AZ_PRI: case SendMail.Model.EntitaType.AZ_PS: complOrderBy = " order by ragione_sociale asc nulls last"; break; case SendMail.Model.EntitaType.PA_UFF_PF: case SendMail.Model.EntitaType.AZ_UFF_PF: case SendMail.Model.EntitaType.AZ_PF: case SendMail.Model.EntitaType.PA_PF: case SendMail.Model.EntitaType.PF: case SendMail.Model.EntitaType.PG: complOrderBy = " order by cognome, nome asc nulls last"; break; case SendMail.Model.EntitaType.PA_UFF: case SendMail.Model.EntitaType.AZ_UFF: complOrderBy = " order by ufficio asc nulls last"; break; case SendMail.Model.EntitaType.GRP: case SendMail.Model.EntitaType.UNKNOWN: break; default: throw new ArgumentException("Caso non implementato"); } try { using (OracleCommand oCmd = base.CurrentConnection.CreateCommand()) { if (per > 0) { oCmd.CommandText = OrderedTOracleDB.GetOrderedQuery(query, da, per); } else { oCmd.CommandText = query; } oCmd.CommandText += complOrderBy; using (OracleDataReader r = oCmd.ExecuteReader()) { if (r.HasRows) { res.List = new List <RubricaEntita>(); while (r.Read()) { res.List.Add(DaoOracleDbHelper.MapToRubricaEntita(r)); } } } } } catch { res = null; throw; } return(res); }
public ResultList <RubricaEntita> LoadEntitaByParams(IList <SendMail.Model.EntitaType> tEnt, IDictionary <SendMail.Model.FastIndexedAttributes, IList <string> > pars, int da, int per) { if (tEnt == null) { tEnt = new List <SendMail.Model.EntitaType>(); } if (tEnt.Count == 0) { tEnt.Add(SendMail.Model.EntitaType.UNKNOWN); } tEnt = tEnt.Where(te => te != EntitaType.ALL).DefaultIfEmpty(EntitaType.UNKNOWN).ToList(); ResultList <RubricaEntita> res = new ResultList <RubricaEntita>(); res.Da = da; string query = selectEntitaBaseQuery; string orderby = " order by {0} asc nulls last"; string[] oBy = new string[pars.Count]; if (pars != null && pars.Count != 0) { query += " WHERE "; string[] wherePars = new string[pars.Count]; for (int i = 0; i < pars.Count; i++) { KeyValuePair <SendMail.Model.FastIndexedAttributes, IList <string> > p = pars.ElementAt(i); if (p.Value == null || p.Value.Count == 0) { throw new ArgumentException("Parametri non validi"); } string qPar = null; switch (p.Key) { case SendMail.Model.FastIndexedAttributes.COGNOME: qPar = "lower(r.cognome||' '||r.nome) like"; oBy[i] = "cognome, nome"; break; case SendMail.Model.FastIndexedAttributes.RAGIONE_SOCIALE: qPar = "lower(r.disamb_pre||' '||r.ragione_sociale||' '||r.disamb_post) like"; oBy[i] = "disamb_pre, ragione_sociale, disamb_post"; break; case SendMail.Model.FastIndexedAttributes.UFFICIO: qPar = "lower(r.ufficio) like"; oBy[i] = "ragione_sociale, ufficio"; break; default: throw new NotImplementedException("Tipo di rircerca non implementato"); } string[] qCrt = new string[p.Value.Count]; for (int j = 0; j < p.Value.Count; j++) { qCrt[j] = String.Format("{0} '%{1}%'", qPar, p.Value[j].ToLower()); } wherePars[i] = String.Format("({0})", String.Join(" OR ", qCrt)); } query += String.Join(" AND ", wherePars); if (!(tEnt.Contains(SendMail.Model.EntitaType.UNKNOWN))) { query += String.Format(" and r.REFERRAL_TYPE IN ({0})", String.Join(", ", tEnt.Select(c => String.Format("'{0}'", c.ToString())).ToArray())); } } else if (!(tEnt.Contains(SendMail.Model.EntitaType.UNKNOWN))) { query += String.Format(" and r.REFERRAL_TYPE IN ({0})", String.Join(", ", tEnt.Select(c => String.Format("'{0}'", c.ToString())).ToArray())); } string qryCount = "SELECT COUNT(*) FROM (" + query + ")"; query += String.Format(orderby, String.Join(", ", oBy)); using (OracleCommand oCmd = base.CurrentConnection.CreateCommand()) { oCmd.CommandText = qryCount; try { int tRig = Convert.ToInt32(oCmd.ExecuteScalar()); res.Totale = tRig; res.Per = (tRig > per) ? per : tRig; } catch { res.Per = res.Totale = 0; res.List = null; throw; } if (res.Totale > 0) { if (res.Per > 0) { oCmd.CommandText = OrderedTOracleDB.GetOrderedQuery(query, da, res.Per); } else { oCmd.CommandText = query; } try { using (OracleDataReader r = oCmd.ExecuteReader()) { if (r.HasRows) { res.List = new List <RubricaEntita>(); while (r.Read()) { res.List.Add(DaoOracleDbHelper.MapToRubricaEntita(r)); } } } } catch { res.List = null; throw; } } else { try { res = LoadSimilarityEntitaByParams(tEnt, pars, 1, per); } catch { res = null; throw; } } } return(res); }
public ResultList <SimpleResultItem> LoadSimilarityFieldsByParams(SendMail.Model.IndexedCatalogs ctg, IList <SendMail.Model.EntitaType> tEnt, KeyValuePair <SendMail.Model.FastIndexedAttributes, string> par, int da, int per) { if (String.IsNullOrEmpty(par.Value)) { return(null); } if (tEnt == null) { tEnt = new List <SendMail.Model.EntitaType>(); } if (tEnt.Count == 0) { tEnt.Add(SendMail.Model.EntitaType.ALL); } ResultList <SimpleResultItem> res = new ResultList <SimpleResultItem>(); res.Da = da; res.Per = per; res.Totale = per; string queryRubrica = "SELECT distinct r.RAGIONE_SOCIALE AS rag_soc" + ", {0} as descr" + ", r.DISAMB_PRE as prefix" + ", r.DISAMB_POST as suffix" + ", id_referral AS ids" + ", 'R' as SRC" + ", REFERRAL_TYPE as subtype" + ", utl_match.edit_distance_similarity('{1}', lower({0})) AS sim" + " FROM rubr_entita r {2}" + " WHERE {3}" + " order by 8 desc, 1"; string campi = ""; switch (par.Key) { case SendMail.Model.FastIndexedAttributes.RAGIONE_SOCIALE: case SendMail.Model.FastIndexedAttributes.COGNOME: case SendMail.Model.FastIndexedAttributes.FAX: case SendMail.Model.FastIndexedAttributes.MAIL: case SendMail.Model.FastIndexedAttributes.TELEFONO: case SendMail.Model.FastIndexedAttributes.UFFICIO: campi += par.Key.ToString(); break; default: throw new ArgumentException("Parametro non implementato"); } string innerJoin = ""; if (par.Key.Equals(SendMail.Model.FastIndexedAttributes.FAX) || par.Key.Equals(SendMail.Model.FastIndexedAttributes.MAIL) || par.Key.Equals(SendMail.Model.FastIndexedAttributes.TELEFONO)) { innerJoin = "INNER JOIN rubr_contatti c ON c.REF_ID_REFERRAL = r.id_referral"; } string whereConds = null; if (!tEnt.Contains(SendMail.Model.EntitaType.ALL) && !tEnt.Contains(SendMail.Model.EntitaType.UNKNOWN)) { whereConds += "REFERRAL_TYPE in ("; whereConds += String.Join(", ", tEnt.Select(t => String.Format("'{0}'", t.ToString())).ToArray()); whereConds += ") and "; } whereConds += "length(" + par.Key.ToString() + ") >= " + par.Value.Length; string query = string.Format(queryRubrica, campi, par.Value, innerJoin, whereConds); using (OracleCommand oCmd = base.CurrentConnection.CreateCommand()) { if (per > 0) { oCmd.CommandText = OrderedTOracleDB.GetOrderedQuery(query, da, per); } else { oCmd.CommandText = query; } try { using (OracleDataReader r = oCmd.ExecuteReader()) { if (r.HasRows) { res.List = new List <SimpleResultItem>(); while (r.Read()) { res.List.Add( new SimpleResultItem( r.GetValue("descr").ToString(), r.GetValue("ids").ToString(), String.Format("{0} {1} {2}", r.GetValue("prefix"), r.GetValue("rag_soc"), r.GetValue("suffix")), r.GetValue("subtype").ToString(), r.GetValue("SRC").ToString(), Convert.ToInt64(r.GetValue("sim")))); } } } } catch { res.List = null; } } return(res); }
public ResultList <SimpleResultItem> LoadFieldsByParams(SendMail.Model.IndexedCatalogs ctg, IList <SendMail.Model.EntitaType> tEnt, KeyValuePair <SendMail.Model.FastIndexedAttributes, string> par, int da, int per) { if (String.IsNullOrEmpty(par.Value)) { return(null); } if (tEnt == null) { tEnt = new List <SendMail.Model.EntitaType>(); } if (tEnt.Count == 0) { tEnt.Add(SendMail.Model.EntitaType.ALL); } ResultList <SimpleResultItem> res = new ResultList <SimpleResultItem>(); res.Da = da; string queryCountBase = "SELECT count(*) from ({0})"; string queryRubrica = "SELECT distinct r.RAGIONE_SOCIALE AS rag_soc" + ", r.DISAMB_PRE as prefix" + ", r.DISAMB_POST as suffix" + ", {0} as descr" + ", LISTAGG(r.ID_REFERRAL, ';') within group (order by r.ID_REFERRAL) over (partition by NVL(r.DISAMB_PRE,' ')||r.RAGIONE_SOCIALE||NVL(r.DISAMB_POST,' ')) AS ids" //(partition by {0}) + ", 'R' as SRC" + ", REFERRAL_TYPE as subtype" + " FROM rubr_entita r {1}" + " WHERE {2}" + " order by 1"; string campi = ""; switch (par.Key) { case SendMail.Model.FastIndexedAttributes.RAGIONE_SOCIALE: case SendMail.Model.FastIndexedAttributes.COGNOME: case SendMail.Model.FastIndexedAttributes.FAX: case SendMail.Model.FastIndexedAttributes.MAIL: case SendMail.Model.FastIndexedAttributes.TELEFONO: case SendMail.Model.FastIndexedAttributes.UFFICIO: campi += par.Key.ToString(); break; default: throw new ArgumentException("Parametro non implementato"); } string innerJoin = ""; if (par.Key.Equals(SendMail.Model.FastIndexedAttributes.FAX) || par.Key.Equals(SendMail.Model.FastIndexedAttributes.MAIL) || par.Key.Equals(SendMail.Model.FastIndexedAttributes.TELEFONO)) { innerJoin = "INNER JOIN rubr_contatti c ON c.REF_ID_REFERRAL = r.id_referral"; } string whereConds = null; if (!tEnt.Contains(SendMail.Model.EntitaType.ALL) && !tEnt.Contains(SendMail.Model.EntitaType.UNKNOWN)) { whereConds += "REFERRAL_TYPE in ("; whereConds += String.Join(", ", tEnt.Select(t => String.Format("'{0}'", t.ToString())).ToArray()); whereConds += ") and "; } whereConds += "length(" + par.Key.ToString() + ") >= " + par.Value.Length + " and "; switch (par.Key) { case SendMail.Model.FastIndexedAttributes.COGNOME: case SendMail.Model.FastIndexedAttributes.MAIL: case SendMail.Model.FastIndexedAttributes.UFFICIO: case SendMail.Model.FastIndexedAttributes.RAGIONE_SOCIALE: whereConds += "lower(" + par.Key.ToString() + ") like '%" + par.Value.ToLower() + "%'"; break; case SendMail.Model.FastIndexedAttributes.FAX: case SendMail.Model.FastIndexedAttributes.TELEFONO: whereConds += par.Key.ToString() + " like '%" + par.Value.ToLower() + "%'"; break; default: throw new ArgumentException("Parametro non implementato"); } string query = string.Format(queryRubrica, campi, innerJoin, whereConds); string queryCount = String.Format(queryCountBase, query); using (OracleCommand oCmd = base.CurrentConnection.CreateCommand()) { //count int tot = 0; oCmd.CommandText = queryCount; try { tot = Convert.ToInt32(oCmd.ExecuteScalar()); res.Per = (tot > per) ? per : tot; res.Totale = tot; } catch { tot = 0; res.List = null; } if (tot > 0) { if (per > 0) { oCmd.CommandText = OrderedTOracleDB.GetOrderedQuery(query, da, per); } else { oCmd.CommandText = query; } try { using (OracleDataReader r = oCmd.ExecuteReader()) { if (r.HasRows) { res.List = new List <SimpleResultItem>(); while (r.Read()) { res.List.Add( new SimpleResultItem( r.GetValue("descr").ToString(), r.GetValue("ids").ToString(), String.Format("{0} {1} {2}", r.GetValue("prefix"), r.GetValue("rag_soc"), r.GetValue("suffix")), r.GetValue("subtype").ToString(), r.GetValue("SRC").ToString(), 100)); } } } } catch { res.List = null; } } else if ((par.Key != SendMail.Model.FastIndexedAttributes.FAX) && (par.Key != SendMail.Model.FastIndexedAttributes.TELEFONO)) { res = LoadSimilarityFieldsByParams(ctg, tEnt, par, 1, per); } } return(res); }
internal ResultList <RubricaContattiType> GetContattiByParams(List <SendMail.Model.EntitaType> tEnt, Dictionary <SendMail.Model.FastIndexedAttributes, List <string> > pars, int da, int per, bool withEntita) { ResultList <RubricaContattiType> res = new ResultList <RubricaContattiType>(); if (da == 0) { ++da; } res.Da = da; string query = String.Format("SELECT VALUE(V0) FROM {0} V0", ((intoIPA) ? "V_RUBR_CONTATTI_IPA_OBJ" : "V_RUBR_CONTATTI_OBJ")); string orderby = " order by {0} asc nulls last"; string[] oBy = new string[pars.Count]; if (pars != null && pars.Count != 0) { query += " WHERE "; } string[] wherePars = new string[pars.Count]; for (int i = 0; i < pars.Count; i++) { KeyValuePair <SendMail.Model.FastIndexedAttributes, List <string> > p = pars.ElementAt(i); if (p.Value == null || p.Value.Count == 0) { throw new ArgumentException("Parametri non validi"); } string qPar = null; switch (p.Key) { case SendMail.Model.FastIndexedAttributes.FAX: qPar = "V0.FAX ="; oBy[i] = "V0.fax"; break; case SendMail.Model.FastIndexedAttributes.MAIL: qPar = "V0.MAIL ="; oBy[i] = "V0.mail"; break; case SendMail.Model.FastIndexedAttributes.TELEFONO: qPar = "V0.TELEFONO ="; oBy[i] = "V0.telefono"; break; case SendMail.Model.FastIndexedAttributes.COGNOME: qPar = "V0.ENTITA_REF.COGNOME ="; oBy[i] = "V0.ENTITA_REF.COGNOME"; break; case SendMail.Model.FastIndexedAttributes.RAGIONE_SOCIALE: qPar = "V0.ENTITA_REF.RAGIONE_SOCIALE ="; oBy[i] = "V0.ENTITA_REF.RAGIONE_SOCIALE"; break; case SendMail.Model.FastIndexedAttributes.UFFICIO: qPar = "V0.ENTITA_REF.UFFICIO ="; oBy[i] = "V0.ENTITA_REF.UFFICIO"; break; default: throw new NotImplementedException("Tipo di rircerca non implementato"); } string[] qCrt = new string[p.Value.Count]; for (int j = 0; j < p.Value.Count; j++) { qCrt[j] = String.Format("{0} '{1}'", qPar, p.Value[j]); } wherePars[i] = String.Format("({0})", String.Join(" OR ", qCrt)); } query += String.Join(" AND ", wherePars); string queryCount = query.Replace(" VALUE(V0) ", " count(*) "); query += String.Format(orderby, String.Join(", ", oBy)); using (OracleCommand oCmd = base.CurrentConnection.CreateCommand()) { oCmd.CommandText = queryCount; try { int tot = Convert.ToInt32(oCmd.ExecuteScalar()); res.Totale = tot; res.Per = (tot > per) ? per : tot; } catch { res.Per = res.Totale = 0; res.List = null; throw; } if (res.Totale > 0) { if (res.Per > 0) { oCmd.CommandText = OrderedTOracleDB.GetOrderedQuery(query, da, res.Per); } else { oCmd.CommandText = query; } try { using (OracleDataReader r = oCmd.ExecuteReader()) { if (r.HasRows) { res.List = new List <RubricaContattiType>(); while (r.Read()) { RubricaContattiType rc = r.GetValue(1) as RubricaContattiType; if (withEntita) { rc.SetEntita(base.CurrentConnection); } res.List.Add(rc); } } } } catch { res.List = null; throw; } } } return(res); }