当前位置: 首页 > news >正文

建设玩外汇平台网站如何用dw做网站前端

建设玩外汇平台网站,如何用dw做网站前端,wordpress可以做外贸,宁波网站建设哪里有1、功能介绍 通过Excel表配置表数据#xff0c;一键生成对应Excel配置表的数据结构类、数据容器类、已经二进制数据文件#xff0c;加载二进制数据文件获取所有表数据 需要使用Excel读取的dll包 2、关键代码 2.1 ExcelTool类 实现一键生成Excel配置表的数据结构类、数据…1、功能介绍 通过Excel表配置表数据一键生成对应Excel配置表的数据结构类、数据容器类、已经二进制数据文件加载二进制数据文件获取所有表数据 需要使用Excel读取的dll包 2、关键代码 2.1 ExcelTool类 实现一键生成Excel配置表的数据结构类、数据容器类、已经二进制数据文件 using Excel; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.IO; using System.Text; using UnityEditor; using UnityEngine;public class ExcelTool {/// summary/// excel文件存放路径/// /summarypublic static string EXCEL_PATH Application.dataPath /ArtRes/Excel/;/// summary/// 数据结构类脚本存储路径/// /summarypublic static string DATA_CLASS_PATH Application.dataPath /Scripts/ExcelData/DataClass/;/// summary/// 容器类脚本存储路径/// /summarypublic static string DATA_CONTAINER_PATH Application.dataPath /Scripts/ExcelData/Container/;/// summary/// 二进制数据存储路径/// /summary//public static string DATA_BINARY_PATH Application.streamingAssetsPath /Bianry/;/// summary/// 真正内容开始行号/// /summarypublic static int BEGIN_INDEX 4;[MenuItem(GameTool/GenerateExcelInfo)]private static void GenerateExcelInfo(){//加载指定路径中的所有Excel文件 用于生成对应的3个文件DirectoryInfo dInfo Directory.CreateDirectory(EXCEL_PATH);//得到指定路径中的所有文件信息 相当于就是得到所有的Exce1表FileInfo[] files dInfo.GetFiles();//数据容器DataTableCollection tableCollection;for (int i 0; i files.Length; i){//如果不是Excel文件就不要处理if (files[i].Extension ! .xlsx files[i].Extension ! .xls)continue;//打开一个excel文件得到其中所有表的数据using(FileStream fs files[i].Open(FileMode.Open, FileAccess.Read)){IExcelDataReader excelReader ExcelReaderFactory.CreateOpenXmlReader(fs);tableCollection excelReader.AsDataSet().Tables;fs.Close();}//遍历文件中的所有表的信息foreach (DataTable table in tableCollection){Debug.Log(table.TableName);//生成数据结构类GenerateExcelDataClass(table);//生成容器类GenerateExcelContainer(table);//生成2进制数据GenerateExcelBinary(table);}}}/// summary/// 生成Excel表对应的数据结构类/// /summary/// param nametable/paramprivate static void GenerateExcelDataClass(DataTable table){//字段名行DataRow rowName GetVariableNameRow(table);//字段类型行DataRow rowType GetVariableTypeRow(table);//判断路径是否存在 没有的话 就创建文件夹if (!Directory.Exists(DATA_CLASS_PATH))Directory.CreateDirectory(DATA_CLASS_PATH);//如果我们要生成对应的数据结构类脚本 其实就是通过代码进行字符串拼接 然后存进文件就行了string str public class table.TableName \n{\n;//变量进行字符串拼接for (int i 0; i table.Columns.Count; i){str \tpublic rowType[i].ToString() rowName[i].ToString() ;\n;}str }\n;//把拼接好的字符串存进占地文件中File.WriteAllText(DATA_CLASS_PATH table.TableName .cs, str);//刷新Project窗口AssetDatabase.Refresh();}/// summary/// 生成Excel表对应的数据容器类/// /summary/// param nametable/paramprivate static void GenerateExcelContainer(DataTable table){//得到主键索引int keyIndex GetKeyIndex(table);//得到字段类型行DataRow rowType GetVariableTypeRow(table);//没有路径就创建路径if (!Directory.Exists(DATA_CONTAINER_PATH)) Directory.CreateDirectory (DATA_CONTAINER_PATH);string str using System.Collections.Generic;\n\n;str public class table.TableName Container \n{\n;str \tpublic Dictionary rowType[keyIndex].ToString() , table.TableName ;str dataDic new Dictionary rowType[keyIndex].ToString() , table.TableName ();\n;str };File.WriteAllText(DATA_CONTAINER_PATH table.TableName Container.cs, str);//刷新Project窗口AssetDatabase.Refresh();}/// summary/// 生成Excel 2进制数据/// /summary/// param nametable/paramprivate static void GenerateExcelBinary(DataTable table){//没有路径创建路径if(!Directory.Exists(BinaryDataMgr.DATA_BINARY_PATH)) Directory.CreateDirectory(BinaryDataMgr.DATA_BINARY_PATH);//创建一个2进制文件进行写入using(FileStream fs new FileStream(BinaryDataMgr.DATA_BINARY_PATH table.TableName .zhou, FileMode.OpenOrCreate, FileAccess.Write)){//存储具体的Excel对应的2进制信息//1.先要存储需要写的行数//-4 因为前面4行是配置规则 不是需要记录的数据内容fs.Write(BitConverter.GetBytes(table.Rows.Count - 4), 0, 4);//2.存储主键的变量名string keyName GetVariableNameRow(table)[GetKeyIndex(table)].ToString();byte[] bytes Encoding.UTF8.GetBytes(keyName);//存储字符串字节数据的长度fs.Write(BitConverter.GetBytes(keyName.Length), 0, 4);//存储字符串字节数组fs.Write(bytes, 0, bytes.Length);//遍历所有内容的行 进行2进制的写入DataRow row;//得到类型行 根据类型来决定应该如何写入DataRow rowType GetVariableTypeRow(table);for (int i BEGIN_INDEX; i table.Rows.Count; i){//得到一行的数据row table.Rows[i];for (int j 0; j table.Columns.Count; j){switch(rowType[j].ToString()){case int:fs.Write(BitConverter.GetBytes(int.Parse(row[j].ToString())), 0, 4);break;case float:fs.Write(BitConverter.GetBytes(float.Parse(row[j].ToString())), 0, 4);break;case bool:fs.Write(BitConverter.GetBytes(bool.Parse(row[j].ToString())), 0, 1);break;case string:bytes Encoding.UTF8.GetBytes(row[j].ToString());//写入字节数据的长度fs.Write(BitConverter.GetBytes(bytes.Length), 0, 4);//写入字符串字节数组fs.Write(bytes, 0, bytes.Length);break;}}}fs.Close();}AssetDatabase.Refresh();}/// summary/// 获取变量名所在行/// /summary/// param nametable/param/// returns/returnsprivate static DataRow GetVariableNameRow(DataTable table){return table.Rows[0];}/// summary/// 获取变量类型所在行/// /summary/// param nametable/param/// returns/returnsprivate static DataRow GetVariableTypeRow(DataTable table){return table.Rows[1];}/// summary/// 获取主键索引/// /summary/// param nametable/param/// returns/returnsprivate static int GetKeyIndex(DataTable table){DataRow row table.Rows[2];for (int i 0;i table.Columns.Count; i){if (row[i].ToString() key)return i;}return 0;}}2.2 BinaryDataMgr 保存数据读取数据 读取Excel表生成的二进制文件加载到内容中以供使用 using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Reflection; using System.Runtime.Serialization.Formatters.Binary; using System.Text; using UnityEngine;/// summary /// 2进制数据管理器 /// /summary public class BinaryDataMgr {private static BinaryDataMgr instance new BinaryDataMgr();public static BinaryDataMgr Instance instance;private BinaryDataMgr() { }/// summary/// 用于存储所有Excel表数据的容器/// /summaryprivate Dictionarystring, object tableDic new Dictionarystring, object();/// summary/// 数据存储路径/// /summaryprivate static string SAVE_PATH Application.persistentDataPath /Data/;/// summary/// 二进制数据存储路径/// /summarypublic static string DATA_BINARY_PATH Application.streamingAssetsPath /Bianry/;public void InitData(){//加载自己的表到内存//LoadTableTowerInfoContainer, TowerInfo();//LoadTablePlayerInfo1Container, PlayerInfo1();//LoadTableTestInfoContainer, TestInfo();}/// summary/// 加载Excel表的2进制数据到内存中/// /summary/// typeparam nameT容器类名/typeparam/// typeparam nameK数据结构体类名/typeparampublic void LoadTableT, K(){//读取Excel表对应的2进制文件 来进行解析using (FileStream fs File.Open(DATA_BINARY_PATH typeof(K).Name .zhou, FileMode.Open, FileAccess.Read)){byte[] bytes new byte[fs.Length];fs.Read(bytes, 0, bytes.Length);fs.Close();//用于记录当前读取了多少字节int index 0;//读取多少行数据int count BitConverter.ToInt32 (bytes, index);index 4;//读取主键的名字int keyNameLength BitConverter.ToInt32 (bytes, index);index 4;string keyName Encoding.UTF8.GetString(bytes, index, keyNameLength);index keyNameLength;//创建容器类对象Type contaninerType typeof (T);object contaninerObj Activator.CreateInstance(contaninerType);//得到数据结构类TypeType classType typeof(K);//通过反射得到数据结构类 所有字段的信息FieldInfo[] infos classType.GetFields();//读取每一行的信息for (int i 0; i count; i){//实例化一个结构对象类 对象object dataObj Activator.CreateInstance(classType);foreach (FieldInfo info in infos){if(info.FieldType typeof(int)){//相当于将2进制数据转为int 然后赋值给对应字段info.SetValue(dataObj, BitConverter.ToInt32(bytes, index));index 4;}else if (info.FieldType typeof(float)){info.SetValue(dataObj, BitConverter.ToSingle(bytes, index));index 4;}else if (info.FieldType typeof(bool)){info.SetValue(dataObj, BitConverter.ToBoolean(bytes, index));index 1;}else if (info.FieldType typeof(string)){//读取字符串字节数组长度int length BitConverter.ToInt32(bytes, index);index 4;info.SetValue(dataObj, Encoding.UTF8.GetString(bytes, index, length));index length;}}//读取完一行的数据后 将这个数据存到容器对象中object dicObj contaninerType.GetField(dataDic).GetValue(contaninerObj);//得到容器字段对象MethodInfo mInfo dicObj.GetType().GetMethod(Add);//得到数据结构类对象中 指定主键字段的值object keyValue classType.GetField(keyName).GetValue(dataObj);mInfo.Invoke(dicObj, new object[] { keyValue, dataObj });}//把读取完的表记录下来tableDic.Add(typeof(T).Name, contaninerObj);fs.Close();}}/// summary/// 得到一张表的信息/// /summary/// typeparam nameT容器类名/typeparam/// returns/returnspublic T GetTableT() where T : class{string tableName typeof(T).Name;if(tableDic.ContainsKey(tableName)){return tableDic[tableName] as T;}return null;}/// summary/// 存储类对象数据/// /summary/// param namedata/param/// param namefileName/parampublic void Save(object data, string fileName){if(!Directory.Exists(SAVE_PATH)){Directory.CreateDirectory(SAVE_PATH);}using(FileStream fs new FileStream(SAVE_PATH fileName .zhou, FileMode.OpenOrCreate, FileAccess.Write)){BinaryFormatter bf new BinaryFormatter();bf.Serialize(fs, data);fs.Flush();fs.Close();}}/// summary/// 读取2进制数据转换成对象/// /summary/// typeparam nameT/typeparam/// param namefileName/param/// returns/returnspublic T LoadT(string fileName) where T : class{if(!File.Exists(SAVE_PATH fileName .zhou)){return default(T);}T data;using(FileStream fs new FileStream(SAVE_PATH fileName .zhou, FileMode.Open, FileAccess.Read)){BinaryFormatter bf new BinaryFormatter();data bf.Deserialize(fs) as T;fs.Close();}return data;}}3、使用步骤 3.1 根据规则创建Excel配置表 创建的Excel表需要放置到ArtRes/Excel路径下 Excel配置规则 第一行字段名    第二行字段类型字段类型一定不要配置错误字段类型目前只支持int float bool string如果想要在添加类型需要ExcelTool的GenerateExcelBianary和BianryDataMgr的LoadTable方法当中对应添加读写的逻辑    第三行主键是哪一个字段 需要通过key来标识主键    第四行描述信息只是给别人看不会有别的作用    第五行~第n行就是具体数据信息    下方的表名决定类数据结构类容器类2进制文件的文件名 3.2 点击按钮GenerateExcelInfo 生成所有Excel表的数据结构类、数据结构容器类和二进制数据文件 3.3 完善BinaryDataMgr的InitData()方法将自己创建的表进行加载 public void InitData(){//加载自己的表到内存//LoadTableTowerInfoContainer, TowerInfo();//LoadTablePlayerInfo1Container, PlayerInfo1();//LoadTableTestInfoContainer, TestInfo();LoadTableWeaponItemContainer, WeaponItem();} 3.4 初始化数据加载数据到内存 BinaryDataMgr.Instance.InitData()        加载二进制数据到内存当中 BinaryDataMgr.Instance.GetTableTowerInfoContainer()        获取需要使用的表的数据 BinaryDataMgr.Instance.InitData();WeaponItemContainer data BinaryDataMgr.Instance.GetTableWeaponItemContainer();foreach (var item in data.dataDic.Values){Debug.Log($id:{item.id}-name:{item.name}-des:{item.des}-money:{item.money}-ATK:{item.atk});}
http://www.hkea.cn/news/14555425/

