Example #1
0
        private void cmbTable_SelectedIndexChanged(object sender, EventArgs e)
        {
            WizardSQLHelper.displayField(cmbChamp, ((TabloidConfigView)cmbTable.SelectedValue).NomTable, _connectionString);

            if (init)
            {
                return;
            }

            if (cmbJoin.SelectedIndex == -1 || ((TabloidConfigView)cmbTable.SelectedItem).NomTable != ((TabloidConfigJointure)cmbJoin.SelectedItem).NomTable)//no selection look for an interesting join in current list
            {
                cmbJoin.SelectedItem = null;

                selectJoinFromTableName();

                if (cmbJoin.SelectedIndex == -1)//no interesting join in current list try to create one from joins in joined table list
                {
                    var joinedTable = (TabloidConfigView)cmbTable.SelectedItem;

                    foreach (TabloidConfigJointure j in joinedTable.Jointures)
                    {
                        if (j.NomTable == _view.NomTable)
                        {
                            var dr = MetroMessageBox.Show(this, Properties.Resources.NoJoinCreate, Properties.Resources.CreateJoin, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                            if (dr == DialogResult.No)
                            {
                                break;
                            }

                            WizardJoin.joinConverter(j, true, joinedTable);

                            cmbJoin.DataSource = get1NJoin();

                            selectJoinFromTableName();
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Build required task on wizard end
        /// </summary>
        /// <returns></returns>
        bool addField()
        {
            var useJoinName = "";

            if (_iviewFct is TabloidConfigView && !radbutton.Checked)
            {
                var view = (TabloidConfigView)_iviewFct;

                if (_useDatabaseField && //handel label with no database field
                    ((TabloidBaseControl)wzCmbEditeur.SelectedItem).type != TemplateType.Graphique) //no database field for graphic
                {
                    if (radioCrea.Checked)                                                          //field must be created in database
                    {
                        var t       = (DbType)Enum.Parse(typeof(DbType), lstTypeCrea.SelectedItem.ToString());
                        var sqlType = dataHelper.DbTypeConverter.ConvertFromGenericDbType(t, Tools.ConvertProviderType(_provider));

                        var fieldArg = txtLong.Text;
                        if (txtDec.Text != "")
                        {
                            fieldArg = fieldArg + "," + txtDec.Text;
                        }
                        if (fieldArg != "")
                        {
                            fieldArg = "(" + fieldArg + ")";
                        }

                        var param = new string[] { view.NomTable, txtNomCrea.Text, sqlType + fieldArg, view.Schema };

                        if (!WizardSQLHelper.ExecuteFromFile("addField.sql", param, _connectionString, this))
                        {
                            return(true);
                        }
                    }
                    else//use existing field
                    {
                        if (fs.cmbTable.SelectedValue.ToString() != view.NomTable &&
                            ((TabloidBaseControl)wzCmbEditeur.SelectedItem).type != TemplateType.Graphique)//verify if field is in current table
                        {
                            var useJoin = view.Jointures.GetJoinFromTableName(fs.cmbTable.SelectedValue.ToString());
                            if (useJoin == null)//verify if table is in joined table list
                            {
                                if (MetroMessageBox.Show(this, Resources.add_join, Resources.Warning, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
                                {
                                    var w = new WizardJoin(
                                        view,
                                        null,
                                        Program.AppSet.ConnectionString);

                                    w.ShowDialog();

                                    useJoin = view.Jointures.GetJoinFromTableName(fs.cmbTable.SelectedValue.ToString());
                                    if (useJoin != null)
                                    {
                                        useJoinName = useJoin.Nom;
                                    }
                                }
                            }
                            else
                            {
                                useJoinName = useJoin.Nom;
                            }
                        }
                    }
                }
            }

            if (radbutton.Checked)//add button
            {
                Tc = new TabloidConfigColonne
                {
                    Champ         = fs.lstChamp.Text,
                    Titre         = WzTxtTitre.Text,
                    Editeur       = TemplateType.Btn,
                    Type          = DbType.String,
                    EditeurParam2 = txtIcoBtn.Text,
                    EditeurParam3 = txtUrlBtn.Text,
                    EditeurParam4 = txtToolTipBtn.Text,
                    VisibleDetail = true,
                    Parent        = _parentField,
                    Nom           = "btn"
                }
            }
            ;
            else//add other type field
            {
                Tc = new TabloidConfigColonne
                {
                    Champ   = radioCrea.Checked ? txtNomCrea.Text : fs.lstChamp.Text,
                    Titre   = WzTxtTitre.Text,
                    Editeur = ((TabloidBaseControl)wzCmbEditeur.SelectedItem).type,
                    Type    = radioCrea.Checked ?
                              (DbType)Enum.Parse(typeof(DbType), lstTypeCrea.SelectedItem.ToString()) :
                              DbType.String,
                    EditeurParam1 = txtUrlBtn.Text,
                    Parent        = _parentField,
                    Jointure      = useJoinName,
                    Nom           = "C"
                };

                if (Tc.Editeur == TemplateType.Picture)
                {
                    Tc.EditeurParam1 = "144x200";
                    Tc.EditeurParam2 = "/Tabloid/images/inconnu.png";
                    Tc.EditeurParam3 = "jpg";
                    Tc.EditeurParam4 = "4";
                }

                if (Tc.Editeur == TemplateType.Graphique)
                {
                    Tc.EditeurParam1 = ((TabloidConfigGraph)cmbGraph.SelectedItem).Nom;
                }

                if (_iviewFct is TabloidConfigView)
                {
                    var view = (TabloidConfigView)_iviewFct;

                    if (Tc.Editeur == TemplateType.Mobile)
                    {
                        view.Recherche.ChampMobile = radioCrea.Checked ? txtNomCrea.Text : fs.lstChamp.Text;
                        WizardSQLHelper.SetMobile(view);
                    }
                    if (Tc.Editeur == TemplateType.Mail)
                    {
                        view.Recherche.ChampMail = radioCrea.Checked ? txtNomCrea.Text : fs.lstChamp.Text;
                    }
                }
            }

            WizardSQLHelper.SetFieldVisibilityProperties(Tc, lstVisibilites);

            var parent = _iviewFct.Colonnes;

            if (_parentField != null)
            {
                parent = _parentField.Colonnes;
            }

            Tools.AddWithUniqueName(_iviewFct.Colonnes, Tc, "C", parent);

            return(false);
        }