Beispiel #1
0
        //private void AddReturnAddress()
        //{
        //    Request.ReturnAddress = new Address
        //    {
        //        Attention = "RAA",
        //        City = "RAC",
        //        CountryCode = "DK",
        //        Email = "*****@*****.**",
        //        Name = "Villy",
        //        Phone = "21174505",
        //        Reference = "RAR",
        //        StateCode = "",
        //        Street1 = "Stavnsholt Gydevej",
        //        Street2 = "70",
        //        ZipCode = "3460"
        //    };
        //}

        //private void AddServices()
        //{

        //    Request.Services =
        //        (
        //            new[]
        //            {
        //                new WsServiceV2
        //                {
        //                    Name = V3cServiceCode.FlexDeposit,
        //                    Parameters = new[] {"Stilles ved bagdør"}
        //                }
        //            }
        //        );
        //}


        private void XuSubmit_Click(object sender, EventArgs e)
        {
            XuSubmit.Enabled = false;

            ReadFields();

            #region UploadDocument

            var uploadDocumentSave = new List <V3dUploadDocument>();
            foreach (var ud in Request.UploadDocumentList)
            {
                uploadDocumentSave.Add(
                    new V3dUploadDocument
                {
                    Filename      = ud.Filename,
                    ImageBase64   = null,
                    ImageEncoding = ud.ImageEncoding,
                    ImageType     = ud.ImageType,
                }
                    );
            }

            DocumentUploadRead();

            foreach (var ud in Request.UploadDocumentList)
            {
                // Strip off path.
                ud.Filename = new FileInfo(ud.Filename).Name;
            }
            #endregion

            //AddReturnAddress();

            //AddServices();


            BusinessContext.Request = Request;

            if (!(BusinessContext.Execute())) // -------------> extern call --------> response
            {
                // Failure

                Clipboard.SetText(ToXmlString(BusinessContext.Response));

                var msg = new StringBuilder();
                msg.Append(String.IsNullOrWhiteSpace(BusinessContext.Response.StatusText) ? "" : String.Format("{0}", BusinessContext.Response.StatusText));

                if (BusinessContext.Response.StatusList != null)
                {
                    foreach (var current in BusinessContext.Response.StatusList)
                    {
                        msg.AppendFormat("{0}", msg.Length > 0 ? "\r\n" : "");
                        msg.Append(String.IsNullOrWhiteSpace(current.Code) ? "" : String.Format("Code: {0}, ", current.Code));
                        msg.Append(String.IsNullOrWhiteSpace(current.FieldName) ? "" : String.Format("Field: {0}, ", current.FieldName));
                        msg.Append(String.IsNullOrWhiteSpace(current.Code) ? "" : String.Format("Severity: {0}, ", current.Severity));
                        msg.Append(String.IsNullOrWhiteSpace(current.Code) ? "" : String.Format("Description: {0}", current.Text));
                    }
                }

                MessageBox.Show(msg.ToString());
            }
            else
            {
                // Success

                try
                {
                    if (BusinessContext.Response.BinaryImageList != null && BusinessContext.Response.BinaryImageList.Any())
                    {
                        var    current = BusinessContext.Response.BinaryImageList[0];
                        var    t1      = current.ImageBase64;
                        byte[] bytes   = Convert.FromBase64String(t1);

                        const string path = @"C:\Users\Administrator\Downloads";
                        var          name = String.Format("WayBill {0}.pdf", BusinessContext.Response.WayBillNumberHead);

                        var fullpath = Path.Combine(path, name);
                        var file     = new FileInfo(fullpath);

                        using (var fs = file.OpenWrite())
                        {
                            foreach (var b in bytes)
                            {
                                fs.WriteByte(b);
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show(@"No image returned");
                    }
                }
                // ReSharper disable once RedundantCatchClause
                // ReSharper disable once UnusedVariable
                catch (Exception ex)
                {
                    throw;
                }

                Clipboard.SetText(ToXmlString(BusinessContext.Response));
                MessageBox.Show(@"OK\r\n" + ToXmlString(BusinessContext.Response));
            }

            Request.UploadDocumentList = uploadDocumentSave.ToArray();

            XuSubmit.Enabled = true;
        }