Example #1
0
        public LicConfig()
        {
            XmlSerializer serializerlic = new XmlSerializer(typeof(LicencjaClass));

            try
            {
                LicOk = true;
                StreamReader readerbaza = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "Lic.ihp");
                string       ToDecrypt  = readerbaza.ReadToEnd();
                var          TextBody   = Krypto.Decrypt(ToDecrypt);

                var serializer = new XmlSerializer(typeof(LicencjaClass));
                using (var reader = new StringReader(TextBody))
                {
                    UstawieniaLicencji = (LicencjaClass)serializer.Deserialize(reader);
                    if (UstawieniaLicencji != null)
                    {
                        NIP = UstawieniaLicencji.Firma.NIP;
                    }
                    NAZWAFIRMY = UstawieniaLicencji.Firma.Nazwa;
                }
                //    UstawieniaLicencji = (LicencjaClass)serializerlic.Deserialize(readerbaza);
                readerbaza.Close();
            }
            catch (Exception ex)
            {
                LicOk = false;
                //throw ex;
            }
        }
Example #2
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);
        }
        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;
                    }
                }
            }
        }