Example #1
0
def save_infor():
    if request.method == 'POST':

        data = request.get_json()

        # save csdl

        filename = None
        if ("avt" not in data.keys()):
            # update in csdl
            res = {}
            res['status'] = 'Vui lòng tải ảnh avatar'

            return jsonify(res)
        elif ("cmtnd1" not in data.keys()) or ("cmtnd2" not in data.keys()):
            res = {}
            res['status'] = 'Vui lòng upload ảnh chứng minh thư nhân dân'

            return jsonify(res)
        elif "avt" in data.keys():

            check, filename = have_face(data["avt"])
            # print(check, filename)
            if check == False:
                res = {}
                res['status'] = 'Upload ảnh có khuôn mặt để sử dụng chức năng điểm danh'

                return jsonify(res)
            else:
                print("Lưu vào CSDL")
                # save thông in vào cớ ở dữ liệu
                query_update = "UPDATE dbo.ThanhVien SET CMND = '" + data[
                    'cmtnd'] + "', DiaChi = N'" + data[
                        'diachi'] + "', Tinh = N'" + data[
                            'tinh'] + "', Activate = 1 WHERE Id = " + data[
                                'id'] + ";"

                sql = SQL_Server()
                sql.insert(query_update)

                del sql  #

                sql = SQL_Server()  #
                query_insert = "INSERT INTO dbo.NhanVien VALUES(N'{}', N'{}', {}, {}, {}, '{}', '{}', '{}', {});"
                query_insert = query_insert.format(data['vitri'], "Nhân viên",
                                                   100, 0, 1.2, data['avt'],
                                                   data['cmtnd1'],
                                                   data['cmtnd2'], data['id'])

                # print(query_insert)
                sql.insert(query_insert)

                t1 = threading.Thread(target=extract_faceID,
                                      args=(filename, data['id']))
                t1.start()

                res = {}
                res['status'] = 'Cập nhật thông tin thành công'

                return jsonify(res)
Example #2
0
def dataAccount():
    if request.method == 'POST':
        data = request.get_json()

        sql = SQL_Server()
        query = "SELECT * FROM db_Credit_TheUnlimited.dbo.ThanhVien WHERE (Email = '" + data[
            'email'] + "' OR Sdt = '" + data[
                'sdt'] + "' OR Username = '******'username'] + "')"
        tmp = sql.select(query)
        res = {}
        if len(list(tmp)) > 0:

            res['status'] = "Email hoặc số điện thoại hoặc tài khoản đã tồn tài trong CSDL"

        else:
            res['status'] = 'Tạo tài khoản: ' + data['username'] + " thành công"

            query = "INSERT INTO db_Credit_TheUnlimited.dbo.ThanhVien VALUES ( N'" + data[
                'hoten'] + "', ' ' ,' ', ' ', '" + data[
                    'username'] + "', '" + data['password'] + "', '', '" + data[
                        'email'] + "', '" + data['sdt'] + "', '0', '2')"
            sql.insert(query)

        return jsonify(res)

    else:
        return "Không hỗ trợ phương thức GET"
Example #3
0
def extract_faceID(filename, id):
    print("BAT DAU LAY THONG TIN FACE ID")
    img = cv2.imread(filename)
    embedder = FaceNet()
    detector = MTCNN()
    data = []
    faces = detector.detect_faces(img)
    for face in faces:
        st = (face['box'][0], face['box'][1])
        en = (face['box'][0] + face['box'][2], face['box'][1] + face['box'][3])
        data.append(img[st[1]:en[1], st[0]:en[0]])
        break
    vt = embedder.embeddings(data)[0]

    # save to database
    sql = SQL_Server()

    query = "INSERT INTO dbo.FaceID VALUES (" + str(id)

    for i in vt:
        query += " , " + str(i)

    query += ")"

    # print(query)
    sql.insert(query)

    print("ADD FACE ID INTO CSDL THANH CÔNG")
Example #4
0
def datahosothem():
    data = request.get_json()
    # print(data)
    sql = SQL_Server()
    query1 = "SELECT dbo.KhachHang.Id FROM dbo.ThanhVien, dbo.KhachHang "
    query1 += " WHERE dbo.ThanhVien.Id =  dbo.KhachHang.ThanVienID "
    query1 += " AND dbo.ThanhVien.CMND ='" + str(data['cmnd']) + "'"
    # print(query1)
    data_id_kh = sql.select(query1)
    del sql
    sql = SQL_Server()
    query1 = "SELECT dbo.PhongGiaoDich.Id FROM dbo.ThanhVien, dbo.PhongGiaoDich "
    query1 += " WHERE dbo.ThanhVien.Tinh =  dbo.PhongGiaoDich.Tinh "
    query1 += " AND dbo.ThanhVien.Id = " + str(data['id'])
    data_id_pgd = sql.select(query1)
    # print(data['giatri'])/
    # print(data['thoihan'])
    stmoithang = float(data['giatri'])
    thoihan = float(data['thoihan'])
    tmp = stmoithang * 0.015
    stmoithang += tmp - float(data['tratruoc'])
    stmoithang = stmoithang / thoihan
    query_insertTv = "INSERT INTO dbo.HopDongTraGop (NgayMoHD, TenSP, Giatri, ThoiHan, Tratruoc, Moithang, Laisuat, KhacHangID, PGDId, Activate) VALUES ('{}', N'{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}')"
    query_insertTv1 = query_insertTv.format(data['nmhd'], data['tsp'],
                                            data['giatri'], data['thoihan'],
                                            data['tratruoc'], stmoithang, 0.15,
                                            data_id_kh[0][0],
                                            data_id_pgd[0][0], 1)
    sql.insert(query_insertTv1)
    ress = {}
    del sql
    sql = SQL_Server()
    query = "SELECT dbo.ThanhVien.HoTen, dbo.ThanhVien.CMND, dbo.HopDongTraGop.Giatri, dbo.ThanhVien.Email, dbo.ThanhVien.Sdt FROM dbo.ThanhVien, dbo.HopDongTraGop, dbo.KhachHang "
    query += " WHERE dbo.HopDongTraGop.Activate = 1 "
    query += " AND dbo.HopDongTraGop.KhacHangID = dbo.KhachHang.Id "
    query += " AND dbo.KhachHang.ThanVienID = dbo.ThanhVien.Id"
    res = sql.select(query)
    del sql
    if len(res) == 0:
        ress['status'] = "no"
    else:
        ress['status'] = "yes"
    tmp_res = {}
    tmp_data = []
    ii = 1
    for row in res:
        tmp_data.append([ii, row[0], row[1], row[2], row[4], row[3]])
        ii = ii + 1
    i = 0
    for row in tmp_data:
        tmp_res[str(i)] = [str(i) for i in row]
        i = i + 1
    ress['data'] = tmp_res
    return jsonify(ress)
