示例#1
0
 static NickNameColCatchManager()
 {
     s_Instence            = new NickNameColCatchManager();
     s_typeName            = new Dictionary <string, string>();
     s_typeName["intX"]    = "int";
     s_typeName["cstring"] = "string";
 }
示例#2
0
        protected override bool _OnInit(string v_strCellVal)
        {
            NickNameColCatchManager nickNameColCatchManager = NickNameColCatchManager.getInstence();

            if (!nickNameColCatchManager.checkData(m_type, v_strCellVal, out _data))
            {
                Debug.Error("没有找到名为[{0}]的类型为{1}的ID", v_strCellVal, m_type);
                return(false);
            }
            return(true);
        }
示例#3
0
        private void frmMain_Load(object sender, EventArgs e)
        {
            try
            {
                Config.load();
            }
            catch (Exception ex) { Debug.Error("xml解析时失败" + ex.ToString()); }
            //加载luastate
            LuaState.Init(Config.luaCfgPath + "main.lua");
            LuaState.SetPath(Config.luaCfgPath);
            LuaState.DoMain();
            cliPath   = Config.cliPath;
            servPath  = Config.servPath;
            excelPath = Config.excelPath;
            Excel.Workbook  indexBook  = new Excel.Workbook(Config.indexPath);
            Excel.Worksheet indexSheet = indexBook.Worksheets["index"];
            Excel.Cells     data       = indexSheet.Cells;
            SheetHeader     header     = new SheetHeader();

            header.readHeader(indexSheet);
            List <NameCatchIndexData> nameCatchIndexDatas = new List <NameCatchIndexData>();

            //读取需要索引的数据列表
            for (int row = 1; row < 200; row++)
            {
                if (data[row, 0].Value == null || string.IsNullOrWhiteSpace(data[row, 0].Value.ToString()))
                {
                    break;
                }
                NameCatchIndexData rowData = new NameCatchIndexData();
                rowData.readData(data, row, header);
                nameCatchIndexDatas.Add(rowData);
            }
            NickNameColCatchManager nickNameColCatchManager = NickNameColCatchManager.getInstence();

            //打开各表,生成各名称ID转换
            foreach (NameCatchIndexData curIndex in nameCatchIndexDatas.ToArray())
            {
                string          excelPath = Config.excelPath + curIndex.excelFileName + ".xlsx";
                Excel.Worksheet sheet     = null;
                if (!File.Exists(excelPath))
                {
                    Debug.Error("{0}不存在", excelPath);
                    return;
                }
                try
                {
                    Excel.Workbook book = new Excel.Workbook(excelPath);
                    sheet = book.Worksheets[curIndex.sheetName];
                    if (sheet == null)
                    {
                        Debug.Exception("没有找到名为[" + curIndex.sheetName + "]的sheet");
                    }
                }
                catch (Exception ex) {
                    Debug.Error(ex.ToString());
                    Application.Exit();
                    return;
                }
                SheetHeader theHeader = new SheetHeader();
                theHeader.readHeader(sheet, curIndex.headRow - 1);
                int idColIndex = theHeader[curIndex.columName];
                if (idColIndex == -1)
                {
                    Debug.Error("{1}  列{0}不存在", curIndex.columName, curIndex.excelFileName + "[" + curIndex.sheetName + "]");
                    return;
                }
                int noteIndex = theHeader[curIndex.noteColName];
                if (noteIndex == -1)
                {
                    Debug.Error("{1}  列{0}不存在", curIndex.noteColName, curIndex.excelFileName + "[" + curIndex.sheetName + "]");
                    return;
                }
                Excel.Cells theDatas = sheet.Cells;
                for (int row = curIndex.dataRowBegin - 1; row < 100000; row++)
                {
                    nickNameColCatchManager.createCatch(curIndex.fieldName, curIndex.valueType);
                    if (theDatas[row, 0].Value == null || string.IsNullOrWhiteSpace(theDatas[row, 0].Value.ToString()))
                    {
                        break;
                    }
                    try
                    {
                        int    id       = theDatas[row, idColIndex].IntValue;
                        string nickName = theDatas[row, noteIndex].StringValue;
                        nickNameColCatchManager.addData(curIndex.fieldName, nickName, id);
                    }
                    catch (Exception ex)
                    {
                        Debug.Error("{0}表[{1}],第{2}行出错啦,错误信息为:\r\n  " + ex.ToString(), curIndex.excelFileName, curIndex.sheetName, row + 1);
                        return;
                    }
                }
            }
        }
示例#4
0
 static NickNameColCatchManager()
 {
     s_Instence = new NickNameColCatchManager();
 }
