private void btnSendXML_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(authToken))
            {
                APIRequestResponse requestResponse = new APIRequestResponse();
                string             sourceFile      = txtSendXMLPath.Text;
                string             sendString      = System.IO.File.ReadAllText(sourceFile);

                using (HttpClient client = new HttpClient())
                {
                    client.BaseAddress = new Uri(landSeaOrderURL);

                    client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("BIPASK", authToken);
                    client.DefaultRequestHeaders.Add("BIPASK", authToken);
                    var res = client.PostAsJsonAsync("ProcessXML/", sendString).Result;

                    if (res.IsSuccessStatusCode)
                    {
                        requestResponse = res.Content.ReadAsAsync <APIRequestResponse>().Result;
                    }
                    else
                    {
                        string resultString = res.Content.ReadAsStringAsync().Result;
                    }
                }

                MessageBox.Show("XML message send successful.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("XML message send failed.", "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnGetXML_Click(object sender, EventArgs e)
        {
            string selectedType = gbxGetXML.Controls.OfType <RadioButton>().FirstOrDefault(n => n.Checked).Text;
            string type         = string.Empty;

            if (selectedType == "Organization")
            {
                type = "Organization";
            }
            else if (selectedType == "Shipment")
            {
                type = "ForwardingShipment";
            }

            //string key = txtMessageKey.Text;

            //if (string.IsNullOrEmpty(type) || string.IsNullOrEmpty(key))
            if (string.IsNullOrEmpty(type))
            {
                MessageBox.Show("Please specify both type and message number.", "Failure");
            }
            else
            {
                APIRequestResponse requestResponse = new APIRequestResponse();

                using (HttpClient client = new HttpClient())
                {
                    client.BaseAddress = new Uri(landSeaOrderURL);

                    client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("BIPASK", authToken);
                    client.DefaultRequestHeaders.Add("BIPASK", authToken);
                    //HttpResponseMessage res = client.GetAsync("GetXMLDocs?key=" + key + "&type=" + type).Result;
                    HttpResponseMessage res = client.GetAsync("XMLDocuments/GetXMLDocs?type=" + type).Result;

                    if (res.IsSuccessStatusCode)
                    {
                        requestResponse = res.Content.ReadAsAsync <APIRequestResponse>().Result;
                    }
                    else
                    {
                        string resultString = res.Content.ReadAsStringAsync().Result;
                    }
                }

                if (requestResponse.Data == null)
                {
                    rtxXMLMessageResult.Text = requestResponse.Message + Environment.NewLine + requestResponse.MessageDetail;
                }
                else
                {
                    rtxXMLMessageResult.Text = requestResponse.Data.ToString();
                }
            }
        }
        private void btnMarkAsProcessed_Click(object sender, EventArgs e)
        {
            string processedMessageID = txtProcessedMessageID.Text;

            if (string.IsNullOrEmpty(processedMessageID))
            {
                MessageBox.Show("Please specify message ID.", "Failure");
            }
            else
            {
                try
                {
                    APIRequestResponse requestResponse = new APIRequestResponse();

                    using (HttpClient client = new HttpClient())
                    {
                        client.BaseAddress = new Uri(landSeaOrderURL);

                        client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("BIPASK", authToken);
                        client.DefaultRequestHeaders.Add("BIPASK", authToken);
                        HttpResponseMessage res = client.GetAsync("SAPProcessed?messageID=" + processedMessageID).Result;

                        if (res.IsSuccessStatusCode)
                        {
                            requestResponse = res.Content.ReadAsAsync <APIRequestResponse>().Result;
                        }
                        else
                        {
                            string resultString = res.Content.ReadAsStringAsync().Result;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
        private void btnUpdateETN_Click(object sender, EventArgs e)
        {
            APIRequestResponse apiResponse      = new APIRequestResponse();
            string             tokenReturnValue = string.Empty;
            string             tokenvalue       = string.Empty;

            System.Net.WebRequest req = System.Net.WebRequest.Create("http://129.232.164.178/BIPEXAPI/Authentication?username=LandseaAPIUser&password=ujD@wxxg_z3Eg9aK");
            req.ContentType = "application/x-www-form-urlencoded";
            req.Method      = "GET";

            string tokenResponse = string.Empty;

            System.Net.WebResponse resp = req.GetResponse();
            if (resp == null)
            {
                MessageBox.Show("Authentication Failed");
                return;
            }

            using (System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream()))
            {
                tokenResponse = sr.ReadToEnd().Trim();
            }
            if (!string.IsNullOrEmpty(tokenResponse))
            {
                tokenReturnValue = "Data";
                tokenvalue       = JObject.Parse(tokenResponse)[tokenReturnValue].ToString();
            }

            ETNNumberModel model = new ETNNumberModel
            {
                CaroWiseKey      = "S00001006",
                ETNNumber        = "DOC16",
                GIBInvoiceNumber = "LSG00000000001"
            };

            // Update ETN Numbers linked to Cargo Wise key
            System.Net.ServicePointManager.ServerCertificateValidationCallback += (senderDetail, certificate, chain, sslPolicyErrors) => true;
            using (HttpClient client = new HttpClient(new HttpClientHandler {
                ClientCertificateOptions = ClientCertificateOption.Automatic
            }))
            {
                string landseaAPIURL = "http://129.232.164.178/LandSeaGlobal/LandseaAPI/api/ETNNumber/";
                //string landseaAPIURL = "http://localhost:51203/api/ETNNumber/";
                client.BaseAddress = new Uri(landseaAPIURL);

                client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("BIPASK", tokenvalue);
                client.DefaultRequestHeaders.Add("BIPASK", authToken);
                HttpResponseMessage res = client.PutAsJsonAsync("Update", model).Result;

                if (res.IsSuccessStatusCode)
                {
                    apiResponse = res.Content.ReadAsAsync <APIRequestResponse>().Result;
                    MessageBox.Show(apiResponse.ToString());
                }
                else
                {
                    string resultString = res.Content.ReadAsStringAsync().Result;
                    MessageBox.Show(resultString);
                }
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            APIRequestResponse apiResponse      = new APIRequestResponse();
            string             tokenReturnValue = string.Empty;
            string             tokenvalue       = string.Empty;

            System.Net.WebRequest req = System.Net.WebRequest.Create("http://129.232.164.178/BIPEXAPI/Authentication?username=LandseaAPIUser&password=ujD@wxxg_z3Eg9aK");
            req.ContentType = "application/x-www-form-urlencoded";
            req.Method      = "GET";

            string tokenResponse = string.Empty;

            System.Net.WebResponse resp = req.GetResponse();
            if (resp == null)
            {
                MessageBox.Show("Authentication Failed");
                return;
            }

            using (System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream()))
            {
                tokenResponse = sr.ReadToEnd().Trim();
            }
            if (!string.IsNullOrEmpty(tokenResponse))
            {
                tokenReturnValue = "Data";
                tokenvalue       = JObject.Parse(tokenResponse)[tokenReturnValue].ToString();
            }

            //string sendString = "<Payments>";
            //sendString += "<Payment>";
            //sendString += "<CompanyCode>IST</CompanyCode>";
            //sendString += "<OrgCode>KASDUAIST</OrgCode>";
            //sendString += "<LedgerType>AR</LedgerType>";
            //sendString += "<TransactionType>INV</TransactionType>";
            //sendString += "<TransactionNo>S00001004</TransactionNo>";
            //sendString += "<JobNumber/>";
            //sendString += "<PaymentReference>Payment Testing</PaymentReference>";
            //sendString += "<IntReference>Payment to BSW</IntReference>";
            //sendString += "<Amount>150.00</Amount>";
            //sendString += "<PaidUpDate/>";
            //sendString += "</Payment>";
            //sendString += "</Payments>";
            string sendString = File.ReadAllText(@"C:\General Development\Clients\LandSea Global\2021-12-22 Add ChargeLine Table\Payment Test.xml");

            // Update ETN Numbers linked to Cargo Wise key
            System.Net.ServicePointManager.ServerCertificateValidationCallback += (senderDetail, certificate, chain, sslPolicyErrors) => true;
            using (HttpClient client = new HttpClient(new HttpClientHandler {
                ClientCertificateOptions = ClientCertificateOption.Automatic
            }))
            {
                //string landseaAPIURL = "http://129.232.164.178/LandSeaGlobal/LandseaAPI/api/Accounting/";
                string landseaAPIURL = "http://localhost:51203/api/Accounting/";
                client.BaseAddress = new Uri(landseaAPIURL);

                client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("BIPASK", tokenvalue);
                client.DefaultRequestHeaders.Add("BIPASK", authToken);
                HttpResponseMessage res = client.PostAsJsonAsync("UpdateInvoicePaymentDetails", sendString).Result;

                if (res.IsSuccessStatusCode)
                {
                    apiResponse = res.Content.ReadAsAsync <APIRequestResponse>().Result;
                    MessageBox.Show(apiResponse.ToString());
                }
                else
                {
                    string resultString = res.Content.ReadAsStringAsync().Result;
                    MessageBox.Show(resultString);
                }
            }
        }