コード例 #1
0
        private async void KartaDoBazy(StorageFile file)
        {
            KartaPostaci kp = new KartaPostaci();

            using (var stream = await file.OpenStreamForReadAsync())
            {
                string streamContents;
                using (var sr = new StreamReader(stream))
                {
                    streamContents = sr.ReadToEnd();
                }

                var document = XDocument.Parse(streamContents);

                using (XmlReader reader = XmlReader.Create(new StringReader(document.ToString())))
                {
                    reader.ReadToFollowing("Karta");
                    reader.MoveToFirstAttribute();
                    List <object> lista = new List <object>();

                    String[] kolumny = mSQH.getKolumny();
                    for (int i = 0; i < (kolumny.Length); i++)
                    {
                        reader.ReadToFollowing(kolumny[i]);
                        lista.Add(reader.ReadElementContentAsString());
                        // Debug.WriteLine(i+":"+kolumny[i]+"\t"+ lista.Last().ToString());
                    }
                    //reader.ReadToFollowing("imie");
                    //kp.setImie(reader.ReadElementContentAsString());
                    kp.setByList(lista);
                    mSQH.addNewKP(kp);
                }
                //Show(document.ToString());
            }
        }
コード例 #2
0
        private async void eksportuj_Click(object sender, RoutedEventArgs e)
        {
            XmlDocument dom = new XmlDocument();
            XmlElement  x;
            XmlComment  dec = dom.CreateComment("This is data of " + KPMAIN.getId() + ":" + KPMAIN.getImie());

            dom.AppendChild(dec);
            String[] kolumny = mSQL.getKolumny();
            x = dom.CreateElement("Karty");
            dom.AppendChild(x);

            XmlElement x1 = dom.CreateElement("Karta");



            List <object> lista = KPMAIN.zwrocListe();

            for (int i = 0; i < kolumny.Length; i++)
            {
                XmlElement w = dom.CreateElement(kolumny[i]);
                w.InnerText = lista[i].ToString();
                x1.AppendChild(w);
            }



            x.AppendChild(x1);



            StorageFolder sf = await ApplicationData.Current.LocalFolder.CreateFolderAsync("EMP", CreationCollisionOption.OpenIfExists);

            StorageFile st = await sf.CreateFileAsync("Karta" + KPMAIN.getId() + KPMAIN.getImie() + ".xml", CreationCollisionOption.ReplaceExisting);

            // var filee = await sf.GetFileAsync("Karta" + KPMAIN.getId() + KPMAIN.getImie() + ".xml");
            // //var readFile = await Windows.Storage.FileIO.ReadLinesAsync(filee);
            //  String dane = "";



            await dom.SaveToFileAsync(st);

            //await Windows.System.Launcher.LaunchFolderAsync(sf);

            String test = dom.GetXml();
            //Show(test);

            /*foreach (var line in readFile)
             * {
             *  dane += line;
             * }
             * Show(dane);*/
            var savePicker = new Windows.Storage.Pickers.FileSavePicker();

            savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;
            // Dropdown of file types the user can save the file as
            savePicker.FileTypeChoices.Add("Plain Text", new List <string>()
            {
                ".xml"
            });
            // Default file name if the user does not type one in or select a file to replace
            savePicker.SuggestedFileName = "Karta" + KPMAIN.getId() + KPMAIN.getImie() + ".xml";

            Windows.Storage.StorageFile file = await savePicker.PickSaveFileAsync();

            if (file != null)
            {
                // Prevent updates to the remote version of the file until
                // we finish making changes and call CompleteUpdatesAsync.
                Windows.Storage.CachedFileManager.DeferUpdates(file);
                // write to file

                await Windows.Storage.FileIO.WriteTextAsync(file, test);

                // Let Windows know that we're finished changing the file so
                // the other app can update the remote version of the file.
                // Completing updates may require Windows to ask for user input.
                Windows.Storage.Provider.FileUpdateStatus status =
                    await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file);

                if (status == Windows.Storage.Provider.FileUpdateStatus.Complete)
                {
                    //this.textBlock.Text = "File " + file.Name + " was saved.";
                }
                else
                {
                    //this.textBlock.Text = "File " + file.Name + " couldn't be saved.";
                }
            }
            else
            {
                //this.textBlock.Text = "Operation cancelled.";
            }
        }