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

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

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

            return(collection);
        }
示例#2
0
        public DIAGPERTOPEDIDOCollection ReadCollectionByParameter(List <RowsFiltro> RowsFiltro, string FieldOrder)
        {
            FbDataReader dataReader = null;
            DIAGPERTOPEDIDOCollection collection = null;

            string strSqlCommand = String.Empty;

            try
            {
                if (RowsFiltro != null)
                {
                    if (RowsFiltro.Count > 0)
                    {
                        strSqlCommand = "SELECT * FROM DIAGPERTOPEDIDO 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 DIAGPERTOPEDIDO  order by  " + FieldOrder;
                    }
                }
                else
                {
                    strSqlCommand = "SELECT * FROM DIAGPERTOPEDIDO  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;
            }
        }
示例#3
0
        private void FrmRelatPedidoEconomico_Load(object sender, EventArgs e)
        {
            this.MinimizeBox     = false;
            this.FormBorderStyle = FormBorderStyle.FixedDialog;

            EMPRESAProvider   EMPRESAP    = new EMPRESAProvider();
            EMPRESACollection EMPRESAColl = new EMPRESACollection();

            EMPRESAColl = EMPRESAP.ReadCollectionByParameter(null);

            //Logomarca
            CONFISISTEMAProvider CONFISISTEMAP  = new CONFISISTEMAProvider();
            CONFISISTEMAEntity   CONFISISTEMAty = CONFISISTEMAP.Read(1);

            if (CONFISISTEMAty.FLAGLOGORELATORIO == "S")
            {
                if (CONFISISTEMAty.IDARQUIVOBINARIO1 != null)
                {
                    ARQUIVOBINARIOProvider   ARQUIVOBINARIOP    = new ARQUIVOBINARIOProvider();
                    ARQUIVOBINARIOCollection ARQUIVOBINARIOColl = new ARQUIVOBINARIOCollection();
                    RowRelatorio.Clear();
                    RowRelatorio.Add(new RowsFiltro("IDARQUIVOBINARIO", "System.Int32", "=", CONFISISTEMAty.IDARQUIVOBINARIO1.ToString()));
                    ARQUIVOBINARIOColl = ARQUIVOBINARIOP.ReadCollectionByParameter(RowRelatorio);
                    this.ARQUIVOBINARIOCollectionBindingSource.DataSource = ARQUIVOBINARIOColl;
                }
            }

            //Dados do Cliente
            RowRelatorio.Clear();
            RowRelatorio.Add(new RowsFiltro("IDCLIENTE", "System.Int32", "=", idcliente.ToString()));
            LIS_CLIENTEProvider LIS_CLIENTEP = new LIS_CLIENTEProvider();

            LIS_CLIENTEColl = LIS_CLIENTEP.ReadCollectionByParameter(RowRelatorio);
            string cpfcnpjPar = (LIS_CLIENTEColl[0].CNPJ == "  .   .   /    -" || LIS_CLIENTEColl[0].CNPJ == string.Empty) ? LIS_CLIENTEColl[0].CPF : LIS_CLIENTEColl[0].CNPJ;

            //Dados do Pedido Otica
            RowRelatorio.Clear();
            RowRelatorio.Add(new RowsFiltro("IDPEDIDOOTICA", "System.Int32", "=", IDPEDIDOOTICA.ToString()));
            LIS_PEDIDOOTICACollection LIS_PEDIDOOTICAColl = new LIS_PEDIDOOTICACollection();
            LIS_PEDIDOOTICAProvider   LIS_PEDIDOOTICAP    = new LIS_PEDIDOOTICAProvider();

            LIS_PEDIDOOTICAColl = LIS_PEDIDOOTICAP.ReadCollectionByParameter(RowRelatorio);

            //Diagnóstico  Perto
            RowRelatorio.Clear();
            RowRelatorio.Add(new RowsFiltro("IDPEDIDO", "System.Int32", "=", IDPEDIDOOTICA.ToString()));
            DIAGPERTOPEDIDOProvider   DIAGPERTOPEDIDOP    = new DIAGPERTOPEDIDOProvider();
            DIAGPERTOPEDIDOCollection DIAGPERTOPEDIDOColl = new DIAGPERTOPEDIDOCollection();

            DIAGPERTOPEDIDOColl = DIAGPERTOPEDIDOP.ReadCollectionByParameter(RowRelatorio);

            //Diagnóstico  Medio
            RowRelatorio.Clear();
            RowRelatorio.Add(new RowsFiltro("IDPEDIDO", "System.Int32", "=", IDPEDIDOOTICA.ToString()));
            DIAGMEDIOPEDIDOProvider   DIAGMEDIOPEDIDOP    = new DIAGMEDIOPEDIDOProvider();
            DIAGMEDIOPEDIDOCollection DIAGMEDIOPEDIDOColl = new DIAGMEDIOPEDIDOCollection();

            DIAGMEDIOPEDIDOColl = DIAGMEDIOPEDIDOP.ReadCollectionByParameter(RowRelatorio);

            //Diagnóstico  Longe
            RowRelatorio.Clear();
            RowRelatorio.Add(new RowsFiltro("IDPEDIDOOTICA", "System.Int32", "=", IDPEDIDOOTICA.ToString()));
            DIAGLONGEPEDIDOProvider   DIAGLONGEPEDIDOP    = new DIAGLONGEPEDIDOProvider();
            DIAGLONGEPEDIDOCollection DIAGLONGEPEDIDOColl = new DIAGLONGEPEDIDOCollection();

            DIAGLONGEPEDIDOColl = DIAGLONGEPEDIDOP.ReadCollectionByParameter(RowRelatorio);

            if (LIS_PRODUTOSPEDOTICAColl.Count > 0)
            {
                listaproduto = "true";
            }

            if (LIS_SERVICOPEDOTICAColl.Count > 0)
            {
                listaservico = "true";
            }

            //setando os parametro
            Microsoft.Reporting.WinForms.ReportParameter[] p = new Microsoft.Reporting.WinForms.ReportParameter[7];
            p[0] = new Microsoft.Reporting.WinForms.ReportParameter("CPFCNPJ", cpfcnpjPar);
            p[1] = new Microsoft.Reporting.WinForms.ReportParameter("listaproduto", listaproduto);
            p[2] = new Microsoft.Reporting.WinForms.ReportParameter("listaservico", listaservico);
            p[3] = new Microsoft.Reporting.WinForms.ReportParameter("NomeLaboratorio", NomeLaboratorio);
            p[4] = new Microsoft.Reporting.WinForms.ReportParameter("ExibirPerto", ExibirPerto);
            p[5] = new Microsoft.Reporting.WinForms.ReportParameter("ExibirMedio", ExibirMedio);
            p[6] = new Microsoft.Reporting.WinForms.ReportParameter("ExibirLonge", ExibirLonge);
            reportViewer1.LocalReport.SetParameters(p);

            EMPRESACollectionBindingSource.DataSource              = EMPRESAColl;
            LIS_CLIENTECollectionBindingSource.DataSource          = LIS_CLIENTEColl;
            LIS_PEDIDOOTICACollectionBindingSource.DataSource      = LIS_PEDIDOOTICAColl;
            LIS_SERVICOPEDOTICACollectionBindingSource.DataSource  = LIS_SERVICOPEDOTICAColl;
            LIS_PRODUTOSPEDOTICACollectionBindingSource.DataSource = LIS_PRODUTOSPEDOTICAColl;
            DIAGPERTOPEDIDOCollectionBindingSource.DataSource      = DIAGPERTOPEDIDOColl;
            DIAGMEDIOPEDIDOCollectionBindingSource.DataSource      = DIAGMEDIOPEDIDOColl;
            DIAGLONGEPEDIDOCollectionBindingSource.DataSource      = DIAGLONGEPEDIDOColl;

            this.reportViewer1.SetDisplayMode(DisplayMode.PrintLayout);
            this.reportViewer1.ZoomMode = ZoomMode.Percent;
            this.reportViewer1.RefreshReport();
        }