예제 #1
0
        public CheckoutProfileManagerViewModel()
        {
            AddNew = new DelegateCommand(parameter =>
            {
                CheckoutProfileEditor editor = null;
                CheckoutProfile profile      = new CheckoutProfile();

                while (true)
                {
                    editor = new CheckoutProfileEditor()
                    {
                        DataContext = new CheckoutProfileEditViewModel()
                        {
                            Model = profile
                        }
                    };

                    if (editor.ShowDialog() ?? false)
                    {
                        if (m_model.Where(p => p.Name == profile.Name).ToList().Count == 0)
                        {
                            m_model.Add(profile);

                            break;
                        }

                        MessageBox.Show($"Checkout profile name {profile.Name} is busy. Choose another name, please.", "Duplication", MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                    else
                    {
                        break;
                    }
                }
            });

            Edit = new DelegateCommand(parameter =>
            {
                CheckoutProfile originalProfile = SelectedProfiles[0].Model;
                CheckoutProfile profile         = new CheckoutProfile(originalProfile);

                while (true)
                {
                    CheckoutProfileEditor editor = new CheckoutProfileEditor()
                    {
                        DataContext = new CheckoutProfileEditViewModel()
                        {
                            Model = profile
                        }
                    };

                    if (editor.ShowDialog() ?? false)
                    {
                        List <CheckoutProfile> dupList = m_model.Where(p => p.Name == profile.Name).ToList();

                        if (dupList.Count == 0 || dupList[0] == originalProfile)
                        {
                            profile.CopyTo(originalProfile);
                            break;
                        }

                        MessageBox.Show(
                            $"Checkout profile name {profile.Name} is busy. Choose another name, please.",
                            "Duplication", MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                    else
                    {
                        break;
                    }
                }
            },
                                       parameter => SelectedProfiles.Count == 1);

            Duplicate = new DelegateCommand(parameter =>
            {
                CheckoutProfileEditor editor = null;
                CheckoutProfile profile      = new CheckoutProfile(SelectedProfiles[0].Model);

                while (true)
                {
                    editor = new CheckoutProfileEditor()
                    {
                        DataContext = new CheckoutProfileEditViewModel()
                        {
                            Model = profile
                        }
                    };

                    if (editor.ShowDialog() ?? false)
                    {
                        if (m_model.Where(p => p.Name == profile.Name).ToList().Count == 0)
                        {
                            m_model.Add(profile);

                            break;
                        }

                        MessageBox.Show($"Checkout profile name {profile.Name} is busy. Choose another name, please.", "Duplication", MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                    else
                    {
                        break;
                    }
                }
            },
                                            parameter => SelectedProfiles.Count == 1);

            Delete = new DelegateCommand(parameter =>
            {
                foreach (CheckoutProfileRecordViewModel profile in SelectedProfiles.ToList())
                {
                    m_model.Remove(profile.Model);
                }
            },
                                         parameter => SelectedProfiles.Count > 0);

            Import = new DelegateCommand(parameter =>
            {
                OpenFileDialog openFIleDialog = new OpenFileDialog()
                {
                    DefaultExt = ".csv",
                    Filter     = "CSV files (.csv)|*.csv"
                };

                if (openFIleDialog.ShowDialog() ?? false)
                {
                    using (StreamReader reader = new StreamReader(openFIleDialog.FileName))
                    {
                        int lineCount = 0;
                        bool isOk     = true;
                        while (!reader.EndOfStream)
                        {
                            string[] profileParameters = reader.ReadLine().Split(new char[] { ';' });

                            CheckoutProfile profile = null;

                            try
                            {
                                profile = new CheckoutProfile()
                                {
                                    Name           = profileParameters[0],
                                    Email          = profileParameters[1],
                                    BillingAddress = new Address()
                                    {
                                        FirstName          = profileParameters[2],
                                        SecondName         = profileParameters[3],
                                        StreetAddress1     = profileParameters[4],
                                        StreetAddressLine2 = profileParameters[5],
                                        PostalCode         = profileParameters[6],
                                        City        = profileParameters[7],
                                        State       = CountriesCollection.Countries[(CountryCode)int.Parse(profileParameters[9])].States.ElementAtOrDefault(int.Parse(profileParameters[8])),
                                        Country     = CountriesCollection.Countries[(CountryCode)int.Parse(profileParameters[9])],
                                        PhoneNumber = profileParameters[25]
                                    },
                                    ShippingAddress = new Address()
                                    {
                                        FirstName          = profileParameters[10],
                                        SecondName         = profileParameters[11],
                                        StreetAddress1     = profileParameters[12],
                                        StreetAddressLine2 = profileParameters[13],
                                        PostalCode         = profileParameters[14],
                                        City        = profileParameters[15],
                                        State       = CountriesCollection.Countries[(CountryCode)int.Parse(profileParameters[17])].States.ElementAtOrDefault(int.Parse(profileParameters[16])),
                                        Country     = CountriesCollection.Countries[(CountryCode)int.Parse(profileParameters[17])],
                                        PhoneNumber = profileParameters[26]
                                    },
                                    IsShippingAsBilling = bool.Parse(profileParameters[18]),
                                    PayCard             = new PayCard()
                                    {
                                        Number         = profileParameters[19],
                                        Holder         = profileParameters[20],
                                        ExpirationDate = DateTime.ParseExact(profileParameters[21], "O",
                                                                             CultureInfo.InvariantCulture),
                                        CVS  = profileParameters[22],
                                        Type = PayCardTypeCollection.TypesDictionary[(PayCardTypeCode)int.Parse(profileParameters[23])]
                                    },
                                    BuyLimit = int.Parse(profileParameters[24])
                                };
                            }
                            catch (Exception e)
                            {
                                isOk = false;
                                break;
                            }

                            if (m_model.Where(p => p.Name == profile.Name).ToList().Count == 0)
                            {
                                m_model.Add(profile);
                            }

                            lineCount++;
                        }

                        if (!isOk)
                        {
                            MessageBox.Show($"Wrong format at line {lineCount + 1}");
                        }

                        reader.Close();
                    }
                }
            });

            Export = new DelegateCommand(parameter =>
            {
                SaveFileDialog saveFileDialog = new SaveFileDialog
                {
                    DefaultExt = ".csv",
                    Filter     = "CSV files (.csv)|*.csv"
                };

                if (saveFileDialog.ShowDialog() ?? false)
                {
                    using (StreamWriter writer = new StreamWriter(saveFileDialog.FileName))
                    {
                        foreach (CheckoutProfileRecordViewModel profileVM in Profiles)
                        {
                            CheckoutProfile profile = profileVM.Model;
                            writer.WriteLine($"{profile.Name};{profile.Email};{profile.BillingAddress.FirstName};" +
                                             $"{profile.BillingAddress.SecondName};{profile.BillingAddress.StreetAddress1};" +
                                             $"{profile.BillingAddress.StreetAddressLine2};{profile.BillingAddress.PostalCode};" +
                                             $"{profile.BillingAddress.City};{profile.BillingAddress.Country.States.IndexOf(profile.BillingAddress.State)};" +
                                             $"{(int)profile.BillingAddress.Country.Code};" +
                                             $"{profile.ShippingAddress.FirstName};" +
                                             $"{profile.ShippingAddress.SecondName};{profile.ShippingAddress.StreetAddress1};" +
                                             $"{profile.ShippingAddress.StreetAddressLine2};{profile.ShippingAddress.PostalCode};" +
                                             $"{profile.ShippingAddress.City};{profile.ShippingAddress.Country.States.IndexOf(profile.ShippingAddress.State)};" +
                                             $"{(int)profile.ShippingAddress.Country.Code};" +
                                             $"{profile.IsShippingAsBilling};{profile.PayCard.Number};{profile.PayCard.Holder};" +
                                             $"{profile.PayCard.ExpirationDate.Value.ToString("O")};{profile.PayCard.CVS};{(int)PayCardTypeCollection.TypesDictionary.First(p => p.Value == profile.PayCard.Type).Key};" +
                                             $"{profile.BuyLimit};{profile.BillingAddress.PhoneNumber};{profile.ShippingAddress.PhoneNumber};");
                        }

                        writer.Close();
                    }
                }
            },
                                         parameter => Profiles.Count > 0);
        }
예제 #2
0
        /// <summary>
        /// Checkout di un documento
        /// </summary>
        /// <param name="checkOutStatus">Metadati relativi allo stato del documento in checkout</param>
        /// <param name="user"></param>
        /// <param name="library"></param>
        /// <returns></returns>
        public bool CheckOut(string idDocument, string documentNumber, string documentLocation, string machineName, out CheckOutStatus checkOutStatus)
        {
            checkOutStatus = null;

            // Determina se il documento da bloccare è di tipo stampa registro
            bool isStampaRegistro = (DocsPaQueryHelper.isStampaRegistro(documentNumber));

            bool retValue = this.SaveCheckOutDocumentProperties(string.Empty, documentNumber, documentLocation, machineName);

            try
            {
                if (retValue)
                {
                    ObjectIdentity identity = null;

                    // Reperimento identity del documento da bloccare
                    if (isStampaRegistro)
                    {
                        identity = Dfs4DocsPa.getDocumentoStampaRegistroIdentityByDocNumber(documentNumber);
                    }
                    else
                    {
                        identity = Dfs4DocsPa.getDocumentoIdentityByDocNumber(documentNumber);
                    }

                    ObjectIdentitySet identitySet = new ObjectIdentitySet();
                    identitySet.Identities.Add(identity);

                    OperationOptions opts = null;

                    if (DocsPaQueryHelper.getCountAllegati(idDocument) > 0)
                    {
                        // Se il documento contiene allegati, è sicuramente un virtual document
                        CheckoutProfile checkOutProfile = new CheckoutProfile();

                        // Ulteriore verifica se il documento è un allegato o un documento principale
                        checkOutProfile.CheckoutOnlyVDMRoot = !DocsPaQueryHelper.isAllegatoProfilato(documentNumber);

                        opts = new OperationOptions();
                        opts.CheckoutProfile = checkOutProfile;
                    }

                    IVersionControlService service     = this.GetServiceInstance <IVersionControlService>(false);
                    DataPackage            dataPackage = service.Checkout(identitySet, opts);

                    // Reperimento ObjectId della versione in checkout
                    ObjectId objectId = (ObjectId)dataPackage.DataObjects[0].Identity.Value;
                    checkOutStatus = this.GetCheckOutStatus(objectId.Id, idDocument, documentNumber);

                    //if (DocsPaQueryHelper.getCountAllegati(idDocument) > 0)
                    //{
                    //    // Workaround per gli allegati
                    //    this.UndoCheckOutAllegati(documentNumber);
                    //}

                    retValue = true;

                    logger.Debug(string.Format("Documentum.CheckOut: effettuato il checkout del documento con id {0} e docnumber {1}", idDocument, documentNumber));
                }
            }
            catch (Exception ex)
            {
                retValue = false;

                logger.Debug("Errore in Documentum.CheckOut: " + ex.ToString());
            }

            return(retValue);
        }