public ActionResult Add(string name, string address) { var db = new FoodDb(@"Data Source=.\SQLEXPRESS;Initial Catalog=Food;Integrated Security=True"); db.AddCustomer(name, address); return(RedirectToAction("Index")); }
public bool deleteTableFoodDb(FoodDb foodDb) { try { using (var connection = new SQLiteConnection(System.IO.Path.Combine(folder, "Foods.db"))) { connection.Delete(foodDb); return(true); } } catch (SQLiteException ex) { Log.Info("SQLiteEx", ex.Message); return(false); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.NeighboursView); TextView txtNeighbour = FindViewById <TextView>(Resource.Id.txtSeeNeighbours); var db = new SQLiteConnection(dbPath); var table = db.Table <FoodDb>(); foreach (var item in table) { FoodDb food = new FoodDb(); item.Address = food.Address; txtNeighbour.Text = food + "\n"; } }
public async Task <IActionResult> Create([Bind("ID,servqty,serv,group,food")] FoodDb foodDb) { try { if (ModelState.IsValid) { _context.Add(foodDb); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(foodDb)); } catch (SqlException) { string action = this.ControllerContext.RouteData.Values["action"].ToString(); string controller = this.ControllerContext.RouteData.Values["controller"].ToString(); return(RedirectToAction("Error", "Admin", new { controllerName = controller, actionName = action })); } }
public async Task <IActionResult> Edit(int id, [Bind("ID,servqty,serv,group,food")] FoodDb foodDb) { try { if (id != foodDb.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(foodDb); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FoodDbExists(foodDb.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(foodDb)); } catch (SqlException) { string action = this.ControllerContext.RouteData.Values["action"].ToString(); string controller = this.ControllerContext.RouteData.Values["controller"].ToString(); return(RedirectToAction("Error", "Admin", new { controllerName = controller, actionName = action })); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.GvOrderMain); db = new DataBase(); db.createDatabase(); string foodName = Intent.GetStringExtra("foodname" ?? "Not Recv"); var edtFoodName = FindViewById <EditText>(Resource.Id.edtFoodName); var btnCreate = FindViewById <Button>(Resource.Id.btnCreate); var btnTake = FindViewById <Button>(Resource.Id.btnTake); edtFoodName.Text = foodName; lstData = FindViewById <ListView>(Resource.Id.listView1); var edtNum = FindViewById <EditText>(Resource.Id.edtNofPerson); var edtDet = FindViewById <EditText>(Resource.Id.edtDetails); var edtAddr = FindViewById <EditText>(Resource.Id.edtAddress); LoadData(); btnCreate.Click += delegate { FoodDb food = new FoodDb() { Foodname = edtFoodName.Text, NofPerson = edtNum.Text, MoreDetail = edtDet.Text, Address = edtAddr.Text }; db.insertIntoTableFoodDb(food); LoadData(); Toast.MakeText(this, "Succeed", ToastLength.Short).Show(); }; btnTake.Click += delegate { FoodDb food = new FoodDb() { id = int.Parse(edtFoodName.Tag.ToString()), Foodname = edtFoodName.Text, NofPerson = edtNum.Text, MoreDetail = edtDet.Text, Address = edtAddr.Text }; db.deleteTableFoodDb(food); LoadData(); Toast.MakeText(this, "Succeed", ToastLength.Short).Show(); }; lstData.ItemClick += (s, e) => { for (int i = 0; i < lstData.Count; i++) { if (e.Position == i) { lstData.GetChildAt(i).SetBackgroundColor(Android.Graphics.Color.DarkGray); } else { lstData.GetChildAt(i).SetBackgroundColor(Android.Graphics.Color.Transparent); } } var txtName = e.View.FindViewById <TextView>(Resource.Id.textView1); var txtNumber = e.View.FindViewById <TextView>(Resource.Id.textView2); var txtDet = e.View.FindViewById <TextView>(Resource.Id.textView3); var txtAddr = e.View.FindViewById <TextView>(Resource.Id.textView4); edtFoodName.Text = txtName.Text; edtFoodName.Tag = e.Id; edtNum.Text = txtNumber.Text; edtDet.Text = txtDet.Text; edtAddr.Text = txtAddr.Text; }; }