コード例 #1
0
ファイル: CommonService.cs プロジェクト: stonezhu870/istock
 /// <summary>
 /// 控件销毁
 /// </summary>
 /// <param name="control">需要销毁的控件</param>
 public static void DisposeControl(Control control)
 {
     if (control == null)
     {
         return;
     }
     foreach (Control c in control.Controls)
     {
         if (c != null)
         {
             DisposeControl(c);
         }
     }
     try
     {
         Type type = control.GetType();
         if (type.Name != "ToolStripContentPanel" && type.Name != "ToolStripPanel")
         {
             control.Dispose();
             control.Controls.Clear();
         }
         else
         {
         }
     }
     catch (Exception exception)
     {
         CommonService.Log(String.Format("控件垃圾回收出错: {0}{1}", exception.Message, exception.StackTrace));
     }
 }
コード例 #2
0
ファイル: DataCache.cs プロジェクト: stonezhu870/istock
 /// <summary>
 /// 查询专题
 /// </summary>
 /// <returns>专题树数据源</returns>
 public static DataTable QuerySpecialTopic()
 {
     //if (EmReportWatch.SpecialCommon.CommonService.ISCLIENT == ClientType.Config)
     //{
     //return QueryByDatasoureName("MOD_SS");
     if (CommonService.ISCLIENT == ClientType.Config)
     {
         try
         {
             List <String> feilds = new List <String>()
             {
                 "SPECIALTOPICCODE",
                 "SPECIALTOPICNAME",
                 "CATEGORYCODE",
                 "SORTCODE",
                 "IMPORTANT",
                 "ISSHOWBLOCK",
                 "CONFIGFILENAME"
             };
             DataSet ds = QueryData("MOD_SS", feilds.ToArray());
             if (ds.Tables.Count == 0)
             {
                 return(null);
             }
             return(ds.Tables[0]);
         }
         catch (Exception e)
         {
             CommonService.Log(e.ToString());
             MessageBox.Show(e.ToString());
         }
     }
     //}
     //while (!AppBaseServices.NecessaryDataIsLoaded)
     //{
     //  Thread.Sleep(10);
     //}
     try
     {
         //定义文件夹
         String fileName = DataCenter.GetAppPath() + "\\NecessaryData\\MOD_SS";
         if (File.Exists(fileName))
         {
             return(JSONHelper.DeserializeObject <DataSet>(File.ReadAllText(fileName)).Tables[0]);
         }
         return(null);
     }
     catch
     {
         return(null); // QueryByDatasoureName("MOD_SS");
     }
 }
コード例 #3
0
 public static void CancelQuery(String threadid)
 {
     new DataQuery().CancelRequest(threadid);
     CommonService.Log(String.Format("取消数据请求ID: {0}", threadid));
 }
