Пример #1
0
        public async void getMarked(chapter c)
        {
            string          pathField   = "path";
            string          markedField = "marked";
            string          table       = "chapterInfo";
            SqliteParameter param       = new SqliteParameter()
            {
                ParameterName = string.Format("@{0}", pathField),
                Value         = c.path
            };
            string        sql = string.Format("select {2} from {0} where {1}=@{1}", table, pathField, markedField);
            SqliteCommand cmd = new SqliteCommand(sql, m_cnn);

            cmd.Parameters.Add(param);
            var ret = await cmd.ExecuteScalarAsync();

            var indexs = new List <int>();

            if (ret != null)
            {
                string txt = ret.ToString();
                var    arr = txt.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var i in arr)
                {
                    indexs.Add(int.Parse(i));
                }
            }
            c.markedIndexs = indexs;
        }
Пример #2
0
        public async void saveChapter(chapter c)
        {
            //open file & save
            StorageFile file = c.file;

            if (file != null)
            {
                await saveWords(file, c.words);
            }
        }
Пример #3
0
        public async void updateMarked(chapter c)
        {
            string pathField   = "path";
            string idField     = "id";
            string markedField = "marked";
            string table       = "chapterInfo";

            string          sql   = string.Format("select {2} from {0} where {1}=@{1}", table, pathField, idField);
            SqliteParameter param = new SqliteParameter
            {
                ParameterName = string.Format("@{0}", pathField),
                Value         = c.path,
                DbType        = System.Data.DbType.String
            };
            SqliteCommand cmd = new SqliteCommand(sql, m_cnn);

            cmd.Parameters.Add(param);
            var ret = await cmd.ExecuteScalarAsync();

            Debug.WriteLine("{0} updateMarked find {2} {1}", this, ret, c.path);

            string markedVal = string.Join(";", c.markedIndexs);
            List <SqliteParameter> arrParams = new List <SqliteParameter> {
                new SqliteParameter {
                    ParameterName = "@" + markedField, Value = markedVal,
                    DbType        = System.Data.DbType.String
                }
            };

            if (ret != null)
            {
                string idVal = ret.ToString();
                sql = string.Format("update {0} set {1}=@{1} where {2}=@{2}", table, markedField, idField);
                arrParams.Add(new SqliteParameter {
                    ParameterName = "@" + idField, Value = idVal,
                    DbType        = System.Data.DbType.UInt64
                });
            }
            else
            {
                sql = string.Format("insert into {0} ({1}, {2}) values (@{1}, @{2}) ",
                                    table, pathField, markedField);
                arrParams.Add(new SqliteParameter {
                    ParameterName = "@" + pathField, Value = c.path, DbType = System.Data.DbType.String
                });
            }
            cmd.CommandText = sql;
            cmd.Parameters.Clear();
            cmd.Parameters.AddRange(arrParams);
            int x = await cmd.ExecuteNonQueryAsync();

            Debug.WriteLine("{0} updateMarked complete {1} {2}", this, x, Environment.TickCount);
        }
Пример #4
0
        public async void getMarked(chapter c)
        {
            List <int>  indexs = new List <int>();
            XmlDocument xd     = new XmlDocument();
            StorageFile file;

            XmlElement found = null;

            do
            {
                try
                {
                    file = await ApplicationData.Current.LocalFolder.GetFileAsync(path);
                }
                catch
                {
                    //if file not exist, create new
                    break;
                }

                IRandomAccessStream textStream = await file.OpenAsync(FileAccessMode.ReadWrite);

                Stream stream = textStream.AsStreamForRead();

                xd.Load(stream);
                XmlElement root = xd.DocumentElement;

                foreach (XmlElement node in root.ChildNodes)
                {
                    if (node.GetAttribute("path") == c.path)
                    {
                        found = node;
                        break;
                    }
                }
                stream.Dispose();
            } while (false);
            if (found != null)
            {
                string txt = found.GetAttribute("markedIndex");
                var    arr = txt.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var i in arr)
                {
                    indexs.Add(int.Parse(i));
                }
            }
            c.markedIndexs = indexs;
        }
Пример #5
0
        public async void updateMarked(chapter c)
        {
            XmlDocument xd = new XmlDocument();
            StorageFile file;
            bool        isNewFile = false;

            try
            {
                file = await ApplicationData.Current.LocalFolder.GetFileAsync(path);
            } catch {
                //if file not exist, create new
                file = await ApplicationData.Current.LocalFolder.CreateFileAsync(path, CreationCollisionOption.OpenIfExists);

                isNewFile = true;
            }

            IRandomAccessStream textStream = await file.OpenAsync(FileAccessMode.ReadWrite);

            Stream stream = textStream.AsStreamForRead();

            XmlElement root = null;

            if (isNewFile)
            {
                root = xd.CreateElement("chapter");
                xd.AppendChild(root);
            }
            else
            {
                xd.Load(stream);
                root = xd.DocumentElement;
            }

            XmlElement found = null;

            foreach (XmlElement node in root.ChildNodes)
            {
                if (node.GetAttribute("path") == c.path)
                {
                    found = node;
                    break;
                }
            }

            string txt = string.Join(";", c.markedIndexs);

            if (found == null)
            {
                XmlElement e = xd.CreateElement(c.name);
                e.SetAttribute("path", c.path);
                e.SetAttribute("markedIndex", txt);
                root.AppendChild(e);
            }
            else
            {
                found.SetAttribute("markedIndex", txt);
            }

            stream.SetLength(0);
            xd.Save(stream);
            stream.Dispose();
            textStream.Dispose();
        }