day13 員工管理系統(tǒng) (登錄注冊部分)

import file_funcs
from employers import Employers
import human_resource_sys

file_employer = 'employers'
# employee = 'employees'
name = 'name'
password = 'password'


# 登錄注冊界面
def list_login():
    print('''
    +++++++++++++++++++++++++++++++++++++++++++++++++
    +        welcome to human resource system       +
    +                                               +
    +                   1.register                  +
    +                                               +
    +                   2.login                     +
    +                                               +
    +                   0.exit                      +
    +++++++++++++++++++++++++++++++++++++++++++++++++
    ''')
    cmd = input('>>>>>>>')
    if '0' <= cmd <= '2':
        return cmd
    else:
        print('輸入內(nèi)存錯誤宠默!')
        return False


def register():
    user_name = input('請輸入用戶名:')
    # 取出說有的用戶信息阳藻,列表
    all_info = file_funcs.get_content(file_employer)
    for info in all_info:
        # 用戶個人信息辆憔,對象
        user = Employers.set_employer(info)
        if user_name == user.name:
            print('該用戶名已經(jīng)存在蒋失!')
            return False
    else:
        print('用戶名可用!')
        pass_word = input('請輸入密碼:')
        pass_word2 = input('請再次輸入密碼:')
        if pass_word == pass_word2:
            new_user = {name: user_name, password: pass_word}
            new_employer = Employers.set_employer(new_user)
            file_funcs.set_content(file_employer, new_employer.__dict__)
            print('注冊成功钻洒!')

            return user_name
        else:
            print('兩次密碼不一致酗昼!')
            return False


def login():
    user_name = input('請輸入用戶名:')
    all_info = file_funcs.get_content(file_employer)
    print(all_info)
    for info in all_info:
        user = Employers.set_employer(info)
        if user_name == user.name:
            pass_word = input('請輸入密碼:')
            if pass_word == user.password:
                print('登錄成功!')
                return True
            else:
                print('密碼錯誤闺骚!')
                return False

    print('用戶名不存在彩扔!')


# 用戶登錄
def main():
    while True:
        cmd = list_login()
        if not cmd:
            continue

        if cmd == '1':
            result = register()
            if result:
                human_resource_sys.main(result)

        if cmd == '2':
            login()

        if cmd == '0':
            exit(0)


if __name__ == '__main__':
    main()

employee

class Employees:
    """員工類"""

    def __init__(self):
        self.name = ''
        self._age = 0
        self.id = ''
        self._salary = 0
        self.position = ''
        self.department = ''

    @property
    def age(self):
        return self._age

    @age.setter
    def age(self, age):
        if not age.isdigit():
            print('輸入數(shù)據(jù)類型錯誤!')

        elif 16 < age < 70:
            print('不在法定工作年齡內(nèi)!')

        else:
            self._age = int(age)

    @property
    def salary(self):
        return self._salary

    @salary.setter
    def salary(self, salary):
        if not salary.isdigit():
            print('輸入數(shù)據(jù)類型錯誤僻爽!')
        else:
            self._salary = int(salary)

    @classmethod
    def set_employee(cls, employee):
        new_employee = cls()
        for key in employee:
            if key == 'age':
                new_employee.age = employee[key]

            if key == 'salary':
                new_employee.salary = employee[key]

            new_employee.__setattr__(key, employee[key])

        return new_employee


if __name__ == '__main__':
    pass

employer

class Employers:
    """雇主類"""

    def __init__(self):
        self.name = ''
        self.password = ''
        self.employees = []

    @classmethod
    def set_employer(cls, employer):
        new_employer = cls()
        for key in employer:
            new_employer.__setattr__(key, employer[key])

        return new_employer


if __name__ == '__main__':
    pass

文件操作

import json


def get_content(file_name):
    try:
        with open('./files/' + file_name + '.json', 'r', encoding='utf-8') as f:
            content = json.load(f)
    except FileNotFoundError:
        content = []
    
    return content


def set_content(file_name, new_content):
    content = get_content(file_name)
    with open('./files/' + file_name + '.json', 'w', encoding='utf-8') as f:
        content.append(new_content)
        json.dump(content, f)
        return True


def reset_content(file_name, new_content):
    with open('./files/' + file_name + '.json', 'w', encoding='utf-8') as f:
        json.dump(new_content, f)
        return True


if __name__ == '__main__':
    pass

human resource

import dao
file_employer = 'employers'


