Exemple #1
0
        public static OptData getExportContent(ExcelToMapData v_data, int v_optCode,
                                               string[] rootPath, string fileName)
        {
            OptData       rtn = new OptData();
            StringBuilder sb  = new StringBuilder();

            try
            {
                LuaMap root = GetLuaTable(v_data._data, v_data.IsSingleKey);
                sb.Append("--[[\r\n");
                sb.AppendFormat("output from excel {0}\r\n", v_data.excelName);
                v_data.opt_note(sb, "note");
                sb.Append("\r\n");
                sb.Append("colums:\r\n");
                v_data.opt_colum_notes(sb, v_optCode);
                sb.Append("\r\n");
                sb.Append("primary key:\r\n");
                for (int i = 0; i < v_data.sheet_bins.Count; i++)
                {
                    sb.AppendFormat("#{0} [{1}]: ", i, v_data.sheet_bins[i].sheetName);
                    sb.Append(string.Join(",", v_data.sheet_bins[i].indexData.pmKey));
                    sb.Append("\r\n");
                }
                sb.Append("]]\r\n");

                sb.Append("local _T = LangUtil.Language\r\n");

                if (v_data.IsDataPersistence)
                {
                    sb.AppendFormat("if ddt[\"{0}\"] ~= nil then\r\n\treturn ddt[\"{0}\"]\r\nend\r\n", v_data.className);
                    sb.Append("local data = ");
                    root.outputValue(sb, 0);
                    sb.AppendLine();
                    sb.AppendFormat("ddt[\"{0}\"] = data\r\n", v_data.className);
                    //sb.Append("SetLooseReadonly(data)\r\n");
                    sb.Append("return data");
                }
                else
                {
                    sb.Append("return");
                    root.outputValue(sb, 0);
                }
            }
            catch (Exception ex)
            {
                rtn.errList.Add("导出基础数据时出现错误,错误信息为:\r\n" + ex.ToString());
            }

            rtn.content = sb.ToString();

            for (int i = 0; i < rootPath.Length; i++)
            {
                string opt_path = rootPath[i] + fileName;
                File.WriteAllText(opt_path, rtn.content);
            }

            return(rtn);
            //sb.Append(string.Format("\r\nreturn {0}", curIndex.className));
        }
Exemple #2
0
        public static OptData getExportContent(ExcelToMapData v_data, int v_optCode)
        {
            OptData       rtn = new OptData();
            StringBuilder sb  = new StringBuilder();

            try
            {
                LuaMap root = GetLuaTable(v_data._data);
                sb.Append("--[[\r\n");
                v_data.opt_note(sb, "note");
                sb.Append("\r\n");
                sb.Append("colums:\r\n");
                v_data.opt_colum_notes(sb);
                sb.Append("\r\n");
                sb.Append("primary key:\r\n");
                for (int i = 0; i < v_data.sheet_bins.Count; i++)
                {
                    sb.AppendFormat("#{0} [{1}]: ", i, v_data.sheet_bins[i].sheetName);
                    sb.Append(string.Join(",", v_data.sheet_bins[i].indexData.pmKey));
                    sb.Append("\r\n");
                }
                sb.Append("]]\r\n");

                if (v_data.IsDataPersistence)
                {
                    sb.AppendFormat("if ddt[v_data.className] ~= nil then\r\n\treturn {0}\r\nend\r\n", v_data.className);
                    sb.AppendFormat("local {0} = ", v_data.className);
                    root.outputValue(sb, 0);
                    sb.AppendLine();
                    sb.AppendFormat("ddt[v_data.className] = {0}\r\n", v_data.className);
                    sb.AppendFormat("SetLooseReadonly({0})\r\n", v_data.className);
                    sb.AppendFormat("return {0}", v_data.className);
                }
                else
                {
                    sb.Append("return");
                    root.outputValue(sb, 0);
                }
            }
            catch (Exception ex)
            {
                rtn.errList.Add("导出基础数据时出现错误,错误信息为:\r\n" + ex.ToString());
            }
            rtn.content = sb.ToString();
            return(rtn);
            //sb.Append(string.Format("\r\nreturn {0}", curIndex.className));
        }