コード例 #1
0
    public void LoadProfile()
    {
        ProfileCommon pcProfile;

        if (this.sUserName.Length > 0)
        {
            pcProfile = this.Profile.GetProfile(this.sUserName);
        }
        else
        {
            pcProfile = this.Profile;
        }

        txtAddressLine1.Text = pcProfile.AddressLine1;
        txtAddressLine2.Text = pcProfile.AddressLine2;
        txtCity.Text         = pcProfile.City;
        txtPostalCode.Text   = pcProfile.PostalCode;

        CCustomer customer =
            CCustomer.GetCustomer(Convert.ToInt32(pcProfile.CustomerID));

        if (customer != null)
        {
            txtFirstName.Text     = customer.Cus_FName;
            txtLastName.Text      = customer.Cus_LName;
            txtContactNumber.Text = customer.Cus_ContactNumber;
            txtRSAID.Text         = customer.Cus_IDNumber;
            imgPicture.ImageUrl   = customer.Cus_ProfilePic;
        }
    }
コード例 #2
0
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        if (sUserName != "")
        {
            if (!Roles.IsUserInRole(sUserName, "Admin"))
            {
                ProfileCommon pcProfile = Profile.GetProfile(sUserName);

                CCustomer customer =
                    CCustomer.GetCustomer(Convert.ToInt32(pcProfile.CustomerID));

                if (customer != null)
                {
                    string sVirtualFolder = customer.Cus_ProfilePic;
                    string sPhysicalPath  = Server.MapPath(sVirtualFolder);

                    //Step 3: Check if file exists
                    if (File.Exists(sPhysicalPath))
                    {
                        //Step 4: Delete image file
                        File.Delete(sPhysicalPath);
                    }
                }


                lblStatus.Text      = "User \"" + sUserName + "\" successfully deleted.";
                lblStatus.ForeColor = System.Drawing.Color.Green;
                lblStatus.Font.Size = 12;

                //Step 4: Delete record from database
                Membership.DeleteUser(sUserName, true);

                LoadAllUsers();
            }
            else
            {
                lblStatus.Text      = "User \"" + sUserName + "\" is an admin, you cannot delete user with admin role.";
                lblStatus.ForeColor = System.Drawing.Color.Red;
                lblStatus.Font.Size = 12;
            }
        }
    }
コード例 #3
0
    public void SaveProfile()
    {
        int cus_ID = 0;

        ProfileCommon pcProfile = this.Profile;

        CCustomer customer =
            CCustomer.GetCustomer(Convert.ToInt32(pcProfile.CustomerID));

        // When saving profile picture
        // Check whether the user also want to save profile picture
        // If so, call saveProfilePicture to save the attached image file If the user is updating the profile picture as well
        // Pass the previous VirtualPath to delete the Existing profile picture.

        if (customer != null)
        {
            if (pnlChangePicture.Visible)
            {
                //Before updating, delete previous image file if exist
                string sVirtualPath = Server.MapPath(customer.Cus_ProfilePic);

                if (File.Exists(sVirtualPath))
                {
                    //Step 4: Delete image file
                    File.Delete(sVirtualPath);
                }

                CCustomer.UpdateCustomer(Convert.ToInt32(pcProfile.CustomerID),
                                         txtFirstName.Text,
                                         txtLastName.Text,
                                         txtContactNumber.Text,
                                         txtRSAID.Text,
                                         saveImage());
            }
            else
            {
                CCustomer.UpdateCustomer(Convert.ToInt32(pcProfile.CustomerID),
                                         txtFirstName.Text,
                                         txtLastName.Text,
                                         txtContactNumber.Text,
                                         txtRSAID.Text,
                                         customer.Cus_ProfilePic);
            }
        }
        else
        {
            if (pnlChangePicture.Visible)
            {
                cus_ID = CCustomer.AddCustomer(txtFirstName.Text,
                                               txtLastName.Text,
                                               txtContactNumber.Text,
                                               txtRSAID.Text,
                                               saveImage()
                                               );
            }
            else
            {
                cus_ID = CCustomer.AddCustomer(txtFirstName.Text,
                                               txtLastName.Text,
                                               txtContactNumber.Text,
                                               txtRSAID.Text,
                                               null
                                               );
            }
        }

        pcProfile.AddressLine1 = txtAddressLine1.Text;
        pcProfile.AddressLine2 = txtAddressLine2.Text;
        pcProfile.City         = txtCity.Text;
        pcProfile.PostalCode   = txtPostalCode.Text;
        pcProfile.CustomerID   = cus_ID;

        pcProfile.Save();

        pnlChangePicture.Visible = false;
    }