コード例 #1
0
def AddNewSwitch(SwitchID, Location="", IPv4Address="", IPv6Address="", Notes=""):
    database = sqlite3.connect(ReadSettings.GetSetting("Database","DatabaseLocation"))
    cursor = database.cursor()

    cursor.execute("""INSERT INTO SWITCHES (SwitchName, Location, IPv4Address, IPv6Address, Notes) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}')""".format(SwitchID, Location, IPv4Address, IPv6Address, Notes))

    database.commit()
    database.close()
コード例 #2
0
def GetLocations():
    database = sqlite3.connect(ReadSettings.GetSetting("Database","DatabaseLocation"))
    cursor = database.cursor()

    cursor.execute("""SELECT DISTINCT Location FROM SWITCHES""")
    Result = cursor.fetchall()
    database.close()
    return (Result)
コード例 #3
0
def SearchPatch(SearchTerms):
    database = sqlite3.connect(ReadSettings.GetSetting("Database","DatabaseLocation"))
    cursor = database.cursor()
    cursor.execute("""SELECT * FROM PATCHES WHERE{0}""".format(SearchTerms))
    Result = cursor.fetchall()
    database.close()
    print(Result)
    return Result
コード例 #4
0
def GetTechNameFromID(ID):
    database = sqlite3.connect(ReadSettings.GetSetting("Database","DatabaseLocation"))
    cursor = database.cursor()

    cursor.execute("""SELECT Tech FROM TECHS WHERE TECHS_id = "{0}" """.format(ID))
    Result = cursor.fetchall()
    database.close()

    return str((Result[0])[0])
コード例 #5
0
def GetTechNames():
    database = sqlite3.connect(ReadSettings.GetSetting("Database","DatabaseLocation"))
    cursor = database.cursor()

    cursor.execute("""SELECT Tech FROM TECHS""")
    Result = cursor.fetchall()
    database.close()

    return(Result)
コード例 #6
0
def GetSwitchIDFromLocation(Location):
    database = sqlite3.connect(ReadSettings.GetSetting("Database","DatabaseLocation"))
    cursor = database.cursor()

    cursor.execute("""SELECT SWITCHES_id FROM SWITCHES WHERE Location = "{0}" """.format(Location))
    Result = cursor.fetchall()
    database.close()

    return (Result)
コード例 #7
0
def GetSwitchLocationFromID(ID):
    database = sqlite3.connect(ReadSettings.GetSetting("Database","DatabaseLocation"))
    cursor = database.cursor()

    cursor.execute("""SELECT Location FROM SWITCHES WHERE SWITCHES_id = "{0}" """.format(ID))
    Result = cursor.fetchall()
    database.close()

    return str((Result[0])[0])
コード例 #8
0
def CustomQuery(Query):
    database = sqlite3.connect(ReadSettings.GetSetting("Database","DatabaseLocation"))
    cursor = database.cursor()

    cursor.execute("""{0}""".format(Query))
    Result = cursor.fetchall()

    database.commit()
    database.close()

    return(Result)
コード例 #9
0
def AddPatch(Tech,Switch,PannelPort,SwitchUnit,SwitchPort,PatchType,Date,Notes):
    database = sqlite3.connect(ReadSettings.GetSetting("Database","DatabaseLocation"))
    cursor = database.cursor()

    if PatchType == "New":
        AlreadyPatched=0
        PatchRemoved=0
    elif PatchType == "Existing":
        AlreadyPatched=1
        PatchRemoved=0
    elif PatchType == "Removal":
        AlreadyPatched=1
        PatchRemoved=1
    
    cursor.execute("""INSERT INTO PATCHES ({0}) VALUES ("{1}","{2}","{3}","{4}","{5}","{6}","{7}","{8}","{9}")""".format(GetTablesColumns("PATCHES",cursor),Tech,Switch,PannelPort,SwitchUnit,SwitchPort,Date,Notes,AlreadyPatched,PatchRemoved))
    database.commit()
    database.close()