コード例 #4
0
        /// <summary>
        /// 分页数据查询
        /// </summary>
        /// <param name="sourcename">数据源名</param>
        /// <param name="modes">过滤条件集合</param>
        /// <param name="fields">数据列名</param>
        /// <param name="map">键值对</param>
        /// <param name="_orders">排序键值对</param>
        /// <param name="_needToGroup">是否要组合列</param>
        /// <param name="statisticsEngName">统计英文名</param>
        /// <param name="handler">数据处理委托</param>
        /// <param name="form">父容器控件</param>
        /// <param name="startindex">数据开始行数</param>
        /// <param name="pageCount">页数</param>
        /// <param name="queryHandle">分页数据查询委托</param>
        /// <returns>查询到的数据集</returns>
        public static DataSet QueryPageData(String sourcename, List <FilterMode> modes, String[] fields,
                                            Dictionary <GROUPTYPE, String> map, Dictionary <String, bool> _orders, bool _needToGroup,
                                            String statisticsEngName, DelegateMgr.SendBackHandle handler, int startindex, int pageCount, DelegateMgr.QueryHandle queryHandle
                                            //,Dictionary<String,String[]> blockfilters
                                            )
        {
            String log = null;

            if (String.IsNullOrEmpty(sourcename))
            {
                //res = 0;
                return(null);
            }

            //记录数据源名
            log = "数据源: " + sourcename;
            if (_needToGroup)
            {
                log = ",统计名: " + statisticsEngName;
            }

            log = log + "\r\n";

            if (_orders != null)
            {
                log = log + "排序信息:";
                foreach (KeyValuePair <String, bool> keyValuePair in _orders)
                {
                    log = log + "\r\n    " + keyValuePair.Key;
                    if (keyValuePair.Value)
                    {
                        log = log + ": 升序";
                    }
                    else
                    {
                        log = log + ": 升序";
                    }
                }
                log = log + "\r\n";
            }
            log = log + PrintFilterLog(modes);

            CommonService.Log(log);
            //业务平台调用;提取参数过滤排序信息
            if (CommonService.ISCLIENT == ClientType.Config)
            {
                SetFilterLog(sourcename, modes, fields, map, _orders, _needToGroup, statisticsEngName);
            }

            List <DataTransmission> requests = new List <DataTransmission>();
            DataTransmission        dt       = new DataTransmission();
            List <Expression>       filters  = new List <Expression>();

            //Expression bolckexp = null;
            //if (blockfilters != null)
            //  bolckexp = GetBlockExpression(blockfilters);
            dt.DataSource = sourcename;

            if (modes != null && modes.Count > 0)
            {
                Expression e = null;
                foreach (FilterMode mode in modes)
                {
                    if (!mode.IsSendFilter)
                    {
                        continue;
                    }
                    String[] values = mode.Value as String[];
                    if (values != null)
                    {
                        Expression eps = null;
                        eps = Expression.In(mode.BindParam, values);
                        if (eps != null)
                        {
                            filters.Add(eps);
                        }
                        continue;
                    }
                    else
                    {
                        Expression exp = GetExpression(mode.BindParam, mode.Filter, mode.Value);
                        if (exp != null)
                        {
                            filters.Add(exp);
                        }
                    }
                }
            }

            //if (bolckexp != null)
            //  filters.Add(bolckexp);
            dt.Selector = filters;
            if (map != null && map.Count > 0)
            {
                Expression ep = Expression.Computing();
                foreach (GROUPTYPE g in map.Keys)
                {
                    switch (g)
                    {
                    case GROUPTYPE.GROUP:
                        ep = ep.GroupBy(map[g]);
                        break;

                    case GROUPTYPE.MAX:
                        ep = ep.Max(map[g]);
                        break;

                    case GROUPTYPE.MIN:
                        ep = ep.Min(map[g]);
                        break;

                    default:
                        break;
                    }
                }
                dt.Computing = ep;
            }

            if (_orders != null && _orders.Count > 0)
            {
                dt.Orders = GetOrders(_orders);
            }
            dt.FirstResult = startindex;
            //if (!(CommonService.ISCLIENT == ClientType.Client || CommonService.ISCLIENT == ClientType.Config))
            //{
            //  dt.MaxResult = 500;
            //  dt.IsPaging = true;
            //}
            dt.Fields = fields;
            //dt.MaxResult = pageCount;
            dt.MaxResult = int.MaxValue;
            dt.IsPaging  = true;
            //if (CommonService.ISCLIENT != "1"||CommonService.ISCLIENT!="2")
            //{
            //  dt.MaxResult = 500;
            //  dt.IsPaging = true;
            //}
            requests.Add(dt);
            DataQuery dq = null;

            //try
            //{
            dq = new DataQuery();
            //}
            //catch
            //{

            //    dq = new DataQuery();
            //}

            //System.Diagnostics.Stopwatch ss = new System.Diagnostics.Stopwatch();
            //ss.Start();
            DataSet result = null;

            //lock (lockObj)
            //{

            if (_needToGroup)
            {
                try
                {
                    dt.DataSource = sourcename;
                    if (String.IsNullOrEmpty(statisticsEngName))
                    {
                        dt.StatisticsEngName = sourcename;
                    }
                    else
                    {
                        dt.StatisticsEngName = statisticsEngName;
                    }
                    dt.Filters = filters;
                    if (handler != null)
                    {
                        dq.QueryStaticsForPaging(dt, handler);
                    }
                    else if (queryHandle != null)
                    {
                        String threadid = "";
                        dq.QueryStatics(dt, out threadid, queryHandle);
                        CommonService.Log("开始执行QueryHandler ID:" + threadid);
                        CommonContant.QueryThreadIds.Add(threadid);
                    }
                    else
                    {
                        // form.CurRequestCount++;
                        result = dq.QueryStatics(dt).Data;

                        //return null;
                    }
                    CommonService.Log("请求数据DataQuery数据:\n 调用方法【ResultData QueryStatics(DataTransmission dt)】成功");
                }
                catch
                {
                    CommonService.ClearMemory();

                    return(null);
                }
                finally
                {
                }
            }
            else
            {
                try
                {
                    if (handler == null)
                    {
                        //result = dq.Query(requests);
                        //  String threadid;
                        result = dq.Query(requests);
                    }
                    else
                    {
                        if (startindex == 0)
                        //dq.Query(requests, handler);
                        {
                            String threadid = "";
                            dq.QueryForPagging(dt, out threadid, handler);
                            CommonContant.QueryThreadIds.Add(threadid);
                            CommonService.Log(String.Format("发起数据请求: {0}", threadid));
                        }

                        //lock (CommonContant.LockRequestid)
                        //{
                        //  TaskHelper.CloseProgress(CommonContant.Requestid);
                        //  TaskHelper.StartProgress(ref CommonContant.Requestid);
                        //}

                        //res = 1;
                        CommonService.ClearMemory();
                        return(null);
                    }
                }
                catch (Exception e)
                {
                    //	res = 0;
                    CommonService.Log(e);
                    CommonService.ClearMemory();
                    return(null);
                }
                finally
                {
                    CommonService.Log(String.Format("执行到位置{0}", 17));
                }
                //}
            }
            //dq.Dispose();
            //ss.Stop();
            //	res = 0;
            CommonService.ClearMemory();
            return(result);
        }
