Esempio n. 1
0
        private List <TabloidConfigJointure> get1NJoin()
        {
            var result = _view.Jointures.GetJointures(VisibiliteTools.GetFullVisibilite(), false);

            return(result.Where(x => x.Relation == "1:N").ToList());
        }
Esempio n. 2
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            switch (context.PropertyDescriptor.Name)
            {
            case "Champ":
            case "ChampLimite":
            case "Fin":
            case "Debut":
            case "Titre":
            case "ChampX":
            case "ChampY":
            case "ChampCritere":
            case "ChampCritere2":
            case "ChampAffichage":
            case "ChampClef":
            case "ChampValeur":
            case "ChampDeRef":
            case "ChampDeRef2":
            case "DbKey":
            case "Champ Limite":
            case "Couleur":
            case "Tooltip":
            case "ChampGroupe":
            case "FieldName":
            case "JoinFieldName":
            case "JoinValueField":
                string table = null;
                if (context.PropertyDescriptor.ComponentType.Name == "TabloidConfigEdition" &&    //cliqued from edition
                    (context.PropertyDescriptor.Name == "ChampAffichage" ||
                     context.PropertyDescriptor.Name == "ChampCritere" ||
                     context.PropertyDescriptor.Name == "ChampCritere2" ||
                     context.PropertyDescriptor.Name == "ChampClef"))
                {
                    var j = ((TabloidConfigEdition)context.Instance).Jointure;
                    if (!string.IsNullOrEmpty(j))
                    {
                        var join = CurrentContext.CurrentView.Jointures.GetJointure(j);
                        if (join != null)
                        {
                            table = join.NomTable;
                        }
                    }
                }
                if (context.PropertyDescriptor.ComponentType.Name == "TabloidConfigJointure" &&    //cliqued from join
                    (context.PropertyDescriptor.Name == "DbKey"))
                {
                    var j = ((TabloidConfigJointure)context.Instance);

                    if (!string.IsNullOrEmpty(j.NomTable))
                    {
                        table = j.NomTable;
                    }
                }

                var frm = new TableFieldSelectorForm(CurrentContext.CurrentView, (string)value, table);
                frm.ShowDialog();
                if (frm.DialogResult == DialogResult.OK)
                {
                    value = frm.Value;
                }
                break;

            case "Jointure":
                setJoinList(provider, CurrentContext.CurrentView.Jointures.GetJointures(VisibiliteTools.GetFullVisibilite(), false), value);
                var v = _list.SelectedItem;
                value = v == null ? "" :
                        v.ToString() == " " ? "" : ((TabloidConfigJointure)_list.SelectedItem).Nom;

                if (context.PropertyDescriptor.ComponentType.Name == "TabloidConfigEdition")
                {
                    var j = (TabloidConfigJointure)_list.SelectedItem;
                    var o = (TabloidConfigEdition)context.Instance;
                    o.ChampClef    = setIfEmpty(o.ChampClef, j.DbKey);
                    o.ChampCritere = setIfEmpty(o.ChampCritere, j.DbKey);

                    var cs = CurrentContext.CurrentView.Colonnes.First(c => c.Jointure == j.Nom);
                    if (cs != null)
                    {
                        o.ChampAffichage = setIfEmpty(o.ChampAffichage,
                                                      ((Champ)cs).NomChamp);
                    }
                }
                break;

            case "Table":
            case "TableSource":
            case "NomTable":
            case "TableName":
            case "JoinTableName":
                setTableList(provider, value);
                value = _list.SelectedItem;
                break;

            case "Select":
            case "Where":
            case "GroupBy":
            case "Distinct":
            case "WherePeuplement":
            case "Order":
                var sqlEditor = new SqlEditor(value == null ? "" : value.ToString());
                sqlEditor.ShowDialog();

                if (sqlEditor.DialogResult == DialogResult.OK)
                {
                    value = sqlEditor.txtSql.Text;
                }
                break;

            case "Rolels":
            case "VisibleRole":
            case "Authorization":
                string      title = "?";
                WizardRoles wz    = null;

                if (context.PropertyDescriptor.Name == "Authorization")
                {
                    title = Properties.Resources.Edition + ((TabloidConfigEdition)context.Instance).ToString();

                    wz = new WizardRoles(title, Properties.Resources.DisplayOnly);
                }
                else
                {
                    title = Properties.Resources.TheField + ((TabloidConfigColonne)context.Instance).ToString();

                    wz = context.PropertyDescriptor.Name == "VisibleRole" ?
                         new WizardRoles(title, Properties.Resources.Hidden) :
                         new WizardRoles(title, Properties.Resources.WithReadOnly);
                }

                if (wz.ShowDialog() == DialogResult.OK)
                {
                    value = wz.txtResult.Text;
                }
                break;

            case "ColName":
                var frmXLS = new XLSColumnSelector(Program.CurrentXLSStructure, XLSColumnSelector.BehaviourTypes.ColumnSelect);
                if (frmXLS.ShowDialog() == DialogResult.OK)
                {
                    Program.CurrentXLSStructure = frmXLS.CurrentXLSStructure;
                    value = frmXLS.cmbField.SelectedItem;
                }
                break;

            case "DSID":
                setDMFieldList(provider, value);
                break;
            }

            return(base.EditValue(context, provider, value));
        }
        private void Analyse(object sender, DoWorkEventArgs e)
        {
            string lastError;

            var           dc        = DataTools.Data(SqlCommands.SqlGetTable(), Program.AppSet.ConnectionString, out lastError);
            List <string> tableList = new List <string>();

            //search in table list and attach corresponding view
            foreach (DataRow dcr in dc.Rows)
            {
                var attachedView = TabloidConfig.Config.Views.Where(c => string.Equals(c.NomTable, dcr[0].ToString(), StringComparison.InvariantCultureIgnoreCase)).ToList();
                tableList.Add(dcr[0].ToString());

                var result = new TableAnalysisResult
                {
                    TableName = dcr[0].ToString(),
                    Views     = attachedView
                };

                if (attachedView.Count == 0)
                {
                    result.Results.Add(new TableWithNoView(result, this));
                }
                _results.Add(result);
            }


            foreach (TabloidConfigView v in TabloidConfig.Config.Views)
            {
                var result = new TableAnalysisResult
                {
                    TableName = null
                };
                result.Views.Add(v);

                if (!tableList.Contains(v.NomTable, StringComparer.OrdinalIgnoreCase))//search view with no table
                {
                    result.Results.Add(new ViewWithNoTable(result, this));
                }


                var joinList = v.Jointures.GetJointures(VisibiliteTools.GetFullVisibilite(), true);
                if (joinList.Count > 0)
                {
                    var dfk = DataTools.Data(SqlCommands.SqlGetForeignKey(v.NomTable, v.Schema), Program.AppSet.ConnectionString, out lastError);

                    foreach (TabloidConfigJointure j in joinList)
                    {
                        if (j.Relation == "N:1" || string.IsNullOrEmpty(j.Relation))
                        {
                            var sql = $"{dfk.Columns[0].ColumnName}='{j.ChampDeRef}' and {dfk.Columns[1].ColumnName}='{j.NomTable}' and {dfk.Columns[2].ColumnName}='{j.DbKey}'";
                            if (dfk.Select(sql).Count() == 0)
                            {
                                result.Results.Add(new JoinWithNoConstraint(j, v, this));
                            }
                        }
                    }
                }

                if (result.Results.Count > 0)
                {
                    _results.Add(result);
                }
            }
        }