Пример #1
0
        public void ReadConnectionSetting(XmlFile src, bool remove, IWin32Window own)
        {
            foreach (var pi in GetType().GetProperties())
            {
                switch (pi.Name)
                {
                case "ConnectionString":
                    ConnectionString = src.GetAttributeFromCollection("/connectionStrings/add",
                                                                      "TabloidConnection", "connectionString");
                    break;

                case ("ProviderType"):

                    DataTools.DefaultProviderName = src.GetAttributeFromCollection("/connectionStrings/add",
                                                                                   "TabloidConnection", "providerName");

                    ProviderType = GetProviderType(DataTools.DefaultProviderName);
                    WizardTools.Tools.SetDefaultProviderFromAppSet();
                    SqlCommands.Provider = ProviderType;
                    break;
                }
            }

            if (string.IsNullOrEmpty(Schema))//set schéma for old version
            {
                if (MetroMessageBox.Show(own, Properties.Resources.AddSchema, Properties.Resources.Confirmation, MessageBoxButtons.OKCancel)
                    == DialogResult.OK)
                {
                    setSchemaFromConnectionString(ProviderType);
                    WizardSQLHelper.SetAllViewSchema(Schema);
                }
            }

            if (remove)
            {
                src.RemoveNode("/connectionStrings/add[@name='TabloidConnection']");
            }
        }
Пример #2
0
        public static void onConfigLoaded(string schema, IWin32Window own)
        {
            //for mysql verify if default schema is database name
            if (Program.AppSet.ProviderType == Provider.MySql && Program.AppSet.Schema != getDataBaseNameFromConnectionString(Program.AppSet.ConnectionString))
            {
                if (MetroMessageBox.Show(own, Properties.Resources.MySQLDifferentBaseName, Properties.Resources.Question, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    var connectionDataBaseName = getDataBaseNameFromConnectionString(Program.AppSet.ConnectionString);
                    WizardSQLHelper.SetAllViewSchema(connectionDataBaseName);
                    Program.AppSet.Schema = connectionDataBaseName;
                }
            }

            //verify role columun existance
            var tableColumns = new Dictionary <string, Dictionary <string, FieldDescriptionType> > {
                { "roles", new Dictionary <string, FieldDescriptionType> {
                      { "ad_group", new FieldDescriptionType {
                            type = DbType.String, extra = "(255)"
                        } },
                      { "droits_limiteecr", new FieldDescriptionType {
                            type = DbType.Int64, extra = "(20) DEFAULT 0"
                        } },                                                                                  //"numeric(20,0) DEFAULT 0"
                      { "droits_limite", new FieldDescriptionType {
                            type = DbType.Int64, extra = "(20) DEFAULT 1"
                        } }
                  } },
                { "utilisateurs", new Dictionary <string, FieldDescriptionType> {
                      { "theme", new FieldDescriptionType {
                            type = DbType.String, extra = "(100)"
                        } },
                      { "lastchatid", new FieldDescriptionType {
                            type = DbType.Int64, extra = " DEFAULT 0"
                        } },
                      { "password", new FieldDescriptionType {
                            type = DbType.String, extra = "(100)"
                        } },
                      { "token", new FieldDescriptionType {
                            type = DbType.String, extra = "(40)"
                        } },
                      { "ref", new FieldDescriptionType {
                            type = DbType.Boolean
                        } }
                  } }
            };

            foreach (var t in tableColumns)
            {
                string lastError;

                DataTable tableColumnsList = null;

                if (Program.AppSet.ProviderType == Provider.Postgres)
                {
                    foreach (var cschema in WizardTools.Tools.GetSearchPath(Program.AppSet.ConnectionString))
                    {
                        tableColumnsList = DataTools.Data(SqlCommands.SqlGetColums(t.Key, cschema), Program.AppSet.ConnectionString, out lastError);//c0
                        if (!string.IsNullOrEmpty(lastError))
                        {
                            throw new Exception(lastError);
                        }
                        if (tableColumnsList.Rows.Count > 0)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    tableColumnsList = DataTools.Data(SqlCommands.SqlGetColums(t.Key, null), Program.AppSet.ConnectionString, out lastError);//c0
                    if (!string.IsNullOrEmpty(lastError))
                    {
                        throw new Exception(lastError);
                    }
                }

                var fieldColumnName = tableColumnsList.Columns[0].ColumnName;

                foreach (var c in t.Value)
                {
                    if (tableColumnsList.Select(fieldColumnName + "='" + c.Key + "'").Length == 0)//field doesn't exist
                    {
                        var param = new[] { t.Key, c.Key, c.Value.ToString(), Program.AppSet.Schema };

                        var result = WizardSQLHelper.ExecuteFromFile("addField.sql", param, Program.AppSet.ConnectionString, own);
                    }
                }
            }
            //Detect old role implementation
            if (!WizardTools.Tools.isTableExist("lst_roles"))
            {
                var result = MetroMessageBox.Show(own, Properties.Resources.WrongConfigVersion, Properties.Resources.Information, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);

                if (result == DialogResult.Yes)
                {
                    AutomaticViewBuilder.setOldUtilisateurs(schema);       //.SetTable(schema);

                    var view = TabloidConfig.Config.Views["utilisateurs"]; //Todo role field could not be c4 on manual déclaration

                    WizardSQLHelper.ConvertSimpleList(view, view.Colonnes["c4"], "lst_roles", own);

                    removeView("utilisateurs");
                    removeView("roles");
                    removeView("lst_roles");
                    removeView("perso");
                }
            }

            //Detect roles/utilisateur/perso définition
            if (!TabloidConfig.Config.Views["roles"].AutomaticCreation ||
                !TabloidConfig.Config.Views["utilisateurs"].AutomaticCreation ||
                !TabloidConfig.Config.Views["perso"].AutomaticCreation)
            {
                var dr = MetroMessageBox.Show(own, Properties.Resources.CustumRoleUsed,
                                              Properties.Resources.Information, MessageBoxButtons.YesNo, MessageBoxIcon.Information);


                if (dr == DialogResult.Yes)
                {
                    removeView("roles");
                    removeView("utilisateurs");
                    removeView("perso");
                }
            }
            //Detect empty salt grain
            if (string.IsNullOrEmpty(Program.AppSet.grainDeSable))
            {
                Program.AppSet.grainDeSable = GetUniqueKey(7);
                TabloidConfig.Config.updateCurrentKey(Program.AppSet.grainDeSable);
            }
        }