Esempio n. 1
0
        public RespFinishAll(IDbName database, int bInterfaceId, int cutCounter)
        {
            BeamCutQuery   BeamCutQuery   = new BeamCutQuery(database);
            StockQuery     StockQuery     = new StockQuery(database);
            EmployeeQuery  EmployeeQuery  = new EmployeeQuery(database);
            SequenceQuery  SequenceQuery  = new SequenceQuery(database);
            ScheduleQuery  ScheduleQuery  = new ScheduleQuery(database);
            ComponentQuery ComponentQuery = new ComponentQuery(database);

            try
            {
                var bInterface = BeamCutQuery.GetBeamInterfaceById(bInterfaceId);
                if (bInterface == null)
                {
                    Exception = new RespException(true, "Can not find BInterface", EKB_SYS_REQUEST.FINISH_ALL);
                    return;
                }

                var clonePo = BeamCutQuery.GetBeamCutPo(ShareFuncs.GetInt(bInterface.BeamCutPo_Id));
                if (clonePo == null)
                {
                    Exception = new RespException(true, "Invalid clone Po Id", EKB_SYS_REQUEST.BEAM_START_CUTTING);
                    return;
                }

                int addQty = 0;
                foreach (var seq in clonePo.BeamCutSeqs)
                {
                    var currentSeq = BeamCutQuery.GetBeamCutSeq(seq.id);
                    if (currentSeq.SequenceNo < bInterface.SequenceNo + bInterface.TotalSequence)
                    {
                        foreach (var size in seq.BeamCutSizes)
                        {
                            addQty         += ShareFuncs.GetInt(size.SizeQty - size.CutQty);
                            size.CutQty     = size.SizeQty;
                            size.Finished   = true;
                            size.LastUpdate = DateTime.Now;
                            BeamCutQuery.UpdateBeamSize(size);
                        }

                        currentSeq.CutQty    += addQty;
                        currentSeq.LastUpdate = DateTime.Now;
                        currentSeq.Finish     = true;
                        BeamCutQuery.UpdateBeamCutSeq(currentSeq);
                    }
                }

                bInterface.BeamCutCounter += cutCounter;
                bInterface.CuttingQty     += addQty;
                bInterface.StopCutTime     = DateTime.Now;
                if (!BeamCutQuery.UpdateBeamInterface(bInterface))
                {
                    Exception = new RespException(true, "Can not update BInterface", EKB_SYS_REQUEST.FINISH_ALL);
                    return;
                }
            }
            catch (Exception e)
            {
                Exception = new RespException(true, e.Message, EKB_SYS_REQUEST.FINISH_ALL);
            }
        }
