Beispiel #1
0
        /// <summary>
        /// List合并成字符串
        /// </summary>
        /// <typeparam name="K"></typeparam>
        /// <param name="values"></param>
        /// <param name="format"></param>
        /// <param name="props"></param>
        /// <returns></returns>
        public static String listTostr <K>(List <K> values, String format = "", Properties props = null)
        {
            StringBuilder str = new StringBuilder();
            String        sep = ",";

            if (props != null)
            {
                sep = props.Get <String>("sep", ",");
            }
            foreach (K value in values)
            {
                if (str.ToString() != "")
                {
                    str.Append(sep);
                }
                str.Append(ConvertTo <String>(value, format, props));
            }
            return(str.ToString());
        }
Beispiel #2
0
        /// <summary>
        /// 导入数据
        /// </summary>
        public bool doMergeToRepository()
        {
            showBeginMessage("开始合并数据...");
            if (repository == null)
            {
                repository = new IndicatorRepository(FileUtils.GetDirectory(props.Get <String>("repository")));
                repository.Initilization();
            }
            String datapath = FileUtils.GetDirectory(props.Get <String>("datapath"));

            DirectoryInfo dInfo = new DirectoryInfo(datapath);

            FileInfo[] fInfos = dInfo.GetFiles("*.scv");
            if (fInfos == null || fInfos.Length <= 0)
            {
                showResultMessage("没有需要导入的新文件", 1);
                return(false);
            }
            try
            {
                foreach (FileInfo fInfo in fInfos)
                {
                    String             code = fInfo.Name.Substring(3, 6);
                    TimeSerialsDataSet ds   = repository[code];
                    KLine kline             = ds.DayKLine;
                    if (ds == null)
                    {
                        continue;
                    }
                    showProgressMessage(code);
                    CSVFile csvFile = new CSVFile();
                    csvFile.Load(fInfo.FullName, Encoding.UTF8, false, ",");
                    List <String> lines = csvFile.Lines;
                    for (int i = lines.Count - 1; i >= 0; i--)
                    {
                        if (lines[i] == null || lines[i].Trim() == "")
                        {
                            continue;
                        }
                        String[] ss = lines[i].Split(',');
                        if (ss == null || ss.Length < 7)
                        {
                            continue;
                        }

                        DateTime  d    = DateUtils.Parse(ss[0]);
                        KLineItem item = kline[d];
                        if (item != null)
                        {
                            break;
                        }

                        double[] v = new double[6];
                        for (int j = 0; j < v.Length; j++)
                        {
                            v[j] = double.Parse(ss[j + 1]);
                        }
                        item      = new KLineItem();
                        item.Date = d;
                        item.SetValue <double>("OPEN", v[0]);
                        item.SetValue <double>("HIGH", v[1]);
                        item.SetValue <double>("LOW", v[2]);
                        item.SetValue <double>("CLOSE", v[3]);
                        item.SetValue <double>("VOLUME", v[4]);
                        item.SetValue <double>("TURNOVER", v[5]);
                        kline.Add(item);
                    }

                    ds.Save("kline", TimeUnit.day);
                }
                showResultMessage("");
                return(true);
            }
            catch (Exception e)
            {
                showResultMessage("导入失败", -1, e.Message);
                return(false);
            }
        }
Beispiel #3
0
        /// <summary>
        /// 对象转字符串
        /// </summary>
        /// <param name="x"></param>
        /// <param name="format"></param>
        /// <param name="props"></param>
        /// <returns></returns>
        public static String objectToStr(this Object x, String format = "", Properties props = null)
        {
            if (x == null)
            {
                return("");
            }
            String sep = props == null ? TEXT_PROP_SEP_DEFAULT : props.Get <String>(TEXT_PROP_SEP, TEXT_PROP_SEP_DEFAULT);

            if (format == null || format == "")
            {
                format = props == null ? "" : props.Get <String>(TEXT_PROP_FORMAT, "");
            }
            String[] propertyNames = props == null ? null : props.Get <String[]>(TEXT_PROP_PROPNAMES, null);

            //基础数据类型转换
            if (x.GetType() == typeof(char))
            {
                return(x.ToString());
            }
            else if (x.GetType() == typeof(int) || x.GetType() == typeof(Int32))
            {
                return(intToStr((int)x, format, props));
            }
            else if (x.GetType() == typeof(float) || x.GetType() == typeof(double))
            {
                return(doubleToStr((double)x, format, props));
            }
            else if (x.GetType() == typeof(String))
            {
                return((String)x);
            }
            else if (x.GetType() == typeof(DateTime))
            {
                return(datetimeToStr((DateTime)x, format, props));
            }
            else if (x.GetType() == typeof(String))
            {
                return(x.ToString());
            }
            else if (x.GetType().IsEnum)
            {
                return(x.ToString());
            }
            else if (x.GetType().IsArray)
            {
                StringBuilder st = new StringBuilder();
                foreach (Object ele in (Array)x)
                {
                    if (st.ToString() != null)
                    {
                        st.Append(",");
                    }
                    st.Append(objectToStr(ele, format, props));
                }
                return(st.ToString());
            }
            else if (typeof(IEnumerable).IsInstanceOfType(x))
            {
                StringBuilder st  = new StringBuilder();
                IEnumerable   tor = (IEnumerable)x;
                foreach (Object ele in tor)
                {
                    if (st.ToString() != "")
                    {
                        st.Append(",");
                    }
                    st.Append(objectToStr(ele, format, props));
                }
                return(st.ToString());
            }



            MemberInfo[] memberInfos = x.GetType().GetProperties();

            List <String> results = new List <string>();

            for (int i = 0; i < memberInfos.Length; i++)
            {
                TransinetAttribute transinet = memberInfos[i].GetCustomAttribute <TransinetAttribute>();
                if (transinet != null)
                {
                    continue;
                }
                TextAttribute txtAttr = memberInfos[i].GetCustomAttribute <TextAttribute>();
                if (txtAttr != null && txtAttr.Ignored)
                {
                    continue;
                }
                String name = memberInfos[i].Name;
                if (propertyNames != null && propertyNames.Length > 0 && !propertyNames.Contain(name, true))
                {
                    continue;
                }


                if (txtAttr != null && StringUtils.NotEmpty(txtAttr.ShowText))
                {
                    name = txtAttr.ShowText;
                }
                Object value    = memberInfos[i].FindValue(x);
                String valueStr = value == null ? "" : ConvertUtils.ConvertTo <String>(value, txtAttr != null ? txtAttr.Format : "");
                String text     = format;
                text = text.Replace("{$P}", name);
                text = text.Replace("{$V}", valueStr);
                results.Add(text);
            }
            return(results.Aggregate <String>((a, b) => a + sep + b));
        }