Esempio n. 1
0
        public static String BuildSql(FilterEntity entity)
        {
            if ((entity.LeftPart == null) || (entity.RightPart == null))
            {
                return(String.Empty);
            }
            StringBuilder builder = new StringBuilder();

            if ((entity.Operate == CommonEnumerators.FilterOperate.And) || (entity.Operate == CommonEnumerators.FilterOperate.Or))
            {
                builder.Append("(");
                FilterEntity leftPart = entity.LeftPart as FilterEntity;
                if (leftPart != null)
                {
                    builder.Append(BuildSql(leftPart));
                }
                FilterEntity rightPart = entity.RightPart as FilterEntity;
                if (rightPart != null)
                {
                    builder.Append(CommonEnumerators.GetOperate(entity.Operate));
                    builder.Append(BuildSql(rightPart));
                }
                builder.Append(")");
            }
            else
            {
                builder.Append(BuildSql(entity.LeftPart.ToString(), entity.RightPart, entity.Operate));
            }
            return(builder.ToString());
        }
Esempio n. 2
0
        private static String BuildSql(String leftPart, object rightPart, CommonEnumerators.FilterOperate operate)
        {
            String format = " [{0}] {1} {2} ";
            String str2   = CommonEnumerators.GetOperate(operate);

            switch (rightPart.GetType().FullName)
            {
            case "System.String":
            {
                String str3 = rightPart.ToString().Replace("'", "").Replace("%", "").Trim();
                if (operate == CommonEnumerators.FilterOperate.StartWith)
                {
                    return(String.Format(format, leftPart, str2, String.Format("'{0}%'", str3)));
                }
                if (operate == CommonEnumerators.FilterOperate.EndWith)
                {
                    return(String.Format(format, leftPart, str2, String.Format("'%{0}'", str3)));
                }
                if ((operate == CommonEnumerators.FilterOperate.Contains) || (operate == CommonEnumerators.FilterOperate.NotContains))
                {
                    return(String.Format(format, leftPart, str2, String.Format("'%{0}%'", str3)));
                }
                if ((operate == CommonEnumerators.FilterOperate.GtIndicator) || (operate == CommonEnumerators.FilterOperate.LtIndicator))
                {
                    return(String.Format(format, leftPart, str2, String.Format("[{0}]", rightPart)));
                }
                return(String.Format(format, leftPart, str2, String.Format("'{0}'", str3)));
            }

            case "System.DateTime":
            {
                DateTime time = Convert.ToDateTime(rightPart);
                return(String.Format(format, leftPart, str2, String.Format("'{0}'", time.ToString("yyyy-MM-dd"))));
            }
            }
            return(String.Format(format, leftPart, str2, rightPart));
        }
        public override String Coding()
        {
            this._customIndicatorDictionary = new Dictionary <int, IndicatorEntity>();
            foreach (IndicatorEntity entity in this.IndicatorList)
            {
                if (((entity.CustomIndicator == null) || (entity.CustomIndicator.IndicatorList == null)) || (entity.CustomIndicator.IndicatorList.Count == 0))
                {
                    this._customIndicatorDictionary[entity.CustomerId] = entity;
                }
                else
                {
                    foreach (IndicatorEntity entity2 in entity.CustomIndicator.IndicatorList)
                    {
                        this._customIndicatorDictionary[entity2.CustomerId] = entity2;
                    }
                }
            }
            StringBuilder builder = new StringBuilder();

            builder.AppendFormat("$-{0}{1}", CommonEnumerators.GetIndicatorRequestTypeCmd(this._requestDataType), Environment.NewLine);
            List <String> list  = new List <String>();
            List <String> list2 = new List <String>();

            foreach (KeyValuePair <int, IndicatorEntity> pair in this._customIndicatorDictionary)
            {
                IndicatorEntity entity3 = pair.Value;
                list.Add(entity3.IndicatorCode);
                List <String> list3 = new List <String>();
                list3.Add(String.Format("$TableName={0}", entity3.CustomerId));
                if (String.IsNullOrEmpty(entity3.Parameters) || entity3.Parameters.Equals("null"))
                {
                    list2.Add(String.Join(",", list3.ToArray()));
                    continue;
                }
                List <ParamterObject> indicatorParameterList = JSONHelper.DeserializeObject <List <ParamterObject> >(entity3.Parameters);
                base.ResolveObjectParameters(indicatorParameterList);
                foreach (ParamterObject obj2 in indicatorParameterList)
                {
                    if (obj2.Type.Equals("261"))
                    {
                        continue;
                    }
                    if (String.IsNullOrEmpty(obj2.Name))
                    {
                        if (obj2.Type != "279")
                        {
                            list3.Add(String.Format("FieldName={0}", obj2.DefaultValue));
                        }
                        else if (obj2.Name.Trim().Equals("type"))
                        {
                            String str = obj2.DefaultValue.ToString();
                            list3.Add(String.Format("type={0}", str.Substring(str.Length - 1, 1)));
                        }
                        continue;
                    }
                    if ((obj2.Name.Trim().Equals("type") && (obj2.Type != "115")) && (obj2.Type != "219"))
                    {
                        int    result = 0;
                        String s      = obj2.DefaultValue.ToString();
                        if (!int.TryParse(s, out result))
                        {
                            s = s.Substring(s.Length - 1, 1);
                        }
                        list3.Add(String.Format("type={0}", s));
                        continue;
                    }
                    list3.Add(String.Format("{0}={1}", obj2.Name.Trim(), obj2.DefaultValue));
                }
                list2.Add(String.Join(",", list3.ToArray()));
            }
            builder.AppendFormat("$name={0}{1}", String.Join(",", list.ToArray()), Environment.NewLine);
            foreach (StockEntity entity4 in this._stockList)
            {
                if (!this._categoryStockCodeDict.ContainsKey(entity4.CategoryCode))
                {
                    this._categoryStockCodeDict[entity4.CategoryCode] = new List <String>();
                }
                this._categoryStockCodeDict[entity4.CategoryCode].Add(entity4.StockCode);
            }
            List <String> list5 = new List <String>();

            foreach (KeyValuePair <int, List <String> > pair2 in this._categoryStockCodeDict)
            {
                list5.Add(String.Format("{0}:{1}", pair2.Key, String.Join(",", pair2.Value.ToArray())));
            }
            builder.AppendFormat("$secucode={0}{1}", String.Join("#", list5.ToArray()), Environment.NewLine);
            builder.Append(String.Join(Environment.NewLine, list2.ToArray()));
            return(builder.ToString());
        }
        public override String Coding()
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendFormat("$-{0}{1}", CommonEnumerators.GetIndicatorRequestTypeCmd(base._requestDataType), Environment.NewLine);
            List <String> list  = new List <String>();
            List <String> list2 = new List <String>();

            for (int i = 0; i < base._indicatorList.Count; i++)
            {
                String[]        strArray;
                IndicatorEntity entity = base._indicatorList[i];
                list.Add(entity.ProductFunc);
                List <String> list3 = new List <String>();
                list3.Add(String.Format("$TableName={0}", base._customerIndicatorIdList[i]));
                Dictionary <String, object> dictionary  = base.BuildParamDictionary(entity.Parameters);
                Dictionary <String, object> dictionary2 = base.BuildParamDictionary(entity.ParaInfo);
                foreach (KeyValuePair <String, object> pair in dictionary)
                {
                    dictionary2[pair.Key] = dictionary[pair.Key];
                }
                foreach (KeyValuePair <String, object> pair2 in base.ParamDictionary)
                {
                    if (dictionary2.ContainsKey(pair2.Key.ToLower()))
                    {
                        dictionary2[pair2.Key.ToLower()] = pair2.Value;
                    }
                }
                dictionary2["indicatorcode"] = entity.IndicatorCode;
                String   str = dictionary2["reportdate"].ToString();
                DateTime secuLatestReportDate = DataServiceHelper.GetSecuLatestReportDate(base._stockList[0].StockCode);
                if ((base.ParamDictionary.Count == 0) || str.ToUpper().Trim().Equals("N"))
                {
                    List <String> list4 = new List <String>();
                    list4.Add(new DateTime(secuLatestReportDate.Year - 5, 12, 0x1f).ToString("yyyy-MM-dd"));
                    list4.Add(new DateTime(secuLatestReportDate.Year - 4, 12, 0x1f).ToString("yyyy-MM-dd"));
                    list4.Add(new DateTime(secuLatestReportDate.Year - 3, 12, 0x1f).ToString("yyyy-MM-dd"));
                    list4.Add(new DateTime(secuLatestReportDate.Year - 2, 12, 0x1f).ToString("yyyy-MM-dd"));
                    list4.Add(new DateTime(secuLatestReportDate.Year - 1, 12, 0x1f).ToString("yyyy-MM-dd"));
                    String item = secuLatestReportDate.ToString("yyyy-MM-dd");
                    if (!list4.Contains(item))
                    {
                        list4.Add(item);
                    }
                    strArray = list4.ToArray();
                }
                else
                {
                    strArray = str.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                }
                List <String> list5 = new List <String>();
                foreach (String str3 in strArray)
                {
                    DateTime time2 = DateTime.Parse(str3);
                    if (time2.Date <= secuLatestReportDate.Date)
                    {
                        list5.Add(str3);
                        String s = String.Empty;
                        if (!base.DateList.Contains(time2))
                        {
                            base.DateList.Add(time2);
                        }
                        s = DateHelper.GetSameCompareReportDate(str3);
                        this._sameDateList.Add(DateTime.Parse(s));
                        list5.Add(s);
                        s = DateHelper.GetHuanCompareReportDate(str3);
                        this._huanDateList.Add(DateTime.Parse(s));
                        list5.Add(s);
                    }
                }
                base.DateList.Sort();
                base.DateList.Reverse();
                dictionary2["reportdate"] = String.Join("|", list5.ToArray());
                foreach (KeyValuePair <String, object> pair3 in dictionary2)
                {
                    list3.Add(String.Format("{0}={1}", pair3.Key, pair3.Value.ToString().Trim()));
                }
                list2.Add(String.Join(",", list3.ToArray()));
            }
            builder.AppendFormat("$name={0}{1}", String.Join(",", list.ToArray()), Environment.NewLine);
            foreach (StockEntity entity2 in base._stockList)
            {
                if (!base._categoryStockCodeDict.ContainsKey(entity2.CategoryCode))
                {
                    base._categoryStockCodeDict[entity2.CategoryCode] = new List <String>();
                }
                base._categoryStockCodeDict[entity2.CategoryCode].Add(entity2.StockCode);
            }
            List <String> list6 = new List <String>();

            foreach (KeyValuePair <int, List <String> > pair4 in base._categoryStockCodeDict)
            {
                list6.Add(String.Format("{0}:{1}", pair4.Key, String.Join(",", pair4.Value.ToArray())));
            }
            builder.AppendFormat("$secucode={0}{1}", String.Join("#", list6.ToArray()), Environment.NewLine);
            builder.Append(String.Join(Environment.NewLine, list2.ToArray()));
            return(builder.ToString());
        }
        public override String Coding()
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendFormat("$-{0}{1}", CommonEnumerators.GetIndicatorRequestTypeCmd(base._requestDataType), Environment.NewLine);
            List <String> list  = new List <String>();
            List <String> list2 = new List <String>();

            for (int i = 0; i < base._indicatorList.Count; i++)
            {
                IndicatorEntity entity = base._indicatorList[i];
                list.Add(entity.ProductFunc);
                List <String> list3 = new List <String>();
                list3.Add(String.Format("$TableName={0}", base._customerIndicatorIdList[i]));
                Dictionary <String, object> dictionary  = base.BuildParamDictionary(entity.Parameters);
                Dictionary <String, object> dictionary2 = base.BuildParamDictionary(entity.ParaInfo);
                foreach (KeyValuePair <String, object> pair in dictionary)
                {
                    dictionary2[pair.Key] = dictionary[pair.Key];
                }
                foreach (KeyValuePair <String, object> pair2 in base.ParamDictionary)
                {
                    if (dictionary2.ContainsKey(pair2.Key.ToLower()))
                    {
                        dictionary2[pair2.Key.ToLower()] = pair2.Value;
                    }
                }
                if (!dictionary2.ContainsKey("period"))
                {
                    dictionary2["period"] = 1;
                }
                foreach (KeyValuePair <String, object> pair3 in dictionary2)
                {
                    list3.Add(String.Format("{0}={1}", pair3.Key, pair3.Value));
                }
                if (dictionary2.ContainsKey("startdate"))
                {
                    base.ParamDictionary["startdate"] = DateHelper.ResolveDate(dictionary2["startdate"].ToString());
                }
                if (dictionary2.ContainsKey("enddate"))
                {
                    base.ParamDictionary["enddate"] = DateHelper.ResolveDate(dictionary2["enddate"].ToString());
                }
                if (dictionary2.ContainsKey("period"))
                {
                    base.ParamDictionary["period"] = dictionary2["period"];
                }
                list2.Add(String.Join(",", list3.ToArray()));
            }
            builder.AppendFormat("$name={0}{1}", String.Join(",", list.ToArray()), Environment.NewLine);
            foreach (StockEntity entity2 in base._stockList)
            {
                if (!base._categoryStockCodeDict.ContainsKey(entity2.CategoryCode))
                {
                    base._categoryStockCodeDict[entity2.CategoryCode] = new List <String>();
                }
                base._categoryStockCodeDict[entity2.CategoryCode].Add(entity2.StockCode);
            }
            List <String> list4 = new List <String>();

            foreach (KeyValuePair <int, List <String> > pair4 in base._categoryStockCodeDict)
            {
                list4.Add(String.Format("{0}:{1}", pair4.Key, String.Join(",", pair4.Value.ToArray())));
            }
            builder.AppendFormat("$secucode={0}{1}", String.Join("#", list4.ToArray()), Environment.NewLine);
            builder.Append(String.Join(Environment.NewLine, list2.ToArray()));
            return(builder.ToString());
        }