Esempio n. 2
0
        public RespConfirmSize(IDbName database, int bInterfaceId, int sizeId, int sizeQty)
        {
            try
            {
                BeamCutQuery   = new BeamCutQuery(database);
                StockQuery     = new StockQuery(database);
                EmployeeQuery  = new EmployeeQuery(database);
                SequenceQuery  = new SequenceQuery(database);
                ScheduleQuery  = new ScheduleQuery(database);
                ComponentQuery = new ComponentQuery(database);

                var beamInterface = BeamCutQuery.GetBeamInterfaceById(bInterfaceId);
                if (beamInterface == null)
                {
                    Exception = new RespException(true, "Can not find BInterface", EKB_SYS_REQUEST.BEAM_CONFIRM_SIZE);
                    return;
                }

                var bdevice = BeamCutQuery.GetBeamCutDevice(beamInterface.BeamCutDevice_Id);

                if (bdevice == null)
                {
                    Exception = new RespException(true, "Can not find beam cut device", EKB_SYS_REQUEST.BEAM_CONFIRM_SIZE);
                    return;
                }

                var clonePo = BeamCutQuery.GetBeamCutPo(ShareFuncs.GetInt(beamInterface.BeamCutPo_Id));

                if (clonePo == null)
                {
                    Exception = new RespException(true, "Can not find clone Po", EKB_SYS_REQUEST.BEAM_CONFIRM_SIZE);
                    return;
                }

                var seq1 = BeamCutQuery.GetBeamCutSeq(ShareFuncs.GetInt(beamInterface.BeamCutStartSeq_Id));

                var seq2 = BeamCutQuery.GetBeamCutSeq(ShareFuncs.GetInt(beamInterface.BeamCutStopSeq_Id));

                int cutQty      = 0;
                int totalQty    = 0;
                int currentQty  = 0;
                int addQty      = 0;
                int seqTotalQty = 0;
                int seqQty      = 0;
                foreach (var seq in clonePo.BeamCutSeqs)
                {
                    if (seq.SequenceNo >= seq1.SequenceNo && seq.SequenceNo <= seq2.SequenceNo)
                    {
                        if (seq.Finish == false)
                        {
                            var sizes = BeamCutQuery.GetBeamCutSize(seq.id);

                            int seqcutQty = ShareFuncs.GetInt(seq.CutQty);
                            foreach (var size in sizes)
                            {
                                if (size.SizeId == sizeId)
                                {
                                    if (size.Finished != true && sizeQty > 0)
                                    {
                                        int oldval = ShareFuncs.GetInt(size.CutQty);

                                        int addval = ShareFuncs.GetInt(size.SizeQty) - oldval;

                                        if (sizeQty >= addval)
                                        {
                                            addval        = ShareFuncs.GetInt(size.SizeQty) - oldval;
                                            size.CutQty   = size.SizeQty;
                                            size.Finished = true;
                                            seqcutQty    += addval;
                                            sizeQty      -= addval;

                                            addQty += addval;
                                        }
                                        else
                                        {
                                            size.CutQty += sizeQty;
                                            seqcutQty   += sizeQty;
                                            addQty      += sizeQty;
                                            sizeQty      = 0;
                                        }
                                        size.BeamCutDevice_Id = beamInterface.BeamCutDevice_Id;
                                        size.Worker_Id        = beamInterface.Employee_Id;
                                        size.LastUpdate       = DateTime.Now;
                                        BeamCutQuery.UpdateBeamSize(size);
                                    }

                                    totalQty += ShareFuncs.GetInt(size.SizeQty);
                                    cutQty   += ShareFuncs.GetInt(size.CutQty);
                                }

                                currentQty += ShareFuncs.GetInt(size.CutQty);
                            }
                            seq.BeamCutDevice_Id = beamInterface.BeamCutDevice_Id;
                            seq.Worker_Id        = beamInterface.Employee_Id;
                            seq.CutQty           = seqcutQty;
                            seq.LastUpdate       = DateTime.Now;
                            seq.Finish           = seq.CutQty == seq.SequenceQty ? true : false;
                            BeamCutQuery.UpdateBeamCutSeq(seq);
                        }

                        seqTotalQty += ShareFuncs.GetInt(seq.CutQty);
                        seqQty      += ShareFuncs.GetInt(seq.SequenceQty);
                    }
                }

                if (seqTotalQty == seqQty)
                {
                    StopCutting = true;
                }

                int oldVal = beamInterface.CuttingQty != null ? (int)beamInterface.CuttingQty : 0;
                beamInterface.LastConfirmSize = DateTime.Now;
                beamInterface.CuttingQty      = addQty + oldVal;
                BeamCutQuery.UpdateBeamInterface(beamInterface);

                clonePo.LastUpdate       = DateTime.Now;
                clonePo.CuttingQuantity += addQty;
                if (clonePo.CuttingQuantity == clonePo.PoQuantity)
                {
                    clonePo.Finish     = true;
                    clonePo.FinishTime = DateTime.Now;
                }

                BeamCutQuery.UpdateBeamCutPo(clonePo);

                var statistic = BeamCutQuery.GetBMachineStatistic(ShareFuncs.GetInt(beamInterface.BeamCutDevice_Id), DateTime.Now);
                if (statistic == null)
                {
                    statistic = BeamCutQuery.AddNewBcutStatistic(ShareFuncs.GetInt(beamInterface.BeamCutDevice_Id), DateTime.Now);
                }

                BDeviceCutTimeRecord record = new BDeviceCutTimeRecord
                {
                    TotalCutTime         = 0,
                    BeamCutDevice_Id     = bdevice.id,
                    ConfirmQuantity      = addQty,
                    BMachineStatistic_Id = statistic.id,
                };

                if (!BeamCutQuery.AddNewBCutTimeRecord(record))
                {
                    Exception = new RespException(true, "Add new record failed", EKB_SYS_REQUEST.BEAM_CONFIRM_SIZE);
                }

                int temp = statistic.TotalCutQty != null ? (int)statistic.TotalCutQty : 0;
                statistic.TotalCutQty = temp + addQty;
                BeamCutQuery.UpdateBStatistic(statistic);

                RespTotalCuttingQty = ShareFuncs.GetInt(beamInterface.CuttingQty);
                SizeId = sizeId;
                CutQty = cutQty;
                Finish = (totalQty == cutQty ? true : false);

                Exception = new RespException(false, "Confirm Size: OK", EKB_SYS_REQUEST.BEAM_CONFIRM_SIZE);
            }
            catch (Exception e)
            {
                Exception = new RespException(true, e.Message, EKB_SYS_REQUEST.BEAM_CONFIRM_SIZE);
            }
        }
