Advertisement
onzulin

busqueda dentro de los ficheros

Mar 21st, 2013
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 12.09 KB | None | 0 0
  1. private void SearchEarn()
  2.         {
  3.             double balance = 0;
  4.             double earn = 0;
  5.             double spent = 0;
  6.             List<Transacciones> transaccionesListEarn = new List<Transacciones>();
  7.             //List<Transacciones> LTransacciones = new List<Transacciones>();
  8.             IEnumerable<Transacciones> ITransacciones;
  9.             IEnumerable<Transacciones> ITransaccionSecond;
  10.             //SearchUserControl searchUserControl = new SearchUserControl();
  11.             DateTime desde = new DateTime();
  12.             DateTime hasta = new DateTime();
  13.            
  14.            
  15.             if (TextBoxNameEarn.Text.Length == 0 && TextBoxFromEarn.Text.Length == 0 && TextBoxToEarn.Text.Length == 0)
  16.             {
  17.                
  18.                 //mostrar lo que habia en el ListBoxEarn
  19.                 ListBoxEarn.ItemsSource = ListaTransaccionesEarn;
  20.                 earn = ListaTransaccionesEarn.Sum(transacciones => transacciones.amount);
  21.  
  22.                 if (TextBoxTotalSpent.Text == "")
  23.                 {
  24.                     TextBoxTotalSpent.Text = "0";
  25.                     spent = Convert.ToDouble(TextBoxTotalSpent.Text);
  26.                 }
  27.                 else
  28.                 {
  29.                     spent = Convert.ToDouble(TextBoxTotalSpent.Text);
  30.                 }
  31.                 balance = earn - spent;
  32.                 SolidColorBrush mySolidColorBrush = new SolidColorBrush();
  33.                 if (balance >= 0)
  34.                 {
  35.                     // eesto pinta el color en un tono verde
  36.                     mySolidColorBrush.Color = Color.FromArgb(255, 2, 144, 70);
  37.                     TextBoxBalance.Foreground = mySolidColorBrush;
  38.                 }
  39.                 else
  40.                 {
  41.                     mySolidColorBrush.Color = Color.FromArgb(255, 191, 9, 19);
  42.                     TextBoxBalance.Foreground = mySolidColorBrush;
  43.                 }
  44.                 TextBoxBalance.Text = balance.ToString();
  45.                 TextBoxTotalEarn.Text = earn.ToString();
  46.                 TextBoxTotalSpent.Text = spent.ToString();
  47.                 //this.Frame.Navigate(typeof(Archivo));
  48.                 SecondSearch = false;
  49.             }
  50.  
  51.             if (TextBoxNameEarn.Text.Length > 0)
  52.             {
  53.                 if (SecondSearch == false)
  54.                 {
  55.                     ITransacciones = from transaccion in ListaTransaccionesEarn
  56.                                      where transaccion.nombre.Contains(TextBoxNameEarn.Text)
  57.                                      select transaccion;
  58.                     ListBoxEarn.ItemsSource = ITransacciones;
  59.                     earn = ITransacciones.Sum(transacciones => transacciones.amount);
  60.                 }
  61.                 /* aqui en vez de hacer una 2ª busqueda lño que haremos sera que todas las busquedas sucesivas busquen a  
  62.                  * raiz de los objetos que aslgan en la ListBoxEarn.
  63.                  */
  64.                 if (SecondSearch == true)
  65.                 {
  66.                     //cogemos los objetos del listbox y hacemos la busqueda con los objetos que hay en la ListBoxEarn
  67.                     foreach (Transacciones transacciones in ListBoxEarn.Items)
  68.                     {
  69.                         transaccionesListEarn.Add(transacciones);
  70.                     }
  71.                     ITransaccionSecond = from transaccion in transaccionesListEarn
  72.                                          where transaccion.nombre.Contains(TextBoxNameEarn.Text)
  73.                                          select transaccion;
  74.                     ListBoxEarn.ItemsSource = ITransaccionSecond;
  75.                     earn = ITransaccionSecond.Sum(transacciones => transacciones.amount);
  76.                     transaccionesListEarn.Clear();
  77.                 }
  78.  
  79.                 if (TextBoxTotalSpent.Text == "")
  80.                 {
  81.                     TextBoxTotalSpent.Text = "0";
  82.                     spent = Convert.ToDouble(TextBoxTotalSpent.Text);
  83.                 }
  84.                 else
  85.                 {
  86.                     spent = Convert.ToDouble(TextBoxTotalSpent.Text);
  87.                 }
  88.                 balance = earn - spent;
  89.                 SolidColorBrush mySolidColorBrush = new SolidColorBrush();
  90.                 if (balance >= 0)
  91.                 {
  92.                     // eesto pinta el color en un tono verde
  93.                     mySolidColorBrush.Color = Color.FromArgb(255, 2, 144, 70);
  94.                     TextBoxBalance.Foreground = mySolidColorBrush;
  95.                 }
  96.                 else
  97.                 {
  98.                     mySolidColorBrush.Color = Color.FromArgb(255, 191, 9, 19);
  99.                     TextBoxBalance.Foreground = mySolidColorBrush;
  100.                 }
  101.                 TextBoxBalance.Text = balance.ToString();
  102.                 TextBoxTotalEarn.Text = earn.ToString();
  103.                 TextBoxTotalSpent.Text = spent.ToString();
  104.  
  105.                 //aqui vamos a poner un if para si es 2ª busqueda no entre pero si es por ej la 3ª busqueda entre
  106.                 if (SecondSearch == false)
  107.                 {
  108.                     SecondSearch = true;
  109.                 }
  110.                
  111.  
  112.             }
  113.             if (TextBoxFromEarn.Text.Length > 0 && TextBoxToEarn.Text.Length == 0)
  114.             {
  115.                 //esto en terminos de rendimiento no tiene sentido lo pongo pq lo voy a hacer asi para que funcione el programa pero lo voy a cambia
  116.                 try
  117.                 {
  118.                     desde = DateTime.Parse(TextBoxFromEarn.Text);
  119.                     hasta = DateTime.Parse(TextBoxFromEarn.Text);
  120.                 }
  121.                 catch (Exception ex)
  122.                 {
  123.                     MessageDialog msg = new MessageDialog(ex.Message);
  124.                     msg.ShowAsync();
  125.                 }
  126.                 if (SecondSearch == false)
  127.                 {
  128.                     ITransacciones = from transaccion in ListaTransaccionesEarn
  129.                                      let fecha = DateTime.Parse(transaccion.date)
  130.                                      where fecha >= desde && fecha <= hasta
  131.                                      select transaccion;
  132.                     ListBoxEarn.ItemsSource = ITransacciones;
  133.                     earn = ITransacciones.Sum(transacciones => transacciones.amount);
  134.                 }
  135.                 if (SecondSearch == true)
  136.                 {
  137.                     //para asegurarnos de que cogemos los elementos en la 2ª busqueda que hay en el la ListBoxEarm
  138.                     foreach (Transacciones transacciones in ListBoxEarn.Items)
  139.                     {
  140.                         transaccionesListEarn.Add(transacciones);
  141.                     }
  142.                     ITransaccionSecond = from transaccion in transaccionesListEarn
  143.                                          let fecha = DateTime.Parse(transaccion.date)
  144.                                          where fecha >= desde && fecha <= hasta
  145.                                          select transaccion;
  146.                     ListBoxEarn.ItemsSource = ITransaccionSecond;
  147.                     earn = ITransaccionSecond.Sum(transacciones => transacciones.amount);
  148.                     transaccionesListEarn.Clear();
  149.                 }
  150.                 // aqui ya actualizamos el TextBoxTotalEarn
  151.                 TextBoxTotalEarn.Text = Convert.ToString(earn);
  152.                 //logicamnete esto afecta al balance que tenemos con respecto al otro total spent
  153.                 if (TextBoxTotalSpent.Text == "")
  154.                 {
  155.                     TextBoxTotalSpent.Text = "0";
  156.                     spent = Convert.ToDouble(TextBoxTotalSpent.Text);
  157.                 }
  158.                 else
  159.                 {
  160.                     spent = Convert.ToDouble(TextBoxTotalSpent.Text);
  161.                 }
  162.                 balance = earn - spent;
  163.                 SolidColorBrush mySolidColorBrush = new SolidColorBrush();
  164.                 if (balance >= 0)
  165.                 {
  166.                     // eesto pinta el color en un tono verde
  167.                     mySolidColorBrush.Color = Color.FromArgb(255, 2, 144, 70);
  168.                     TextBoxBalance.Foreground = mySolidColorBrush;
  169.                 }
  170.                 else
  171.                 {
  172.                     mySolidColorBrush.Color = Color.FromArgb(255, 191, 9, 19);
  173.                     TextBoxBalance.Foreground = mySolidColorBrush;
  174.                 }
  175.                 TextBoxBalance.Text = balance.ToString();
  176.  
  177.                 //aqui vamos a poner un if para si es 2ª busqueda no entre pero si es por ej la 3ª busqueda entre
  178.                 if (SecondSearch == false)
  179.                 {
  180.                     SecondSearch = true;
  181.                 }
  182.                
  183.                 //pongo a true la propiedad BusquedaEarn
  184.                
  185.  
  186.             }
  187.             if (TextBoxFromEarn.Text.Length > 0 && TextBoxToEarn.Text.Length > 0)
  188.             {
  189.                 try
  190.                 {
  191.                     desde = DateTime.Parse(TextBoxFromEarn.Text);
  192.                     hasta = DateTime.Parse(TextBoxToEarn.Text);
  193.                 }
  194.                 catch (Exception ex)
  195.                 {
  196.                     MessageDialog msg = new MessageDialog(ex.Message);
  197.                     msg.ShowAsync();
  198.                 }
  199.                 if (SecondSearch == false)
  200.                 {
  201.                     ITransacciones = from transaccion in ListaTransaccionesEarn
  202.                                      let fecha = DateTime.Parse(transaccion.date)
  203.                                      where fecha >= desde && fecha <= hasta
  204.                                      select transaccion;
  205.                     ListBoxEarn.ItemsSource = ITransacciones;
  206.                     earn = ITransacciones.Sum(transacciones => transacciones.amount);
  207.                 }
  208.                 if (SecondSearch == true)
  209.                 {
  210.                     //para asegurarnos de que cogemos los elementos en la 2ª busqueda que hay en el la ListBoxEarm
  211.                     foreach (Transacciones transacciones in ListBoxEarn.Items)
  212.                     {
  213.                         transaccionesListEarn.Add(transacciones);
  214.                     }
  215.                     ITransaccionSecond = from transaccion in transaccionesListEarn
  216.                                          let fecha = DateTime.Parse(transaccion.date)
  217.                                          where fecha >= desde && fecha <= hasta
  218.                                          select transaccion;
  219.                     ListBoxEarn.ItemsSource = ITransaccionSecond;
  220.                     earn = ITransaccionSecond.Sum(transacciones => transacciones.amount);
  221.                     transaccionesListEarn.Clear();
  222.                 }
  223.                 // aqui ya actualizamos el TextBoxTotalEarn
  224.                 TextBoxTotalEarn.Text = Convert.ToString(earn);
  225.                 //logicamnete esto afecta al balance que tenemos con respecto al otro total spent
  226.                 if (TextBoxTotalSpent.Text == "")
  227.                 {
  228.                     TextBoxTotalSpent.Text = "0";
  229.                     spent = Convert.ToDouble(TextBoxTotalSpent.Text);
  230.                 }
  231.                 else
  232.                 {
  233.                     spent = Convert.ToDouble(TextBoxTotalSpent.Text);
  234.                 }
  235.                 balance = earn - spent;
  236.                 SolidColorBrush mySolidColorBrush = new SolidColorBrush();
  237.                 if (balance >= 0)
  238.                 {
  239.                     // eesto pinta el color en un tono verde
  240.                     mySolidColorBrush.Color = Color.FromArgb(255, 2, 144, 70);
  241.                     TextBoxBalance.Foreground = mySolidColorBrush;
  242.                 }
  243.                 else
  244.                 {
  245.                     mySolidColorBrush.Color = Color.FromArgb(255, 191, 9, 19);
  246.                     TextBoxBalance.Foreground = mySolidColorBrush;
  247.                 }
  248.                 TextBoxBalance.Text = balance.ToString();
  249.  
  250.                 //aqui vamos a poner un if para si es 2ª busqueda no entre pero si es por ej la 3ª busqueda entre
  251.                 if (SecondSearch == false)
  252.                 {
  253.                     SecondSearch = true;
  254.                 }
  255.                
  256.             }
  257.        
  258.            
  259.         } // final del metodo SearchEarn
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement