示例#1
0
        //从文件中添加图片
        public static void AddEmoji(Emoji emoji)
        {
            //席诺&马草原
            try
            {
                using (var db = new EmojiContext())
                {
                    string src      = emoji.Path;
                    string filename = Path.GetFileName(src);
                    string dest     = @"D:\projects\.netprojects\DouTu\test\" + filename;

                    //File.Copy(src, dest);
                    //string pLocalFilePath = "";//要复制的文件路径
                    // string pSaveFilePath = "";//指定存储的路径
                    if (File.Exists(src))           //必须判断要复制的文件是否存在
                    {
                        File.Copy(src, dest, true); //三个参数分别是源文件路径,存储路径,若存储路径有相同文件是否替换
                    }

                    emoji.Path = dest;
                    db.Emojis.Add(emoji);
                    db.SaveChanges();
                }
            }
            catch (Exception e) { }
        }
示例#2
0
 //返回数据库中为收藏的表情 马草原
 public static List <Emoji> FavoriteEmoji()
 {
     using (var db = new EmojiContext())
     {
         var query = AllEmojis(db).Where(emo => emo.IsFavorite == true);
         return(query.ToList());
     }
 }
示例#3
0
 public static List <Emoji> GetAllEmojis()
 {
     using (var db = new EmojiContext())
     {
         var query = AllEmojis(db).ToList();
         return(query);
     }
 }
示例#4
0
 //根据表情热度进行排序的结果 马草原
 public static List <Emoji> SortbyFrequency()
 {
     using (var db = new EmojiContext())
     {
         var query = AllEmojis(db).ToList();
         query.Sort();
         return(query);
     }
 }
示例#5
0
 //按目标人群搜索
 public static List <Emoji> SearchByTargetPeople(string info)
 {
     //张智敏&马草原
     using (var db = new EmojiContext())
     {
         var query = AllEmojis(db)
                     .Where(e => e.TargetPeople == info);
         return(query.ToList());
     }
 }
示例#6
0
 //这个是一个综合的搜索,先空着
 public static List <Emoji> SearchEmoji(string info)
 {
     //张智敏&马草原
     using (var db = new EmojiContext())
     {
         var query = AllEmojis(db)
                     .Where(e => e.Keyword == info);
         return(query.ToList());
     }
 }
示例#7
0
 //Frequency++ 蒋沁月
 public static void FrequencyPlus(Emoji e)
 {
     using (var db = new EmojiContext())
     {
         var query = db.Emojis.Where(o => o.Id == e.Id);
         foreach (Emoji ee in query)
         {
             ee.Frequency++;
         }
         db.SaveChanges();
     }
 }
示例#8
0
 //因为要用所以我先写了 蒋沁月
 public static void ModifyEmoji(Emoji e, string key, string target, string series)
 {
     using (var db = new EmojiContext())
     {
         var query = db.Emojis.Where(o => o.Id == e.Id);
         foreach (Emoji ee in query)
         {
             ee.Keyword      = key;
             ee.TargetPeople = target;
             ee.Series       = series;
         }
         db.SaveChanges();
     }
 }
示例#9
0
        //导出表情
        public static void ExportEmoji(List <Emoji> emojis)
        {
            using (var db = new EmojiContext())
            {
                var queary = db.Emojis;
                foreach (Emoji ee in queary)
                {
                    if (ee.Path != null)
                    {
                        try
                        {
                            string src      = ee.Path;
                            string filename = Path.GetFileName(src);
                            string dest     = @"..\..\..\Export\" + filename;
                            if (File.Exists(src))           //必须判断要复制的文件是否存在
                            {
                                File.Copy(src, dest, true); //三个参数分别是源文件路径,存储路径,若存储路径有相同文件是否替换
                            }
                            ee.Path = dest;
                        }
                        catch (Exception ep) { }
                    }
                }
            }
            using (var db = new EmojiContext())
            {
                try
                {
                    using (System.IO.StringWriter stringWriter = new StringWriter(new StringBuilder()))
                    {
                        XmlSerializer xmlSerializer = new XmlSerializer(typeof(List <Emoji>));
                        xmlSerializer.Serialize(stringWriter, emojis);

                        FileStream   fs = new FileStream("export.xml", FileMode.OpenOrCreate);
                        StreamWriter sw = new StreamWriter(fs);
                        sw.Write(stringWriter.ToString());
                        sw.Close();
                        fs.Close();
                        MessageBox.Show("导出文件成功!");
                        string src      = @"..\..\..\EmojiForm\bin\Debug\export.xml";
                        string filename = Path.GetFileName(src);
                        string dest     = @"..\..\..\Export\" + filename;
                        File.Copy(src, dest, true);
                    }
                }
                catch (System.Exception ex)
                { }
            }
        }