コード例 #5
0
        /// <summary>
        /// 数据查询
        /// </summary>
        /// <param name="sourcename">数据源名</param>
        /// <param name="modes">过滤条件集合</param>
        /// <param name="fields">数据列名</param>
        /// <param name="map">键值对</param>
        /// <param name="_orders">排序键值对</param>
        /// <param name="_needToGroup">是否要组合列</param>
        /// <param name="statisticsEngName">统计英文名</param>
        /// <param name="handler">数据处理委托</param>
        /// <param name="form">父容器控件</param>
        /// <returns>查询到的数据集</returns>
        public static DataSet QueryData(String sourcename, List <FilterMode> modes, String[] fields,
                                        Dictionary <GROUPTYPE, String> map, Dictionary <String, bool> _orders, bool _needToGroup,
                                        String statisticsEngName, DelegateMgr.QueryHandle handler
                                        //,Dictionary<String,String[]> blockfilters
                                        )
        {
            String log = null;

            if (String.IsNullOrEmpty(sourcename))
            {
                //	res = 0;
                return(null);
            }

            if (!_needToGroup)
            {
                log = "\n\n\nQueryData请求数据描述开始-------------->\n专题:数据源名 " + sourcename + " ";
            }
            else
            {
                log = "\n\n\nQueryData请求数据描述开始-------------->\n专题:统计名名 " + statisticsEngName + " " + _needToGroup + " SourceName: " +
                      sourcename;
            }
            log = "\n" + log + "\n请求参数描述:\n" + PrintFilterLog(modes) + "\nQueryData请求数据描述结束-------------->\n\n\n";
            if (_orders != null)
            {
                foreach (KeyValuePair <String, bool> keyValuePair in _orders)
                {
                    log = log + "r\n" + "排序字段: " + keyValuePair.Key + keyValuePair.Value;
                }
            }
            CommonService.Log(log);
            try
            {
                //业务平台调用;提取参数过滤排序信息
                if (CommonService.ISCLIENT == ClientType.Config)
                {
                    SetFilterLog(sourcename, modes, fields, map, _orders, _needToGroup, statisticsEngName);
                }
            }
            catch { }
            List <DataTransmission> requests = new List <DataTransmission>();
            DataTransmission        dt       = new DataTransmission();
            List <Expression>       filters  = new List <Expression>();

            //Expression bolckexp = null;
            //if (blockfilters != null)
            //  bolckexp = GetBlockExpression(blockfilters);
            dt.DataSource = sourcename;
            if (modes != null && modes.Count > 0)
            {
                Expression e = null;
                foreach (FilterMode mode in modes)
                {
                    if (!mode.IsSendFilter)
                    {
                        continue;
                    }
                    String[] values = mode.Value as String[];
                    if (values != null && values.Length >= 2)
                    {
                        Expression eps = null;
                        eps = Expression.In(mode.BindParam, values);
                        if (eps != null)
                        {
                            filters.Add(eps);
                        }
                        continue;
                    }
                    else
                    {
                        Expression exp = GetExpression(mode.BindParam, mode.Filter, mode.Value);
                        if (exp != null)
                        {
                            filters.Add(exp);
                        }
                    }
                }
            }
            //if (bolckexp != null)
            //  filters.Add(bolckexp);
            dt.Selector = filters;
            if (map != null && map.Count > 0)
            {
                Expression ep = Expression.Computing();
                foreach (GROUPTYPE g in map.Keys)
                {
                    switch (g)
                    {
                    case GROUPTYPE.GROUP:
                        ep = ep.GroupBy(map[g]);
                        break;

                    case GROUPTYPE.MAX:
                        ep = ep.Max(map[g]);
                        break;

                    case GROUPTYPE.MIN:
                        ep = ep.Min(map[g]);
                        break;

                    default:
                        break;
                    }
                }
                dt.Computing = ep;
            }
            if (_orders != null && _orders.Count > 0)
            {
                dt.Orders = GetOrders(_orders);
            }
            dt.FirstResult = 0;
            if (!(CommonService.ISCLIENT == ClientType.Client || CommonService.ISCLIENT == ClientType.Config))
            {
                dt.MaxResult = 500;
                dt.IsPaging  = true;
            }
            //if (CommonService.ISCLIENT != "1"||CommonService.ISCLIENT!="2")
            //{
            //  dt.MaxResult = 500;
            //  dt.IsPaging = true;
            //}
            requests.Add(dt);
            DataQuery dq = new DataQuery();
            //System.Diagnostics.Stopwatch ss = new System.Diagnostics.Stopwatch();
            //ss.Start();
            DataSet result = null;

            lock (lockObj)
            {
                if (_needToGroup)
                {
                    try
                    {
                        dt.DataSource = sourcename;
                        if (String.IsNullOrEmpty(statisticsEngName))
                        {
                            dt.StatisticsEngName = sourcename;
                        }
                        else
                        {
                            dt.StatisticsEngName = statisticsEngName;
                        }
                        dt.Filters = filters;
                        CommonService.Log("开始请求数据DataQuery数据:\n 调用方法【ResultData QueryStatics(DataTransmission dt)】");
                        if (handler == null)
                        {
                            result = dq.QueryStatics(dt).Data;
                        }
                        else
                        {
                            dq.QueryStatics(dt, handler);
                            //res = 1;
                            CommonService.ClearMemory();
                            return(null);
                        }
                        CommonService.Log("请求数据DataQuery数据:\n 调用方法【ResultData QueryStatics(DataTransmission dt)】成功");
                    }
                    catch
                    {
                        //	res = 0;
                        CommonService.Log("请求数据DataQuery数据:\n 调用方法【ResultData QueryStatics(DataTransmission dt)】失败"); CommonService.ClearMemory();
                        return(null);
                    }
                    finally
                    {
                    }
                }
                else
                {
                    try
                    {
                        if (handler == null)
                        {
                            result = dq.Query(requests);
                        }
                        else
                        {
                            dq.Query(requests, handler);
                            CommonService.ClearMemory();
                            return(null);
                        }
                    }
                    catch
                    {
                        CommonService.ClearMemory();
                        return(null);
                    }
                    finally
                    {
                    }
                }
            }
            //dq.Dispose();
            //ss.Stop();
            //res = 0;
            CommonService.ClearMemory();
            return(result);
        }