Exemple #1
0
        /// <summary>
        /// 拖放车辆
        /// </summary>
        /// <param name="carid"></param>
        /// <param name="orders"></param>
        public void DragMixerCar(string carid, string[] orders)
        {
            Car         thisCar = this.Get(carid);
            IList <Car> carlist = this.Query().Where(c => c.CarTypeID == CarType.Mixer && c.CarStatus == thisCar.CarStatus && c.IsUsed)
                                  .OrderBy(c => c.OrderNum).OrderBy(c => c.ID).ToList();

            string[]     beforeDragCar = carlist.Select(p => p.ID).ToArray();
            CarChangeLog changelog     = new CarChangeLog();
            string       beforeNum     = null;
            string       afterNum      = null;
            //创建顺序索引
            Dictionary <int, Car> cardic = new Dictionary <int, Car>();

            for (int i = 0; i < carlist.Count; i++)
            {
                cardic.Add(i, carlist[i]);
            }

            int dragedPos     = 0;
            int beforeDragPos = 0;

            //获取之后的位置
            for (int i = 0; i < orders.Length; i++)
            {
                if (carid == orders[i])
                {
                    dragedPos = i;
                }

                afterNum = afterNum + orders[i] + ",";
            }
            if (afterNum.Length > 0)
            {
                afterNum = afterNum.Remove(afterNum.Length - 1, 1);
            }
            //获取之前的位置
            for (int i = 0; i < beforeDragCar.Length; i++)
            {
                if (carid == beforeDragCar[i])
                {
                    beforeDragPos = i;
                }

                beforeNum = beforeNum + beforeDragCar[i] + ",";
            }
            if (beforeNum.Length > 0)
            {
                beforeNum = beforeNum.Remove(beforeNum.Length - 1, 1);
            }
            using (var tx = this.m_UnitOfWork.BeginTransaction())
            {
                try
                {
                    //提前操作,更新提前之后的操作,直到原来的位置
                    if (beforeDragPos > dragedPos)
                    {
                        for (int i = dragedPos; i < beforeDragPos; i++)
                        {
                            if (cardic.ContainsKey(i))
                            {
                                Car swapCar = cardic[i];
                                if (i == dragedPos)
                                {
                                    int swaporder = swapCar.OrderNum ?? 0;
                                    if (thisCar.OrderNum != swaporder)
                                    {
                                        thisCar.OrderNum = swaporder;
                                        this.Update(thisCar, null);
                                    }
                                }
                                swapCar.OrderNum = swapCar.OrderNum + 1;
                                this.Update(swapCar, null);
                            }
                        }
                    }
                    else
                    {
                        //挪后操作
                        for (int i = dragedPos; i > beforeDragPos; i--)
                        {
                            if (cardic.ContainsKey(i))
                            {
                                Car swapCar = cardic[i];
                                if (i == dragedPos)
                                {
                                    int swaporder = swapCar.OrderNum ?? 0;
                                    if (thisCar.OrderNum != swaporder)
                                    {
                                        thisCar.OrderNum = swaporder;
                                        this.Update(thisCar, null);
                                    }
                                }
                                swapCar.OrderNum = swapCar.OrderNum - 1;
                                this.Update(swapCar, null);
                            }
                        }
                    }


                    changelog.beforeNum = beforeNum;
                    changelog.afterNum  = afterNum;
                    this.m_UnitOfWork.GetRepositoryBase <CarChangeLog>().Add(changelog);
                    //记录日志
                    LogUserOperation(SysLogType.ChangeCarOrder, carid, null, string.Format("车辆{0}从位置{1}移动至位置{2}", carid, beforeDragPos + 1, dragedPos + 1));
                    tx.Commit();
                }
                catch (Exception ex)
                {
                    tx.Rollback();
                    logger.Error(ex.Message, ex);
                    throw ex;
                }
            }
        }