示例#5
0
        protected void _load()
        {
            //加载luastate
            if (Config.bLoadLua)
            {
                updateDesc("加载luastate......");
                try
                {
                    LuaState.Init(Config.luaCfgPath + "main.lua");
                    LuaState.SetPath(Config.luaCfgPath);
                    LuaState.DoMain();
                }
                catch (Exception ex)
                {
                    Debug.Error("加载lua报错,信息是" + ex.ToString());
                    return;
                }
                updateDesc("luastate加载完成");
            }
            Thread.Sleep(50);
            if (Config.bReadIndex)
            {
                updateDesc("读取INDEX表......");
                Excel.Workbook  indexBook  = new Excel.Workbook(Config.indexPath);
                Excel.Worksheet indexSheet = indexBook.Worksheets["index"];
                Excel.Cells     data       = indexSheet.Cells;
                SheetHeader     header     = new SheetHeader();
                header.readHeader(indexSheet);
                List <NameCatchIndexData> nameCatchIndexDatas = new List <NameCatchIndexData>();

                //读取需要索引的数据列表
                for (int row = 1; row < 200; row++)
                {
                    if (data[row, 0].Value == null || string.IsNullOrWhiteSpace(data[row, 0].Value.ToString()))
                    {
                        break;
                    }
                    NameCatchIndexData rowData = new NameCatchIndexData();
                    rowData.readData(data, row, header);
                    nameCatchIndexDatas.Add(rowData);
                }
                updateDesc("INDEX表读取完成");
                Thread.Sleep(50);
                updateDesc("根据INDEX表加载各名称表......");
                NickNameColCatchManager nickNameColCatchManager = NickNameColCatchManager.getInstence();
                nickNameColCatchManager.init();
                Thread.Sleep(50);
                //打开各表,生成各名称ID转换
                foreach (NameCatchIndexData curIndex in nameCatchIndexDatas.ToArray())
                {
                    string excelPath = Config.excelPath + curIndex.excelFileName;
                    updateDesc(string.Format("加载表{0},处理名称{1}......", curIndex.excelFileName, curIndex.fieldName));
                    Excel.Worksheet sheet = null;
                    if (!File.Exists(excelPath))
                    {
                        Debug.Error("{0}不存在", excelPath);
                        return;
                    }
                    try
                    {
                        Excel.Workbook book = new Excel.Workbook(excelPath);
                        sheet = book.Worksheets[curIndex.sheetName];
                        if (sheet == null)
                        {
                            Debug.Exception("没有找到名为[" + curIndex.sheetName + "]的sheet");
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.Error(ex.ToString());
                        Application.Exit();
                        return;
                    }
                    SheetHeader theHeader = new SheetHeader();
                    theHeader.readHeader(sheet, curIndex.headRow - 1);
                    int idColIndex = theHeader[curIndex.columName];
                    if (idColIndex == -1)
                    {
                        Debug.Error("{1}  列{0}不存在", curIndex.columName, curIndex.excelFileName + "[" + curIndex.sheetName + "]");
                        return;
                    }
                    int noteIndex = theHeader[curIndex.noteColName];
                    if (noteIndex == -1)
                    {
                        Debug.Error("{1}  列{0}不存在", curIndex.noteColName, curIndex.excelFileName + "[" + curIndex.sheetName + "]");
                        return;
                    }
                    Excel.Cells theDatas = sheet.Cells;
                    for (int row = curIndex.dataRowBegin - 1; row < 100000; row++)
                    {
                        nickNameColCatchManager.createCatch(curIndex.fieldName, curIndex.valueType);
                        if (theDatas[row, 0].Value == null || string.IsNullOrWhiteSpace(theDatas[row, 0].Value.ToString()))
                        {
                            break;
                        }
                        try
                        {
                            long   id       = long.Parse(theDatas[row, idColIndex].StringValue);
                            string nickName = theDatas[row, noteIndex].StringValue;
                            nickNameColCatchManager.addData(curIndex.fieldName, nickName, id);
                        }
                        catch (Exception ex)
                        {
                            Debug.Error("{0}表[{1}],第{2}行出错啦,错误信息为:\r\n  " + ex.ToString(), curIndex.excelFileName, curIndex.sheetName, row + 1);
                            return;
                        }
                    }
                    updateDesc(string.Format("表{0}加载完成", curIndex.excelFileName));
                    Thread.Sleep(50);
                }
            }
            else
            {
                updateDesc("INDEX表没有配置,不加载nickNameCatch");
                Thread.Sleep(50);
            }
            workFinished();
        }