from unitls.LogerinTxt import app_logger
from unitls.StaticDataclass import get_dic
from .flightDB import flightDB


def updateEidteItem(fdb:flightDB,text,flightid,displayMode,flighttype,selectedtime):
    try:
        rowlistLabel = get_dic('rowlistLabel')
        if displayMode =="A":
            if flighttype =="短停接" or flighttype =="航后" or flighttype =="特后前接" or flighttype =="停场":
                flightid_new=flightid+"-1"+"-A"
            elif flighttype =="短停送" or flighttype =="航前" or flighttype =="特后前送":
                flightid_new = flightid + "-2" + "-A"
        elif displayMode =="B":
            if flighttype =="短停" or flighttype =="航后" or flighttype =="特后前" or flighttype =="停场":
                flightid_new=flightid+"-1"+"-B"
        flightids_in_peopleSchedule=fdb.getSingledata("编号","peopleSchedule{}".format(selectedtime))
        newdic = {}
        if str(flightid_new) not in str(flightids_in_peopleSchedule):
            newdic={"编号":flightid_new,"航班编号":flightid,"显示模式":displayMode}
            for i in rowlistLabel.keys():
                if i == -1:
                    if text !="清空项目12345678987654321":
                        newdic[rowlistLabel[i]]=text
                    else:
                        newdic[rowlistLabel[i]] = ""
                else:
                    newdic[rowlistLabel[i]] = ""
            fdb.insertData("peopleSchedule{}".format(selectedtime),newdic)
        else:
            if text != "清空项目12345678987654321":
                newdic[rowlistLabel[int(-1)]]="'%s'"%text
            else:
                newdic[rowlistLabel[int(-1)]]="''"

            fdb.upDateItem("peopleSchedule{}".format(selectedtime),newdic,"编号='%s'"%flightid_new)
    except Exception as e:
        app_logger.log_error(e)