private void btnDelete_Click(object sender, EventArgs e) { if (txtShopId.Text == "") { MessageBox.Show("Anda harus memilih data dulu"); } else { int shopId = int.Parse(txtShopId.Text.ToString()); tblShop deleteShop = (from x in de.tblShops where x.ShopId == shopId select x).FirstOrDefault(); DialogResult result = MessageBox.Show("Apa Anda yakin ingin delete data?", "Confirmation", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { de.tblShops.Remove(deleteShop); clear(); } else { return; } de.SaveChanges(); update_data(); } }
private void btnSubmit_Click(object sender, EventArgs e) { if (_insert) { input(); if (isCheckedName && isCheckedAddress && isCheckedNumber) { tblShop newShop = new tblShop { ShopName = txtShopName.Text.ToUpper(), Address = rtxtboxShopAddress.Text.ToUpper(), Telephone = txtShopNumber.Text, OwnerName = txtOwnerName.Text.ToUpper(), OwnerPhone = txtOwnerNumber.Text }; de.tblShops.Add(newShop); MessageBox.Show("Success input data"); } else { return; } } else if (_update) { int shopId = int.Parse(txtShopId.Text.ToString()); tblShop updateShop = (from x in de.tblShops where x.ShopId == shopId select x).FirstOrDefault(); input(); if (isCheckedName && isCheckedAddress && isCheckedNumber) { //change data in database updateShop.ShopName = txtShopName.Text.ToUpper(); updateShop.Address = rtxtboxShopAddress.Text.ToUpper(); updateShop.Telephone = txtShopNumber.Text; updateShop.OwnerName = txtOwnerName.Text.ToUpper(); updateShop.OwnerPhone = txtOwnerNumber.Text; MessageBox.Show("Success update data"); } else { return; } } de.SaveChanges(); update_data(); clear(); mode(true); _insert = _update = false; }