private bool CallLuaPostExport(string strTableName, string strTargetPath) { string oldcurdir = System.IO.Directory.GetCurrentDirectory(); System.IO.Directory.SetCurrentDirectory(Application.StartupPath); string luafile = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + @"\post_export.lua"; if (!File.Exists(luafile)) { return(false); } LuaEx lua = new LuaEx(); lua["RootDir"] = Program.RootDir; lua["Conn"] = m_conn; lua.DoString("function trace(txt)\r\n MainForm.LogEditBox.Visible = true\r\n MainForm.LogEditBox.OutputBox.Text = MainForm.LogEditBox.Text ..txt..'\\r\\n' \r\n end"); lua.RegisterFunction("msgbox", this, typeof(TabExport).GetMethod("ShowMessage")); lua.RegisterFunction("GetDataTableRow", this, typeof(TabExport).GetMethod("GetDataTableRow")); lua.DoFile(luafile); LuaFunction fun = lua.GetFunction("onpostexport"); if (fun != null) { object[] retobjs = fun.Call(strTableName, strTargetPath); if (retobjs.Length > 0) { System.IO.Directory.SetCurrentDirectory(oldcurdir); return((bool)retobjs[0]); } } System.IO.Directory.SetCurrentDirectory(oldcurdir); return(false); }
public ScriptCodeForm(MainForm mainform) { this.m_mainform = mainform; g_lua.RegisterFunction("lt2ArrayList", this, typeof(ScriptCodeForm).GetMethod("lt2ArrayList")); g_lua.RegisterFunction("lt2ArrayList_parms", this, typeof(ScriptCodeForm).GetMethod("lt2ArrayList_parms")); g_lua.RegisterFunction("lt_GetType", this, typeof(ScriptCodeForm).GetMethod("lt_GetType")); g_lua.RegisterFunction("SaveScriptIntoDatabase", this, typeof(ScriptCodeForm).GetMethod("SaveScriptIntoDatabase")); string strInitFileName = Path.Combine(Application.StartupPath, @"Plugins\LuaEditor\scriptcode.lua"); if (!File.Exists(strInitFileName)) { MessageBox.Show("找不到" + strInitFileName, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } g_lua.DoFile(strInitFileName); }
private bool CallLuaPostExport(string strTableName, string strTargetPath) { string oldcurdir = System.IO.Directory.GetCurrentDirectory(); System.IO.Directory.SetCurrentDirectory(Application.StartupPath); string luafile = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + @"\post_export.lua"; if (!File.Exists(luafile)) return false; LuaEx lua = new LuaEx(); lua["RootDir"] = Program.RootDir; lua["Conn"] = m_conn; lua.DoString("function trace(txt)\r\n MainForm.LogEditBox.Visible = true\r\n MainForm.LogEditBox.OutputBox.Text = MainForm.LogEditBox.Text ..txt..'\\r\\n' \r\n end"); lua.RegisterFunction("msgbox", this, typeof(TabExport).GetMethod("ShowMessage")); lua.RegisterFunction("GetDataTableRow", this, typeof(TabExport).GetMethod("GetDataTableRow")); lua.DoFile(luafile); LuaFunction fun = lua.GetFunction("onpostexport"); if (fun != null) { object[] retobjs = fun.Call(strTableName, strTargetPath); if (retobjs.Length > 0) { System.IO.Directory.SetCurrentDirectory(oldcurdir); return (bool)retobjs[0]; } } System.IO.Directory.SetCurrentDirectory(oldcurdir); return false; }
/* public string[] CloneValue(string[] strvalues) { if (strvalues != null) return (string[])(strvalues.Clone()); return null; }*/ private bool CallLuaExport(string strLuaFile, string strTableName, ref string fields, ref string values) { LuaEx lua = new LuaEx(); lua["Conn"] = m_conn; // 注册sql连接 lua["RootDir"] = Program.RootDir; lua.DoString("function trace(txt)\r\n MainForm.LogEditBox.Visible = true\r\n MainForm.LogEditBox.OutputBox.Text = MainForm.LogEditBox.Text ..txt..'\\r\\n' \r\n end"); lua.RegisterFunction("writefile", this, typeof(FileFolderHelper).GetMethod("WriteStringToFile")); lua.RegisterFunction("msgbox", this, typeof(TabExport).GetMethod("ShowMessage")); lua.RegisterFunction("GetDataTableRow", this, typeof(TabExport).GetMethod("GetDataTableRow")); //lua.RegisterFunction("clonevalues", this, typeof(TabExport).GetMethod("CloneValue")); String luafile = strLuaFile; try { if (!File.Exists(luafile)) return false; try { lua.DoFile(luafile); LuaFunction fun = lua.GetFunction("onexport"); if (fun != null) { ImportInfoHelper helper = new ImportInfoHelper(); ArrayList feildlist = new ArrayList(); feildlist.AddRange(fields.Split(new char[] { '\t' })); helper.Fields = feildlist; helper.Values = values.Split(new string[] { "\r\n" }, StringSplitOptions.None); object[] retobjs = fun.Call(m_strModlName, strTableName, Program.RootDir, helper); if (retobjs != null && retobjs.GetLength(0) > 0) { if (retobjs[0] is bool) { StringBuilder strFields = new StringBuilder(); foreach (string strLine in feildlist) { strFields.Append(strLine); strFields.Append('\t'); } strFields.Remove(strFields.Length - 1, 1); strFields.Append("\r\n"); fields = strFields.ToString(); StringBuilder strValues = new StringBuilder(); foreach (string strLine in helper.Values) { strValues.Append(strLine); strValues.Append("\r\n"); } values = strValues.ToString(); return (bool)retobjs[0]; } } } } catch (Exception ex) { ScriptDebugForm frm = Program.MainForm.DebugForm; frm.OutputBox.Text += ex.Message + "\r\n"; frm.Show(); frm.BringToFront(); } } finally { lua.Dispose(); } return false; }
/* public string[] CloneValue(string[] strvalues) * { * if (strvalues != null) * return (string[])(strvalues.Clone()); * return null; * }*/ private bool CallLuaExport(string strLuaFile, string strTableName, ref string fields, ref string values) { LuaEx lua = new LuaEx(); lua["Conn"] = m_conn; // 注册sql连接 lua["RootDir"] = Program.RootDir; lua.DoString("function trace(txt)\r\n MainForm.LogEditBox.Visible = true\r\n MainForm.LogEditBox.OutputBox.Text = MainForm.LogEditBox.Text ..txt..'\\r\\n' \r\n end"); lua.RegisterFunction("writefile", this, typeof(FileFolderHelper).GetMethod("WriteStringToFile")); lua.RegisterFunction("msgbox", this, typeof(TabExport).GetMethod("ShowMessage")); lua.RegisterFunction("GetDataTableRow", this, typeof(TabExport).GetMethod("GetDataTableRow")); //lua.RegisterFunction("clonevalues", this, typeof(TabExport).GetMethod("CloneValue")); String luafile = strLuaFile; try { if (!File.Exists(luafile)) { return(false); } try { lua.DoFile(luafile); LuaFunction fun = lua.GetFunction("onexport"); if (fun != null) { ImportInfoHelper helper = new ImportInfoHelper(); ArrayList feildlist = new ArrayList(); feildlist.AddRange(fields.Split(new char[] { '\t' })); helper.Fields = feildlist; helper.Values = values.Split(new string[] { "\r\n" }, StringSplitOptions.None); object[] retobjs = fun.Call(m_strModlName, strTableName, Program.RootDir, helper); if (retobjs != null && retobjs.GetLength(0) > 0) { if (retobjs[0] is bool) { StringBuilder strFields = new StringBuilder(); foreach (string strLine in feildlist) { strFields.Append(strLine); strFields.Append('\t'); } strFields.Remove(strFields.Length - 1, 1); strFields.Append("\r\n"); fields = strFields.ToString(); StringBuilder strValues = new StringBuilder(); foreach (string strLine in helper.Values) { strValues.Append(strLine); strValues.Append("\r\n"); } values = strValues.ToString(); return((bool)retobjs[0]); } } } } catch (Exception ex) { ScriptDebugForm frm = Program.MainForm.DebugForm; frm.OutputBox.Text += ex.Message + "\r\n"; frm.Show(); frm.BringToFront(); } } finally { lua.Dispose(); } return(false); }