コード例 #1
0
        /// <summary>
        /// 初始化队列名称
        /// </summary>
        /// <param name="departmentId"></param>
        private void InitQueueName(string departmentId, string applyId)
        {
            cbxQueueName.Items.Clear();

            if (string.IsNullOrEmpty(departmentId))
            {
                return;
            }

            DataTable dtQueues = _qm.GetQueueInfoByDeptId(departmentId);

            cbxQueueName.DisplayMember = "Name";
            cbxQueueName.ValueMember   = "Value";

            DataTable dtRooms = _qm.GetApplyRoomId(applyId);


            foreach (DataRow dr in dtQueues.Rows)
            {
                QueueData queueData = new QueueData();
                queueData.BindRowData(dr);


                //如果队列不包含房间信息,则不进行加载
                if (queueData.包含房间.房间明细.Count <= 0)
                {
                    continue;
                }

                if (dtRooms.Rows.Count > 0)
                {
                    //需要判断队列是否包含了对应的房间
                    bool hasRoom = false;

                    foreach (DataRow drRoom in dtRooms.Rows)
                    {
                        if (queueData.包含房间.房间明细.FindIndex(T => T.房间ID == drRoom["房间ID"].ToString()) >= 0)
                        {
                            hasRoom = true;
                            break;
                        }
                    }

                    if (hasRoom == false)
                    {
                        continue;
                    }
                }


                ItemBind ib = new ItemBind();

                ib.Name  = queueData.队列名称;
                ib.Value = queueData.队列ID;

                ib.Tag = queueData;

                cbxQueueName.Items.Add(ib);
            }

            if (cbxQueueName.Items.Count <= 0)
            {
                return;
            }

            //默认定位到队列人数最少且只有一个房间的队列
            if (cbxQueueName.Items.Count <= 1)
            {
                cbxQueueName.SelectedIndex = 0;
            }
            else
            {
                int    roomCount = 999999;
                string minQueue  = "";
                foreach (ItemBind ib in cbxQueueName.Items)
                {
                    QueueData queData = ib.Tag as QueueData;

                    if (queData.包含房间.房间明细.Count == 1)
                    {
                        int curCount = _qm.GetLineupCount(queData.队列ID, dtpIntoQueue.Value);
                        if (curCount < roomCount)
                        {
                            roomCount = curCount;
                            minQueue  = queData.队列名称;
                        }
                    }
                }

                if (string.IsNullOrEmpty(minQueue) == false)
                {
                    cbxQueueName.Text = minQueue;
                }
            }
        }