コード例 #10
0
def SetupDatabase():
    database = sqlite3.connect(
        ReadSettings.GetSetting("Database", "DatabaseLocation"))
    cursor = database.cursor()

    CreateTable("TECHS", "Tech varchar(255)", cursor)
    CreateTable("ENDUSERS", "EndUser varchar(255)", cursor)
    CreateTable(
        "SWITCHES",
        "SwitchName varchar(255), Location varchar(255), IPv4Address varchar(15), IPv6Address varchar(39), Notes varchar(255)",
        cursor)
    CreateTable(
        "PATCHES",
        "tech_id INTEGER, switch_id INTEGER, PannelPort varchar(255), Unit INTEGER, Port INTEGER, Date varchar(10), Notes varchar(255), AlreadyPatched BOOLEAN, PatchRemoved BOOLEAN",
        cursor)

    database.commit()
    database.close()
コード例 #11
0
ファイル: register.py プロジェクト: ddavedd/Register
    def __init__(self, master, init_file_name, scale):
        """Initiate all variables for the register program"""
        try:
            init_file = open(init_file_name)
        except IOError:
            print "Couldn't find initiation file for configuring register"
        self.employee_discount_enabled = False
        self.values_dict = ReadSettings.get_values_from_init_file(init_file)
        print self.values_dict
        # Radio variable for 
        #self.radio_variable = Tkinter.IntVar()
        #self.radio_variable.set(0) # Set to grove initially
        self.scale = scale
        self.master = master
        self.cashierVar = Tkinter.StringVar()
        self.cashierVar.set(self.values_dict["register_name"])
        self.cart = []    
        self.items = []
        self.products = []
        self.categories = []
        self.prod_cats = []
        self.prod_prices = []
        self.deals = []
        self.deal_prices = []
        self.current_category_id = 1
        self.start_time = time.time()
        
        cursor, conn = DatabaseConnect.connect(self.values_dict)
        # Early exit if can't connect to database
        if cursor is None:
            tkMessageBox.showwarning("Database Error", "Could not connect to database, check errors on terminal")
            new_ip_address = tkSimpleDialog.askstring("Manual ip address entry", "Enter ip address of host to connect to (127.0.0.1 if can't connect to network)")
            
            if new_ip_address is not None:
               self.values_dict["database_path"] = new_ip_address 
               cursor, conn = DatabaseConnect.connect(self.values_dict)
               print "Tried connecting to manual ip address " + new_ip_address
               if cursor is None:
                  tkMessageBox.showwarning("Manual ip entry failure", "Failed to connect to manual ip address, closing")
                  master.destroy()
                  return
            else:
               master.destroy()
               return
        
        # read product ordering in category preferences
        
        self.category_order_dict = read_category_order.read_category_order()

        self.products_db_cursor = cursor
        self.products_db_connect = conn
         
        self.update_info_from_database()
        self.transaction_number = 0
        self.read_products_categories_constants()
                
        application_height = int(self.values_dict["application_height"])
        application_width = int(self.values_dict["application_width"])
        self.edible_tax_rate = float(self.values_dict["edible_tax_rate"])
        self.nonedible_tax_rate = float(self.values_dict["nonedible_tax_rate"])
        
        self.products_width = int(self.values_dict["products_width"])
        self.cart_width = int(self.values_dict["cart_width"])
        
        # Inside products frame, eventually read these from a file
        information_height = int(self.values_dict["information_height"])
        categories_height = int(self.values_dict["categories_height"])
        items_height = int(self.values_dict["items_height"])
        debug_height = int(self.values_dict["debug_height"])
                
        #Inside cart frame
        cart_info_height = int(self.values_dict["cart_info_height"])
        cart_items_height = int(self.values_dict["cart_items_height"])
        totals_height = int(self.values_dict["totals_height"])
        payment_type_height = int(self.values_dict["payment_type_height"])
        #Receipt info
        self.receipt_chars_per_inch = int(self.values_dict["receipt_chars_per_inch"])
        print self.receipt_chars_per_inch
        
        self.master.resizable(False,False)
        
        self.products_frames = 0
        self.cart_frames = 0
        self.master_frame = Tkinter.Frame(master)
       
        self.master_frame.grid()
        
        # EXP ---
        #self.secondary_cart = Tkinter.Toplevel(master)
        #self.secondary_cart.title("Customer Cart View")
        #self.secondary_cart.resizable(False,False)
        #self.secondary_cart.protocol("WM_DELETE_WINDOW", self.secondary_cart.iconify)
        #self.secondary_cart.grid()
        #self.secondary_cart_frames = 0
        # EXP ---
        
        #Removed functionality, possibly read later but not unless necessary
        self._shift_is_pressed = False
        self.master_frame.bind_all("<Shift_L>", self._shift_pressed)
        self.master_frame.bind_all("<KeyRelease-Shift_L>", self._shift_released)
                
                
        assert application_height == information_height + categories_height + items_height + debug_height
        assert application_height == cart_info_height + cart_items_height + totals_height + payment_type_height
        assert application_width == self.products_width + self.cart_width
        if CART_RIGHT:
            products_frame_column = 0
            cart_frame_column = 1
        else:
            products_frame_column = 1
            cart_frame_column = 0
        self.products_frame = add_frame(self.master_frame, self.products_width, application_height, "gray", 0, products_frame_column)
        self.cart_frame = add_frame(self.master_frame, self.cart_width, application_height, "gray", 0, cart_frame_column)
    
        # Products frame additions
        self.information_frame = self.add_products_frame(information_height, self.values_dict["information_frame_color"])
        self.category_frame = self.add_products_frame(categories_height, self.values_dict["categories_frame_color"])
        self.items_frame = self.add_products_frame(items_height, self.values_dict["items_frame_color"])
        self.debug_frame = self.add_products_frame(debug_height, self.values_dict["debug_frame_color"])

        # Cart frame additions
        self.payment_type_frame = self.add_cart_frame(payment_type_height, self.values_dict["payment_type_frame_color"])
        self.cart_info_frame = self.add_cart_frame(cart_info_height, self.values_dict["cart_info_frame_color"])
        self.cart_items_frame = self.add_cart_frame(cart_items_height, self.values_dict["cart_items_frame_color"])
        self.totals_frame = self.add_cart_frame(totals_height, self.values_dict["totals_frame_color"])
        
        # EXP ---
        # Secondary cart additions
        # self.secondary_cart_items_frame = self.add_secondary_cart_frame(cart_items_height, self.values_dict["cart_items_frame_color"])
        # self.secondary_totals_frame = self.add_secondary_cart_frame(totals_height, "gray")
        # EXP ---
        
        #self.update_admin_frame()
        self.update_category_frame()
        self.update_products_frame()
        self.update_cart()
        self.update_payment_frame()            
        self.update_debug_frame()
