public override string ToString() { string outputStr = "Ticket Details" + "\n" + "Student Id: " + StudentId + "\n" + "Student Category: " + StudentCategory.ToString() + "\n" + CategoryName + "\n" + "Speed Limit: " + SpeedLimit + "\n" + "Speed Reported: " + SpeedReported + "\n" + "Fine: " + Fine.ToString("C"); return(outputStr); }
public void btnGetBook_Click(object sender, EventArgs e) { // Disclaimers if (txtBookID.Text == "") { goto End; } //Remove single & double quoteswhich cause sql troubles foreach (Control c in this.Controls) { if (c is TextBox || c is ComboBox) { c.Text = c.Text.Replace("'", ""); c.Text = c.Text.Replace("\"", ""); } } //Declarations string Avail, BookID, MemID; DateTime LendD; double Fine; BookID = txtBookID.Text; //Get Details from Book Table string sqlBook = string.Format("SELECT TitleID FROM Book WHERE BookID = '{0}'", BookID); OleDbCommand cmdBook = new OleDbCommand(sqlBook, db.con); if (db.con.State.Equals(ConnectionState.Closed)) { db.con.Open(); } OleDbDataReader drBook = cmdBook.ExecuteReader(); drBook.Read(); //Disclaimer: If Invalid BookID if (drBook.HasRows) { IsValidID = true; TitleID = drBook["TitleID"].ToString(); } else { MessageBox.Show("No Book exist with the given BookID", "Invalid BookID", MessageBoxButtons.OK, MessageBoxIcon.Error); IsValidID = false; txtBookID.Clear(); goto End; } //Call Method for details. Methods m = new Methods(); m.TitleInfo(TitleID, out IsValidID, out Title, out Author, out Genre, out Publish, out Pg, out ISBN, out Ty, out Price, out Popul, out Times, out NoAvail, out NoBooks); //Error Handling if (IsValidID == false) { MessageBox.Show("Some Error Occured"); goto End; } //Get Lend Details from lendStatus string sqlLendD = string.Format("SELECT * FROM LendStatus WHERE BookID = '{0}'", BookID); OleDbCommand cmdLendD = new OleDbCommand(sqlLendD, db.con); if (db.con.State.Equals(ConnectionState.Closed)) { db.con.Open(); } OleDbDataReader drLendD = cmdLendD.ExecuteReader(); drLendD.Read(); if (drLendD.HasRows) // If lent { //Call method to calculate fines bool isBFine, IsBlocked; int Days; DateTime iDate; int MTi; m.FindBookFine(BookID, out isBFine, out Fine, out Days, out iDate, out MemID, out IsBlocked, out MTi); //Load into variables MemID = drLendD["MemberID"].ToString(); Avail = "Lent"; LendD = DateTime.Parse(drLendD["LendDate"].ToString()); //Show details lblLentTo.Text = MemID; lblLentOn.Text = LendD.ToString("dd MMMM yyyy"); lblFine.Text = Fine.ToString(); } else { Avail = "Available"; //Modify Form lblLLFine.Visible = lblLLLentOn.Visible = lblLLLentTo.Visible = lblFine.Visible = lblLentOn.Visible = lblLentTo.Visible = false; } //Display all details lblTitle.Text = Title; lblAuthor.Text = Author; lblGenre.Text = Genre; lblPublish.Text = Publish; lblPg.Text = Pg; lblISBN.Text = ISBN; lblTy.Text = Ty; lblPrice.Text = Price; lblPop.Text = Popul; lblAvail.Text = Avail; btnRemtitle.Enabled = false; //Modify Form lblTimes.Visible = lblNoBooks.Visible = lblAvNo.Visible = false; txtTitleID.Clear(); txtBookID.Enabled = txtTitleID.Enabled = btnGetTitle.Visible = btnGetBook.Visible = lblLLNoAvail.Visible = lblLLNoBooks.Visible = lblLLTimes.Visible = false; MakeTaller(); End : if (db.con.State.Equals(ConnectionState.Open)) { db.con.Close(); } }
private void btnGet_Click(object sender, EventArgs e) { //Remove single & double quotes which cause sql troubles foreach (Control c in this.Controls) { if (c is TextBox || c is ComboBox || c is RichTextBox) { c.Text = c.Text.Replace("'", ""); c.Text = c.Text.Replace("\"", ""); } } //Declare MemID based on Input Type if (cvar.InsertID && txtMemID.Text == "") { MemID = cvar.MemID; txtMemID.Text = MemID; } // If input from outside. else if (txtMemID.Text == "") { goto End; // If Form opened anew. } else { MemID = txtMemID.Text; // If Value entered in textbox. } //Access Database for Details string sqlMemD = string.Format("SELECT * FROM Member WHERE MemberID = '{0}'", MemID); OleDbCommand cmdMemD = new OleDbCommand(sqlMemD, db.con); if (db.con.State.Equals(ConnectionState.Closed)) { db.con.Open(); } OleDbDataReader drMemD = cmdMemD.ExecuteReader(); if (drMemD.Read()) { txtMemID.Enabled = false; MakeWide(); //Make the form wider. txtFName.Text = drMemD["FName"].ToString(); txtLName.Text = drMemD["LName"].ToString(); txtAddr.Text = drMemD["Address"].ToString(); txtEmail.Text = drMemD["Email"].ToString(); txtGuardian.Text = drMemD["Guardian"].ToString(); txtNIC.Text = drMemD["NIC"].ToString(); txtTP.Text = drMemD["TP"].ToString(); txtWork.Text = drMemD["MWork"].ToString(); lblStatus.Text = drMemD["MStatus"].ToString(); Fine = double.Parse(drMemD["Fine"].ToString()); lblFine.Text = Fine.ToString() + "/-"; lblRenew.Text = drMemD["Renewed"].ToString(); Popul p = new Popul(); TimesBorrow = int.Parse(drMemD["TimesBorrow"].ToString()); if (Fine == 0) { btnFine.Enabled = false; } else { btnFine.Enabled = true; } DateTime now = DateTime.Today; DateTime Dob = DateTime.Parse(drMemD["DateOfBirth"].ToString()); int age = now.Year - Dob.Year; if (Dob > now.AddYears(-age)) { age--; } lblAge.Text = age.ToString(); MType = drMemD["MType"].ToString(); if (MType == "Child") { cboxType.SelectedIndex = 0; lblLLg.Visible = txtGuardian.Visible = true; lblLLNic.Text = "Guardian's NIC"; } else if (MType == "Adult") { cboxType.SelectedIndex = 1; lblLLg.Visible = txtGuardian.Visible = false; lblLLNic.Text = "NIC Number"; cboxType.Enabled = false; } if (lblStatus.Text == "Blocked") { btnBlack.Text = "Remove from Blacklist"; } else { btnBlack.Text = "Add to Blacklist"; } //Split & Use Date of Birth string Fulldob = drMemD["DateOfBirth"].ToString(); string[] DoBSpace = Fulldob.Split(' '); // Split Date from Time string[] DoBSlash = DoBSpace[0].Split('/'); // SpilitDate components txtDobMon.Text = DoBSlash[0]; txtDobDate.Text = DoBSlash[1]; txtDobYear.Text = DoBSlash[2]; //Split & Use Date Joined DateJ = DateTime.Parse(drMemD["DateJoined"].ToString()); FullDate = DateJ.ToString(); string[] DateSpace = FullDate.Split(' '); // Split Date from Time string[] DateSlash = DateSpace[0].Split('/'); // SpilitDate components lblDate.Text = DateSlash[1] + "-" + DateSlash[0] + "-" + DateSlash[2]; // To Retrive BookIDs string sqlBookID = string.Format("SELECT BookID FROM LendStatus WHERE MemberID = '{0}'", MemID); OleDbCommand cmdBookID = new OleDbCommand(sqlBookID, db.con); OleDbDataReader drBookID = cmdBookID.ExecuteReader(); while (drBookID.Read()) // For Each bookID { string BookID = drBookID["BookID"].ToString(); string sqlBook = string.Format("SELECT TitleID FROM Book WHERE BookID = '{0}'", BookID); //Get TitleID from BookID OleDbCommand cmdBook = new OleDbCommand(sqlBook, db.con); OleDbDataReader drBook = cmdBook.ExecuteReader(); if (drBook.Read()) { string TitleID = drBook["TitleID"].ToString(); string sqlTitle = string.Format("SELECT BTitle, Author, Genre FROM Title WHERE TitleID = '{0}'", TitleID); // Get Title info from TitleID OleDbCommand cmdTitle = new OleDbCommand(sqlTitle, db.con); OleDbDataReader drTitle = cmdTitle.ExecuteReader(); if (drTitle.Read()) { lboxBookID.Items.Add(BookID); lboxTitle.Items.Add(drTitle["BTitle"].ToString()); lboxAuthor.Items.Add(drTitle["Author"].ToString()); lboxGenre.Items.Add(drTitle["Genre"].ToString()); } } } //To Get last Check In string sqlCheckIn = string.Format("SELECT Max(CDate) as MaxCheckIn FROM CheckInOut WHERE MemberID = '{0}' AND EVENT = 'In' GROUP BY MemberID, Event", MemID); OleDbCommand cmdCheckIn = new OleDbCommand(sqlCheckIn, db.con); OleDbDataReader drCheckIn = cmdCheckIn.ExecuteReader(); if (drCheckIn.Read() & drCheckIn.HasRows) { DateTime CheckIn = DateTime.Parse(drCheckIn["MaxCheckIn"].ToString()); lblCheckIn.Text = CheckIn.ToString("dd-MM-yyyy"); } //Calculate Recent Star Points Via method & Display Popul star = new Popul(); fullStars = star.MemCalc(MemID, false); Stars = double.Parse(Math.Round(decimal.Parse(fullStars.ToString()), 2).ToString()); lblStars.Text = Stars.ToString(); btnGet.Enabled = false; } else { MessageBox.Show("MemberID does not match with any of the members. Try again", "Invalid MemberID", MessageBoxButtons.OK, MessageBoxIcon.Error); } cvar.MemID = ""; cvar.InsertID = false; if (db.con.State.Equals(ConnectionState.Open)) { db.con.Close(); } End : if (db.con.State.Equals(ConnectionState.Open)) { db.con.Close(); } }