示例#1
0
        public static string GetClientArray <T>(IEnumerable <T> eValue, string VarName, bool AddScriptTag)
        {
            List <string> aStmt = new List <string>();

            aStmt.Add("var " + VarName + " = [];");

            int i = -1;

            foreach (T Value in eValue)
            {
                string Quot     = "";
                string ValueNew = "";

                if (CLang.In(typeof(T), typeof(string), typeof(char)))
                {
                    Quot     = "\"";
                    ValueNew = CScript.ReplaceForScriptVariable(Value.ToString());
                }
                else if (typeof(T) == typeof(DateTime))
                {
                    ValueNew = CScript.GetJavaScriptDateTime(Convert.ToDateTime(Value));
                }
                else
                {
                    Quot     = "";
                    ValueNew = Value.ToString();
                }

                aStmt.Add(VarName + "[" + (++i).ToString() + "] = " + Quot + ValueNew + Quot + ";");
            }

            return(CScript.GetScript(aStmt, AddScriptTag));
        }
示例#2
0
 public static bool GetAttributeBoolean(XmlAttribute Attr)
 {
     if (Attr != null)
     {
         return(CLang.In(Attr.Value, "-1", "1", "true", "True"));
     }
     else
     {
         return(false);
     }
 }
示例#3
0
        ///// <summary>
        ///// \r\n, \r, \n, \t 등 정상적으로 입력되지 않는 문자열이 구분자로 쓰였다면
        ///// 해당 문자열들을 CD in (1, 2, 3)과 in 절에 넣을 수 있도록 "1, 2, 3"과 같이 변환해서 리턴함.
        ///// </summary>
        ///// <param name="Value"> </param>
        ///// <param name="IsNumberType">숫자형식의 필드인 지 여부 </param>
        ///// <param name="IsMultipleIs">in 절에 들어갈 수 있도록 콤마로 구분된 값으로 변환되었는 지 여부 </param>
        ///// <example>
        ///// bool IsMultipleIs;
        ///// string SQL = "", SQLIn = "";
        /////
        ///// SQL = "select * from CodeList";
        ///// SQLIn = GetInList("1\t2\t3", true, out IsMultipleIs);
        ///// if (IsMultipleIs)
        ///// {
        /////   SQL += " where Code in (" + SQLIn + ")";
        ///// }
        ///// else
        ///// {
        /////   SQL += " where Code = " + SQLIn;
        ///// }
        ///// Console.WriteLine(SQL); //"select * from CodeList where Code in (1, 2, 3)"
        /////
        ///// SQL = "select * from JobList";
        ///// SQLIn = GetInList("학생\t교사\t프로그래머", false, out IsMultipleIs);
        ///// if (IsMultipleIs)
        ///// {
        /////   SQL += " where JobName in (" + SQLIn + ")";
        ///// }
        ///// else
        ///// {
        /////   SQL += " where JobName = " + SQLIn;
        ///// }
        ///// Console.WriteLine(SQL); //"select * from JobList where JobName in ('학생', '교사', '프로그래머')"
        ///// </example>
        //public static string GetInList(string Value, bool IsNumberType,
        //                                out bool IsMultipleIs)
        //{
        //    char[] Delim;
        //    string ValueList = "";

        //    IsMultipleIs = false;

        //    Delim = GetDelimChar(Value);
        //    if (Delim.Length == 0)
        //    {
        //        return Value;
        //    }

        //    ValueList = GetInList(Value.Split(Delim), IsNumberType);

        //    IsMultipleIs = true;
        //    return ValueList;
        //}

        public static string GetInList <T>(T[] aValue)
        {
            string ValueList = "";

            SqlColumnTypeSimple TypeSimple = GetColumnTypeSimple(typeof(T));
            string Delim = CLang.In(TypeSimple, SqlColumnTypeSimple.DateTime, SqlColumnTypeSimple.String) ? "'" : "";

            for (int i = 0; i < aValue.Length; i++)
            {
                ValueList += "," + Delim + aValue[i] + Delim;
            }
            if (!string.IsNullOrEmpty(ValueList))
            {
                ValueList = ValueList.Substring(1);
            }

            return(ValueList);
        }
