Example #1
0
        protected void btnReg_Click(object sender, EventArgs e)
        {
            string sName = txtName.Text.Trim();

            if (sName == "")
            {
                MessageBox.Show("Please fill in Name");
            }
            else
            {
                string sEmail = txtEmail.Text.Trim();
                if (sEmail == "")
                {
                    MessageBox.Show("Please fill in Email");
                }
                else
                {
                    if (!CMain.IsValidEmail(sEmail))
                    {
                        MessageBox.Show("Email is not in correct format");
                    }
                    else
                    {
                        string sPhone = txtPhone.Text.Trim();
                        if (sPhone == "")
                        {
                            MessageBox.Show("Please fill in Phone Number");
                        }
                        else
                        {
                            switch (btnReg.CommandName)
                            {
                            case "create":
                                string sPswd = txtPass.Text.Trim();
                                if (PasswordInputOK(sPswd))
                                {
                                    //save to table Member:
                                    CMember         member = new CMember();
                                    DateTime        dt     = CMain.ConvertString_ToDate(txtDoB.Text);
                                    MySqlConnection conn   = CMain.GetConnection(ApplicationSession.DBName);
                                    bool            bln    = member.Insert(conn, sName, txtFullName.Text.Trim(), sEmail, sPswd,
                                                                           sPhone, txtAddr.Text.Trim(), txtCity.Text.Trim(), txtZipCode.Text.Trim(),
                                                                           txtCountry.Text.Trim(), dt, rbtnFemale.Checked ? "F" : "M", ApplicationSession.StoreID);
                                    if (bln)
                                    {
                                        MessageBox.Show("Registration successfull. Thank you!");

                                        ApplicationSession.member = new CMiniMember(member.Name, member.ID, member.Email);
                                        //masuk ke outlet screen
                                        Response.Redirect("HomePage.aspx");
                                    }
                                    else
                                    {
                                        MessageBox.Show("Registration is not successfull. Please try again.");
                                    }
                                }

                                break;

                            case "update":
                                if (_isDirty)
                                {
                                    bool bln = int.TryParse(btnReg.CommandArgument, out int iID);
                                    if (bln && iID > 0)
                                    {
                                        CMember         member = new CMember();
                                        MySqlConnection conn   = CMain.GetConnection(ApplicationSession.DBName);
                                        DateTime        dt     = CMain.ConvertString_ToDate(txtDoB.Text);
                                        bln = member.Update(conn, iID, sName, txtFullName.Text.Trim(), sEmail, sPhone, txtAddr.Text.Trim(),
                                                            txtCity.Text.Trim(), txtZipCode.Text.Trim(), txtCountry.Text.Trim(), dt,
                                                            rbtnFemale.Checked ? "F" : "M");
                                        if (bln)
                                        {
                                            MessageBox.Show("Update successfull. Thank you!");

                                            ApplicationSession.member = new CMiniMember(member.Name, member.ID, member.Email);
                                            //masuk ke outlet screen
                                            Response.Redirect("HomePage.aspx");
                                        }
                                        else
                                        {
                                            MessageBox.Show("Fail to update info. Please try again.");
                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show("Fail to update info. Please try again.");
                                    }
                                }
                                else
                                {
                                    Response.Redirect("HomePage.aspx");
                                }
                                break;
                            }
                        }
                    }
                }
            }
        }