Пример #1
0
        /// <summary />
        private T ExecuteInternalCommand <T>(Func <T> action)
        {
            ResetException();

            try
            {
                // Commom operations before execution
                this.OperationsBeforeExecution();

                // Send the request to the Database server
                T result = action.Invoke();

                // Action After Execution
                if (this.ActionAfterExecution != null &&
                    typeof(T) != typeof(System.Data.DataSet))
                {
                    var tables = DataTableConvertor.ToDataTable(result);
                    this.ActionAfterExecution.Invoke(this, tables);
                }

                return(result);
            }
            catch (DbException ex)
            {
                return(ThrowSqlExceptionOrDefaultValue <T>(ex));
            }
        }
Пример #2
0
        public void DataTableConvertor_ArrayOfIntegers_Test()
        {
            var data = new[] { 1, 2 };

            var table = DataTableConvertor.ToDataTable(data).First();

            Assert.AreEqual("Column", table.Columns[0].ColumnName);
            Assert.AreEqual(1, table.Rows[0][0]);
            Assert.AreEqual(2, table.Rows[1][0]);
        }
Пример #3
0
    public void RefreshTableData()
    {
        m_FilesDict      = new Dictionary <string, string>();
        m_TableInfos     = new List <TableInfo>();
        m_ExportTabInfos = new List <TableInfo>();
        string[] files = null;
        if (!Directory.Exists(m_DataFullPath))
        {
            return;
        }
        files = Directory.GetFiles(m_DataFullPath, "*.xlsx", SearchOption.AllDirectories);
        int       cnt  = files.Length;
        TableInfo info = null;

        for (int idx = 0; idx < cnt; ++idx)
        {
            string file = files[idx];
            if (file.Contains("Server"))
            {
                continue;
            }
            string fileName = file.Substring(file.LastIndexOf('\\') + 1);
            fileName = fileName.Substring(0, fileName.IndexOf("."));
            if (m_FilesDict.ContainsKey(fileName))
            {
                Debug.LogError("The table named '" + fileName + "' has existed!");
                continue;
            }
            if (fileName.Contains("~"))
            {
                continue;
            }
            m_FilesDict.Add(fileName, file);

            info = new TableInfo();
            info.m_ExportClassName = DataTableConvertor.HandleName(fileName);
            info.m_RealName        = fileName;
            info.m_FullName        = file;
            info.m_IsSelected      = false;
            m_TableInfos.Add(info);
        }

        // 对表格按字典排序
        m_TableInfos.Sort((TableInfo a, TableInfo b) =>
        {
            return(a.m_RealName.CompareTo(b.m_RealName));
        });

        for (int i = 0; i < m_TableInfos.Count; i++)
        {
            m_TableConvertor.Convert(m_TableInfos[i]);
        }
        //        m_TableConvertor.ExportDataTableScript(m_TableInfos);
    }
Пример #4
0
        private T ExecuteInternalCommand <T>(Func <T> action)
        {
            ResetException();

            try
            {
                Update_CommandDotCommandText_If_CommandText_IsNew();

                // Action Before Execution
                if (this.ActionBeforeExecution != null)
                {
                    this.ActionBeforeExecution.Invoke(this);
                    Update_CommandDotCommandText_If_CommandText_IsNew();
                }

                // Replace null parameters by DBNull value.
                this.Replace_ParametersNull_By_DBNull();

                // Log
                if (this.Log != null)
                {
                    this.Log.Invoke(this.Command.CommandText);
                }

                // Send the request to the Database server
                T result = action.Invoke();

                // Action After Execution
                if (this.ActionAfterExecution != null &&
                    typeof(T) != typeof(System.Data.DataSet))
                {
                    var tables = DataTableConvertor.ToDataTable(result);
                    this.ActionAfterExecution.Invoke(this, tables);
                }

                return(result);
            }
            catch (DbException ex)
            {
                return(ThrowSqlExceptionOrDefaultValue <T>(ex));
            }
        }
Пример #5
0
    void Init()
    {
        m_GUIStyle = new GUIStyle();

        #region AssetBundle
        m_CurStep   = ExportStep.STEP_BEGIN;
        m_TotalStep = ExportStep.STEP_END;

        RefreshExportInfo();
        #endregion

        #region DataTable
        m_IsStartExport  = false;
        m_ExportTabNum   = 0;
        m_TableConvertor = new DataTableConvertor();

        // 枚举出所有的配表
        m_DataFullPath = Application.dataPath + "/" + m_DataTablePath;
//        m_OtherDataFullPath = Application.dataPath + "/../" + m_OtherDataTablePath;
        RefreshTableData();
        #endregion
    }
Пример #6
0
        public void DataTableConvertor_ArrayOfObjects_Test()
        {
            var data = new[]
            {
                new Employee {
                    Id = 1, Name = "Denis", Birthdate = new DateTime(2019, 12, 29)
                },
                new Employee {
                    Id = 2, Name = "Anne", Birthdate = new DateTime(2018, 10, 26)
                },
            };

            var table = DataTableConvertor.ToDataTable(data).First();

            Assert.AreEqual("Id", table.Columns[0].ColumnName);
            Assert.AreEqual("Name", table.Columns[1].ColumnName);
            Assert.AreEqual("string", table.Columns[1].CSharpType);
            Assert.AreEqual("Birthdate", table.Columns[2].ColumnName);
            Assert.AreEqual("DateTime", table.Columns[2].CSharpType);
            Assert.AreEqual(true, table.Columns[2].IsNullable);

            Assert.AreEqual(1, table.Rows[0][0]);
            Assert.AreEqual(2, table.Rows[1].Field <int>("Id"));
        }
