internal static List <UFD1> RetornaValores(string nomeTabela, string nomeCampo) { List <UFD1> lista = new List <UFD1>(); Recordset oRs = B1AppDomain.RSQuery(string.Format(@"SELECT [TableID] ,[FieldID] ,[IndexID] ,[FldValue] ,[Descr] ,[FldDate] FROM [UFD1] where tableid = '{0}' and fieldid = (select FieldID from CUFD where TableID = '{0}' and AliasID = '{1}')", nomeTabela, nomeCampo)); while (!oRs.EoF) { lista.Add(new UFD1() { TableID = oRs.Fields.Item("TableID").Value.ToString(), FieldID = Convert.ToInt32(oRs.Fields.Item("FieldID").Value.ToString()), IndexID = Convert.ToInt32(oRs.Fields.Item("IndexID").Value.ToString()), FldValue = oRs.Fields.Item("FldValue").Value.ToString(), Descr = oRs.Fields.Item("Descr").Value.ToString(), FldDate = Convert.ToDateTime(oRs.Fields.Item("FldDate").Value.ToString()) }); oRs.MoveNext(); } Objects.LimpaMemoria(oRs); return(lista); }
public void Delete(TEntity obj) { string code = ""; TablesAttribute tbAttribute = null; foreach (PropertyInfo info in obj.GetType().GetProperties()) { if (info.Name == "Code") { code = info.GetValue(obj).ToString(); } } string nomeTabela = ""; foreach (object customAttribute in obj.GetType().GetCustomAttributes(true)) { if (customAttribute is TablesAttribute) { tbAttribute = customAttribute as TablesAttribute; nomeTabela = tbAttribute.Nome; break; } } B1AppDomain.RSQuery(string.Format("delete from [@{0}] where Code = '{1}'", nomeTabela, code)); }
internal static List <UFD1> RetornaValores() { List <UFD1> lista = new List <UFD1>(); Recordset oRs = B1AppDomain.RSQuery(@"SELECT [TableID] ,[FieldID] ,[IndexID] ,[FldValue] ,[Descr] ,[FldDate] FROM [UFD1]"); while (!oRs.EoF) { lista.Add(new UFD1() { TableID = oRs.Fields.Item("TableID").Value.ToString(), FieldID = oRs.Fields.Item("FieldID").Value.ToString(), IndexID = oRs.Fields.Item("IndexID").Value.ToString(), FldValue = oRs.Fields.Item("FldValue").Value.ToString(), Descr = oRs.Fields.Item("Descr").Value.ToString(), FldDate = oRs.Fields.Item("FldDate").Value.ToString() }); oRs.MoveNext(); } Objects.LimpaMemoria(oRs); return(lista); }
protected MenuBase() { this.menuUid = new List <string>(); MenuAttribute attribute = null; int index = 0; foreach (object obj2 in base.GetType().GetCustomAttributes(false)) { if (obj2 is MenuAttribute) { attribute = obj2 as MenuAttribute; this.menuUid.Add(attribute.menuUid); B1AppDomain.RegisterMenuByType(this.menuUid.SingleOrDefault(e => e == attribute.menuUid), this); index++; } } if (attribute == null) { B1Exception.writeLog("Falha ao indexar Form. Por favor checar os atributos informados"); } this.OnInitializeFormEvents(); }
protected FormBase() { formUid = new List <string>(); FormAttribute attribute = null; int index = 0; foreach (object obj2 in base.GetType().GetCustomAttributes(false)) { if (obj2 is FormAttribute) { attribute = obj2 as FormAttribute; if (!string.IsNullOrEmpty(attribute.formUid)) { string form = attribute.formUid; this.formUid.Add(form.Substring(0, 1) == "@" ? form.Replace("@", "UDO_FT_") : form); } string formulario = this.formUid.SingleOrDefault(e => e == attribute.formUid); if (!string.IsNullOrEmpty(formulario)) { B1AppDomain.RegisterFormByType(formulario, this); } index++; } } if (attribute == null) { B1Exception.writeLog("Falha ao indexar Form. Por favor checar os atributos informados"); } this.OnInitializeFormEvents(); }
protected TableBase() { TableId = new List <string>(); TablesAttribute attribute = null; FieldsAttribute flAttribute = null; UdoAttribute udoAttribute = null; UdoChildAttribute udoChildAttribute = null; ValidValuesAttribute valoresValidos = null; foreach (object obj2 in base.GetType().GetCustomAttributes(false)) { #region Atributo Tabelas if (obj2 is TablesAttribute) { attribute = obj2 as TablesAttribute; if (!string.IsNullOrEmpty(attribute.Nome)) { Tabelas tb = new Tabelas(); tb.NomeTabela = attribute.Nome; tb.DescricaoTabela = attribute.Descricao; tb.TipoTabelaSap = attribute.Tipo; tb.Campos = new List <Campos>(); tb.Ttabela = attribute.TabelaSistema ? Tipos.TipoTabela.Sap : Tipos.TipoTabela.Usuario; foreach (PropertyInfo info in this.GetType().GetProperties()) { List <ValoresValidos> vlrs = new List <ValoresValidos>(); Campos cp = new Campos(); foreach (object field in info.GetCustomAttributes(true)) { if (field is FieldsAttribute) { flAttribute = field as FieldsAttribute; RelationalReader.verificaTipos(cp, info, flAttribute, tb.NomeTabela); } if (field is ValidValuesAttribute) { valoresValidos = field as ValidValuesAttribute; vlrs.Add(new ValoresValidos() { Descricao = valoresValidos.Descricao, Valor = valoresValidos.Valor }); } } if (!string.IsNullOrEmpty(cp.NomeCampo)) { if (vlrs.Count > 0) { cp.ValoresValidos = vlrs; } tb.Campos.Add(cp); } } B1AppDomain.RegisterTable(this, tb); } } #endregion #region Atributo Udo if (obj2 is UdoAttribute) { udoAttribute = obj2 as UdoAttribute; if (!string.IsNullOrEmpty(udoAttribute.Code)) { Udo ud = new Udo(); ud.TableName = udoAttribute.TableName; ud.Name = udoAttribute.Name; ud.Code = udoAttribute.Code; ud.Cancel = udoAttribute.Cancel; ud.Close = udoAttribute.Close; ud.CreateDefaultForm = udoAttribute.CreateDefaultForm; ud.Delete = udoAttribute.Delete; ud.Find = udoAttribute.Find; ud.YearTransfer = udoAttribute.YearTransfer; ud.ManageSeries = udoAttribute.ManageSeries; ud.ObjectType = udoAttribute.ObjectType; ud.Formulario = udoAttribute.Formulario; ud.EnableEnhancedform = udoAttribute.EnableEnhancedform; ud.RebuildEnhancedForm = udoAttribute.RebuildEnhancedForm; B1AppDomain.RegisterUdo(this, ud); } } #endregion #region Atributo UdoFilhos if (obj2 is UdoChildAttribute) { udoChildAttribute = obj2 as UdoChildAttribute; if (!string.IsNullOrEmpty(udoChildAttribute.TableName)) { UdoFilhos udf = new UdoFilhos(); udf.TableName = udoChildAttribute.TableName; udf.TabelaPai = udoChildAttribute.TabelaPai; B1AppDomain.RegisterUdoChild(this, udf); } } #endregion } if (attribute == null) { B1Exception.writeLog("Falha ao indexar Tabela. Por favor checar os atributos informados"); } }
public void Add(TEntity obj) { Dictionary <string, object> lista = new Dictionary <string, object>(); FieldsAttribute flAttribute = null; TablesAttribute tbAttribute = null; foreach (PropertyInfo info in obj.GetType().GetProperties()) { foreach (object field in info.GetCustomAttributes(true)) { if (field is FieldsAttribute) { flAttribute = field as FieldsAttribute; if (info.GetValue(obj) != null) { if (info.GetValue(obj).GetType() == typeof(DateTime)) { lista.Add("U_" + flAttribute.Nome, ((DateTime)info.GetValue(obj)).ToString("yyyyMMdd")); } else { lista.Add("U_" + flAttribute.Nome, info.GetValue(obj)); } } } } } string campos = ""; string valores = ""; int controle = 1; foreach (KeyValuePair <string, object> objetos in lista) { if (controle == 1) { campos = objetos.Key; valores = "'" + objetos.Value + "'"; } else { campos = campos + "," + objetos.Key; valores = valores + "," + "'" + objetos.Value + "'"; } controle++; } string nomeTabela = ""; foreach (object customAttribute in obj.GetType().GetCustomAttributes(true)) { if (customAttribute is TablesAttribute) { tbAttribute = customAttribute as TablesAttribute; nomeTabela = tbAttribute.Nome; } } string key = Guid.NewGuid().ToString().Substring(0, 30); string query = string.Format(@"insert into [@{0}] (Code, Name, {1}) values ('{3}','{3}',{2})", nomeTabela, campos, valores, key); B1AppDomain.RSQuery(query); }
public void Update(TEntity obj) { Dictionary <string, object> lista = new Dictionary <string, object>(); FieldsAttribute flAttribute = null; TablesAttribute tbAttribute = null; string key = ""; foreach (PropertyInfo info in obj.GetType().GetProperties()) { if (info.Name == "Code") { key = info.GetValue(obj).ToString(); } foreach (object field in info.GetCustomAttributes(true)) { if (field is FieldsAttribute) { flAttribute = field as FieldsAttribute; if (info.GetValue(obj) != null) { if (info.GetValue(obj).GetType() == typeof(DateTime)) { lista.Add("U_" + flAttribute.Nome, ((DateTime)info.GetValue(obj)).ToString("yyyyMMdd")); } else { lista.Add("U_" + flAttribute.Nome, info.GetValue(obj)); } } } } } string campos = ""; int controle = 1; foreach (KeyValuePair <string, object> objetos in lista) { if (controle == 1) { campos = objetos.Key + " = '" + objetos.Value + "'"; } else { campos = campos + ", " + objetos.Key + " = '" + objetos.Value + "'"; } controle++; } string nomeTabela = ""; foreach (object customAttribute in obj.GetType().GetCustomAttributes(true)) { if (customAttribute is TablesAttribute) { tbAttribute = customAttribute as TablesAttribute; nomeTabela = tbAttribute.Nome; } } string query = string.Format(@"update [@{0}] set {1} where Code = '{2}'", nomeTabela, campos, key); B1AppDomain.RSQuery(query); }
/// <summary> /// busca todos usando filtros and /// </summary> /// <param name="filtros">campo, valor </param> /// <returns></returns> public List <TEntity> GetAll(Dictionary <string, object> filtros) { if (filtros == null) { return(null); } TEntity obj = new TEntity(); Dictionary <string, object> lista = new Dictionary <string, object>(); FieldsAttribute flAttribute = null; TablesAttribute tbAttribute = null; foreach (PropertyInfo info in obj.GetType().GetProperties()) { foreach (object field in info.GetCustomAttributes(true)) { if (field is FieldsAttribute) { flAttribute = field as FieldsAttribute; lista.Add("U_" + flAttribute.Nome, info.GetValue(obj)); } } } string campos = ""; int controle = 1; foreach (KeyValuePair <string, object> objetos in lista) { if (controle == 1) { campos = objetos.Key; } else { campos = campos + "," + objetos.Key; } controle++; } string nomeTabela = ""; foreach (object customAttribute in obj.GetType().GetCustomAttributes(true)) { if (customAttribute is TablesAttribute) { tbAttribute = customAttribute as TablesAttribute; nomeTabela = tbAttribute.Nome; } } string where = ""; controle = 1; foreach (KeyValuePair <string, object> filtro in filtros) { if (controle == 1) { where = filtro.Key + " = '" + filtro.Value + "'"; } else { where = where + " and " + filtro.Key + " = '" + filtro.Value + "'"; } } string query = string.Format("select Code, Name, {0} from [@{1}] where {2}", campos, nomeTabela, where); var oRs = B1AppDomain.RSQuery(query); List <TEntity> resultado = new List <TEntity>(); while (!oRs.EoF) { TEntity obj2 = new TEntity(); foreach (PropertyInfo info in obj2.GetType().GetProperties()) { foreach (object field in info.GetCustomAttributes(true)) { if (field is FieldsAttribute) { flAttribute = field as FieldsAttribute; info.SetValue(obj2, oRs.Fields.Item("U_" + flAttribute.Nome).Value); } } } resultado.Add(obj2); oRs.MoveNext(); } return(resultado); }
public TEntity GetByEntity(TEntity obj) { Dictionary <string, object> lista = new Dictionary <string, object>(); FieldsAttribute flAttribute = null; TablesAttribute tbAttribute = null; foreach (PropertyInfo info in obj.GetType().GetProperties()) { foreach (object field in info.GetCustomAttributes(true)) { if (field is FieldsAttribute) { flAttribute = field as FieldsAttribute; lista.Add("U_" + flAttribute.Nome, info.GetValue(obj)); } } } string campos = ""; string where = ""; int controle = 1; foreach (KeyValuePair <string, object> objetos in lista) { if (controle == 1) { campos = objetos.Key; where = objetos.Key + " = '" + objetos.Value.ToString() + "'"; } else { campos = campos + "," + objetos.Key; if (objetos.Value != null) { if (objetos.Value.ToString().Length < 254) { if (objetos.Value.GetType() == typeof(DateTime)) { DateTime datavalor = Convert.ToDateTime(objetos.Value); DateTime datavazia = Convert.ToDateTime("01/01/0001 00:00:00"); if (datavalor > datavazia) { where = where + " and " + objetos.Key + " = '" + Convert.ToDateTime(objetos.Value).ToString("yyyyMMdd") + "'"; } } else if (objetos.Value.GetType() == typeof(int)) { if (Convert.ToInt32(objetos.Value) != 0) { where = where + " and " + objetos.Key + " = '" + objetos.Value.ToString() + "'"; } } else { where = where + " and " + objetos.Key + " = '" + objetos.Value.ToString() + "'"; } } } } controle++; } string nomeTabela = ""; foreach (object customAttribute in obj.GetType().GetCustomAttributes(true)) { if (customAttribute is TablesAttribute) { tbAttribute = customAttribute as TablesAttribute; nomeTabela = tbAttribute.Nome; } } string query = string.Format("select Code, Name, {0} from [@{1}] where {2}", campos, nomeTabela, where); var oRs = B1AppDomain.RSQuery(query); foreach (PropertyInfo info in obj.GetType().GetProperties()) { if (info.Name == "Code") { info.SetValue(obj, oRs.Fields.Item("Code").Value); } else if (info.Name == "Name") { info.SetValue(obj, oRs.Fields.Item("Name").Value); } foreach (object field in info.GetCustomAttributes(true)) { if (field is FieldsAttribute) { flAttribute = field as FieldsAttribute; info.SetValue(obj, oRs.Fields.Item("U_" + flAttribute.Nome).Value); } } } return(obj); }