/// <summary> /// 导出自定义数据表 /// </summary> /// <param name="tableName">数据表名</param> private void ExportCustomTable(string tableName) { logText.Append(string.Format("{0} —— 准备导出数据表{1}...\r\n", DateTime.Now, tableName)); string content = GenerateContentString(tableName); string[] lines = content.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); string[] headLineArray = lines[0].TrimEnd(new char[] { '\r' }).Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); ArrayList fields = new ArrayList(); fields.AddRange(headLineArray); string[] values = new string[lines.Length - 1]; for (int i = 1; i < lines.Length; i++) { values[i - 1] = lines[i].TrimEnd(new char[] { '\r' }); } ImportInfoHelper helper = new ImportInfoHelper(); helper.Fields = fields; helper.Values = values; bool exportSuccess = true; try { LuaFunction function = exportLua.GetFunction("onexport"); object[] results = function.Call("", tableName, rootPath, helper); if (results != null && results.Length > 0 && !(bool)results[0]) { ExportAutoTable(tableName); } } catch (Exception ex) { logText.Append(string.Format("{0} —— 数据表{1}导出失败:{2}\r\n", DateTime.Now, tableName, ex.Message)); exportSuccess = false; } if (exportSuccess) { logText.Append(string.Format("{0} —— 数据表{1}导出成功!\r\n", DateTime.Now, tableName)); } }
/// <summary> /// 导出自定义数据表 /// </summary> /// <param name="tableName">数据表名</param> private void ExportCustomTable(string tableName) { outputDebugString(string.Format("{0} —— 正在导出数据表{1}...", DateTime.Now, tableName)); string content = GenerateContentString(tableName); string[] lines = content.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); string[] headLineArray = lines[0].TrimEnd(new char[] { '\r' }).Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); ArrayList fields = new ArrayList(); fields.AddRange(headLineArray); string[] values = new string[lines.Length - 1]; for (int i = 1; i < lines.Length; i++) { values[i - 1] = lines[i].TrimEnd(new char[] { '\r' }); } ImportInfoHelper helper = new ImportInfoHelper(); helper.Fields = fields; helper.Values = values; bool exportSuccess = true; try { LuaFunction function = exportLua.GetFunction("onexport"); object[] results = function.Call("", tableName, rootPath, helper); if (results != null && results.Length > 0 && !(bool)results[0]) { ExportAutoTable(tableName); } } catch (Exception ex) { outputDebugStringError(string.Format("{0} —— 数据表{1}导出失败:{2}", DateTime.Now, tableName, ex.Message)); exportSuccess = false; } if (exportSuccess) { outputDebugString(string.Format("{0} —— 数据表{1}导出成功!", DateTime.Now, tableName)); } }
/* 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); }