public void popup(string iOrderId) { pnlPrepare.Visible = true; hfOrderId.Value = iOrderId; BindShipment(iOrderId); MPEPrepare.Show(); }
protected void lbPrintLabel_Click(object sender, EventArgs e) { try { string labelNumber = PrintLabel(); ClearPanel(); ctlEmptyCart.popup(hfOrderId.Value, labelNumber); MPEPrepare.Hide(); } catch (Exception ex) { lblErr.Text = ex.Message; } }
private string PrintLabel() { try { ShipService shpSvc = new ShipService(); ShipmentRequest shipmentRequest = new ShipmentRequest(); UPSSecurity upss = new UPSSecurity(); UPSSecurityServiceAccessToken upssSvcAccessToken = new UPSSecurityServiceAccessToken(); upssSvcAccessToken.AccessLicenseNumber = hfLicense.Value; upss.ServiceAccessToken = upssSvcAccessToken; UPSSecurityUsernameToken upssUsrNameToken = new UPSSecurityUsernameToken(); upssUsrNameToken.Username = hfUserName.Value; upssUsrNameToken.Password = hfPassword.Value; upss.UsernameToken = upssUsrNameToken; shpSvc.UPSSecurityValue = upss; RequestType request = new RequestType(); String[] requestOption = { lblAddressValidation.Text.Trim() }; request.RequestOption = requestOption; shipmentRequest.Request = request; ShipmentType shipment = new ShipmentType(); shipment.Description = "CMS Label Printing"; ShipperType shipper = new ShipperType(); shipper.ShipperNumber = hfAccountNumber.Value; PaymentInfoType paymentInfo = new PaymentInfoType(); ShipmentChargeType shpmentCharge = new ShipmentChargeType(); BillShipperType billShipper = new BillShipperType(); billShipper.AccountNumber = hfAccountNumber.Value; shpmentCharge.BillShipper = billShipper; shpmentCharge.Type = lblChargeType.Text.Trim(); ShipmentChargeType[] shpmentChargeArray = { shpmentCharge }; paymentInfo.ShipmentCharge = shpmentChargeArray; shipment.PaymentInformation = paymentInfo; UPSShipWebReference.ShipAddressType shipperAddress = new UPSShipWebReference.ShipAddressType(); String[] addressLine = { lblFromStreet.Text.Trim() }; shipperAddress.AddressLine = addressLine; shipperAddress.City = lblFromCity.Text.Trim(); shipperAddress.PostalCode = lblFromZip.Text.Trim(); shipperAddress.StateProvinceCode = hfFromStateUPSCode.Value; shipperAddress.CountryCode = hfFromCountryUPSCode.Value; shipperAddress.AddressLine = addressLine; shipper.Address = shipperAddress; shipper.Name = lblFromName.Text.Trim(); shipper.AttentionName = lblFromName.Text.Trim(); ShipPhoneType shipperPhone = new ShipPhoneType(); shipperPhone.Number = lblFromPhone.Text.Trim(); shipper.Phone = shipperPhone; shipment.Shipper = shipper; ShipFromType shipFrom = new ShipFromType(); UPSShipWebReference.ShipAddressType shipFromAddress = new UPSShipWebReference.ShipAddressType(); String[] shipFromAddressLine = { lblFromStreet.Text.Trim() }; shipFromAddress.AddressLine = addressLine; shipFromAddress.City = lblFromCity.Text.Trim(); shipFromAddress.PostalCode = lblFromZip.Text.Trim(); shipFromAddress.StateProvinceCode = hfFromStateUPSCode.Value; shipFromAddress.CountryCode = hfFromCountryUPSCode.Value; shipFrom.Address = shipFromAddress; shipFrom.AttentionName = lblFromName.Text.Trim(); shipFrom.Name = lblFromName.Text.Trim(); shipment.ShipFrom = shipFrom; ShipToType shipTo = new ShipToType(); ShipToAddressType shipToAddress = new ShipToAddressType(); String[] addressLine1 = { lblToStreet.Text.Trim() }; shipToAddress.AddressLine = addressLine1; shipToAddress.City = lblToCity.Text.Trim(); shipToAddress.PostalCode = lblToZip.Text.Trim(); shipToAddress.StateProvinceCode = hfToStateUPSCode.Value; shipToAddress.CountryCode = hfToCountryUPSCode.Value; shipTo.Address = shipToAddress; shipTo.AttentionName = lblToName.Text.Trim(); shipTo.Name = lblToName.Text.Trim(); ShipPhoneType shipToPhone = new ShipPhoneType(); shipToPhone.Number = lblToPhone.Text.Trim(); shipTo.Phone = shipToPhone; shipment.ShipTo = shipTo; ServiceType service = new ServiceType(); service.Code = lblShipService.Text.Trim(); shipment.Service = service; PackageType package = new PackageType(); PackageWeightType packageWeight = new PackageWeightType(); packageWeight.Weight = lblWeight.Text.Trim(); ShipUnitOfMeasurementType uom = new ShipUnitOfMeasurementType(); uom.Code = lblMeasurementType.Text.Trim(); packageWeight.UnitOfMeasurement = uom; package.PackageWeight = packageWeight; PackagingType packType = new PackagingType(); packType.Code = lblPackagingType.Text.Trim(); package.Packaging = packType; PackageType[] pkgArray = { package }; shipment.Package = pkgArray; LabelSpecificationType labelSpec = new LabelSpecificationType(); LabelStockSizeType labelStockSize = new LabelStockSizeType(); labelStockSize.Height = "6"; labelStockSize.Width = "4"; labelSpec.LabelStockSize = labelStockSize; LabelImageFormatType labelImageFormat = new LabelImageFormatType(); labelImageFormat.Code = "GIF"; labelSpec.LabelImageFormat = labelImageFormat; shipmentRequest.LabelSpecification = labelSpec; shipmentRequest.Shipment = shipment; System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy(); ShipmentResponse shipmentResponse = shpSvc.ProcessShipment(shipmentRequest); iTextSharp.text.Document doc = new iTextSharp.text.Document(); //Output to File string localPath = Server.MapPath("../Labels") + "\\" + shipmentResponse.ShipmentResults.ShipmentIdentificationNumber + ".pdf"; PdfWriter.GetInstance(doc, new FileStream(localPath, FileMode.Create)); doc.Open(); Byte[] labelBuffer = System.Convert.FromBase64String(shipmentResponse.ShipmentResults.PackageResults[0].ShippingLabel.GraphicImage); MemoryStream stream = new MemoryStream(labelBuffer); iTextSharp.text.Image gif = iTextSharp.text.Image.GetInstance(stream); gif.RotationDegrees = -90f; gif.ScalePercent(50f); stream.Close(); doc.NewPage(); doc.Add(gif); doc.Close(); MemoryStream output = new MemoryStream(); doc = new iTextSharp.text.Document(); PdfWriter.GetInstance(doc, output); doc.Open(); doc.NewPage(); doc.Add(gif); doc.Close(); (new OrderEntryDAL()).UploadShippingLabel_DAL("Shipping Label", output.ToArray(), "application/pdf", shipmentResponse.ShipmentResults.ShipmentIdentificationNumber + ".pdf", "", labelBuffer.Length, int.Parse(hfOrderId.Value), int.Parse(Session["UserID"].ToString())); output.Close(); return(shipmentResponse.ShipmentResults.ShipmentIdentificationNumber); } catch (System.Web.Services.Protocols.SoapException ex) { lblErr.Text = ex.Message; MPEPrepare.Show(); return(""); } catch (Exception ex) { lblErr.Text = ex.Message; MPEPrepare.Show(); return(""); } }