示例#1
0
        public void Zapisz()
        {
            string TextBody = string.Empty;
            // Create a new Serializer
            XmlSerializer serializer = new XmlSerializer(typeof(LicencjaClass));

            using (StringWriter textWriter = new StringWriter())
            {
                serializer.Serialize(textWriter, UstawieniaLicencji);
                TextBody = textWriter.ToString();
            }
            string cruptobody = Krypto.Encrypt(TextBody);

            System.IO.File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "Lic.ihp", cruptobody);
        }
示例#2
0
        public void ZaczytajPlik()
        {
            string fileName = OpenFileService.Show();

            if (string.IsNullOrEmpty(fileName))
            {
                return;
            }
            LicConfig lic = LicConfig.GetInstance;

            lic.ZaczytajNowa(fileName);
            LicencjaClass licust = lic.UstawieniaLicencji;

            if (licust != null)
            {
                NAZWAFIRMY = licust.Firma.Nazwa;
                NIP        = licust.Firma.NIP;
                string krypto = Krypto.Encrypt(NAZWAFIRMY + NIP);

                IHP_PARAMETRY ihp = context.IHP_PARAMETRY?.FirstOrDefault(x => x.ID_IHP_PARAMETRY == 0);
                if (ihp != null)
                {
                    try
                    {
                        krypto      = krypto.Substring(1, 35);
                        ihp.WARTOSC = krypto;
                        context.IHP_PARAMETRY.Attach(ihp);
                        context.Entry(ihp).State = EntityState.Modified;
                        context.SaveChanges();
                        lic.Zapisz();
                    }
                    catch (DbEntityValidationException e)
                    {
                        foreach (var eve in e.EntityValidationErrors)
                        {
                            LogManager.WriteLogMessage(LogManager.LogType.Error, String.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State));
                            foreach (var ve in eve.ValidationErrors)
                            {
                                LogManager.WriteLogMessage(LogManager.LogType.Error, String.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage));
                            }
                        }
                        //throw;
                    }
                }
            }
        }