Exemplo n.º 1
0
        public void ReworkScanBarcode(Sender sender, string Barcode, Guid WorkShiftID, Guid WorkFlowID)
        {
            try
            {
                using (ObjectProxy op = new ObjectProxy(true))
                {
                    WorkFlow wf = new WorkFlow();
                    wf.WorkFlowID = WorkFlowID;
                    //if (op.LoadWorkFlowByWorkFlowID(wf) == 0)
                    //{
                    //    throw new PException("工序代码【{0}】无效或不存在", WorkFlowID);
                    //}

                    OrderDetail orderDetail = new OrderDetail();
                    orderDetail.BarcodeNo = Barcode;
                    if (op.LoadOrderDetailByBarcodeNo(orderDetail) == 0)
                    {
                        throw new PException("板件条码【{0}】无效", Barcode);
                    }

                    Order order = new Order();
                    order.OrderID = orderDetail.OrderID;
                    if (op.LoadOrder(order) == 0)
                    {
                        throw new PException("板件条码【{0}】无效", Barcode);
                    }

                    //if (order.ManufactureDate == DateTime.MinValue)
                    //{
                    //    order.ManufactureDate = DateTime.Now;
                    //    op.UpdateOrderByOrderID(order); //订单开始生产日期
                    //}

                    //判断当前板件是否需要经过当前工序
                    OrderWorkFlow ow = new OrderWorkFlow();
                    ow.ItemID           = orderDetail.ItemID;
                    ow.SourceWorkFlowID = WorkFlowID;
                    if (op.LoadOrderWorkFlowByItemID_SourceWorkFlowID(ow) == 0)
                    {
                        throw new PException("板件条码【{0}】不需要经过此生产工序", Barcode);
                    }
                    //判断是否已经全部扫描
                    //int Qty = op.CountOrderMadeStatesByBarcode_WorkFlowID(Barcode, WorkFlowID);
                    //if (Qty >= ow.TotalQty)
                    //{
                    //    throw new PException("板件条码【{0}】在此工序中已经全部扫描,请检查是否重复扫描。", Barcode);
                    //}

                    op.DeleteOrderMadeStateByItemID_WorkFlowID(orderDetail.ItemID, wf.WorkFlowID);

                    OrderWorkFlow owf = new OrderWorkFlow();
                    owf.ItemID           = orderDetail.ItemID;
                    owf.SourceWorkFlowID = WorkFlowID;

                    if (op.LoadOrderWorkFlowByItemID_SourceWorkFlowID(owf) != 0)
                    {
                        owf.MadeQty = 0;
                        op.UpdateOrderWorkFlowByItemID_SourceWorkFlowID(owf);
                    }

                    OrderScheduling os = new OrderScheduling();
                    os.CabinetID  = orderDetail.CabinetID;
                    os.WorkFlowID = WorkFlowID;
                    if (op.LoadOrderSchedulingByCabinetID_WorkFlowID(os) != 0)
                    {
                        if (os.MadeStarted == DateTime.MinValue)
                        {
                            //生产开始时间
                            os.MadeStarted = DateTime.Now;
                        }
                        os.MadeTotalQty    -= 1;
                        os.MadeTotalAreal  -= orderDetail.MadeLength * orderDetail.MadeWidth * 0.000001M;
                        os.MadeTotalLength -= (orderDetail.MadeLength + orderDetail.MadeWidth) * 2 * 0.001M;

                        if (os.MadeTotalQty == os.TotalQty)
                        {
                            //生产结束时间
                            os.MadeEnded = DateTime.Now;
                        }
                        op.UpdateOrderSchedulingByMadeID(os);
                    }
                    op.CommitTransaction();
                }
            }
            catch (Exception ex)
            {
                PLogger.LogError(ex);
                throw ex;
            }
        }