예제 #1
0
        public static bool Execute(out DBLangEngine.DatabaseType dbType)
        {
            FormSelectDBType frm = new FormSelectDBType();

            if (frm.ShowDialog() == DialogResult.OK)
            {
                KeyValuePair <DBLangEngine.DatabaseType, string> v = (KeyValuePair <DBLangEngine.DatabaseType, string>)frm.cmbDatabaseType.SelectedItem;
                dbType = v.Key;
                return(true);
            }
            else
            {
                dbType = DBLangEngine.DatabaseType.dtSQLite;
                return(false);
            }
        }
예제 #2
0
        private void DoMessageDump()
        {
            DBLangEngine.DatabaseType scriptDbType;
            if (FormSelectDBType.Execute(out scriptDbType))
            {
                string scriptSchema = string.Empty;
                if (scriptDbType == DBLangEngine.DatabaseType.dtMSSQL)
                {
                    scriptSchema = "[dbo].";
                }
                else if (scriptDbType == DBLangEngine.DatabaseType.dtPostgreSQL)
                {
                    scriptSchema = "public.";
                }

                List <string> sqlDump = new List <string>();

                string addStrForm = "INSERT INTO FORMITEMS(APP_FORM, ITEM, CULTURE, PROPERTYNAME, VALUETYPE, VALUE, INUSE) " + Environment.NewLine +
                                    "SELECT {0}, {1}, {2}, {3}, {4}, {5}, {6} " + Environment.NewLine +
                                    "WHERE NOT EXISTS (SELECT 1 FROM {7}FORMITEMS WHERE APP_FORM = {0} AND ITEM = {1} AND CULTURE = {2} AND PROPERTYNAME = {3}); " + Environment.NewLine +
                                    "UPDATE {7}FORMITEMS SET INUSE = {6}, VALUE = {5} WHERE APP_FORM = {0} AND ITEM = {1} AND PROPERTYNAME = {3} AND CULTURE = {2}; " + Environment.NewLine;
                string addStrMessage = "INSERT INTO {5}MESSAGES(CULTURE, MESSAGENAME, VALUE, COMMENT_EN_US, INUSE) " +
                                       "SELECT {0}, {1}, {2}, {3}, {4} " + Environment.NewLine +
                                       "WHERE NOT EXISTS (SELECT 1 FROM {5}MESSAGES WHERE MESSAGENAME = {1} AND CULTURE = {0}); " + Environment.NewLine +
                                       "UPDATE {5}MESSAGES SET VALUE = {2}, COMMENT_EN_US = {3}, INUSE = {4} WHERE MESSAGENAME = {1} AND CULTURE = {0}; " + Environment.NewLine;

                if (scriptDbType == DBLangEngine.DatabaseType.dtMySQL)
                {
                    addStrForm = "INSERT INTO FORMITEMS(APP_FORM, ITEM, CULTURE, PROPERTYNAME, VALUETYPE, VALUE, INUSE) " + Environment.NewLine +
                                 "SELECT {0}, {1}, {2}, {3}, {4}, {5}, {6} FROM DUAL " + Environment.NewLine +
                                 "WHERE NOT EXISTS (SELECT * FROM {7}FORMITEMS WHERE APP_FORM = {0} AND ITEM = {1} AND CULTURE = {2} AND PROPERTYNAME = {3}) LIMIT 1; " + Environment.NewLine +
                                 "UPDATE {7}FORMITEMS SET INUSE = {6}, VALUE = {5} WHERE APP_FORM = {0} AND ITEM = {1} AND PROPERTYNAME = {3} AND CULTURE = {2}; " + Environment.NewLine;

                    addStrMessage = "INSERT INTO {5}MESSAGES(CULTURE, MESSAGENAME, VALUE, COMMENT_EN_US, INUSE) " +
                                    "SELECT {0}, {1}, {2}, {3}, {4} FROM DUAL " + Environment.NewLine +
                                    "WHERE NOT EXISTS (SELECT * FROM {5}MESSAGES WHERE MESSAGENAME = {1} AND CULTURE = {0}) LIMIT 1; " + Environment.NewLine +
                                    "UPDATE {5}MESSAGES SET VALUE = {2}, COMMENT_EN_US = {3}, INUSE = {4} WHERE MESSAGENAME = {1} AND CULTURE = {0}; " + Environment.NewLine;
                }

                using (IDbCommand command = GetCommand())
                {
                    command.CommandText = SQLs.SelectDumpFormItems(dbType);
                    using (IDataReader dr = command.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            sqlDump.Add(string.Format(addStrForm,
                                                      DBUtils.MkStr(dr.GetString(0)),
                                                      DBUtils.MkStr(dr.GetString(1)),
                                                      DBUtils.MkStr(dr.GetString(2)),
                                                      DBUtils.MkStr(dr.GetString(3)),
                                                      DBUtils.MkStr(dr.GetString(4)),
                                                      DBUtils.MkStr(dr.GetString(5)),
                                                      dr.GetInt32(6),
                                                      scriptSchema));
                        }
                    }
                }

                using (IDbCommand command = GetCommand())
                {
                    command.CommandText = SQLs.SelectDumpMessages(dbType);
                    using (IDataReader dr = command.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            sqlDump.Add(string.Format(addStrMessage,
                                                      DBUtils.MkStr(dr.GetString(0)),
                                                      DBUtils.MkStr(dr.GetString(1)),
                                                      DBUtils.MkStr(dr.GetString(2)),
                                                      DBUtils.MkStr(dr.GetString(3)),
                                                      dr.GetInt32(4),
                                                      scriptSchema));
                        }
                    }
                }
                FormDataDump.Execute(sqlDump);
            }
        }