Пример #1
0
        public Note(OrderedDictionary infoPerMid, MediaInfo?mediaInfo, AnkiItem ankiItem)
        {
            var fields = (infoPerMid[ankiItem.Mid] as Info).Item3;

            Id    = DateTimeOffset.Now.ToUnixTimeMilliseconds();
            _guid = ((ShortGuid)Guid.NewGuid()).ToString().Substring(0, 10);
            _mid  = ankiItem.Mid;


            _mod = DateTimeOffset.Now.ToUnixTimeMilliseconds().ToString();

            _flds = "";
            if (mediaInfo != null)
            {
                _flds = GeneralHelper.ConcatFields(fields, ankiItem, "\x1f", mediaInfo.Value.field);
            }
            else
            {
                _flds = GeneralHelper.ConcatFields(fields, ankiItem, "\x1f");
            }

            _sfld = ankiItem[fields[0].Name].ToString();
            var csum = GeneralHelper.CheckSum(_sfld);

            Query = "INSERT INTO notes VALUES(" + Id + ", '" + _guid + "', " + _mid + ", " + _mod + ", -1, '  ', '" + _flds + "', '" + _sfld + "', " + csum + ", 0, '');";
        }
Пример #2
0
        public Note(IDictionary infoPerMid, AnkiItem ankiItem, string uniqueField = null)
        {
            var fields = ((Info)infoPerMid[ankiItem.Mid]).Item3;

            Id = DateTimeOffset.Now.ToUnixTimeMilliseconds();
            string guid;

            try
            {
                guid = uniqueField == null ? ((ShortGuid)Guid.NewGuid()).ToString().Substring(0, 10) : ankiItem["SortField"].GetHashCode().ToString();
            }
            catch (Exception ex)
            {
                guid = ((ShortGuid)Guid.NewGuid()).ToString().Substring(0, 10);
            }
            var mid  = ankiItem.Mid;
            var mod  = DateTimeOffset.Now.ToUnixTimeMilliseconds().ToString();
            var flds = GeneralHelper.ConcatFields(fields, ankiItem, "\x1f");
            var sfld = ankiItem[fields[0].Name].ToString();
            var csum = GeneralHelper.CheckSum(sfld);

            SqlQuery = @"INSERT INTO notes VALUES(@id, @guid, @mid, @mod, -1, '  ', @flds, @sfld, @csum, 0, '');";
            SQLiteParameter[] parameters =
            {
                new SQLiteParameter("id",   Id),
                new SQLiteParameter("guid", guid),
                new SQLiteParameter("mid",  mid),
                new SQLiteParameter("mod",  mod),
                new SQLiteParameter("flds", flds),
                new SQLiteParameter("sfld", sfld),
                new SQLiteParameter("csum", csum),
            };
            SqlParameters = parameters;
        }