public int Insert <T>(T entity) { Type type = entity.GetType(); if (type == typeof(City)) { return(CityTable.Insert(entity as City)); } if (type == typeof(Customer)) { return(CustomerTable.Insert(entity as Customer)); } if (type == typeof(Distillation)) { return(DistillationTable.Insert(entity as Distillation)); } if (type == typeof(District)) { return(DistrictTable.Insert(entity as District)); } if (type == typeof(Material)) { return(MaterialTable.Insert(entity as Material)); } if (type == typeof(Period)) { return(PeriodTable.Insert(entity as Period)); } if (type == typeof(Region)) { return(RegionTable.Insert(entity as Region)); } if (type == typeof(Reservation)) { return(ReservationTable.Insert(entity as Reservation)); } if (type == typeof(Season)) { return(SeasonTable.Insert(entity as Season)); } if (type == typeof(UserInfo)) { return(UserInfoTable.Insert(entity as UserInfo)); } return(0); }
private void BindBack() { Material m = new Material(); bool IsInsert = Material.MId == -1 ? true : false; m.MId = Material.MId != -1 ? Material.MId : getNextID(); m.Predmet = Material.Predmet != null ? Material.Predmet : new PredmetTable().SelectByID((int)predmetComboBox.SelectedValue); m.Uzivatel = Material.Uzivatel != null ? Material.Uzivatel : new UzivatelTable().SelectByID((int)uzivatelComboBox.SelectedValue); m.Typ = TypBox.Text; m.Dokument = DokumentBox.Text;; try { m.Datum = DateTime.Parse(DatumBox.Text); } catch (Exception) { Dialog.BadDateNotify notify = new Dialog.BadDateNotify(); notify.ShowDialog(); return; } m.Okruh = OkruhBox.Text; if (m.Okruh != "zap." && m.Okruh != "klzap." && m.Okruh != "zk.") { Dialog.InvalidInput notify = new Dialog.InvalidInput(); notify.ShowDialog(); return; } if (IsInsert) { MaterialTable.Insert(m); } else { MaterialTable.Update(m); } }