Пример #1
0
        public List <CamposBanco> Select()
        {
            string query = "SELECT * FROM " + nomeTabela;

            CamposBanco        camposBanco = null;
            List <CamposBanco> list        = new List <CamposBanco>();

            //Open connection
            if (this.OpenConnection() == true)
            {
                //Create Command
                MySqlCommand cmd = new MySqlCommand(query, connection);
                //Create a data reader and Execute the command
                MySqlDataReader dataReader = cmd.ExecuteReader();

                //Read the data and store them in the list
                while (dataReader.Read())
                {
                    camposBanco = new CamposBanco();
                    if (dataReader["CDDISCRI"] != DBNull.Value)
                    {
                        camposBanco.CODDISCRI = Convert.ToInt32(dataReader["CDDISCRI"]);
                    }
                    if (dataReader["CDEMPRESA"] != DBNull.Value)
                    {
                        camposBanco.CODEMPRESA = Convert.ToInt32(dataReader["CDEMPRESA"]);
                    }
                    if (dataReader["ORDEM"] != DBNull.Value)
                    {
                        camposBanco.ORDEM = Convert.ToInt32(dataReader["ORDEM"]);
                    }
                    if (dataReader["ANO"] != DBNull.Value)
                    {
                        camposBanco.ANO = Convert.ToInt32(dataReader["ANO"]);
                    }
                    if (dataReader["CDMES"] != DBNull.Value)
                    {
                        camposBanco.CDMES = dataReader["CDMES"].ToString();
                    }
                    if (dataReader["QTD"] != DBNull.Value)
                    {
                        camposBanco.QTD = Convert.ToInt32(dataReader["QTD"]);
                    }
                }

                //close Data Reader
                dataReader.Close();

                //close Connection
                this.CloseConnection();

                //return list to be displayed
                return(list);
            }
            else
            {
                return(list);
            }
        }
Пример #2
0
        public static List <CamposBanco> PreencherObjeto(List <CamposBanco> listaCampo, DataTable result, int ano, string mes, bool fazSoma = false, int qtdCampoSoma = 0, bool fazDivisao = false)
        {
            try
            {
                EmpresasRepository empresasRepository = new EmpresasRepository();
                CamposBanco        camposBanco;
                foreach (var item in result.Rows)
                {
                    if (((DataRow)item).ItemArray[1].ToString() != "")
                    {
                        var empresa = empresasRepository.Get(((DataRow)item).ItemArray[1].ToString());
                        if (empresa == null)
                        {
                            continue;
                        }
                        else
                        {
                            camposBanco            = new CamposBanco();
                            camposBanco.CODDISCRI  = int.Parse(((DataRow)item).ItemArray[0].ToString());
                            camposBanco.CODEMPRESA = empresa.Codigo;
                            camposBanco.ORDEM      = int.Parse(((DataRow)item).ItemArray[2].ToString());
                            camposBanco.ANO        = ano;
                            camposBanco.CDMES      = mes;

                            if (fazSoma)
                            {
                                camposBanco.QTD = 0;
                                for (int i = 1; i <= qtdCampoSoma; i++)
                                {
                                    int indexArray = i + 3;
                                    if (double.TryParse(((DataRow)item).ItemArray[indexArray].ToString(), out var v0))
                                    {
                                        camposBanco.QTD += v0;
                                    }
                                }

                                if (fazDivisao)
                                {
                                    //index 3 = F3
                                    if (double.TryParse(((DataRow)item).ItemArray[3].ToString(), out var v1))
                                    {
                                        if (camposBanco.QTD > 0)
                                        {
                                            camposBanco.QTD = (v1 * 1000000) / camposBanco.QTD;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (double.TryParse(((DataRow)item).ItemArray[3].ToString(), out var v1))
                                {
                                    camposBanco.QTD = v1;
                                }
                                else
                                {
                                    camposBanco.QTD = 0;
                                }
                            }


                            listaCampo.Add(camposBanco);
                        }
                    }
                }
                return(listaCampo);
            }
            catch (Exception ex)
            {
                throw;
            }
        }