I'm developing some tool for a client, and they don't want to use LINQ to SQL, they also don't want to use WPF but I'm using it, they are afraid to new coding or something... But i can't with database, because they don't know anything about LINQ... so they gave me this annoying class (http://pastebin.com/VUzvN44i too long for paste here, sorry) which is "ok" when retrieving row by row...
But I have the following function, which is fully functional with linq to sql, but I'm lost with this class they gave me... So if someone can give me some advice on how to do it without modify the class it will be very helpful. Thanks.
private void GenerarFichero_Click(object sender, RoutedEventArgs e)
{
string valEmisora = "02827003";
string codigoCabecera;
if (DateTime.Today.Day > 7)
codigoCabecera = "AE570200";
else
codigoCabecera = "AE570100";
DataBaseDataContext dc = new DataBaseDataContext();
using (StreamWriter sw = new StreamWriter(codigoCabecera.Remove(6, 2)))
{
sw.WriteLine("775701 " + DateTime.Now.ToString("yy") + DateTime.Now.Month.ToString("d2") + DateTime.Now.AddDays(1).Day.ToString("d2") + DateTime.Now.Hour.ToString("d2") + DateTime.Now.Minute.ToString("d2") + "008910 00" + txtBanco.Text + codigoCabecera + txtBanco.Text + "");
sw.WriteLine("0170 " + valEmisora + " " + this.txtBanco.Text + " 10" + DateTime.Now.ToString("MM") + DateTime.Now.ToString("yy"));
var OutputQuery =
from o in dc.Seguros
group o by o.emisora;
List<int> TotalRegistros = new List<int>();
List<int> TotalSumas = new List<int>();
foreach (var grupo in OutputQuery)
{
sw.WriteLine("0270 " + valEmisora + grupo.Key + " " + this.txtBanco.Text + " 10" + DateTime.Now.ToString("MM") + DateTime.Now.ToString("yy"));
List<int> Suma = new List<int>();
foreach (var data in grupo)
{
Suma.Add(Convert.ToInt32(data.importe + data.importe_dec));
sw.WriteLine("6070 " + valEmisora + data.emisora + "1" + data.banco + data.sucursal + data.fecha + data.importe + data.importe_dec + data.identificacion + " " + data.referencia);
}
TotalRegistros.Add((grupo.Count() + 2));
TotalSumas.Add(Suma.Sum());
sw.WriteLine("8070 " + valEmisora + grupo.Key + " " + (grupo.Count() + 2).ToString().PadLeft(6, '0') + " " + Suma.Sum().ToString().PadLeft(12, '0'));
}
sw.WriteLine("9070 " + valEmisora + " " + (TotalRegistros.Sum() + 2).ToString().PadLeft(6, '0') + " " + TotalSumas.Sum().ToString().PadLeft(12, '0'));
this.txtTotal.Text = TotalSumas.Sum().ToString();
}
MessageBox.Show("El fichero ha sido guardado, ya no se puede editar");
}