Exemplo n.º 1
0
        private async void getFileFromLocal(object obj)
        {
            string newFileFullPath = InfoGeneral.ExecuteOpenFileDialog("Select an image file", new List <string> {
                "png", "jpeg", "jpg"
            });

            if (!string.IsNullOrEmpty(newFileFullPath) && File.Exists(newFileFullPath))
            {
                var ftpCredentials = Bl.BlReferential.searchInfo(new Info {
                    Name = "ftp_"
                }, ESearchOption.AND);

                if (!string.IsNullOrEmpty(SelectedAgentModel.TxtPicture))
                {
                    WPFHelper.deleteFileFromFtpServer(ConfigurationManager.AppSettings["ftp_profile_image_folder"], SelectedAgentModel.TxtPicture, ftpCredentials);
                }

                if (SelectedAgentModel.Image != null)
                {
                    SelectedAgentModel.Image.closeImageSource();
                    WPFHelper.deleteFileFromFtpServer(ConfigurationManager.AppSettings["ftp_profile_image_folder"], SelectedAgentModel.TxtPicture, ftpCredentials);
                }
                else
                {
                    SelectedAgentModel.Image = await Task.Factory.StartNew(() => { return(SelectedAgentModel.Image.downloadPicture(ConfigurationManager.AppSettings["ftp_profile_image_folder"], ConfigurationManager.AppSettings["local_profile_image_folder"], SelectedAgentModel.TxtPicture, SelectedAgentModel.TxtProfileImageFileNameBase + "_" + Bl.BlSecurity.GetAuthenticatedUser().ID, ftpCredentials)); });
                }

                // opening the file explorer to choose and resize an image file
                SelectedAgentModel.Image.TxtChosenFile = newFileFullPath.resizeImage();
                SelectedAgentModel.TxtPicture          = SelectedAgentModel.Image.TxtFileName;

                Singleton.getDialogueBox().showSearch(ConfigurationManager.AppSettings["update_message"]);

                // upload the image file to the FTP server
                SelectedAgentModel.Image.uploadImage();

                // update item image
                var savedAgentList = await Bl.BlAgent.UpdateAgentAsync(new List <Agent> {
                    SelectedAgentModel.Agent
                });

                if (savedAgentList.Count > 0)
                {
                    await Singleton.getDialogueBox().showAsync("The picture has been saved successfully!");
                }
                else
                {
                    string errorMessage = "Error occured while updating the agent [" + SelectedAgentModel.TxtLastName + "] picture";
                    Log.error(errorMessage, EErrorFrom.ITEM);
                    await Singleton.getDialogueBox().showAsync(errorMessage);
                }

                Singleton.getDialogueBox().IsDialogOpen = false;
            }
        }
Exemplo n.º 2
0
        private async void deleteImage(InfoDisplay obj)
        {
            if (await Singleton.getDialogueBox().showAsync("Do you really want to delete this image [" + obj.TxtFileName + "] ?"))
            {
                Singleton.getDialogueBox().showSearch(ConfigurationManager.AppSettings["delete_message"]);
                var notDeletedInfosList = await Bl.BlReferential.DeleteInfoAsync(obj.InfoDataList);

                var whereImageInfosIDIsZeroList = obj.InfoDataList.Where(x => x.ID == 0 && x.Name.Equals(obj.TxtFileNameWithoutExtension)).ToList();
                if ((notDeletedInfosList.Count == 0 || whereImageInfosIDIsZeroList.Count > 0) && obj.deleteFiles())
                {
                    var credentials = Bl.BlReferential.searchInfo(new Info {
                        Name = "ftp_"
                    }, ESearchOption.AND);
                    if (WPFHelper.deleteFileFromFtpServer(ConfigurationManager.AppSettings["ftp_image_folder"], obj.TxtFileName, credentials))
                    {
                        await Singleton.getDialogueBox().showAsync(obj.TxtFileName + " has been successfully deteleted!");

                        obj.TxtFileFullPath = "";
                    }
                    else
                    {
                        string errorMessage = "Error occurred while deleting the image [" + obj.TxtFileName + "]";
                        Log.error(errorMessage, EErrorFrom.REFERENTIAL);
                        Singleton.getDialogueBox().showSearch(errorMessage);
                    }
                }

                // reset the picture information
                foreach (Info info in obj.InfoDataList)
                {
                    info.ID = 0;
                }

                Singleton.getDialogueBox().IsDialogOpen = false;
            }
        }
