using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace TestWebService2

{

    class Program

    {

        private const string Username = "username";

        private const string Password = "password";

 

        static private dclcorp.DCLWebService myService = new dclcorp.DCLWebService();

        static private string SessionID = "";

 

        // -------------------------------------

 

        static void Main(string[] args)

        {

            if (string.IsNullOrEmpty(Username) || string.IsNullOrEmpty(Password))

            {

                Console.WriteLine("Please set Username and Password");

                return;

            }

 

            SessionID = myService.Login(Username, Password);

            if (string.IsNullOrEmpty(SessionID))

            {

                Console.WriteLine("Wrong Username/Password");

                return;

            }

 

            dclcorp.BatchType01Object Batch = new dclcorp.BatchType01Object();

            Batch.Location = "FR"; // or "LA"

 

            // In this sample we add just one order to the batch

            Batch.OrderArray = new dclcorp.OrderType01Object[2];

            for(int i = 0; i < Batch.OrderArray.Length; i++)

            {

                Batch.OrderArray[i] = new dclcorp.OrderType01Object();

            }

 

            // Let's get the first order

            // -----------------------------------------------------------

            dclcorp.OrderType01Object Order = Batch.OrderArray[0];

            // -----------------------------------------------------------

 

            Order.AccountNumber = "01234";

            Order.OrderNumber = "Test1234";

            Order.ShipTo = new dclcorp.AddressType01Object();

            Order.ShipTo.Attention = "Mr. Smith";

            Order.ShipTo.Address1 = "48641 Milmont Dr";

            Order.ShipTo.City = "Fremont";

            Order.ShipTo.Country = "USA";

            Order.ShipTo.PostalCode = "94538";

            Order.ShipTo.StateProvince = "CA";

 

            Order.FreightAccount = "00500";

            Order.ShippingCarrier = "UPS";

            Order.ShippingService = "GROUND";

            Order.OrderStatus = dclcorp.OrderStatusObject.HoldOrder;

 

            // In this sample we add just one detail to the order

            Order.DetailArray = new dclcorp.DetailType01Object[1];

            for (int i = 0; i < Order.DetailArray.Length; i++)

            {

                Order.DetailArray[i] = new dclcorp.DetailType01Object();

            }

 

            // Let's get the first detail

            dclcorp.DetailType01Object Detail = Order.DetailArray[0];

            Detail.ItemNumber = "ITEM0001";

            Detail.Quantity = 1;

 

            // -----------------------------------------------------------

            // Second order

            // -----------------------------------------------------------

            Order = Batch.OrderArray[1];

 

            Order.AccountNumber = "01234";

            Order.OrderNumber = "Test5678";

            Order.ShipTo = new dclcorp.AddressType01Object();

            Order.ShipTo.Attention = "Mr. Smith";

            Order.ShipTo.Address1 = "48641 Milmont Dr";

            Order.ShipTo.City = "Fremont";

            Order.ShipTo.Country = "USA";

            Order.ShipTo.PostalCode = "94538";

            Order.ShipTo.StateProvince = "CA";

 

            Order.FreightAccount = "00500";

            Order.ShippingCarrier = "UPS";

            Order.ShippingService = "GROUND";

            Order.OrderStatus = dclcorp.OrderStatusObject.HoldOrder;

 

            // In this sample we add just one detail to the order

            Order.DetailArray = new dclcorp.DetailType01Object[1];

            for (int i = 0; i < Order.DetailArray.Length; i++)

            {

                Order.DetailArray[i] = new dclcorp.DetailType01Object();

            }

 

            // Let's get the first detail

            Detail = Order.DetailArray[0];

            Detail.ItemNumber = "ITEM0002";

            Detail.Quantity = 1;

 

            // ===========================================================

            // Let's submit the batch using SubmitBatchOrder

            /*

            dclcorp.BatchType01Result Result =

                myService.SubmitBatchOrder(SessionID, Batch);

            if (Result.ResultStatus.Error == 0)

            {

                // Update SessionID for next calls (in case needed)

                SessionID = Result.ResultStatus.SessionID;

                Console.WriteLine("Success!");

                Console.WriteLine(string.Format("Batch Name: {0}", Result.BatchName));

            }

            else

            {

                Console.WriteLine(Result.ResultStatus.ErrorStr);

            }

            */

            // Let's submit the batch using SubmitBatchOrder2

            dclcorp.BatchType02Result Result =

                myService.SubmitBatchOrder2(SessionID, Batch);

            if (Result.ResultStatus.Error == 0) // Batch header is OK!

            {

                // Let's see which order has been accepted and which one has been rejected

                for (int i = 0; i < Result.OrderStatusArray.Length; i++)

                {

                    if (Result.OrderStatusArray[i].Error != 0)

                    {

                        Console.WriteLine("Order index = {0} rejected with error: {1}", i, Result.OrderStatusArray[i].ErrorStr);

                    }

                    else

                    {

                        Console.WriteLine("Order index = {0} accepted!", i);

                    }

                }

                // Update SessionID for next calls (in case needed)

                SessionID = Result.ResultStatus.SessionID;

                Console.WriteLine("Success!");

                Console.WriteLine(string.Format("Batch Name: {0}", Result.BatchName));

            }

            else

            {

                Console.WriteLine(Result.ResultStatus.ErrorStr);

            }

 

            return;

        }

    }

}