コード例 #1
0
ファイル: BranchAPIService.cs プロジェクト: kksboltibay/UPOSS
        public async Task <RootBranchObject> BranchPostAPI(string apiCommand, object param)
        {
            dynamic requestBody = new { command = apiCommand, @params = param };

            var content = new StringContent(JsonConvert.SerializeObject(requestBody), Encoding.UTF8, "application/json");

            try
            {
                string currentUsername = Properties.Settings.Default.CurrentUsername;
                string currentBranch   = Properties.Settings.Default.CurrentBranch;

                var authToken = Encoding.ASCII.GetBytes($"{currentUsername}:{currentBranch}");
                _request.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(authToken));

                var response = await _request.PostAsync("" + _Path, content);

                response.EnsureSuccessStatusCode();

                var responseString = await response.Content.ReadAsStringAsync();

                RootBranchObject responseObj = JsonConvert.DeserializeObject <RootBranchObject>(responseString);

                return(responseObj);
            }
            catch (HttpRequestException e)
            {
                Console.WriteLine("\nException Caught!");
                Console.WriteLine("Message :{0} ", e.Message);

                return(new RootBranchObject {
                    Status = "error", Msg = e.Message, Data = null
                });
            }
        }
コード例 #2
0
        private async void GetLoginBranchList()
        {
            try
            {
                dynamic param = new { page = 0 };

                RootBranchObject Response = await ObjAuthService.PostAPI("getLoginBranchList", param, _BranchPath);

                if (Response.Status == "ok")
                {
                    ActiveBranchList = new ObservableCollection <string>(Response.Data.OrderBy(property => property.Name).Select(item => item.Name));

                    if (ActiveBranchList.Contains(Properties.Settings.Default.CurrentBranch))
                    {
                        SelectedBranch = Properties.Settings.Default.CurrentBranch;
                    }
                    else
                    {
                        SelectedBranch = ActiveBranchList[0];
                    }
                }
                else
                {
                    MessageBox.Show(Response.Msg, "UPO$$");
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message.ToString(), "UPO$$");
            }
        }
コード例 #3
0
        private async Task Add()
        {
            try
            {
                BranchInputDialog _defaultInputDialog = new BranchInputDialog("What is the new branch name to be added ?", "add");

                if (_defaultInputDialog.ShowDialog() == true)
                {
                    if (_defaultInputDialog.Result is null || _defaultInputDialog.Result.Name == "")
                    {
                        IsLoading = false;
                        MessageBox.Show("New branch name can't be empty", "UPO$$");
                    }
                    else
                    {
                        dynamic param = new { branchName = _defaultInputDialog.Result.Name };

                        RootBranchObject Response = await ObjBranchService.PostAPI("addBranch", param, _Path);

                        MessageBox.Show(Response.Msg, "UPO$$");

                        if (Response.Status is "ok")
                        {
                            RefreshTextBox();
                            await Search();
                        }
                    }
                }
            }
コード例 #4
0
ファイル: ProductViewModel.cs プロジェクト: kksboltibay/UPOSS
        private async void GetActiveBranchList()
        {
            try
            {
                dynamic param = new { page = 0 };

                RootBranchObject Response = await ObjProductService.PostAPI("getBranchList", param, "branch");

                if (Response.Status == "ok")
                {
                    BranchList = new ObservableCollection <string>(Response.Data.OrderBy(property => property.Name).Select(item => item.Name));
                    BranchList.Add("All");
                }
                else
                {
                    BranchList = new ObservableCollection <string> {
                        "- Fail to get branch list -"
                    };
                    BranchList.Add("All");
                }
            }
            catch (Exception e)
            {
                BranchList = new ObservableCollection <string> {
                    "- Fail to get branch list -"
                };
                BranchList.Add("All");
            }
        }
コード例 #5
0
        private async Task Search()
        {
            try
            {
                var currentPage = Pagination.CurrentPage;

                dynamic param = new { page = currentPage, branchName = InputBranch.Name, is_active = SelectedStatus == "All" ? null : SelectedStatus };

                RootBranchObject Response = await ObjBranchService.PostAPI("getBranchList", param, _Path);

                if (Response.Status != "ok")
                {
                    IsLoading = false;
                    MessageBox.Show(Response.Msg, "UPO$$");
                    BranchList = null;
                    Pagination = new Pagination {
                        CurrentPage = 1, CurrentRecord = "0 - 0", TotalPage = 1, TotalRecord = 0
                    };
                }
                else
                {
                    //record section
                    var totalRecord = Response.Total;
                    var fromRecord  = currentPage == 0 ? 1 : (currentPage * 70) - 69;
                    var toRecord    = currentPage == 0 ? totalRecord : (fromRecord + 69 < totalRecord ? fromRecord + 69 : totalRecord);

                    //page section
                    var totalPage = currentPage == 0 ? 1 : Convert.ToInt32(Math.Ceiling((double)totalRecord / 70));

                    Pagination = new Pagination
                    {
                        CurrentRecord = fromRecord.ToString() + " ~ " + toRecord.ToString(),
                        TotalRecord   = totalRecord,

                        CurrentPage = currentPage == 0 ? 1 : currentPage,
                        TotalPage   = totalPage
                    };

                    //datagrid
                    BranchList = new ObservableCollection <Branch>(Response.Data.OrderBy(property => property.Id));

                    for (int i = 0; i < BranchList.Count; i++)
                    {
                        BranchList[i].Id = i + 1;
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message.ToString(), "UPO$$");
                BranchList = null;
                Pagination = new Pagination {
                    CurrentPage = 1, CurrentRecord = "0 - 0", TotalPage = 1, TotalRecord = 0
                };
            }

            RefreshTextBox();
        }
コード例 #6
0
        private async void GetActiveBranchList()
        {
            try
            {
                dynamic param = new { page = 0 };

                RootBranchObject Response = await ObjBranchService.PostAPI("getBranchList", param, "branch");

                if (Response.Status == "ok")
                {
                    cbBranchList.ItemsSource = Response.Data.OrderBy(property => property.Name).Select(item => item.Name);
                }
                else
                {
                    cbBranchList.Items.Add("- Fail to get branch list -");
                }
            }
            catch (Exception e)
            {
                cbBranchList.Items.Add("- Fail to get branch list -");
            }
        }