private void BtnImport2_Click(object sender, EventArgs e) { var db = new AppG2Context(); foreach (Contact ct in listContact) { var result = db.ContactDbset.SingleOrDefault(a => a.phoneContact.Equals(ct.phoneContact)); if (result != null) { result.nameContact = ct.nameContact; result.phoneContact = ct.phoneContact; result.emailContact = ct.emailContact; db.SaveChanges(); } else { var cre = db.ContactDbset.Create(); cre.iDContact = Guid.NewGuid().ToString(); cre.nameContact = ct.nameContact; cre.phoneContact = ct.phoneContact; cre.emailContact = ct.emailContact; cre.userName = userName; db.ContactDbset.Add(cre); db.SaveChanges(); } } this.Hide(); frmContacts frmContacts = new frmContacts(userName); frmContacts.ShowDialog(); this.Close(); }
public static void AddContactDB(Contacts contact) { var db = new AppG2Context(); db.ContactsDbset.Add(contact); db.SaveChanges(); }
//xóa student public static void DeleteStudent(string idStudent) { var db = new AppG2Context(); var lsDiem = db.DiemDbset.Where(e => e.IDStudent == idStudent).ToList(); foreach (var diem in lsDiem) { db.DiemDbset.Remove(diem); } var lsHistory = db.HistoryLearningDbset.Where(e => e.IDStudent == idStudent).ToList(); foreach (var history in lsHistory) { db.HistoryLearningDbset.Remove(history); } var student = db.StudentDbset.Where(e => e.IDStudent == idStudent).FirstOrDefault(); if (student != null) { db.StudentDbset.Remove(student); } db.SaveChanges(); }
public static void Import(User user, List <Contacts> listContacts) { var db = new AppG2Context(); OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "Chọn file .csv"; ofd.Filter = "File csv(*.csv)|*.csv"; if (ofd.ShowDialog() == DialogResult.OK) { var listLines = File.ReadAllLines(ofd.FileName); foreach (var line in listLines) { var rs = line.Split(new char[] { ',' }); Contacts contact = new Contacts { IDContact = Guid.NewGuid().ToString(), Name = rs[0], Phone = rs[1], Email = rs[2], Username = user.Username }; if (isExist(contact, listContacts) == null) { db.ContactsDbset.Add(contact); } else { EditContactImport(contact); } } db.SaveChanges(); } }
public static void CreateHistoryLearningDB(HistoryLearning history) { var db = new AppG2Context(); history.IDHistoryLearning = Guid.NewGuid().ToString(); db.HistoryLearningDbset.Add(history); db.SaveChanges(); }
public static void EditContactImport(Contacts contact) { var db = new AppG2Context(); var cnt = db.ContactsDbset.Where(e => e.Phone == contact.Phone && e.Username == contact.Username).FirstOrDefault(); cnt.Name = contact.Name; cnt.Email = contact.Email; db.SaveChanges(); }
public static void EditHistoryLearningDB(HistoryLearning history) { var db = new AppG2Context(); var ht = db.HistoryLearningDbset.Find(history.IDHistoryLearning); ht.Address = history.Address; ht.YearFrom = history.YearFrom; ht.YearEnd = history.YearEnd; db.SaveChanges(); }
//thêm student public static void CreateStudentDB(Student student) { var db = new AppG2Context(); var std = db.StudentDbset.Find(student.IDStudent); if (std == null) { db.StudentDbset.Add(student); db.SaveChanges(); } }
public static void DeleteContactDB(string id) { var db = new AppG2Context(); var contact = db.ContactDbset.Where(e => e.ID == id).FirstOrDefault(); if (contact != null) { db.ContactDbset.Remove(contact); } db.SaveChanges(); }
public static void DeleteHistoryLearningDB(string id) { var db = new AppG2Context(); var history = db.HistoryLearningDbset.Where(e => e.IDHistoryLearning == id).FirstOrDefault(); if (history != null) { db.HistoryLearningDbset.Remove(history); } db.SaveChanges(); }
public static void DeleteContactDB(string idContact) { var db = new AppG2Context(); var itemToRemove = db.ContactDbset.SingleOrDefault(x => x.iDContact.Equals(idContact)); if (itemToRemove != null) { db.ContactDbset.Remove(itemToRemove); db.SaveChanges(); } }
//xóa student public static void EditStudentDB(Student student) { var db = new AppG2Context(); var std = db.StudentDbset.Find(student.IDStudent); std.FirstName = student.FirstName; std.LastName = student.LastName; std.Gender = student.Gender; std.DOB = student.DOB; std.POB = student.POB; std.IDKhoa = student.IDKhoa; db.SaveChanges(); }
public static void EditContactDB(string IDContact, string name, string phone, string email) { var db = new AppG2Context(); var result = db.ContactDbset.SingleOrDefault(a => a.iDContact.Equals(IDContact)); if (result != null) { result.nameContact = name; result.phoneContact = phone; result.emailContact = email; db.SaveChanges(); } }
public static void CreateContactDB(string name, string phone, string email, string userName) { var db = new AppG2Context(); var cre = db.ContactDbset.Create(); cre.iDContact = Guid.NewGuid().ToString(); cre.nameContact = name; cre.phoneContact = phone; cre.emailContact = email; cre.userName = userName; db.ContactDbset.Add(cre); db.SaveChanges(); }
public static Boolean CreateContactDB(Contact contact) { var db = new AppG2Context(); contact.ID = Guid.NewGuid().ToString(); if (!ExistPhoneOrEmail(contact.Phone, contact.Email, contact.UserName, contact.ID)) { db.ContactDbset.Add(contact); db.SaveChanges(); return(true); } return(false); }
public static void EditContactDB(Contacts contact) { var db = new AppG2Context(); //List<Contacts> listContacts = GetContactDB(user); //Contacts contactOld = isExist(contact, listContacts); //if (contactOld != null) //{ var cnt = db.ContactsDbset.Find(contact.IDContact); cnt.Name = contact.Name; cnt.Email = contact.Email; cnt.Phone = contact.Phone; db.SaveChanges(); //} }
public static void AddOrEditDiemDB(Diem diem) { var db = new AppG2Context(); var std = db.DiemDbset.Where(e => e.IDMonHoc == diem.IDMonHoc && e.IDStudent == diem.IDStudent).FirstOrDefault(); if (std != null) { std.DiemMonHoc = diem.DiemMonHoc; } else { db.DiemDbset.Add(diem); } db.SaveChanges(); }
public static Boolean EditContactDB(Contact contact) { var db = new AppG2Context(); var cnt = db.ContactDbset.Where(e => (e.ID == contact.ID)).FirstOrDefault(); cnt.NameContact = contact.NameContact; cnt.Email = contact.Email; cnt.Phone = contact.Phone; if (!ExistPhoneOrEmail(cnt.Phone, cnt.Email, cnt.UserName, cnt.ID)) { db.SaveChanges(); return(true); } return(false); }
private void btnimport_Click(object sender, EventArgs e) { var count = 0; var db = new AppG2Context(); OpenFileDialog openfileDialog = new OpenFileDialog(); openfileDialog.Title = "Chọn file csv"; openfileDialog.Filter = "File csv(*.csv)|*.csv"; if (openfileDialog.ShowDialog() == DialogResult.OK) { if (File.Exists(openfileDialog.FileName)) { var lstcnt = File.ReadAllLines(openfileDialog.FileName); foreach (var contact in lstcnt) { var ls = contact.Split(new char[] { ',' }); Contact cnt = new Contact(); cnt.ID = Guid.NewGuid().ToString(); cnt.NameContact = ls[0]; cnt.Phone = ls[1]; cnt.Email = ls[2]; cnt.UserName = usr.UserName; if (!ContactService.ExistPhoneOrEmail(cnt.Phone, cnt.Email, cnt.UserName, cnt.ID)) { db.ContactDbset.Add(cnt); count++; } } db.SaveChanges(); loadContact(usr); MessageBox.Show("Import thành công " + count + " giá trị", "Thông báo"); } else { MessageBox.Show("Lỗi khi mở file", "Thông báo"); } } }