def removeWorkerNameDataBase(name, firstName, fileWorkerName) :
    """
    remove worker off the database.
    :param name: the worker's name.
    :param firstName: the worker's firstname.
    :param fileWOrkerName: the path to the file to get name and firstname's worker.
    :rtype: str
    :return: message to check the removing.
    """
    if name == "" :
        return "name"
    elif firstName == "" :
        return "firstname"
    else :
        res = ""
        remove = False
        lines = gl.getLinesOfFile(fileWorkerName)
        for l in lines :
            line = l.split(";")
            nameFile = line[0]
            firstNameFile = line[1]
            if not(name == nameFile and firstName == firstNameFile) : #if not the worker ti remove, write the line.
                res += l
            else : #else, do nothing to not write the line.
                remove = True 
        gl.writeInFile(fileWorkerName, res)
        if remove :
            return "okRemoveWorker"
        else :
            return "remove"
 def editEmail(self):
     """
     edit the email. (write on the database the new email).
     """
     email = self.valueEMail.get().strip()
     if email == "":
         tkmsg.showerror("Erreur ", "Mail vide")
     else:
         self.email = email
         gl.writeInFile(self.fileUserPath,
                        self.password + "\n" + self.email)
         tkmsg.showinfo("Ok ", "Mail changé en : " + email)
def hoursDataBase(workerFile, hourFile, cssFile, show=True) :
    """
    write an html file with all work hours of all workers.
    :param workerFile: the path to the file with work hours.
    :param hourFile: the path to the html file, to write on it.
    :param cssFile: the path to the css, to write it in the html file. (when the html file is sended by email, we don't need to send the css file).
    :param show: default, true, to show the html file. (false when the html file is sended by email).
    """
    lines = gl.getLinesOfFile(workerFile)
    res = "<!doctype html><html lang='fr'><head><meta charset='utf-8'><title>Heure des ouvriers du mois de" + gl.getMonth() + "</title>" 
    #read the css file to write it on the html file.
    f = open(cssFile, "r")
    css = f.read()
    f.close()
    res += "<style>" + css + "</style>"
    res += "</head><body>"
    #show columns
    num_col = 0
    number_of_columns = 2
    cols = ['gauche', 'droite']
    for l in lines :
        line = l.split(";")
        name = line[0]
        firstName = line[1]
        #show columns
        res += "<div id='" + cols[num_col%number_of_columns] + "'>"
        num_col += 1
        res += "<p id='worker'>" + name + " " + firstName + "</p><table><tbody><tr><td id='date'>Date</td><td id='hour'>Nombre d'heure</td><td id='mg'>MG</td></tr>"
        sumHour = 0
        sumMG = 0
        lineLen = len(line)
        for i in range(2,lineLen) :
            try : 
                construction = line[i].split(":")
                d = construction[0]
                year = d[0:4]
                month = d[5:7]
                day = d[8:10]
                nbHour = construction[1]
                mg = construction[2]
                sumHour += float(nbHour)
                sumMG += float(mg)
                res += "<tr><td>" + day + "/" + month + "/" + year + "</td><td>" + nbHour + "</td><td>" + mg + "</td></tr>"
            except :
                None
        res += "<tr><td>Totaux</td><td>" + str(sumHour) + "</td><td>" + str(sumMG) + "</td></tr>"
        res += "</tbody></table>"
        res += "</div>" #show columns
    res += "</body></html>"
    gl.writeInFile(hourFile, res)
    if show :
        webbrowser.open(hourFile)
 def editPassWord(self):
     """
     edit the password. (write on the database the new password).
     """
     pw = self.valuePassWord.get().strip()
     self.valuePassWord.set("")  #to hide password
     if pw == "":
         tkmsg.showerror("Erreur ", "Mot de passe vide")
     else:
         self.password = pw
         gl.writeInFile(self.fileUserPath,
                        self.password + "\n" + self.email)
         tkmsg.showinfo("Ok ", "Mot de passe changé en : " + pw)
Exemple #5
0
def editWorkerDataBase(workerName, workerFirstName, workerArrivingTime,
                       workerDepartureTime, workerMeal, editDate,
                       fileWorkerHourPath):
    """
    edit work hours on the database.
    :param workerName: the worker's name.
    :param workerFirstName: the worker's firstname.
    :parzm workerArrivingTime: the arriving time.
    :param workerDepartureTime: the departure time.
    :param workerMeal: the meal time.
    :param editDate: date to edit work hours.
    :param fileWorkerHourPath: the path to the file includes the work hours of workers.
    :rtype: str
    :return: :return: message to check the editing.
    """
    try:
        workerHour, lines = checkParams(workerName, workerFirstName,
                                        workerArrivingTime,
                                        workerDepartureTime, workerMeal,
                                        fileWorkerHourPath)
        res = ""
        edit = False
        for l in lines:
            line = l.split(";")
            if line[0] == workerName and line[
                    1] == workerFirstName:  #good worker
                lineLen = len(line)
                for i in range(
                        2, lineLen
                ):  #range 2 -> 2 first element are name and firstname
                    construction = line[i].split(":")
                    if construction[0] == editDate:  #good date
                        edit = True
                        index = l.index(editDate)
                        res += l[0:index - 1] + ";" + editDate + ":" + str(
                            workerHour) + ":" + construction[2] + l[
                                (index + len(editDate) + len(str(workerHour)) +
                                 2 + len(construction[2])):-1]
                    #if not found the date, we copy the whole line anyway
                    if not (edit) and i == lineLen - 1:
                        res += l
            else:
                res += l
        genLib.writeInFile(fileWorkerHourPath, res)
        if edit:
            return "okEditWorker"
        else:
            return "edit"
    except:
        return checkParams(workerName, workerFirstName, workerArrivingTime,
                           workerDepartureTime, workerMeal, fileWorkerHourPath)
