Пример #1
0
    public static int AddORUpdateByHashtable(Hashtable hst, string TableName, string UpdateCon)
    {
        string str      = "";
        string sql      = "";
        bool   IsUpdate = false;

        if (!string.IsNullOrWhiteSpace(UpdateCon))
        {
            IsUpdate = true;
        }

        List <Field> FieldList = ReadDataColumnSet.GetTableFieldByTableName(TableName);


        if (FieldList.Count == 0)
        {
            return(-1);
        }

        StringBuilder sbField = new StringBuilder();
        StringBuilder sbValue = new StringBuilder();

        foreach (DictionaryEntry de in hst)
        {
            string field = de.Key.ToString();
            if (string.IsNullOrWhiteSpace(field))
            {
                continue;
            }

            string valueStr = "";
            Field  f        = FieldList.FirstOrDefault(p => p.Name.Equals(field));

            if (f == null)
            {
                continue;
            }

            int t = ReadDataColumnSet.getType(f.DataType);
            if (de.Value == null)
            {
                valueStr = " null ";
            }
            else
            {
                valueStr = de.Value.ToString();
                if (t == 0 || t == -1 || string.IsNullOrWhiteSpace(valueStr))
                {
                    valueStr = "'" + valueStr + "'";
                }
            }

            if (IsUpdate)
            {
                if (sbValue.Length == 0)
                {
                    sbValue.Append(" SET ");
                }
                else
                {
                    sbValue.Append(",");
                }
                sbValue.Append(field + "=" + valueStr);
            }
            else
            {
                if (sbField.Length == 0)
                {
                    sbField.Append(" ( ");
                }
                else
                {
                    sbField.Append(",");
                }
                sbField.Append(field);

                if (sbValue.Length == 0)
                {
                    sbValue.Append("VALUES (");
                }
                else
                {
                    sbValue.Append(",");
                }
                sbValue.Append(valueStr);
            }
        }

        if (IsUpdate)
        {
            str = " UPDATE  " + TableName;
            sql = str + sbValue.ToString() + " " + " where " + UpdateCon;
        }
        else
        {
            str = " INSERT INTO " + TableName;
            sql = str + sbField.ToString() + " ) " + sbValue.ToString() + " ) ";
        }
        string[] changePassWord = Common.getChangePassWord();
        return(Resource.ExecuteSql(sql, changePassWord[0], changePassWord[1], changePassWord[2]));
    }
Пример #2
0
    public static string GetALLCommonSearchField(string argResourcesId, string argReportKey, string argSearchType, string argIsDynamicallyCreatTableHead, bool argAutomaticFilteringColumn = true, bool argIsUsedFieldNameQuery = false, bool argIsSearchQuery = false)
    {
        List <Field> FieldList = new List <Field>();
        string       str       = "";

        if (string.IsNullOrWhiteSpace(argIsDynamicallyCreatTableHead))
        {
            FieldList = GetSearchFieldList(argResourcesId, argReportKey);
        }

        if (argIsSearchQuery)
        {
            dynamic ReturnFieldList = FieldList.Select(p => new { FieldId = p.Name, FieldName = p.Description, FieldType = ReadDataColumnSet.getType(p.DataType) });
            str = Newtonsoft.Json.JsonConvert.SerializeObject(ReturnFieldList);
        }
        else
        {
            dynamic ReturnFieldList = FieldList.Select(p => new { FieldId = p.Name, FieldName = p.Description, FieldType = p.DataType });
            str = Newtonsoft.Json.JsonConvert.SerializeObject(ReturnFieldList);
        }
        return(str + "[#]" + GetCombobox_Data(null, "OP", "", argIsUsedFieldNameQuery) + "[#]" + GetCombobox_Data(FieldList, "field", "", argIsUsedFieldNameQuery));
    }