Пример #7
0
    void DrawExportDataTableWindow()
    {
        titleContent.text = "导出DataTable";
        // 出错了
        if (m_ExportTabInfos == null)
        {
            m_GUIStyle.fontSize         = 30;
            m_GUIStyle.fontStyle        = FontStyle.Bold;
            m_GUIStyle.normal.textColor = Color.red;
            GUILayout.Label("请重新扫描表格文件!!!", m_GUIStyle);
            if (GUILayout.Button("重新扫描表格文件", GUILayout.Width(500), GUILayout.Height(30)))
            {
                if (m_TableConvertor == null)
                {
                    m_TableConvertor = new DataTableConvertor();
                }
                RefreshTableData();
            }
            return;
        }

        EditorGUILayout.Separator();
        GUI.contentColor   = Color.white;
        m_IsExportAllTable = EditorGUILayout.Toggle("是否要导出全部表格", m_IsExportAllTable, GUILayout.Width(300));
        EditorGUILayout.Separator();
        GUI.contentColor = Color.green;
        GUILayout.TextArea("【导出】:将所选Excel表全部导出为txt格式,并生成对应的脚本如Table_HeroAttr.cs。如果是全部导出,则在导出完毕后会自动生成DataTable.cs文件;如果是部分导出且增加了表格文件,则需要【导出DataTable.cs】。", GUILayout.MaxWidth(500));
        GUI.contentColor = Color.white;
        if (GUILayout.Button("导出", GUILayout.Width(500), GUILayout.Height(50)))
        {
            if (!m_IsExportAllTable)
            {
                if (m_ExportTabInfos.Count == 0)
                {
                    EditorUtility.DisplayDialog("提示", "请选择需要导出的表格", "关闭");
                    return;
                }
                if (EditorUtility.DisplayDialog("提示!!!", "确定要导出所选表格?", "确定", "取消"))
                {
                    StartExport();
                }
            }
            else
            {
                if (EditorUtility.DisplayDialog("提示!!!", "确定要导出所有表格?", "确定", "取消"))
                {
                    StartExport();
                }
            }
        }

        EditorGUILayout.Separator();
        GUI.contentColor = Color.green;
        GUILayout.TextArea("【转为二进制】:将所选Excel表导出的txt文件全部转出二进制格式,此功能仅用于测试。", GUILayout.MaxWidth(500));
        GUI.contentColor = Color.white;
        if (GUILayout.Button("转为二进制", GUILayout.Width(500), GUILayout.Height(30)))
        {
            if (EditorUtility.DisplayDialog("提示!!!", "确定要将所选表格转为二进制?", "确定", "取消"))
            {
                string[] convertFiles;
                int      fileCnt  = 0;
                string   fileName = "";
                if (m_IsExportAllTable)
                {
                    fileCnt      = m_TableInfos.Count;
                    convertFiles = new string[fileCnt];
                    for (int idx = 0; idx < fileCnt; ++idx)
                    {
                        fileName          = Path.GetFileNameWithoutExtension(m_TableInfos[idx].m_FullName);
                        fileName         += ".txt";
                        fileName          = Application.dataPath + m_TableConvertor.m_TableExportPath + fileName;
                        convertFiles[idx] = fileName;
                    }
                }
                else
                {
                    fileCnt      = m_ExportTabInfos.Count;
                    convertFiles = new string[fileCnt];
                    for (int idx = 0; idx < fileCnt; ++idx)
                    {
                        fileName          = Path.GetFileNameWithoutExtension(m_ExportTabInfos[idx].m_FullName);
                        fileName         += ".txt";
                        fileName          = Application.dataPath + m_TableConvertor.m_TableExportPath + fileName;
                        convertFiles[idx] = fileName;
                    }
                }
                //                TxtConvertTool.ConvertSelectedTxt(convertFiles);
            }
        }
        EditorGUILayout.Separator();
        if (GUILayout.Button("重新扫描表格文件", GUILayout.Width(500), GUILayout.Height(30)))
        {
            RefreshTableData();
        }
        EditorGUILayout.Separator();
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("打开脚本导出目录", GUILayout.MaxWidth(240), GUILayout.Height(30)))
        {
            string exportPath = Application.dataPath + "/ExportDataByExcel/Scripts/Core/Configs/DataTable/";
            Process.Start(exportPath);
        }
        GUILayout.Space(20);
        if (GUILayout.Button("打开TXT导出目录", GUILayout.MaxWidth(240), GUILayout.Height(30)))
        {
            string exportPath = Application.dataPath + "/Resources/DataTable/";
            Process.Start(exportPath);
        }
        EditorGUILayout.EndHorizontal();
        DrawReverseUI();

        DrawSelectTableUI();

        if (m_IsStartExport)
        {
            float percent = 0;
            if (m_IsExportAllTable)
            {
                percent = (m_CurExportTabIdx + 1) / (float)m_TableInfos.Count;
            }
            else
            {
                percent = (m_CurExportTabIdx + 1) / (float)m_ExportTabInfos.Count;
            }
            EditorUtility.DisplayProgressBar("当前导出表格:" + m_CurExportTabInfo.m_RealName + "...", percent.ToString("0%"), percent);
        }
    }