Пример #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
 //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();
     }
 }
Пример #3
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();
     }
 }
Пример #4
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();
     }
 }
Пример #5
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();
     }
 }
Пример #6
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($"删除订单错误!");
     }
 }
Пример #7
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}");
     }
 }