def list_human_resource():
    print('''
        +++++++++++++++++++++++++++++++++++++++++++++++++
        +       welcome to human resource system        +
        +       1.add new employee                      +
        +       2.View employee's information by id     +
        +       3.del employee by id                    +
        +       4.view all employees' information       +
        +       5.view employees' average age           +
        +       6.view the most high salary             +
        +       0.exit                                  +
        +++++++++++++++++++++++++++++++++++++++++++++++++
            ''')
    user_cmd = input('>>>>>')

    if '0' <= user_cmd <= '6':
        return user_cmd
    else:
        print('輸入內(nèi)存錯誤虫碉!')
        return False


def human_resource(user_cmd):
    while True:
        if not user_cmd:
            continue

        # 添加員工
        if user_cmd == '1':
            while True:
                new_employee = dao.employee_input()
                dao.add_employee(file_employer, new_employee, employer_name)

                # 判斷是否繼續(xù)或者退出
                print('''
                                    1.繼續(xù)添加
                                    2.返回上一層
                                    ''')
                user_cmd = input('>>>>>')
                if user_cmd == '1':
                    continue
                elif user_cmd == '2':
                    return
                else:
                    print('輸入有誤!')
                    return

        # 查看員工個人信息
        if user_cmd == '2':
            pass

        # 刪除員工
        if user_cmd == '3':
            pass

        # 查看所有員工
        if user_cmd == '4':
            dao.find_all(employer_name)

        # 查看平均年齡
        if user_cmd == '5':
            pass

        # 查看最高工資
        if user_cmd == '6':
            pass

        # 退出程序
        if user_cmd == '0':
            exit(0)


def main(employer):
    global employer_name
    employer_name = employer

    while True:
        human_resource(list_human_resource())


if __name__ == '__main__':
    pass
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市胸梆,隨后出現(xiàn)的幾起案子敦捧,更是在濱河造成了極大的恐慌,老刑警劉巖碰镜,帶你破解...
    沈念sama閱讀 218,858評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件兢卵,死亡現(xiàn)場離奇詭異,居然都是意外死亡绪颖,警方通過查閱死者的電腦和手機(jī)秽荤,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,372評論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人窃款,你說我怎么就攤上這事课兄。” “怎么了晨继?”我有些...
    開封第一講書人閱讀 165,282評論 0 356
  • 文/不壞的土叔 我叫張陵第喳,是天一觀的道長。 經(jīng)常有香客問我踱稍,道長曲饱,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,842評論 1 295
  • 正文 為了忘掉前任珠月,我火速辦了婚禮扩淀,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘啤挎。我一直安慰自己驻谆,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,857評論 6 392
  • 文/花漫 我一把揭開白布庆聘。 她就那樣靜靜地躺著胜臊,像睡著了一般。 火紅的嫁衣襯著肌膚如雪伙判。 梳的紋絲不亂的頭發(fā)上象对,一...
    開封第一講書人閱讀 51,679評論 1 305
  • 那天,我揣著相機(jī)與錄音宴抚,去河邊找鬼勒魔。 笑死,一個胖子當(dāng)著我的面吹牛菇曲,可吹牛的內(nèi)容都是我干的冠绢。 我是一名探鬼主播,決...
    沈念sama閱讀 40,406評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼常潮,長吁一口氣:“原來是場噩夢啊……” “哼弟胀!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起喊式,我...
    開封第一講書人閱讀 39,311評論 0 276
  • 序言:老撾萬榮一對情侶失蹤孵户,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后垃帅,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體延届,經(jīng)...
    沈念sama閱讀 45,767評論 1 315
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,945評論 3 336
  • 正文 我和宋清朗相戀三年贸诚,在試婚紗的時候發(fā)現(xiàn)自己被綠了方庭。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片厕吉。...
    茶點(diǎn)故事閱讀 40,090評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖械念,靈堂內(nèi)的尸體忽然破棺而出头朱,到底是詐尸還是另有隱情,我是刑警寧澤龄减,帶...
    沈念sama閱讀 35,785評論 5 346
  • 正文 年R本政府宣布项钮,位于F島的核電站,受9級特大地震影響希停,放射性物質(zhì)發(fā)生泄漏烁巫。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,420評論 3 331
  • 文/蒙蒙 一宠能、第九天 我趴在偏房一處隱蔽的房頂上張望亚隙。 院中可真熱鬧,春花似錦违崇、人聲如沸阿弃。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,988評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽渣淳。三九已至,卻和暖如春伴箩,著一層夾襖步出監(jiān)牢的瞬間入愧,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,101評論 1 271
  • 我被黑心中介騙來泰國打工赛蔫, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留砂客,地道東北人。 一個月前我還...
    沈念sama閱讀 48,298評論 3 372
  • 正文 我出身青樓呵恢,卻偏偏與公主長得像,于是被迫代替她去往敵國和親媚创。 傳聞我的和親對象是個殘疾皇子渗钉,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,033評論 2 355

推薦閱讀更多精彩內(nèi)容