예제 #1
0
        private void btnPesquisa_Click(object sender, EventArgs e)
        {
            if (Validacoes())
            {
                try
                {
                    RowRelatorio.Clear();
                    string DataInicial = Util.ConverStringDateSearch(msktDataInicial.Text);
                    string DataFinal   = Util.ConverStringDateSearch(msktDataFinal.Text);

                    if (Convert.ToInt32(cbFuncionario.SelectedValue) > 0)
                    {
                        RowRelatorio.Add(new RowsFiltro("IDFUNCIONARIO", "System.Int32", "=", Convert.ToInt32(cbFuncionario.SelectedValue).ToString()));
                    }

                    RowRelatorio.Add(new RowsFiltro("DTEMISSAO", "System.DateTime", ">=", DataInicial));
                    RowRelatorio.Add(new RowsFiltro("DTEMISSAO", "System.DateTime", "<=", DataFinal));

                    if (Convert.ToInt32(cbStatus.SelectedValue) > 0)
                    {
                        RowRelatorio.Add(new RowsFiltro("IDSTATUS", "System.Int32", "=", Convert.ToInt32(cbStatus.SelectedValue).ToString()));
                    }

                    if (rdOrcamento.Checked)
                    {
                        RowRelatorio.Add(new RowsFiltro("FLAGORCAMENTO", "System.String", "=", "S"));
                    }
                    if (rdVenda.Checked)
                    {
                        RowRelatorio.Add(new RowsFiltro("FLAGORCAMENTO", "System.String", "=", "N"));
                    }

                    LIS_COMISSAOTERCColl = LIS_COMISSAOTERCP.ReadCollectionByParameter(RowRelatorio);

                    //Remove Funcionario Repetido
                    LIS_COMISSAOTERCCollection LIS_COMISSAOTERC2Coll = new LIS_COMISSAOTERCCollection();
                    foreach (LIS_COMISSAOTERCEntity item in LIS_COMISSAOTERCColl)
                    {
                        if (LIS_COMISSAOTERC2Coll.Find(delegate(LIS_COMISSAOTERCEntity item2) { return(item2.IDFUNCIONARIO == item.IDFUNCIONARIO); }) == null)
                        {
                            LIS_COMISSAOTERC2Coll.Add(item);
                        }
                    }

                    LIS_COMISSAOTERCColl = LIS_COMISSAOTERC2Coll;

                    PreencheGrid();
                }
                catch (Exception EX)
                {
                    MessageBox.Show("Erro na pesquisa!");
                    MessageBox.Show("Erro técnico: " + EX.Message);
                }
            }
        }
예제 #2
0
        private static LIS_COMISSAOTERCCollection ExecuteReader(ref LIS_COMISSAOTERCCollection collection, ref FbDataReader dataReader, FbCommand dbCommand)
        {
            using (dataReader = dbCommand.ExecuteReader())
            {
                collection = new LIS_COMISSAOTERCCollection();

                if (dataReader.HasRows)
                {
                    while (dataReader.Read())
                    {
                        collection.Add(FillEntityObject(ref dataReader));
                    }
                }

                if (!(dataReader.IsClosed))
                {
                    dataReader.Close();
                }
                dataReader.Dispose();
            }

            return(collection);
        }
예제 #3
0
        private void ListaComissaoTerceiros(int IDPEDIDO)
        {
            try
            {
                RowRelatorio.Clear();
                RowRelatorio.Add(new RowsFiltro("IDPEDIDO", "System.Int32", "=", IDPEDIDO.ToString()));
                LIS_COMISSAOTERCColl = LIS_COMISSAOTERCP.ReadCollectionByParameter(RowRelatorio);


                lblTotalPesquisa.Text = LIS_COMISSAOTERCColl.Count.ToString();

                //Colocando somatorio no final da lista
                LIS_COMISSAOTERCEntity LIS_COMISSAOTERCTy = new LIS_COMISSAOTERCEntity();
                LIS_COMISSAOTERCTy.VALOR = SumTotalPesquisa("VALOR");
                LIS_COMISSAOTERCColl.Add(LIS_COMISSAOTERCTy);

                DataGriewDados.AutoGenerateColumns = false;
                DataGriewDados.DataSource          = LIS_COMISSAOTERCColl;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro técnico: " + ex.Message);
            }
        }
