コード例 #1
0
//### Formatting & Escaping ######################################################################################
        #region "Formatting & Escaping"

        static internal string dbformat2(string myVal, string myType, string language)
        {
            //Used for Export
            switch (myType)
            {
            case "System.String":
                return(string.Format("N'{0}'", SQLescape(myVal)));

            case "System.Boolean":
                return((myVal == "True") ? "1" : EvoTC.StrVal(myVal));

            case "System.DateTime":
                switch (language)
                {
                case "EN":                                 // English
                case "ZH":                                 // Chinese
                    // Date format = Month/Day/Year, example 4/24/2008
                    if (EvoTC.isDate(myVal))
                    {
                        return(string.Format("'{0}'", EvoTC.String2DateTime(myVal).ToString("yyyy-M-d hh:mm:ss tt")));
                    }
                    else
                    {
                        return(SQL_NULL);
                    }

                case "DA":                                 // Danish
                    // Date format = Month-Day-Year, example 4-24-2008
                    if (EvoTC.isDate(myVal.Replace("-", "/")))
                    {
                        return(string.Format("'{0}'", EvoTC.String2DateTime(myVal).ToString("G")));
                    }
                    else
                    {
                        return(SQL_NULL);
                    }

                default:
                    // Date format = Day/Month/Year, example 24/4/2008
                    return(GetDateDMY(myVal));
                }

            default:                     //"System.Int32", "System.Byte", "System.Decimal"
                return(EvoTC.StrVal(myVal));
            }
        }
コード例 #2
0
        static internal string dbFormat(string fieldValue, string fieldType, int fieldMaxLength, string language)
        {
            switch (fieldType)
            {
            case t_text:
            case t_txtm:
            case t_pix:
            case t_doc:
            case t_email:
            case t_url:
            case t_html:
                if (fieldMaxLength > 0 && fieldValue.Length > fieldMaxLength)
                {
                    return(string.Format("N'{0}'", fieldValue.Substring(0, fieldMaxLength).Replace("'", "''")));
                }
                else
                {
                    return(string.Format("N'{0}'", fieldValue.Replace("'", "''")));
                }

            case t_lov:
                return(string.IsNullOrEmpty(fieldValue) ? string.Empty : EvoTC.StrVal(fieldValue));

            case t_bool:
            case t_int:
                return(string.IsNullOrEmpty(fieldValue)? SQL_NULL : EvoTC.StrVal(fieldValue));

            case t_dec:
                string tDecStr;
                if (EvoTC.isInteger(fieldValue))
                {
                    //MUST NOT USE FORMATTED NUMBER IN EDIT GRID
                    tDecStr = fieldValue.TrimStart();
                }
                else if (!string.IsNullOrEmpty(fieldValue))
                {
                    tDecStr = EvoTC.String2Dec(fieldValue).ToString();
                }
                else
                {
                    tDecStr = SQL_NULL;
                }
                if (language == "FR" || language == "DA")
                {
                    tDecStr = tDecStr.Replace(",", ".");
                }
                return(tDecStr);

            case t_date:
            case t_datetime:
            case t_time:
                switch (language)
                {
                case "EN":
                case "ZH":
                    if (EvoTC.isDate(fieldValue))
                    {
                        string df;
                        switch (fieldType)
                        {
                        case t_date:
                            df = "yyyy-M-d";
                            break;

                        case t_datetime:
                            df = "yyyy-M-d hh:mm:ss tt";
                            break;

                        default:                                                        //"time"
                            df = "hh:mm:ss tt";
                            break;
                        }
                        return(string.Format("'{0}'", EvoTC.String2DateTime(fieldValue).ToString(df)));
                    }
                    else
                    {
                        return(SQL_NULL);
                    }

                case "DA":
                    if (EvoTC.isDate(fieldValue))
                    {
                        string df;
                        switch (fieldType)
                        {
                        case t_date:
                            df = "yyyy-M-d";
                            break;

                        case t_datetime:
                            df = "yyyy-M-d HH:mm:ss";
                            break;

                        default:                                                        //"time"
                            df = "HH:mm:ss";
                            break;
                        }
                        return(string.Format("'{0}'", EvoTC.String2DateTime(fieldValue).ToString(df)));
                    }
                    else
                    {
                        return(SQL_NULL);
                    }

                default:
                    return(GetDateDMY(fieldValue));
                }

            default:
                return(SQLescape(fieldValue));
            }
        }