Beispiel #1
0
        private static LIS_MANUTESQUIPAMENTOCollection ExecuteReader(ref LIS_MANUTESQUIPAMENTOCollection collection, ref FbDataReader dataReader, FbCommand dbCommand)
        {
            using (dataReader = dbCommand.ExecuteReader())
            {
                collection = new LIS_MANUTESQUIPAMENTOCollection();

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

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

            return(collection);
        }
Beispiel #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            CreaterCursor Cr = new CreaterCursor();

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

            TotalProduto = 0;
            errorProvider1.Clear();
            if (!ValidacoesLibrary.ValidaTipoDateTime(maskedtxtData.Text))
            {
                errorProvider1.SetError(maskedtxtData, ConfigMessage.Default.CampoObrigatorio);
                Util.ExibirMSg(ConfigMessage.Default.CampoObrigatorio2, "Red");
            }
            else if (!ValidacoesLibrary.ValidaTipoDateTime(maskedtxtDataProxManut.Text))
            {
                errorProvider1.SetError(maskedtxtDataProxManut, ConfigMessage.Default.CampoObrigatorio);
                Util.ExibirMSg(ConfigMessage.Default.CampoObrigatorio2, "Red");
            }
            else
            {
                RowRelatorio.Clear();
                if (Convert.ToInt32(cbEquipamento.SelectedValue) > 0)
                {
                    RowRelatorio.Add(new RowsFiltro("IDEQUIPAMENTO", "System.Int32", "=", cbEquipamento.SelectedValue.ToString()));
                }

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


                RowRelatorio.Add(new RowsFiltro("DATAMANUT", "System.DateTime", ">=", Util.ConverStringDateSearch(maskedtxtData.Text)));
                RowRelatorio.Add(new RowsFiltro("DATAMANUT", "System.DateTime", "<=", Util.ConverStringDateSearch(maskedtxtDataProxManut.Text)));

                LIS_MANUTESQUIPAMENTOColl = LIS_MANUTESQUIPAMENTOP.ReadCollectionByParameter(RowRelatorio, "NOMEEQUIPAMENTO, DATAMANUT DESC");

                var booleanGroupQuery =
                    from MANUTESQUIPAMENTO in LIS_MANUTESQUIPAMENTOColl
                    group MANUTESQUIPAMENTO by MANUTESQUIPAMENTO.IDEQUIPAMENTO; //pass or fail!


                //limpa grid
                dataGridView1.Rows.Clear();

                // example of unbound items
                int     CodEqSelec  = 0;
                int     CodEqSelec2 = 0;
                decimal TotalGeral  = 0;

                foreach (var MANUTESQUIPAMENTOGroup in booleanGroupQuery)
                {
                    foreach (var MANUTESQUIPAMENTO in MANUTESQUIPAMENTOGroup)
                    {
                        DataGridViewRow row = new DataGridViewRow();
                        row.CreateCells(dataGridView1, MANUTESQUIPAMENTO.IDMANUTEESQUIPAMENTO.ToString(), Util.LimiterText(MANUTESQUIPAMENTO.NOMEEQUIPAMENTO, 40), Convert.ToDateTime(MANUTESQUIPAMENTO.DATAMANUT).ToString("dd/MM/yyyy"), Util.LimiterText(MANUTESQUIPAMENTO.NOMETIPOMANUTENCAO, 40), Convert.ToDecimal(MANUTESQUIPAMENTO.VALORMANUTENCAO).ToString("n2"));
                        dataGridView1.Rows.Add(row);
                        CodEqSelec  = Convert.ToInt32(MANUTESQUIPAMENTO.IDEQUIPAMENTO);
                        CodEqSelec2 = Convert.ToInt32(MANUTESQUIPAMENTO.IDMANUTEESQUIPAMENTO);

                        //Produtos usados
                        if (chkEmpresContrata.Checked)
                        {
                            DataGridViewRow row_1_3 = new DataGridViewRow();

                            //Empresa Contratada
                            row_1_3.DefaultCellStyle.Font = new Font("Arial", 9, FontStyle.Bold);
                            row_1_3.CreateCells(dataGridView1, "Empresa:", MANUTESQUIPAMENTO.NOMEFORNECEDOR, string.Empty, string.Empty, string.Empty);
                            dataGridView1.Rows.Add(row_1_3);
                        }

                        //Produtos usados
                        if (chkSomaProduto.Checked)
                        {
                            DataGridViewRow row_1_2 = new DataGridViewRow();
                            ListaItensProduto(Convert.ToInt32(MANUTESQUIPAMENTO.IDMANUTEESQUIPAMENTO));

                            //Cabeçalho dados do produto
                            row_1_2.DefaultCellStyle.Font = new Font("Arial", 9, FontStyle.Bold);
                            row_1_2.CreateCells(dataGridView1, string.Empty, "Nome Produto", "Quant. Prod.", string.Empty, "                 Total Produto");
                            dataGridView1.Rows.Add(row_1_2);
                            foreach (var itemProduto in LIS_PRODUTOSMANUTColl)
                            {
                                DataGridViewRow row_1             = new DataGridViewRow();
                                string          ValorTotalProduto = Convert.ToDecimal(itemProduto.VALORTOTAL).ToString("n2");
                                row_1.CreateCells(dataGridView1, string.Empty, itemProduto.NOMEPRODUTO, itemProduto.QUANTIDADE.ToString(), string.Empty, ValorTotalProduto);
                                dataGridView1.Rows.Add(row_1);
                            }
                        }
                    }


                    decimal TotalServico = CalculaTotalItem(CodEqSelec);
                    TotalGeral += TotalServico;

                    if (chkSomaProduto.Checked)
                    {
                        DataGridViewRow row2_1 = new DataGridViewRow();
                        row2_1.CreateCells(dataGridView1, "", "Total de Produtos Usados: " + TotalProduto.ToString("n2"), "", "Total Manut. :", TotalServico.ToString("n2"));
                        row2_1.DefaultCellStyle.Font = new Font("Arial", 8, FontStyle.Bold);
                        dataGridView1.Rows.Add(row2_1);
                        TotalGeral += TotalProduto;
                    }
                    else
                    {
                        DataGridViewRow row2 = new DataGridViewRow();
                        row2.CreateCells(dataGridView1, "", "", "", "Total Manut. : ", TotalServico.ToString("n2"));
                        row2.DefaultCellStyle.Font = new Font("Arial", 8, FontStyle.Bold);
                        dataGridView1.Rows.Add(row2);
                    }
                }

                DataGridViewRow row3 = new DataGridViewRow();
                row3.CreateCells(dataGridView1, "", "", "", "TOTAL GERAL: ", TotalGeral.ToString("n2"));
                row3.DefaultCellStyle.Font = new Font("Arial", 9, FontStyle.Bold);
                dataGridView1.Rows.Add(row3);
            }

            this.Cursor = Cursors.Default;
        }
Beispiel #3
0
        public LIS_MANUTESQUIPAMENTOCollection ReadCollectionByParameter(List <RowsFiltro> RowsFiltro, string FieldOrder)
        {
            FbDataReader dataReader    = null;
            string       strSqlCommand = String.Empty;
            LIS_MANUTESQUIPAMENTOCollection collection = null;

            try
            {
                if (RowsFiltro != null)
                {
                    if (RowsFiltro.Count > 0)
                    {
                        strSqlCommand = "SELECT * FROM LIS_MANUTESQUIPAMENTO 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_MANUTESQUIPAMENTO  order by  " + FieldOrder;
                    }
                }
                else
                {
                    strSqlCommand = "SELECT * FROM LIS_MANUTESQUIPAMENTO 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;
            }
        }
Beispiel #4
0
        public LIS_MANUTESQUIPAMENTOCollection ReadCollection()
        {
            FbDataReader dataReader = null;

            try
            {
                LIS_MANUTESQUIPAMENTOCollection 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_MANUTESQUIPAMENTO", 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_MANUTESQUIPAMENTO", 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;
            }
        }