private void populateFieldList()
        {
            string lastError;

            lstChamp.Items.Clear();

            if (cmbTable.SelectedValue == null)
            {
                return;
            }

            var dc = DataTools.Data(SqlCommands.SqlGetColums(
                                        cmbTable.SelectedValue.ToString(),
                                        cmdSchema.SelectedValue.ToString()), ConnectionString, out lastError);//0

            foreach (DataRow dcr in dc.Rows)
            {
                if (TabloidFields.IstabloidField(dcr[0].ToString()) == -1)
                {
                    lstChamp.Items.Add(dcr[0].ToString());
                }
            }

            if (lstChamp.Items.Count > 0)
            {
                lstChamp.SelectedIndex = 0;
            }
        }
        /// <summary>
        /// add field list to combobox from sql request
        /// </summary>
        /// <param name="cmb">Combobox to populate</param>
        /// <param name="table">Table name</param>
        /// <param name="connectionString">connexction string</param>
        /// <param name="DbKeyName">if set field with DbKeyName is not shown</param>
        /// <param name="allowNull">Add selectable null item</param>
        /// <param name="hideTabloidField">if true Tabloid fields are hidden</param>
        public static void displayField(ComboBox cmb, string table, string connectionString, string schema = null, string DbKeyName = "", bool allowNull = false, bool hideTabloidField = true)
        {
            cmb.Items.Clear();
            string lastError;

            if (string.IsNullOrEmpty(schema))
            {
                schema = Program.AppSet.Schema;
            }

            var dc = DataTools.Data(SqlCommands.SqlGetColums(table, schema), connectionString, out lastError);//0

            if (allowNull)
            {
                cmb.Items.Add("");
            }
            foreach (DataRow dcr in dc.Rows)
            {
                if (hideTabloidField || TabloidFields.IstabloidField(dcr[0].ToString()) == -1)
                {
                    cmb.Items.Add(dcr[0].ToString());
                    if (dcr[0].ToString() == DbKeyName)
                    {
                        cmb.SelectedIndex = cmb.Items.Count - 1;
                    }
                }
            }

            if (cmb.Items.Count > 0)
            {
                cmb.SelectedIndex = 0;
            }
        }
Beispiel #3
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);
        }