private void btnTestConnection_Click(object sender, EventArgs e)
        {
            _customerRestObj = null;

            var getListResult = CustomerRestObj.GetList("top=1");
            var validConInfo  = GenericsEpicorAPI.RESTAPI.IsValidJsonStr(getListResult);

            MessageBox.Show(
                validConInfo ?
                "Entered server information is correct!" :
                "Invalid server information", StrategicCustomerManager, MessageBoxButtons.OK, MessageBoxIcon.Information);

            if (validConInfo)
            {
                var resultDictionary = JsonConvert.DeserializeAnonymousType(getListResult, new Dictionary <string, object>());

                try
                {
                    resultDictionary = JsonConvert.DeserializeAnonymousType(
                        resultDictionary["value"].ToString()
                        .Substring(1, resultDictionary["value"].ToString().Length - 2),
                        new Dictionary <string, object>());

                    Company = resultDictionary["Company"].ToString();
                }
                catch
                {
                    // ignored
                }
            }

            statusLbl.Text = StatusFixedText + CustomerRestObj.LastUrlRequested;
        }
        private void RefreshList(ListBox selectedList, string filter)
        {
            selectedList.Items.Clear();

            var jsonFriendlist = CustomerRestObj.GetList(string.Format(filter, Company, "", ""));

            statusLbl.Text = StatusFixedText + CustomerRestObj.LastUrlRequested;

            if (!GenericsEpicorAPI.RESTAPI.IsValidJsonStr(jsonFriendlist))
            {
                return;
            }

            var resultDictionary = JsonConvert.DeserializeAnonymousType(jsonFriendlist, new Dictionary <string, object>());

            if ((resultDictionary?.ContainsKey("value") ?? false) && resultDictionary?["value"].ToString().Length > 10)
            {
                if (!(resultDictionary["value"] is JArray jArr))
                {
                    return;
                }

                foreach (var x in jArr)
                {
                    selectedList.Items.Add($"{x.Value<int>("CustNum")}~{x.Value<string>("Name")}");
                }
            }
        }
        private string EpicorDeleteImplementation()
        {
            var result = string.Empty;

            if ((int)CustomerView[0]["CustNum"] > 0)
            {
                result = CustomerRestObj.DeleteCustomer("", (int)CustomerView[0]["CustNum"]);
                this.statusLbl.Text = StatusFixedText + CustomerRestObj.LastUrlRequested;
            }



            _customerTable.Clear();
            NotifyAll();
            ModifiedTableIntegrity();

            if (!GenericsEpicorAPI.RESTAPI.IsValidJsonStr(result))
            {
                return(result);
            }

            var resultDictionary = JsonConvert.DeserializeAnonymousType(result, new Dictionary <string, object>());

            return(resultDictionary?.ContainsKey("ErrorMessage") ?? false
                ? resultDictionary?["ErrorMessage"].ToString()
                : "Delete successful");
        }
        private string EpicorUpdateImplementation()
        {
            var mod = new Dictionary <string, object>
            {
                { "CustID", CustomerView[0]["CustID"] },
                { "Name", CustomerView[0]["Name"] },
                { "City", CustomerView[0]["City"] },
                { "Country", CustomerView[0]["Country"] },
                { "Zip", CustomerView[0]["Interest"] },
                { "PhoneNum", chkIsStrategicCustomer.Checked ? "StrategicCustomer" : "" }
            };

            var result = (int)CustomerView[0]["CustNum"] == 0 ?
                         CustomerRestObj.GetNewCustomer(Company, mod) :                         // if it's a Customer: "GetNewCustomer"
                         CustomerRestObj.Update(Company, (int)CustomerView[0]["CustNum"], mod); // if we are updating customer information: "Update"

            if (!GenericsEpicorAPI.RESTAPI.IsValidJsonStr(result))
            {
                return(string.IsNullOrEmpty(result) ? "Update successful" : result);
            }

            var resultDictionary = JsonConvert.DeserializeAnonymousType(result, new Dictionary <string, object>());

            return(resultDictionary?.ContainsKey("ErrorMessage") ?? false
                ? resultDictionary?["ErrorMessage"].ToString()
                : "Update successful");
        }
        private void ListValueChanged(ListBox selectedList)
        {
            var custnum = selectedList?.SelectedItem?.ToString()
                          .Substring(0, selectedList.SelectedItem.ToString().IndexOf("~", StringComparison.Ordinal) > 0
                    ? selectedList.SelectedItem.ToString().IndexOf("~", StringComparison.Ordinal)
                    : 0);


            var s = CustomerRestObj.GetList(string.Format(allCustomersFilter, Company, $" and CustNum eq {custnum}",
                                                          ", CustID, City, Country, Zip, PhoneNum"));

            if (!GenericsEpicorAPI.RESTAPI.IsValidJsonStr(s))
            {
                return;
            }

            var resultDictionary = JsonConvert.DeserializeAnonymousType(s, new Dictionary <string, object>());

            if (resultDictionary.ContainsKey("value") && resultDictionary["value"].ToString().Length > 10)
            {
                if (!(resultDictionary["value"] is JArray jArr))
                {
                    return;
                }

                _customerTable.Clear();
                _customerTable.Rows.Add();


                CustomerView[0]["CustNum"]     = jArr.First.Value <string>("CustNum");
                CustomerView[0]["CustID"]      = jArr.First.Value <string>("CustID");
                CustomerView[0]["Name"]        = jArr.First.Value <string>("Name");
                CustomerView[0]["City"]        = jArr.First.Value <string>("City");
                CustomerView[0]["Country"]     = jArr.First.Value <string>("Country");
                CustomerView[0]["Interest"]    = jArr.First.Value <string>("Zip");
                chkIsStrategicCustomer.Checked =
                    jArr.First.Value <string>("PhoneNum")?.Equals("StrategicCustomer") ?? false;

                if (!string.IsNullOrEmpty(CustomerView[0]["Interest"].ToString()))
                {
                    for (var ix = 0; ix < chkInterest.Items.Count; ++ix)
                    {
                        if (chkInterest.GetItemText(chkInterest.Items[ix]) ==
                            CustomerView[0]["Interest"].ToString())
                        {
                            chkInterest.SetItemChecked(ix, true);
                        }
                    }
                }

                NotifyAll();
            }
        }