Exemplo n.º 1
0
 public static void Add(string category, string txt, string imageFileName)
 {
     try
     {
         using (KnowledgeEntities en = new KnowledgeEntities())
         {
             if (en.KBs.Any(x => x.Category == category && x.Txt == txt))
             {
                 MessageBox.Show("文本和以前的重复,请修改后再添加!");
                 return;
             }
             KB kb = new KB();
             kb.Category = category;
             kb.Txt      = txt;
             kb.Pic      = File.ReadAllBytes(imageFileName);
             en.KBs.Add(kb);
             en.SaveChanges();
         }
         MessageBox.Show("添加成功!");
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 2
0
 public static List <string> GetTxtUnderCategory(string category)
 {
     try
     {
         using (KnowledgeEntities en = new KnowledgeEntities())
         {
             return(en.KBs.Where(x => x.Category == category).Select(x => x.Txt).Distinct().ToList());
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         return(new List <string>());
     }
 }
Exemplo n.º 3
0
 public static KB GetKBByTxt(string txt)
 {
     try
     {
         using (KnowledgeEntities en = new KnowledgeEntities())
         {
             return(en.KBs.First(x => x.Txt == txt));
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         return(null);
     }
 }
Exemplo n.º 4
0
 public static KB GetKnowledge(int id)
 {
     try
     {
         using (KnowledgeEntities en = new KnowledgeEntities())
         {
             KB kb = en.KBs.First(x => x.ID == id);
             return(kb);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         return(null);
     }
 }
Exemplo n.º 5
0
 public static bool DeleteKBById(int id)
 {
     try
     {
         using (KnowledgeEntities en = new KnowledgeEntities())
         {
             KB kb = en.KBs.First(x => x.ID == id);
             en.KBs.Remove(kb);
             en.SaveChanges();
         }
         MessageBox.Show("删除成功");
         return(true);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         return(false);
     }
 }
Exemplo n.º 6
0
 public static bool Update(int id, string category, string txt, string imageFileName)
 {
     try
     {
         using (KnowledgeEntities en = new KnowledgeEntities())
         {
             KB kb = en.KBs.First(x => x.ID == id);
             kb.Category = category;
             kb.Txt      = txt;
             if (!string.IsNullOrWhiteSpace(imageFileName))
             {
                 kb.Pic = File.ReadAllBytes(imageFileName);
             }
             en.SaveChanges();
         }
         MessageBox.Show("修改成功!");
         return(true);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         return(false);
     }
 }