相关文章:

  • 网站建设 php网站seo检测报告
  • 做趣味图形的网站网络营销的五个特点
  • 专业建设网站山东手机网站建设电话
  • 前端开发是做网站的吗在线设计平台的市场调研
  • 网站建设5000费用预算桂林智能网络营销好选择
  • 大型网站建设推荐河南和城乡建设厅网站
  • 企业网站改版计划书中交上航建设网站
  • 长沙营销型网站开发做网站一定要会ps么
  • 新手学做网站 pdf 下载卖域名的网站哪些好
  • 集团网站建设活动方案2008iis里没加域名 网站指向还在
  • 手机网站建设wap网络营销与策划书
  • html静态网站模板下载中国建设网站工程承包分包法
  • 重庆水舟科技做网站wordpress打开速度慢解决办法
  • 通州郑州阳网站建设wordpress无限地址
  • 南京市高淳区城乡建设局网站大网站建设规范
  • 手机如何建立自己网站上海互联网网站建设公司
  • 网址导航网站一键建设海南创作什么网站
  • 成都网站开发环球中心五 网站开发总体进度安排
  • 网站建设到上线的步骤过程软件开发专业专科学校
  • 网站数据丢失了做数据恢复需多久成都海鸥手表网站
  • 成都门户网站建设中铁建设集团有限公司电话
  • 河北涿州网站建设装修网站有哪些
  • 微网站建设市场分析业务宣传网站建设
  • 公司是做网站建设的怎么开票制作app界面
  • 专门做运动装备的网站网站模板编辑
  • 做网站网页的公司dede 网站模板
  • 电商网站商品详情页网站引导页是什么
  • 网站如何链接备案系统濮阳 网站建设
  • 温州网站建设价格不备案的网站能上去吗
  • wordpress 增删改查seo实战密码第三版pdf