Ejemplo n.º 1
0
        public void TestWork_OneJob()
        {
            ObjectJobDefinition d = new ObjectJobDefinition(
                new PipelineDefinition(
                    new AlgorithmDefinition[] { }),
                new JobInput[] { });
            JobRequest    r        = new JobRequest(d);
            JobTicket     ticket   = new JobTicket(r, new DudCancellationHandler());
            JobQueue      queue    = new JobQueue();
            WorkerImpl    worker   = new WorkerImpl();
            QueueExecutor executor = new QueueExecutor(queue);

            executor.Worker        = worker;
            executor.PluginFactory = new DudFactory();
            executor.Persister     = new DudPersister();
            bool didComplete = false;

            executor.ExhaustedQueue += (s, e) => didComplete = true;
            queue.Enqueue(ticket);

            executor.Start();

            int totalTime = 0;

            while (didComplete == false)
            {
                Thread.Sleep(1);
                totalTime += 1;
                if (totalTime > 10000)
                {
                    Assert.Fail("Did not complete job in less than 10s");
                }
            }

            Assert.IsTrue(worker.DidWork);
        }
Ejemplo n.º 2
0
        private void FormJobTicketItem_Load(object sender, EventArgs e)
        {
            InitComponents();
            WMSEntities wmsEntities = new WMSEntities();
            JobTicket   jobTicket   = null;

            try
            {
                jobTicket = (from j in wmsEntities.JobTicket where j.ID == jobTicketID select j).FirstOrDefault();
            }
            catch
            {
                MessageBox.Show("加载数据失败,请检查网络连接", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
                return;
            }
            if (jobTicket == null)
            {
                MessageBox.Show("作业单信息不存在,请刷新查询", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
                return;
            }
            this.Search();
        }
Ejemplo n.º 3
0
        public static bool GeneratePutOutStorageTicketFullSync(int[] jobTicketIDs, WMSEntities wmsEntities)
        {
            int succeedCount = 0;

            foreach (int jobTicketID in jobTicketIDs)
            {
                var newPutOutStorageTicket = new PutOutStorageTicket();

                JobTicket jobTicket = (from s in wmsEntities.JobTicket
                                       where s.ID == jobTicketID
                                       select s).FirstOrDefault();

                if (jobTicket == null)
                {
                    MessageBox.Show("作业单不存在,请重新查询", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
                newPutOutStorageTicket.State        = PutOutStorageTicketViewMetaData.STRING_STATE_NOT_LOADED;
                newPutOutStorageTicket.JobTicketID  = jobTicket.ID;
                newPutOutStorageTicket.ProjectID    = GlobalData.ProjectID;
                newPutOutStorageTicket.WarehouseID  = GlobalData.WarehouseID;
                newPutOutStorageTicket.CreateUserID = GlobalData.UserID;
                newPutOutStorageTicket.CreateTime   = DateTime.Now;

                JobTicketItem[] jobTicketItems = jobTicket.JobTicketItem.ToArray();

                //把所有条目加进出库单
                foreach (var jobTicketItem in jobTicketItems)
                {
                    if (jobTicketItem == null)
                    {
                        MessageBox.Show("无法找到作业单条目,请重新查询", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return(false);
                    }

                    PutOutStorageTicketItem newPutOutStorageTicketItem = new PutOutStorageTicketItem();

                    newPutOutStorageTicketItem.State                   = PutOutStorageTicketItemViewMetaData.STRING_STATE_WAIT_FOR_LOAD;
                    newPutOutStorageTicketItem.StockInfoID             = jobTicketItem.StockInfoID;
                    newPutOutStorageTicketItem.JobTicketItemID         = jobTicketItem.ID;
                    newPutOutStorageTicketItem.RealAmount              = 0;
                    newPutOutStorageTicketItem.Unit                    = jobTicketItem.Unit;
                    newPutOutStorageTicketItem.UnitAmount              = jobTicketItem.UnitAmount;
                    newPutOutStorageTicketItem.ReturnQualityUnit       = "个";
                    newPutOutStorageTicketItem.ReturnQualityUnitAmount = 1;
                    newPutOutStorageTicketItem.ReturnRejectUnit        = "个";
                    newPutOutStorageTicketItem.ReturnRejectUnitAmount  = 1;

                    decimal restSchedulableAmountNoUnit = ((jobTicketItem.RealAmount ?? 0) - (jobTicketItem.ScheduledPutOutAmount ?? 0)) * (jobTicketItem.UnitAmount ?? 1);
                    if (restSchedulableAmountNoUnit <= 0)
                    {
                        continue;
                    }
                    jobTicketItem.ScheduledPutOutAmount        = jobTicketItem.RealAmount;
                    newPutOutStorageTicketItem.ScheduledAmount = restSchedulableAmountNoUnit / newPutOutStorageTicketItem.UnitAmount;
                    newPutOutStorageTicket.PutOutStorageTicketItem.Add(newPutOutStorageTicketItem);
                }
                if (newPutOutStorageTicket.PutOutStorageTicketItem.Count == 0)
                {
                    continue;
                }
                //生成出库单号
                if (string.IsNullOrWhiteSpace(newPutOutStorageTicket.No))
                {
                    DateTime createDay      = new DateTime(newPutOutStorageTicket.CreateTime.Value.Year, newPutOutStorageTicket.CreateTime.Value.Month, newPutOutStorageTicket.CreateTime.Value.Day);
                    DateTime nextDay        = createDay.AddDays(1);
                    int      maxRankOfToday = Utilities.GetMaxTicketRankOfDay((from p in wmsEntities.PutOutStorageTicket
                                                                               where p.CreateTime >= createDay && p.CreateTime < nextDay
                                                                               select p.No).ToArray());
                    newPutOutStorageTicket.No = Utilities.GenerateTicketNo("C", newPutOutStorageTicket.CreateTime.Value, maxRankOfToday + 1);
                }
                wmsEntities.PutOutStorageTicket.Add(newPutOutStorageTicket);
                wmsEntities.SaveChanges();
                succeedCount++;
            }
            if (succeedCount == 0)
            {
                MessageBox.Show("没有可用于分配出库的零件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 4
0
 public void TestConstructor_NullHandler()
 {
     IJobDefinition d      = new DudDefinition();
     JobRequest     r      = new JobRequest(d);
     JobTicket      ticket = new JobTicket(r, null);
 }
Ejemplo n.º 5
0
 public void TestConstructor_NullRequest()
 {
     JobTicket ticket = new JobTicket(null, new DudHandler());
 }
Ejemplo n.º 6
0
        private void buttonDelete_Click(object sender, EventArgs e)
        {
            int[] ids = Utilities.GetSelectedIDs(this.reoGridControlMain);
            if (ids.Length == 0)
            {
                MessageBox.Show("请选择要删除的项目!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            WMSEntities wmsEntities = new WMSEntities();

            //如果被出库单引用了,不能删除
            try
            {
                StringBuilder sbIDArray = new StringBuilder();
                foreach (int id in ids)
                {
                    sbIDArray.Append(id + ",");
                }
                sbIDArray.Length--;
                int countRef = wmsEntities.Database.SqlQuery <int>(string.Format("SELECT COUNT(*) FROM PutOutStorageTicket WHERE JobTicketID IN ({0})", sbIDArray.ToString())).Single();
                if (countRef > 0)
                {
                    MessageBox.Show("删除失败,作业单被出库单引用,请先删除出库单", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }
            catch
            {
                MessageBox.Show("操作失败,请检查您的网络连接", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (MessageBox.Show("确定要删除选中项吗?\n重要提示:\n删除后所有零件的分配翻包数量将会退回发货单中,无视实际翻包数量!\n请谨慎操作!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
            {
                return;
            }
            this.labelStatus.Text = "正在删除";
            new Thread(new ThreadStart(() =>
            {
                try
                {
                    List <int> shipmentTicketIDs = new List <int>();
                    foreach (int id in ids)
                    {
                        JobTicket jobTicket = (from j in wmsEntities.JobTicket where j.ID == id select j).FirstOrDefault();
                        if (jobTicket.State != JobTicketViewMetaData.STRING_STATE_UNFINISHED)
                        {
                            MessageBox.Show("删除失败,只能删除未完成翻包的作业单!\n如果需要强行删除,请使用修改功能将单据状态改为未完成", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                        foreach (JobTicketItem jobTicketItem in jobTicket.JobTicketItem)
                        {
                            ShipmentTicketItem shipmentTicketItem = (from s in wmsEntities.ShipmentTicketItem where s.ID == jobTicketItem.ShipmentTicketItemID select s).FirstOrDefault();
                            if (shipmentTicketItem == null)
                            {
                                continue;
                            }
                            //如果删除作业单,则发货单直接把计划翻包数量的全部数量加回来,无视实际翻包数量
                            shipmentTicketItem.ScheduledJobAmount -= ((jobTicketItem.ScheduledAmount ?? 0) * (jobTicketItem.UnitAmount ?? 1)) / (shipmentTicketItem.UnitAmount ?? 1);
                        }
                        if (jobTicket.ShipmentTicketID != null)
                        {
                            shipmentTicketIDs.Add(jobTicket.ShipmentTicketID.Value);
                        }
                        wmsEntities.Database.ExecuteSqlCommand(string.Format("DELETE FROM JobTicket WHERE ID = {0}", id));
                    }
                    wmsEntities.SaveChanges();
                    foreach (int shipmentTicketID in shipmentTicketIDs)
                    {
                        ShipmentTicketUtilities.UpdateShipmentTicketStateSync(shipmentTicketID, wmsEntities);
                    }
                }
                catch
                {
                    MessageBox.Show("删除失败,请检查网络连接", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                this.Invoke(new Action(() =>
                {
                    this.Search(true);
                }));
            })).Start();
        }
Ejemplo n.º 7
0
 public void Forward(JobTicket <TTicketOut> ticketOut)
 {
 }
Ejemplo n.º 8
0
        /// <summary>
        /// 无脑生成作业单,不选零件不填数量。
        /// </summary>
        /// <param name="shipmentTicketIDs"></param>
        /// <param name="wmsEntities"></param>
        public static bool GenerateJobTicketFullSync(int shipmentTicketID, WMSEntities wmsEntities, DateTime?createTime = null)
        {
            ShipmentTicket shipmentTicket = (from s in wmsEntities.ShipmentTicket
                                             where s.ID == shipmentTicketID
                                             select s).FirstOrDefault();

            if (shipmentTicket == null)
            {
                MessageBox.Show("发货单不存在,请重新查询", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            ShipmentTicketItem[] shipmentTicketItems = (from s in wmsEntities.ShipmentTicketItem
                                                        where s.ShipmentTicketID == shipmentTicketID
                                                        select s).ToArray();
            List <JobTicketItem> newJobTicketItems = new List <JobTicketItem>();

            for (int i = 0; i < shipmentTicketItems.Length; i++)
            {
                ShipmentTicketItem shipmentTicketItem = shipmentTicketItems[i];
                if (shipmentTicketItem == null)
                {
                    MessageBox.Show("发货单条目不存在,可能已被删除,请重新查询", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
                decimal restScheduableAmount = (shipmentTicketItem.ShipmentAmount - (shipmentTicketItem.ScheduledJobAmount ?? 0)) ?? 0;
                if (restScheduableAmount <= 0)
                {
                    continue;
                }
                var jobTicketItem = new JobTicketItem();
                jobTicketItem.ScheduledAmount      = restScheduableAmount;
                jobTicketItem.StockInfoID          = shipmentTicketItem.StockInfoID;
                jobTicketItem.ShipmentTicketItemID = shipmentTicketItem.ID;
                jobTicketItem.State      = JobTicketItemViewMetaData.STRING_STATE_UNFINISHED;
                jobTicketItem.Unit       = shipmentTicketItem.Unit;
                jobTicketItem.UnitAmount = shipmentTicketItem.UnitAmount;
                jobTicketItem.RealAmount = 0;
                shipmentTicketItem.ScheduledJobAmount = (shipmentTicketItem.ScheduledJobAmount ?? 0) + jobTicketItem.ScheduledAmount;
                newJobTicketItems.Add(jobTicketItem);
            }
            if (newJobTicketItems.Count == 0)
            {
                MessageBox.Show("发货单 " + shipmentTicket.No + " 中无可分配翻包的零件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }

            JobTicket newJobTicket = new JobTicket();

            foreach (JobTicketItem item in newJobTicketItems)
            {
                newJobTicket.JobTicketItem.Add(item);
            }
            wmsEntities.JobTicket.Add(newJobTicket);

            newJobTicket.State            = JobTicketViewMetaData.STRING_STATE_UNFINISHED;
            newJobTicket.ShipmentTicketID = shipmentTicket.ID;
            newJobTicket.ProjectID        = GlobalData.ProjectID;
            newJobTicket.WarehouseID      = GlobalData.WarehouseID;
            newJobTicket.CreateUserID     = GlobalData.UserID;
            newJobTicket.CreateTime       = createTime ?? DateTime.Now;

            if (string.IsNullOrWhiteSpace(newJobTicket.JobTicketNo))
            {
                DateTime createDay      = new DateTime(shipmentTicket.CreateTime.Value.Year, shipmentTicket.CreateTime.Value.Month, shipmentTicket.CreateTime.Value.Day);
                DateTime nextDay        = createDay.AddDays(1);
                int      maxRankOfToday = Utilities.GetMaxTicketRankOfDay((from j in wmsEntities.JobTicket
                                                                           where j.CreateTime >= createDay && j.CreateTime < nextDay
                                                                           select j.JobTicketNo).ToArray());
                newJobTicket.JobTicketNo = Utilities.GenerateTicketNo("Z", newJobTicket.CreateTime.Value, maxRankOfToday + 1);
            }
            wmsEntities.SaveChanges();
            //更新发货单状态
            ShipmentTicketUtilities.UpdateShipmentTicketStateSync(shipmentTicketID, wmsEntities, true);
            return(true);
        }