Ejemplo n.º 1
0
        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();
            }
        }
Ejemplo n.º 2
0
        //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();
        }
Ejemplo n.º 3
0
        public static List <Contact> GetContactDBFromCharacter(string character)
        {
            var db  = new AppG2Context();
            var lst = db.ContactDbset.Where(e => (string.Compare(e.NameContact, character) >= 0)).OrderBy(e => e.NameContact).ToList();

            return(lst);
        }
Ejemplo n.º 4
0
        public static void AddContactDB(Contacts contact)
        {
            var db = new AppG2Context();

            db.ContactsDbset.Add(contact);
            db.SaveChanges();
        }
Ejemplo n.º 5
0
        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();
        }
Ejemplo n.º 6
0
        public static void CreateHistoryLearningDB(HistoryLearning history)
        {
            var db = new AppG2Context();

            history.IDHistoryLearning = Guid.NewGuid().ToString();
            db.HistoryLearningDbset.Add(history);
            db.SaveChanges();
        }
        //Database
        public static Student GetStudentDB(string idStudent)
        {
            var db = new AppG2Context();

            //e là 1 sinh viên, lấy mã sinh viên so sánh trùng
            return(db.StudentDbset.Where(e => e.IDStudent == idStudent).FirstOrDefault());
            //first or default: lấy thằng đầu tiên hoặc null
        }
Ejemplo n.º 8
0
        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();
        }
Ejemplo n.º 9
0
        public static List <Student> GetAllStudentDB(string key = null)
        {
            var db = new AppG2Context();

            if (key == null)
            {
                key = "";
            }
            return(db.StudentDbset.Where(e => e.FirstName.Contains(key) || e.LastName.Contains(key) || e.POB.Contains(key)).ToList());
        }
Ejemplo n.º 10
0
        public static List <Contact> GetContactDB(User user, string key = null)
        {
            var db = new AppG2Context();

            if (key == null)
            {
                key = "";
            }
            return(db.ContactDbset.Where(e => (e.UserName == user.UserName) && ((e.NameContact.Contains(key)) || (e.Email.Contains(key)) || (e.Phone.Contains(key)))).OrderBy(e => e.NameContact).ToList());
        }
Ejemplo n.º 11
0
        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();
        }
Ejemplo n.º 12
0
        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();
        }
Ejemplo n.º 13
0
        public static Boolean ExistPhoneOrEmail(string phone, string email, string username, string idcontact)
        {
            var db = new AppG2Context();
            var ct = db.ContactDbset.Where(e => (e.ID != idcontact) && (((e.Phone == phone) || (e.Email == email)) && e.UserName == username)).FirstOrDefault();

            if (ct != null)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 14
0
        public static Boolean CheckLogin(User user)
        {
            var db = new AppG2Context();
            var us = db.UserDbset.Where(e => (e.UserName == user.UserName) && (e.PassWord == user.PassWord)).FirstOrDefault();

            if (us != null)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 15
0
        public static User login(string username, string password)
        {
            var db   = new AppG2Context();
            var user = db.UserDbset.Where(e => e.Username == username && e.Password == password).FirstOrDefault();

            if (user != null)
            {
                return(user);
            }
            return(null);
        }
Ejemplo n.º 16
0
        //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 idContact)
        {
            var db           = new AppG2Context();
            var itemToRemove = db.ContactDbset.SingleOrDefault(x => x.iDContact.Equals(idContact));

            if (itemToRemove != null)
            {
                db.ContactDbset.Remove(itemToRemove);
                db.SaveChanges();
            }
        }
Ejemplo n.º 18
0
        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();
        }
Ejemplo n.º 19
0
        /****************************ĐÂY LÀ DB******************************/
        public static List <Contacts> GetContactDB(User user, string search = null)
        {
            var db = new AppG2Context();

            if (search == null)
            {
                search = "";
            }
            return(db.ContactsDbset.
                   Where(e => (e.Username == user.Username) && ((e.Name.Contains(search)) || (e.Email.Contains(search)) || (e.Phone.Contains(search)))).
                   OrderBy(e => e.Name).
                   ToList());
        }
        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();
        }
Ejemplo n.º 22
0
        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);
        }
Ejemplo n.º 23
0
        //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();
        }
Ejemplo n.º 24
0
        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();
            //}
        }
Ejemplo n.º 25
0
        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();
        }
Ejemplo n.º 26
0
        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);
        }
Ejemplo n.º 27
0
        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");
                }
            }
        }
        public static List <HistoryLearning> GetHistoryLearningDB(string idStudent)
        {
            var db = new AppG2Context();

            return(db.HistoryLearningDbset.Where(e => e.IDStudent == idStudent && e.YearFrom > 2007).OrderBy(e => e.YearFrom).ToList());
        }
Ejemplo n.º 29
0
        public static User checkUser(string userName, string password)
        {
            var db = new AppG2Context();

            return(db.UserDbset.Where(e => (e.userName == userName && e.pasword == password)).FirstOrDefault());
        }
Ejemplo n.º 30
0
        public static Diem GetDiemByIDStudentAndIDMonHoc(string IDStudent, string IDMonHoc)
        {
            var db = new AppG2Context();

            return(db.DiemDbset.Where(e => e.IDStudent == IDStudent && e.IDMonHoc == IDMonHoc).FirstOrDefault());
        }