Exemple #1
0
 public FrmLicenceInvalide()
 {
     InitializeComponent();
     lblVersion.Text = Version;
     Icon            = Properties.Resources.log22;
     txtCode.Text    = GeneratorCode.Value();
     lbTunis.Text    = "Golden Estates-9 ème étage App D7-D8 - Centre Urbain Nord-1082 Tunis Tunisie";
     lbSfax.Text     = "Route Gabes, Km3 Immeuble SOTEME 1er étage-3052 Sfax Tunisie";
     lbTel.Text      = " +216 71 428 073";
     lbFax.Text      = " +216 71 428 135";
     lbEmail.Text    = " [email protected]";
 }
        static void Main(string[] args)
        {
            //Dossier Application data
            var dossierName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                                           Application.ProductName);

            if (!Directory.Exists(dossierName))
            {
                Directory.CreateDirectory(dossierName);
            }

            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("fr-FR");
            // Add the event handler for handling UI thread exceptions to the event.
            Application.ThreadException += ThreadException;
            // Set the unhandled exception mode to force all Windows Forms errors to go through our handler.
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            // Add the event handler for handling non-UI thread exceptions to the event.
            AppDomain.CurrentDomain.UnhandledException += UnhandledException;

            BonusSkins.Register();
            SkinManager.EnableFormSkins();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            string path = args.Length != 0 ? args[0] : string.Empty;


//#if DEBUG
//            IsMultiSociete = true;
//#else
            // determinition code hardware du pc actuel
            var codePc = GeneratorCode.Value();

            // verification de la license
            try
            {
                var publicKey = File.ReadAllText("publicKey.xml");
                var validator = new LicenseValidator(publicKey, "lic.tvs", false);
                validator.AssertValidLicense();
                if (validator.Name != codePc)
                {
                    throw new ApplicationException("Licence invalide!");
                }
                var attribute = validator.LicenseAttributes;
                IsMultiSociete = attribute["MultiSocite"] == "0";
                IsCnss         = attribute["Cnss"] == "0";
                IsDecBc        = attribute["BcSuspension"] == "0";
                IsDecFc        = attribute["FcSuspension"] == "0";
                IsEmp          = attribute["Employeur"] == "0";
                IsVirement     = attribute["Virement"] == "0";
                Societe        = attribute["Societe"];
                DateExpiration = validator.ExpirationDate;
                IsLiasse       = attribute["Liasse"] == "0";
                // IsCovis = attribute["Covis"] == "0";
            }
            catch (LicenseFileNotFoundException e)
            {
                XtraMessageBox.Show("Fichier de licence introuvable");
                new FrmLicenceInvalide().ShowDialog();
                return;
            }
            catch (LicenseExpiredException e)
            {
                XtraMessageBox.Show("Licence expirée");
                new FrmLicenceInvalide().ShowDialog();
                return;
            }
            catch (Exception e)
            {
                XtraMessageBox.Show(e.Message);
                new FrmLicenceInvalide().ShowDialog();
                return;
            }
            //#endif


            // init Ninject dependencies resolver
            Kernel = new StandardKernel();
            Kernel.Bind <IUserControlFactory>().ToFactory().InSingletonScope();
            Kernel.Bind <IFormFactory>().ToFactory().InSingletonScope();

            Kernel.Bind <AppConfiguration>()
            .ToSelf()
            .InSingletonScope();


            Kernel.Bind <IConfigurationRepository <GroupConfiguration> >()
            .To <GroupConfigurationRepository>()
            .InSingletonScope();

            // check configs (connection ...)
            // get configs / connection to `Groupe`
            // should return a valid connection
            var appConfig = Kernel.Get <AppConfiguration>();
            GroupConfiguration groupeConfig = appConfig.Load(path);

            if (!string.IsNullOrEmpty(path))
            {
                try
                {
                    appConfig.Load(path);
                }
                catch (Exception ex)
                {
                    XtraMessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            if (groupeConfig == null)
            {
                XtraMessageBox.Show("Configuration invalide!");
                // demarrer la fenetre principale
                //var frm = new FrmNouveauFichier(appConfig);
                //frm.ShowDialog();
                return;
            }
            // RebindGroupConnection(groupeConfig);


            Application.SetCompatibleTextRenderingDefault(false);
            var main                = Kernel.Get <FrmMain>();
            var service             = GetService();
            var frmAuthentification = new FrmOuverture(service);

            if (frmAuthentification.ShowDialog() != DialogResult.Yes)
            {
                return;
            }
            Context = new CommandContext
            {
                MainForm           = main,
                Container          = InitializeContainer(),
                Exercice           = service.Exercice,
                Societe            = service.Societe,
                User               = service.User,
                ConnectionProvider = Kernel.Get <IConnectionProvider>()
            };

            // demarrer la fenetre principale
            Application.Run(Context.MainForm);
            //   Application.Run(new XtraForm1());
        }