static void ExportAllExcel(ExportTo to) { string dir = Application.dataPath + "/Excel/"; string[] files = Directory.GetFiles(dir); try { int count = files.Length; for (int i = 0; i < files.Length; ++i) { string path = files[i]; EditorUtility.DisplayProgressBar("导出Excel", string.Format("开始导出:{0}", path.Replace(Application.dataPath, "Assets")), (i + 1) * 1f / count); ExportExcel(path, to); } } catch (Exception e) { throw e; } finally { EditorUtility.ClearProgressBar(); } }
static void ExportExcel(ExportTo to) { if (Selection.activeObject == null) { return; } try { int count = Selection.objects.Length; for (int i = 0; i < count; ++i) { string path = AssetDatabase.GetAssetPath(Selection.objects[i]); EditorUtility.DisplayProgressBar("导出Excel", string.Format("开始导出:{0}", path), (i + 1) * 1f / count); string fullpath = Application.dataPath + path.Substring("Assets".Length); ExportExcel(fullpath, to); } } catch (Exception e) { throw e; } finally { EditorUtility.ClearProgressBar(); } }
public void TestGetQryValueWrappedWithLimit() { var testResult = ExportTo.GetQryValueWrappedWithLimit(SerializedTableMetadata(), "LastName", "Tamburello", 0); Assert.IsNotNull(testResult); Assert.AreNotEqual("''", testResult); Assert.AreEqual("'Tamburello'", testResult); testResult = ExportTo.GetQryValueWrappedWithLimit(SerializedTableMetadata(), "LastName", "Tamburello", 5); Assert.IsNotNull(testResult); Assert.AreNotEqual("''", testResult); Assert.AreEqual("'Tambu'", testResult); testResult = ExportTo.GetQryValueWrappedWithLimit(SerializedTableMetadata(), "EmailPromotion", "1", 0); Assert.IsNotNull(testResult); Assert.AreNotEqual("NULL", testResult); Assert.AreEqual("1", testResult); testResult = ExportTo.GetQryValueWrappedWithLimit(SerializedTableMetadata(), "EmailPromotion", "NULL", 0); Assert.IsNotNull(testResult); Assert.AreNotEqual("1", testResult); Assert.AreEqual("NULL", testResult); }
public void TestScriptDataBodyMerge() { var dt = ReadSerializedTableFromDisk("DataTable.Person.bin"); var testResult = ExportTo.ScriptDataBody(QRY, 32, ExportToStatementType.MERGE, SerializedTableMetadata(), dt); Assert.IsNotNull(testResult); Console.WriteLine(testResult); }
private void OnFocus() { projectPath = EditorPrefs.GetString("TRMB.ProjectPath"); gamePath = EditorPrefs.GetString("TRMB.GamePath"); exportFolderName = EditorPrefs.HasKey("TRMB.ExportFolderName") ? EditorPrefs.GetString("TRMB.ExportFolderName") : "MyMod"; exportTo = (ExportTo)EditorPrefs.GetInt("TRMB.ExportTo"); toDefault = EditorPrefs.GetBool("TRMB.ToDefault"); runGameAfterBuild = EditorPrefs.GetBool("TRMB.RunGameAfterBuild"); cleanDestination = EditorPrefs.GetBool("TRMB.CleanDestination"); runGameArguments = EditorPrefs.GetString("TRMB.RunGameArguments"); gameName = (SupportedGame)EditorPrefs.GetInt("TRMB.GameName"); action = (Action)EditorPrefs.GetInt("TRMB.Action"); }
static void ExportExcel(string path, ExportTo to) { if (string.IsNullOrEmpty(path)) { return; } if (path.EndsWith(".xlsx") || path.EndsWith(".xls")) { FileStream stream = File.Open(path, FileMode.Open, FileAccess.Read); IExcelDataReader reader = ExcelReaderFactory.CreateOpenXmlReader(stream); DataSet dataSet = reader.AsDataSet(); if (dataSet == null || dataSet.Tables == null || dataSet.Tables.Count <= 0) { stream.Close(); Debug.Log("Excel表格没有Sheet:" + path); return; } string dir = Path.GetDirectoryName(path); try { for (int i = 0; i < dataSet.Tables.Count; ++i) { DataTable table = dataSet.Tables[i]; if (to == ExportTo.Database) { ExportToDatabase(dir, table); } else { ExportToLua(dir, table); } } } catch (Exception e) { throw e; } finally{ stream.Close(); } } }
public void TestGetTableSchemaAndNameFromExpression() { var testResult = ExportTo.GetTableSchemaAndNameFromExpression("select * from MyTable"); Assert.AreEqual("MyTable", testResult.TableName); Console.WriteLine("----------------------------"); testResult = ExportTo.GetTableSchemaAndNameFromExpression("select * from MyTable where id = 12"); Assert.AreEqual("MyTable", testResult.TableName); Console.WriteLine("----------------------------"); testResult = ExportTo.GetTableSchemaAndNameFromExpression("select * from [MyTable]"); Assert.AreEqual("MyTable", testResult.TableName); Console.WriteLine("----------------------------"); testResult = ExportTo.GetTableSchemaAndNameFromExpression("select * from dbo.MyTable"); Assert.AreEqual("MyTable", testResult.TableName); Assert.AreEqual("dbo", testResult.SchemaName); Console.WriteLine("----------------------------"); testResult = ExportTo.GetTableSchemaAndNameFromExpression("select * from [dbo].[MyTable]"); Assert.AreEqual("MyTable", testResult.TableName); Assert.AreEqual("dbo", testResult.SchemaName); Console.WriteLine("----------------------------"); testResult = ExportTo.GetTableSchemaAndNameFromExpression("select * from [dbo].[MyTable] where id = 12"); Assert.AreEqual("MyTable", testResult.TableName); Assert.AreEqual("dbo", testResult.SchemaName); Console.WriteLine("----------------------------"); testResult = ExportTo.GetTableSchemaAndNameFromExpression("select * from dbo.MyTable where id = 12"); Assert.AreEqual("MyTable", testResult.TableName); Assert.AreEqual("dbo", testResult.SchemaName); Console.WriteLine("----------------------------"); testResult = ExportTo.GetTableSchemaAndNameFromExpression("select * from MyDb.dbo.MyTable"); Assert.AreEqual("MyTable", testResult.TableName); Assert.AreEqual("dbo", testResult.SchemaName); Console.WriteLine("----------------------------"); testResult = ExportTo.GetTableSchemaAndNameFromExpression("select * from [MyDb].[dbo].[MyTable]"); Assert.AreEqual("MyTable", testResult.TableName); Assert.AreEqual("dbo", testResult.SchemaName); Console.WriteLine("----------------------------"); //MSSQL lets you use anything as long as its in square braces testResult = ExportTo.GetTableSchemaAndNameFromExpression("select * from [MyDb].[MySchema.Data].[MyTable]"); Assert.AreEqual("MyTable", testResult.TableName); Assert.AreEqual("MySchema.Data", testResult.SchemaName); Console.WriteLine("----------------------------"); testResult = ExportTo.GetTableSchemaAndNameFromExpression("select * from [BBG].[Ordering].[Transactions] WHERE Id = '1145221B'"); Assert.AreEqual("Transactions", testResult.TableName); Assert.AreEqual("Ordering", testResult.SchemaName); Console.WriteLine("----------------------------"); testResult = ExportTo.GetTableSchemaAndNameFromExpression("select * from [BBG].[Ordering].[Transactions]\n\tWHERE Id = '1145221B'"); Assert.AreEqual("Transactions", testResult.TableName); Assert.AreEqual("Ordering", testResult.SchemaName); Console.WriteLine("----------------------------"); var testResult2 = ExportTo.GetTableSchemaAndNameFromExpression("[BBG].[Ordering].[Transactions]"); Assert.AreEqual("Transactions", testResult2.TableName); Assert.AreEqual("Ordering", testResult2.SchemaName); Console.WriteLine("----------------------------"); var testResult3 = ExportTo.GetTableSchemaAndNameFromExpression("[Ordering].Transactions"); Assert.AreEqual("Transactions", testResult2.TableName); Assert.AreEqual("Ordering", testResult2.SchemaName); Console.WriteLine("----------------------------"); testResult = ExportTo.GetTableSchemaAndNameFromExpression( "select top 10 programid, partnum from [MyDb].[dbo].[MyTable]"); Assert.AreEqual("MyTable", testResult.TableName); Assert.AreEqual("dbo", testResult.SchemaName); }
static void ExportToGUI() { GUILayout.BeginHorizontal(); ExportTo newExportTo = (ExportTo)EditorGUILayout.EnumPopup("Export to", exportTo); if (newExportTo != exportTo) { EditorPrefs.SetInt("TRMB.ExportTo", (int)newExportTo); exportTo = newExportTo; } EditorGUI.BeginDisabledGroup((exportTo == ExportTo.Project) ? true : false); bool newRunGameAfterBuild = GUILayout.Toggle(runGameAfterBuild, "Run game after build", GUILayout.Width(150)); if (newRunGameAfterBuild != runGameAfterBuild) { EditorPrefs.SetBool("TRMB.RunGameAfterBuild", newRunGameAfterBuild); runGameAfterBuild = newRunGameAfterBuild; } EditorGUI.EndDisabledGroup(); bool newCleanDestination = GUILayout.Toggle(cleanDestination, "Clean destination", GUILayout.Width(150)); if (newCleanDestination != cleanDestination) { EditorPrefs.SetBool("TRMB.CleanDestination", newCleanDestination); cleanDestination = newCleanDestination; } GUILayout.EndHorizontal(); if (runGameAfterBuild && exportTo == ExportTo.Game) { GUILayout.Space(5); GUILayout.BeginHorizontal(); GUILayout.Label(new GUIContent("Arguments"), new GUIStyle("BoldLabel"), GUILayout.Width(150)); string newRunGameArguments = GUILayout.TextField(runGameArguments, 25); if (newRunGameArguments != runGameArguments) { EditorPrefs.SetString("TRMB.RunGameArguments", newRunGameArguments); runGameArguments = newRunGameArguments; } GUILayout.EndHorizontal(); } GUILayout.Space(5); #if PrivateSDK if (exportTo == ExportTo.Android) { GUILayout.Space(5); SupportedGame newGameName = (SupportedGame)EditorGUILayout.EnumPopup("Game name", gameName); if (newGameName != gameName) { EditorPrefs.SetInt("TRMB.GameName", (int)newGameName); gameName = newGameName; } } #endif if (exportTo == ExportTo.Game) { GUILayout.BeginHorizontal(); GUILayout.Label(new GUIContent("Game folder Directory"), new GUIStyle("BoldLabel"), GUILayout.Width(150)); if (GUILayout.Button(gamePath, new GUIStyle("textField"))) { gamePath = EditorUtility.OpenFolderPanel("Select game folder", "", ""); EditorPrefs.SetString("TRMB.GamePath", gamePath); } GUILayout.EndHorizontal(); } if (exportTo == ExportTo.Project) { GUILayout.BeginHorizontal(); GUILayout.Label(new GUIContent("Project folder Directory"), new GUIStyle("BoldLabel"), GUILayout.Width(150)); if (GUILayout.Button(projectPath, new GUIStyle("textField"))) { projectPath = EditorUtility.OpenFolderPanel("Select project folder", "", ""); EditorPrefs.SetString("TRMB.ProjectPath", projectPath); } GUILayout.EndHorizontal(); } }