コード例 #1
0
    private void OnConnectionEvent(object sender, ConnectionMsg e)
    {
        DebugInfo.text = string.Format("new connection: recHostId: {0}, connectionId: {1},channelId:{2}, Ip: {3}, Port: {4}", e.HostId, e.ConnectionId, e.ChannelId, e.ClientIp, e.ClientPort);
        ClientInstance client = Instantiate(Client, Clients.transform);

        client.ClientInfo   = string.Format("ID: {0}   IP:{1}  Port:{2}", e.ConnectionId, e.ClientIp, e.ClientPort);
        client.HostId       = e.HostId;
        client.ConnectionId = e.ConnectionId;
        client.ChannelId    = myReliableChannelId;
        _clientObjects      = Clients.GetComponentsInChildren <ClientInstance>();
    }
コード例 #2
0
 private void OnDisconnectionEvent(object sender, ConnectionMsg e)
 {
     DebugInfo.text = string.Format("disconnection: recHostId:{0}, connectionId:{1},channelId:{2}", e.HostId,
                                    e.ConnectionId, e.ChannelId);
     foreach (ClientInstance item in _clientObjects)
     {
         if (item.ConnectionId == e.ConnectionId)
         {
             Destroy(item.gameObject);
         }
     }
 }
コード例 #3
0
    private void Test_ConnectionEvent(object sender, ConnectionMsg e)
    {
        Debug.Log(string.Format("new connection: recHostId: {0}, connectionId: {1},channelId:{2}, Ip: {3}, Port: {4}", e.HostId, e.ConnectionId, e.ChannelId, e.ClientIp, e.ClientPort));
        //throw new NotImplementedException();
        ClientInstance client = Instantiate(Client, Clients.transform);

        client.ClientInfo   = string.Format("ID: {0}   IP:{1}  Port:{2}", e.ConnectionId, e.ClientIp, e.ClientPort);
        client.HostId       = e.HostId;
        client.ConnectionId = e.ConnectionId;
        client.ChannelId    = myReliableChannelId;
        ClientsList.Add(client);
        _clientObjects = Clients.GetComponentsInChildren <ClientInstance>();
    }
コード例 #4
0
 private void Test_DisconnectionEvent(object sender, ConnectionMsg e)
 {
     Debug.Log(string.Format("disconnection: recHostId:{0}, connectionId:{1},channelId:{2}", e.HostId, e.ConnectionId, e.ChannelId));
     //throw new NotImplementedException();
     for (int i = 0; i < ClientsList.Count; i++)
     {
         if (ClientsList[i].ConnectionId == e.ConnectionId)
         {
             ClientsList.RemoveAt(i);
         }
     }
     foreach (ClientInstance item in _clientObjects)
     {
         if (item.ConnectionId == e.ConnectionId)
         {
             Destroy(item.gameObject);
         }
     }
 }
コード例 #5
0
        //扩展其他数据库操作方法

        /// <summary>
        /// 获取当前承载库
        /// </summary>
        /// <returns></returns>
        public static ConnectionMsg GetCurConnection()
        {
            return(ConnectionMsg.GetCurConnection());
        }
コード例 #6
0
ファイル: ReportAppService.cs プロジェクト: radtek/Fms
        /// <summary>
        /// 根据传入code执行报表,返回datatable
        /// </summary>
        /// <param name="code"></param>
        /// <param name="queryParams"></param>
        /// <param name="err"></param>
        /// <returns></returns>
        public DataTable GetDataTableFromCode(string code, string queryParams, ref ErrorInfo err)
        {
            DataTable dt = new DataTable();

            if (!string.IsNullOrEmpty(code))
            {
                var ent = _reportRepository.FirstOrDefault(p => p.Code == code);
                if (ent != null)
                {
                    string dbType = "";//数据库种类

                    #region 获取数据库
                    DbServerOutput dbServer = new DbServerOutput();
                    //中心库
                    if (ent.DbServerId == null)
                    {
                        var connection = ConnectionMsg.GetCurConnection();//获取当前承载库连接信息
                        dbType   = connection.DbType.ToString();
                        dbServer = null;
                    }
                    else
                    {
                        dbServer = _dbServerApp.GetDbServer(ent.DbServerId.Value);
                        dbType   = dbServer.DbTypeName;
                        if (dbServer == null)
                        {
                            err.IsError = true;
                            err.Message = "未找到当前code对应的数据库编号[" + ent.DbServerId.Value + "]!";
                            return(dt);
                        }
                    }
                    #endregion

                    //替换全局变量
                    string sql = ReplaceGlobalVar(ent.Sql);
                    //替换变量(内置或自定义、外置)
                    sql = ReplaceDefaultValue(sql, queryParams);
                    //当IsPlaceholder==true时,拼凑查询筛选条件
                    if (ent.IsPlaceholder == null || !ent.IsPlaceholder.Value)
                    {
                        sql = AnalysisParam(dbType, sql, queryParams);
                    }
                    if (dbServer == null)
                    {
                        dt = DbHelper.ExecuteGetTable(sql);
                    }
                    else
                    {
                        dt = _dbServerApp.ExecuteGetTable(dbServer.Id, sql);//执行sql
                    }
                }
                else
                {
                    err.IsError = true;
                    err.Message = "未找到编号为[" + code + "]的报表!";
                }
            }
            else
            {
                err.IsError = true;
                err.Message = "传入的code代码不能为空!";
            }
            return(dt);
        }
