Exemple #1
0
 private bool Validate(DBCell cell)
 {
     bool isValid = true;
     try
     {
         switch (cell.Type)
         {
             case DbDataType.Int:
                 {
                     Convert.ToInt32(cell.Value);
                     break;
                 }
             case DbDataType.DateTime:
             case DbDataType.Date:
                 {
                     Convert.ToDateTime(cell.Value);
                     break;
                 }
             case DbDataType.VarChar:
                 {
                     break;
                 }
             default:
                 {
                     isValid = false;
                     break;
                 }
         }
     }
     catch
     {
         isValid = false;
     }
     return isValid;
 }
Exemple #2
0
 private DbCommand GetUpdateCommand(GenericDatabase db, DbConnection conn, string tableName, DBCell[] cells, DBCell[] condetions)
 {
     DbCommand cmd = GetUpdateCommand(db, conn, tableName, cells);
     cmd.CommandText += " WHERE ";
     foreach (DBCell condetion in condetions)
     {
         cmd.CommandText += condetion.Name + " = " + db.GetAsParameterName(condetion.Name) + " AND ";
         cmd.Parameters.Add(db.GetDBCellAsDBParameter(cmd, condetion));
     }
     cmd.CommandText += " 1=1";
     return cmd;
 }
Exemple #3
0
 private DbCommand GetInsertCommand(GenericDatabase db, DbConnection conn, string tableName, DBCell[] cells)
 {
     if(Validate())
     {
         DbCommand dbCommand = conn.CreateCommand();
         dbCommand.CommandText = "INSERT INTO " + tableName + "(";
         String vals = "";
         for (int i = 0; i < cells.Length; i++)
         {
             if (cells[i].IsUpdatable)
             {
                 dbCommand.CommandText += cells[i].Name;
                 dbCommand.CommandText += ", ";
                 vals += db.GetAsParameterName(cells[i].Name);
                 vals += ", ";
                 dbCommand.Parameters.Add(db.GetDBCellAsDBParameter(dbCommand, cells[i]));
             }
         }
         dbCommand.CommandText = Utils.RemoveTrailingSymbol(dbCommand.CommandText, ",");
         vals = Utils.RemoveTrailingSymbol(vals, ",");
         dbCommand.CommandText += ") VALUES (" + vals + ")";
         return dbCommand;
     }
     return null;
 }
Exemple #4
0
 private DbCommand GetUpdateCommand(GenericDatabase db, DbConnection conn, string tableName, DBCell[] cells)
 {
     if (Validate())
     {
         string sql = "UPDATE " + tableName + " SET ";
         DbCommand dbCommand = conn.CreateCommand();
         for (int i = 0; i < cells.Length; i++)
         {
             if (cells[i].IsUpdatable)
             {
                 sql += cells[i].Name + " = " + db.GetAsParameterName(cells[i].Name);
                 sql += ", ";
                 dbCommand.Parameters.Add(db.GetDBCellAsDBParameter(dbCommand, cells[i]));
             }
         }
         sql = Utils.RemoveTrailingSymbol(sql, ",");
         dbCommand.CommandText = sql;
         return dbCommand;
     }
     return null;
 }
Exemple #5
0
 public abstract DbParameter GetDBCellAsDBParameter(DbCommand cmd, DBCell cell);