public static void DeleteItem(int pid) { using (var db = new AutoDataContext()) { Receptions reception = new Receptions(); var items_query = from item in db.Reception where item.id == pid select item; if (items_query.Count() == 0) { MessageBox.Show("Delete not completed (error: no correct id Reception table). Please contact service center."); return; } foreach (var item in items_query) { reception = item; } db.Reception.Remove(reception); try { db.SaveChanges();// delete employee } catch (Exception exc) { MessageBox.Show("Delete reception complete with error: " + exc.Message); } } }
public static Receptions GetItem(int pid) { Receptions reception = new Receptions(); using (var db = new AutoDataContext()) { reception = db.Reception.Find(pid); } return(reception); }
/* * Update new row in table * Return * true if added sucsessfull * false if don' added (have error message) */ public static bool UpdateItem(int pid, Patients patient, double cost, DateTime dateNext, string completedWork) { if (patient.id == 0) { MessageBox.Show("Patient not select"); return(false); } using (var db = new AutoDataContext()) { Receptions reception = db.Reception.Find(pid); reception.patientid = patient.id; reception.cost = cost; reception.dateNext = dateNext; reception.completedWork = completedWork; db.SaveChanges();// update row return(true); } }
/* * Add new row in table * Returnpost * true if added sucsessfull * false if don' added (have error message) */ public static bool NewItem(Patients patient, double cost, DateTime dateNext, string completedWork) { if (patient.id == 0) { MessageBox.Show("Patient not select"); return(false); } using (var db = new AutoDataContext()) { Receptions reception = new Receptions(); reception.patientid = patient.id; reception.cost = cost; reception.dateNext = dateNext; reception.completedWork = completedWork; db.Reception.Add(reception); db.SaveChanges();// add new return(true); } }