private bool KiemTraHopLeVaThongBao(DoanTau doanTau) { if (doanTau.Name.Trim().Equals(string.Empty)) { MessageBox.Show(Resources.KhongDeTrong1, Resources.MNhapLieuSai); return false; } return true; }
public static int ThemDoanTau(DoanTau doanTau) { using (var context = new VeTauEntities(false)) { context.DoanTaus.Add(doanTau); return context.SaveChanges(); } }
public static int CapNhatDoanTau(DoanTau doanTau) { using (var context = new VeTauEntities(false)) { var doiTuong = context.DoanTaus.SingleOrDefault(i => i.Id == doanTau.Id); if (doiTuong != null) { doiTuong.GhiChu = doanTau.GhiChu; doiTuong.Name = doanTau.Name; doiTuong.TocDo = doanTau.TocDo; } return context.SaveChanges(); } }
private void btnThem_Click(object sender, EventArgs e) { var doanTau = new DoanTau { Id = tbMa.Text.ToUpper().Replace(" ", ""), Name = tbTen.Text, TocDo = trckTocDo.Value, GhiChu = tbGhiChu.Text }; if (KiemTraHopLeVaThongBao(doanTau)) { if (DoanTauDal.ThemDoanTau(doanTau) > 0) { btnLamMoi_Click(null,null); MessageBox.Show(Resources.TaoDoiTuong + Resources.thanhCong, Resources.MThanhCong); } else { MessageBox.Show(Resources.TaoDoiTuong + Resources.thatBai, Resources.MThatBai); } } }