private void DisplayDetail(ShippingLabelInfo info)
 {
     StringBuilder builder = new StringBuilder();
     builder.Append("<table>");
     builder.Append("<tr><td>Shipping Label ID:</td><td>");
     builder.Append(info.ShippingLabelID);
     builder.Append("</td><tr/>");
     builder.Append("<tr><td>Barcode No:</td><td>");
     builder.Append(info.BarcodeNo);
     builder.Append("</td><tr/>");
     builder.Append("<tr><td>Tracking No:</td><td>");
     builder.Append(info.TrackingNo);
     builder.Append("<td></tr>");
     builder.Append("</table>");
     ltLabelDetail.Text = builder.ToString();
 }
        public static void SaveShippingLabelInfo(ShippingLabelInfo labelInfo, AspxCommonInfo commonInfo)
        {
            List <KeyValuePair <string, object> > paraMeter = new List <KeyValuePair <string, object> >();

            paraMeter.Add(new KeyValuePair <string, object>("OrderID", labelInfo.OrderID));
            paraMeter.Add(new KeyValuePair <string, object>("ShippingLabelImage", labelInfo.ShippingLabelImage));
            paraMeter.Add(new KeyValuePair <string, object>("Extention", labelInfo.Extension));
            paraMeter.Add(new KeyValuePair <string, object>("TrackingNo", labelInfo.TrackingNo));
            paraMeter.Add(new KeyValuePair <string, object>("BarcodeNo", labelInfo.BarcodeNo));
            paraMeter.Add(new KeyValuePair <string, object>("IsRealTime", labelInfo.IsRealTime));
            paraMeter.Add(new KeyValuePair <string, object>("PortalId", commonInfo.StoreID));
            paraMeter.Add(new KeyValuePair <string, object>("StoreId", commonInfo.StoreID));
            paraMeter.Add(new KeyValuePair <string, object>("UserName", commonInfo.UserName));
            OracleHandler sqLh = new OracleHandler();

            sqLh.ExecuteNonQuery("usp_Aspx_AddOrderShippingLabel", paraMeter);
        }
        public static void SaveShippingLabelInfo(ShippingLabelInfo labelInfo, AspxCommonInfo commonInfo)
        {

            List<KeyValuePair<string, object>> paraMeter = new List<KeyValuePair<string, object>>();
            paraMeter.Add(new KeyValuePair<string, object>("@OrderID", labelInfo.OrderID));
            paraMeter.Add(new KeyValuePair<string, object>("@ShippingLabelImage", labelInfo.ShippingLabelImage));
            paraMeter.Add(new KeyValuePair<string, object>("@Extention", labelInfo.Extension));
            paraMeter.Add(new KeyValuePair<string, object>("@TrackingNo", labelInfo.TrackingNo));
            paraMeter.Add(new KeyValuePair<string, object>("@BarcodeNo", labelInfo.BarcodeNo));
            paraMeter.Add(new KeyValuePair<string, object>("@IsRealTime", labelInfo.IsRealTime));
            paraMeter.Add(new KeyValuePair<string, object>("@PortalId", commonInfo.StoreID));
            paraMeter.Add(new KeyValuePair<string, object>("@StoreId", commonInfo.StoreID));
            paraMeter.Add(new KeyValuePair<string, object>("@UserName", commonInfo.UserName));
            SQLHandler sqLh = new SQLHandler();
            sqLh.ExecuteNonQuery("[dbo].[usp_Aspx_AddOrderShippingLabel]", paraMeter);
        }
 private void SaveLabelInfo(ShippingLabelInfo info)
 {
     try
     {
         AspxCommonInfo commonObj = new AspxCommonInfo();
         commonObj.StoreID = _storeId;
         commonObj.PortalID = _portalId;
         commonObj.UserName = GetUsername;
         AspxShipProviderMgntController ctl = new AspxShipProviderMgntController();
         ctl.SaveShippingLabelInfo(info, commonObj);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
    private void CreateLabel()
    {
        try
        {


            string api = rblLabelTypeList.SelectedValue;
            var items = (List<ItemDetail>)Session["sl_items"];
            var orderInfo = (OrderLabel)Session["labelOrderInfo"];
            if (items == null)
            {
                BindPackageDetails(orderInfo);
                items = (List<ItemDetail>)Session["sl_items"];
            }
            var totalWt = items.Sum(itemDetail => itemDetail.Weight);
            if (totalWt == 0)
            {
                throw new Exception("Minimum weight of package must be 0.1");
            }
            decimal totalWtInOunce = 0;
            if (_weightUnit.ToLower().Trim() == "lbs" || _weightUnit.ToLower().Trim() == "lb")
            {
                               totalWtInOunce = (decimal)((totalWt) * 16);
            }
            else
            {
                               totalWt = totalWt * (decimal)2.2;
            }

            var package = new USPSShipment();
            package.Width = decimal.Parse(txtPackageWidth.Text.Trim());
            package.Height = decimal.Parse(txtPackageHeight.Text.Trim());
            package.FromAddress = (OriginAddress)Session["sl_frAddress"];
            package.GrossOunce = totalWtInOunce;
            package.GrossPound = totalWt;
            var total = CalculateGirth();
            package.Container = Container.RECTANGULAR;
            package.ContentType = ContentType.OTHER;
            package.ImageLayout = ImageLayout.ALLINONEFILE;
            package.ImageType = (ImageType)Enum.Parse(typeof(ImageType), ddlImageType.SelectedValue);
            package.Items = items;
            package.NonDeliveryOption = NonDeliveryOption.RETURN;
            package.Option = "1";
            package.POZipCode = "";
            package.ServiceType = (ServiceType)Enum.Parse(typeof(ServiceType), ddlServiceType.SelectedValue);
            package.ToAddress = (DestinationAddress)Session["sl_toAddress"];
            package.Length = decimal.Parse(txtPackageLength.Text.Trim());
            package.Grith = decimal.Parse(txtPackageGirth.Text.Trim());
            package.Api = api;
            var providerId = int.Parse(Session["sl_pid"].ToString());

            var labelCreater = new USPS();

            var response = labelCreater.SendShipmentConfirmation(package, providerId, GetStoreID, GetPortalID);

            if (!response.IsFailed)
            {


                if (response.IsDomestic)
                {
                    string trackingNo = response.DeliveryConfirmationNumber;
                                                          ShippingLabelInfo info = new ShippingLabelInfo();
                    info.TrackingNo = trackingNo;
                    info.ShippingLabelImage = response.LabelString;
                    info.OrderID = orderInfo.OrderId;
                    info.Extension = package.ImageType.ToString().ToLower();
                    info.IsRealTime = true;
                    SaveLabelInfo(info);
                    DisplayFile(response.TempLabelPath);
                    lblErrorMessage.Text = "";
                }
                else
                {
                    string barcodeNo = response.IntlResponse.BarcodeNumber;
                                      
                    ShippingLabelInfo info = new ShippingLabelInfo();
                    info.ShippingLabelImage = response.LabelString;
                    info.OrderID = orderInfo.OrderId;
                    info.Extension = package.ImageType.ToString().ToLower();
                    info.IsRealTime = true;
                    info.TrackingNo = "";
                    info.BarcodeNo = barcodeNo;
                    SaveLabelInfo(info);
                }
                ClearForm();

            }
            else
            {
                lblErrorMessage.Text = response.Error;
            }
        }
        catch (Exception ex)
        {

            throw ex;
        }
    }
 private void DisplayFile(ShippingLabelInfo info)
 {
     string strExtenstion = info.Extension.ToLower();
     Response.Clear();
     Response.Buffer = true;
     if (strExtenstion == "doc" || strExtenstion == "docx")
     {
         Response.ContentType = "application/vnd.ms-word";
                    Response.AddHeader("content-disposition", "inline;filename=_labelPreview.doc");
     }
     else if (strExtenstion == "xls" || strExtenstion == "xlsx")
     {
         Response.ContentType = "application/vnd.ms-excel";
         Response.AddHeader("content-disposition", "inline;filename=_labelPreview.xls");
     }
     else if (strExtenstion == "pdf")
     {
         Response.ContentType = "application/pdf";
         Response.AddHeader("content-disposition", "inline;filename=_labelPreview.pdf");
     }
     else if (strExtenstion == "tif")
     {
         Response.ContentType = "image/tiff";
         Response.AddHeader("content-disposition", "inline;filename=_labelPreview.tif");
     }
     else if (strExtenstion == "jpeg" || strExtenstion == "jpg")
     {
         Response.ContentType = "image/jpeg";
         Response.AddHeader("content-disposition", "inline;filename=_labelPreview.jpg");
     }
     else if (strExtenstion == "gif")
     {
         Response.ContentType = "image/gif";
         Response.AddHeader("content-disposition", "inline;filename=_labelPreview.gif");
     }
     Response.Charset = "";
     Response.Cache.SetCacheability(HttpCacheability.NoCache);
    
     Response.BinaryWrite(Convert.FromBase64String(info.ShippingLabelImage));
     Response.End();
 }