Exemple #2
0
        public void ShiftMixerCarStatus(string operType, string carId, string status)
        {
            Car         thisCar = this.Get(carId);
            IList <Car> carlist = this.Query().Where(c => c.CarTypeID == CarType.Mixer && c.CarStatus == status && c.IsUsed)
                                  .OrderBy(c => c.OrderNum).OrderBy(c => c.ID).ToList();
            CarChangeLog changelog = new CarChangeLog();
            string       beforeNum = null;

            foreach (Car item in carlist)
            {
                beforeNum = beforeNum + item.CarNo + ",";
            }
            // this.m_UnitOfWork.GetRepositoryBase<CarChangeLog>().Add(changelog);
            //置顶不改变其状态,仅修改orderNum
            if (operType == "Top")
            {
                int minValue = carlist.Min(c => c.OrderNum) ?? 0;
                thisCar.OrderNum = minValue - 1;
                this.Update(thisCar, null);
            }
            else if (operType == "Up")
            {
                //如果为休息状态,上移时自动进入可调度队列
                if (status == CarStatus.RestCar)
                {
                    this.ChangeCarStatus(thisCar.ID, CarStatus.AllowShipCar);
                    LogUserOperation(SysLogType.ChangeCarOrder, thisCar.ID, null, string.Format("车辆{0}由休息->可调度,经办人:{1}", thisCar.ID, AuthorizationService.CurrentUserID));
                    return;
                }
                //如果为出车状态,上移则进入可调度列表
                if (status == CarStatus.ShippingCar)
                {
                    this.ChangeCarStatus(thisCar.ID, CarStatus.AllowShipCar);
                    LogUserOperation(SysLogType.ChangeCarOrder, thisCar.ID, null, string.Format("车辆{0}由出货->可调度,经办人:{1}", thisCar.ID, AuthorizationService.CurrentUserID));
                    return;
                }
                //可调度状态则交换ordernum
                if (status == CarStatus.AllowShipCar)
                {
                    Car prevCar = carlist.Where(c => c.OrderNum < thisCar.OrderNum)
                                  .OrderByDescending(c => c.OrderNum).FirstOrDefault();
                    if (prevCar != null && thisCar.OrderNum != prevCar.OrderNum)
                    {
                        //交换orderNum
                        int orderNum = prevCar.OrderNum ?? 0;
                        prevCar.OrderNum = thisCar.OrderNum;
                        thisCar.OrderNum = orderNum;
                        this.Update(prevCar, null);
                        this.Update(thisCar, null);
                    }
                }
            }
            else if (operType == "Down")
            {
                //如果在送货中,下移则进入休息队列
                if (status == CarStatus.ShippingCar)
                {
                    this.ChangeCarStatus(thisCar.ID, CarStatus.RestCar);
                    LogUserOperation(SysLogType.ChangeCarOrder, thisCar.ID, null, string.Format("车辆{0}由可调度->休息,经办人:{1}", thisCar.ID, AuthorizationService.CurrentUserID));
                    return;
                }
                //如果为可调度状态则交换顺序。
                if (status == CarStatus.AllowShipCar)
                {
                    Car nextCar = carlist.Where(c => c.OrderNum > thisCar.OrderNum).FirstOrDefault();
                    if (nextCar != null && nextCar.OrderNum != thisCar.OrderNum)
                    {
                        int orderNum = nextCar.OrderNum ?? 0;
                        nextCar.OrderNum = thisCar.OrderNum;
                        thisCar.OrderNum = orderNum;
                        this.Update(nextCar, null);
                        this.Update(thisCar, null);
                    }
                }
            }

            else if (operType == "Handle")
            {
                if (status == CarStatus.AllowShipCar)
                {
                    this.ChangeCarStatus(thisCar.ID, CarStatus.ShippingCar);
                    LogUserOperation(SysLogType.ChangeCarOrder, thisCar.ID, null, string.Format("车辆{0}出厂,经办人:{1}", thisCar.ID, AuthorizationService.CurrentUserID));
                    return;
                }
            }

            IList <Car> carlist1 = this.Query().Where(c => c.CarTypeID == CarType.Mixer && c.CarStatus == status && c.IsUsed)
                                   .OrderBy(c => c.OrderNum).OrderBy(c => c.ID).ToList();
            string afterNum = null;

            foreach (Car item in carlist1)
            {
                afterNum = afterNum + item.CarNo + ",";
            }
            if (beforeNum.Length > 0)
            {
                beforeNum = beforeNum.Remove(beforeNum.Length - 1, 1);
            }
            if (afterNum.Length > 0)
            {
                afterNum = afterNum.Remove(afterNum.Length - 1, 1);
            }
            changelog.beforeNum = beforeNum;
            changelog.afterNum  = afterNum;
            //记录日志
            LogUserOperation(SysLogType.ChangeCarOrder, carId, null, string.Format("车辆{0}从位置{1}移动至位置{2}", carId, carlist.Select(c => c.ID).ToList().IndexOf(carId) + 1, carlist1.Select(c => c.ID).ToList().IndexOf(carId) + 1));

            this.m_UnitOfWork.GetRepositoryBase <CarChangeLog>().Add(changelog);
        }