protected void inputResetPassword_Click(object sender, EventArgs e) { Member member = DatabaseRepositories.findEmail(inputemail.Text); txtError.Text = ""; txtError.ForeColor = System.Drawing.Color.Red; if (member == null) { txtError.Text = "Email Not Found"; } else { string name = member.Name; string newPassword; const string alphabet = "abcdefghijklmnopqrstuvwxyz"; Random rand = new Random((int)DateTime.Now.Ticks); string number1 = rand.Next(0, 9).ToString(); string number2 = rand.Next(0, 9).ToString(); string char1 = alphabet.Substring(rand.Next(0, alphabet.Length - 1), 1); string char2 = alphabet.Substring(rand.Next(0, alphabet.Length - 1), 1); string cutName = name.Substring(0, 2); newPassword = number1 + number2 + char1 + char2 + cutName; txtError.ForeColor = System.Drawing.Color.Green; txtError.Text = "Your New Password : " + newPassword; List <Member> m = DatabaseRepositories.getAllMember(inputemail.Text); int row = DatabaseRepositories.updateMember(m, newPassword); } }
protected void btnLogin_Click(object sender, EventArgs e) { Member member = DatabaseRepositories.LoginUser(inputEmail.Text, inputPassword.Text); txtError.Text = ""; txtError.ForeColor = System.Drawing.Color.Red; if (member == null) { txtError.Text = "User Not Found"; } else { if (isRemember.Checked) { Response.Cookies["UserCookies"].Expires = DateTime.Now.AddHours(1); } else { Response.Cookies["UserCookies"].Expires = DateTime.Now.AddHours(-1); } Response.Cookies["UserCookies"].Value = inputEmail.Text; Session["user"] = member; Response.Redirect("Home.aspx"); } }
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { string memberEmail = GridView1.Rows[e.RowIndex].Cells[1].Text; Member m = DatabaseRepositories.findEmail(memberEmail); int row = DatabaseRepositories.deleteMember(m); if (row > 0) { Response.Redirect("ViewCustomer.aspx"); } else { errorText.ForeColor = System.Drawing.Color.Red; errorText.Text = "Delete Failed"; } }
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { string cakeName = GridView1.Rows[e.RowIndex].Cells[0].Text; Cake c = DatabaseRepositories.findCake(cakeName); int row = DatabaseRepositories.deleteCake(c); if (row > 0) { Response.Redirect("Cake.aspx"); } else { errorText.ForeColor = System.Drawing.Color.Red; errorText.Text = "Delete Failed"; } }
protected void Page_Load(object sender, EventArgs e) { string cakeName = Request.QueryString["cakeName"]; if (cakeName != null) { editCake = DatabaseRepositories.findCake(cakeName); if (editCake != null) //check if cake exists { if (!Page.IsPostBack) { inputCakeName.Text = editCake.CakeName; inputPrice.Text = Convert.ToString(editCake.Price); inputStock.Text = Convert.ToString(editCake.Stock); } } } }
protected void registerBtn_Click(object sender, EventArgs e) { string name = inputName.Text; string email = inputEmail.Text; string password = inputPassword.Text; string cPassword = confirmPassword.Text; string phone = inputPhoneNumber.Text; string address = inputAddress.Text; System.DateTime dob; Member member = DatabaseRepositories.findEmail(email); txtError.Text = ""; txtError.ForeColor = System.Drawing.Color.Red; if (member == null) { if (!DateTime.TryParse(inputDOB.Text, out dob)) { txtError.Text = "DOB is Wrong"; } else if (name == "") { txtError.Text = "Name Must Not Empty"; } else if (email == "") { txtError.Text = "Email Must Not Empty"; } else if (checkEmail(email) == false) { txtError.Text = "Wrong Email Format"; } else if (password == "") { txtError.Text = "Password Must Not Empty"; } else if (cPassword != password) { txtError.Text = "Password Not Match"; } else if (phone == "") { txtError.Text = "Phone Must Not Empty"; } else if (address == "") { txtError.Text = "Address Must Not Empty"; } else { Member m = UserFactory.create(email, password, name, dob, phone, address); int row = DatabaseRepositories.register(m); if (row > 0) { txtError.ForeColor = System.Drawing.Color.Blue; txtError.Text = "Register Success"; } else { txtError.Text = "Register Failed"; } } } else { txtError.Text = "Email Already Taken"; } }
protected void btnUpdateCake_Click(object sender, EventArgs e) { string picExt; string cakePic; //Cake cake = DatabaseRepositories.findCake(inputCakeName.Text); Cake cake = DatabaseRepositories.findCake(inputCakeName.Text); if (editCake == null) { errorText.Text = "Cake Does Not Exist"; } else { if (inputCakeName.Text == "") { errorText.Text = "Input Cake Name"; } else if (inputCakeName.Text != editCake.CakeName && cake != null) { errorText.Text = "Cake Name Already Exist"; } else if (inputPrice.Text == "") { errorText.Text = "Cake Price Must Not Empty"; } else if (inputStock.Text == "") { errorText.Text = "Cake Stock Must Not Empty & Greater Than 0"; } else if (Int32.Parse(inputStock.Text) <= 0) { errorText.Text = "Cake Stock Must Not Empty & Greater Than 0"; } else { if (this.uploadPicture.HasFile) { //picExt = uploadPicture.FileName.Substring(uploadPicture.FileName.Length - 4); picExt = System.IO.Path.GetExtension(uploadPicture.FileName).ToLower(); if (picExt == ".jpg" || picExt == ".png") { this.uploadPicture.SaveAs(Server.MapPath("~/") + inputCakeName.Text + picExt); cakePic = inputCakeName.Text + picExt; string cakeName = inputCakeName.Text; int cakePrice = Int32.Parse(inputPrice.Text); int cakeStock = Int32.Parse(inputStock.Text); List <Cake> c = DatabaseRepositories.getAllCake(editCake.CakeName); int row = DatabaseRepositories.updateCake(c, cakeName, cakePrice, cakeStock, cakePic); } else { errorText.Text = "Image Ekstension Must be .jpg or .png"; } } else { string cakeName = inputCakeName.Text; int cakePrice = Int32.Parse(inputPrice.Text); int cakeStock = Int32.Parse(inputStock.Text); cakePic = null; List <Cake> c = DatabaseRepositories.getAllCake(editCake.CakeName); int row = DatabaseRepositories.updateCake(c, cakeName, cakePrice, cakeStock, cakePic); } Response.Redirect("Cake.aspx"); } } }
void loadData() { GridView1.DataSource = DatabaseRepositories.getAllMember(); GridView1.DataBind(); }
void loadDataCustomer() { GridView2.DataSource = DatabaseRepositories.getAllCake(); GridView2.DataBind(); }
void loadDataAdmin() { GridView1.DataSource = DatabaseRepositories.getAllCake(); GridView1.DataBind(); }
protected void btnAddCake_Click(object sender, EventArgs e) { string picExt; string cakePic; Cake cake = DatabaseRepositories.findCake(inputCakeName.Text); if (cake == null) { if (inputCakeName.Text == "") { errorText.Text = "Input Cake Name"; } else if (inputPrice.Text == "") { errorText.Text = "Cake Price Must Not Empty"; } else if (inputStock.Text == "") { errorText.Text = "Cake Stock Must Not Empty & Greater Than 0"; } else if (Int32.Parse(inputStock.Text) <= 0) { errorText.Text = "Cake Stock Must Not Empty & Greater Than 0"; } else { if (this.uploadPicture.HasFile) { picExt = uploadPicture.FileName.Substring(uploadPicture.FileName.Length - 4); if (picExt == ".jpg" || picExt == ".png") { this.uploadPicture.SaveAs(Server.MapPath("~/") + inputCakeName.Text + picExt); cakePic = inputCakeName.Text + picExt; string cakeName = inputCakeName.Text; int cakePrice = Int32.Parse(inputPrice.Text); int cakeStock = Int32.Parse(inputStock.Text); Cake c = CakeFactory.create(cakeName, cakePrice, cakeStock, cakePic); int row = DatabaseRepositories.addCake(c); if (row > 0) { errorText.ForeColor = System.Drawing.Color.Blue; errorText.Text = "Add Cake Success"; } else { errorText.Text = "Add Cake Failed"; } } else { errorText.Text = "Image Ekstension Must be .jpg or .png"; } } else { string cakeName = inputCakeName.Text; int cakePrice = Int32.Parse(inputPrice.Text); int cakeStock = Int32.Parse(inputStock.Text); cakePic = null; Cake c = CakeFactory.create(cakeName, cakePrice, cakeStock, cakePic); int row = DatabaseRepositories.addCake(c); if (row > 0) { errorText.ForeColor = System.Drawing.Color.Blue; errorText.Text = "Add Cake Success, No Picture Added"; } else { errorText.Text = "Add Cake Failed"; } } } } else { errorText.Text = "Cake Name Already Exist"; } }