Example #5
0
def khachHang():
    if request.method == 'POST':
        data = request.get_json()

        sql = SQL_Server()
        insert_kh = "INSERT INTO dbo.KhachHang(Chungthuctaisan, Diem, ThanVienID) VALUES('{}', '{}', '{}')"
        insert_khFn = insert_kh.format(data["luong"], 100, data["id_tv"])

        sql.insert(insert_khFn)

    res = {}
    res['status'] = "Đã tạo tài khoản khách hàng thành công!"
    return jsonify(res)
Example #6
0
def deactiveKH():
    sql = SQL_Server()
    data = request.form['khachhang']
    id = data.split(' ')
    data = id[-1]
    tmp = id[0]
    query1 = "UPDATE dbo.ThanhVien SET Activate = " + str(
        tmp
    ) + " FROM dbo.ThanhVien INNER JOIN dbo.KhachHang ON (dbo.ThanhVien.Id = dbo.KhachHang.ThanVienID) WHERE dbo.KhachHang.Id = " + str(
        data)
    print(query1)
    sql.insert(query1)
    ress = {}
    ress['status'] = "no"
    return jsonify(ress)
Example #7
0
def predict():
    if request.method == 'POST':
        res = {}
        data = request.get_json()

        sql = SQL_Server()
        handel = Handel()
        ten = handel.handel_Hoten(data["hoten"])

        query_check_email = "SELECT * FROM dbo.ThanhVien WHERE Email = '{}' OR CMND = '{}' OR Sdt = '{}'"
        query_check_email = query_check_email.format(data['email'],
                                                     data['cmt'], data['sdt'])
        if (len(list(sql.select(query_check_email))) > 0):
            res['check_email'] = "Email/CMDN/Số điện thoại đã được sử dụng"
            return jsonify(res)
        else:
            username = handel.get_username(ten)
            password = handel.get_password()
            query_insertTv = "INSERT INTO dbo.ThanhVien (HoTen, CMND, DiaChi, Tinh, Username, Password, Nsinh, Email, Sdt, Loai, Activate) VALUES (N'{}', '{}', N'{}', '{}', N'{}', '{}', '{}', '{}', '{}', '{}', '{}')"
            query_insertTv1 = query_insertTv.format(data["hoten"], data["cmt"],
                                                    data["dia_chi"],
                                                    data["tinh"], username,
                                                    password, data["ngaysinh"],
                                                    data["email"], data["sdt"],
                                                    1, 1)
            # print(query_insertTv1)

            sql.insert(query_insertTv1)

            cursor = sql.select(query_check_email)
            for i in cursor:
                idTv = i[0]

            sdt = str(data["sdt"])
            sdt = sdt[1:]
            sdt = "+84" + sdt
            print(sdt)
            mess = 'Your Account The Unlimted \n username: {} \n password: {}'
            mess = mess.format(username, password)
            t1 = threading.Thread(target=send_sms, args=(sdt, mess))
            t1.start()

            res['id_tv'] = idTv
            res['username'] = username
            res['password'] = password

            return jsonify(res)
Example #8
0
def addthanhtoanTG():
    # print("da vao add thanh toan")
    dataAddthanhtoanTG = request.get_json()
    sql = SQL_Server()

    insert_ttTG = "INSERT INTO dbo.ThanhToanHDTG(NgayTT, Thang, Sotien, Noidung, KhacHangID, HDTGId) VALUES('{}', '{}', '{}', N'{}', '{}', '{}')"
    insert_ttTGFn = insert_ttTG.format(dataAddthanhtoanTG["date"],
                                       dataAddthanhtoanTG["thang"],
                                       dataAddthanhtoanTG["sotien"],
                                       dataAddthanhtoanTG["noidung"],
                                       dataAddthanhtoanTG["khachhangid"],
                                       dataAddthanhtoanTG["HDTGid"])
    sql.insert(insert_ttTGFn)
    # print("da insert xong")

    res = {}
    return jsonify(res)