Flash Cards
FlashCardClass.cs
public class FlashCardClass
{
int mintFirstNumber, mintSecondNumber;
string[] mstrOp_list = { "+", "-", "*", "/", "%" };
string mstrOp="+";
Random mrndNumber;
int min, max;
public int Min
{
get
{
return min;
}
set
{
min = value;
}
}
public int Max
{
get { return max; }
set { max = value; }
}
public FlashCardClass()
{
// Initialize the random number generator object.
mrndNumber = new Random();
return mstrOp;
}
set
{
mstrOp = value;
}
}
// Calculates answer based on current operation.
public int Answer()
{
switch (mstrOp)
{
case "+":
return mintFirstNumber + mintSecondNumber;
case "x":
return mintFirstNumber * mintSecondNumber;
case "*":
return mintFirstNumber * mintSecondNumber;
case "-":
return mintFirstNumber - mintSecondNumber;
case "/":
return mintFirstNumber / mintSecondNumber;
case "%":
return mintFirstNumber % mintSecondNumber;
default:
return 0;
}
}
{
lblFeedback.Text = "Correct!";
// Get another set of numbers.
FlashCard1.Shuffle();
// Refresh display to show new numbers.
RefreshDisplay();
}
else
{
lblFeedback.Text = "Oops! Try Again.";
}
txtAnswer.Text = "";
}
private void RefreshDisplay()
{
TextBox2.Text = FlashCard1.Max.ToString();
TextBox1.Text = FlashCard1.Min.ToString();
lblFirst.Text = FlashCard1.FirstNumber.ToString();
lblSecond.Text = FlashCard1.Operation +
FlashCard1.SecondNumber.ToString();
}
Translator
TranslatorClass.cs
public class TranslatorClass
{
string mstrText, mstrOriginal;
// Controls access to class-level variables.
public string Text
// Change to lowercase.
strWord = arrWords[intCount].ToLower();
// Check if word is capitalized.
if (!arrWords[intCount].Equals(strWord))
bCaps = true;
// Do translation.
if (strWord != "")
{
strWord = strWord.Substring(1, strWord.Length - 1) +
strWord.Substring(0, 1) + "ay";
// Recapitalize if necessary.
if (bCaps)
strWord = strWord.Substring(0, 1).ToUpper() +
strWord.Substring(1, strWord.Length - 1);
}
// Store the word back in the array.
arrWords[intCount] = strWord;
// Reset the caps flag.
bCaps = false;
}
// Rebuild the string from the array.
mstrText = String.Join(" ", arrWords);
}
}
Translator.aspx
Translator.aspx.cs
public partial class Translator : System.Web.UI.Page
{
TranslatorClass TransClass;
// the text in txtSource.
if (bSwitch)
{
// Get the text.
TransClass.Text = txtSource.Text;
// Translate it.
TransClass.Translate();
// Display the text.
txtSource.Text = TransClass.Text;
// Change the Button text.
butTranslate.Text = "Restore";
}
else
{
// Restore the original text.
TransClass.Restore();
// Display the text.
txtSource.Text = TransClass.Text;
// Change the Button text.
butTranslate.Text = "Translate";
}
}
WebTextEditor
SignOn.aspx
public partial class SignOn : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
public partial class NewAccount : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
txtName.Text=Session["NewName"].ToString();
}
protected void butCreate_Click(object sender, System.EventArgs e)
{
string strPath;
//Check if directory exists.
strPath = Server.MapPath(Request.ApplicationPath) + "\\"
+ txtName.Text;
if (Directory.Exists(strPath))
{
// Tell the user to choose another name.
litNameExists.Text = "<p>The name " + txtName.Text +
" already exists. Please choose a different one.</p>";
return;
}
else
{
try
{
// Create the directory.
Directory.CreateDirectory(strPath);
// Set the session variable.
Session["Path"] = strPath;
// Go to file manager.
Server.Transfer("FileManager.aspx");
// Bind lstFiles to file array.
lstFiles.DataSource = strFiles;
lstFiles.DataBind();
}
protected void butNew_Click(object sender, System.EventArgs e)
{
//If there is a file name, then start the editor.
if (!(txtNewFile.Text == ""))
Response.Redirect("EditFile.aspx?file=" +
txtNewFile.Text);
else
// Otherwise, display a message.
litNoFile.Text = "<p>You must enter the name of a file " +
" to create.<p>";
}
protected void butEdit_Click(object sender, System.EventArgs e)
{
// If there is a file name, then start the editor.
if (lstFiles.SelectedItem != null)
Response.Redirect("EditFile.aspx?file=" +
lstFiles.SelectedItem.ToString());
else
// Otherwise, display a message.
litNoneSelected.Text = "<p>You must select a file.<p>";
}
protected void butDelete_Click(object sender, System.EventArgs e)
{
// Get the path and file names.
strPath = Session["Path"].ToString();
strFile = Request.QueryString["file"];
// If this is not a post-back event.
if (!Page.IsPostBack)
{
StreamReader strmEditFile;
try
{
// Open the file.
strmEditFile = File.OpenText(strPath + "\\" +
strFile);
// Read its text.
txtEditFile.Text =
strmEditFile.ReadToEnd().ToString();
// Close the file.
strmEditFile.Close();
}
catch (FileNotFoundException ex)
{
// If it doesn't exist, create it.
File.CreateText(strPath + "\\" +
strFile).Close();
// Clear text box.
txtEditFile.Text = "";
}
catch (System.UnauthorizedAccessException ex)
{
Server.Transfer("NotAuthorized.aspx");
}
strmEditWrite.Write(txtEditFile.Text);
strmEditWrite.Close();
// Reset changed flag.
ViewState["Changed"] = "false";
}
}
NotAuthorized.aspx
Quản lý thông tin người dùng
SignOn.aspx
SignOn.aspx.cs
public partial class SignOn : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSignOn_Click(object sender, EventArgs e)
{
string strPath;
// If the user exists, there is a directory of the same name.
strPath = Server.MapPath(Request.ApplicationPath) + "\\"
+ tbAccount.Text;
// Read its text.
truepas = strmEditFile.ReadToEnd().ToString();
// Close the file.
strmEditFile.Close();
if (truepas == pass)
{
return true;
}
else
{
lit.Text = "Password incorrect";
return false;
}
}
catch (FileNotFoundException ex)
{
lit.Text = "Error!Password file doesn't exist";
return false;
}
}
}
NewAccount.aspx
NewAccount.aspx.cs
public partial class NewAccount : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
{
Server.Transfer("NotAuthorized.aspx");
}*/
}
}
void SaveInfo(string strPath)
{
StreamWriter strmEditWrite;
strmEditWrite = File.CreateText(strPath + "\\" + "information.txt");
strmEditWrite.Write(tbRealname.Text+"\n"+tbBirthday.Text+"\n"+tbBirthyear.Tex
t);
strmEditWrite.Close();
strmEditWrite = File.CreateText(strPath + "\\" + "password.txt");
strmEditWrite.Write(tbPassword.Text);
strmEditWrite.Close();
}
}
UserInformation.aspx
UserInformation.aspx.cs
public partial class UserInformation : System.Web.UI.Page
{
string strPath;
protected void Page_Load(object sender, EventArgs e)
{
Tạo các trang
- SwitchBoard.aspx
- Calls.aspx
- AddContact.aspx
- DeleteContact.aspx
- ContactTypes.aspx
1. Thiết kế trang SwitchBoard.aspx
2. Thiết kế trang AddContact
2/18
3/18 Thêm vào Website class DataSet
4/18 5/18 6/18