示例#1
0
        //public void ImportaCsvArticoli()
        //{
        //    try
        //    {
        //        using (OpenFileDialog res = new OpenFileDialog())
        //        {
        //            res.Title = "Seleziona file da importare";
        //            //Filter
        //            res.Filter = "File csv|*.csv;";

        //            //When the user select the file
        //            if (res.ShowDialog() == DialogResult.OK)
        //            {
        //                //Get the file's path
        //                var fileName = res.FileName;

        //                using (var curs = new CursorManager())
        //                {
        //                    using (StreamReader sr = new StreamReader(fileName, Encoding.Default, true))
        //                    {
        //                        String line;
        //                        bool firstLine = true;
        //                        int progress = 1;
        //                        // Read and display lines from the file until the end of
        //                        // the file is reached.
        //                        using (var uof = new UnitOfWork())
        //                        {
        //                            while ((line = sr.ReadLine()) != null)
        //                            {
        //                                if (!firstLine)
        //                                {
        //                                    progress = ImportLine(line, progress, uof);
        //                                }
        //                                firstLine = false;
        //                            }
        //                            uof.Commit();
        //                        }
        //                    }
        //                }
        //                EventAggregator.Instance().Publish<UpdateList<Articolo>>(new UpdateList<Articolo>(this));
        //                MessageManager.NotificaInfo("Terminata importazione articoli");
        //            }
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        ExceptionManager.ManageError(ex);
        //    }
        //}

        //private int ImportLine(string line, int progress, UnitOfWork uof)
        //{
        //    var dat = line.Split('§');
        //    var cond = enCondizioneArticolo.Nuovo;
        //    if (dat[2] == "N")
        //    {
        //        cond = enCondizioneArticolo.Nuovo;
        //    }
        //    else if (dat[2] == "U")
        //    {
        //        cond = enCondizioneArticolo.UsatoGarantito;
        //    }
        //    else if (dat[2] == "E")
        //    {
        //        cond = enCondizioneArticolo.ExDemo;
        //    }
        //    else
        //    {
        //        throw new Exception("Tipo dato non gestito o mancante nella condizione articolo.");
        //    }
        //    decimal prezzo = 0;
        //    decimal prezzoBarrato = 0;
        //    bool prezzoARichiesta = false;
        //    var strPrezzo = dat[6];
        //    if (strPrezzo == "NC")
        //    {
        //        prezzoARichiesta = true;
        //    }
        //    else if (strPrezzo.Contains(";"))
        //    {
        //        prezzo = decimal.Parse(strPrezzo.Split(';')[0]);

        //    }
        //    else
        //    {
        //        if (strPrezzo.Trim().Length > 0)
        //        {
        //            prezzo = decimal.Parse(strPrezzo);
        //        }
        //    }
        //    var artNew = (new Articolo()
        //    {
        //        CategoriaID = int.Parse(dat[1]),
        //        Condizione = cond,

        //        Titolo = dat[4],
        //        Testo = dat[5].Replace("<br>", Environment.NewLine),
        //        Prezzo = prezzo,


        //    });
        //    artNew.Strumento.Marca = dat[3];
        //    uof.ArticoliRepository.Add(artNew);
        //    var foto = dat[7];
        //    if (foto.Length > 0)
        //    {
        //        int ordine = 0;
        //        foreach (var item in foto.Split(';'))
        //        {
        //            var artFoto = new FotoArticolo()
        //            {
        //                Articolo = artNew,
        //                UrlFoto = item,
        //                Ordine = ordine
        //            };
        //            ordine++;
        //            uof.FotoArticoloRepository.Add(artFoto);
        //        }
        //    }

        //    return progress;
        //}

        private void DeleteArticolo(object obj)
        {
            try
            {
                if (!MessageManager.QuestionMessage("Sei sicuro di voler cancellare l'articolo selezionato?"))
                {
                    return;
                }
                using (var save = new SaveEntityManager())
                {
                    using (var immaginiController = new ControllerImmagini())
                    {
                        var item = save.UnitOfWork.ArticoliRepository.Find(a => a.ID ==
                                                                           this.SelectedItem.ID).FirstOrDefault();
                        _logger.Info(string.Format("Cancellazione articolo /r/n{0} /r/n{1}", item.Titolo, item.ID));

                        if (!immaginiController.CheckFolderImmagini())
                        {
                            return;
                        }

                        var folderFoto = SettingSitoValidator.ReadSetting().CartellaLocaleImmagini;
                        var listFile   = new List <string>();
                        foreach (var itemFoto in save.UnitOfWork.FotoArticoloRepository.Find(a => a.ArticoloID == item.ID))
                        {
                            immaginiController.RimuoviItemDaRepo(
                                folderFoto, listFile, save.UnitOfWork, itemFoto);
                        }
                        immaginiController.DeleteFile(listFile);
                        var mag = save.UnitOfWork.MagazzinoRepository.Find(a => a.ArticoloID == item.ID);
                        foreach (Magazzino itemMg in mag)
                        {
                            save.UnitOfWork.MagazzinoRepository.Delete(itemMg);
                        }
                        foreach (var itemAgg in save.UnitOfWork.AggiornamentoWebArticoloRepository.Find(a => a.ArticoloID == item.ID))
                        {
                            save.UnitOfWork.AggiornamentoWebArticoloRepository.Delete(itemAgg);
                        }

                        save.UnitOfWork.ArticoliRepository.Delete(item);

                        if (save.SaveEntity(enSaveOperation.OpDelete))
                        {
                            EventAggregator.Instance().Publish <UpdateList <Articolo> >(new UpdateList <Articolo>(this));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.ManageError(ex);
            }
        }
示例#2
0
        public override void Dispose()
        {
            base.Dispose();

            EventAggregator.Instance().UnSbscribe(sub11);
            EventAggregator.Instance().UnSbscribe(sub10);
            EventAggregator.Instance().UnSbscribe(sub1);
            EventAggregator.Instance().UnSbscribe(sub2);
            EventAggregator.Instance().UnSbscribe(sub3);
            EventAggregator.Instance().UnSbscribe(sub4);
            EventAggregator.Instance().UnSbscribe(sub5);
            EventAggregator.Instance().UnSbscribe(sub6);
            EventAggregator.Instance().UnSbscribe(sub8);

            EventAggregator.Instance().UnSbscribe(_orderImage);
            EventAggregator.Instance().UnSbscribe(_subAddImage);

            _controllerImmagini.Dispose();
            _controllerImmagini = null;
        }