#!D:/IDE/anaconda3/envs python
# -*- coding: UTF-8 -*-
"""
 @Author: Administrator
 @FileName：ScanStatusModel.py\n
 @DateTime: 2025/6/26 9:22\n
 @Author  ：xsh
"""
from datetime import datetime
from AppCore.AppDBModels.CoreModel import (CoreModel, dbController)
from sqlalchemy.orm         import Session
from sqlalchemy.orm         import (Mapped, mapped_column, relationship)
from sqlalchemy             import ForeignKey
from sqlalchemy.types       import (Text, DateTime)
from AppUtils.utils         import *
from AppCore.Levels         import *
from AppInterfaces.utils    import *
from AppCore.Requests       import *
from AppCore.AppDBModels.Permissions.UserModel                  import UserModel
from AppCore.AppDBModels.StateModels.OperatingStatusModel       import OperatingStatusModel
from AppCore.AppDBModels.SlideModels.SlideModelInterface        import SlideModelInterface
from AppCore.AppDBModels.TemplateModels.ScanTemplate            import ScanTemplate, Collectsettings, Previewsettings
from AppCore.AppDBModels.WeightModels.PreferredClassifierModel  import PreferredClassifierModel
from AppCore.AppDBModels.WeightModels.PreviewClassifierModel    import PreviewClassifierModel
from AppCore.AppDBModels.WeightModels.CollectClassifierModel    import CollectClassifierModel
class ScanStatusModel(CoreModel):
    __tablename__ = 't_ScanStatusModel'
    ID                      : Mapped[int                    ] = mapped_column(primary_key=True                                              , nullable=False    , doc='数据序号　', comment='数据序号　')
    ObjectiveLevel          : Mapped[int                    ] = mapped_column(default=ObjectiveLevel.ObjectiveNone                          , nullable=True     , doc='当前物镜　', comment='当前物镜　')
    ChamberGroupNumber      : Mapped[int                    ] = mapped_column(default=1                                                     , nullable=True     , doc='片仓组号　', comment='片仓组号　')
    ChamberRowNumber        : Mapped[int                    ] = mapped_column(default=1                                                     , nullable=True     , doc='片仓行号　', comment='片仓行号　')
    TrayNumber              : Mapped[int                    ] = mapped_column(default=ModuleLevel.ModuleTraySlide1                          , nullable=True     , doc='载玻台号　', comment='载玻台号　')
    RowNumber               : Mapped[int                    ] = mapped_column(default=0                                                     , nullable=True     , doc='玻片行号　', comment='玻片行号　')
    ColNumber               : Mapped[int                    ] = mapped_column(default=0                                                     , nullable=True     , doc='玻片列号　', comment='玻片列号　')
    ScanStatus              : Mapped[int                    ] = mapped_column(default=0                                                     , nullable=True     , doc='扫描状态　', comment='扫描状态　')
    RunStatus               : Mapped[int                    ] = mapped_column(default=0                                                     , nullable=True     , doc='运行状态　', comment='运行状态　')
    Template_ID             : Mapped[int                    ] = mapped_column(default=1                                                     , nullable=True     , doc='模板序号　', comment='模板序号　')
    PreferredClassifier_ID  : Mapped[int                    ] = mapped_column(default=1                                                     , nullable=True     , doc='优选器序号', comment='优选器序号')
    PreviewClassifier_ID    : Mapped[int                    ] = mapped_column(default=1                                                     , nullable=True     , doc='预选器序号', comment='预选器序号')
    CollectClassifier_ID    : Mapped[int                    ] = mapped_column(default=1                                                     , nullable=True     , doc='采集器序号', comment='采集器序号')
    User_ID                 : Mapped[int                    ] = mapped_column(ForeignKey("t_UserModel.ID"             ), default=None       , nullable=True     , doc='当前账号　', comment='当前账号　')
    OperatingStatus_ID      : Mapped[int                    ] = mapped_column(ForeignKey("t_OperatingStatusModel.ID"  ), default=None       , nullable=True     , doc='当前状态　', comment='当前状态　')
    CodeString              : Mapped[str                    ] = mapped_column(Text      , default=''                                        , nullable=True     , doc='玻片二维码', comment='玻片二维码')
    ScanningDateTime        : Mapped[datetime               ] = mapped_column(DateTime  , default=datetime.now()                            , nullable=True     , doc='开始时间　', comment='开始时间　')
    StopScanningDateTime    : Mapped[datetime               ] = mapped_column(DateTime  , default=None                                      , nullable=True     , doc='停止时间　', comment='停止时间　')
    OperatingStatus         : Mapped['OperatingStatusModel' ] = relationship('OperatingStatusModel' , backref="t_OperatingStatusModel"      , foreign_keys=[OperatingStatus_ID ])

    @classmethod
    def changedScanningStatus(cls, chamber_number: int, row_number: int, tray_number: int = None, level: int = 0, codestring: str = None, objective: int = None):
        try:
            dbController.initEngine()
            with Session(dbController.Engine) as session:
                session.query(cls).update(
                    {
                        cls.ChamberGroupNumber  : chamber_number    ,
                        cls.ChamberRowNumber    : row_number        ,
                        cls.TrayNumber          : tray_number       ,
                        cls.CodeString          : codestring        ,
                        cls.ObjectiveLevel      : objective         ,
                        cls.ScanStatus          : level if level in ScanStatusLevel.all() else ScanStatusLevel.ScanComplete_Status,

                    })
                session.commit()
                session.close()
        except Exception as e:
            from AppLog.logHelper import logDB
            logDB << AppUtils.toString(e)



    @classmethod
    def CollectSetting(cls) -> Collectsettings:
        item: cls = cls.first()
        template: ScanTemplate = ScanTemplate.Primary(item.Template_ID)
        Model: Collectsettings = None
        if template is not None:
            Model = Collectsettings.Primary(template.collectsettings_ID)
        return Model

    @classmethod
    def PreviewSetting(cls) -> Previewsettings:
        item: cls = cls.first()
        template: ScanTemplate = ScanTemplate.Primary(item.Template_ID)
        Model: Previewsettings = None
        if template is not None:
            Model = Previewsettings.Primary(template.previewsettings_ID)
        return Model

    @classmethod
    def Template            (cls) -> ScanTemplate:
        item: cls = cls.first()
        return ScanTemplate.Primary(item.Template_ID)

    @classmethod
    def PreferredClassifier (cls) -> PreferredClassifierModel:
        item: cls = cls.first()
        return PreferredClassifierModel.Primary(item.PreferredClassifier_ID)

    @classmethod
    def PreviewClassifier   (cls) -> PreviewClassifierModel:
        item: cls = cls.first()
        return CollectClassifierModel.Primary(item.PreviewClassifier_ID)

    @classmethod
    def CollectClassifier   (cls) -> CollectClassifierModel:
        item: cls = cls.first()
        return CollectClassifierModel.Primary(item.CollectClassifier_ID)

    @classmethod
    def User                (cls) -> UserModel:
        item: cls = cls.first()
        return UserModel.Primary(item.User_ID)
        pass

    @classmethod
    def OperatingStatus(cls) -> OperatingStatusModel:
        item: cls = cls.first()
        return OperatingStatusModel.Primary(item.OperatingStatus_ID)



    def __init__(self, **args):
        super(ScanStatusModel, self).__init__()
        self.initialize()
        self.initParameter(**args)

    @classmethod
    def initModels(cls):
        return [cls.instance(ID=1)]

    def initValue(self):
        super(ScanStatusModel, self).initValue()


    def getScanningData(self) -> dict[str, object]:
        return {
            'ChamberGroupNumber'    : self.ChamberGroupNumber                       ,
            'ChamberRowNumber'      : self.ChamberRowNumber                         ,
            'TrayNumber'            : self.TrayNumber                               ,
            'CodeString'            : self.CodeString                               ,
            'ObjectiveLevel'        : ObjectiveLevel.toUiString(self.ObjectiveLevel),
            'ScanStatus'            : self.ScanStatus                               ,
            'RunStatus'             : self.RunStatus                                ,
            'ScanningDateTime'      : self.ScanningDateTime     .timestamp() if self.hasScanningDateTime     else None,
            'StopScanningDateTime'  : self.StopScanningDateTime .timestamp() if self.hasStopScanningDateTime else None,
            'Template_ID'           : self.Template_ID                              ,
            'PreferredClassifier_ID': self.PreferredClassifier_ID                   ,
            'PreviewClassifier_ID'  : self.PreviewClassifier_ID                     ,
            'CollectClassifier_ID'  : self.CollectClassifier_ID                     ,
            'User_ID'               : self.User_ID                                  ,
            'OperatingStatus_ID'    : self.OperatingStatus_ID                       ,


        }

    def getScanningStatus(self) -> dict[str, object]:
        return {
            'ChamberGroupNumber'    : self.ChamberGroupNumber                       ,
            'ChamberRowNumber'      : self.ChamberRowNumber                         ,
            'TrayNumber'            : self.TrayNumber                               ,
            'CodeString'            : self.CodeString                               ,
            'ObjectiveLevel'        : ObjectiveLevel.toUiString(self.ObjectiveLevel),
            'ScanStatus'            : self.ScanStatus                               ,
            'RunStatus'             : self.RunStatus                                ,
            'ScanningDateTime'      : self.ScanningDateTime     .timestamp() if self.hasScanningDateTime     else None,
            'StopScanningDateTime'  : self.StopScanningDateTime .timestamp() if self.hasStopScanningDateTime else None,
            'Template_ID'           : self.Template_ID                              ,
            'PreferredClassifier_ID': self.PreferredClassifier_ID                   ,
            'PreviewClassifier_ID'  : self.PreviewClassifier_ID                     ,
            'CollectClassifier_ID'  : self.CollectClassifier_ID                     ,
            'User_ID'               : self.User_ID                                  ,
            'OperatingStatus_ID'    : self.OperatingStatus_ID                       ,
        }


    @classmethod
    def changed(cls, data: dict):
        item: cls
        try:
            dbController.initEngine()
            with Session(dbController.Engine) as session:
                session.query(cls).update(data)
                session.commit()
                session.close()
        except Exception as e:
            from AppLog.logHelper import logDB
            logDB << AppUtils.toString(e)
        return

    @classmethod
    def user_model             (cls) -> UserModel            :
        item: UserModel = UserModel.getCurrentUser()
        return item

    @classmethod
    def operating_model        (cls) -> OperatingStatusModel :
        return OperatingStatusModel.first()


    @classmethod
    def Classifiers(cls) -> (int, int, int):
        item: cls = cls.first()
        return item.PreferredClassifier_ID, item.PreviewClassifier_ID, item.CollectClassifier_ID

    @classmethod
    def ClassifierModels(cls) -> (PreferredClassifierModel, PreviewClassifierModel, CollectClassifierModel):
        item: cls = cls.first()
        Preferred   : PreferredClassifierModel  =   PreferredClassifierModel.Primary(item.PreferredClassifier_ID)
        Preview     : PreviewClassifierModel    =   PreviewClassifierModel  .Primary(item.PreviewClassifier_ID  )
        Collect     : CollectClassifierModel    =   CollectClassifierModel  .Primary(item.CollectClassifier_ID  )
        return Preferred, Preview, Collect

    @classmethod
    def setCurrentScanningSlide(cls, slide: SlideModelInterface):
        if slide is None:
            return
        if slide.template is not None:
            cls.changed(
                {
                    cls.ObjectiveLevel          : slide.ObjectiveLevel          ,
                    cls.ChamberGroupNumber      : slide.ChamberGroupNumber      ,
                    cls.ChamberRowNumber        : slide.ChamberRowNumber        ,
                    cls.TrayNumber              : slide.TrayNumber              ,
                    cls.RowNumber               : slide.RowNumber               ,
                    cls.ColNumber               : slide.ColNumber               ,
                    cls.ScanStatus              : slide.Level                   ,
                    cls.CodeString              : slide.CodeString              ,
                    cls.Template_ID             : slide.template.ID             ,
                }
            )
        else:
            cls.changed(
                {
                    cls.ObjectiveLevel          : slide.ObjectiveLevel          ,
                    cls.ChamberGroupNumber      : slide.ChamberGroupNumber      ,
                    cls.ChamberRowNumber        : slide.ChamberRowNumber        ,
                    cls.TrayNumber              : slide.TrayNumber              ,
                    cls.RowNumber               : slide.RowNumber               ,
                    cls.ColNumber               : slide.ColNumber               ,
                    cls.ScanStatus              : slide.Level                   ,
                    cls.CodeString              : slide.CodeString              ,
                }
            )

    @classmethod
    def setCurrentScanningTrayNumber(cls, ChamberNumber: int, RowNumber: int, TrayNumber: int, Objective: int, templateID: int = 1, CodeString: str = None):
        if isinstance(CodeString, str) and len(CodeString) > 0:
            cls.changed(
                {
                    cls.ChamberGroupNumber  : ChamberNumber   ,
                    cls.ChamberRowNumber    : RowNumber       ,
                    cls.TrayNumber          : TrayNumber      ,
                    cls.CodeString          : f'{CodeString}' ,
                    cls.ObjectiveLevel      : Objective       ,
                    cls.Template_ID         : templateID      ,
                    cls.PreviewClassifier_ID: templateID,
                    cls.CollectClassifier_ID: templateID,
                }
            )
        else:
            cls.changed(
                {
                    cls.ChamberGroupNumber  : ChamberNumber     ,
                    cls.ChamberRowNumber    : RowNumber         ,
                    cls.TrayNumber          : TrayNumber        ,
                    cls.ObjectiveLevel      : Objective         ,
                    cls.Template_ID         : templateID        ,
                    cls.PreviewClassifier_ID: templateID        ,
                    cls.CollectClassifier_ID: templateID        ,
                }
            )
        WebSlot.WebServerReceivedSignal.emit(Request.APIInstance(WebAPILevel.getScanningData))

    @classmethod
    def setScanningTrayNumber(cls, ChamberNumber: int, RowNumber: int, TrayNumber: int, Objective: int, CodeString: str = None):

        if isinstance(CodeString, str) and len(CodeString) > 0:
            cls.changed(
                {
                    cls.ChamberGroupNumber: ChamberNumber   ,
                    cls.ChamberRowNumber  : RowNumber       ,
                    cls.TrayNumber        : TrayNumber      ,
                    cls.CodeString        : f'{CodeString}' ,
                    cls.ObjectiveLevel    : Objective       ,
                }
            )
        else:
            cls.changed(
                {
                    cls.ChamberGroupNumber: ChamberNumber   ,
                    cls.ChamberRowNumber  : RowNumber       ,
                    cls.TrayNumber        : TrayNumber      ,
                    cls.ObjectiveLevel    : Objective       ,
                }
            )
        WebSlot.WebServerReceivedSignal.emit(Request.APIInstance(WebAPILevel.getScanningData))

    @classmethod
    def setCurrentTemplate(cls, TemplateID: int):
        cls.changed({cls.Template_ID: TemplateID})
        WebSlot.WebServerReceivedSignal.emit(Request.APIInstance(WebAPILevel.getScanningData))
    @classmethod
    def currentScanningTemplate(cls):
        return cls.Template()

    @classmethod
    def getCurrentScanningTrayNumber(cls) -> (int, int, int, str):
        item: cls = cls.first()
        return item.ChamberGroupNumber, item.ChamberRowNumber, item.TrayNumber, item.CodeString


    @classmethod
    def getObjectiveModel(cls) -> int:
        item: cls = cls.first()
        return item.ObjectiveLevel

    @classmethod
    def ScanningStatus(cls) -> int:
        item: cls = cls.first()
        return item.ScanStatus




    @classmethod
    def setRunStatus   (cls, status: int):
        state: int = status if status in RunStatusLevel.all() else RunStatusLevel.ExitRunning
        cls.changed({cls.RunStatus: status})
        WebSlot.WebServerReceivedSignal.emit(Request.APIInstance(WebAPILevel.getScanningData))
        return

    @classmethod
    def IsExitRunning(cls) -> bool:
        item: cls = cls.first()
        return item.RunStatus == RunStatusLevel.ExitRunning

    @classmethod
    def IsRunning             (cls) -> bool:
        item: cls = cls.first()
        return item.RunStatus == RunStatusLevel.Running
    @classmethod
    def IsPauseRunning        (cls) -> bool:
        item: cls = cls.first()
        return item.RunStatus == RunStatusLevel.PauseRunning


    @classmethod
    def changedCurrentScanTemplate(cls, templateID: int):
        cls.changed({cls.Template_ID: templateID})
        WebSlot.WebServerReceivedSignal.emit(Request.APIInstance(WebAPILevel.getScanningData))

    @classmethod
    def setScanStatus(cls, state: int):
        status: int = state if state in ScanStatusLevel.all() else ScanStatusLevel.Default_Status
        cls.changed({cls.ScanStatus: status})
        WebSlot.WebServerReceivedSignal.emit(Request.APIInstance(WebAPILevel.getScanningData))


    @classmethod
    def getScanStatus(cls):
        item: cls = cls.first()
        return item.ScanStatus

    @classmethod
    def setRunStatus(cls, state: int):
        status: int = state if state in RunStatusLevel.all() else RunStatusLevel.Running
        if status == RunStatusLevel.Running:
            cls.changed({cls.RunStatus: status, cls.ScanningDateTime        : datetime.now()})
        elif status == RunStatusLevel.ExitRunning:
            cls.changed({cls.RunStatus: status, cls.StopScanningDateTime    : datetime.now(), cls.ScanningDateTime        : None          ,})
        else:
            cls.changed({cls.RunStatus: status})

        WebSlot.WebServerReceivedSignal.emit(Request.APIInstance(WebAPILevel.getScanningData))

    @classmethod
    def setRunStatus(cls, state: int):
        status: int = state if state in RunStatusLevel.all() else RunStatusLevel.Running
        status: int = state if state in RunStatusLevel.all() else RunStatusLevel.Running
        if status == RunStatusLevel.Running:
            cls.changed({cls.RunStatus: status, cls.ScanningDateTime: datetime.now()})
        elif status == RunStatusLevel.ExitRunning:
            cls.changed({cls.RunStatus: status, cls.StopScanningDateTime: datetime.now(), cls.ScanningDateTime: None})
        else:
            cls.changed({cls.RunStatus: status})
        WebSlot.WebServerReceivedSignal.emit(Request.APIInstance(WebAPILevel.getScanningData))

    @classmethod
    def setPause(cls, enable: (int, bool)):
        status: int = RunStatusLevel.PauseRunning if enable else RunStatusLevel.Running
        cls.changed({cls.RunStatus: status})
        WebSlot.WebServerReceivedSignal.emit(Request.APIInstance(WebAPILevel.getScanningData))

    @classmethod
    def setExit(cls):
        status: int = RunStatusLevel.ExitRunning
        cls.changed({cls.RunStatus: status, cls.StopScanningDateTime: datetime.now(), cls.ScanningDateTime: None})
        WebSlot.WebServerReceivedSignal.emit(Request.APIInstance(WebAPILevel.getScanningData))

    @classmethod
    def setRunning(cls):
        status: int = RunStatusLevel.Running
        cls.changed({cls.RunStatus: status, cls.ScanningDateTime: datetime.now()})
        WebSlot.WebServerReceivedSignal.emit(Request.APIInstance(WebAPILevel.getScanningData))

    @classmethod
    def IsPause(cls) -> bool:
        item: cls = cls.first()
        return item.RunStatus == RunStatusLevel.PauseRunning

    @classmethod
    def isExit(cls) -> bool:
        item: cls = cls.first()
        return item.RunStatus == RunStatusLevel.ExitRunning


    @classmethod
    def getRunStatus(cls) -> int:
        item: cls = cls.first()
        return item.RunStatus

    @classmethod
    def setObjectiveLevel          (cls, value: int             ):
        cls.changed({cls.ObjectiveLevel          : value})

    @classmethod
    def setChamberGroupNumber      (cls, value: int             ):
        cls.changed({cls.ChamberGroupNumber      : value})

    @classmethod
    def setChamberRowNumber        (cls, value: int             ):
        cls.changed({cls.ChamberRowNumber        : value})

    @classmethod
    def setTrayNumber              (cls, value: int             ):
        cls.changed({cls.TrayNumber              : value})

    @classmethod
    def setRowNumber               (cls, value: int             ):
        cls.changed({cls.RowNumber               : value})

    @classmethod
    def setColNumber               (cls, value: int             ):
        cls.changed({cls.ColNumber               : value})

    @classmethod
    def setScanStatus              (cls, value: int             ):
        cls.changed({cls.ScanStatus              : value})

    @classmethod
    def setRunStatus               (cls, value: int             ):
        cls.changed({cls.RunStatus               : value})

    @classmethod
    def setTemplate_ID             (cls, value: int             ):
        cls.changed({cls.Template_ID             : value})

    @classmethod
    def setPreferredClassifier_ID  (cls, value: int             ):
        cls.changed({cls.PreferredClassifier_ID  : value})

    @classmethod
    def setPreviewClassifier_ID    (cls, value: int             ):
        cls.changed({cls.PreviewClassifier_ID    : value})

    @classmethod
    def setCollectClassifier_ID    (cls, value: int             ):
        cls.changed({cls.CollectClassifier_ID    : value})

    @classmethod
    def setUser_ID                 (cls, value: int             ):
        cls.changed({cls.User_ID                 : value})

    @classmethod
    def setOperatingStatus_ID      (cls, value: int             ):
        cls.changed({cls.OperatingStatus_ID      : value})

    @classmethod
    def setCodeString              (cls, value: int             ):
        cls.changed({cls.CodeString              : value})

    @classmethod
    def setScanningDateTime        (cls, value: str             ):
        cls.changed({cls.ScanningDateTime        : value})

    @classmethod
    def setStopScanningDateTime    (cls, value: datetime        ):
        cls.changed({cls.StopScanningDateTime    : value})

    @classmethod
    def getObjectiveLevel          (cls) -> int             :
        item: cls = cls.first()
        return item.GetObjectiveLevel                  #

    @classmethod
    def getChamberGroupNumber      (cls) -> int             :
        item: cls = cls.first()
        return item.GetChamberGroupNumber              #

    @classmethod
    def getChamberRowNumber        (cls) -> int             :
        item: cls = cls.first()
        return item.GetChamberRowNumber                #

    @classmethod
    def getTrayNumber              (cls) -> int             :
        item: cls = cls.first()
        return item.GetTrayNumber                      #

    @classmethod
    def getRowNumber               (cls) -> int             :
        item: cls = cls.first()
        return item.GetRowNumber                       #

    @classmethod
    def getColNumber               (cls) -> int             :
        item: cls = cls.first()
        return item.GetColNumber                       #

    @classmethod
    def getScanStatus              (cls) -> int             :
        item: cls = cls.first()
        return item.GetScanStatus                      #

    @classmethod
    def getRunStatus               (cls) -> int             :
        item: cls = cls.first()
        return item.GetRunStatus                       #

    @classmethod
    def getTemplate_ID             (cls) -> int             :
        item: cls = cls.first()
        return item.GetTemplate_ID                     #

    @classmethod
    def getPreferredClassifier_ID  (cls) -> int             :
        item: cls = cls.first()
        return item.GetPreferredClassifier_ID          #

    @classmethod
    def getPreviewClassifier_ID    (cls) -> int             :
        item: cls = cls.first()
        return item.GetPreviewClassifier_ID            #

    @classmethod
    def getCollectClassifier_ID    (cls) -> int             :
        item: cls = cls.first()
        return item.GetCollectClassifier_ID            #

    @classmethod
    def getUser_ID                 (cls) -> int             :
        item: cls = cls.first()
        return item.GetUser_ID                         #

    @classmethod
    def getOperatingStatus_ID      (cls) -> int             :
        item: cls = cls.first()
        return item.GetOperatingStatus_ID              #

    @classmethod
    def getCodeString              (cls) -> int             :
        item: cls = cls.first()
        return item.GetCodeString                      #

    @classmethod
    def getScanningDateTime        (cls) -> str             :
        item: cls = cls.first()
        return item.GetScanningDateTime                #

    @classmethod
    def getStopScanningDateTime    (cls) -> datetime        :
        item: cls = cls.first()
        return item.GetStopScanningDateTime            #

















    __field__ = (
        'ID'                        ,
        'ObjectiveLevel'            ,
        'ChamberGroupNumber'        ,
        'ChamberRowNumber'          ,
        'TrayNumber'                ,
        'RowNumber'                 ,
        'ColNumber'                 ,
        'ScanStatus'                ,
        'RunStatus'                 ,
        'Template_ID'               ,
        'PreferredClassifier_ID'    ,
        'PreviewClassifier_ID'      ,
        'CollectClassifier_ID'      ,
        'User_ID'                   ,
        'OperatingStatus_ID'        ,
        'CodeString'                ,
        'ScanningDateTime'          ,
        'StopScanningDateTime'      ,
    )
    __types__ = (
        int             ,
        int             ,
        int             ,
        int             ,
        int             ,
        int             ,
        int             ,
        int             ,
        int             ,
        int             ,
        int             ,
        int             ,
        int             ,
        int             ,
        int             ,
        str             ,
        datetime        ,
        datetime        ,

    )

    def SetID                      (self, value: int     ):
        if isinstance(value, int     ):
            self.ID                      = value

    def SetObjectiveLevel          (self, value: int     ):
        if isinstance(value, int     ):
            self.ObjectiveLevel          = value

    def SetChamberGroupNumber      (self, value: int     ):
        if isinstance(value, int     ):
            self.ChamberGroupNumber      = value

    def SetChamberRowNumber        (self, value: int     ):
        if isinstance(value, int     ):
            self.ChamberRowNumber        = value

    def SetTrayNumber              (self, value: int     ):
        if isinstance(value, int     ):
            self.TrayNumber              = value

    def SetRowNumber               (self, value: int     ):
        if isinstance(value, int     ):
            self.RowNumber               = value

    def SetColNumber               (self, value: int     ):
        if isinstance(value, int     ):
            self.ColNumber               = value

    def SetScanStatus              (self, value: int     ):
        if isinstance(value, int     ):
            self.ScanStatus              = value

    def SetRunStatus               (self, value: int     ):
        if isinstance(value, int     ):
            self.RunStatus               = value

    def SetTemplate_ID             (self, value: int     ):
        if isinstance(value, int     ):
            self.Template_ID             = value

    def SetPreferredClassifier_ID  (self, value: int     ):
        if isinstance(value, int     ):
            self.PreferredClassifier_ID  = value

    def SetPreviewClassifier_ID    (self, value: int     ):
        if isinstance(value, int     ):
            self.PreviewClassifier_ID    = value

    def SetCollectClassifier_ID    (self, value: int     ):
        if isinstance(value, int     ):
            self.CollectClassifier_ID    = value

    def SetUser_ID                 (self, value: int     ):
        if isinstance(value, int     ):
            self.User_ID                 = value

    def SetOperatingStatus_ID      (self, value: int     ):
        if isinstance(value, int     ):
            self.OperatingStatus_ID      = value

    def SetCodeString              (self, value: str     ):
        if isinstance(value, str     ):
            self.CodeString              = value

    def SetScanningDateTime        (self, value: datetime):
        if isinstance(value, datetime):
            self.ScanningDateTime        = value

    def SetStopScanningDateTime    (self, value: datetime):
        if isinstance(value, datetime):
            self.StopScanningDateTime    = value

    @property
    def GetID                      (self) -> int             :
        return None if not self.hasID                       else self.ID

    @property
    def GetObjectiveLevel          (self) -> int             :
        return None if not self.hasObjectiveLevel           else self.ObjectiveLevel

    @property
    def GetChamberGroupNumber      (self) -> int             :
        return None if not self.hasChamberGroupNumber       else self.ChamberGroupNumber

    @property
    def GetChamberRowNumber        (self) -> int             :
        return None if not self.hasChamberRowNumber         else self.ChamberRowNumber

    @property
    def GetTrayNumber              (self) -> int             :
        return None if not self.hasTrayNumber               else self.TrayNumber

    @property
    def GetRowNumber               (self) -> int             :
        return None if not self.hasRowNumber                else self.RowNumber

    @property
    def GetColNumber               (self) -> int             :
        return None if not self.hasColNumber                else self.ColNumber

    @property
    def GetScanStatus              (self) -> int             :
        return None if not self.hasScanStatus               else self.ScanStatus

    @property
    def GetRunStatus               (self) -> int             :
        return None if not self.hasRunStatus                else self.RunStatus

    @property
    def GetTemplate_ID             (self) -> int             :
        return None if not self.hasTemplate_ID              else self.Template_ID

    @property
    def GetPreferredClassifier_ID  (self) -> int             :
        return None if not self.hasPreferredClassifier_ID   else self.PreferredClassifier_ID

    @property
    def GetPreviewClassifier_ID    (self) -> int             :
        return None if not self.hasPreviewClassifier_ID     else self.PreviewClassifier_ID

    @property
    def GetCollectClassifier_ID    (self) -> int             :
        return None if not self.hasCollectClassifier_ID     else self.CollectClassifier_ID

    @property
    def GetUser_ID                 (self) -> int             :
        return None if not self.hasUser_ID                  else self.User_ID

    @property
    def GetOperatingStatus_ID      (self) -> int             :
        return None if not self.hasOperatingStatus_ID       else self.OperatingStatus_ID

    @property
    def GetCodeString              (self) -> str             :
        return None if not self.hasCodeString               else self.CodeString

    @property
    def GetScanningDateTime        (self) -> datetime        :
        return None if not self.hasScanningDateTime         else self.ScanningDateTime

    @property
    def GetStopScanningDateTime    (self) -> datetime        :
        return None if not self.hasStopScanningDateTime     else self.StopScanningDateTime



    @property
    def hasID                      (self) -> bool:
        return hasattr(self, 'ID'                        ) and isinstance(self.ID                      , int             )

    @property
    def hasObjectiveLevel          (self) -> bool:
        return hasattr(self, 'ObjectiveLevel'            ) and isinstance(self.ObjectiveLevel          , int             )

    @property
    def hasChamberGroupNumber      (self) -> bool:
        return hasattr(self, 'ChamberGroupNumber'        ) and isinstance(self.ChamberGroupNumber      , int             )

    @property
    def hasChamberRowNumber        (self) -> bool:
        return hasattr(self, 'ChamberRowNumber'          ) and isinstance(self.ChamberRowNumber        , int             )

    @property
    def hasTrayNumber              (self) -> bool:
        return hasattr(self, 'TrayNumber'                ) and isinstance(self.TrayNumber              , int             )

    @property
    def hasRowNumber               (self) -> bool:
        return hasattr(self, 'RowNumber'                 ) and isinstance(self.RowNumber               , int             )

    @property
    def hasColNumber               (self) -> bool:
        return hasattr(self, 'ColNumber'                 ) and isinstance(self.ColNumber               , int             )

    @property
    def hasScanStatus              (self) -> bool:
        return hasattr(self, 'ScanStatus'                ) and isinstance(self.ScanStatus              , int             )

    @property
    def hasRunStatus               (self) -> bool:
        return hasattr(self, 'RunStatus'                 ) and isinstance(self.RunStatus               , int             )

    @property
    def hasTemplate_ID             (self) -> bool:
        return hasattr(self, 'Template_ID'               ) and isinstance(self.Template_ID             , int             )

    @property
    def hasPreferredClassifier_ID  (self) -> bool:
        return hasattr(self, 'PreferredClassifier_ID'    ) and isinstance(self.PreferredClassifier_ID  , int             )

    @property
    def hasPreviewClassifier_ID    (self) -> bool:
        return hasattr(self, 'PreviewClassifier_ID'      ) and isinstance(self.PreviewClassifier_ID    , int             )

    @property
    def hasCollectClassifier_ID    (self) -> bool:
        return hasattr(self, 'CollectClassifier_ID'      ) and isinstance(self.CollectClassifier_ID    , int             )

    @property
    def hasUser_ID                 (self) -> bool:
        return hasattr(self, 'User_ID'                   ) and isinstance(self.User_ID                 , int             )

    @property
    def hasOperatingStatus_ID      (self) -> bool:
        return hasattr(self, 'OperatingStatus_ID'        ) and isinstance(self.OperatingStatus_ID      , int             )

    @property
    def hasCodeString              (self) -> bool:
        return hasattr(self, 'CodeString'                ) and isinstance(self.CodeString              , str             )

    @property
    def hasScanningDateTime        (self) -> bool:
        return hasattr(self, 'ScanningDateTime'          ) and isinstance(self.ScanningDateTime        , (datetime, DateTime, Qt.QDateTime)        )

    @property
    def hasStopScanningDateTime    (self) -> bool:
        return hasattr(self, 'StopScanningDateTime'      ) and isinstance(self.StopScanningDateTime    , (datetime, DateTime, Qt.QDateTime)        )
