private async void UploadPhotoToServer(MediaFile file)
        {
            try
            {
                string[] temp     = file.Path.Split('/');
                string[] tempName = temp[temp.Length - 1].Split('.');
                string   filename = tempName[0];

                string     foldername = DateTime.Now.ToString("yyyy-MM-dd") + "/" + DateTime.Now.ToString("H-mm-ss");
                string     filepath   = "Files/InternalControl/" + Application.Current.Properties["CompanyId"].ToString() + "/" + Application.Current.Properties["OfficeId"].ToString() + "/" + foldername + "/" + temp[temp.Length - 1];
                var        content    = new MultipartFormDataContent();
                Uri        host       = new Uri("http://www.bisoft.se/Bisoft/receiver.ashx");
                UriBuilder ub         = new UriBuilder(host)
                {
                    Query = string.Format("filename={0}", filepath)
                };

                Stream data = file.GetStream();

                WebClient c = new WebClient();
                c.OpenWriteCompleted += (sender, e) =>
                {
                    PushData(data, e.Result);
                    e.Result.Close();
                    data.Close();

                    PhotoCls photo = new PhotoCls
                    {
                        Name = filename,
                        Path = filepath
                    };

                    AddedPhotos.Add(photo);
                };
                c.OpenWriteAsync(ub.Uri);


                // content.Add(new StreamContent(file.GetStream()),
                //    "\"file\"",
                //     $"\"{file.Path}\"");

                // var _httpClient = new HttpClient();
                //// _httpClient.PutAsync()

                // //_httpClient.Timeout = TimeSpan.FromSeconds(520);
                // //_httpClient.DefaultRequestHeaders.Accept.



                // var resp = await _httpClient.PostAsync(ub.Uri, content);
            }
            catch (Exception e)
            {
                await Application.Current.MainPage.DisplayAlert("", e.Message, "Stäng");
            }
        }
Beispiel #2
0
        public async void UploadFile()
        {
            if (!CrossMedia.Current.IsPickPhotoSupported)
            {
                await Application.Current.MainPage.DisplayAlert("File Not Supported.", "Permission not granted to files.", "STÄNG");

                return;
            }

            var file = await CrossMedia.Current.PickPhotoAsync(new PickMediaOptions
            {
                PhotoSize = PhotoSize.Large,
            });

            if (file != null)
            {
                string[] temp       = file.Path.Split('/');
                string[] tempName   = temp[temp.Length - 1].Split('.');
                string   filename   = tempName[0];
                string   foldername = DateTime.Now.ToString("yyyy-MM-dd") + "/" + DateTime.Now.ToString("H-mm-ss");
                string   filePath   = "Files/NyKvalitetsRapport/" + Application.Current.Properties["CompanyId"].ToString() + "/" + Application.Current.Properties["OfficeId"].ToString() + "/" + foldername + "/" + temp[temp.Length - 1];

                var        content = new MultipartFormDataContent();
                Uri        host    = new Uri("http://www.bisoft.se/Bisoft/receiver.ashx");
                UriBuilder ub      = new UriBuilder(host)
                {
                    Query = string.Format("filename={0}", filePath)
                };

                Stream data = file.GetStream();

                WebClient c = new WebClient();
                c.OpenWriteCompleted += (sender, e) =>
                {
                    PushData(data, e.Result);
                    e.Result.Close();
                    data.Close();

                    if (AllPhotoFiles == null)
                    {
                        AllPhotoFiles = new ObservableCollection <PhotoCls>();
                    }

                    PhotoCls phfile = new PhotoCls();
                    phfile.Name = filename;
                    phfile.Path = filePath;

                    AllPhotoFiles.Add(phfile);
                };
                c.OpenWriteAsync(ub.Uri);
            }
            else
            {
                await Application.Current.MainPage.DisplayAlert("File not supported.", "Ingen fil vald.", "STÄNG");
            }
        }
        private void Page_Disappearing1(object sender, EventArgs e)
        {
            if (SelectedPhoto != null)
            {
                if (_imagesVM.DeletePhoto == true)
                {
                    if (AddedPhotos != null && AddedPhotos.Count > 0 && AddedPhotos.Contains(SelectedPhoto))
                    {
                        AddedPhotos.Remove(SelectedPhoto);
                    }
                }
            }

            SelectedPhoto = null;
        }
Beispiel #4
0
        public async void GetControlRows()
        {
            try
            {
                InternalControlPerformRow cont;
                ICErrorCodeCls            codeCls;
                ICErrorCodeGroupCls       codeGroupCls;
                ICErrorCodeMainGroupCls   maingroupCls;

                PhotoCls photoCls;

                var result = Dbcontext.GetOfficeInternalControlLog(Application.Current.Properties["UN"].ToString(),
                                                                   Application.Current.Properties["PW"].ToString(), Application.Current.Properties["Ucid"].ToString(), IniControlLogId);
                ObservableCollection <InternalControlPerformRow> temp = new ObservableCollection <InternalControlPerformRow>();

                if (result != null)
                {
                    PerformedDate = result.Created;
                    if (result.Employee != null)
                    {
                        SelectedEmployee = AllOffices.SelectMany(emp => emp.Employees).Where(em => em.Id == result.Employee.Id).FirstOrDefault();
                    }

                    if (result.IsPartSaved == true)
                    {
                        IsEditable = true;
                        IsVisible  = true;
                    }
                    else
                    {
                        IsEditable = false;
                        IsVisible  = false;
                    }

                    if (result.InternalControlOffice.HasVehicleBrand == true)
                    {
                        VehicleIsVisible = true;
                        AONr             = result.AoNr;
                        RegNr            = result.RegNr;
                        if (result.VehicleBrand != null)
                        {
                            SelectedVehicleBrand = AllVehicleBrands.Where(vb => vb.Id == result.VehicleBrand.Id).FirstOrDefault();
                        }
                    }
                    if (result.Rows != null && result.Rows.Length > 0)
                    {
                        foreach (var data in result.Rows)
                        {
                            cont = new InternalControlPerformRow();
                            if (data.Id != null)
                            {
                                cont.Id = (int)data.Id;
                            }

                            cont.Question            = data.Text;
                            cont.TextColor           = Xamarin.Forms.Color.Gray;
                            cont.IndicatorColor      = Xamarin.Forms.Color.Gray;
                            cont.Group               = data.Group;
                            cont.Helptext            = data.HelpText;
                            cont.IsEA                = data.IsEA;
                            cont.IsNotOk             = data.IsNo;
                            cont.IsOk                = data.IsYes;
                            cont.ErrorCodeMainGroups = ErrorCodeMainGroups;
                            cont.Comment             = data.Comment;

                            if (result.IsPartSaved == true)
                            {
                                cont.AddErrorCodesIsVisible = true;
                                cont.IsClickabled           = true;
                                cont.AddPhotoIsVisible      = true;
                            }
                            else
                            {
                                cont.AddErrorCodesIsVisible = false;
                                cont.IsClickabled           = false;
                                cont.AddPhotoIsVisible      = false;
                            }


                            if (data.ErrorCodes != null && data.ErrorCodes.Count() > 0)
                            {
                                foreach (ServiceReference1.ICErrorCodeData codedata in data.ErrorCodes)
                                {
                                    codeCls      = new ICErrorCodeCls();
                                    codeCls.Code = codedata.Code;
                                    codeCls.Id   = codedata.Id;
                                    if (codedata.Group != null)
                                    {
                                        codeGroupCls      = new ICErrorCodeGroupCls();
                                        codeGroupCls.Id   = codedata.Group.Id;
                                        codeGroupCls.Name = codedata.Group.Name;
                                        codeCls.Group     = codeGroupCls;

                                        if (codedata.Group.MainGroup != null)
                                        {
                                            maingroupCls            = new ICErrorCodeMainGroupCls();
                                            maingroupCls.Id         = codedata.Group.MainGroup.Id;
                                            maingroupCls.Name       = codedata.Group.MainGroup.Name;
                                            codeCls.Group.MainGroup = maingroupCls;
                                        }
                                    }


                                    cont.SelectedErrorCodes.Add(codeCls);
                                }
                            }

                            cont.DeleteErrorCodesIsVisible = false;

                            cont.DeletePhotoIsVisible = false;
                            cont.AddedPhotos          = new ObservableCollection <Classes.Photo.PhotoCls>();

                            if (data.ImageFiles != null && data.ImageFiles.Count() > 0)
                            {
                                foreach (ServiceReference1.ICOLogRowFileData file in data.ImageFiles)
                                {
                                    photoCls      = new PhotoCls();
                                    photoCls.Name = file.FileName;
                                    photoCls.Path = file.FilePath;
                                    photoCls.Id   = file.Id;
                                    cont.AddedPhotos.Add(photoCls);
                                }
                            }

                            temp.Add(cont);
                        }
                    }
                }



                AllRows = new ObservableCollection <InternalControlPerformRow>(temp);
                // await Dbcontext.CloseAsync();
            }
            catch (Exception e)
            {
                await Dbcontext.CloseAsync();

                await Application.Current.MainPage.DisplayAlert("Fel", e.Message, "Stäng");
            }

            //Dbcontext = new ServiceReference1.Service1Client(ServiceReference1.Service1Client.EndpointConfiguration.BasicHttpBinding_IService1);
        }