Пример #1
0
        private async Task <JObject> ExportScheData(JObject root)
        {
            ScheManager     sManager = new ScheManager();
            List <ScheData> read     = await sManager.ReadData();

            JArray cl = new JArray();

            foreach (ScheData o in read)
            {
                JObject obj = new JObject();
                obj.Add("ID", o.ID);
                obj.Add("Cont", o.Content);
                obj.Add("Date", o.Time.ToString("yyyy/MM/dd"));
                obj.Add("Txt", o.Complete);
                cl.Add(obj);
            }
            root.Add("Schedule", cl);
            return(root);
        }
Пример #2
0
        private new async void PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            string sT = xList.Text;

            string[] lns = sT.Split((char)0x0d);

            ScheManager sManager = new ScheManager();

            foreach (string s in lns)
            {
                if (s == "")
                {
                    continue;
                }
                await sManager.Insert(new ScheData()
                {
                    Content  = s,
                    Time     = now,
                    Complete = false
                });
            }
        }
Пример #3
0
        public async Task LoadData(StorageFile from)
        {
            JObject      root    = JObject.Parse(await FileIO.ReadTextAsync(from));
            JArray       classes = (JArray)root.GetValue("Classroom");
            JArray       sches   = (JArray)root.GetValue("Schedule");
            ClassManager cM      = new ClassManager();
            ScheManager  sM      = new ScheManager();
            string       dbpath  = Path.Combine(ApplicationData.Current.LocalFolder.Path, ClassManager.DB_FILE);

            using (SqliteConnection db = new SqliteConnection($"Filename={dbpath}"))
            {
                await db.OpenAsync();

                SqliteTransaction transC = db.BeginTransaction();
                try
                {
                    await cM.Clear(db, transC);

                    foreach (JObject o in classes)
                    {
                        await cM.AddData(new ClassObj()
                        {
                            Order  = (long)o.GetValue("Order"),
                            Link   = o.GetValue("Link").ToString(),
                            DisTxt = o.GetValue("Txt").ToString()
                        }, db, transC);
                    }
                }
                catch (Exception e)
                {
                    transC.Rollback();
                    throw e;
                }
                transC.Commit();
            }

            dbpath = Path.Combine(ApplicationData.Current.LocalFolder.Path, ScheManager.DB_FILE);
            using (SqliteConnection db = new SqliteConnection($"Filename={dbpath}"))
            {
                await db.OpenAsync();

                SqliteTransaction transS = db.BeginTransaction();
                try
                {
                    await sM.Clear(db, transS);

                    foreach (JObject o in sches)
                    {
                        await sM.Insert(new ScheData()
                        {
                            Content  = o.GetValue("Cont").ToString(),
                            Complete = (long)o.GetValue("Txt") == 1 ? true : false,
                            Time     = DateTimeOffset.ParseExact(o.GetValue("Date").ToString(), "yyyy/MM/dd", new CultureInfo("ko-KR"))
                        }, db, transS);
                    }
                }
                catch (Exception e)
                {
                    transS.Rollback();
                    throw e;
                }
                transS.Commit();
            }
        }