private void btnDelete_Click(object sender, EventArgs e) { if (txtExpeditionId.Text == "") { MessageBox.Show("Anda harus memlihi data dulu"); } else { int expeditionId = int.Parse(txtExpeditionId.Text.ToString()); tblExpedition deleteExpedition = (from x in de.tblExpeditions where x.ExpeditionId == expeditionId select x).FirstOrDefault(); DialogResult result = MessageBox.Show("Apa Anda yakin ingin delete data?", "Confirmation", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { de.tblExpeditions.Remove(deleteExpedition); clear(); } else { return; } de.SaveChanges(); update_data(); } }
private void btnSubmit_Click(object sender, EventArgs e) { if (_insert) { input(); if (isCheckedName && isCheckedAddress && isCheckedNumber) { tblExpedition newExpedition = new tblExpedition { ExpeditionName = txtExpeditionName.Text.ToUpper(), Address = rtxtboxExpeditionAddress.Text.ToUpper(), Phone = txtExpeditionNumber.Text, AdditionalContact = txtAdditionalName.Text.ToUpper(), AdditionalPhone = txtAdditionalNumber.Text }; de.tblExpeditions.Add(newExpedition); MessageBox.Show("Success input data"); } else { return; } } else if (_update) { int expeditionId = int.Parse(txtExpeditionId.Text.ToString()); tblExpedition updateExpedition = (from x in de.tblExpeditions where x.ExpeditionId == expeditionId select x).FirstOrDefault(); input(); if (isCheckedName && isCheckedAddress && isCheckedNumber) { //change data in database updateExpedition.ExpeditionName = txtExpeditionName.Text.ToUpper(); updateExpedition.Address = rtxtboxExpeditionAddress.Text.ToUpper(); updateExpedition.Phone = txtExpeditionNumber.Text; updateExpedition.AdditionalContact = txtAdditionalName.Text.ToUpper(); updateExpedition.AdditionalPhone = txtAdditionalNumber.Text; MessageBox.Show("Success update data"); } else { return; } } de.SaveChanges(); update_data(); clear(); mode(true); _insert = _update = false; }