//更新给定项,成功返回true,失败意味着没有这个名称的项
 public static bool Update(string oldItemName, menuItem newItem)
 {
     if (GetAItem(oldItemName) == null)
     {
         return(false);
     }
     try
     {                                                           //"UPDATE TodoItem SET Ti = ?, Desc = ?, Time = ?, Pic = ?, Finished = ? WHERE Tid = ?"
                                                                 //Name, Formula, Category, Description, Image, Price
         using (var custstmt = ((App)App.Current).conn.Prepare("update MenuItem set Name = ?, Formula = ?, Category = ?, Description = ?, Image = ?, Price = ? where Name = ?"))
         {
             custstmt.Bind(1, newItem.menuName);
             custstmt.Bind(2, newItem.generateSQLSavingString());
             custstmt.Bind(3, newItem.Category);
             custstmt.Bind(4, newItem.description);
             custstmt.Bind(5, newItem.Image);
             custstmt.Bind(6, newItem.price);
             custstmt.Bind(7, oldItemName);
             custstmt.Step();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(true);
 }
 //插入给定的项,成功返回true,失败意味着已经有重复名称的项存在
 public static bool Insert(menuItem aim)
 {
     if (GetAItem(aim.menuName) != null)
     {
         return(false);
     }
     // SqlConnection was opened in App.xaml.cs and exposed through property conn
     try
     {
         using (var custstmt = ((App)App.Current).conn.Prepare("INSERT INTO MenuItem (Name, Formula, Category, Description, Image, Price) VALUES (?, ?, ?, ?, ?, ?)"))
         {
             custstmt.Bind(1, aim.menuName);
             custstmt.Bind(2, aim.generateSQLSavingString());
             custstmt.Bind(3, aim.Category);
             custstmt.Bind(4, aim.description);
             custstmt.Bind(5, aim.Image);
             custstmt.Bind(6, aim.price);
             custstmt.Step();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(true);
 }
        //测试菜单数据库
        private void testMenu_Click(object sender, RoutedEventArgs e)
        {
            string   result = "";
            menuItem t1     = new menuItem("t1", "apple,1.5,banana,2.5,water,3.5,", "a", "hello", "zzz", "100$");
            menuItem t2     = new menuItem("t2", "f**k,1.5,banana,2.5,water,3.5,", "a", "hello", "zzz", "100$");
            menuItem t3     = new menuItem("t3", "apple,1.5,banana,2.5,water,100000,", "a", "hello", "zzz", "100$");
            menuItem t4     = new menuItem("t4", "apple,1.5,banana,2.5,water,100000,", "a", "hello", "zzz", "100$");
            menuItem t5     = new menuItem("t5", "det,1.5,", "a", "hello", "zzz", "100$");
            menuItem t6     = new menuItem("t6", "egg,1,", "a", "hello", "zzz", "100$");

            result += t1.generateSQLSavingString();
            menuManager.BuildDatabase();
            menuManager.Insert(t1);
            menuManager.Insert(t2);
            menuManager.Insert(t3);
            menuManager.Insert(t4);
            menuManager.Insert(t5);
            menuManager.Insert(t6);
            menuManager.Remove("t4");
            menuManager.Update("t3", new menuItem("t3", "apple,1.5,banana,2.5,water,1999999,", "a", "hello", "zzz", "100$"));
            result += "\n" + menuManager.GetAItem("t3").generateFormulaString() + "\n";
            menuManager.ServeMenuItem("t1");
            menuManager.ServeMenuItem("t1");
            var             temp = menuManager.ServeMenuItem("t1");
            List <menuItem> res  = menuManager.GetItems();

            for (int i = 0; i < res.Count; i++)
            {
                result += res.ElementAt(i).menuName;
                result += "  ";
                result += res.ElementAt(i).SQLString;
                result += "  ";
                result += res.ElementAt(i).description;
                result += "  ";
                result += res.ElementAt(i).Category;
                result += "  ";
                result += res.ElementAt(i).price;
                result += "\n";
            }
            result += "=====================\n";
            result += temp.serveSucessed + "\n";
            temp    = menuManager.ServeMenuItem("t2");
            for (int i = 0; i < temp.needMaterialName.Count; i++)
            {
                result += temp.needMaterialName.ElementAt(i) + "  " + temp.needMaterialNumber.ElementAt(i) + "\n";
            }
            result += "=====================\n";
            temp    = menuManager.ServeMenuItem("t5");
            for (int i = 0; i < temp.needMaterialName.Count; i++)
            {
                result += temp.needMaterialName.ElementAt(i) + "  " + temp.needMaterialNumber.ElementAt(i) + "\n";
            }
            test2.Text = result;
        }