예제 #1
0
        private void btn_Click(object sender, EventArgs e)
        {
            var error = false;

            progressBar1.Maximum = 100;
            progressBar1.Value   = 0;

            var schema = txtSchema.Text == "" ? "public" : txtSchema.Text;

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

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

            Program.AppSet = new AppSetting
            {
                ConnectionString = connectionString,
                ProviderType     = cmbType.SelectedIndex == 0 ? Provider.MySql : Provider.Postgres,
                Titre            = txtBase.Text,
                identParam       = cmbType.SelectedIndex == 0 ? "?" : "@",
                sqlDebug         = "oui"
            };

            Tools.SetDefaultProviderFromAppSet();

            lblState.Text = Resources.NewFromBaseForm_btn_Click_Récupération_des_Tables;
            lblState.Refresh();

            SqlCommands.Provider  = cmbType.SelectedIndex == 0 ? Provider.MySql : Provider.Postgres;
            Program.AppSet.Schema = schema;

            string lastError;

            var dt = DataTools.Data(SqlCommands.SqlGetTable(), connectionString, out lastError);

            if (dt == null)
            {
                MetroMessageBox.Show(this, Resources.NewFromBaseForm_btn_Click_ + lastError, Resources.Erreur,
                                     MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!string.IsNullOrEmpty(lastError))
            {
                lblState.Text = lastError;
                error         = true;
            }
            else
            {
                TabloidConfig.Config = new TabloidConfig();

                TabloidConfig.Config.TabloidConfigApp.UseLockDatabaseField = chkLockInDB.Checked;

                var avt = new ArrayVerify();

                var config = new BuildFromBase.BaseImporterConfig
                {
                    RemoveTableName    = chkSuppNomTable.Checked,
                    ToUpperCase        = chkCasse.Checked,
                    ReplaceUnderscrore = chkUnderscrore.Checked,

                    ConnectionString = connectionString
                };

                if (dt.Rows.Count > 0)
                {
                    TabloidFields.TabloidFieldsArray = null;
                    //Program.AppSet.pageDefaut = "/tabloid/BSliste.aspx?table=" +
                    AppSetting.setDefaultPage(dt.Rows[0][0].ToString());
                    var delta = 100 / dt.Rows.Count;

                    //read Tables
                    foreach (DataRow dtr in dt.Rows)
                    {
                        progressBar1.Value += delta;
                        progressBar1.Refresh();

                        var dtName = dtr[0].ToString();

                        var tableConfig = new TabloidConfigView();

                        try
                        {
                            BuildFromBase.GetTable(this, dtName, schema, ref tableConfig, ref avt, config);
                            TabloidConfig.Config.Views.Add(tableConfig);
                        }
                        catch (Exception ex)
                        {
                            lblState.Text = ex.ToString();
                        }
                    }

                    if (error)
                    {
                        return;
                    }
                }

                //verify tabloid table existance
                if (!avt.IsThereAll(TabloidTables.TabloidTablesArray.Count()))
                {
                    var l = avt.NotInIndex(TabloidTables.TabloidTablesArray.Count()); //list unaviable tables
                    var r = DialogResult.Yes;

                    if (!chkAutoTable.Checked)
                    {
                        //Show message
                        var strCh = string.Join("\n\t- ",
                                                TabloidTables.TabloidTablesArray
                                                .Where((f, index) => l.Any(i => i == index))
                                                .Select((x, index) => x.Name).ToArray());

                        r = MetroMessageBox.Show(this,
                                                 string.Format(
                                                     Resources.NewFromBaseForm_tables_inutiles,
                                                     strCh),
                                                 Resources.Information,
                                                 MessageBoxButtons.YesNo,
                                                 MessageBoxIcon.Exclamation);
                    }

                    if (r == DialogResult.Yes)
                    {
                        var toCreate = TabloidTables.TabloidTablesArray
                                       .Where((f, index) => l.Any(i => i == index))
                                       .ToList();

                        TabloidTables.CreateTable(
                            toCreate, connectionString, this);

                        foreach (var t in toCreate)// table to config
                        {
                            var tableConfig = new TabloidConfigView();
                            try {
                                BuildFromBase.GetTable(this, t.Name, schema, ref tableConfig, ref avt, config);
                                TabloidConfig.Config.Views.Add(tableConfig);
                            }
                            catch (Exception ex)
                            {
                                lblState.Text = ex.ToString();
                            }
                        }
                    }
                }

                OlStyleCollection.olStyles = new List <OlStyle>();

                DialogResult = DialogResult.OK;
                Close();
            }
        }
예제 #2
0
        /// <summary>
        /// verify tabloid table aviability
        /// </summary>
        /// <param name="tableName">table to search</param>
        /// <param name="schema"></param>
        /// <param name="tableConfig"></param>
        /// <param name="avt"></param>
        /// <param name="connectionString"></param>
        /// <returns></returns>
        public static bool GetTable(IWin32Window own, string tableName, string schema, ref TabloidConfigView tableConfig, ref ArrayVerify avt, BaseImporterConfig config)
        {
            var indexTable = TabloidTables.IsTabloidTable(tableName, ref avt);
            var toShow     = indexTable == -1;

            if (!toShow)                                                       //this is a tabloid table
            {
                toShow = !TabloidTables.TabloidTablesArray[indexTable].Hidden; //for tabloid table verify hidden propertie
            }
            if (toShow)                                                        //this is not a tabloid table
            {
                tableConfig        = new TabloidConfigView();
                tableConfig.Nom    = tableConfig.Titre = tableName;
                tableConfig.Titre  = ModifyTitle(tableConfig.Titre, tableName, config);
                tableConfig.Schema = schema;

                string lastError;

                var dc = DataTools.Data(SqlCommands.SqlGetColums(tableName), config.ConnectionString, out lastError);//013

                if (!string.IsNullOrEmpty(lastError))
                {
                    throw new Exception(lastError);
                    //lblState.Text = lastError;
                    return(false);
                }
                //read Fields
                var avc  = new ArrayVerify();
                var cmpt = 0;

                foreach (DataRow dcr in dc.Rows)
                {
                    cmpt++;

                    if (TabloidFields.IstabloidField(dcr[0].ToString(), ref avc) == -1)
                    {
                        var colonneConfig = new TabloidConfigColonne();

                        if (dcr[3].ToString().StartsWith("PRI", StringComparison.InvariantCulture))
                        {
                            tableConfig.DbKey = dcr[0].ToString();
                        }
                        else
                        {
                            colonneConfig.Nom   = "C" + cmpt;
                            colonneConfig.Champ = colonneConfig.Titre = dcr[0].ToString();

                            colonneConfig.Titre = ModifyTitle(colonneConfig.Titre, tableName, config);



                            colonneConfig.Type = dataHelper.DbTypeConverter.Convert(dcr[1].ToString(), SqlCommands.Provider.ToString());

                            tableConfig.Colonnes.Add(colonneConfig);
                        }
                    }
                }

                if (!avc.IsThereAll(TabloidFields.TabloidFieldsArray.Count()))        //is all tabloid field there?
                {
                    var l = avc.NotInIndex(TabloidFields.TabloidFieldsArray.Count()); //list unaviable fields
                    var r = DialogResult.Yes;

                    if (!config.CreateAuto)
                    {
                        //Show message
                        var strCh = string.Join("\n\t- ",
                                                TabloidFields.TabloidFieldsArray
                                                .Where((f, index) => l.Any(i => i == index))
                                                .Select((x, index) => x.Name + "_" + tableName).ToArray());

                        r = MetroMessageBox.Show(own,
                                                 string.Format(
                                                     Resources.NewFromBaseForm_GetTable_,
                                                     tableName, strCh),
                                                 Resources.Information,
                                                 MessageBoxButtons.YesNo,
                                                 MessageBoxIcon.Exclamation);
                    }

                    if (r == DialogResult.Yes)
                    {
                        TabloidFields.CreateField(
                            TabloidFields.TabloidFieldsArray
                            .Where((f, index) => l.Any(i => i == index))
                            .ToList(), tableName, schema, config.ConnectionString);
                    }
                }

                var jr = WizardSQLHelper.SetJoinFromConstraint(tableConfig, config.ConnectionString, ref lastError); //getting join

                if (jr != null && !string.IsNullOrEmpty(lastError))
                {
                    throw new Exception(lastError);                                               //lblState.Text = lastError;
                }
                return(jr != null);
            }

            return(false);
        }