Exemplo n.º 3
0
        private async void getFileFromLocal(object obj)
        {
            string newFileFullPath = InfoGeneral.ExecuteOpenFileDialog("Select an image file", new List <string> {
                "png", "jpeg", "jpg"
            });

            if (!string.IsNullOrEmpty(newFileFullPath) && File.Exists(newFileFullPath))
            {
                Singleton.getDialogueBox().showSearch(ConfigurationManager.AppSettings["wait_message"]);
                var ftpCredentials = Bl.BlReferential.searchInfo(new Info {
                    Name = "ftp_"
                }, ESearchOption.AND);

                // closing the image file if opened in the order detail
                if (_main.OrderViewModel != null &&
                    _main.OrderViewModel.OrderDetailViewModel != null &&
                    _main.OrderViewModel.OrderDetailViewModel.Order_ItemModelList != null)
                {
                    var imageFound = _main.OrderViewModel.OrderDetailViewModel.Order_ItemModelList.Where(x => x.TxtItem_ref == SelectedItemModel.TxtRef).Select(x => x.ItemModel.Image).SingleOrDefault();
                    if (imageFound != null)
                    {
                        imageFound.closeImageSource();
                    }
                }

                if (SelectedItemModel.Image != null)
                {
                    SelectedItemModel.Image.closeImageSource();
                    WPFHelper.deleteFileFromFtpServer(ConfigurationManager.AppSettings["ftp_catalogue_image_folder"], SelectedItemModel.TxtPicture, ftpCredentials);
                }
                else
                {
                    SelectedItemModel.Image = await Task.Factory.StartNew(() => { return(SelectedItemModel.Image.downloadPicture(ConfigurationManager.AppSettings["ftp_catalogue_image_folder"], ConfigurationManager.AppSettings["local_catalogue_image_folder"], SelectedItemModel.TxtPicture, SelectedItemModel.TxtRef.Replace(' ', '_').Replace(':', '_'), ftpCredentials)); });
                }

                // opening the file explorer for image file choosing and resizing
                SelectedItemModel.Image.TxtChosenFile = newFileFullPath.resizeImage();
                SelectedItemModel.TxtPicture          = SelectedItemModel.Image.TxtFileName;

                // upload the image file to the FTP server
                SelectedItemModel.Image.uploadImage();

                // update item image
                var savedItemList = await Bl.BlItem.UpdateItemAsync(new List <Item> {
                    SelectedItemModel.Item
                });

                if (savedItemList.Count > 0)
                {
                    await Singleton.getDialogueBox().showAsync("The picture has been saved successfully!");
                }
                else
                {
                    string errorMessage = "Error occured while updating the item [" + SelectedItemModel.TxtRef + "] picture";
                    Log.error(errorMessage, EErrorFrom.ITEM);
                    await Singleton.getDialogueBox().showAsync(errorMessage);
                }

                Singleton.getDialogueBox().IsDialogOpen = false;
            }
        }
Exemplo n.º 4
0
        //----------------------------[ Action Commands ]------------------

        private async void deleteItem(string obj)
        {
            if (await Singleton.getDialogueBox().showAsync("Do you confirm the deletion of the item [" + SelectedItemModel.TxtRef + "] ?"))
            {
                var itemFoundList = Bl.BlItem.searchItem(new Item {
                    Ref = SelectedItemModel.TxtRef, ID = SelectedItemModel.Item.ID
                }, ESearchOption.AND);
                var provider_itemFoundList = Bl.BlItem.searchProvider_item(new Provider_item {
                    ItemId = SelectedItemModel.Item.ID
                }, ESearchOption.AND);
                if (itemFoundList.Count > 0 && itemFoundList[0].Erasable == EItem.Yes.ToString())
                {
                    Singleton.getDialogueBox().showSearch(ConfigurationManager.AppSettings["delete_message"]);
                    await Bl.BlItem.DeleteProvider_itemAsync(provider_itemFoundList);

                    var notSavedItemList = await Bl.BlItem.DeleteItemAsync(new List <Item> {
                        SelectedItemModel.Item
                    });

                    if (notSavedItemList.Count == 0)
                    {
                        if (!string.IsNullOrEmpty(SelectedItemModel.TxtPicture))
                        {
                            var credentials = Bl.BlReferential.searchInfo(new Info {
                                Name = "ftp_"
                            }, ESearchOption.AND);
                            bool isPictureDeleted = WPFHelper.deleteFileFromFtpServer(ConfigurationManager.AppSettings["ftp_catalogue_image_folder"], SelectedItemModel.TxtPicture, credentials);
                            if (!isPictureDeleted)
                            {
                                string errorMessage = "Error occurred while deleting the item [ref=" + SelectedItemModel.TxtRef + "] picture deletion error [" + ConfigurationManager.AppSettings["ftp_catalogue_image_folder"] + "][" + SelectedItemModel.TxtPicture + "].";
                                Log.error(errorMessage, EErrorFrom.ITEM);
                            }
                        }

                        // remove the deleted item from the item list
                        if (_main.ItemViewModel.ItemModelList.Where(x => x.TxtID == SelectedItemModel.TxtID).Count() != 0)
                        {
                            List <ItemModel> buffer = _main.ItemViewModel.ItemModelList;
                            buffer.Remove(SelectedItemModel);

                            // call the property change for UI update
                            _main.ItemViewModel.ItemModelList = new List <ItemModel>(buffer);
                        }
                        await Singleton.getDialogueBox().showAsync("Item deleted successfully!");
                    }
                    else
                    {
                        string errorMessage = "Error occurred while deleting the item [ref=" + SelectedItemModel.TxtRef + "].";
                        Log.error(errorMessage, EErrorFrom.ITEM);
                        await Singleton.getDialogueBox().showAsync(errorMessage);
                    }

                    Singleton.getDialogueBox().IsDialogOpen = false;
                    _page(_main.ItemViewModel);
                }
                else
                {
                    await Singleton.getDialogueBox().showAsync("The Item " + SelectedItemModel.TxtRef + " is used in one or several order!");
                }
            }
        }