コード例 #7
0
ファイル: ReportAppService.cs プロジェクト: radtek/Fms
        /// <summary>
        /// 根据code代码及传入条件拼凑和执行sql
        /// </summary>
        /// <param name="code"></param>
        /// <param name="rows"></param>
        /// <param name="page"></param>
        /// <param name="queryParams"></param>
        /// <param name="sidx"></param>
        /// <param name="sord"></param>
        /// <param name="err"></param>
        /// <returns></returns>
        public string ExcuteReportSql(string code, int rows, int page, string queryParams, string sidx, string sord, ref ErrorInfo err)
        {
            if (!string.IsNullOrEmpty(code))
            {
                var ent = _reportRepository.FirstOrDefault(p => p.Code == code);
                if (ent != null)
                {
                    string    dbType   = "";              //数据库种类
                    int       records  = 0;               //总数量
                    DataTable endTable = new DataTable(); //查询结果

                    #region 获取数据库
                    DbServerOutput dbServer = new DbServerOutput();
                    //中心库
                    if (ent.DbServerId == null)
                    {
                        var connection = ConnectionMsg.GetCurConnection();//获取当前承载库连接信息
                        dbType   = connection.DbType.ToString();
                        dbServer = null;
                    }
                    else
                    {
                        dbServer = _dbServerApp.GetDbServer(ent.DbServerId.Value);
                        dbType   = dbServer.DbTypeName;
                        if (dbServer == null)
                        {
                            err.IsError = true;
                            err.Message = "未找到当前code对应的数据库编号[" + ent.DbServerId.Value + "]!";
                            return("");
                        }
                    }
                    #endregion

                    //替换全局变量
                    string sql = ReplaceGlobalVar(ent.Sql);
                    //替换变量(内置或自定义、外置)
                    sql = ReplaceDefaultValue(sql, queryParams);
                    //当IsPlaceholder==true时,拼凑查询筛选条件
                    if (ent.IsPlaceholder == null || !ent.IsPlaceholder.Value)
                    {
                        sql = AnalysisParam(dbType, sql, queryParams);
                    }
                    sql = SqlForOrder(sql, sidx, sord);                            //生成排序sql
                    string sqlPage = SqlForPage(dbType, sql, page, rows, ref err); //拼凑分页sql

                    //获取总数
                    string sqlC = string.Format(@"select count(1) from ({0})", sql);
                    if (dbServer != null)
                    {
                        //记录总数
                        object num = _dbServerApp.ExecuteScalar(ent.DbServerId.Value, sqlC, ref err);
                        records  = Convert.ToInt32(num);
                        endTable = _dbServerApp.ExecuteGetTable(ent.DbServerId.Value, sqlPage);
                    }
                    else//根据承载库查询
                    {
                        try
                        {
                            object num = DbHelper.ExecuteScalar(sqlC);
                            records  = Convert.ToInt32(num);
                            endTable = DbHelper.ExecuteGetTable(sqlPage);
                        }
                        catch (Exception ex)
                        {
                            err.IsError = true;
                            err.Message = "查询数据错误:" + ex.Message;
                            return("");
                        }
                    }
                    //拼凑json串
                    string result = "{\"records\":" + records + ",\"page\":" + page + ",\"total\":" + Math.Ceiling(decimal.Divide(records, rows)) + ",\"rows\":" + JSON.DecodeToStr(endTable) + "}";
                    return(result);
                }
                else
                {
                    err.IsError = true;
                    err.Message = "未找到编号为[" + code + "]的报表!";
                }
            }
            else
            {
                err.IsError = true;
                err.Message = "传入的代码不能为空!";
            }
            return("");
        }