コード例 #12
0
def CheckDatabaseExists():
    if os.path.exists(ReadSettings.GetSetting("Database","DatabaseLocation")):
        return True
    else:
        return False
コード例 #13
0
def AddNewTech(Name):
    database = sqlite3.connect(ReadSettings.GetSetting("Database","DatabaseLocation"))
    cursor = database.cursor()
    cursor.execute("""INSERT INTO TECHS (Tech) VALUES ("{0}") """.format(Name))
    database.commit()
    database.close()
コード例 #14
0
    cursor.execute("SELECT max(transaction_id) FROM transaction_total")        
    for max_transaction_number_row in cursor:
        max_trans_number = max_transaction_number_row[0]
        
    if max_trans_number is None:
        max_trans_number = 1
    else:
        return max_trans_number + 1
    
try:
    init_file_name = "settings.txt"
    init_file = open(init_file_name)
except:
    print "Couldn't open settings.txt"
    
values_dict = ReadSettings.get_values_from_init_file(init_file)
try:
    cursor, conn = DatabaseConnect.connect(values_dict)   
except:
    print "Error connecting to database"
# Insert into database
for f in os.listdir("UnsavedTrans"):
    max_trans_num = get_max_transaction_number(cursor)
    file_path = os.getcwd() + "/UnsavedTrans/" + f
    open_f = open(file_path)
    transaction_statements = open_f.read()
    open_f.close()
    clean_statements = transaction_statements.replace("-1,", str(max_trans_num) + ",")
    print clean_statements
    for l in clean_statements.split("\n"):
        cursor.execute(l)