iT IS MY CODE
BUT ON THIS LINE
sheet.Cells[iRow2, col].Value = dataB[row2 - 4, col - 1];
SAY ME System.IndexOutOfRangeException
I need one table at top and another below
private void SetSheetData(SheetView sheet)
{
oCommand = new OleDbCommand("[dbo].[sp_CortesxTurno]", dbConn);
oCommand.CommandType = CommandType.StoredProcedure;
OleDbParameter oDate1 = oCommand.Parameters.Add("@date1", OleDbType.VarChar);
OleDbParameter oDate2 = oCommand.Parameters.Add("@date2", OleDbType.VarChar);
OleDbParameter sParam1 = oCommand.Parameters.Add("@sParam1", OleDbType.VarChar);
OleDbParameter sParam2 = oCommand.Parameters.Add("@sParam2", OleDbType.VarChar);
OleDbParameter sParam3 = oCommand.Parameters.Add("@sParam3", OleDbType.VarChar);
//OleDbParameter nUsuario = oCommand.Parameters.Add("@pUsuario_Id", OleDbType.VarChar); // usuario
oDate1.Direction = ParameterDirection.Input;
oDate2.Direction = ParameterDirection.Input;
sParam1.Direction = ParameterDirection.Input;
sParam2.Direction = ParameterDirection.Input;
sParam3.Direction = ParameterDirection.Input;
//nUsuario.Direction = ParameterDirection.Input;
oDate1.Value = dateTimePicker1.Text.Replace(" p.m.", "");
oDate2.Value = dateTimePicker2.Text.Replace(" p.m.", "");
sParam3.Value = "";
sParam1.Value = "";
sParam2.Value = "3";
turnosDA = new OleDbDataAdapter();
turnosDA.SelectCommand = oCommand;
DataSet dsTurnos = new DataSet("rtpTurnos");
turnosDA.Fill(dsTurnos);
var rowsTurnos = dsTurnos.Tables[0].Rows.Count;
//List<CortesxTurnos> lsCTurnos = new List<CortesxTurnos>();
object[,] data = new object[rowsTurnos, 7];
int x = 0;
try
{
foreach (DataRow row in dsTurnos.Tables[0].Rows)
{
for (var c = 0; c < 7; c++)
{
data[x, c] = row.ItemArray[c];
}
x++;
}
}
catch (Exception ex)
{ var _ = ex.Message; }
//object[,] data = { { "STATUS", "OPERATING", "BUDGET", "ACTUAL", "DIFFERENCE ($)", "DIFFERENCE (%)" },
// { 0, "Advertising", 600, 545, 0, 0 },
// { 0, "Debts", 125, 150, 0, 0 },
// { 0, "Benefits", 100, 100, 0, 0 },
// { 0, "Supplies", 100, 90, 0, 0 },
// { 0, "Postage", 150, 145, 0, 0 },
// { 0, "Rent or mortgage", 1000, 1000, 0, 0 },
// { 0, "Sales expenses", 500, 630, 0, 0 },
// { 0, "Taxes", 350, 375, 0, 0 },
// { 0, "Utilities", 400, 370, 0, 0 },
// { 0, "Other", 500, 435, 0, 0 },
// { 0, "Total Expenses", 0, 0, 0, 0 }
//};
for (int row = 4; row < rowsTurnos; ++row)
{
for (int col = 1; col < 7; ++col)
{
sheet.Cells[row, col].Value = data[row - 4, col - 1];
}
}
sheet.FpSpread.AllowUserFormulas = true;
TableView table = sheet.AddTable("tblOperatingExpense", 4, 1, rowsTurnos, 6, TableStyle.TableStyleLight1);
//sheet.Cells[15, 3].Formula = "Sum($D$6:$D$15)";
//sheet.Cells[15, 4].Formula = "Sum($E$6:$E$15)";
//sheet.Cells[15, 5].Formula = "Sum($F$6:$F$15)";
/*for (int row = 5; row < 15; ++row)
{
sheet.Cells[row, 1].Formula = "IFERROR([ACTUAL] / [BUDGET], \"\")";
sheet.Cells[row, 5].Formula = "[BUDGET] - [ACTUAL]";
sheet.Cells[row, 6].Formula = "IFERROR([DIFFERENCE ($)] / [BUDGET], \"\")";
}*/
//fpSpread1.ActiveSheet.SetFormula(iRowCount + 1, 8, "SUM(I1:I" + iRowCount + ")");
sheet.Cells[rowsTurnos, 6].Formula = "SUM(G4:G" + rowsTurnos + ")";
//sheet.Cells[15, 6].Formula = "IFERROR($F$16 / $D$16, \"\")";
//2DA Consulta
//---------------------------------------------------------------------
oCommand = new OleDbCommand("[dbo].[sp_CortesxTurno]", dbConn);
oCommand.CommandType = CommandType.StoredProcedure;
OleDbParameter oDate1b = oCommand.Parameters.Add("@date1", OleDbType.VarChar);
OleDbParameter oDate2b = oCommand.Parameters.Add("@date2", OleDbType.VarChar);
OleDbParameter sParam1b = oCommand.Parameters.Add("@sParam1", OleDbType.VarChar);
OleDbParameter sParam2b = oCommand.Parameters.Add("@sParam2", OleDbType.VarChar);
OleDbParameter sParam3b = oCommand.Parameters.Add("@sParam3", OleDbType.VarChar);
//OleDbParameter nUsuario = oCommand.Parameters.Add("@pUsuario_Id", OleDbType.VarChar); // usuario
oDate1b.Direction = ParameterDirection.Input;
oDate2b.Direction = ParameterDirection.Input;
sParam1b.Direction = ParameterDirection.Input;
sParam2b.Direction = ParameterDirection.Input;
sParam3b.Direction = ParameterDirection.Input;
//nUsuario.Direction = ParameterDirection.Input;
oDate1b.Value = dateTimePicker1.Text.Replace(" p.m.", "");
oDate2b.Value = dateTimePicker2.Text.Replace(" p.m.", "");
sParam3b.Value = "";
sParam1b.Value = "";
sParam2b.Value = "2";
turnosDA2 = new OleDbDataAdapter();
turnosDA2.SelectCommand = oCommand;
DataSet dsTurnosb = new DataSet("rtpTurnos");
turnosDA2.Fill(dsTurnosb);
var rowsTurnosB = dsTurnosb.Tables[0].Rows.Count;
//List<CortesxTurnos> lsCTurnos = new List<CortesxTurnos>();
object[,] dataB = new object[rowsTurnosB, 7];
int x2 = 0;
try
{
foreach (DataRow row in dsTurnosb.Tables[0].Rows)
{
for (var c = 0; c < 7; c++)
{
dataB[x2, c] = row.ItemArray[c];
}
x2++;
}
}
catch (Exception ex)
{ var _ = ex.Message; }
//object[,] data = { { "STATUS", "OPERATING", "BUDGET", "ACTUAL", "DIFFERENCE ($)", "DIFFERENCE (%)" },
// { 0, "Advertising", 600, 545, 0, 0 },
// { 0, "Debts", 125, 150, 0, 0 },
// { 0, "Benefits", 100, 100, 0, 0 },
// { 0, "Supplies", 100, 90, 0, 0 },
// { 0, "Postage", 150, 145, 0, 0 },
// { 0, "Rent or mortgage", 1000, 1000, 0, 0 },
// { 0, "Sales expenses", 500, 630, 0, 0 },
// { 0, "Taxes", 350, 375, 0, 0 },
// { 0, "Utilities", 400, 370, 0, 0 },
// { 0, "Other", 500, 435, 0, 0 },
// { 0, "Total Expenses", 0, 0, 0, 0 }
//};
// 4 + el tamaño de el array
int iRow2 = rowsTurnos + 4;
for (int row2= 0; row2 < rowsTurnosB; ++row2)
{
for (int col = 1; col < 7; ++col)
{
sheet.Cells[iRow2, col].Value = dataB[row2 - 4, col - 1];
}
iRow2++;
}
sheet.FpSpread.AllowUserFormulas = true;
TableView table2 = sheet.AddTable("tblOperatingExpense2", rowsTurnos+4, 1, rowsTurnosB, 6, TableStyle.TableStyleLight1);
//sheet.Cells[15, 3].Formula = "Sum($D$6:$D$15)";
//sheet.Cells[15, 4].Formula = "Sum($E$6:$E$15)";
//sheet.Cells[15, 5].Formula = "Sum($F$6:$F$15)";
/*for (int row = 5; row < 15; ++row)
{
sheet.Cells[row, 1].Formula = "IFERROR([ACTUAL] / [BUDGET], \"\")";
sheet.Cells[row, 5].Formula = "[BUDGET] - [ACTUAL]";
sheet.Cells[row, 6].Formula = "IFERROR([DIFFERENCE ($)] / [BUDGET], \"\")";
}*/
//fpSpread1.ActiveSheet.SetFormula(iRowCount + 1, 8, "SUM(I1:I" + iRowCount + ")");
//sheet.Cells[rowsTurnosB, 6].Formula = "SUM(G4:G" + rowsTurnosB + ")";
//-------------
}