示例#10
0
 //通过路径判断数据库中是否存在当前表情。马草原
 public static bool Emojiexist(string path)
 {
     using (var db = new EmojiContext())
     {
         var queary = db.Emojis.Where(o => o.Path == path);
         if (queary == null)
         {
             return(false);//不存在返回false
         }
         else
         {
             return(true);
         }
     }
 }
示例#11
0
 public static void DeleteEmoji()
 {
     //张智敏&马草原
     try
     {
         using (var db = new EmojiContext())
         {
         }
     }
     catch (Exception e)
     {
         //TODO 需要更加错误类型返回不同错误信息
         throw new ApplicationException($"删除订单错误!");
     }
 }
示例#12
0
 //这个是一个综合的搜索,先空着
 public static List <Emoji> SearchEmoji(string info)
 {
     //张智敏&马草原
     using (var db = new EmojiContext())
     {
         var query1 = AllEmojis(db)
                      .Where(e => e.Keyword == info);
         var query2 = AllEmojis(db)
                      .Where(e => e.Series == info);
         var query3 = AllEmojis(db)
                      .Where(e => e.TargetPeople == info);
         var query = query1.Concat(query2);
         query = query.Concat(query3);
         return(query.ToList());
     }
 }
示例#13
0
 public static void DeleteNull()
 {
     using (var db = new EmojiContext())
     {
         var query = db.Emojis.Where(o => o.Id == null || o.IsFavorite == null ||
                                     o.Path == "" || o.Keyword == null);
         foreach (Emoji e in query)
         {
             db.Emojis.Remove(e);
         }
         foreach (Emoji e in db.Emojis)
         {
             Console.WriteLine(e);
         }
         db.SaveChanges();
     }
 }
示例#14
0
 //按系列搜索
 public static List <Emoji> SearchBySeries(string info)
 {
     //张智敏&马草原
     if (info == "全部")
     {
         using (var db = new EmojiContext())
         {
             var query = AllEmojis(db);
             return(query.ToList());
         }
     }
     using (var db = new EmojiContext())
     {
         var query = AllEmojis(db)
                     .Where(e => e.Series.Contains(info));
         return(query.ToList());
     }
 }
示例#15
0
 /// <summary>
 /// 修改IsFavorite,参数i为0改为true,参数i为1改为false
 /// 蒋沁月
 /// </summary>
 public static void ModifyIsFavorite(Emoji e, int i)
 {
     using (var db = new EmojiContext())
     {
         var query = db.Emojis.Where(o => o.Id == e.Id);
         foreach (Emoji ee in query)
         {
             if (i == 0)
             {
                 ee.IsFavorite = true;
             }
             else if (i == 1)
             {
                 ee.IsFavorite = false;
             }
         }
         db.SaveChanges();
     }
 }
示例#16
0
 public static void DeleteEmoji(Emoji emoji)
 {
     //张智敏&马草原
     try
     {
         using (var db = new EmojiContext())
         {
             var query = db.Emojis.Where(o => o.Id == emoji.Id);
             foreach (Emoji ee in query)
             {
                 db.Emojis.Remove(ee);
             }
             db.SaveChanges();
         }
     }
     catch (Exception e)
     {
         //TODO 需要更加错误类型返回不同错误信息
         throw new ApplicationException($"删除订单错误!");
     }
 }
示例#17
0
 //从文件中添加图片
 public static void AddEmoji(Emoji emoji)
 {
     //席诺&马草原
     try
     {
         using (var db = new EmojiContext())
         {
             //拷贝图片到指定文件夹
             string picPath    = emoji.Path;//这里记得传入图片的路径,通过可视化操作选中图片传参,参数记得改一下奥席诺同学
             string filename   = Path.GetFileName(picPath);
             string str        = System.Environment.CurrentDirectory;
             string targetPath = @"str" + filename;
             //在数据库里添加这个表情的信息
             db.Emojis.Add(emoji);
             db.SaveChanges();
         }
         return;
     }
     catch (Exception e)
     {
         //TODO 需要更加错误类型返回不同错误信息
         //throw new ApplicationException($"添加错误: {e.Message}");
     }
 }
示例#18
0
 //返回所有表情 马草原
 public static IQueryable <Emoji> AllEmojis(EmojiContext db)
 {
     return(db.Emojis);
 }