Ejemplo n.º 1
0
        private void btnLockImage_Click(object sender, EventArgs e)
        {
            if (!ThisApp.user.accessBlockImage)
            {
                MessageBox.Show("You are not authorised to lock images", "No Authorisation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            var img = GetSelectedImage();

            if (img != null)
            {
                if (img.onPrinter == PrinterImage.ImageStatus.Loaded)
                {
                    img.RemoveFromPrinter();
                }

                MessageLogger.Add(string.Format("Image {0} locked by {1}", img.description, ThisApp.user.name), MessageLogger.MsgLevel.permanent);

                img.SetLockedOnDB(true);
                UpdateImagesList();
            }
        }
Ejemplo n.º 2
0
 public bool SetCancelled()
 {
     try
     {
         DBOperations.OpenDBConnection();
         DBOperations.BeginTransaction();
         MySqlCommand cmd = DBOperations.myConn.CreateCommand();
         cmd.CommandText = "UPDATE pck.pack SET sent_to_SAP = null, cancelled = 1 where serial = @serial";
         cmd.Parameters.AddWithValue("@serial", serial);
         cmd.ExecuteNonQuery();
         DBOperations.CommitTransaction();
     }
     catch (MySqlException ex)
     {
         MessageLogger.Add(string.Format("Error setting cancelled flag for pack {0}", serial), MessageLogger.MsgLevel.error);
         MessageLogger.Add(ex.ToString(), MessageLogger.MsgLevel.additional);
         DBOperations.RollbackTransaction();
         return(false);
     }
     this.cancelled = true;
     return(true);
 }
Ejemplo n.º 3
0
        public bool RemoveFromPrinter()
        {
            if (printerHost == null)
            {
                return(false);
            }

            try
            {
                var request = GetFtpRequest(string.Format("ftp://{0}/c/{1}", printerHost, Path.GetFileName(fullPath)));
                request.Method = WebRequestMethods.Ftp.DeleteFile;
                FtpWebResponse response = (FtpWebResponse)request.GetResponse();
                response.Close();
            }
            catch (WebException ex)
            {
                MessageLogger.Add(string.Format("Error deleting file {1} via FTP from printer host {0} - see log for details", printerHost, fullPath), MessageLogger.MsgLevel.error);
                MessageLogger.Add(ex.ToString(), MessageLogger.MsgLevel.additional);
                return(false);
            }
            return(true);
        }
Ejemplo n.º 4
0
        private void btnSendImage_Click(object sender, EventArgs e)
        {
            if (!ThisApp.user.accessSendImage)
            {
                MessageBox.Show("You are not authorised to enable images", "No Authorisation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            var img = GetSelectedImage();

            if (img != null)
            {
                if (img.locked)
                {
                    MessageBox.Show("Image is locked", "Enabling Image not Allowed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else if (img.SendToPrinter())
                {
                    UpdateImagesList();
                    MessageLogger.Add(string.Format("Image {0} sent to printer by {1}", img.description, ThisApp.user.name), MessageLogger.MsgLevel.permanent);
                }
            }
        }
Ejemplo n.º 5
0
        public bool DeleteFromDB()
        {
            DBOperations.OpenDBConnection();
            DBOperations.BeginTransaction();

            try
            {
                var cmd = DBOperations.myConn.CreateCommand();
                cmd.CommandText = "DELETE FROM pck.printer_image WHERE id = @id";

                cmd.Parameters.AddWithValue("@id", id);
                cmd.ExecuteNonQuery();
                DBOperations.CommitTransaction();
            }
            catch (MySqlException ex)
            {
                DBOperations.RollbackTransaction();
                MessageLogger.Add(string.Format("Error deleting printer image '{0}' from DB - see log for details", description), MessageLogger.MsgLevel.error);
                MessageLogger.Add(ex.ToString(), MessageLogger.MsgLevel.additional);
                return(false);
            }
            return(true);
        }
Ejemplo n.º 6
0
        public static bool SendPacks()
        {
            DBOperations.BeginTransaction();

            var packs = ReadUnsentPacks();

            if (packs.Count == 0)
            {
                DBOperations.CommitTransaction();
                return(true);  //Okay - no cartons need to be sent
            }

            var binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);

            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
            binding.MaxReceivedMessageSize = 1000000;
            var address = new EndpointAddress(CommonData.webServiceEndPoint);
            ZStandalonePackingClient client = new ZStandalonePackingClient(binding, address);

            var toSAP = new ZReceiptCartons();

            toSAP.Cartons = new ZsapaCarton[packs.Count];

            int i = 0;

            foreach (var p in packs)
            {
                toSAP.Cartons[i] = new ZsapaCarton();

                toSAP.Cartons[i].Serial         = p.serial.ToString();
                toSAP.Cartons[i].MaterialNum    = p.materialNum;
                toSAP.Cartons[i].Batch          = p.batch;
                toSAP.Cartons[i].OrderNum       = p.orderNum;
                toSAP.Cartons[i].Plant          = p.plant;
                toSAP.Cartons[i].StorageLctn    = p.storage_lctn;
                toSAP.Cartons[i].PackedQty      = p.qty;
                toSAP.Cartons[i].PackedUom      = p.uom;
                toSAP.Cartons[i].Weight         = p.netWeight;
                toSAP.Cartons[i].PlannedWeight  = p.plannedWeight;
                toSAP.Cartons[i].ActualWeight   = p.actualWeight;
                toSAP.Cartons[i].TareWeight     = p.tareWeight;
                toSAP.Cartons[i].PackedOn       = p.packedOn.ToString("yyyy-MM-dd");
                toSAP.Cartons[i].PackedAt       = p.packedOn.ToString("HHmmss");
                toSAP.Cartons[i].ManuDate       = p.manuDate.ToString("yyyy-MM-dd");
                toSAP.Cartons[i].ExpiryDate     = p.expiryDate.ToString("yyyy-MM-dd");
                toSAP.Cartons[i].SlaughterDates = p.slaughterDates;
                toSAP.Cartons[i].Device         = p.terminal;
                toSAP.Cartons[i].UseFreezer     = p.useFreezer ? "X" : "";
                toSAP.Cartons[i].DgaUser        = p.user;
                toSAP.Cartons[i].GrReversal     = p.cancelled ? "X" : "";
                i++;
            }

            client.ClientCredentials.UserName.UserName = CommonData.sapSettings.user;
            client.ClientCredentials.UserName.Password = CryptoSystem.Decrypt(CommonData.sapSettings.password);

            ZReceiptCartonsResponse fromSAP;

            try
            {
                fromSAP = client.ZReceiptCartons(toSAP);
            }
            catch (Exception e)
            {
                MessageLogger.Add("Error sending packs to SAP " + e.ToString(), MessageLogger.MsgLevel.error);
                DBOperations.RollbackTransaction();
                return(false);
            }

            foreach (var c in fromSAP.ReturnMsgs)
            {
                MessageLogger.Add("Flagging carton " + c.Serial + " " + c.Msg, MessageLogger.MsgLevel.info);

                FlagAsSent(ulong.Parse(c.Serial), c.Msg);
            }
            DBOperations.CommitTransaction();
            return(true);
        }
Ejemplo n.º 7
0
        private void ServiceWorkerThread(object state)
        {
            int matTurns;           // Number of times the Send Cartons interval occurs for each Material Read interval
            int orderTurns;         // Number of times the Send Cartons interval occurs for each Order Read interval

            int matTurnsToGo   = 0; // Start with zero turns to go i.e. pull orders and material from SAP when service is first started.
            int orderTurnsToGo = 0;

            bool initilised = false;

            if (CommonData.localSettings.MaterialReadInterval != 0)
            {
                matTurns = CommonData.localSettings.MaterialReadInterval * 60 * 60 / CommonData.localSettings.CartonSendInterval;
            }
            else
            {
                matTurns = -1;
            }

            if (CommonData.localSettings.OrderReadInterval != 0)
            {
                orderTurns = CommonData.localSettings.OrderReadInterval * 60 / CommonData.localSettings.CartonSendInterval;
            }
            else
            {
                orderTurns = -1;
            }

            if (matTurns == -1 && orderTurns != -1)
            {
                // We're pulling Prod Orders from SAP but not Materials, read in the current material master records from local DB
                MessageLogger.Add("Reading materials from local DB", MessageLogger.MsgLevel.info);
                CommonData.mats = Material.readMaterialsFromDB();
            }
            while (!this.stopping)
            {
                if (!initilised)
                {
                    // Initialise DB connection
                    initilised = Order.Initialise();
                }

                if (initilised)
                {
                    // Send new cartons to SAP
                    MessageLogger.Add("Sending Packs to SAP", MessageLogger.MsgLevel.info);
                    bool packsSentOk = Pack.SendPacks();

                    if (matTurns != -1)
                    {
                        if (matTurnsToGo == 0)
                        {
                            // It's time to read Materials from SAP
                            MessageLogger.Add("Reading Materials from SAP", MessageLogger.MsgLevel.info);
                            if (Material.readMaterialsFromSAP(out CommonData.mats))
                            {
                                MessageLogger.Add("Saving Materials to local DB", MessageLogger.MsgLevel.info);
                                Material.saveMaterialsToDB(CommonData.mats, true);
                            }
                            matTurnsToGo = matTurns;
                        }
                        else
                        {
                            matTurnsToGo--;
                        }
                    }

                    if (orderTurns != -1)
                    {
                        if (orderTurnsToGo == 0 && packsSentOk)
                        {
                            // It's time to read Production Orders from SAP
                            MessageLogger.Add("Reading Production Orders from SAP", MessageLogger.MsgLevel.info);
                            if (Order.ReadOrdersFromSAP(out CommonData.normalOrders, out CommonData.reworkOrders, out CommonData.slDates))
                            {
                                MessageLogger.Add("Saving Production Orders to local DB", MessageLogger.MsgLevel.info);
                                Order.SaveOrdersToDB(CommonData.normalOrders);
                                Order.SaveOrdersToDB(CommonData.reworkOrders);
                                Order.SavePackDatesToDB(CommonData.slDates);
                            }
                            orderTurnsToGo = orderTurns;
                        }
                        else
                        {
                            orderTurnsToGo--;
                        }
                    }
                }
                // Go to sleep
                Thread.Sleep(TimeSpan.FromSeconds(CommonData.localSettings.CartonSendInterval));
            }
        }
Ejemplo n.º 8
0
 protected override void OnStop()
 {
     this.stopping = true;
     MessageLogger.Add("Stopping Service...", MessageLogger.MsgLevel.info);
 }
Ejemplo n.º 9
0
        public static void ReadOrdersFromDB(out List <Order> normalOrders, out List <Order> reworkOrders, out List <Order.PackedOn> slDates)
        {
            normalOrders = new List <Order>();
            reworkOrders = new List <Order>();

            string prevMatNumber = "~";

            Order normalOrder         = null;
            Order reworkOrder         = null;
            bool  missingMaterialData = false;

            DBOperations.BeginTransaction();
            MySqlCommand cmd = DBOperations.myConn.CreateCommand();

            cmd.CommandText = "select * from pck.order where start_date = current_date() and rel_ind = 1 order by material_num";

            try
            {
                MySqlDataReader rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    var  newIncOrd = new IncOrder(rdr);
                    bool rework    = newIncOrd.orderType.Equals("YREW");

                    if (!newIncOrd.materialNum.Equals(prevMatNumber))
                    {
                        normalOrder         = reworkOrder = null;
                        missingMaterialData = false;

                        var ord = new Order(newIncOrd);
                        if (ord.material == null)
                        {
                            missingMaterialData = true;
                            MessageLogger.Add("No master data for material " + ord.materialNum, MessageLogger.MsgLevel.warning);
                        }
                        else if (rework)
                        {
                            reworkOrder = ord;
                            reworkOrders.Add(ord);
                        }
                        else
                        {
                            normalOrder = ord;
                            normalOrders.Add(ord);
                        }
                    }
                    if (missingMaterialData)
                    {
                        continue;
                    }

                    if (rework)
                    {
                        if (reworkOrder == null)
                        {
                            reworkOrder = new Order(newIncOrd);
                            reworkOrders.Add(reworkOrder);
                        }
                        reworkOrder.AddIncOrder(newIncOrd);
                    }
                    else
                    {
                        if (normalOrder == null)
                        {
                            normalOrder = new Order(newIncOrd);
                            normalOrders.Add(normalOrder);
                        }
                        normalOrder.AddIncOrder(newIncOrd);
                    }
                    prevMatNumber = newIncOrd.materialNum;
                }
                rdr.Close();
            }
            catch (MySqlException ex)
            {
                MessageLogger.Add("Error reading materials from DB - see log file for more details", MessageLogger.MsgLevel.critical);
                MessageLogger.Add(ex.ToString(), MessageLogger.MsgLevel.additional);
            }

            slDates = ReadPackedOnDatesFromDB();
            DBOperations.CommitTransaction();
        }
Ejemplo n.º 10
0
        public static bool ReadOrdersFromSAP(out List <Order> normalOrders, out List <Order> reworkOrders, out List <Order.PackedOn> slDates)
        {
            normalOrders = new List <Order>();
            reworkOrders = new List <Order>();
            slDates      = new List <PackedOn>();

            var binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);

            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
            binding.MaxReceivedMessageSize = 1000000;

            var address = new EndpointAddress(CommonData.webServiceEndPoint);
            var client  = new ZStandalonePackingClient(binding, address);
            var toSAP   = new ZGetProductionOrders();

            toSAP.Device = CommonData.sapSettings.device;

            client.ClientCredentials.UserName.UserName = CommonData.sapSettings.user;
            client.ClientCredentials.UserName.Password = CryptoSystem.Decrypt(CommonData.sapSettings.password);
            ZGetProductionOrdersResponse fromSAP;

            try
            {
                fromSAP = client.ZGetProductionOrders(toSAP);
            }
            catch (CommunicationException ex)
            {
                MessageLogger.Add("Error reading orders from SAP", MessageLogger.MsgLevel.error);
                MessageLogger.Add(ex.ToString(), MessageLogger.MsgLevel.additional);
                return(false);
            }
            string prevMatNumber = "~";

            Order normalOrder         = null;
            Order reworkOrder         = null;
            bool  missingMaterialData = false;

            foreach (ZsapaProdOrder sapOrd in fromSAP.Orders)
            {
                var  newIncOrd = new IncOrder(sapOrd);
                bool rework    = sapOrd.OrderType.Equals("YREW");

                if (!sapOrd.MaterialNum.Equals(prevMatNumber))
                {
                    normalOrder         = reworkOrder = null;
                    missingMaterialData = false;

                    var ord = new Order(newIncOrd);
                    if (ord.material == null)
                    {
                        missingMaterialData = true;
                        MessageLogger.Add("No master data for material " + ord.materialNum, MessageLogger.MsgLevel.warning);
                    }
                    else if (rework)
                    {
                        reworkOrder = ord;
                        reworkOrders.Add(ord);
                    }
                    else
                    {
                        normalOrder = ord;
                        normalOrders.Add(ord);
                    }
                }
                if (missingMaterialData)
                {
                    continue;
                }

                if (rework)
                {
                    if (reworkOrder == null)
                    {
                        reworkOrder = new Order(newIncOrd);
                        reworkOrders.Add(reworkOrder);
                    }
                    reworkOrder.AddIncOrder(newIncOrd);
                }
                else
                {
                    if (normalOrder == null)
                    {
                        normalOrder = new Order(newIncOrd);
                        normalOrders.Add(normalOrder);
                    }
                    normalOrder.AddIncOrder(newIncOrd);
                }
                prevMatNumber = sapOrd.MaterialNum;
            }
            foreach (var sl in fromSAP.ProdDates)
            {
                slDates.Add(new Order.PackedOn(sl));
            }
            return(true);
        }
Ejemplo n.º 11
0
        public static string saveMaterialsToDB(List <Material> mats, bool refreshDB)
        {
            DBOperations.OpenDBConnection();
            DBOperations.BeginTransaction();
            MySqlCommand cmd = DBOperations.myConn.CreateCommand();

            cmd.CommandText = "DELETE FROM pck.material";
            cmd.Prepare();
            cmd.ExecuteNonQuery();

            cmd             = DBOperations.myConn.CreateCommand();
            cmd.CommandText = "INSERT INTO pck.material VALUES (@mat_number,@desc,@l1,@l2,@l3,@l4,@fw,@max,@min,@nom,@buom,@puom,@unlim,@overdel,@EAN,@m2o,@label,@shelf,@cust,@old,@target,@wool)";
            bool first = true;

            foreach (Material mat in mats)
            {
                if (first)
                {
                    cmd.Parameters.AddWithValue("@mat_number", mat.matNumber);
                    cmd.Parameters.AddWithValue("@desc", mat.description);
                    cmd.Parameters.AddWithValue("@l1", mat.labelLine1);
                    cmd.Parameters.AddWithValue("@l2", mat.labelLine2);
                    cmd.Parameters.AddWithValue("@l3", mat.labelLine3);
                    cmd.Parameters.AddWithValue("@l4", mat.labelLine4);
                    cmd.Parameters.AddWithValue("@fw", mat.fixedWeight);
                    cmd.Parameters.AddWithValue("@max", mat.maxWeight);
                    cmd.Parameters.AddWithValue("@min", mat.minWeight);
                    cmd.Parameters.AddWithValue("@nom", mat.nomWeight);
                    cmd.Parameters.AddWithValue("@buom", mat.baseUom);
                    cmd.Parameters.AddWithValue("@puom", mat.parallelUom);
                    cmd.Parameters.AddWithValue("@unlim", mat.unlimOverdel);
                    cmd.Parameters.AddWithValue("@overdel", mat.overdelPerc);
                    cmd.Parameters.AddWithValue("@EAN", mat.Ean);
                    cmd.Parameters.AddWithValue("@m2o", mat.madeToOrd);
                    cmd.Parameters.AddWithValue("@label", mat.labelFile);
                    cmd.Parameters.AddWithValue("@shelf", mat.shelfLife);
                    cmd.Parameters.AddWithValue("@cust", mat.custMatNumber);
                    cmd.Parameters.AddWithValue("@old", mat.oldMatNumber);
                    cmd.Parameters.AddWithValue("@target", mat.targetMatNumber);
                    cmd.Parameters.AddWithValue("@wool", mat.woolGrp);
                    cmd.Prepare();
                    first = false;
                }
                else
                {
                    cmd.Parameters[0].Value  = mat.matNumber;
                    cmd.Parameters[1].Value  = mat.description;
                    cmd.Parameters[2].Value  = mat.labelLine1;
                    cmd.Parameters[3].Value  = mat.labelLine2;
                    cmd.Parameters[4].Value  = mat.labelLine3;
                    cmd.Parameters[5].Value  = mat.labelLine4;
                    cmd.Parameters[6].Value  = mat.fixedWeight;
                    cmd.Parameters[7].Value  = mat.maxWeight;
                    cmd.Parameters[8].Value  = mat.minWeight;
                    cmd.Parameters[9].Value  = mat.nomWeight;
                    cmd.Parameters[10].Value = mat.baseUom;
                    cmd.Parameters[11].Value = mat.parallelUom;
                    cmd.Parameters[12].Value = mat.unlimOverdel;
                    cmd.Parameters[13].Value = mat.overdelPerc;
                    cmd.Parameters[14].Value = mat.Ean;
                    cmd.Parameters[15].Value = mat.madeToOrd;
                    cmd.Parameters[16].Value = mat.labelFile;
                    cmd.Parameters[17].Value = mat.shelfLife;
                    cmd.Parameters[18].Value = mat.custMatNumber;
                    cmd.Parameters[19].Value = mat.oldMatNumber;
                    cmd.Parameters[20].Value = mat.targetMatNumber;
                    cmd.Parameters[21].Value = mat.woolGrp;
                }
                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch (MySqlException ex)
                {
                    DBOperations.RollbackTransaction();
                    MessageLogger.Add(string.Format("Error saving material {0} to DB - see log for details", mat.matNumber), MessageLogger.MsgLevel.error);
                    MessageLogger.Add(ex.ToString(), MessageLogger.MsgLevel.additional);
                    return(null);
                }
            }

            DBOperations.CommitTransaction();
            return(null);
        }
Ejemplo n.º 12
0
        public static void ListenToOtherStation(ButtonMatrix bt)
        {
            // Get local IP V4 address
            var addr = GetLocalIPv4();

            if (addr == null)
            {
                MessageLogger.Add("Unable to determine local IP address for inter-station comms", MessageLogger.MsgLevel.warning);
                return;
            }

            MessageLogger.Add(string.Format("Listening to address {0}, port {1} for inter-station comms",
                                            addr, CommonData.localSettings.ThisPackingStationPort),
                              MessageLogger.MsgLevel.info);

            var listener = new TcpListener(addr, CommonData.localSettings.ThisPackingStationPort);

            listener.Start();

            while (true)
            {
                Byte[] response = new Byte[80];
                var    client   = listener.AcceptTcpClient();
                var    stream   = client.GetStream();

                Int32  bytes    = stream.Read(response, 0, response.Length);
                bool   finished = false;
                bool   inRes    = true;
                string res      = "";

                for (int i = 0; i < bytes && !finished; i++)
                {
                    switch (response[i])
                    {
                    case startChar:
                        inRes = true;
                        break;

                    case endChar:
                        if (inRes)
                        {
                            finished = true;
                        }
                        break;

                    default:
                        if (inRes)
                        {
                            res += (char)response[i];
                        }
                        break;
                    }
                }
                var words = res.Split(',');
                if (words.Length == 3)
                {
                    string  orderNum    = words[0];
                    string  materialNum = words[1];
                    decimal qtyPacked   = decimal.Parse(words[2]);

                    var ord = CommonData.normalOrders.Find(o => o.materialNum.Equals(materialNum));
                    if (ord == null)
                    {
                        ord = CommonData.reworkOrders.Find(o => o.materialNum.Equals(materialNum));
                    }
                    if (ord != null)
                    {
                        var incOrd = ord.incOrders.Find(i => i.orderNum.Equals(orderNum));
                        if (incOrd != null)
                        {
                            ord.IncreaseDeliveredQty(qtyPacked, incOrd);
                            bt.UpdateButton(materialNum);
                        }
                    }
                }
            }
        }
Ejemplo n.º 13
0
 public static void ReadMaterialsFromDB(BusyDialog bd)
 {
     bd.SetTitle("Reading Material Master Data from DB");
     CommonData.mats = Material.readMaterialsFromDB();
     MessageLogger.Add(CommonData.mats.Count + " materials read from DB", MessageLogger.MsgLevel.info);
 }
Ejemplo n.º 14
0
        public static bool CancelCartonReceipt(string bc)
        {
            if (bc.Length < 8)
            {
                MessageLogger.Add(string.Format("Funny looking barcode {0} - cannot process", bc), MessageLogger.MsgLevel.error);
                return(false);
            }
            ulong serial;

            if (!ulong.TryParse(bc.Substring(0, bc.Length - 3), out serial))
            {
                MessageLogger.Add(string.Format("Non-numeric barcode {0} - cannot process", bc), MessageLogger.MsgLevel.error);
                return(false);
            }
            Pack p = Pack.ReadSingle(serial);

            if (p == null)
            {
                MessageLogger.Add(string.Format("Unrecognised barcode {0}", bc), MessageLogger.MsgLevel.error);
                return(false);
            }
            if (p.cancelled)
            {
                MessageLogger.Add(string.Format("Barcode {0} - already cancelled", bc), MessageLogger.MsgLevel.error);
                return(false);
            }
            if (p.SetCancelled())
            {
                MessageLogger.Add(string.Format("Barcode {0} Material {1} Weight {2} cancelled", bc, p.materialNum, p.netWeight), MessageLogger.MsgLevel.info);
            }
            var ord = CommonData.normalOrders.Find(o => o.materialNum.Equals(p.materialNum));

            if (ord == null)
            {
                ord = CommonData.reworkOrders.Find(o => o.materialNum.Equals(p.materialNum));
            }

            if (ord != null)
            {
                var incOrd = ord.incOrders.Find(i => i.orderNum.Equals(p.orderNum));
                if (incOrd != null)
                {
                    ord.IncreaseDeliveredQty(-p.qty, incOrd);

                    if (CommonData.localSettings.OtherPackingStationPort != 0)
                    {
                        // Start new thread to send carton receipt info to the other packing station
                        var ri = new InterStationComms.ReceiptInfo();
                        ri.materialNum = incOrd.materialNum;
                        ri.orderNum    = incOrd.orderNum;
                        ri.qtyPacked   = -p.qty;

                        ThreadPool.QueueUserWorkItem(new WaitCallback(InterStationComms.SendToOtherStation), ri);
                    }

                    if (packLastPrint?.serial == p.serial)
                    {
                        // Have just cancelled the last pack receipted, clear out "Last Pack" fields
                        ordLastPrint    = null;
                        incOrdLastPrint = null;
                        packLastPrint   = null;
                    }

                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 15
0
        public static bool PostReceipt(Order ord, Mode mode, Order.PackedOn reworkDateSel = null, Order.IncOrder incOrderSel = null)
        {
            // Get weight from scale
            if (scale.ReadScale(out decimal gross, out decimal net, out decimal tare) != ScaleReader.Stability.stableWeight)
            {
                MessageLogger.Add("Stable weight not returned from scale", MessageLogger.MsgLevel.error);
                return(false);
            }

            if (tare <= 0)
            {
                MessageLogger.Add("No tare weight returned from scale", MessageLogger.MsgLevel.error);
                return(false);
            }

            Order.IncOrder incOrd;
            if (incOrderSel == null)
            {
                // No specific order selected by user - use the order at the top of the list, which is always sorted to
                // put the highest priority, not-yet-completely-delivered order at the top.
                incOrd = ord.incOrders[0];
            }
            else
            {
                // User has selected a specific order i.e. we're in bin receipting mode
                incOrd = incOrderSel;
            }

            if (net < 0)
            {
                MessageLogger.Add("Negative net weight returned from scale.", MessageLogger.MsgLevel.error);
                return(false);
            }

            if (!ThisApp.weightToleranceDisabled)
            {
                // Check maximum and minimum carton weights
                if (ord.material.minWeight != 0M && net < ord.material.minWeight)
                {
                    MessageLogger.Add(string.Format("Weight ({1:0.00} kg) is below the minimum weight of {0:0.00}", ord.material.minWeight, net),
                                      MessageLogger.MsgLevel.error);
                    return(false);
                }

                if (ord.material.maxWeight != 0M && net > ord.material.maxWeight)
                {
                    MessageLogger.Add(string.Format("Weight ({1:0.00} kg) is above the maximum weight of {0:0.00}", ord.material.maxWeight, net),
                                      MessageLogger.MsgLevel.error);
                    return(false);
                }
            }

            decimal qtyToPack;

            if (ord.material.baseUom.Equals("KG"))
            {
                qtyToPack = net;  // Receipting a bin
            }
            else
            {
                qtyToPack = 1;    // Packing a single carton
            }
            //Check over delivery tolerance
            if (ord.maxQty != 0M && (ord.packedQty + qtyToPack) > ord.maxQty)
            {
                MessageLogger.Add(string.Format("Maximum qty of {0} {1} already packed for this product", ord.maxQty, ord.Uom), MessageLogger.MsgLevel.error);
                return(false);
            }

            if (mode == Mode.Rework && reworkDateSel == null)
            {
                MessageLogger.Add("Please select a production date for re-work,", MessageLogger.MsgLevel.error);
                return(false);
            }
            decimal actWeight = net;

            DateTime manuDate;
            string   slaughterDates;

            if (mode == Mode.Rework)
            {
                manuDate       = reworkDateSel.packedOn;
                slaughterDates = reworkDateSel.slaughterDates;
            }
            else
            {
                manuDate       = DateTime.Now;
                slaughterDates = incOrd.slaughterDates;
            }

            if (ord.material.fixedWeight)
            {
                net = ord.material.nomWeight; //Fixed weight carton, always pack at nominal weight
            }
            Pack pack = new Pack(incOrd: incOrd,
                                 mat: ord.material,
                                 _qty: qtyToPack,
                                 _uom: ord.material.baseUom,
                                 _netWeight: net,
                                 _tareWeight: tare,
                                 _actualWeight: actWeight,
                                 _manuDate: manuDate,
                                 _slaughterDates: slaughterDates,
                                 _terminal: CommonData.sapSettings.device,
                                 _batch: manuDate.ToString("yyyyMMdd"),
                                 _user: ThisApp.user?.userId);

            DBOperations.BeginTransaction();
            pack.InsertSingle();
            ord.IncreaseDeliveredQty(qtyToPack, incOrd);
            DBOperations.CommitTransaction();

            var barcode = PrintLabel(ord, incOrd, pack);

            if (CommonData.localSettings.OtherPackingStationPort != 0)
            {
                // Start new thread to send carton receipt info to the other packing station
                var ri = new InterStationComms.ReceiptInfo();
                ri.materialNum = incOrd.materialNum;
                ri.orderNum    = incOrd.orderNum;
                ri.qtyPacked   = qtyToPack;

                ThreadPool.QueueUserWorkItem(new WaitCallback(InterStationComms.SendToOtherStation), ri);
            }

            MessageLogger.Add(string.Format("Packed material {0} barcode {1} weight {2}", pack.materialNum, pack.serial, net), MessageLogger.MsgLevel.info);

            return(true);
        }