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); }
private bool CallLuaImport(LuaEx lua, string strTableName, string filename, ref string[] fields, ref string[] values) { //LuaEx lua = new LuaEx(); lua["Conn"] = m_conn; // 注册sql连接 String luafile = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + @"\import.lua"; if (!File.Exists(luafile)) return false; try { lua.DoFile(luafile); LuaFunction fun = lua.GetFunction("onimport"); if (fun != null) { ImportInfoHelper helper = new ImportInfoHelper(); ArrayList feildlist = new ArrayList(); if (fields != null) feildlist.AddRange(fields); helper.Fields = feildlist; helper.Values = values; object[] retobjs = fun.Call(strTableName, Path.GetDirectoryName(filename), filename, helper); //fields = (string[])feildlist.ToArray(typeof(string)); fields = (string[])(helper.Fields).ToArray(typeof(string)); values = helper.Values; if (retobjs != null && retobjs.GetLength(0) > 0) { bool ret = (bool)retobjs[0]; return ret; } } } catch (Exception ex) { //ScriptDebugForm frm = Program.MainForm.DebugForm; //frm.OutputBox.Text += ex.Message + "\r\n"; //frm.Show(); //frm.BringToFront(); Helper.AddLog(ex.Message); throw; } return false; }
/// <summary> /// 调用lua脚本同时导入多文件 /// </summary> /// <param name="lua">lua对象</param> /// <param name="path">导入根路径</param> /// <param name="tableName">数据表名</param> private object[] CallLuaLoadMultiFile(LuaEx lua, string path, string tableName) { //LuaEx lua = new LuaEx(); String luafile = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + @"\import.lua"; if (!File.Exists(luafile)) return null; try { lua.DoFile(luafile); LuaFunction fun = lua.GetFunction("loadmultifile"); if (fun != null) { object[] retobjs = fun.Call(path, tableName); return retobjs; } return null; } catch (Exception ex) { Helper.AddLog(ex.Message); throw; } }
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); }