Exemplo n.º 1
0
        private void CarregarArquivosDiretorio(string FindAno)
        {
            #region "Buscar Arquivos"

            DirectoryInfo   Dir     = new DirectoryInfo(Caminho.PastaXML);
            List <ListItem> ListMes = new List <ListItem>();
            List <ListItem> ListAno = new List <ListItem>();

            FileInfo[] Files = Dir.GetFiles("*.xml", SearchOption.AllDirectories);

            foreach (FileInfo File in Files)
            {
                string[] strMes = File.Name.Replace(".xml", string.Empty).Split('_');

                #region "Valida Mês"

                ListItem ItemMes = new ListItem();
                ItemMes.Value    = strMes[1];
                ItemMes.ValueAux = strMes[0];
                ItemMes.Text     = Util_BLL.RetornaMes(Convert.ToInt32(ItemMes.Value));

                ListMes.Add(ItemMes);

                //if (ListMes.Count(p => ((ListItem)p).Value == ItemMes.Value) <= 0)
                //{
                //    ListMes.Add(ItemMes);
                //}

                #endregion

                if (string.IsNullOrEmpty(FindAno))
                {
                    #region "Valida Ano"

                    ListItem ItemAno = new ListItem();
                    ItemAno.Value = strMes[0];
                    ItemAno.Text  = strMes[0];

                    if (ListAno.Count(p => ((ListItem)p).Value == ItemAno.Value) <= 0)
                    {
                        ListAno.Add(ItemAno);
                    }

                    #endregion
                }
            }

            #endregion

            #region "Ano"

            if (string.IsNullOrEmpty(FindAno))
            {
                cboAno.DisplayMember = "Text";
                cboAno.ValueMember   = "Value";
                cboAno.DataSource    = ListAno;

                cboAno.SelectedIndexChanged += cboAno_SelectedIndexChanged;

                cboAno.SelectedIndex = cboAno.Items.Count - 1;

                FindAno = cboAno.SelectedValue.ToString();
            }

            #endregion

            #region "Mês"

            cboMes.DisplayMember = "Text";
            cboMes.ValueMember   = "Value";
            cboMes.DataSource    = ListMes.Where(p => ((ListItem)p).ValueAux == FindAno).ToList();

            cboMes.SelectedIndex = cboMes.Items.Count - 1;

            #endregion
        }