private void ExisteNCM(string CODNCM, int IDNCM) { try { RowRelatorio.Clear(); RowRelatorio.Add(new RowsFiltro("CODNCM", "System.String", "=", CODNCM.ToString())); NCMCollection NCMColl_2 = new NCMCollection(); NCMColl_2 = NCMP.ReadCollectionByParameter(RowRelatorio); if (NCMColl_2.Count > 1) { foreach (NCMEntity item in NCMColl_2) { if (item.ALNACIONAL == null) { NCMP.Delete(item.IDNCM); } } } } catch (Exception ex) { MessageBox.Show("Erro ao excluir NCM!"); MessageBox.Show("Erro técnico: " + ex.Message); } }
private void FilterList() { /// referente ao tipo de campo string campo = cbCamposPesquisa.SelectedValue.ToString(); //Necessario passar a coleção vazia para o grid, para pegar o tipo da coluna if (NCMColl.Count == 0) { DataGriewDados.AutoGenerateColumns = false; DataGriewDados.DataSource = NCMColl; } // Retorna o tipo de campo para pesquisa Ex.: String, Integer, Date... string Tipo = DataGriewDados.Columns[cbCamposPesquisa.SelectedValue.ToString()].ValueType.FullName; if (Tipo.Length > 20) { Tipo = Util.GetTypeCell(Tipo);//Retorna o texto resumido do tipo } string Valor = txtCriterioPesquisa.Text; //Verifica se o valor digitado e compativel com // o tipo de pesquisa if (ValidacoesLibrary.ValidaTipoPesquisa(Tipo, Valor)) { if (Tipo == "System.DateTime")//formata data para pesquisa. { Valor = Util.ConverStringDateSearch(txtCriterioPesquisa.Text); } else if (Tipo == "System.Decimal")//formata Numeric para pesquisa. { Valor = Util.ConverStringDecimalSearch(txtCriterioPesquisa.Text); } filtroProfile = new RowsFiltro(campo, Tipo, cbTipoPesquisa.SelectedValue.ToString(), Valor); if (!chkBoxAcumulaPesquisa.Checked)//Acumular pesquisa { Filtro.Clear(); } Filtro.Insert(Filtro.Count, filtroProfile); NCMColl = NCMP.ReadCollectionByParameter(Filtro, "DESCRICAO"); DataGriewDados.AutoGenerateColumns = false; DataGriewDados.DataSource = NCMColl; lblTotalPesquisa.Text = NCMColl.Count.ToString(); } else { MessageBox.Show(ConfigMessage.Default.searchFieldType); errorProvider1.SetError(txtCriterioPesquisa, ConfigMessage.Default.searchFieldType); txtCriterioPesquisa.Focus(); } }
private decimal CalculoTributoAprox(string CODNCM) { decimal rsult = 0; try { RowRelatorio.Clear(); if (CODNCM != string.Empty) { RowRelatorio.Add(new RowsFiltro("CODNCM", "System.String", "=", CODNCM.ToString())); } NCMCollection NCMColl = new NCMCollection(); NCMProvider NCMP = new NCMProvider(); NCMColl = NCMP.ReadCollectionByParameter(RowRelatorio); if (NCMColl.Count > 0) { if (txtQuant.Text.TrimEnd().TrimStart() == string.Empty) { txtQuant.Text = "0,00"; } if (txtValorUnit.Text.TrimEnd().TrimStart() == string.Empty) { txtValorUnit.Text = "0,00"; } decimal TotalProduto = Convert.ToDecimal(txtQuant.Text) * Convert.ToDecimal(txtValorUnit.Text); decimal TributoAprox = (TotalProduto * Convert.ToDecimal(NCMColl[0].ALNACIONAL)) / 100; rsult = TributoAprox; } return(rsult); } catch (Exception ex) { return(rsult); MessageBox.Show("Não foi possível efetuar cálculo de tributos aproximados!"); } }
private Boolean VerificaExisteNCM(string NCM) { Boolean result = false; RowRelatorio.Clear(); RowRelatorio.Add(new RowsFiltro("CODNCM", "System.String", "=", NCM.ToString())); NCMCollection NCMColl_2 = new NCMCollection(); NCMColl_2 = NCMP.ReadCollectionByParameter(RowRelatorio); if (NCMColl_2.Count > 0) { result = true; } return(result); }
private static NCMCollection ExecuteReader(ref NCMCollection collection, ref FbDataReader dataReader, FbCommand dbCommand) { using (dataReader = dbCommand.ExecuteReader()) { collection = new NCMCollection(); if (dataReader.HasRows) { while (dataReader.Read()) { collection.Add(FillEntityObject(ref dataReader)); } } if (!(dataReader.IsClosed)) { dataReader.Close(); } dataReader.Dispose(); } return(collection); }
private void btnPesquisa_Click(object sender, EventArgs e) { CreaterCursor Cr = new CreaterCursor(); this.Cursor = Cr.CreateCursor(Cr.btmap, 0, 0); if (cbTipoPesquisa.Text == "Todos") { Filtro.Clear(); NCMColl = NCMP.ReadCollectionByParameter(Filtro, "DESCRICAO"); DataGriewDados.AutoGenerateColumns = false; DataGriewDados.DataSource = NCMColl; lblTotalPesquisa.Text = NCMColl.Count.ToString(); } else { PesquisaFiltro(); } this.Cursor = Cursors.Default; }
private void PesquisaServico() { try { NCMProvider NCMP = new NCMProvider(); RowsFiltroCollection RowRelatorio = new RowsFiltroCollection(); RowRelatorio.Add(new RowsFiltro("DESCRICAO", "System.String", "like", txtNomePesquisa.Text)); NCMColl = NCMP.ReadCollectionByParameter(RowRelatorio, "DESCRICAO"); DataGriewSearch.AutoGenerateColumns = false; DataGriewSearch.DataSource = NCMColl; txtNomePesquisa.Focus(); } catch (Exception) { MessageBox.Show(ConfigMessage.Default.searchFieldType, ConfigSistema1.Default.NomeEmpresa, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } }
public NCMCollection ReadCollectionByParameter(List <RowsFiltro> RowsFiltro, string FieldOrder) { FbDataReader dataReader = null; NCMCollection collection = null; string strSqlCommand = String.Empty; try { if (RowsFiltro != null) { if (RowsFiltro.Count > 0) { strSqlCommand = "SELECT * FROM NCM WHERE ("; ArrayList _rowsFiltro = new ArrayList(); RowsFiltro.ForEach(delegate(RowsFiltro i) { string[] item = { i.Condicao.ToString(), i.Campo.ToString(), i.Tipo.ToString(), i.Operador.ToString(), i.Valor.ToString() }; _rowsFiltro.Add(item); }); int _count = 1; foreach (string[] item in _rowsFiltro) { strSqlCommand += "(" + item[1] + " " + item[3]; switch (item[2]) { case ("System.String"): if (item[3].ToUpper() != "LIKE") { strSqlCommand += " '" + item[4] + "')"; } else { strSqlCommand += " '%" + item[4] + "%')"; } break; case ("System.Int16"): if (item[3].ToUpper() != "LIKE") { strSqlCommand += " " + item[4] + ")"; } else { strSqlCommand += " '%" + item[4] + "%')"; } break; case ("System.Int32"): if (item[3].ToUpper() != "LIKE") { strSqlCommand += " " + item[4] + ")"; } else { strSqlCommand += " '%" + item[4] + "%')"; } break; case ("System.Int64"): if (item[3].ToUpper() != "LIKE") { strSqlCommand += " " + item[4] + ")"; } else { strSqlCommand += " '%" + item[4] + "%')"; } break; case ("System.Double"): if (item[3].ToUpper() != "LIKE") { strSqlCommand += " " + item[4] + ")"; } else { strSqlCommand += " '%" + item[4] + "%')"; } break; case ("System.Decimal"): if (item[3].ToUpper() != "LIKE") { strSqlCommand += " " + item[4] + ")"; } else { strSqlCommand += " '%" + item[4] + "%')"; } break; case ("System.Float"): if (item[3].ToUpper() != "LIKE") { strSqlCommand += " " + item[4] + ")"; } else { strSqlCommand += " '%" + item[4] + "%')"; } break; case ("System.Byte"): strSqlCommand += " " + item[4] + ")"; break; case ("System.SByte"): strSqlCommand += " " + item[4] + ")"; break; case ("System.Char"): if (item[3].ToUpper() != "LIKE") { strSqlCommand += " '" + item[4] + "')"; } else { strSqlCommand += " '%" + item[4] + "%')"; } break; case ("System.DateTime"): if (item[3].ToUpper() != "LIKE") { strSqlCommand += " '" + item[4] + "')"; } else { strSqlCommand += " '%" + item[4] + "%')"; } break; case ("System.Guid"): if (item[3].ToUpper() != "LIKE") { strSqlCommand += " '" + item[4] + "')"; } else { strSqlCommand += " '%" + item[4] + "%')"; } break; case ("System.Boolean"): strSqlCommand += " " + item[4] + ")"; break; } if (_rowsFiltro.Count > 1) { if (_count < _rowsFiltro.Count) { strSqlCommand += " " + item[0] + " "; } _count++; } } strSqlCommand += ") order by " + FieldOrder; } else { strSqlCommand = "SELECT * FROM NCM order by " + FieldOrder; } } else { strSqlCommand = "SELECT * FROM NCM order by " + FieldOrder; } //Verificando a existência de um transação if (dbTransaction != null) { if (dbCnn.State == ConnectionState.Closed) { dbCnn.Open(); } dbCommand = new FbCommand(strSqlCommand, dbCnn); dbCommand.CommandType = CommandType.Text; dbCommand.Transaction = ((FbTransaction)(dbTransaction)); } else { if (dbCnn == null) { dbCnn = new FbConnection(connectionString); } if (dbCnn.State == ConnectionState.Closed) { dbCnn.Open(); } dbCommand = new FbCommand(strSqlCommand, dbCnn); dbCommand.CommandType = CommandType.Text; dbCommand.Transaction = dbCnn.BeginTransaction(IsolationLevel.ReadCommitted); } collection = ExecuteReader(ref collection, ref dataReader, dbCommand); if (dataReader != null) { dataReader.Close(); dataReader.Dispose(); } if (dbTransaction == null) { dbCommand.Transaction.Commit(); dbCnn.Close(); } return(collection); } catch (Exception ex) { // Deleta reader if (dataReader != null) { dataReader.Close(); dataReader.Dispose(); } if (dbTransaction != null) { this.RollbackTransaction(); } else { if (dbCommand.Transaction != null) { dbCommand.Transaction.Rollback(); } if (dbCnn.State == ConnectionState.Open) { dbCnn.Close(); } } throw ex; } }