Exemple #1
0
        public List<Menu> GetAllMenu()
        {
            //string connString = ConfigurationManager.ConnectionStrings["CYJHOrderSysConn"].ConnectionString;
            //SQLHelper sqlHelp = new SQLHelper(connString, true);

            string sqlCmd = "select * from Menu";
            List<Menu> menuList=new List<Menu>();

            if (_sqlHelp.TryConnection()) {
                DataTable menuResult = _sqlHelp.ExecuteFillDataTable(sqlCmd);
                for (int i=0;i<menuResult.Rows.Count;i++) {
                    DataRow dr=menuResult.Rows[i];
                    Menu menu=new Menu();
                    menu.Id=Int32.Parse(dr["Id"].ToString());
                    menu.RestaurantName=dr["RestaurantName"].ToString();
                    menu.Phone=dr["Phone"].ToString();
                    menu.Address=dr["Address"].ToString();
                    menu.Comment=dr["Comment"].ToString();
                    menuList.Add(menu);
                }
            } else {
                throw new Exception("数据库连接失败");
            }
            return menuList;
        }
Exemple #2
0
        public Menu GetMenuByMenuId(int menuId)
        {
            string sqlCmd = "select * from [Menu] where Id=" + menuId;
            if (_sqlHelp.TryConnection()) {
                DataTable orderResult = _sqlHelp.ExecuteFillDataTable(sqlCmd);
                if (orderResult.Rows.Count != 0) {
                    DataRow dr = orderResult.Rows[0];
                    Menu menu = new Menu();
                    menu.Id = Int32.Parse(dr["Id"].ToString());
                    menu.RestaurantName = dr["RestaurantName"].ToString();
                    menu.Phone = dr["Phone"].ToString();
                    menu.Address = dr["Address"].ToString();
                    menu.Comment = dr["Comment"].ToString();
                    return menu;
                }

            } else {
                throw new Exception("数据库连接失败");
            }
            return null;
        }