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)); }
public static bool GetAttributeBoolean(XmlAttribute Attr) { if (Attr != null) { return(CLang.In(Attr.Value, "-1", "1", "true", "True")); } else { return(false); } }
public List <MemoryStream> ExtractZipToStream(string ZipFullPath, string SearchPattern, string Password) { List <MemoryStream> aZipStream = new List <MemoryStream>(); ZipFile zf = null; try { FileStream fs = File.OpenRead(ZipFullPath); zf = new ZipFile(fs); if (!string.IsNullOrEmpty(Password)) { zf.Password = Password; // AES encrypted entries are handled automatically } long TotalCount = zf.Count; foreach (ZipEntry Entry in zf) { if (!Entry.IsFile) { continue; // Ignore directories } if (!CLang.Like(Entry.Name, SearchPattern, true)) { continue; } string DirectoryName = Path.GetDirectoryName(Entry.Name); string FileName = Path.GetFileName(Entry.Name); byte[] buffer = new byte[4096]; // 4K is optimum Stream zipStream = zf.GetInputStream(Entry); MemoryStream ms = CFile.GetMemoryStreamFromStream(zipStream); aZipStream.Add(ms); } } finally { if (zf != null) { zf.IsStreamOwner = true; // Makes close also shut the underlying stream zf.Close(); // Ensure we release resources } } return(aZipStream); }
///// <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); }
public static IntPtr GetHandleByWindowCaptionAndSizeLike(string Caption, Size Size, int SizeTolerance) { Dictionary <IntPtr, IntPtr> aChildParent = new Dictionary <IntPtr, IntPtr>(); GetHandleList(ref aChildParent, GetDesktopWindow(), true); foreach (KeyValuePair <IntPtr, IntPtr> kv in aChildParent) { CInfoWindow Info = kv.Key.GetWindowInfo(); if (!string.IsNullOrEmpty(Caption) && CLang.Like(Info.Caption, Caption, true) && (Math.Abs(Info.PositionSize.Width - Size.Width) <= SizeTolerance) && (Math.Abs(Info.PositionSize.Height - Size.Height) <= SizeTolerance) ) { return(kv.Key); } } return(IntPtr.Zero); }
public static IntPtr GetHandleByWindowCaptionLike(string WindowCaption) { Dictionary <IntPtr, IntPtr> aChildParent = new Dictionary <IntPtr, IntPtr>(); GetHandleList(ref aChildParent, GetDesktopWindow(), true); foreach (KeyValuePair <IntPtr, IntPtr> kv in aChildParent) { string Caption = GetWindowCaptionByHandle(kv.Key); if (string.IsNullOrEmpty(Caption)) { continue; } //Debug.WriteLine(Caption); if (CLang.Like(Caption.ToString(), WindowCaption, true)) { return(kv.Key); } } return(IntPtr.Zero); }
public static bool Is2ByteChar(char c) { //Basic Latin http://msdn.microsoft.com/en-us/library/dd374090(VS.85).aspx 참조 if (CLang.Between((int)c, 0, 127)) { return(false); } else { return(true); } //정확하지 않아 주석. //UnicodeCategory cat = char.GetUnicodeCategory(c); //switch (cat) //{ // case UnicodeCategory.FinalQuotePunctuation: //’ // case UnicodeCategory.OtherLetter: // case UnicodeCategory.OtherSymbol: // return true; //} //return false; }
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); }