Ejemplo n.º 1
0
def delete_car():
    sql_command = 'DELETE FROM Cars WHERE idCars=%s' % (idCar_input_c.get())
    confirmation = messagebox.askyesno(
        title='Подтверждение',
        message='Вы действительно хотите удалить машину с № %s' %
        (idCar_input_c.get()))
    if confirmation:
        db.execute(sql_command)
        db.commit()
        messagebox.showinfo('', 'Данные успешно удалены!')
Ejemplo n.º 2
0
def add_car():
    idColor = db.get_idcolor(color_input.get())
    idModel = db.get_idModel(model_name_input.get())
    idBody_type = db.get_idBody_type(body_type_input.get())

    sql_command = 'INSERT INTO Cars(Transmition, Mileage, PTC, Price, Year_of_issue, Engine_capacity, Color_idColor, Body_type_idBody_type, Model_idModel) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s)'
    values = (transmition_input.get(),
              mileage_input.get(), num_ptc_input.get(), price_input.get(),
              year_issue_input.get(), float(engine_capacity_input.get()),
              int(idColor), int(idBody_type), int(idModel))
    db.execute(sql_command, values)

    # commit changes
    db.commit()
    messagebox.showinfo('', 'Машина добавлена!')
Ejemplo n.º 3
0
def search_car():
    sql_command = "SELECT * FROM Cars WHERE "
    where_clauses = []
    if not (color_input_s.get() == ''):
        idColor = db.get_idcolor(color_input_s.get())
    else:
        idColor = ''

    if not (model_name_input_s.get() == ''):
        idModel = db.get_idModel(model_name_input_s.get())
    else:
        idModel = ''

    if not (body_type_input_s.get() == ''):
        idBody_type = db.get_idBody_type(body_type_input_s.get())
    else:
        idBody_type = ''

    transmition = transmition_input_s.get()
    mileage = mileage_input_s.get()
    engineCapacity = engine_capacity_input_s.get()
    year = year_issue_input_s.get()
    price = price_input_s.get()

    car_dict = create_dict(idModel, idBody_type, transmition, idColor, mileage,
                           engineCapacity, year, price)
    for key in car_dict.keys():
        if not (car_dict.get(key) == None or car_dict.get(key) == ''):
            where_clauses.append(key + "=" + "'" + car_dict.get(key) + "'")
    where_clauses = ' AND '.join(where_clauses)

    db.execute(sql_command + where_clauses)
    result = [i for i in mycursor]
    if result:
        for i in result:
            if db.check_availability(i) == None:
                txt.insert(INSERT, display_result(i) + '\n')
    else:
        messagebox.showinfo('Ошибка',
                            "Машина с такими характеристиками отсутствует!")
Ejemplo n.º 4
0
def update_car():
    sql_command = 'UPDATE Cars SET %s WHERE idCars=%s'
    idCar = idCar_input_c.get()

    set_clauses = []
    if not (color_input.get() == ''):
        idColor = db.get_idcolor(color_input.get())
    else:
        idColor = ''

    if not (model_name_input.get() == ''):
        idModel = db.get_idModel(model_name_input.get())
    else:
        idModel = ''

    if not (body_type_input.get() == ''):
        idBody_type = db.get_idBody_type(body_type_input.get())
    else:
        idBody_type = ''

    transmition = transmition_input.get()
    mileage = mileage_input.get()
    engineCapacity = engine_capacity_input.get()
    year = year_issue_input.get()
    price = price_input.get()

    car_dict = create_dict(idModel, idBody_type, transmition, idColor, mileage,
                           engineCapacity, year, price)
    for key in car_dict.keys():
        if not (car_dict.get(key) == None or car_dict.get(key) == ''):
            set_clauses.append(key + "=" + "'" + car_dict.get(key) + "'")
    set_clauses = ', '.join(set_clauses)
    print(sql_command % (set_clauses, int(idCar)))
    if idCar:
        db.execute(sql_command % (set_clauses, int(idCar)))
        db.commit()
        messagebox.showinfo('', 'Данные успешно изменены!')
    else:
        messagebox.showinfo('Ошибка!',
                            'Для изменения необходимо ввести номер машины!')
Ejemplo n.º 5
0
def make_order():
    sql_command = "INSERT INTO Orders(Data_of_sale, Cars_idCars, \
                                      Clients_idClients, Customers_idCustomers, \
                                      Form_of_payment_idForm_of_payment) VALUES(%s, %s, %s, %s, %s)"

    customer_firstName = customer_firstName_input.get()
    customer_lastName = customer_lastName_input.get()
    passport_data = passport_data_input.get()
    phone = phone_input.get()
    seller_firstName = seller_firstName_input.get()
    seller_lastName = seller_lastName_input.get()
    seller_position = seller_position_input.get()
    payment_form = payment_form_input.get()
    idseller = idseller_input.get()

    date = datetime.date.today().year

    if not check_car(idCar_input.get()):
        idCar = None
        messagebox.showinfo('Ошибка', 'Машина уже продана')
    else:
        idCar = idCar_input.get()

    idClient = db.get_idClients(passport_data)
    if idClient == None:
        add_client(passport_data, customer_firstName, customer_lastName, phone)
        idClient = db.get_idClients(passport_data)

    idForm_of_payment = db.get_idform_payment(payment_form)
    values = (date, idCar, idClient, idForm_of_payment, idseller)
    val = []
    for data in values:
        if not data == None:
            val.append(data)
    if len(val) == len(values):
        db.execute(sql_command, values)
        db.commit()
        messagebox.showinfo("", "Заказ оформлен!")
    else:
        messagebox.showinfo("Ошибка!", "Все поля должны быть заполнены!")
Ejemplo n.º 6
0
def modify_str(order_data):
    modified_data = between_markers(str(order_data), '(', ')')
    values = str(modified_data).split(',')
    idCar, idClient, idCustomer, idform_payment = values[-4:]
    db.execute("SELECT Model_idModel FROM Cars WHERE idCars='%s'" % (idCar))
    for x in mycursor:
        idModel = ''.join([str(i) for i in list(x)])
    models_name = db.get_model_name(int(idModel))
    client_firstName = db.get_client_firstname(int(idClient))
    customer_firstName = db.get_customer_firstname(int(idCustomer))
    payment_name = db.get_payment_name(int(idform_payment))

    values = values[:-4] + [
        models_name, client_firstName, customer_firstName, payment_name
    ] + ['\n']
    key = [
        '№: ', "Год продажи: ", "Марка: ", "Фамилия клиента: ",
        "Фамилия продавца: ", "Форма оплаты: "
    ]
    order_row = {key[i]: values[i] for i in range(len(key))}
    order_string = ' '
    for key in order_row.keys():
        order_string += key + order_row[key] + ' '
    return order_string
Ejemplo n.º 7
0
def get_idcar(value):
    idCar = None
    db.execute('SELECT idOrders FROM Orders WHERE Cars_idCars="%s"' % (value))
    for x in mycursor:
        idCar = ''.join([str(i) for i in list(x)])
    return idCar
Ejemplo n.º 8
0
def add_client(passport_data, customer_firstName, customer_lastName, phone):
    sql_command = "INSERT INTO Clients(Firstname, Lastname, Passport_data, Phone_num) VALUES(%s, %s, %s, %s)"
    values = (customer_firstName, customer_lastName, passport_data, phone)
    db.execute(sql_command, values)
    db.commit()