import os
from configparser import ConfigParser

# 获取当前脚本所在的目录
current_path = os.getcwd()

# 获取当前脚本所在的项目根目录
root_path = 'D:\\flightinfo\\DATABASE'
#root_path = 'D:\\flightinfo\\DATABASE'
ini_path = os.path.join(root_path,'config.ini')
#print("项目根目录路径：", current_path)
#print(os.path.join(current_path,'config.ini'))

def readConfig():

    config = ConfigParser()
    config.read(ini_path)
    if config.has_section('DBserver'):
        print(config.get('DBserver', 'host'))

def writeConfig():
    config = ConfigParser()
    config.add_section('DBserver')
    config.set('DBserver', 'local_host','localhost')
    config.set('DBserver', 'local_port','9527')
    config.set('DBserver', 'online_host','222.209.89.138')
    config.set('DBserver', 'online_port','9527')
    config.set('DBserver', 'flightDB4','flightDB4')
    with open(ini_path, 'w',encoding='utf-8') as configfile:
        config.write(configfile)
def Server_Class():
    config = ConfigParser()
    config.read(ini_path, encoding='utf-8-sig')
    if config.has_section('Server_Class'):
        path = "天府综合平台一期:" + config.get('Server_Class', "Class")
    else:
        path = "无重要标记"
        print('Not found Server_Class')
    return path
def Main_Sever():
    config = ConfigParser()
    config.read(ini_path, encoding='utf-8-sig')
    if config.has_section('Main_Sever'):
        path = config.get('Main_Sever', "MainSever")
        database = config.get('Main_Sever', "MainDatabase") if config.has_option('Main_Sever', "MainDatabase") else path
    else:
        path = ""
        database = ""
        print('Not found Main_Sever')
    return path, database
def NO_TPIS():
    config = ConfigParser()
    config.read(ini_path, encoding='utf-8-sig')
    if config.has_section('NO_TPIS'):
        ACNO = config.get('NO_TPIS', "ACNO").split(",")
    else:
        ACNO = []
        print('Not found Main_Sever')
    return ACNO
def DBServer():
    config = ConfigParser()
    config.read(ini_path, encoding='utf-8-sig')
    if config.has_section('DBserver'):
        local_host = config.get('DBserver', 'local_host')
        local_port = config.get('DBserver', 'local_port')
        local_user = "user1"           #config.get('DBserver', 'local_user')
        local_password = "a123456s"    #config.get('DBserver', 'local_password')
        online_host = config.get('DBserver', 'online_host')
        online_port = config.get('DBserver', 'online_port')
        online_user = "user1"            #config.get('DBserver', 'online_user')
        online_password = "a123456s"     #config.get('DBserver', 'online_password')
    else:
        local_host = None
        local_port = None
        local_user = None
        local_password = None
        online_host = None
        online_port = None
        online_user = None
        online_password = None
        print('Not found DBserver')
    return local_host, local_port, local_user, local_password, online_host, online_port, online_user,online_password
def MesgTime():
    config = ConfigParser()
    config.read(ini_path, encoding='utf-8-sig')
    if config.has_section('Mesg_Time'):
        APZBZ = int(config.get('Mesg_Time', 'APZBZ'))
        JJZBZ = int(config.get('Mesg_Time', 'JJZBZ'))
        ESZBZ = int(config.get('Mesg_Time', 'ESZBZ'))
        APGR = int(config.get('Mesg_Time', 'APGR'))
        JJGR = int(config.get('Mesg_Time', 'JJGR'))
        ESGR = int(config.get('Mesg_Time', 'ESGR'))
        APPG = int(config.get('Mesg_Time', 'APPG'))
        JJPG = int(config.get('Mesg_Time', 'JJPG'))
        ESPG = int(config.get('Mesg_Time', 'ESPG'))

    else:
        APZBZ = 100
        JJZBZ = 40
        ESZBZ = 40
        APGR = 105
        JJGR = 45
        ESGR = 45
        APPG = 120
        JJPG = 45
        ESPG = 55
        print('Not found Mesg_Time')
    return APZBZ, JJZBZ, ESZBZ, APGR, JJGR, ESGR,APPG,JJPG,ESPG

def flightDB4():
    config = ConfigParser()
    config.read(ini_path, encoding='utf-8-sig')
    if config.has_section('DBserver'):
        database = config.get('DBserver', 'flightDB4')
    else:
        database = None
        print('Not found flightDB4')
    return database
def flightDB():
    config = ConfigParser()
    config.read(ini_path, encoding='utf-8-sig')
    if config.has_section('DBserver'):
        database = config.get('DBserver', 'flightDB')
    else:
        database = None
        print('Not found flightDB')
    return database

def loginDB():
    config = ConfigParser()
    config.read(ini_path, encoding='utf-8-sig')
    if config.has_section('DBserver'):
        database = config.get('DBserver', 'loginDB')
    else:
        database = None
        print('Not found loginDB')
    return database

def databasefileDB():
    config = ConfigParser()
    config.read(ini_path, encoding='utf-8-sig')
    if config.has_section('DBserver'):
        database = config.get('DBserver', 'databasefileDB')
    else:
        database = None
        print('Not found fileDB')
    return database

def UsesrLoginDatabase():
    config = ConfigParser()
    config.read(ini_path, encoding='utf-8-sig')
    if config.has_section('DBserver'):
        database = config.get('DBserver', 'UserLoginDatabase')
    else:
        database = None
        print('Not found UserLoginDatabase')
    return database

def FilePath(name):
    config = ConfigParser()
    config.read(ini_path, encoding='utf-8-sig')
    if config.has_section('FilePath'):
        path = config.get('FilePath', name)
    else:
        path = None
        print('Not found FilePath')
    return path
def Oline_flight():
    config = ConfigParser()
    config.read(ini_path, encoding='utf-8-sig')
    if config.has_section('Online_flight'):
        SameDatabase = config.get('Online_flight', 'SameDatabase')
        HighRefreh= config.get('Online_flight', 'HighRefreh')
        Online_flight_sts= config.get('Online_flight', 'Online_flight_sts')
    else:
        SameDatabase = 0
        HighRefreh = 0
        Online_flight_sts=0
        print('Not found Oline_flight')
    return SameDatabase,HighRefreh,Online_flight_sts


def DataTransferMode():
    config = ConfigParser()
    config.read(ini_path, encoding='utf-8-sig')
    if config.has_section('DataTransferMode'):
        try:
            flightDataTransfer = int(config.get('DataTransferMode', 'flightDataTransfer'))
            displayDataTransfer =  int(config.get('DataTransferMode', 'displayDataTransfer'))
        except:
            flightDataTransfer = 0
            displayDataTransfer = 0
    else:
        flightDataTransfer = 0
        displayDataTransfer = 0
        print('Not found PdfSavePathUrl')
    return flightDataTransfer,displayDataTransfer
