private void button3_Click(object sender, EventArgs e) { dataGridView1.DataSource = null; dataGridView1.DataSource = DALCadastro.FluxoVendaTudo1(); decimal soma = 0; int cont = 0; if (dataGridView1.Rows.Count > 0) { for (int i = 0; i < dataGridView1.Rows.Count; i++) { string prazo1 = dataGridView1.Rows[i].Cells[2].Value.ToString(); if (prazo1 == "a prazo") { cont++; } if (prazo1 == "não definido") { cont++; } if (prazo1 == "a prazo_parcial") { cont++; } if (prazo1 == "Pagamento Misto") { cont++; } if (cont == 0) { soma += Convert.ToDecimal(dataGridView1.Rows[i].Cells[6].Value); dataGridView1.Rows[i].Cells[6].Style.BackColor = System.Drawing.Color.Cyan; } cont = 0; } textBox3.Text = Convert.ToString(soma); } dataGridView2.DataSource = DALCadastro.ListaAUXVendas(monthCalendar1.SelectionStart.Date.ToShortDateString()); if (dataGridView2.Rows.Count > 0) { for (int i = 0; i < dataGridView2.Rows.Count; i++) { if (dataGridView2.Rows[i].Cells[5].Value.ToString() == "Pagamento Fiado Parcial" || dataGridView2.Rows[i].Cells[5].Value.ToString() == "Pagamento Misto") { soma = soma + Convert.ToDecimal(dataGridView2.Rows[i].Cells[6].Value); dataGridView2.Rows[i].Cells[6].Style.BackColor = System.Drawing.Color.Cyan; } else { if (checkBox1.Checked == true) { if (dataGridView2.Rows[i].Cells[1].Value.ToString() == "Saldo Inicial") { soma = soma + Convert.ToDecimal(dataGridView2.Rows[i].Cells[6].Value); dataGridView2.Rows[i].Cells[6].Style.BackColor = System.Drawing.Color.Cyan; textBox3.Text = Convert.ToString(soma); } else { soma = soma - Convert.ToDecimal(dataGridView2.Rows[i].Cells[6].Value); dataGridView2.Rows[i].Cells[6].Style.BackColor = System.Drawing.Color.Coral; textBox3.Text = Convert.ToString(soma); } } } } } textBox3.Text = Convert.ToString(soma); }