- DropKick - superb replacement for standard drop-downs, with in-built graceful degradation
- FlexSlider - awesome slider plugin for image display
- Apprise - a nice little replacement for alert/confirmation boxes, although I\'m not sure how well this works across platforms. It doesn\'t look great on IE7/8.
- Reveal - very nice modal dialog implementation
Caching - File Dependancies
You can output the contents of a file from the cache, and ASP.NET provides the facility to clear the cache whenever the contents of the file change. For example:
DataSet ds = (DataSet)Cache["MyInfo"];
if (ds == null) {
ds = new DataSet();
ds.ReadXml(MapPath("MyInfo.xml"));
Cache.Insert("MyInfo", ds, Caching.CacheDependency(MapPath("MyInfo.xml")));
}
// do whatever you want with the dataset here...
DropDownList1.DataSource = ds; ...
Output Caching
As per the microsoft documentation, pages can be cached on the server with the following:
<%@ OutputCache Duration="60" VaryByParam="None" Location="Server" %>
This can also be cleared on another page (if someone changes the values to be shown on an item, for example), using the static RemoveOutputCacheItem method.
If you want to clear the output cache for "http://yourserver/webSiteRoot/cachedFile.aspx", then in your page that does the clear call, do the following:
HttpResponse.RemoveOutputCacheItem("/webSiteRoot/cachedFile.aspx");
Output Caching - Clearing using Cache Dependencies
An easier way to remove output caching from multiple pages is to attach a cache dependency on those pages. In the page that is actually cached:
string cacheKey = "mypage.aspx?" + parameters; Cache[cacheKey] = new object(); Response.AddCacheItemDependency(cacheKey);
Then, on the page that invalidates the cache (for example, an admin page that inserts/updates database records):
string cacheKey = "mypage.aspx?" + parameters; Cache.Remove(cacheKey);
public class myClass extends Dialog implements Runnable {
private Thread timer; // class-wide reference to thread object
// run method from Runnable interface - this method runs until a
// specified condition is true - so you would probably want to have
// another variable which checks, for example, that the user has clicked
// a Cancel or OK button
public void run() {
while (this.isVisible()) {
try {
// user has not yet closed the window - sleep and loop again
Thread.currentThread().sleep(500);
}
catch (InterruptedException ie) {
}
}
}
// method which will return the value - makes the dialog visible, starts
// the Thread, and then when the thread dies a result is returned
public int setVisible() {
this.show();
this.start();
return result;
}
// implemented from Runnable interface - initiates a new thread
public void start() {
timer = new Thread(this);
timer.start();
}
// cleans up objects when the Thread completes
public void stop() {
timer = null;
}
}
Even more simply, if you want to run a single line in your class as a thread, you can do the following (taking away the pain of implementing the Runnable interface):
public void doStuff() {
Thread runner = new Thread() {
public void run() {
// do thread stuff here
}
};
runner.start();
}
FileDialog dlg = new FileDialog(this, "What file do you want to save?", FileDialog.SAVE);
dlg.setFile("*.java"); // file extension filter
dlg.setDirectory("."); // initial directory
dlg.show();
String saveFile;
if((saveFile = d.getFile()) != null) {
filename.setText(saveFile);
myTextField.setText(d.getDirectory());
}
Alternatively, if you want to maintain a standard swing look and feel, you can import the javax.swing.JFileChooser class, which can be used in the same way.
JFileChooser chooser = new JFileChooser(".");
// chooser.setFileFilter(filter);
chooser.setFileHidingEnabled(false);
int returnVal = chooser.showOpenDialog(parent);
if(returnVal == JFileChooser.APPROVE_OPTION) {
System.out.println("You chose to open this file: " + chooser.getSelectedFile().getName());
System.out.println("You chose to open this directory: " + chooser.getCurrentDirectory());
}
To save files using the swing set, use the following code:
JFileChooser saver = new JFileChooser(".");
saver.setFileHidingEnabled(false);
int returnVal = saver.showSaveDialog(parent);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File selFile = saver.getSelectedFile();
if (selFile.exists()) {
int sel = JOptionPane.showConfirmDialog(parent, "Overwrite file " +
selFile.getAbsolutePath() + "?", "File exists",
JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE);
if (sel == JOptionPane.NO_OPTION) {
// do NO overwrite action here
return;
}
}
// do save action here
}
Eg: to open the user's default browser to a web site:
try
{
System.Diagnostics.Process.Start("http://yoursite.com");
}
catch (Exception)
{
// error handling
}
Eg: To open the user's mail client to send mail to someone:
try
{
System.Diagnostics.Process.Start("mailto: someone@somewhere.com");
}
catch (Exception)
{
// error handling
}
Eg: To open a gif file:
try
{
System.Diagnostics.Process.Start("C:/YourFile.gif");
}
catch (Exception)
{
// error handling
}
private void event_DragOver(object sender, System.Windows.Forms.DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
The second step involves handling the actual dropping of the file. This is done by adding a DragDrop event to your form, and retrieving the string array which Windows passes to your application containing the names of all the files dragged and dropped:
private void event_DragDrop(object sender, DragEventArgs e)
{
// get reference to the dataobject
DataObject dataObj = (DataObject)e.Data;
// convert into array of file names
string[] files = (string[])(dataObj.GetData(DataFormats.FileDrop));
// loop through each argument, performing the appropriate file opening
for (int i=0; iThe process of modelling real-world objects. When you create a class you create an abstraction of a real-world object (like a dictionary definition of that real-world object).
Encapsulation
The property of being a self-contained unit is called encapsulation. With encapsulation, we can accomplish data hiding. Data hiding is the highly valued characteristic that an object can be used without the user knowing or caring how it works internally. Just as you can use a refrigerator without knowing how the compressor works, you can use a well-designed object without knowing about its internal data members.
Inheritance
When an object is derived from another object. It inherits all the properties etc. of the parent object, but can also add to them as needed.
Polymorphism
Different objects do "the right thing" through what is called function polymorphism and class polymorphism. Poly means many, and morph means form. Polymorphism refers to the process whereby an object invokes a method of another object in a common manner (with the same name) without understanding or caring how it is accomplished.
You can use parameters to pass a value into a stored procedure, or to return a value from a stored procedure to a calling program. You can have up to 1024 parameters in a stored procedure.
Parameters can be given default values. The default value can be a constant value or NULL. You do not need to pass a parameter a value if a default is specified.
Example:
CREATE PROCEDURE MyProcedure
(
@Name varchar(200),
@Age int,
@Year int = 2000, /* default of 2000 specified */
@ParticipantID int OUTPUT
)
AS
SELECT @retval = 0
INSERT INTO Participants
(Name, Age, Year, DateEntered)
VALUES
(@Name, @Age, @Year, GetDate())
// Give return variable value of error
SELECT @retval = @@ERROR
// Return the new identity value
SELECT @ParticipantID = @@IDENTITY
return