//Xóa khách hàng public bool DeleteCustomer(string pPhone) { if (acc.IsAccount(pPhone) == 0) { return(false);//Chưa tồn tại khách hàng cần xóa } else { int del = acc.DeleteAccount(pPhone); if (del == 1) { DC_CustomerDataContext cus = new DC_CustomerDataContext(); var query = from c in cus.PROFILEs where c.PHONE.ToString().Equals(pPhone) == true select c; foreach (PROFILE item in query) { item.STATUS = 0; } cus.SubmitChanges(); return(true); } } return(false); }
//Đổi mật khẩu public bool ChangePass(string pUserName, string pPassNew, string pPassOld) { try { DC_CustomerDataContext dc = new DC_CustomerDataContext(); var query = from acc in dc.ACCOUNTs where string.Equals(acc.USERNAME, pUserName) == true select acc; foreach (ACCOUNT item in query) { if (string.Equals(item.PASSWORD, mh.EncodePass(pPassOld))) { item.PASSWORD = mh.EncodePass(pPassNew); } else { return(false); } } dc.SubmitChanges(); return(true);//Cap nhat thanh cong } catch { return(false); } }
//Lấy ID loại KH public int GetID_TypeCus(string pNameType) { int typecus = 0; DC_CustomerDataContext cus = new DC_CustomerDataContext(); var query = from c in cus.TYPE_CUSTOMERs where c.NAME_TYPE.ToString().Equals(pNameType) == true select c; foreach (TYPE_CUSTOMER item in query) { typecus = item.ID_TYPE_CUS; } return(typecus); }
//Thêm khách hàng đồng thời tạo tài khoản khách hàng ID: Số đt KH, Pass : CMND (Mặc định) public int InsertCustomer(string pID, string pLastName, string pFirstName, string pSex, string pPhone, string pAddress, int pTypeCus) { //B1 thêm tài khoản cho khách hàng //Username: Số đt khách hàng, Password: CMND khách hàng if (acc.IsAccount(pPhone) != 0) { return(1);//Tồn tại tài khoản } else { int idUser = acc.InsertAccount(pPhone, pID);//thêm thành công sẽ trả về ID_USER vừa thêm if (idUser != 0) { DC_CustomerDataContext cus = new DC_CustomerDataContext(); PROFILE profile = new PROFILE(); PROFILE_CUSTOMER pro_cus = new PROFILE_CUSTOMER(); int number = GetIDMaxProFile() + 1; profile.ID_PROFILE = number; profile.ID_USER = idUser; profile.IDENFITICATION = pID; profile.LAST_NAME = pLastName; profile.FIRST_NAME = pFirstName; profile.SEX = pSex; profile.PHONE = pPhone; profile.ADDRESS = pAddress; profile.STATUS = 1; pro_cus.ID_PROFILE_CUSTOMER = GetIDMaxProFileTypeCus() + 1; pro_cus.ID_PROFILE = number; pro_cus.ID_TYPE_CUS = pTypeCus; pro_cus.SCORE = 0; cus.PROFILEs.InsertOnSubmit(profile); cus.PROFILE_CUSTOMERs.InsertOnSubmit(pro_cus); cus.SubmitChanges(); return(2);//Thêm thành công } else { return(3);//thêm thất bại } } }
//Xóa tài khoản,Tại đây thực chất cho khóa tài khoản đồng nghĩa với việc dữ liệu tk vẫn còn public int DeleteAccount(string pUserName) { if (IsAccount(pUserName) == 1) { DC_CustomerDataContext account = new DC_CustomerDataContext(); var query = from acc in account.ACCOUNTs where acc.USERNAME.ToString().Equals(pUserName) == true select acc; foreach (ACCOUNT item in query) { item.STATUS = 0; } account.SubmitChanges(); return(1);//Tài khoản bị khóa đồng nghĩa việc xóa tài khoản } else { return(0);//Không tồn tại tài khoản } }
//Thêm tài khoản public int InsertAccount(string pUserName, string pPass) { if (IsAccount(pUserName) == 0) { DC_CustomerDataContext account = new DC_CustomerDataContext(); ACCOUNT temp = new ACCOUNT(); temp.ID_USER = GetIDMax() + 1; temp.USERNAME = pUserName; temp.PASSWORD = mh.EncodePass(pPass); temp.STATUS = 0; account.ACCOUNTs.InsertOnSubmit(temp); account.SubmitChanges(); return(GetIDMax());//Cho thêm tài khoản, trả về ID_USER mới vừa thêm } else { return(0);//Khách hàng đã tạo tài khoản } }
//Thêm nhóm khách hàng public bool InsertGroupCustomer(string pNameGroup) { if (IsGroupCustomer(pNameGroup)) { //Cho thêm int numberID = MaxIDType() + 1; DC_CustomerDataContext typeCus = new DC_CustomerDataContext(); TYPE_CUSTOMER temp = new TYPE_CUSTOMER(); temp.ID_TYPE_CUS = numberID; temp.NAME_TYPE = pNameGroup; temp.STATUS = 0; typeCus.TYPE_CUSTOMERs.InsertOnSubmit(temp); typeCus.SubmitChanges(); return(true); } else { return(false); } }
//Cập nhật thông tin khách hàng public bool UpdateCustomer(string pIDProfile, string pID, string pLastName, string pFirstName, string pSex, string pPhone, string pAddress, int pTypeCus, DateTime pBirtday) { try { DC_CustomerDataContext customer = new DC_CustomerDataContext(); var q1 = from cus in customer.PROFILEs where cus.ID_PROFILE == Int32.Parse(pIDProfile) select cus; var q2 = from c in customer.PROFILE_CUSTOMERs where c.ID_PROFILE == Int32.Parse(pIDProfile) select c; foreach (PROFILE cus in q1) { cus.LAST_NAME = pLastName; cus.FIRST_NAME = pFirstName; cus.SEX = pSex; cus.ADDRESS = pAddress; cus.IDENFITICATION = pID; cus.PHONE = pPhone;//có 2 hướng 1 là cập nhật lại UserName, 2 là không cập nhật vẫn được } foreach (PROFILE_CUSTOMER cus in q2) { cus.ID_TYPE_CUS = pTypeCus; } customer.SubmitChanges(); return(true); } catch { return(false); } }