private void btnImportar_Click(object sender, EventArgs e) { string CaminhoCompleto = Path.Combine(Application.StartupPath, Globais.ARQ_RANKING); if (File.Exists(CaminhoCompleto)) { Arquivo arquivo = new Arquivo(); dataGridViewRanking.DataSource = arquivo.Abrir(Application.StartupPath, Globais.ARQ_RANKING); dataGridViewRanking.RowsDefaultCellStyle.BackColor = Color.Gray; dataGridViewRanking.AlternatingRowsDefaultCellStyle.BackColor = Color.Beige; dataGridViewRanking.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dataGridViewRanking.DefaultCellStyle.Font = new Font("Arial", 12); //dataGridViewRanking.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None; //dataGridViewRanking.AllowUserToOrderColumns = true; //dataGridViewRanking.AllowUserToResizeColumns = true; dataGridViewRanking.Sort(dataGridViewRanking.Columns["Questoes"], ListSortDirection.Descending); } else { if (MessageBox.Show("O arquivo de ranking não foi encontrado em " + CaminhoCompleto, "Arquivo não existe", MessageBoxButtons.OK, MessageBoxIcon.Warning) == DialogResult.OK) { this.Dispose(); } } }
public static void Encode(string arquivo) { LZWEncoder encoder = new LZWEncoder(); string conteudo = Arquivo.Abrir(arquivo); Console.WriteLine("Iniciada a compressão"); DateTime dataInicial = DateTime.Now; //Codificação LZW string lzwEncoded = encoder.Encode(conteudo); HuffmanTree huffman = new HuffmanTree(); //Criação da árvore huffman huffman.Build(lzwEncoded); //Codificação huffman var huffmanEncoded = huffman.Encode(lzwEncoded); DateTime dataFinal = DateTime.Now; string tempoDecorrido = (dataFinal - dataInicial).TotalSeconds.ToString("N2"); //Contabiliza apenas os tempos para compressão. Igora tempo de IO Console.WriteLine($"Arquivo comprimido em {tempoDecorrido} segundos"); byte[] ret = new byte[(huffmanEncoded.Length - 1) / 8 + 1]; huffmanEncoded.CopyTo(ret, 0); //Gravando arquivo comprimido Arquivo.Gravar(ret, $"{arquivo.Split('.')[0]}.scps"); }
public void Abrir_AbrindoArquivo_ArquivoContemTextoEsperado() { var teste = CriarArquivo(); var abrindo = new Arquivo(); abrindo.Abrir(teste.DiretorioCompleto, teste.Nome); Assert.AreEqual(teste.Texto, abrindo.Texto); }
private void Abrir(object sender, RoutedEventArgs e) { if (!Confirmação()) { OpenFileDialog file = new OpenFileDialog() { Filter = "Arquivos de texto|*.txt", Title = "Abrir arquivo" }; file.ShowDialog(); ArqAberto.Abrir(file.FileName, file.SafeFileName); Titulo = ArqAberto.Nome; txtTexto.Text = ArqAberto.Texto; } }
public void ExibirGraficoBarras() { int[] xJogadores = new int[3]; // { 1, 2, 3 }; double[] yPontuacao = new double[3]; // { 70, 100, 50 }; string[] jogadores = new string[3]; //definir o caminho do arquivo string CaminhoCompleto = Path.Combine(Application.StartupPath, Globais.ARQ_RANKING); //verificar se o arquivo existe if (File.Exists(CaminhoCompleto)) { //ler arquivo de ranking Arquivo arquivo = new Arquivo(); DataTable dataTable = arquivo.Abrir(Application.StartupPath, Globais.ARQ_RANKING); //ordenar pela pontuacao (maior para menor) dataTable.DefaultView.Sort = "Pontuacao desc"; dataTable = dataTable.DefaultView.ToTable(); if (dataTable.Rows.Count > 2) { //pegar os 3 primeiros e atribuir aos vetores x e y for (int i = 0; i < 3; i++) { xJogadores[i] = i + 1; yPontuacao[i] = Convert.ToDouble(dataTable.Rows[i]["Pontuacao"]); jogadores[i] = dataTable.Rows[i]["Jogador"].ToString(); } //Gráfico de Barras Vertical //create another area and add it to the chart ChartArea chartArea = new ChartArea("Ranking"); chart1.ChartAreas.Add(chartArea); //Criando a série do eixo xy Series series = new Series(); series.Points.DataBindXY(xJogadores, yPontuacao); //Legend secondLegend = new Legend("Primeiro"); //chart1.Legends.Add("Testeeeee"); //chartArea.Series[0].Legend = "Primeiro"; //chartArea.Series[1].Legend = "Segundo"; //chartArea.Series[2].Legend = "Terceiro"; //Configura o tipo de gráfico, colunas; barras verticais series.ChartType = SeriesChartType.Column; series.ChartArea = "Ranking"; //Add the series to the chart chart1.Series.Add(series); chart1.Visible = true; } else { MessageBox.Show("Tem que haver pelo menos 3 jogadores no arquivo de ranking", "Ranking Insuficiente", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("O arquivo de ranking não foi encontrado em " + CaminhoCompleto, "Arquivo não existe", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }