Ejemplo n.º 1
0
        public static string CreateDeleteCommand(IDBConnectionStateGettable actualPage, string primaryKey, string nameOfPrimaryKey)
        {
            string commandToReturn = "DELETE FROM ";

            commandToReturn += actualPage.GetTableDescriptionToSql();
            commandToReturn += " WHERE " + nameOfPrimaryKey + " = '" + primaryKey + "'";
            return(commandToReturn);
        }
Ejemplo n.º 2
0
        public static string CreateUpdateCommand(IDBConnectionStateGettable actualPage, string primaryKey, string nameOfPrimaryKey,
                                                 List <string> fieldsToUpdate, List <string> valueToSet)
        {
            string commandToReturn = "UPDATE " + actualPage.GetTableDescriptionToSql() + " SET " +
                                     fieldsToUpdate[0] + "='" + valueToSet[0] + "' WHERE " + nameOfPrimaryKey + " = '" + primaryKey + "'";

            if (commandToReturn.Contains(@"'NULL'"))
            {
                commandToReturn = commandToReturn.Replace(@"'NULL'", "NULL");
            }
            return(commandToReturn);
        }
Ejemplo n.º 3
0
        //Dziala!
        /// <summary>
        /// Creates a command string which show actual table and sort it.
        /// </summary>
        /// <param name="actualPage">Actual view</param>
        /// <param name="orderBy">order by (optional)</param>
        /// <param name="sortCriterium"></param>
        /// <returns></returns>
        public static string CreateCommand(IDBConnectionStateGettable actualPage, string orderBy = null,
                                           SortCriteria sortCriterium = SortCriteria.Ascending)
        {
            string actualTableSqlDescription = actualPage.GetTableDescriptionToSql();

            string commandToReturn = "SELECT * FROM ";

            commandToReturn += actualTableSqlDescription;
            if (!string.IsNullOrEmpty(orderBy))
            {
                commandToReturn = CreateCommand(commandToReturn, orderBy, sortCriterium);
            }
            return(commandToReturn);
        }
Ejemplo n.º 4
0
        public static string CreateNewRecordCommand(IDBConnectionStateGettable actualPage, List <string> valuesList, List <string> columnNames)
        {
            string commandToReturn = "INSERT INTO " + actualPage.GetTableDescriptionToSql() + " (";
            string lastColumn      = columnNames.Last();
            string lastValue       = valuesList.Last();

            foreach (string column in columnNames)
            {
                commandToReturn += column;
                if (column == lastColumn)
                {
                    commandToReturn += ") VALUES (";
                }
                else
                {
                    commandToReturn += ", ";
                }
            }
            foreach (object value in valuesList)
            {
                if (value.ToString() == "NULL")
                {
                    commandToReturn += value;
                }
                else
                {
                    commandToReturn += "'" + value + "'";
                }

                if (value.ToString() == lastValue)
                {
                    commandToReturn += ")";
                }
                else
                {
                    commandToReturn += ", ";
                }
            }
            return(commandToReturn);
        }