Esempio n. 3
0
        // start cutting construction
        public RespCutting(IDbName database, int deviceId, int workerId, int clonePoId, int seq1Id, int seq2Id, int binterfaceId)
        {
            BeamCutQuery   = new BeamCutQuery(database);
            StockQuery     = new StockQuery(database);
            EmployeeQuery  = new EmployeeQuery(database);
            SequenceQuery  = new SequenceQuery(database);
            ScheduleQuery  = new ScheduleQuery(database);
            ComponentQuery = new ComponentQuery(database);
            try
            {
                var worker = EmployeeQuery.GetEmployee(workerId);
                if (worker == null)
                {
                    Exception = new RespException(true, "Invalid worker Id", EKB_SYS_REQUEST.BEAM_START_CUTTING);
                    return;
                }

                var bdevice = BeamCutQuery.GetBeamCutDevice(deviceId);
                if (bdevice == null)
                {
                    Exception = new RespException(true, "Invalid device Id", EKB_SYS_REQUEST.BEAM_START_CUTTING);
                    return;
                }

                var clonePo = BeamCutQuery.GetBeamCutPo(clonePoId);
                if (clonePo == null)
                {
                    Exception = new RespException(true, "Invalid clone Po Id", EKB_SYS_REQUEST.BEAM_START_CUTTING);
                    return;
                }

                var originalPo = SequenceQuery.GetOriginalPo(clonePo.OriginalPo_Id);

                if (originalPo == null)
                {
                    Exception = new RespException(true, "Can not find original po", EKB_SYS_REQUEST.BEAM_START_CUTTING);
                    return;
                }

                var component = ComponentQuery.GetShoeComponent(clonePo.Component_Id);

                if (component == null)
                {
                    Exception = new RespException(true, "Can not find component", EKB_SYS_REQUEST.BEAM_START_CUTTING);
                    return;
                }

                var schedule = ScheduleQuery.GetSchedule(originalPo);

                if (schedule == null)
                {
                    Exception = new RespException(true, "Can not find schedule", EKB_SYS_REQUEST.BEAM_START_CUTTING);
                    return;
                }

                var order = BeamCutQuery.GetBDeviceOrder(originalPo, deviceId);

                var startSeq = BeamCutQuery.GetBeamCutSeq(seq1Id);

                var stopSeq = BeamCutQuery.GetBeamCutSeq(seq2Id);

                if (startSeq == null || stopSeq == null)
                {
                    Exception = new RespException(true, "Invalid clone Seq Id", EKB_SYS_REQUEST.BEAM_START_CUTTING);
                    return;
                }

                int[] qty = BeamCutQuery.GetTotalSelectSequenceQty(startSeq, stopSeq);

                if (qty == null)
                {
                    qty = new int[] { 0, 0 }
                }
                ;

                int bId = binterfaceId;
                BeamCutInterface binterface = BeamCutQuery.GetBeamInterfaceById(binterfaceId);

                int scheduleId = 0;
                if (schedule != null)
                {
                    scheduleId = schedule.id;
                }

                if (binterface == null)
                {
                    binterface = new BeamCutInterface
                    {
                        Employee_Id        = workerId,
                        BeamCutDevice_Id   = deviceId,
                        BeamCutPo_Id       = clonePoId,
                        OriginalPo_Id      = clonePo.OriginalPo_Id,
                        BeamCutStartSeq_Id = seq1Id,
                        BeamCutStopSeq_Id  = seq2Id,
                        TotalSelectedQty   = qty[0],
                        TotalSelectCutQty  = qty[1],
                        Schedule_Id        = scheduleId,
                        StartSeqNo         = startSeq.SequenceNo,
                        StopSeqNo          = stopSeq.SequenceNo,
                        StartCutTime       = DateTime.Now,
                        CuttingQty         = 0,
                        BeamCutCounter     = 0,
                        BDeviceOrder_Id    = order != null ? order.id : 0,
                    };

                    var beamInterface = BeamCutQuery.AddNewBeamCutInterface(binterface);
                    if (beamInterface == null)
                    {
                        Exception = new RespException(true, "Add new BInterface error", EKB_SYS_REQUEST.BEAM_START_CUTTING);
                        return;
                    }
                    bId = beamInterface.id;
                }

                StockMeasure stockMeasure = StockQuery.GetStockMeasure(schedule);

                if (stockMeasure == null)
                {
                    var stock = StockQuery.AddNewStockMeasure(schedule);
                }

                Exception = new RespException(false, "Start cutting: OK", EKB_SYS_REQUEST.BEAM_START_CUTTING);

                InterfaceId = bId;
            }
            catch (Exception e)
            {
                Exception = new RespException(true, e.Message, EKB_SYS_REQUEST.BEAM_START_CUTTING);
            }
        }