private bool ErrorInEdit(Artist artist) { bool hasError = false; // Check for existing username from both tables CustomerDao custUsernameDao = new CustomerDao(); Customer checkCust = custUsernameDao.Get("USERNAME", username.Text); ArtistDao artistUsernameDao = new ArtistDao(); Artist checkArtist = artistUsernameDao.Get("USERNAME", username.Text); if (checkArtist != null) { if (checkArtist.Username == artist.Username) { checkArtist = null; } } if (checkCust != null || checkArtist != null) { // There is an existing username lblEditError = FormatLbl.Error("An account with this username already exists."); lblEditError.ID = "lblEditError"; hasError = true; } // Reset values checkCust = null; checkArtist = null; // Check for existing email CustomerDao custEmailDao = new CustomerDao(); checkCust = custEmailDao.Get("EMAIL", email.Text); ArtistDao artistEmailDao = new ArtistDao(); checkArtist = artistEmailDao.Get("EMAIL", email.Text); if (checkArtist != null) { if (checkArtist.Email == artist.Email) { checkArtist = null; } } if (checkCust != null || checkArtist != null) { // There is an existing email lblEditError = FormatLbl.Error("An account with this email already exists."); lblEditError.ID = "lblEditError"; hasError = true; } return(hasError); }
protected void btnEdit_Click(object sender, EventArgs e) { bool hasError = false; // Verify that stocks are correctly entered try { int stocks = Convert.ToInt32(txtStocks.Text); // Verify that stocks are >= 0 if (stocks < 0) { hasError = true; // Show error message lblEditError = FormatLbl.Error("Ensure that stocks are a positive value."); } else { artpiece.Stocks = stocks; } } catch (Exception ex) { hasError = true; // Show error message lblEditError = FormatLbl.Error("Ensure that stocks are numerical."); } if (!hasError) { //Update artpiece ArtpieceDao dao = new ArtpieceDao(); dao.Update(artpiece); // Show success msg lblEditError = FormatLbl.Success("Stocks successfully updated"); } // Refresh page //Net.RefreshPage(); }
private bool FormHasError() { string errorMsg = String.Empty; if (txtCardHolderName.Text == String.Empty || txtCardNo.Text == String.Empty || txtCvv.Text == String.Empty || txtExpDate.Text == String.Empty || txtAddress.Text == String.Empty) { errorMsg = "Ensure all fields are filled in."; } //char[] cardNoChar = txtCardNo.Text.ToCharArray(); /*for (int i = 0; i < cardNoChar.Length; i++) * { * if (!Char.IsDigit(cardNoChar[i])) * errorMsg = "Ensure that Card No. contains only digits"; * }*/ // check the credit card if (!Bank.Validate(txtCardNo.Text, txtCvv.Text, txtExpDate.Text, txtCardHolderName.Text)) // If card is invalid { errorMsg = "Credit Card information is not correct and valid."; } // Check date if (!Quick.CheckRegex(txtExpDate.Text, @"\d\d\/\d\d")) // If expDate is not 00/00 format { errorMsg = "Ensure that Expiry Date is MM/YY format"; } if (errorMsg == String.Empty) { return(false); } else { lblErrorMsg = FormatLbl.Error(errorMsg); return(true); } }
protected void uploadBt_Click(object sender, EventArgs e) { // Validate form first string errorMsg = ValidateForm(); if (errorMsg != null) // If there is an error { // Set the error msg lblUploadError = FormatLbl.Error(errorMsg); } else // If there is no error { // Obtain artist info Artist artist = (Artist)Session["artist"]; // Generate Artpiece Id IdGen IdGen = new IdGen(); String ArtpieceId = IdGen.GenerateId("Artpiece"); // Obtain the values from the form Classes.Artpiece artpiece = new Classes.Artpiece(); artpiece.ArtpieceId = ArtpieceId; artpiece.ArtistId = artist.Id; artpiece.Tags = txtTags.Text; artpiece.About = txtDescription.Text; artpiece.Title = txtTitle.Text; artpiece.Price = Convert.ToDouble(txtPrice.Text); artpiece.Stocks = Convert.ToInt32(txtStocks.Text); // Need to validate // NOTE! NEED TO CHANGE TO DROPDOWNLIST if (rblForSale.SelectedValue == "yes") // If the artpiece is for sale { artpiece.IsForSale = true; } else { artpiece.IsForSale = false; } // NOTE! NEED TO CHANGE TO DROPDOWNLIST if (rblIsPublic.SelectedValue == "yes") // If the artpiece is public { artpiece.IsPublic = true; } else { artpiece.IsPublic = false; } //debug Quick.Print("selected forsale is " + rblIsPublic.SelectedValue); FileUtil file = new FileUtil(fileBt, "~/Pics/"); // Set image link artpiece.ImageLink = file.GetAddress(); // VERIFY THAT IMAGE LINK DOES NOT HAVE DUPLICATE NAME ArtpieceDao linkCheckDao = new ArtpieceDao(); Classes.Artpiece checkArtpiece = linkCheckDao.Get("IMAGELINK", file.GetAddress()); if (checkArtpiece != null) // If there is a duplicate file name { // Set the error msg lblUploadError = FormatLbl.Error("An image with that name already exists. Please rename."); } else // If there is no duplicate { Quick.Print(file.GetFileName().Substring(file.GetFileName().Length - 4)); // Check file type if (file.GetFileName().Substring(file.GetFileName().Length - 4) != ".jpg" && file.GetFileName().Substring(file.GetFileName().Length - 4) != ".png" && file.GetFileName().Substring(file.GetFileName().Length - 5) != ".jpeg") { // Show error lblUploadError = FormatLbl.Error("File must be a picture file that ends in jpg, png, or jpeg"); } else { // Perform file upload file.PerformUpload(); // Perform database insert ArtpieceDao dao = new ArtpieceDao(); dao.Add(artpiece); //To redirect user to the new artpiece Response.Redirect("~/Pages/artpiece.aspx?Id=" + artpiece.ArtpieceId); } } } }