Ejemplo n.º 1
0
 private async void HeaderAsync(Model.InspectionHeaderTable inspectionHeaderTable, int MaxDetailCode, Boolean New)
 {
     inspectionHeaderTable.Id = MaxDetailCode;
     if (New)
     {
         inspectionHeaderTable.CreatedAt = DateTime.Now;
         inspectionHeaderTable.NewEntry  = true;
         await InitData.HeaderRepo.InsertItemAsync(inspectionHeaderTable);
     }
     else
     {
         inspectionHeaderTable.ModifiedAt = DateTime.Now;
         inspectionHeaderTable.Updated    = true;
         await InitData.HeaderRepo.UpdateItemAsync(inspectionHeaderTable);
     }
 }
Ejemplo n.º 2
0
        public async void AddNew_Command()
        {
            if (SelectedCompany == null)
            {
                await App.Current.MainPage.DisplayAlert("Alert ", "Please Select Company Name!", "ok");
            }
            else if (string.IsNullOrEmpty(Invoice))
            {
                await App.Current.MainPage.DisplayAlert("Alert", "Please Enter Invoice!", "ok");
            }
            else if (SelectedProduct == null)
            {
                await App.Current.MainPage.DisplayAlert("Alert ", "Please Select Product Name!", "ok");
            }
            else if (SelectedVariety == null)
            {
                await App.Current.MainPage.DisplayAlert("Alert ", "Please Select Variety Name!", "ok");
            }
            else if (SelectedBrand == null)
            {
                await App.Current.MainPage.DisplayAlert("Alert", "Please Select Brand Name!", "ok");
            }
            else if (SelectedCountryofOrigin == null)
            {
                await App.Current.MainPage.DisplayAlert("Alert", "Please Select CountryofOrigin Name!", "ok");
            }
            else if (TotalBoxQua == 0)
            {
                await App.Current.MainPage.DisplayAlert("Alert", "Please Enter Total Box Quantities!", "ok");
            }
            else if (TempOnCaja == 0)
            {
                await App.Current.MainPage.DisplayAlert("Alert", "Please Enter Temp On Caja!", "ok");
            }
            else if (TempOnTermografo == 0)
            {
                await App.Current.MainPage.DisplayAlert("Alert", "Please Enter Temp On Termografo!", "ok");
            }
            else if (SelectedPalletizingCondition == null)
            {
                await App.Current.MainPage.DisplayAlert("Alert", "Please Select Palletizing Condition!", "ok");
            }
            else
            {
                try
                {
                    UserDialogs.Instance.ShowLoading("Loading...");
                    RememberMe.Set("isSyncDatabse", true);
                    await Xamarin.Forms.Application.Current.SavePropertiesAsync();

                    InspectionHeadersRequestDTO inspectionHeaderRequestDTO = new InspectionHeadersRequestDTO()
                    {
                        Id                     = _InspectionHeader != null ? _InspectionHeader.Id : 0,
                        CompanyId              = (int)SelectedCompany.Id,
                        InspectionDate         = DateTime.Now,
                        UserId                 = Convert.ToInt32(RememberMe.Get("userID")),
                        Invoice                = Invoice,
                        ProducerId             = (int)SelectedProduct.Id,
                        VarietyId              = (int)SelectedVariety.Id,
                        BrandId                = (int)SelectedBrand.Id,
                        CountryofOriginId      = (int)SelectedCountryofOrigin.Id,
                        TotalBoxQuantities     = TotalBoxQua,
                        TempOnCaja             = TempOnCaja,
                        TempOnTermografo       = TempOnTermografo,
                        PalletizingConditionId = (int)SelectedPalletizingCondition.Id,
                    };
                    Model.InspectionHeaderTable inspectionHeaderTable = new Model.InspectionHeaderTable
                    {
                        Id                     = 0,
                        CompanyId              = inspectionHeaderRequestDTO.CompanyId,
                        InspectionDate         = inspectionHeaderRequestDTO.InspectionDate,
                        UserId                 = inspectionHeaderRequestDTO.UserId,
                        Invoice                = inspectionHeaderRequestDTO.Invoice,
                        ProducerId             = inspectionHeaderRequestDTO.ProducerId,
                        VarietyId              = inspectionHeaderRequestDTO.VarietyId,
                        BrandId                = inspectionHeaderRequestDTO.BrandId,
                        CountryofOriginId      = inspectionHeaderRequestDTO.CountryofOriginId,
                        TotalBoxQuantities     = inspectionHeaderRequestDTO.TotalBoxQuantities,
                        TempOnCaja             = inspectionHeaderRequestDTO.TempOnCaja,
                        TempOnTermografo       = inspectionHeaderRequestDTO.TempOnTermografo,
                        PalletizingConditionId = inspectionHeaderRequestDTO.PalletizingConditionId,
                    };

                    if (ConfigurationCommon.App_Online)
                    {
                        var result = await webServiceManager.RegistrationInspectionHeaderAsync(inspectionHeaderRequestDTO).ConfigureAwait(true);;
                        if (result.IsSuccess && result.Data.StatusCode == 0)
                        {
                            await App.Current.MainPage.DisplayAlert("Alert", "Inspection Header has been Saved!", "ok");

                            int InspectionID = _InspectionHeader != null ? _InspectionHeader.Id : 0;
                            var parameters   = new NavigationParameters();
                            if (InspectionID > 0)
                            {
                                HeaderAsync(inspectionHeaderTable, result.Data.Id, false);
                                parameters.Add("HeaderID", result.Data.Id);
                                await _navigationService.NavigateAsync("InspectionDetailsListPage", parameters);
                            }
                            else
                            {
                                UserDialogs.Instance.ShowLoading();
                                HeaderAsync(inspectionHeaderTable, result.Data.Id, true);
                                parameters.Add("HeaderID", result.Data.Id);
                                parameters.Add("ScreenRight", "New Detail Inspection");
                                await _navigationService.NavigateAsync("AddNewDetailsInspectionPage", parameters);

                                UserDialogs.Instance.HideLoading();
                            }
                        }
                        else
                        {
                            await App.Current.MainPage.DisplayAlert("Alert", result.Data.Status, "ok");
                        }
                    }
                    else
                    {
                        int MaxHeaderCode = 0;
                        if (inspectionHeaderRequestDTO.Id == 0)
                        {
                            var data = await InitData.HeaderRepo.GetMaxCode(x => x.Id, false);

                            MaxHeaderCode = (int)data.Id + 1;
                        }
                        else
                        {
                            MaxHeaderCode = inspectionHeaderRequestDTO.Id;
                        }

                        if (inspectionHeaderRequestDTO.Id > 0)
                        {
                            HeaderAsync(inspectionHeaderTable, MaxHeaderCode, false);

                            await App.Current.MainPage.DisplayAlert("Alert", "Inspection Header has been Saved!", "Ok");

                            var parameters = new NavigationParameters();
                            if (MaxHeaderCode > 0)
                            {
                                parameters.Add("HeaderID", MaxHeaderCode);
                                await _navigationService.NavigateAsync("InspectionDetailsListPage", parameters);
                            }
                        }
                        else
                        {
                            HeaderAsync(inspectionHeaderTable, MaxHeaderCode, true);

                            await App.Current.MainPage.DisplayAlert("Alert", "Inspection Header has been Saved!", "Ok");

                            var parameters = new NavigationParameters();
                            if (MaxHeaderCode > 0)
                            {
                                parameters.Add("HeaderID", MaxHeaderCode);
                                await _navigationService.NavigateAsync("InspectionDetailsListPage", parameters);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    UserDialogs.Instance.HideLoading();
                    throw ex;
                }
                finally
                {
                    UserDialogs.Instance.HideLoading();
                }
            }
        }