예제 #1
0
 public HintSetting(string tableName, string idField, string hintField, string hintFieldValue, EnumsHintFieldDataType hintFieldColumnDataType, EnumHintFieldSearchTechnique hintFieldSearchTechnique)
 {
     TableName                = tableName;
     IdField                  = idField;
     HintField                = hintField;
     HintFieldValue           = hintFieldValue;
     HintFieldColumnDataType  = hintFieldColumnDataType;
     HintFieldSearchTechnique = hintFieldSearchTechnique;
 }
예제 #2
0
        public static string GetLastCreatedIdForTable(string tableName, string idFieldName, string hintFieldName = null, string hintFieldValue = null, EnumHintFieldSearchTechnique hintFieldSearchTechnique = EnumHintFieldSearchTechnique.Contains)
        {
            string retValue = string.Empty;

            string sSQL_Template = "SELECT TOP 1 {0} from {1} ORDER BY 1 DESC";//"WHERE SettingName= 'CurrentTimeZone'";

            string sSQL;

            if (hintFieldName != null && hintFieldValue != null)
            {
                string searchString = "";
                switch (hintFieldSearchTechnique)
                {
                case EnumHintFieldSearchTechnique.BeginWith: searchString = string.Format(" LIKE '%{0}' ", hintFieldValue); break;

                case EnumHintFieldSearchTechnique.EndsWith: searchString = string.Format(" LIKE '{0}%' ", hintFieldValue); break;

                case EnumHintFieldSearchTechnique.ExactMatch: searchString = string.Format(" = '{0}' ", hintFieldValue); break;

                case EnumHintFieldSearchTechnique.NotContains: searchString = string.Format(" NOT LIKE '%{0}%' ", hintFieldValue); break;

                default:
                case EnumHintFieldSearchTechnique.Contains: searchString = string.Format(" LIKE '%{0}%' ", hintFieldValue); break;
                }
                sSQL_Template = "SELECT TOP 1 {0} from {1} WHERE {2} {3} ORDER BY 1 DESC";

                sSQL = string.Format(sSQL_Template, idFieldName, tableName, hintFieldName, searchString);
            }
            else
            {
                sSQL = string.Format(sSQL_Template, idFieldName, tableName);
            }


            SqlConnection con;
            SqlDataReader reader;

            try
            {
                con = DBHelper.GetNewConnection();
                con.Open();


                reader = new SqlCommand(sSQL, con).ExecuteReader();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        retValue = reader[0].ToString();
                        break;
                    }
                }
                else
                {
                    throw new ArgumentException("LastCreatedId coulud not be determined.");
                }

                reader.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            if (string.IsNullOrWhiteSpace(retValue))
            {
                throw new ArgumentException("LastCreatedId coulud not be determined.");
            }

            return(retValue);
        }
예제 #3
0
        public static bool Check_DataExist(string tableName, string idFieldName, string hintFieldName, string hintFieldValue, EnumHintFieldSearchTechnique hintFieldSearchTechnique)
        {
            try
            {
                string id = GetLastCreatedIdForTable(tableName, idFieldName, hintFieldName, hintFieldValue, hintFieldSearchTechnique);
                if (!string.IsNullOrEmpty(id))
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                return(false);
            }

            return(false);
        }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="actionIfIdExists">string id, reference to list page</param>
        /// <returns></returns>
        public TSelf ExecuteCustom_Using_LastId(string tableName, string idFieldName, string hintFieldName, string hintFieldValue, EnumHintFieldSearchTechnique hintFieldSearchTechnique, Action <string, TSelf> actionIfIdExists)
        {
            string id = DBHelper.GetLastCreatedIdForTable(tableName, idFieldName, hintFieldName, hintFieldValue, hintFieldSearchTechnique);

            if (!string.IsNullOrEmpty(id))
            {
                actionIfIdExists.Invoke(id, this as TSelf);
            }
            else
            {
                throw new Exception(string.Format("Last ID not available for {0}.{1}", tableName, idFieldName));
            }

            return(this as TSelf);
        }