示例#4
0
        private static CSqlInfoInsert GetSqlInfoInsert(DbServerType DbServer, string Sql)
        {
            CSqlInfoInsert Info = new CSqlInfoInsert();

            CParagraph p = new CParagraph(CParagraph.DelimWord.NoUnderbar);

            p.WordSolo = new char[] { '(', ')', ',', '\'', '#' };
            Dictionary <int, string> dicWordDelim = p.GetIndexAndWords(Sql, true);
            List <int>    aIndex = dicWordDelim.Keys.ToList();
            List <string> aWord  = dicWordDelim.Values.ToList();

            SFromTo ftIndex = new SFromTo();


            ftIndex = IndexOf(aWord, 0, true, "insert", null, "into");
            if (ftIndex.From == -1)
            {
                if (DbServer == DbServerType.SQLite)
                {
                    ftIndex = IndexOf(aWord, 0, true, "insert", null, "or", null, "replace", null, "into");
                }
            }

            if (ftIndex.From == -1)
            {
                return(null);
            }

            int IndexTable = ftIndex.To + 2;

            if ((IndexTable + 1) > aWord.Count)
            {
                return(null);
            }

            Info.Table = aWord[IndexTable];


            ftIndex = IndexOf(aWord, IndexTable + 1, true, "(");
            if (ftIndex.From == -1)
            {
                return(null);
            }

            List <string> aField          = new List <string>();
            int           IndexFieldClose = -1;
            bool          IsFirstField    = true;
            int           IndexFieldStart = (ftIndex.To + 2);   // (Name, Age)에서 "," 위치부터 검사

            for (int i = IndexFieldStart; i < aWord.Count; i++)
            {
                string WordCur = aWord[i];

                if ((WordCur == ",") ||
                    (!IsFirstField && (WordCur == ")")))
                {
                    aField.Add(aWord[i - 1]);

                    if (WordCur == ")")
                    {
                        IndexFieldClose = i;
                        break;
                    }
                }

                IsFirstField = false;
            }

            if (IndexFieldClose == -1)
            {
                return(null);
            }

            Info.Field = aField.ToArray();


            ftIndex = IndexOf(aWord, IndexFieldClose + 1, true, "values");
            if (ftIndex.From == -1)
            {
                return(null);
            }

            List <string> aDelim          = new List <string>();
            List <string> aValue          = new List <string>();
            int           IndexValueClose = -1;
            bool          IsFirstValue    = true;
            int           IndexValueStart = (ftIndex.To + 2);   // (1, '홍길동', 65)에서 "," 위치부터 검사

            for (int i = IndexValueStart; i < aWord.Count; i++)
            {
                string WordCur = aWord[i];

                if ((WordCur == ",") ||
                    (!IsFirstValue && (WordCur == ")")))
                {
                    if (CLang.In(aWord[i - 1], "'", "#"))
                    {
                        string Delim         = aWord[i - 1];
                        int    IndexDelimEnd = i - 1;

                        ftIndex = LastIndexOf(aWord, (IndexDelimEnd - 1), true, Delim);
                        if (ftIndex.From == -1)
                        {
                            return(null);
                        }

                        aDelim.Add(aWord[IndexDelimEnd]);

                        int IndexDelimStart = ftIndex.From;

                        aValue.Add(string.Join("", aWord.ToArray(), (IndexDelimStart + 1), (IndexDelimEnd - IndexDelimStart - 1)));
                    }
                    else
                    {
                        aDelim.Add("");
                        aValue.Add(aWord[i - 1]);
                    }

                    if (aWord[i] == ")")
                    {
                        IndexValueClose = i;
                        break;
                    }
                }

                IsFirstValue = false;
            }

            if (IndexValueClose == -1)
            {
                return(null);
            }

            Info.Delim = aDelim.ToArray();
            Info.Value = aValue.ToArray();

            return(Info);
        }