Advertisement
Mushi

Quiz

Jun 4th, 2013
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 30.15 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. using System.Xml.Serialization;
  7. using Windows.Foundation;
  8. using Windows.Foundation.Collections;
  9. using Windows.Storage;
  10. using Windows.Storage.Streams;
  11. using Windows.UI.Popups;
  12. using Windows.UI.Xaml;
  13. using Windows.UI.Xaml.Controls;
  14. using Windows.UI.Xaml.Controls.Primitives;
  15. using Windows.UI.Xaml.Data;
  16. using Windows.UI.Xaml.Input;
  17. using Windows.UI.Xaml.Media;
  18. using Windows.UI.Xaml.Navigation;
  19.  
  20. // The Basic Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234237
  21.  
  22. namespace Win8AppBox
  23. {
  24.     /// <summary>
  25.     /// A basic page that provides characteristics common to most applications.
  26.     /// </summary>
  27.     public class Passando
  28.     {
  29.         public string right   { get; set; }
  30.         public string wrongs  { get; set; }
  31.         public string questao { get; set; }
  32.         public string botao1  { get; set; }
  33.         public string botao2  { get; set; }
  34.         public string botao3  { get; set; }
  35.         public string botao4  { get; set; }
  36.         public string botao5  { get; set; }
  37.         public string res     { get; set; }
  38.     }
  39.  
  40.     public sealed partial class QuizPage : Win8AppBox.Common.LayoutAwarePage
  41.     {
  42.         public static string tipo;
  43.         public int correct;
  44.         public int wrong;
  45.         public int cont;
  46.         public int anwser;
  47.         public int numbQ;
  48.         public string resposta;
  49.         public List<DataBase> list;
  50.         public Passando info = new Passando();
  51.        
  52.         DispatcherTimer Tempo;
  53.         int Contador = 0;
  54.  
  55.         public QuizPage()
  56.         {
  57.             this.InitializeComponent();
  58.             Tempo = new DispatcherTimer();
  59.             Tempo.Interval = TimeSpan.FromSeconds(1);
  60.             Tempo.Tick += Tempo_Tick;
  61.             Tempo.Stop();
  62.         }
  63.  
  64.         void Tempo_Tick(object sender, object e)
  65.         {
  66.  
  67.             if (Contador == 1)
  68.             {
  69.                 Contador = 0;
  70.                 // if (acertou == false)
  71.                 {
  72.                     F_01.Fill = null;
  73.                     F_02.Fill = null;
  74.                     F_03.Fill = null;
  75.                     F_04.Fill = null;
  76.                     F_05.Fill = null;
  77.                     TB_R.Visibility = Visibility.Collapsed;
  78.                 }
  79.                 loadResultados();
  80.                 BT_01.IsEnabled = true;
  81.                 BT_02.IsEnabled = true;
  82.                 BT_03.IsEnabled = true;
  83.                 BT_04.IsEnabled = true;
  84.                 BT_05.IsEnabled = true;
  85.                 //Tempo.Interval = TimeSpan.FromMinutes(2);
  86.                 Tempo.Stop();
  87.             }
  88.            
  89.             Contador++;
  90.         }
  91.  
  92.         /// <summary>
  93.         /// Populates the page with content passed during navigation.  Any saved state is also
  94.         /// provided when recreating a page from a prior session.
  95.         /// </summary>
  96.         /// <param name="navigationParameter">The parameter value passed to
  97.         /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
  98.         /// </param>
  99.         /// <param name="pageState">A dictionary of state preserved by this page during an earlier
  100.         /// session.  This will be null the first time a page is visited.</param>
  101.         protected async override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
  102.         {
  103.             var txt = navigationParameter as string;
  104.             tipo = txt;
  105.             await carregarLista();
  106.             #region
  107.             if (tipo == "lp")
  108.             {
  109.                 ApplicationDataContainer roamingSettings = ApplicationData.Current.RoamingSettings;
  110.                 if (roamingSettings.Values.ContainsKey("lpcertas") && roamingSettings.Values.ContainsKey("lperradas") && roamingSettings.Values.ContainsKey("lpcontador"))
  111.                 {
  112.                     correct = Convert.ToInt32(roamingSettings.Values["lpcertas"].ToString());
  113.                     wrong = Convert.ToInt32(roamingSettings.Values["lperradas"].ToString());
  114.                     cont = Convert.ToInt32(roamingSettings.Values["lpcontador"].ToString());
  115.                     loadProgram();
  116.                 }
  117.                 else
  118.                 {
  119.                     loadProgram();
  120.                 }
  121.             }
  122.             if (tipo == "rl")
  123.             {
  124.                 ApplicationDataContainer roamingSettings = ApplicationData.Current.RoamingSettings;
  125.                 if (roamingSettings.Values.ContainsKey("rlcertas") && roamingSettings.Values.ContainsKey("rlerradas") && roamingSettings.Values.ContainsKey("rlcontador"))
  126.                 {
  127.                     correct = Convert.ToInt32(roamingSettings.Values["rlcertas"].ToString());
  128.                     wrong = Convert.ToInt32(roamingSettings.Values["rlerradas"].ToString());
  129.                     cont = Convert.ToInt32(roamingSettings.Values["rlcontador"].ToString());
  130.                     loadProgram();
  131.                 }
  132.                 else
  133.                 {
  134.                     loadProgram();
  135.                 }
  136.             }
  137.             if (tipo == "mb")
  138.             {
  139.                 ApplicationDataContainer roamingSettings = ApplicationData.Current.RoamingSettings;
  140.                 if (roamingSettings.Values.ContainsKey("mbcertas") && roamingSettings.Values.ContainsKey("mberradas") && roamingSettings.Values.ContainsKey("mbcontador"))
  141.                 {
  142.                     correct = Convert.ToInt32(roamingSettings.Values["mbcertas"].ToString());
  143.                     wrong = Convert.ToInt32(roamingSettings.Values["mberradas"].ToString());
  144.                     cont = Convert.ToInt32(roamingSettings.Values["mbcontador"].ToString());
  145.                     loadProgram();
  146.                 }
  147.                 else
  148.                 {
  149.                     loadProgram();
  150.                 }
  151.             }
  152.             if (tipo == "at")
  153.             {
  154.                 ApplicationDataContainer roamingSettings = ApplicationData.Current.RoamingSettings;
  155.                 if (roamingSettings.Values.ContainsKey("atcertas") && roamingSettings.Values.ContainsKey("aterradas") && roamingSettings.Values.ContainsKey("atcontador"))
  156.                 {
  157.                     correct = Convert.ToInt32(roamingSettings.Values["atcertas"].ToString());
  158.                     wrong = Convert.ToInt32(roamingSettings.Values["aterradas"].ToString());
  159.                     cont = Convert.ToInt32(roamingSettings.Values["atcontador"].ToString());
  160.                     loadProgram();
  161.                 }
  162.                 else
  163.                 {
  164.                     loadProgram();
  165.                 }
  166.             }
  167.             if (tipo == "if")
  168.             {
  169.                 ApplicationDataContainer roamingSettings = ApplicationData.Current.RoamingSettings;
  170.                 if (roamingSettings.Values.ContainsKey("ifcertas") && roamingSettings.Values.ContainsKey("iferradas") && roamingSettings.Values.ContainsKey("ifcontador"))
  171.                 {
  172.                     correct = Convert.ToInt32(roamingSettings.Values["ifcertas"].ToString());
  173.                     wrong = Convert.ToInt32(roamingSettings.Values["iferradas"].ToString());
  174.                     cont = Convert.ToInt32(roamingSettings.Values["ifcontador"].ToString());
  175.                     loadProgram();
  176.                 }
  177.                 else
  178.                 {
  179.                     loadProgram();
  180.                 }
  181.             }
  182.             if (tipo == "lg")
  183.             {
  184.                 ApplicationDataContainer roamingSettings = ApplicationData.Current.RoamingSettings;
  185.                 if (roamingSettings.Values.ContainsKey("lgcertas") && roamingSettings.Values.ContainsKey("lgerradas") && roamingSettings.Values.ContainsKey("lgcontador"))
  186.                 {
  187.                     correct = Convert.ToInt32(roamingSettings.Values["lgcertas"].ToString());
  188.                     wrong = Convert.ToInt32(roamingSettings.Values["lgerradas"].ToString());
  189.                     cont = Convert.ToInt32(roamingSettings.Values["lgcontador"].ToString());
  190.                     loadProgram();
  191.                 }
  192.                 else
  193.                 {
  194.                     loadProgram();
  195.                 }
  196.                 BT_05.Visibility = Visibility.Collapsed;
  197.             }
  198.             #endregion
  199.         }
  200.  
  201.         /// <summary>
  202.         /// Preserves state associated with this page in case the application is suspended or the
  203.         /// page is discarded from the navigation cache.  Values must conform to the serialization
  204.         /// requirements of <see cref="SuspensionManager.SessionState"/>.
  205.         /// </summary>
  206.         /// <param name="pageState">An empty dictionary to be populated with serializable state.</param>
  207.         protected override void SaveState(Dictionary<String, Object> pageState)
  208.         {
  209.         }
  210.  
  211.         public async Task carregarLista()
  212.         {
  213.             //carregando o xml
  214.             #region
  215.             if (tipo == "if")
  216.             {
  217.                 list = await DeserializeFromXMLif();
  218.             }
  219.             if (tipo == "lp")
  220.             {
  221.                 list = await DeserializeFromXMLlp();
  222.             }
  223.             if (tipo == "rl")
  224.             {
  225.                 list = await DeserializeFromXMLrl();
  226.             }
  227.             if (tipo == "mb")
  228.             {
  229.                 list = await DeserializeFromXMLmb();
  230.             }
  231.             if (tipo == "at")
  232.             {
  233.                 list = await DeserializeFromXMLat();
  234.             }
  235.             if (tipo == "lg")
  236.             {
  237.                 list = await DeserializeFromXMLlg();
  238.             }
  239.             #endregion
  240.             numbQ = list.Count();
  241.         }
  242.         private void loadProgram()
  243.         {
  244.             int seed = unchecked(DateTime.Now.Ticks.GetHashCode());
  245.             Random rnd = new Random(seed);
  246.             int nn = rnd.Next(0, 4);
  247.             info.questao = (cont+1) + "- " +  list[cont].questao;
  248.             if (tipo != "lg")
  249.             {
  250.                 #region
  251.                 if (nn == 0)
  252.                 {
  253.                     info.botao1 = "a) " + list[cont].resposta;
  254.                     info.botao2 = "b) " + list[cont].errada1;
  255.                     info.botao3 = "c) " + list[cont].errada2;
  256.                     info.botao4 = "d) " + list[cont].errada3;
  257.                     info.botao5 = "e) " + list[cont].errada4;
  258.                     info.res = "resposta: letra a";
  259.                     anwser = 0;
  260.                 }
  261.                 if (nn == 1)
  262.                 {
  263.                     info.botao1 = "a) " + list[cont].errada1;
  264.                     info.botao2 = "b) " + list[cont].resposta;
  265.                     info.botao3 = "c) " + list[cont].errada2;
  266.                     info.botao4 = "d) " + list[cont].errada3;
  267.                     info.botao5 = "e) " + list[cont].errada4;
  268.                     info.res = "resposta: letra b";
  269.                     anwser = 1;
  270.                 }
  271.                 if (nn == 2)
  272.                 {
  273.                     info.botao1 = "a) " + list[cont].errada1;
  274.                     info.botao2 = "b) " + list[cont].errada2;
  275.                     info.botao3 = "c) " + list[cont].resposta;
  276.                     info.botao4 = "d) " + list[cont].errada3;
  277.                     info.botao5 = "e) " + list[cont].errada4;
  278.                     info.res = "resposta: letra c";
  279.                     anwser = 2;
  280.                 }
  281.                 if (nn == 3)
  282.                 {
  283.                     info.botao1 = "a) " + list[cont].errada1;
  284.                     info.botao2 = "b) " + list[cont].errada2;
  285.                     info.botao3 = "c) " + list[cont].errada3;
  286.                     info.botao4 = "d) " + list[cont].resposta;
  287.                     info.botao5 = "e) " + list[cont].errada4;
  288.                     info.res = "resposta: letra d";
  289.                     anwser = 3;
  290.                 }
  291.                 if (nn == 4)
  292.                 {
  293.                     info.botao1 = "a) " + list[cont].errada1;
  294.                     info.botao2 = "b) " + list[cont].errada2;
  295.                     info.botao3 = "c) " + list[cont].errada4;
  296.                     info.botao5 = "e) " + list[cont].resposta;
  297.                     info.res = "resposta: letra e";
  298.                     anwser = 4;
  299.                 }
  300.                 #endregion
  301.             }
  302.             else
  303.             {
  304.                 #region
  305.                 if (nn == 0)
  306.                 {
  307.                     info.botao1 = "a) " + list[cont].resposta;
  308.                     info.botao2 = "b) " + list[cont].errada1;
  309.                     info.botao3 = "c) " + list[cont].errada2;
  310.                     info.botao4 = "d) " + list[cont].errada3;
  311.                     info.res = "resposta: letra a";
  312.                     anwser = 0;
  313.                 }
  314.                 if (nn == 1)
  315.                 {
  316.                     info.botao1 = "a) " + list[cont].errada1;
  317.                     info.botao2 = "b) " + list[cont].resposta;
  318.                     info.botao3 = "c) " + list[cont].errada2;
  319.                     info.botao4 = "d) " + list[cont].errada3;
  320.                     info.res = "resposta: letra b";
  321.                     anwser = 1;
  322.                 }
  323.                 if (nn == 2)
  324.                 {
  325.                     info.botao1 = "a) " + list[cont].errada1;
  326.                     info.botao2 = "b) " + list[cont].errada2;
  327.                     info.botao3 = "c) " + list[cont].resposta;
  328.                     info.botao4 = "d) " + list[cont].errada3;
  329.                     info.res = "resposta: letra c";
  330.                     anwser = 2;
  331.                 }
  332.                 if (nn == 3)
  333.                 {
  334.                     info.botao1 = "a) " + list[cont].errada1;
  335.                     info.botao2 = "b) " + list[cont].errada2;
  336.                     info.botao3 = "c) " + list[cont].errada3;
  337.                     info.botao4 = "d) " + list[cont].resposta;
  338.                     info.res = "resposta: letra d";
  339.                     anwser = 3;
  340.                 }
  341.                 #endregion
  342.             }
  343.             info.right = correct.ToString();
  344.             info.wrongs = wrong.ToString();
  345.             this.DataContext = info;
  346.             cont++;
  347.         }
  348.        
  349.         //Botões
  350.         private void BT_01_Click(object sender, RoutedEventArgs e)
  351.         {
  352.             if (anwser == 0)
  353.             {
  354.                 correct++;
  355.                 //load();
  356.                 disableButton();
  357.                 Tempo.Start();
  358.             }
  359.             else
  360.             {
  361.                 wrong++;
  362.                 TB_R.Visibility = Visibility.Visible;
  363.                 if (anwser == 1)
  364.                 {
  365.                     F_02.Fill = new SolidColorBrush(Windows.UI.Colors.Gray);
  366.                     disableButton();
  367.                     Tempo.Start();
  368.                 }
  369.                 if (anwser == 2)
  370.                 {
  371.                     F_03.Fill = new SolidColorBrush(Windows.UI.Colors.Gray);
  372.                     disableButton();
  373.                     Tempo.Start();
  374.                 }
  375.                 if (anwser == 3)
  376.                 {
  377.                     F_04.Fill = new SolidColorBrush(Windows.UI.Colors.Gray);
  378.                     disableButton();
  379.                     Tempo.Start();
  380.                 }
  381.                 if (anwser == 4)
  382.                 {
  383.                     F_05.Fill = new SolidColorBrush(Windows.UI.Colors.Gray);
  384.                     disableButton();
  385.                     Tempo.Start();
  386.                 }
  387.             }
  388.             numbQ--;
  389.             salve();
  390.         }
  391.  
  392.         private void BT_02_Click(object sender, RoutedEventArgs e)
  393.         {
  394.             if (anwser == 1)
  395.             {
  396.                 correct++;
  397.                 //load();
  398.                 disableButton();
  399.                 Tempo.Start();
  400.             }
  401.             else
  402.             {
  403.                 wrong++;
  404.                 TB_R.Visibility = Visibility.Visible;
  405.                 if (anwser == 0)
  406.                 {
  407.                     F_01.Fill = new SolidColorBrush(Windows.UI.Colors.Gray);
  408.                     disableButton();
  409.                     Tempo.Start();
  410.                 }
  411.                 if (anwser == 2)
  412.                 {
  413.                     F_03.Fill = new SolidColorBrush(Windows.UI.Colors.Gray);
  414.                     disableButton();
  415.                     Tempo.Start();
  416.                 }
  417.                 if (anwser == 3)
  418.                 {
  419.                     F_04.Fill = new SolidColorBrush(Windows.UI.Colors.Gray);
  420.                     disableButton();
  421.                     Tempo.Start();
  422.                 }
  423.                 if (anwser == 4)
  424.                 {
  425.                     F_05.Fill = new SolidColorBrush(Windows.UI.Colors.Gray);
  426.                     disableButton();
  427.                     Tempo.Start();
  428.                 }
  429.             }
  430.             numbQ--;
  431.             salve();
  432.         }
  433.  
  434.         private void BT_03_Click(object sender, RoutedEventArgs e)
  435.         {
  436.             if (anwser == 2)
  437.             {
  438.                 correct++;
  439.                 //load();
  440.                 disableButton();
  441.                 Tempo.Start();
  442.             }
  443.             else
  444.             {
  445.                 wrong++;
  446.                 TB_R.Visibility = Visibility.Visible;
  447.                 if (anwser == 0)
  448.                 {
  449.                     F_01.Fill = new SolidColorBrush(Windows.UI.Colors.Gray);
  450.                     disableButton();
  451.                     Tempo.Start();
  452.                 }
  453.                 if (anwser == 1)
  454.                 {
  455.                     F_02.Fill = new SolidColorBrush(Windows.UI.Colors.Gray);
  456.                     disableButton();
  457.                     Tempo.Start();
  458.                 }
  459.                 if (anwser == 3)
  460.                 {
  461.                     F_04.Fill = new SolidColorBrush(Windows.UI.Colors.Gray);
  462.                     disableButton();
  463.                     Tempo.Start();
  464.                 }
  465.                 if (anwser == 4)
  466.                 {
  467.                     F_05.Fill = new SolidColorBrush(Windows.UI.Colors.Gray);
  468.                     disableButton();
  469.                     Tempo.Start();
  470.                 }
  471.             }
  472.             numbQ--;
  473.             salve();
  474.         }
  475.  
  476.         private void BT_04_Click(object sender, RoutedEventArgs e)
  477.         {
  478.             if (anwser == 3)
  479.             {
  480.                 correct++;
  481.                 //load();
  482.                 disableButton();
  483.                 Tempo.Start();
  484.             }
  485.             else
  486.             {
  487.                 wrong++;
  488.                 TB_R.Visibility = Visibility.Visible;
  489.                 if (anwser == 0)
  490.                 {
  491.                     F_01.Fill = new SolidColorBrush(Windows.UI.Colors.Gray);
  492.                     disableButton();
  493.                     Tempo.Start();
  494.                 }
  495.                 if (anwser == 1)
  496.                 {
  497.                     F_02.Fill = new SolidColorBrush(Windows.UI.Colors.Gray);
  498.                     disableButton();
  499.                     Tempo.Start();
  500.                 }
  501.                 if (anwser == 2)
  502.                 {
  503.                     F_03.Fill = new SolidColorBrush(Windows.UI.Colors.Gray);
  504.                     disableButton();
  505.                     Tempo.Start();
  506.                 }
  507.                 if (anwser == 4)
  508.                 {
  509.                     F_05.Fill = new SolidColorBrush(Windows.UI.Colors.Gray);
  510.                     disableButton();
  511.                     Tempo.Start();
  512.                 }
  513.             }
  514.             numbQ--;
  515.             salve();
  516.         }
  517.  
  518.         private void BT_05_Click(object sender, RoutedEventArgs e)
  519.         {
  520.             if (anwser == 4)
  521.             {
  522.                 correct++;
  523.                 //load();
  524.                 disableButton();
  525.                 Tempo.Start();
  526.             }
  527.             else
  528.             {
  529.                 wrong++;
  530.                 TB_R.Visibility = Visibility.Visible;
  531.                 if (anwser == 0)
  532.                 {
  533.                     F_01.Fill = new SolidColorBrush(Windows.UI.Colors.Gray);
  534.                     disableButton();
  535.                     Tempo.Start();
  536.                 }
  537.                 if (anwser == 1)
  538.                 {
  539.                     F_02.Fill = new SolidColorBrush(Windows.UI.Colors.Gray);
  540.                     disableButton();
  541.                     Tempo.Start();
  542.                 }
  543.                 if (anwser == 2)
  544.                 {
  545.                     F_03.Fill = new SolidColorBrush(Windows.UI.Colors.Gray);
  546.                     disableButton();
  547.                     Tempo.Start();
  548.                 }
  549.                 if (anwser == 3)
  550.                 {
  551.                     F_04.Fill = new SolidColorBrush(Windows.UI.Colors.Gray);
  552.                     disableButton();
  553.                     Tempo.Start();
  554.                 }
  555.             }
  556.             numbQ--;
  557.             salve();
  558.         }
  559.  
  560.         void loadResultados()
  561.         {
  562.            
  563.            info.right = correct.ToString();
  564.            info.wrongs = wrong.ToString();
  565.            this.DataContext = null;
  566.            if (numbQ == 0)
  567.            {
  568.                cont = 0;
  569.                result();
  570.            }
  571.            loadProgram();
  572.            this.DataContext = info;
  573.         }
  574.  
  575.         private async void result()
  576.         {
  577.             var mensa = new MessageDialog("Você resolveu todas as questões dessa categoria.");
  578.             await mensa.ShowAsync();
  579.             this.Frame.Navigate(typeof(Principal));
  580.             correct = 0;
  581.             wrong = 0;
  582.             cont = 0;
  583.             salve();
  584.         }
  585.  
  586.         public void disableButton()
  587.         {
  588.             BT_01.IsEnabled = false;
  589.             BT_02.IsEnabled = false;
  590.             BT_03.IsEnabled = false;
  591.             BT_04.IsEnabled = false;
  592.             BT_05.IsEnabled = false;
  593.         }
  594.  
  595.         public static async Task<List<DataBase>> DeserializeFromXMLif()
  596.         {
  597.             try
  598.             {
  599.                 StorageFolder folder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Assets");
  600.                 //await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Xml"); FOLDER INSTALLED LOCATION
  601.                 StorageFile file = await folder.GetFileAsync("if.xml");
  602.                 IRandomAccessStream writeStream = await file.OpenAsync(FileAccessMode.Read);
  603.                 Stream stream = Task.Run(() => writeStream.AsStreamForRead()).Result;
  604.                 XmlSerializer serializer = new XmlSerializer(typeof(List<DataBase>));
  605.                 List<DataBase> list = serializer.Deserialize(stream) as List<DataBase>;
  606.                 stream.Dispose();
  607.                 return list;
  608.             }
  609.             catch
  610.             {
  611.                 return new List<DataBase>();
  612.             }
  613.         }
  614.         public static async Task<List<DataBase>> DeserializeFromXMLlp()
  615.         {
  616.             try
  617.             {
  618.                 StorageFolder folder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Assets");
  619.                 //await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Xml"); FOLDER INSTALLED LOCATION
  620.                 StorageFile file = await folder.GetFileAsync("lp.xml");
  621.                 IRandomAccessStream writeStream = await file.OpenAsync(FileAccessMode.Read);
  622.                 Stream stream = Task.Run(() => writeStream.AsStreamForRead()).Result;
  623.                 XmlSerializer serializer = new XmlSerializer(typeof(List<DataBase>));
  624.                 List<DataBase> list = serializer.Deserialize(stream) as List<DataBase>;
  625.                 stream.Dispose();
  626.                 return list;
  627.             }
  628.             catch
  629.             {
  630.                 return new List<DataBase>();
  631.             }
  632.         }
  633.         public static async Task<List<DataBase>> DeserializeFromXMLrl()
  634.         {
  635.             try
  636.             {
  637.                 StorageFolder folder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Assets");
  638.                 //await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Xml"); FOLDER INSTALLED LOCATION
  639.                 StorageFile file = await folder.GetFileAsync("rl.xml");
  640.                 IRandomAccessStream writeStream = await file.OpenAsync(FileAccessMode.Read);
  641.                 Stream stream = Task.Run(() => writeStream.AsStreamForRead()).Result;
  642.                 XmlSerializer serializer = new XmlSerializer(typeof(List<DataBase>));
  643.                 List<DataBase> list = serializer.Deserialize(stream) as List<DataBase>;
  644.                 stream.Dispose();
  645.                 return list;
  646.             }
  647.             catch
  648.             {
  649.                 return new List<DataBase>();
  650.             }
  651.         }
  652.         public static async Task<List<DataBase>> DeserializeFromXMLmb()
  653.         {
  654.             try
  655.             {
  656.                 StorageFolder folder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Assets");
  657.                 //await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Xml"); FOLDER INSTALLED LOCATION
  658.                 StorageFile file = await folder.GetFileAsync("mb.xml");
  659.                 IRandomAccessStream writeStream = await file.OpenAsync(FileAccessMode.Read);
  660.                 Stream stream = Task.Run(() => writeStream.AsStreamForRead()).Result;
  661.                 XmlSerializer serializer = new XmlSerializer(typeof(List<DataBase>));
  662.                 List<DataBase> list = serializer.Deserialize(stream) as List<DataBase>;
  663.                 stream.Dispose();
  664.                 return list;
  665.             }
  666.             catch
  667.             {
  668.                 return new List<DataBase>();
  669.             }
  670.         }
  671.         public static async Task<List<DataBase>> DeserializeFromXMLat()
  672.         {
  673.             try
  674.             {
  675.                 StorageFolder folder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Assets");
  676.                 //await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Xml"); FOLDER INSTALLED LOCATION
  677.                 StorageFile file = await folder.GetFileAsync("at.xml");
  678.                 IRandomAccessStream writeStream = await file.OpenAsync(FileAccessMode.Read);
  679.                 Stream stream = Task.Run(() => writeStream.AsStreamForRead()).Result;
  680.                 XmlSerializer serializer = new XmlSerializer(typeof(List<DataBase>));
  681.                 List<DataBase> list = serializer.Deserialize(stream) as List<DataBase>;
  682.                 stream.Dispose();
  683.                 return list;
  684.             }
  685.             catch
  686.             {
  687.                 return new List<DataBase>();
  688.             }
  689.         }
  690.         public static async Task<List<DataBase>> DeserializeFromXMLlg()
  691.         {
  692.             try
  693.             {
  694.                 StorageFolder folder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Assets");
  695.                 //await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Xml"); FOLDER INSTALLED LOCATION
  696.                 StorageFile file = await folder.GetFileAsync("lg.xml");
  697.                 IRandomAccessStream writeStream = await file.OpenAsync(FileAccessMode.Read);
  698.                 Stream stream = Task.Run(() => writeStream.AsStreamForRead()).Result;
  699.                 XmlSerializer serializer = new XmlSerializer(typeof(List<DataBase>));
  700.                 List<DataBase> list = serializer.Deserialize(stream) as List<DataBase>;
  701.                 stream.Dispose();
  702.                 return list;
  703.             }
  704.             catch
  705.             {
  706.                 return new List<DataBase>();
  707.             }
  708.         }
  709.  
  710.         private void salve()
  711.         {
  712.             /*
  713.              *  O container de dados do aplicativo das configurações de roaming facilita o
  714.              *  armazenamento de dados de forma que sejam acessíveis para o usuário em vários computadores.
  715.              *  Basicamente, os dados são carregados para a nuvem em segundo plano para você. Você também
  716.              *  pode usar o contêiner de dados do aplicativo de configurações locais (LocalSettings), mas você só
  717.              *  deve usá-lo quando desejar armazenar informações específicas do computador.
  718.              */
  719.  
  720.             // Restore values stored in app data.
  721.             if (tipo == "lp")
  722.             {
  723.                 ApplicationDataContainer roamingSettings = ApplicationData.Current.RoamingSettings;
  724.                 roamingSettings.Values["lpcontador"] = cont;
  725.                 roamingSettings.Values["lpcertas"] = correct;
  726.                 roamingSettings.Values["lperradas"] = wrong;
  727.             }
  728.             if (tipo == "rl")
  729.             {
  730.                 ApplicationDataContainer roamingSettings = ApplicationData.Current.RoamingSettings;
  731.                 roamingSettings.Values["rlcontador"] = cont;
  732.                 roamingSettings.Values["rlcertas"] = correct;
  733.                 roamingSettings.Values["rlerradas"] = wrong;
  734.             }
  735.             if (tipo == "mb")
  736.             {
  737.                 ApplicationDataContainer roamingSettings = ApplicationData.Current.RoamingSettings;
  738.                 roamingSettings.Values["mbcontador"] = cont;
  739.                 roamingSettings.Values["mbcertas"] = correct;
  740.                 roamingSettings.Values["mberradas"] = wrong;
  741.             }
  742.             if (tipo == "at")
  743.             {
  744.                 ApplicationDataContainer roamingSettings = ApplicationData.Current.RoamingSettings;
  745.                 roamingSettings.Values["atcontador"] = cont;
  746.                 roamingSettings.Values["atcertas"] = correct;
  747.                 roamingSettings.Values["aterradas"] = wrong;
  748.             }
  749.             if (tipo == "if")
  750.             {
  751.                 ApplicationDataContainer roamingSettings = ApplicationData.Current.RoamingSettings;
  752.                 roamingSettings.Values["ifcontador"] = cont;
  753.                 roamingSettings.Values["ifcertas"] = correct;
  754.                 roamingSettings.Values["iferradas"] = wrong;
  755.             }
  756.             if (tipo == "lg")
  757.             {
  758.                 ApplicationDataContainer roamingSettings = ApplicationData.Current.RoamingSettings;
  759.                 roamingSettings.Values["lgcontador"] = cont;
  760.                 roamingSettings.Values["lgcertas"] = correct;
  761.                 roamingSettings.Values["lgerradas"] = wrong;
  762.             }
  763.         }
  764.     }
  765. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement