Exemplo n.º 1
0
        void ReleaseDesignerOutlets()
        {
            if (lblTransactionText != null)
            {
                lblTransactionText.Dispose();
                lblTransactionText = null;
            }

            if (PointsText != null)
            {
                PointsText.Dispose();
                PointsText = null;
            }

            if (TimeText != null)
            {
                TimeText.Dispose();
                TimeText = null;
            }

            if (TransactionImage != null)
            {
                TransactionImage.Dispose();
                TransactionImage = null;
            }

            if (vBasis != null)
            {
                vBasis.Dispose();
                vBasis = null;
            }
        }
Exemplo n.º 2
0
        public async Task <HttpResponseMessage> UploadTransactionImage()
        {
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }
            var    TransactionImage = new TransactionImage();
            string root             = HttpContext.Current.Server.MapPath("~/App_Data");
            var    provider         = new MultipartFormDataStreamProvider(root);

            try
            {
                var imageDirPath = HostingEnvironment.MapPath("~/" + TransactionImageFolder);
                if (imageDirPath == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Image Folder not valid"));
                }


                await Request.Content.ReadAsMultipartAsync(provider);

                var filename      = "";
                var localFilename = "";
                foreach (MultipartFileData file in provider.FileData)
                {
                    filename      = file.Headers.ContentDisposition.FileName.Replace("\"", "");;
                    localFilename = file.LocalFileName;
                }

                foreach (var key in provider.FormData.AllKeys)
                {
                    foreach (var val in provider.FormData.GetValues(key))
                    {
                        if (key == "TransactionId")
                        {
                            TransactionImage.TransactionId = long.Parse(val);
                        }
                    }
                }

                if (String.IsNullOrEmpty(filename))
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Filename not valid"));
                }

                if (TransactionImage.TransactionId == 0)
                {
                    var path = Path.Combine(imageDirPath, "temp", filename);
                    if (!Directory.Exists(Path.Combine(imageDirPath, "temp")))
                    {
                        Directory.CreateDirectory(Path.Combine(imageDirPath, "temp"));
                    }
                    File.Copy(localFilename, path, true);
                }
                else
                {
                    var path = Path.Combine(imageDirPath, TransactionImage.TransactionId.ToString(), filename);
                    if (!Directory.Exists(Path.Combine(imageDirPath, TransactionImage.TransactionId.ToString())))
                    {
                        Directory.CreateDirectory(Path.Combine(imageDirPath, TransactionImage.TransactionId.ToString()));
                    }
                    File.Copy(localFilename, path, true);
                }

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e));
            }
        }
        private static void SaveTransactionImages(ServiceReference1.MainClient a, User usr)
        {
            var transactions = a.GetAllTransactions(usr.UserId);
            var trans = transactions[0];
            var transWithImages = transactions.FirstOrDefault(x => x.TransactionId == 11132);
            var transImages = a.GetImagesForTransaction(transWithImages.TransactionId);
            
            var transImage = new TransactionImage(usr)
            {
                Transaction = trans,
                Path = "/Assets/login_white.png",
                Name = string.Format("{0} [{1}]", "aaaa", "bbbb"),
                Image = transImages[0].Image,
                Thumbnail = transImages[0].Image
            };

            var transImageList = new TransactionImageList();
            transImageList.Add(transImage);

            transImages.Add(transImage);
            trans.TransactionImages = (TransactionImageList)transImages;
            trans.ModifiedDate = DateTime.Now;
            trans.OptimizeOnTopLevel(Transaction.ImageRemovalStatus.Unchanged);

            a.SaveTransactions(new ObservableCollection<Transaction> { trans });
//            a.SaveTransactionImages(transImages);
        }
        private void cameraTask_Completed(object sender, PhotoResult e)
        {
            if (e.TaskResult == TaskResult.OK)
            {
                var bitmap = new BitmapImage();
                bitmap.SetSource(e.ChosenPhoto);

                //byte[] m_Bytes = ReadToEnd(e.ChosenPhoto);

                //imgReceipt.Source = new BitmapImage(new Uri(e.OriginalFileName));
                //vm.CurrTransaction.TransactionImages.Add(new TransactionImage(App.Instance.User) { Path = e.OriginalFileName });

                using (var stream = new MemoryStream())
                {
                     //PictureDecoder.DecodeJpeg(stream);
                }

                WriteableBitmap wBitmap = new WriteableBitmap(bitmap);
                
                double factorThumb = 1L;
                double factorImage = 1L;

                if (wBitmap.PixelHeight > wBitmap.PixelWidth)
                {
                    factorThumb = wBitmap.PixelHeight / 150;
                    factorImage = wBitmap.PixelHeight / 600;
                }
                else
                {
                    factorThumb = wBitmap.PixelWidth / 150;
                    factorImage = wBitmap.PixelWidth / 600;
                }

                int heightThumb = Convert.ToInt32(wBitmap.PixelHeight / factorThumb);
                int widthThumb = Convert.ToInt32(wBitmap.PixelWidth / factorThumb);

                int heightImage = Convert.ToInt32(wBitmap.PixelHeight / factorImage);
                int widthImage = Convert.ToInt32(wBitmap.PixelWidth / factorImage);

                MemoryStream msThumb = new MemoryStream();
                wBitmap.SaveJpeg(msThumb, widthThumb, heightThumb, 0, 100);
                byte[] tn_Bytes = ReadToEnd(msThumb);

                MemoryStream msImage = new MemoryStream();
                wBitmap.SaveJpeg(msImage, widthImage, heightImage, 0, 100);
                byte[] m_Bytes = ReadToEnd(msImage);

                var transImage = new TransactionImage(App.Instance.User) { 
                                                Transaction = vm.CurrTransaction,
                                                Path = "/Assets/login_white.png",
                                                Name = string.Format("{0} [{1}]", vm.CurrTransaction.NameOfPlace, vm.CurrTransaction.TotalAmount),
                                                Image = m_Bytes,
                                                Thumbnail = tn_Bytes
                };
                //vm.CurrTransactionImages.Add(transImage);
                if (vm.CurrTransaction.TransactionImages == null)
                    vm.CurrTransaction.TransactionImages = new TransactionImageList();
                vm.CurrTransaction.TransactionImages.Add(transImage);
                vm.CurrTransaction.HasPhotos = true;
                vm.CurrTransaction.HasChanges = true;

                save.IsEnabled = vm.Transactions.HasItemsWithChanges() && vm.IsLoading == false;
                //imgReceipt.Source = bitmap;
            }
        }