예제 #4
0
        public LIS_COMISSAOTERCCollection ReadCollectionByParameter(List <RowsFiltro> RowsFiltro, string FieldOrder)
        {
            FbDataReader dataReader               = null;
            string       strSqlCommand            = String.Empty;
            LIS_COMISSAOTERCCollection collection = null;

            try
            {
                if (RowsFiltro != null)
                {
                    if (RowsFiltro.Count > 0)
                    {
                        strSqlCommand = "SELECT * FROM LIS_COMISSAOTERC 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 LIS_COMISSAOTERC  order by  " + FieldOrder;
                    }
                }
                else
                {
                    strSqlCommand = "SELECT * FROM LIS_COMISSAOTERC order by  " + FieldOrder;
                }

                //Verificando a existência de um transação aberta
                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;
            }
        }
예제 #5
0
        public LIS_COMISSAOTERCCollection ReadCollection()
        {
            FbDataReader dataReader = null;

            try
            {
                LIS_COMISSAOTERCCollection collection = null;

                //Verificando a existência de um transação aberta
                if (dbTransaction != null)
                {
                    if (dbCnn.State == ConnectionState.Closed)
                    {
                        dbCnn.Open();
                    }

                    dbCommand             = new FbCommand("SELECT * FROM LIS_COMISSAOTERC", dbCnn);
                    dbCommand.Transaction = ((FbTransaction)(dbTransaction));
                }
                else
                {
                    if (dbCnn == null)
                    {
                        dbCnn = ((FbConnection)GetConnectionDB());
                    }

                    if (dbCnn.State == ConnectionState.Closed)
                    {
                        dbCnn.Open();
                    }

                    dbCommand             = new FbCommand("SELECT * FROM LIS_COMISSAOTERC", dbCnn);
                    dbCommand.Transaction = dbCnn.BeginTransaction(IsolationLevel.ReadCommitted);
                }

                // Tipo do comando de banco Procedure ou SQL
                dbCommand.CommandType = CommandType.Text;

                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;
            }
        }
