protected void btnSave_Click(object sender, EventArgs e)
        {
            string addrName    = txtAddrName.Text.Trim();
            string addr1       = txtAddr1.Text.Trim();
            string addr2       = txtAddr2.Text.Trim();
            string addr3       = txtAddr3.Text.Trim();
            string city        = txtAddrCity.Text.Trim();
            string zip         = txtAddrZip.Text.Trim();
            int    geographyid = Int32.Parse(ddlState.SelectedValue);

            if (geographyid == 0)
            {
                geographyid = Utils.GetGeographyID(ddlCountry.SelectedValue);
            }
            UserManager.SaveShippingAddress(addrName, addr1, addr2, addr3, city, zip, geographyid);
            displayAddressView();
            Master.ShowMessage(Page.GetDisplayMember("UserAddress", "addressSaved", "Address '{0}' is saved. '", addrName));
        }
        private void saveShippingAddress()
        {
            string addrName    = txtAddressName.Text.Trim();
            string addr1       = txtShipAddr1.Text.Trim();
            string addr2       = txtShipAddr2.Text.Trim();
            string addr3       = txtShipAddr3.Text.Trim();
            string city        = txtShipCity.Text.Trim();
            string zip         = txtShipZip.Text.Trim();
            int    geographyid = Int32.Parse(ddlShipState.SelectedValue);
            string carrier     = ddlCarrier.SelectedValue;
            string carrierAcct = txtCarrierAcct.Text.Trim();


            if (geographyid == 0) // No State/Province needed, only country data
            {
                geographyid = Utils.GetGeographyID(ddlShipCountry.SelectedValue);
            }

            UserManager.SaveShippingAddress(addrName, addr1, addr2, addr3, city, zip, geographyid, true);
        }
        protected void btnCooperator_Click(object sender, EventArgs e)
        {
            string title         = ddlTitle.SelectedItem.Text;
            string firstname     = txtFirstname.Text.Trim();
            string lastname      = txtLastname.Text.Trim();
            string organization  = txtOrganization.Text.Trim();
            string addr1         = txtAddr1.Text.Trim();
            string addr2         = txtAddr2.Text.Trim();
            string addr3         = txtAddr3.Text.Trim();
            string admin1        = txtCity.Text.Trim();
            string admin2        = txtZip.Text.Trim();
            string phone         = txtPhone.Text.Trim();
            string altphone      = txtAltPhone.Text.Trim();
            string fax           = txtFax.Text.Trim();
            string email         = txtEmail.Text.Trim();
            string note          = txtNote.Text.Trim();
            int    geographyid   = Int32.Parse(ddlState.SelectedValue);
            string state         = ddlState.SelectedItem.Text;
            string country       = ddlCountry.SelectedItem.Text;
            bool   emailorder    = cbEmailOrder.Checked;
            bool   emailshipping = cbEmailShipping.Checked;
            bool   emailnews     = cbEmailInfor.Checked;

            int  webuid      = 0;
            int  newCoopID   = 0;
            bool needRefresh = false;

            using (SecureData sd = new SecureData(false, UserManager.GetLoginToken()))
            {
                using (DataManager dm = sd.BeginProcessing(true))
                {
                    if (geographyid == 0) // No State/Province needed, only country data
                    {
                        geographyid = Utils.GetGeographyID(ddlCountry.SelectedValue);
                    }

                    if (_level != "nologin")
                    {
                        webuid = sd.WebUserID;

                        int coopID = Toolkit.ToInt32(dm.ReadValue(@"
                                select 
                                    web_cooperator_id 
                                from 
                                    web_user
                                where 
                                    web_user_id = :webuserid
                                ", new DataParameters(":webuserid", webuid, DbType.Int32)), -1);

                        if (coopID < 0)
                        {
                            //insert into web_cooperator
                            newCoopID = dm.Write(@"
                            insert into web_cooperator
                            (title, last_name, first_name, organization, address_line1, address_line2, address_line3, city,postal_index, geography_id, primary_phone, secondary_phone, fax, email, is_active, note, created_date, created_by, owned_date, owned_by)
                            values
                            (:title, :lastname, :firstname, :organization, :address1, :address2, :address3, :admin1, :admin2, :geographyid, :phone, :altphone, :fax, :email, :isActive, :note, :createddate, :createdby, :owneddate, :ownedby)
                            ", true, "web_cooperator_id", new DataParameters(
                                                     ":title", title, DbType.String,
                                                     ":lastname", lastname, DbType.String,
                                                     ":firstname", firstname, DbType.String,
                                                     ":organization", organization, DbType.String,
                                                     ":address1", addr1, DbType.String,
                                                     ":address2", addr2, DbType.String,
                                                     ":address3", addr3, DbType.String,
                                                     ":admin1", admin1, DbType.String,
                                                     ":admin2", admin2, DbType.String,
                                                     ":geographyid", geographyid, DbType.Int32,
                                                     ":phone", phone, DbType.String,
                                                     ":altphone", altphone, DbType.String,
                                                     ":fax", fax, DbType.String,
                                                     ":email", email, DbType.String,
                                                     ":isActive", "Y", DbType.String,
                                                     ":note", note, DbType.String,
                                                     ":createddate", DateTime.UtcNow, DbType.DateTime2,
                                                     ":createdby", webuid, DbType.Int32,
                                                     ":owneddate", DateTime.UtcNow, DbType.DateTime2,
                                                     ":ownedby", webuid, DbType.Int32
                                                     ));

                            dm.Write(@"
                            update web_user
                            set    
                                web_cooperator_id = :coopid,
                                modified_date = :now
                            where
                                web_user_id = :wuserid
                            ", new DataParameters(
                                         ":coopid", newCoopID, DbType.Int32,
                                         ":now", DateTime.UtcNow, DbType.DateTime2,
                                         ":wuserid", webuid, DbType.Int32
                                         ));
                            needRefresh = true; // new token for new web coop id
                        }
                        else
                        {
                            //update
                            dm.Write(@"
                            update web_cooperator
                            set    
                                title = :title,
                                last_name = :lastname,
                                first_name = :firstname,
                                organization = :organization,
                                address_line1 = :address1,
                                address_line2 = :address2,
                                address_line3 = :address3,
                                city = :admin1,
                                postal_index = :admin2,
                                geography_id = :geographyid,
                                primary_phone = :phone,
                                secondary_phone = :altphone,
                                fax = :fax,
                                email = :email,
                                note = :note,
                                modified_date = :modifieddate,
                                modified_by   = :modifiedby
                             where
                                web_cooperator_id = :coopid
                                ", new DataParameters(
                                         ":title", title, DbType.String,
                                         ":lastname", lastname, DbType.String,
                                         ":firstname", firstname, DbType.String,
                                         ":organization", organization, DbType.String,
                                         ":address1", addr1, DbType.String,
                                         ":address2", addr2, DbType.String,
                                         ":address3", addr3, DbType.String,
                                         ":admin1", admin1, DbType.String,
                                         ":admin2", admin2, DbType.String,
                                         ":geographyid", geographyid, DbType.Int32,
                                         ":phone", phone, DbType.String,
                                         ":altphone", altphone, DbType.String,
                                         ":fax", fax, DbType.String,
                                         ":email", email, DbType.String,
                                         ":note", note, DbType.String,
                                         ":modifieddate", DateTime.UtcNow, DbType.DateTime2,
                                         ":modifiedby", webuid,
                                         ":coopid", coopID
                                         ));
                            newCoopID = coopID;
                        }
                    }
                    else
                    {
                    }
                }
            }

            if (_level != "nologin")
            {
                UserManager.SaveUserPref("EmailOrder", emailorder.ToString());
                UserManager.SaveUserPref("EmailShipping", emailshipping.ToString());
                UserManager.SaveUserPref("EmailNews", emailnews.ToString());
                saveShippingAddress();
            }

            // Anonymous user saves some infor in session
            string addr1_s       = txtShipAddr1.Text.Trim();
            string addr2_s       = txtShipAddr2.Text.Trim();
            string addr3_s       = txtShipAddr3.Text.Trim();
            string city_s        = txtShipCity.Text.Trim();
            string postalIndex_s = txtShipZip.Text.Trim();
            int    geographyid_s = Int32.Parse(ddlShipState.SelectedValue);
            string state_s       = ddlShipState.SelectedItem.Text;
            string country_s     = ddlShipCountry.SelectedItem.Text;
            string carrier       = ddlCarrier.SelectedItem.Text;
            string carrierAcct   = txtCarrierAcct.Text.Trim();

            if (geographyid_s == 0) // No State/Province needed, only country data
            {
                geographyid_s = Utils.GetGeographyID(ddlShipCountry.SelectedValue);
            }

            Requestor requestor = new Requestor(newCoopID, title, firstname, lastname, organization, addr1, addr2, addr3, admin1, admin2, geographyid, phone, altphone, fax, email, note, state, country, addr1_s, addr2_s, addr3_s, city_s, postalIndex_s, geographyid_s, state_s, country_s, carrier, carrierAcct, emailorder, emailshipping, emailnews);

            requestor.Webuserid  = webuid;
            Session["requestor"] = requestor;

            mv2.SetActiveView(vwDisplayInfor);
            displayInfor();
            if (_level == "nologin")
            {
                tUserAcct2.Visible = false;
            }

            if (needRefresh)
            {
                using (SecureData sd = new SecureData(false, UserManager.GetLoginToken()))
                {
                    using (DataManager dm = sd.BeginProcessing(true))
                    {
                        string username = UserManager.GetUserName();
                        string token    = UserManager.ValidateLogin(username, "string", true, false);
                        UserManager.SaveLoginCookieAndRedirect(username, token, true, "~/userinfor.aspx?action=view", null);
                    }
                }
            }
        }