public static QueueManager CreateNewQueueManager(Invoice invoice, InvoiceDetail invoiceDetail,
                                                         ServiceCategory_StationPoint_cu serviceCategoryStationPoint,
                                                         List <StationPointStage_cu> stationPointStagesList)
        {
            if (invoice == null || invoiceDetail == null || serviceCategoryStationPoint == null)
            {
                return(null);
            }

            QueueManager manager = DBCommon.CreateNewDBEntity <QueueManager>();

            if (invoiceDetail.Doctor_CU_ID != null)
            {
                manager.Doctor_CU_ID = Convert.ToInt32(invoiceDetail.Doctor_CU_ID);
            }
            manager.InvoiceDetailID = invoiceDetail.ID;
            manager.Service_CU_ID   = invoiceDetail.Service_CU_ID != null
                                ? Convert.ToInt32(invoiceDetail.Service_CU_ID)
                                : (int?)null;

            if (invoiceDetail.StationPointID != null)
            {
                manager.StationPoint_CU_ID = Convert.ToInt32(invoiceDetail.StationPointID);
            }
            else
            {
                manager.StationPoint_CU_ID = serviceCategoryStationPoint.StationPoint_CU_ID;
            }
            if (invoiceDetail.StationPointStagesID != null)
            {
                manager.StationPointStage_CU_ID = Convert.ToInt32(invoiceDetail.StationPointStagesID);
            }
            else if (stationPointStagesList.Count > 0)
            {
                manager.StationPointStage_CU_ID = stationPointStagesList.First().ID;
            }
            manager.Patient_CU_ID           = invoice.Patient_CU_ID;
            manager.QueueManagerStatus_P_ID = (int)DB_QueueManagerStatus.Waiting;
            manager.IsOnDuty = true;
            return(manager);
        }
        public static QueueManager CreateNewQueueManager(Invoice invoice, InvoiceDetail invoiceDetail)
        {
            Service_cu service;

            if (invoiceDetail.Service_CU_ID != null)
            {
                service = GetService(Convert.ToInt32(invoiceDetail.Service_CU_ID));
            }
            else
            {
                return(null);
            }

            List <StationPointStage_cu> serviceType_StationPointStagesList     = null;
            List <StationPointStage_cu> ServiceCategory_StationPointStagesList = null;
            List <StationPointStage_cu> service_StationPointStagesList         = null;

            ServiceCategory_cu serviceCategory = GetServiceCategory(Convert.ToInt32(service.ServiceCategory_CU_ID));
            ServiceCategory_StationPoint_cu serviceCategoryStation = null;

            if (serviceCategory != null)
            {
                serviceCategoryStation = GetServiceCategoryStationPoint(serviceCategory.ID);
            }
            if (serviceCategoryStation != null)
            {
                ServiceCategory_StationPointStagesList = GetStationPointStagesList(serviceCategoryStation.StationPoint_CU_ID, true);
            }

            DB_ServiceType serviceType = (DB_ServiceType)service.ServiceType_P_ID;
            ServiceType_StationPoint_cu serviceTypeStation =
                ServiceType_StationPoint_cu.ItemsList.Find(
                    item => Convert.ToInt32(item.ServiceType_P_ID).Equals((int)serviceType));

            if (serviceTypeStation != null)
            {
                serviceType_StationPointStagesList = GetStationPointStagesList(serviceTypeStation.StationPoint_CU_ID, true);
            }

            Service_StationPoint_cu serviceStation = GetServiceStationPoint(service.ID);

            if (serviceStation != null)
            {
                service_StationPointStagesList = GetStationPointStagesList(serviceStation.StationPoint_CU_ID, true);
            }

            if (serviceStation != null)
            {
                return(CreateNewQueueManager(invoice, invoiceDetail, serviceStation, service_StationPointStagesList));
            }
            if (serviceCategoryStation != null)
            {
                return(CreateNewQueueManager(invoice, invoiceDetail, serviceCategoryStation, ServiceCategory_StationPointStagesList));
            }
            if (serviceTypeStation != null)
            {
                return(CreateNewQueueManager(invoice, invoiceDetail, serviceTypeStation, serviceType_StationPointStagesList));
            }

            return(null);
        }