Exemple #6
0
def addWorkerDataBase(workerName, workerFirstName, workerArrivingTime,
                      workerDepartureTime, workerMeal, workerCity,
                      fileWorkerHourPath, fileCityPath):
    """
    add work hours on the database.
    :param workerName: the worker's name.
    :param workerFirstName: the worker's firstname.
    :parzm workerArrivingTime: the arriving time.
    :param workerDepartureTime: the departure time.
    :param workerMeal: the meal time.
    :param workerCity: the city where the worker work.
    :param fileWorkerHourPath: the path to the file includes the work hours of workers.
    :param fileCityPath: the path to the file includes the coty and this MG.
    :rtype: str
    :return: message to check the adding.
    """
    if workerCity == "":
        return "city"
    try:
        workerHour, lines = checkParams(workerName, workerFirstName,
                                        workerArrivingTime,
                                        workerDepartureTime, workerMeal,
                                        fileWorkerHourPath)
        res = ""
        mg = takeMG(workerCity, fileCityPath)
        add = False
        for l in lines:
            line = l.split(";")
            if line[0] == workerName and line[1] == workerFirstName:
                try:  #if this first work date, there isn't last date.
                    lastDate = line[-1].split(":")[0]
                except:
                    lastDate = ""
                if str(date.today()) != lastDate:
                    add = True
                    res += l[0:-2] + ";" + str(date.today()) + ":" + str(
                        workerHour) + ":" + str(mg) + "\n"
                else:
                    return "errorSameDate"  #already work hours added for this day.
            else:
                res += l
        genLib.writeInFile(fileWorkerHourPath, res)
        if add:
            return "okAddHour"
        else:
            return "add"
    except:
        return checkParams(workerName, workerFirstName, workerArrivingTime,
                           workerDepartureTime, workerMeal, fileWorkerHourPath)
Exemple #7
0
def addCityDataBase(city, mg, f) :
    """
    add city and this MG in databse.
    :param city: the name of the city.
    :pram mg: the MG.
    :param f: the work hours file.
    :rtype: str
    :return: message to check the adding.
    """
    if city == "" : #empty city.
        return "city" 
    elif mg == "" : #empty MG.
        return "mg" 
    elif "," in mg : #MG with comma.
        return "mg,"
    else : 
        try :
            res = ""
            add = False
            mg = float(mg)
            print(mg)
            lines = gl.getLinesOfFile(f)
            for l in lines :
                line = l.split(";")
                if not add and line[0] > city : #not add, and alphabetical order
                    res += city + ";" + str(mg) + "\n" + l
                    add = True
                else :
                    res += l
            if not add :
                res += city + ";" + str(mg) + "\n"
            gl.writeInFile(f,res)
            return "okAddCity" #city added.
        except :
            print("error")
            return "errorMG" #invalid MG.
def addWorkerNameDataBase(name, firstName, fileWorkerName, fileWorkerHour) :
    """
    add the worker at the databse.
    :param name: the worker's name.
    :param firstName: the worker's firstname.
    :param fileWOrkerName: the path to the file to get name and firstname's worker.
    :param fileWorkerHour: the path to the fileto get work hours, to add the name on this file.
    :rtype: str
    :return: message to check the adding.
    """
    if name == "" :
        return "name"
    elif firstName == "" :
        return "firstname"
    else :
        res = ""
        add = False
        lines = gl.getLinesOfFile(fileWorkerName)
        if lines == [] : #if the file is empty, add name and firstname directly.
            #for name
            gl.writeInFile(fileWorkerName, name + ";" + firstName + ";\n")
            #for hour
            gl.writeInFile(fileWorkerHour, name + ";" + firstName + ";\n")
            return "okAddWorker"
        for l in lines : #else, add them in alphabetical order.
            line = l.split(";")
            if not add and line[0] == name and line[1] == firstName : #same name and firstname.
                return "double" 
            if not add and line[0] > name : #
                res += name + ";" + firstName + ";\n" + l
                add = True
            elif not add and line[0] == name :
                if line[1] > firstName :
                    res += name + ";" + firstName + ";\n" + l
                    add = True
                else :
                    res += l
            else :
                res += l
        if not add :
            res += name + ";" + firstName + ";\n"
        #for name
        gl.writeInFile(fileWorkerName, res)
        #for hour
        fileWorker = open(fileWorkerHour, "a")
        fileWorker.write(name + ";" + firstName + ";\n")
        fileWorker.close()
        return "okAddWorker"