Example #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('', 'Данные успешно удалены!')
Example #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('', 'Машина добавлена!')
Example #3
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('Ошибка!',
                            'Для изменения необходимо ввести номер машины!')
Example #4
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("Ошибка!", "Все поля должны быть заполнены!")
Example #5
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()