Пример #1
0
        private void Info_Paint(object sender, PaintEventArgs e)
        {
            var waitingForm = new WaitingForm(update)
            {
                Text        = TabloidWizard.Properties.Resources.Chargement,
                progressBar = { Style = ProgressBarStyle.Marquee }
            };

            waitingForm.Wr.RunWorkerAsync(new object[] { metroGrid1 });

            waitingForm.ShowDialog();

            metroGrid1.DataSource = _dt;
            metroGrid1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);

            metroGrid1.Columns[2].Width = 50;
        }
Пример #2
0
        private void Analyse()
        {
            try
            {
                var _wf = new WaitingForm(Analyse)
                {
                    Text        = Properties.Resources.Analysing,
                    progressBar = { Style = ProgressBarStyle.Marquee }
                };

                _results = new List <TableAnalysisResult>();
                _wf.Wr.RunWorkerAsync(_results);
                _wf.ShowDialog();

                displayResult();
            }
            catch (Exception ex)
            {
                MetroMessageBox.Show(this, Properties.Resources.AnalyseError, Properties.Resources.Erreur, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #3
0
        private void cmbVisibility_SelectedIndexChanged(object sender, EventArgs e)
        {
            Visibilites v;

            Enum.TryParse <Visibilites>(cmbVisibility.SelectedValue.ToString(), out v);

            var waitingForm = new WaitingForm(update)
            {
                Text        = Properties.Resources.Chargement,
                progressBar = { Style = ProgressBarStyle.Marquee }
            };



            waitingForm.Wr.RunWorkerAsync(new object[] { v, _view.Nom, _connectionString });

            waitingForm.ShowDialog();

            dataGrid1.DataSource = _dt;

            dataGrid1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
        }
Пример #4
0
        void Button_end(object sender, PageEventArgs e)
        {
            var schema = txtSchema.Text == "" ? "public" : txtSchema.Text;
            var importdestinationPath = "";
            var isMySql = cmbType.SelectedIndex == 0;

            string[] param = { txtHote.Text, txtUtil.Text, txtMdp.Text, txtBase.Text, schema };

            var mainConn = new ConnectionProperties
            {
                Host       = txtHote.Text,
                User       = txtUtil.Text,
                Password   = txtMdp.Text,
                Database   = txtBase.Text,
                SearchPath = new string[] { schema, "public" }
            };

            //var connectionString = cmbType.SelectedIndex == 0
            //    ? string.Format("Datasource={0};uid={1};pwd={2};", param)
            //    : string.Format("User ID={1};Password={2};Host={0};Port=5432;Database={3};SearchPath={4},public;", param);

            var tempPath = Path.GetTempPath() + Guid.NewGuid();// used for import only



            if (Program.AppSet == null)
            {
                Program.AppSet = new AppSetting(); //if no default properties
            }
            if (_fromImport)                       //unzip file to temp file and load exported config
            {
                // select file to import
                var fd = new OpenFileDialog
                {
                    Title = Resources.SelectImportFile,

                    CheckFileExists = true,
                    CheckPathExists = true,

                    DefaultExt       = "twz",
                    Filter           = "twz files (*.twz)|*.twz",
                    FilterIndex      = 2,
                    RestoreDirectory = true,

                    ReadOnlyChecked = true,
                    ShowReadOnly    = true
                };

                var result = fd.ShowDialog();
                if (result != DialogResult.OK)
                {
                    return;
                }

                // select destination folder

                var folderDlg = new FolderBrowserDialog
                {
                    Description         = "Selectionnez le répertoire de destination du sit web",
                    ShowNewFolderButton = true
                };

                result = folderDlg.ShowDialog();
                if (result != DialogResult.OK)
                {
                    return;
                }

                importdestinationPath = folderDlg.SelectedPath;


                _waitingForm = new WaitingForm(PrepareImportWorker)
                {
                    Text        = Resources.ImportPrepare,
                    progressBar = { Style = ProgressBarStyle.Marquee }
                };

                _waitingForm.Wr.RunWorkerAsync(new object[] { fd.FileName, tempPath });

                _waitingForm.ShowDialog();

                mainConn.SearchPath = new string[] { Program.AppSet.Schema, "public" };
            }

            //set app setting parameter

            if (!_fromImport)
            {
                Program.AppSet.Titre = cmbType.SelectedIndex == 0 ? txtBase.Text : schema;
            }

            Program.AppSet.ConnectionString = mainConn.GetConnectionString(isMySql);//connectionString;
            Program.AppSet.ProviderType     = cmbType.SelectedIndex == 0 ? Provider.MySql : Provider.Postgres;

            Program.AppSet.identParam = cmbType.SelectedIndex == 0 ? "?" : "@";
            Program.AppSet.sqlDebug   = "oui";

            Tools.SetDefaultProviderFromAppSet();

            SqlCommands.Provider = cmbType.SelectedIndex == 0 ? Provider.MySql : Provider.Postgres;

            //for postgres verify database exist if not create
            if (Program.AppSet.ProviderType == Provider.Postgres)
            {
                var cs = string.Format("User ID={1};Password={2};Host={0};Port=5432;", param);
                if (!dbExist(txtBase.Text, cs))
                {
                    if (MetroMessageBox.Show(this, Resources.DataBaseNotExist, Resources.Erreur, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Error)
                        != DialogResult.Yes)
                    {
                        return;
                    }
                    dbCreate(txtBase.Text, cs);
                }
            }


            //Add schema to database

            if (!_fromImport && (Program.AppSet.ProviderType == Provider.Postgres && schemaExist(schema)))
            {
                string err;

                if (MetroMessageBox.Show(this, Resources.SchemaAlreadyExist, Resources.Erreur, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Error)
                    != DialogResult.Yes)
                {
                    return;
                }

                if (MetroMessageBox.Show(this, Resources.ConfirmDelete, Resources.Confirmation, MessageBoxButtons.YesNo, MessageBoxIcon.Question)
                    != DialogResult.Yes)
                {
                    return;
                }

                DataTools.Command($"DROP SCHEMA {schema} CASCADE;", null, Program.AppSet.ConnectionString, out err);

                if (!string.IsNullOrEmpty(err))
                {
                    MetroMessageBox.Show(this, string.Format(Resources.ErrorMessage, err), Resources.Erreur, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            var connectionString = mainConn.GetConnectionString(isMySql);

            if (!_fromImport)
            {
                Program.AppSet.Schema = schema;
            }

            if (Program.AppSet.ProviderType == Provider.Postgres)
            {//postgres
                param    = new string[] { txtSchema.Text };
                e.Cancel = !WizardSQLHelper.ExecuteFromFile("schema.sql", param, connectionString, this);
                if (e.Cancel)
                {
                    return;          // stop on sql error
                }
            }
            else
            {//mysql
                param    = new string[] { txtBase.Text };
                e.Cancel = !WizardSQLHelper.ExecuteFromFile("schema.sql", param, mainConn.GetConnectionString(isMySql), this);
                if (e.Cancel)
                {
                    return;          // stop on sql error
                }
                Program.AppSet.ConnectionString = connectionString + "Database=" + txtBase.Text + ";";;
            }

            // add tabloid table to database
            try
            {
                if (_fromImport)//unzip file to temp file and load exported config
                {
                    _waitingForm = new WaitingForm(ImportWorker)
                    {
                        Text        = Resources.dbImport,
                        progressBar = { Style = ProgressBarStyle.Marquee }
                    };

                    var conn = new ConnectionProperties
                    {
                        Host     = txtHote.Text,
                        Port     = "5432",
                        User     = txtUtil.Text,
                        Password = txtMdp.Text,
                        Database = txtBase.Text
                    };

                    _waitingForm.Wr.RunWorkerAsync(new object[] { tempPath, conn, importdestinationPath });

                    _waitingForm.ShowDialog();
                }
                else
                if (!TabloidTables.CreateTable(TabloidTables.TabloidTablesArray, connectionString, this))//create tabloid table in base
                {
                    return;
                }
            }
            catch (Exception ex)
            {
                MetroMessageBox.Show(this, ex.ToString(), Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            //add user
            if (_fromImport)
            {
                var utilFrm = new UtilEditor();

                utilFrm.btnCancel.Enabled     = false;
                utilFrm.cmbAuth.SelectedIndex = 1;
                utilFrm.cmbAuth.Enabled       = false;

                if (utilFrm.ShowDialog() == DialogResult.OK)//for user table need to ask for user 0
                {
                    TabloidConfig.Config.updateCurrentKey(Program.AppSet.grainDeSable);
                    var keyParam = GenericParameter.Get("id_utilisateur", DbType.Int32, null);
                    var sql      = $"INSERT INTO utilisateurs(logon, nom, prenom, mail, password, auteur_utilisateurs, datemaj_utilisateurs, deleted_utilisateurs, debutsession, finsession) VALUES('{utilFrm.txtLogin.Text}', '{utilFrm.txtNom.Text}', '{utilFrm.txtPrenom.Text}', '{utilFrm.txtMail.Text}', '{Tabloid.Classes.Tools.SecurityHelper.EncryptPassword(utilFrm.txtMdp1.Text)}', NULL, NULL, 0, now(), NULL)";
                    sql = sql + string.Format(SqlConverter.GetSql(SqlConverter.SqlType.InsertCommandKeyOut), "id_utilisateur");

                    var id = DataTools.ScalarCommand(sql, new[] { keyParam }, mainConn.GetConnectionString(isMySql));

                    sql = $"INSERT INTO lst_roles(utilisateurs_id, roles_id) VALUES({id}, 1);";

                    DataTools.Command(sql, null, mainConn.GetConnectionString(isMySql));
                }
            }
            else
            {
                //open project properties form
                Tools.EditSetting(_configFiles);
            }
        }