示例#1
0
文件: Database.cs 项目: forr/BonTemps
 public override Menu GetMenu(ulong menuID)
 {
     Menu result = Menu.Null;
     string statement = "SELECT * FROM Menus WHERE MenuID=@ID";
     try
     {
         using (SqlConnection sqlConn = new SqlConnection(GetConnectionString()))
         {
             sqlConn.Open();
             if (sqlConn.State == ConnectionState.Open)
             {
                 SqlCommand sqlQuery = new SqlCommand(statement, sqlConn);
                 sqlQuery.Parameters.AddWithValue("@ID", menuID);
                 SqlDataReader sqlDR = sqlQuery.ExecuteReader();
                 if (sqlDR.Read())
                 {
                     Menu m = new Menu();
                     m.MenuID = Convert.ToUInt64(sqlDR["MenuID"]);
                     m.Entree = sqlDR["Entree"].ToString();
                     m.MainCourse = sqlDR["MainCourse"].ToString();
                     m.Dessert = sqlDR["Dessert"].ToString();
                     m.Price = (int)sqlDR["Price"];
                     return m;
                 }
                 result = Menu.Null;
             }
         }
     }
     catch { result = Menu.Null; }
     return result;
 }
示例#2
0
文件: Database.cs 项目: forr/BonTemps
 public override List<Menu> GetAllMenus()
 {
     List<Menu> menus = new List<Menu>();
     string statement = "SELECT * FROM Menus";
     try
     {
         using (SqlConnection sqlConn = new SqlConnection(GetConnectionString()))
         {
             sqlConn.Open();
             if (sqlConn.State == ConnectionState.Open)
             {
                 SqlCommand sqlQuery = new SqlCommand(statement, sqlConn);
                 SqlDataReader sqlDR = sqlQuery.ExecuteReader();
                 while (sqlDR.Read())
                 {
                     Menu m = new Menu();
                     m.MenuID = Convert.ToUInt64(sqlDR["MenuID"]);
                     m.Entree = sqlDR["Entree"].ToString();
                     m.MainCourse = sqlDR["MainCourse"].ToString();
                     m.Dessert = sqlDR["Dessert"].ToString();
                     double priceOut = 0.00;
                     double.TryParse(sqlDR["Price"].ToString(), out priceOut);
                     m.Price = priceOut;
                     menus.Add(m);
                 }
                 return menus;
             }
             return null;
         }
     }
     catch { return null; }
 }