Beispiel #1
0
        private void Save()
        {
            DB db = new DB();

            String Sql =
                "Insert Into mcErrors (DtTm, Message, SrcFile, SrcFunct, SrcLine, Sql, Stack) Values (" +
                DB.PutDtTm(DateTime.Now) + ", " +
                DB.PutStr(Ex.Message, 1024) + ", " +
                DB.PutStr(SrcFile, 32) + ", " +
                DB.PutStr(SrcFunct, 64) + ", " +
                SrcLine + ", " +
                DB.PutStr(this.Sql, 4096) + ", " +
                DB.PutStr(Ex.StackTrace, 4096) + ")";

            try
            {
                db.Exec(Sql);
            }
            catch (Exception Ex1)
            {
                Ex1.GetType();
            }
        }
Beispiel #2
0
        public static DateTime DtTm(String Str)
        {
            DateTime Value = DateTime.MinValue;

            if (Str != "")
            {
                try
                {
                    Value = Convert.ToDateTime(Str);
                }
                catch (Exception Ex)
                {
                    Ex.GetType();

                    int Year  = 0;
                    int Month = 0;
                    int Day   = 0;
                    int Hour  = 0;
                    int Min   = 0;
                    int Sec   = 0;

                    Char[] Separators = { ' ', '/', ':', '.' };
                    Str = Str.Trim().ToUpper();
                    String[] Parts = Str.Split(Separators);
                    for (int iParts = 0; iParts < Parts.Length; iParts++)
                    {
                        switch (iParts)
                        {
                        case 0:
                            Month = Num(Parts[iParts]);
                            break;

                        case 1:
                            Day = Num(Parts[iParts]);
                            break;

                        case 2:
                            Year = Num(Parts[iParts]);
                            break;

                        case 3:
                            Hour = Num(Parts[iParts]);
                            break;

                        case 4:
                            Min = Num(Parts[iParts]);
                            break;

                        case 5:
                            Sec = Num(Parts[iParts]);
                            break;
                        }
                    }

                    if (Hour > 0 && Hour <= 12)
                    {
                        String Last = Parts[Parts.Length - 1];
                        if (Last.IndexOf('P') > -1)
                        {
                            Hour += 12;
                        }
                    }

                    if (Year < 99)
                    {
                        Year += 2000;
                    }
                    if (Month == 0)
                    {
                        Month = 1;
                    }
                    if (Month > 12)
                    {
                        Month = 12;
                    }
                    if (Day == 0)
                    {
                        Day = 1;
                    }
                    if (Day > 31)
                    {
                        Day = 31;
                    }
                    if (Month == 2 &&
                        Day > 29)
                    {
                        Day = 29;
                    }
                    if (Hour > 24)
                    {
                        Hour = 24;
                    }
                    if (Min > 59)
                    {
                        Min = 59;
                    }
                    if (Sec > 59)
                    {
                        Sec = 59;
                    }

                    if (Year > 0 && Month > 0 && Day > 0)
                    {
                        try
                        {
                            Value = new DateTime(Year, Month, Day, Hour, Min, Sec);
                        }
                        catch (Exception Ex1)
                        {
                            Ex1.GetType();

                            Day--;
                            try
                            {
                                Value = new DateTime(Year, Month, Day, Hour, Min, Sec);
                            }
                            catch (Exception Ex2)
                            {
                                Ex2.GetType();
                            }
                        }
                    }
                }
            }

            return(Value);
        }