protected void Printer_Insert(PXGraph graph, EntityImpl entity, EntityImpl targetEntity)
        {
            var printerName = targetEntity.Fields.SingleOrDefault(f => f.Name == "PrinterName") as EntityValueField;
            var description = targetEntity.Fields.SingleOrDefault(f => f.Name == "Description") as EntityValueField;
            var isActive    = targetEntity.Fields.SingleOrDefault(f => f.Name == "IsActive") as EntityValueField;

            if (printerName != null && printerName.Value != null)
            {
                PX.SM.SMPrinterMaint newPrinterGraph = (PX.SM.SMPrinterMaint)PXGraph.CreateInstance(typeof(PX.SM.SMPrinterMaint));

                SMPrinter existingPrinter = SelectFrom <SMPrinter> .Where <SMPrinter.deviceHubID.IsEqual <@P.AsString> .And <SMPrinter.printerName.IsEqual <@P.AsString> > > .View.Select(newPrinterGraph, defaultDeviceHubID, printerName.Value);

                if (existingPrinter != null)
                {
                    return;
                }

                PX.SM.SMPrinter printer = new PX.SM.SMPrinter();
                printer.PrinterID   = Guid.NewGuid();
                printer.DeviceHubID = defaultDeviceHubID;
                printer.PrinterName = printerName.Value;
                if (description != null)
                {
                    printer.Description = description.Value;
                }
                if (isActive != null)
                {
                    printer.IsActive = isActive.Value == "true";
                }

                newPrinterGraph.Printers.Insert(printer);
                newPrinterGraph.Save.Press();
            }
        }
        protected void Printer_Update(PXGraph graph, EntityImpl entity, EntityImpl targetEntity)
        {
            PX.SM.SMPrinterMaint newPrinterGraph = (PX.SM.SMPrinterMaint)PXGraph.CreateInstance(typeof(PX.SM.SMPrinterMaint));
            var    isActive    = targetEntity.Fields.SingleOrDefault(f => f.Name == "IsActive") as EntityValueField;
            string printerName = entity.InternalKeys["Printers"]["PrinterName"];

            foreach (PX.SM.SMPrinter existingPrinter in newPrinterGraph.Printers.Select())
            {
                if (existingPrinter.PrinterName == printerName && isActive != null && isActive.Value != null)
                {
                    existingPrinter.IsActive = isActive.Value == "true";
                    newPrinterGraph.Printers.Update(existingPrinter);
                }
            }
            if (newPrinterGraph.Printers.Cache.IsDirty)
            {
                newPrinterGraph.Save.Press();
            }
        }