// Lista tabelas public List <Tabelas> Listar() { try { List <Tabelas> tabs = new List <Tabelas>(); string qry = ""; qry += "SELECT * FROM Tabelas ORDER BY txtabela"; Connection session = new Connection(); Query query = session.CreateQuery(qry); IDataReader reader = query.ExecuteQuery(); while (reader.Read()) { Tabelas temp = new Tabelas(); temp.idtabela.value = Convert.ToInt32(reader["idtabela"]); temp.txtabela.value = Convert.ToString(reader["txtabela"]); temp.flauditoria.value = Convert.ToInt32(reader["flauditoria"]); temp.idcodigoidioma.value = Convert.ToInt32(reader["idcodigoidioma"]); tabs.Add(temp); } reader.Close(); session.Close(); return(tabs); } catch (Exception error) { throw error; } }
internal static void RegisterTable(object obj, Tabelas tables) { if (obj != null) { DicionarioTabelasCampos.Add(obj, tables); } }
// Busca pelo titulo public Tabelas Buscar(string txtabela = "") { try { Tabelas tabs = new Tabelas(); string qry = ""; qry += "SELECT * FROM Tabelas WHERE txtabela LIKE '%" + txtabela.Replace(" ", "%") + "%'"; Connection session = new Connection(); Query query = session.CreateQuery(qry); IDataReader reader = query.ExecuteQuery(); if (reader.Read()) { tabs.idtabela.value = Convert.ToInt32(reader["idtabela"]); tabs.txtabela.value = Convert.ToString(reader["txtabela"]); tabs.flauditoria.value = Convert.ToInt32(reader["flauditoria"]); tabs.idcodigoidioma.value = Convert.ToInt32(reader["idcodigoidioma"]); } reader.Close(); session.Close(); return(tabs); } catch (Exception error) { throw error; } }
// Gravar nova tabela public int Gravar(Tabelas rs) { try { int idtabela = 0; string qry = ""; qry += "INSERT INTO Tabelas (txtabela, flauditoria, idcodigoidioma) output INSERTED.idtabela "; qry += "VALUES ('" + rs.txtabela.value + "', " + rs.flauditoria.value + ", " + rs.idcodigoidioma.value + ")"; Connection session = new Connection(); Query query = session.CreateQuery(qry); // Retorna o identificador idtabela = query.ExecuteScalar(); // Atualizar registro para registro de auditoria rs.idtabela.value = idtabela; session.Close(); // Auditoria Audit.Check("Tabelas", "I", idtabela, rs); return(idtabela); } catch (Exception erro) { throw erro; } }
public ERPDatabaseContext(DbContextOptions <ERPDatabaseContext> options) : base(options) { Tabelas.Add(typeof(Usuario).Name); Tabelas.Add(typeof(Produto).Name); Tabelas.Add(typeof(ProdutoPropriedades).Name); Tabelas.Add(typeof(Cliente).Name); Tabelas.Add(typeof(ProdutoPropriedadesEstoque).Name); Tabelas.Add(typeof(Venda).Name); Tabelas.Add(typeof(VendaProdutos).Name); }
public f0070() { StringBuilder sb = new StringBuilder(); sb.AppendLine("select "); sb.AppendLine(" notas_fiscais_lotes.*"); sb.AppendLine(" , mrn.descricao as 'Descricao_NFp'"); sb.AppendLine(" , mrnfe.descricao as 'Descricao_NFe'"); sb.AppendLine(" from notas_fiscais_lotes"); sb.AppendLine(" left outer join mensagens_retorno_nfp mrn on mrn.codigo_mensagem_retorno = notas_fiscais_lotes.codigo_mensagem_retorno_NFP"); sb.AppendLine(" left outer join mensagens_retorno_nfe mrnfe on mrnfe.codigo_mensagem_retorno = notas_fiscais_lotes.codigo_mensagem_retorno_NFE"); Tabelas.Add(new Controle_Tabelas(Controle_Tabelas.TiposTabelas.Pai , "notas_fiscais_lotes" , sb.ToString() , "Nota_Fiscal_Lote")); //------------------- sb.Remove(0, sb.Length); sb.AppendLine("select "); sb.AppendLine(" notas_fiscais_lotes_mensagens.*"); sb.AppendLine(" , mrn.descricao as 'Descricao_NFp'"); sb.AppendLine(" , mrnfe.descricao as 'Descricao_NFe'"); sb.AppendLine(" from notas_fiscais_lotes_mensagens"); sb.AppendLine(" left outer join mensagens_retorno_nfp mrn on mrn.codigo_mensagem_retorno = notas_fiscais_lotes_mensagens.codigo_mensagem_retorno_nfp"); sb.AppendLine(" left outer join mensagens_retorno_nfe mrnfe on mrnfe.codigo_mensagem_retorno = notas_fiscais_lotes_mensagens.codigo_mensagem_retorno_nfe"); Tabelas.Add(new Controle_Tabelas(Controle_Tabelas.TiposTabelas.Filha , "notas_fiscais_lotes_mensagens" , sb.ToString())); //------------------- sb.Remove(0, sb.Length); sb.AppendLine("select notas_fiscais_lotes_itens.*, cl.razao_social, nf.Numero_nota, nf.Data_Emissao"); sb.AppendLine(" from notas_fiscais_lotes_itens"); sb.AppendLine(" inner join notas_fiscais nf on nf.nota_fiscal = notas_fiscais_lotes_itens.nota_fiscal"); sb.AppendLine(" inner join clientes cl on cl.cliente = nf.cliente"); Tabelas.Add(new Controle_Tabelas(Controle_Tabelas.TiposTabelas.Filha , "Notas_Fiscais_Lotes_Itens" , sb.ToString())); InitializeComponent(); #if (!DEBUG) this.cf_Button1.Visible = false; #endif if (Name == "f0070") { cmdImprimirDANFE.Visible = false; cmdCancelarNFe.Visible = false; cmdBuscarStatusNFe.Visible = false; cmdEnviarArquivo.Visible = true; cmdCartaCorrecao.Visible = true; } }
public void Listar() { this.Cursor = Cursors.WaitCursor; ConfiguraBanco configBD = new ConfiguraBanco(); // Classe de conexão com o banco de dados ConexaoBanco conexao = new ConexaoBanco(); Tabelas tabelas = new Tabelas(); this.Cursor = Cursors.Default; var dtLista = tabelas.Listar(conexao.ConexaoReturn); dgListar.DataSource = dtLista; }
protected void DeleteTabela(object sender, EventArgs e) { try { object selectedItem = ((DataGrid)data1).SelectedItem; Type type2 = selectedItem.GetType(); id_tab = (string)type2.GetProperty("STAMPTABELA").GetValue(selectedItem, null); Tabelas tabelas = tabela.getTabelaDetails(id_tab); } catch { } if (id_tab != "") { System.Windows.Forms.DialogResult result = System.Windows.Forms.MessageBox.Show("Tem a certeza que pretende eliminar?", "Pergunta!", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question); switch (result) { case System.Windows.Forms.DialogResult.Yes: bool done = tabela.Delete_Tabela(id_tab); string warning = ""; if (done == true) { warning = "Removida com sucesso!"; } else { warning = "Falha ao remover!"; } System.Windows.Forms.MessageBox.Show(warning, "Aviso!", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning); break; default: break; } ActualizaDataGrid(); } else { } }
/// <summary> /// Elimina uma Tabela da Base de Dados. /// </summary> /// <param name="Id">Recebe o id da Tabela que se pretende eliminar.</param> /// <returns>Retorna um bool True=Removida com sucesso, False=Não conseguiu remover a Projetos.</returns> /// <remarks> /// Recebe o id da Tabela que se pretende eliminar, pesquisa na Base de Dados por essa Tabela, ///e caso a encontre, é eliminada. Retorna true se tiver sucesso ao remover a Tabela e retorna false caso contrário. /// </remarks> public bool Delete_Tabela(string Id) { bool done = false; try { BDKnowLedge bd = new BDKnowLedge(); Tabelas tabela = bd.Tabelas.Single(u => u.StampTabela == Id); bd.Tabelas.Remove(tabela); bd.SaveChanges(); done = true; } catch { done = false; } return(done); }
// Excluir tabela public void Excluir(Tabelas rs) { try { string qry = ""; qry += "DELETE FROM Tabelas "; qry += "WHERE idtabela = " + rs.idtabela.value; Connection session = new Connection(); Query query = session.CreateQuery(qry); query.ExecuteUpdate(); // Auditoria Audit.Check("Tabelas", "D", rs.idtabela.value, rs); session.Close(); } catch (Exception erro) { throw erro; } }
private void Row_DoubleClick(object sender, RoutedEventArgs e) { Tipos type = null; Subtipos subtype = null; try { object selectedItem = ((DataGrid)data1).SelectedItem; Type type2 = selectedItem.GetType(); id_tab = (string)type2.GetProperty("STAMPTABELA").GetValue(selectedItem, null); Tabelas tabelas = tabela.getTabelaDetails(id_tab); if (tabelas.StampTabela.Trim() != "") { textEditor.Text = tabelas.QueryString; if (tabelas.Descricao != null && tabelas.Descricao.Trim() != "") { DescricaoTabela.Text = tabelas.Descricao; } if (tabelas.StampTabela.Trim() != "") { id_tip = tabelas.StampTipo; type = tipo.getTipoDetails(tabelas.StampTipo); AutoComplete1.Text = type.Nome; } if (tabelas.StampSubtipo != "") { subtype = subtipo.getSubtipoDetails(tabelas.StampSubtipo); combo_subtipos.SelectedValue = subtype.Nome; } } } catch { } }
// Alterar tabela public void Alterar(Tabelas rs, Tabelas temp) { try { string qry = ""; qry += "UPDATE Tabelas "; qry += "SET txtabela = '" + rs.txtabela.value + "', flauditoria = " + rs.flauditoria.value + ", idcodigoidioma = " + rs.idcodigoidioma.value + " "; qry += "WHERE idtabela = " + rs.idtabela.value; Connection session = new Connection(); Query query = session.CreateQuery(qry); query.ExecuteUpdate(); // Auditoria Audit.Check("Tabelas", "U", rs.idtabela.value, rs, temp); session.Close(); } catch (Exception erro) { throw erro; } }
private void UpdateUI2(int i) { textEditor.Text = ""; textEditor.Text = "Projeto: " + AutoComplete1.Text + "\n"; textEditor.Text = textEditor.Text + "Base de Dados: " + teste + "\n\n"; textEditor.Text = textEditor.Text + "Tipo: " + AutoCompleteTipos.Text + "\n\n"; bool done = false; foreach (CheckBox c in ch) { if (c.IsChecked == true) { try { string IDSubtype = subtipo.getIDFromNomeSubtipos(c.Content.ToString(), idType); Tabelas tab1 = tabelas.TabelasDadoOTipoAndSubtipo(idType, IDSubtype); DataTable dt = importarDados.ObtainDados(tab1.QueryString); string st = "", uHora = ""; DateTime usrData = DateTime.Now; List <string> ls = new List <string>(); int inserts = 0, updates = 0; foreach (DataRow dr in dt.Rows) { ls.Clear(); if (dt.Columns.Contains("stamp")) { st = dr["stamp"].ToString(); ls.Add(dr["stamp"].ToString()); } ls.Add(idPro.ToString()); ls.Add(IDSubtype.ToString()); ls.Add(idType.ToString()); if (dt.Columns.Contains("descricao")) { ls.Add(dr["descricao"].ToString()); } else { ls.Add(" "); } if (dt.Columns.Contains("codigo")) { ls.Add(dr["codigo"].ToString()); } else { ls.Add(" "); } if (dt.Columns.Contains("metadados")) { ls.Add(dr["metadados"].ToString()); } else { ls.Add(" "); } if (dt.Columns.Contains("ecra")) { ls.Add(dr["ecra"].ToString()); } else { ls.Add(" "); } if (dt.Columns.Contains("mensagem")) { ls.Add(dr["mensagem"].ToString()); } else { ls.Add(" "); } if (dt.Columns.Contains("teclas")) { ls.Add(dr["teclas"].ToString()); } else { ls.Add(" "); } if (dt.Columns.Contains("tabela")) { ls.Add(dr["tabela"].ToString()); } else { ls.Add(" "); } ls.Add("0"); ls.Add("1"); if (dt.Columns.Contains("ousrdata")) { ls.Add(dr["ousrdata"].ToString()); } else { ls.Add(" "); } if (dt.Columns.Contains("ousrhora")) { ls.Add(dr["ousrhora"].ToString()); } else { ls.Add(" "); } ls.Add("1"); if (dt.Columns.Contains("usrdata")) { usrData = Convert.ToDateTime(dr["usrdata"].ToString()); ls.Add(dr["usrdata"].ToString()); } else { ls.Add(" "); } if (dt.Columns.Contains("usrhora")) { uHora = dr["usrhora"].ToString(); ls.Add(dr["usrhora"].ToString()); } else { ls.Add(" "); } string existe = ""; int stampExiste = -1; DataTable dtConhecimento = conhecimento.DadosImport(idPro, idType, IDSubtype); if (dtConhecimento.Rows.Count > 0) { string formatted = usrData.ToString("dd/M/yyyy"); DateTime dateTime = Convert.ToDateTime(formatted + " " + uHora); var results = (from myRow in dtConhecimento.AsEnumerable() where myRow.Field <string>("StampConhecimento") == st && (Convert.ToDateTime(myRow.Field <string>("data")) < dateTime) select new { IDCon = myRow.Field <string>("StampConhecimento") }.IDCon).FirstOrDefault(); var results2 = (from myRow in dtConhecimento.AsEnumerable() where myRow.Field <string>("StampConhecimento") == st select new { IDCon = myRow.Field <string>("StampConhecimento") }.IDCon).FirstOrDefault(); try { existe = results.ToString(); } catch { existe = ""; } try { stampExiste = Convert.ToInt32(results2.ToString()); } catch { stampExiste = -1; } } done = false; if (existe.Trim() != "") { done = conhecimento.UpdateConhecimento(existe, ls); if (done == true) { updates++; } } else if (stampExiste < 1) { done = conhecimento.InsertConhecimento(ls); if (done == true) { inserts++; } } } textEditor.Text = textEditor.Text + "Subtipo: " + c.Content.ToString() + "\n"; textEditor.Text = textEditor.Text + "Importados/as: " + inserts + "\n"; textEditor.Text = textEditor.Text + "Actualizados/as: " + updates + "\n\n"; } catch { } } } }
/// <summary> /// Faz o update aos dados de uma determinada Tabela. /// </summary> /// <param name="Id">Recebe o id da Tabela que se pretende fazer o update.</param> /// <param name="ls">Recebe uma List com os dados que se pretende introduzir na Base de Dados.</param> /// <remarks> /// Recebe um id da Tabela que se pretende actualizar e os respectivos dados, /// obtém a Tabela, de seguida percorre a List e faz um update à Tabela do id recebido. /// </remarks> public bool UpdateTabela(string Id, List <string> ls) { BDKnowLedge bd = new BDKnowLedge(); bool done = true; int i = 0, nr = 0; Classes.DataControl dataControl = new Classes.DataControl(); DateTime dt = dataControl.GeraDataHora(); try { Tabelas tabela = bd.Tabelas.Single(u => u.StampTabela == Id); foreach (string res in ls) { switch (i) { //case 0: // tabela.StampTabela = res; // break; case 1: tabela.StampTipo = res; break; case 2: tabela.StampSubtipo = res; break; case 3: tabela.Descricao = res; break; case 4: tabela.QueryString = res; break; case 5: tabela.Ousrinis = tabela.Ousrinis; break; case 6: tabela.Ousrdata = tabela.Ousrdata; break; case 7: tabela.Ousrhora = tabela.Ousrhora; break; case 8: tabela.Usrinis = Global.idUser; break; case 9: tabela.Usrdata = dt; break; case 10: tabela.Usrhora = dataControl.GeraHora(dt); break; } i++; } bd.SaveChanges(); } catch { done = false; } return(done); }
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"); } }
// Listagem public (List <Tabelas>, WidgetsListConfig) ListarWidget(FormCollection form = null) { try { List <Tabelas> list = new List <Tabelas>(); WidgetsListConfig control = new WidgetsListConfig(); string filter = ""; // Parametros de pesquisa int page = 1; int registers = 10; string order = "txtabela"; string direction = "asc"; // Filtro de resultados if (form != null) { if (form.AllKeys.Contains("filter_txtabela")) { string filter_txtabela = Utils.ClearText(form["filter_txtabela"], 50); if (filter_txtabela.Length > 0) { filter += "AND txtabela LIKE '%" + filter_txtabela.Replace(" ", "%") + "%' "; } } if (form.AllKeys.Contains("widget_temp_page")) { page = Convert.ToInt32(form["widget_temp_page"]); } if (form.AllKeys.Contains("widget_temp_registers")) { registers = Convert.ToInt32(form["widget_temp_registers"]); } if (form.AllKeys.Contains("widget_temp_order")) { order = form["widget_temp_order"]; } if (form.AllKeys.Contains("widget_temp_direction")) { direction = form["widget_temp_direction"]; } } // Controle de widget control.count = 0; control.registers = registers; control.page = page; control.order = order; control.direction = direction; control.columns = new int[4] { 0, 34, 33, 34 }; control.show = new int[4] { 0, 1, 1, 1 }; control.headers = new string[4] { "199", "144", "141", "139" }; control.orderfields = new string[4] { "idtabela", "txtabela", "flauditoria", "idcodigoidioma" }; control.fields = new string[4] { "idtabela", "txtabela", "flauditoria", "idcodigoidioma" }; control.formatFields = new string[4] { "master", "", "boolean", "language" }; // Query string qry = ""; qry += "SELECT COUNT (*) OVER () AS ROW_COUNT, idtabela, txtabela, flauditoria, idcodigoidioma "; qry += "FROM Tabelas "; qry += "WHERE 1=1 " + filter; qry += "ORDER BY " + Utils.Null(order, "txtabela") + " " + direction + " "; qry += "OFFSET " + ((page - 1) * registers) + " ROWS FETCH NEXT " + registers + " ROWS ONLY"; Connection session = new Connection(); Query query = session.CreateQuery(qry); IDataReader reader = query.ExecuteQuery(); while (reader.Read()) { control.count = Convert.ToInt32(reader["ROW_COUNT"]); Tabelas temp = new Tabelas(); temp.idtabela.value = Convert.ToInt32(reader["idtabela"]); temp.txtabela.value = Convert.ToString(reader["txtabela"]); temp.flauditoria.value = Convert.ToInt32(reader["flauditoria"]); temp.idcodigoidioma.value = Convert.ToInt32(reader["idcodigoidioma"]); list.Add(temp); } reader.Close(); session.Close(); return(list, control); } catch (Exception error) { throw error; } }
/// <summary> /// Insere uma Tabela na Base de Dados. /// </summary> /// <param name="ls">Recebe os dados da Tabela que se pretende introduzir na Base de Dados.</param> /// <remarks> /// Recebe por parâmetro uma List com os dados da Tabela que se pretende adicionar à Base de Dados, de seguida essa /// List é percorrida e cada um desses parâmetros adicionados à Base de Dados. /// </remarks> public bool InsertTabela(List <string> ls) { BDKnowLedge bd = new BDKnowLedge(); Tabelas tabela = new Tabelas(); bool done = true; Classes.DataControl dataControl = new Classes.DataControl(); DateTime dt = dataControl.GeraDataHora(); int i = 0, nr = 0; try { foreach (string res in ls) { switch (i) { case 0: if (res.Trim() == "") { tabela.StampTabela = dataControl.GenerateStamp(); } else { tabela.StampTabela = res; } break; case 1: tabela.StampTipo = res; break; case 2: tabela.StampSubtipo = res; break; case 3: tabela.Descricao = res; break; case 4: tabela.QueryString = res; break; case 5: tabela.Ousrinis = Global.idUser; break; case 6: tabela.Ousrdata = dt; break; case 7: tabela.Ousrhora = dataControl.GeraHora(dt); break; case 8: tabela.Usrinis = Global.idUser; break; case 9: tabela.Usrdata = dt; break; case 10: tabela.Usrhora = dataControl.GeraHora(dt); break; } i++; } bd.Tabelas.Add(tabela); bd.SaveChanges(); } catch { done = false; } return(done); }