private void action(String actioning) { tick = actioning == "insert" ? new tbl_Ticket() : tick = db.tbl_Tickets.FirstOrDefault(i => i.id_ticket == int.Parse(tbIdClass.Text)); tick.id_ticket = int.Parse(tbIdClass.Text); tick.class_ticket = tbClassname.Text; if (actioning == "insert") { tick.id_ticket = int.Parse(tbIdClass.Text); db.tbl_Tickets.InsertOnSubmit(tick); } db.SubmitChanges(); }
private void setTextBox() { if (!String.IsNullOrEmpty(tbIdClass.Text)) { tick = db.tbl_Tickets.FirstOrDefault(i => i.id_ticket == int.Parse(tbIdClass.Text)); if (tick != null) { tbClassname.Text = tick.class_ticket; btnAdd.Text = "UPDATE"; } else { va.clear("tbIdClass"); btnAdd.Text = "ADD"; } } }
private void btnAdd_Click(object sender, EventArgs e) { try { String message = ""; DialogResult fc = MessageBox.Show("Are you sure want to add this data?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (fc == DialogResult.No) { return; } if (va.doValidation() == false) { return; } tick = db.tbl_Tickets.FirstOrDefault(i => i.id_ticket == int.Parse(tbIdClass.Text)); if (tick != null) { message = "Update"; action("update"); } else { message = "Insert"; action("insert"); } MessageBox.Show(message + " data success!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); loadGrid(); va.clear(""); } catch (Exception err) { MessageBox.Show(err.ToString()); } }