protected bool set_attribute(section.type_section st, long id, section_attr a, object val, bool delete = true) { string qry_val = null; if (val != null) { try { if (a.type == section_attr.section_attr_type.datetime) { qry_val = db_provider.dt_qry(Convert.ToDateTime(val)); } else if (a.type == section_attr.section_attr_type.integer) { qry_val = Convert.ToInt32(val).ToString(); } else { qry_val = db_provider.str_qry(val.ToString()); } } catch { throw new Exception(string.Format("il valore {0} dev'essere di tipo {3} e non è corretto. elemento '{1}' id: {2}" , val.ToString(), st.ToString(), id, a.type.ToString())); } exec_set_attribute(st, id, a.type, a.code, qry_val); return(true); } else { if (delete) { exec_del_attribute(st, id, a.type, a.code); return(true); } } return(false); }
public void set_attribute(string code, object value) { section_attr a = _attributes.FirstOrDefault(x => x.code == code); if (a == null) { throw new Exception("l'attributo '" + code + "' non è stato caricato per l'elemento '" + type.ToString() + "'"); } a.value = value.ToString(); }
public void set_attribute(string code, section_attr.section_attr_type type, object value) { section_attr a = _attributes.FirstOrDefault(x => x.code == code); if (a == null) { a = new section_attr(code, type, value); _attributes.Add(a); } else { if (a.type != type) { throw new Exception("l'attributo '" + code + "' non è di tipo '" + type.ToString() + "'"); } a.value = value; } }
protected void set_attribute(string code, string value, List <section_attr> attrs) { if (string.IsNullOrEmpty(value)) { return; } section_attr a = _attributes.FirstOrDefault(x => x.code == code); if (a == null) { section_attr at = attrs.FirstOrDefault(x => x.code == code); if (at == null) { throw new Exception("non è stato trovato l'attributo '" + code + "' per la sezione '" + this.type.ToString() + "' fra quelli configurati!"); } a = new section_attr(code, at.type, value); _attributes.Add(a); } else { a.value = value; } }
public int get_attribute_int(string code, int def = 0) { section_attr a = _attributes.FirstOrDefault(x => x.code == code); return(a != null && a.get_str != "" ? a.get_int : def); }
public bool get_attribute_bool(string code) { section_attr a = _attributes.FirstOrDefault(x => x.code == code); return(a != null ? a.get_bool : false); }
public string get_attribute_string(string code, string def = "") { section_attr a = _attributes.FirstOrDefault(x => x.code == code); return(a != null && !string.IsNullOrEmpty(a.get_str) ? a.get_str : def); }