예제 #6
0
        private void PreencheGrid()
        {
            try
            {
                TotalGeralPedido   = 0;
                TotalGeralComissao = 0;

                CreaterCursor Cr = new CreaterCursor();
                this.Cursor = Cr.CreateCursor(Cr.btmap, 0, 0);

                DataGriewDados.Rows.Clear();
                string TotalComissao = "0";

                foreach (var LIS_COMISSAOTERCTy in LIS_COMISSAOTERCColl)
                {
                    //Topo Nome do funcionario
                    DataGridViewRow rowTop = new DataGridViewRow();
                    rowTop.CreateCells(DataGriewDados, "Funcionário", string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty);
                    rowTop.DefaultCellStyle.Font = new Font("Arial", 8, FontStyle.Bold);
                    DataGriewDados.Rows.Add(rowTop);

                    string          NOMEFunc = LIS_COMISSAOTERCTy.NOMEFUNC;
                    DataGridViewRow rowTop2  = new DataGridViewRow();
                    rowTop2.CreateCells(DataGriewDados, NOMEFunc, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty);
                    rowTop2.DefaultCellStyle.Font = new Font("Arial", 8, FontStyle.Bold);
                    DataGriewDados.Rows.Add(rowTop2);

                    DataGridViewRow row1 = new DataGridViewRow();
                    row1.CreateCells(DataGriewDados, "Pedido   Emissão   Cliente", "Status", "Vl.Pedido", "Vl.Comissão");
                    row1.DefaultCellStyle.Font = new Font("Arial", 8, FontStyle.Bold);
                    DataGriewDados.Rows.Add(row1);

                    //Pedidos do Funcionario
                    RowRelatorio.Clear();
                    string DataInicial = Util.ConverStringDateSearch(msktDataInicial.Text);
                    string DataFinal   = Util.ConverStringDateSearch(msktDataFinal.Text);

                    RowRelatorio.Add(new RowsFiltro("IDFUNCIONARIO", "System.Int32", "=", Convert.ToInt32(LIS_COMISSAOTERCTy.IDFUNCIONARIO).ToString()));

                    if (rdOrcamento.Checked)
                    {
                        RowRelatorio.Add(new RowsFiltro("FLAGORCAMENTO", "System.String", "=", "S"));
                    }
                    if (rdVenda.Checked)
                    {
                        RowRelatorio.Add(new RowsFiltro("FLAGORCAMENTO", "System.String", "=", "N"));
                    }


                    RowRelatorio.Add(new RowsFiltro("DTEMISSAO", "System.DateTime", ">=", DataInicial));
                    RowRelatorio.Add(new RowsFiltro("DTEMISSAO", "System.DateTime", "<=", DataFinal));

                    if (Convert.ToInt32(cbStatus.SelectedValue) > 0)
                    {
                        RowRelatorio.Add(new RowsFiltro("IDSTATUS", "System.Int32", "=", Convert.ToInt32(cbStatus.SelectedValue).ToString()));
                    }

                    LIS_COMISSAOTERCCollection LIS_COMISSAOTERC3Coll = new LIS_COMISSAOTERCCollection();
                    LIS_COMISSAOTERCProvider   LIS_COMISSAOTERCP     = new LIS_COMISSAOTERCProvider();
                    LIS_COMISSAOTERC3Coll = LIS_COMISSAOTERCP.ReadCollectionByParameter(RowRelatorio, "DTEMISSAO");

                    foreach (var LIS_COMISSAOTERC3Ty in LIS_COMISSAOTERC3Coll)
                    {
                        //Dados do Pedido
                        LIS_PEDIDOCollection LIS_PEDIDOColl     = new LIS_PEDIDOCollection();
                        LIS_PEDIDOProvider   LIS_PEDIDOProvider = new LIS_PEDIDOProvider();
                        RowRelatorio.Clear();
                        RowRelatorio.Add(new RowsFiltro("IDPEDIDO", "System.Int32", "=", Convert.ToInt32(LIS_COMISSAOTERC3Ty.IDPEDIDO).ToString()));
                        LIS_PEDIDOColl = LIS_PEDIDOProvider.ReadCollectionByParameter(RowRelatorio);
                        string DataEmissao = Convert.ToDateTime(LIS_PEDIDOColl[0].DTEMISSAO).ToString("dd/MM/yyyy");

                        string TotalPedido = Convert.ToDecimal(LIS_PEDIDOColl[0].TOTALPEDIDO).ToString("n2");
                        TotalComissao = Convert.ToDecimal(LIS_COMISSAOTERC3Ty.VALOR).ToString("n2");

                        DataGridViewRow row2 = new DataGridViewRow();
                        row2.CreateCells(DataGriewDados, LIS_PEDIDOColl[0].IDPEDIDO.ToString().PadLeft(6, '0') + "   " + DataEmissao + " " + LIS_PEDIDOColl[0].NOMECLIENTE, LIS_PEDIDOColl[0].NOMESTATUS, TotalPedido, TotalComissao);
                        row2.DefaultCellStyle.Font = new Font("Arial", 8);
                        DataGriewDados.Rows.Add(row2);
                        TotalGeralComissao += Convert.ToDecimal(TotalComissao);
                    }
                }

                DataGridViewRow rowLinha = new DataGridViewRow();
                rowLinha.CreateCells(DataGriewDados, string.Empty, string.Empty, "TOTAL ", TotalGeralComissao);
                rowLinha.DefaultCellStyle.Font = new Font("Arial", 8, FontStyle.Bold);
                DataGriewDados.Rows.Add(rowLinha);

                this.Cursor = Cursors.Default;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro técnico: " + ex.Message);
            }
        }