Beispiel #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            System.Data.DataTable dsCustomers = new System.Data.DataTable();
            WcfCustomersVB.ServiceCustomer client = new WcfCustomersVB.ServiceCustomer();

            dsCustomers = client.GetCustomers(0);

            gvCustomers.DataSource = dsCustomers;
            gvCustomers.DataBind();
        }
Beispiel #2
0
        protected void gvCustomers_RowDeleting(object sender, System.Web.UI.WebControls.GridViewDeleteEventArgs e)
        {
            int CustomerID = 0;
            int lErrorCode = 0;
            Boolean bSuccess = false;
            CustomerID = int.Parse(gvCustomers.DataKeys[e.RowIndex].Value.ToString());
            WcfCustomersVB.ServiceCustomer client = new WcfCustomersVB.ServiceCustomer();
            bSuccess = client.DeleteCustomer(CustomerID, ref lErrorCode);

            if (bSuccess)
            {
                Response.Redirect("~/Customer/Default.aspx");
            }
        }
Beispiel #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            System.Data.DataTable dsCustomers = new System.Data.DataTable();
            System.Data.DataTable dsCountry = new System.Data.DataTable();
            WcfCustomersVB.ServiceCustomer client = new WcfCustomersVB.ServiceCustomer();

            dsCustomers = client.GetCustomers(0);
            dsCountry = client.GetCountries();

            //CountryDD.DataSource = dsCountry;
            //CountryDD.DataValueField = "CountryID";
            //CountryDD.DataTextField = "CountryName";
            //CountryDD.DataBind();

            GridView1.DataSource = dsCustomers;
            GridView1.DataBind();
        }
        private bool SaveAddressByCustomer(object sender, ref int lCustomerID, ref int lAddressID, ref int lErrorCode, string mode = "Edit")
        {
            Boolean bSuccess = false;
            int CountryVal = 0;
            int ProvinceVal = 0;
            int CityVal = 0;
            int AddressTypeVal = 0;

            DataKey key = dvAddress.DataKey;
            DropDownList ddCountry = (DropDownList)dvAddress.FindControl("ddCountry" + mode);
            DropDownList ddProvince = (DropDownList)dvAddress.FindControl("ddProvince" + mode);
            DropDownList ddCity = (DropDownList)dvAddress.FindControl("ddCity" + mode);
            TextBox txtAddress = (TextBox)dvAddress.FindControl(mode + "AddressTextBox");
            TextBox txtPostCode = (TextBox)dvAddress.FindControl(mode + "PostCodeTextBox");
            RadioButtonList rblAddressTypes = (RadioButtonList)dvAddress.FindControl(mode + "AddressTypeRadio");

            lCustomerID = Convert.ToInt32(CustomerIDValue.Value);
            lAddressID = Convert.ToInt32(AddressIDValue.Value);
            CountryVal = Convert.ToInt32(ddCountry.SelectedValue);
            ProvinceVal = Convert.ToInt32(ddProvince.SelectedValue);
            CityVal = Convert.ToInt32(ddCity.SelectedValue);
            AddressTypeVal = Convert.ToInt32(rblAddressTypes.SelectedValue);
            WcfCustomersVB.ServiceCustomer client = new WcfCustomersVB.ServiceCustomer();
            bSuccess = client.SaveAddress(ref lAddressID,CountryVal, ProvinceVal,CityVal, txtAddress.Text,txtPostCode.Text, ref lErrorCode);
            if (bSuccess)
            {
                bSuccess = client.LinkAddressToCustomer(lCustomerID, lAddressID, AddressTypeVal, ref lErrorCode);
            }
            return bSuccess;
        }
        protected void Country_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (dvAddress.CurrentMode == DetailsViewMode.Edit)
            {
                strCurrentMode = "Edit";
            }
            else if (dvAddress.CurrentMode == DetailsViewMode.Insert)
            {
                strCurrentMode = "Insert";
            }
            DropDownList ddCountry = (DropDownList)dvAddress.FindControl("ddCountry" + strCurrentMode);
            DropDownList ddProvince = (DropDownList)dvAddress.FindControl("ddProvince" + strCurrentMode);
            DropDownList ddCity = (DropDownList)dvAddress.FindControl("ddCity" + strCurrentMode);
            ddProvince.Items.Clear();
            ddProvince.Items.Add(new ListItem("--Select Province--", ""));
            ddCity.Items.Clear();
            ddCity.Items.Add(new ListItem("--Select City--", ""));

            int CountryVal = 0;
            if (ddCountry.SelectedItem.Value!="")
            {
                CountryVal = Convert.ToInt32(ddCountry.SelectedItem.Value);
            }

            ddProvince.AppendDataBoundItems = true;

            try
            {
                System.Data.DataTable dsProvinces = new System.Data.DataTable();
                WcfCustomersVB.ServiceCustomer client = new WcfCustomersVB.ServiceCustomer();

                dsProvinces = client.GetProvinces(CountryVal);
                ddProvince.DataSource = dsProvinces;
                ddProvince.DataTextField = "ProvinceName";
                ddProvince.DataValueField = "ProvinceID";
                ddProvince.DataBind();
                if (ddProvince.Items.Count > 1)
                {
                    ddProvince.Enabled = true;
                }
                else
                {
                    ddProvince.Enabled = false;
                    ddCity.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void getAddresses(int CustomerID, int AddressID)
        {
            System.Data.DataTable dsCustomerAddress = new System.Data.DataTable();
            WcfCustomersVB.ServiceCustomer client = new WcfCustomersVB.ServiceCustomer();

            if (CustomerID != 0 && AddressID!=0)
            {
                dsCustomerAddress = client.GetCustomerAddress(CustomerID, AddressID);
            }

            dvAddress.DataSource = dsCustomerAddress;
            dvAddress.DataBind();

            if (strCurrentMode=="Insert")
            {
                DropDownList ddCountry = (DropDownList)dvAddress.FindControl("ddCountry" + strCurrentMode);
                DropDownList ddProvince = (DropDownList)dvAddress.FindControl("ddProvince" + strCurrentMode);
                DropDownList ddCity = (DropDownList)dvAddress.FindControl("ddCity" + strCurrentMode);
                ddCountry.AppendDataBoundItems = true;
                try
                {
                    System.Data.DataTable dsCountry = new System.Data.DataTable();

                    dsCountry = client.GetCountries();
                    ddCountry.DataSource = dsCountry;
                    ddCountry.DataTextField = "CountryName";
                    ddCountry.DataValueField = "CountryID";
                    ddCountry.DataBind();
                    ddProvince.Enabled = false;
                    ddCity.Enabled = false;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                SetupAddressType();
            }
        }
        protected void SetupProvinceDD(int SelectedProvinceVal = 0, int CountryID = 0)
        {
            DropDownList ddProvince = (DropDownList)dvAddress.FindControl("ddProvince" + strCurrentMode);
            ddProvince.AppendDataBoundItems = true;
            try
            {
                System.Data.DataTable dsProvince = new System.Data.DataTable();
                WcfCustomersVB.ServiceCustomer client = new WcfCustomersVB.ServiceCustomer();

                dsProvince = client.GetProvinces(CountryID);
                ddProvince.DataSource = dsProvince;
                ddProvince.DataTextField = "ProvinceName";
                ddProvince.DataValueField = "ProvinceID";
                ddProvince.DataBind();
                ddProvince.SelectedValue = SelectedProvinceVal.ToString();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        protected void SetupCountryDD(int SelectCountryVal= 0)
        {
            DropDownList ddCountry = (DropDownList)dvAddress.FindControl("ddCountry" + strCurrentMode);
            ddCountry.AppendDataBoundItems = true;
            try
            {
                System.Data.DataTable dsCountry = new System.Data.DataTable();
                WcfCustomersVB.ServiceCustomer client = new WcfCustomersVB.ServiceCustomer();

                dsCountry = client.GetCountries();
                ddCountry.DataSource = dsCountry;
                ddCountry.DataTextField = "CountryName";
                ddCountry.DataValueField = "CountryID";
                ddCountry.DataBind();
                ddCountry.SelectedValue = SelectCountryVal.ToString();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        protected void SetupAddressType(int SelectAddressTypeVal = 0)
        {
            System.Data.DataTable dtAddressTypes = new System.Data.DataTable();
            WcfCustomersVB.ServiceCustomer client = new WcfCustomersVB.ServiceCustomer();

            dtAddressTypes = client.GetAddressTypes();

            RadioButtonList rblAddressTypes = (RadioButtonList)dvAddress.FindControl(strCurrentMode + "AddressTypeRadio");

            rblAddressTypes.DataSource = dtAddressTypes;
            rblAddressTypes.DataTextField = "AddressTypeDesc";
            rblAddressTypes.DataValueField = "AddressTypeID";
            rblAddressTypes.DataBind();
            try
            {
                if (SelectAddressTypeVal==0)
                {
                    rblAddressTypes.SelectedIndex = 0;
                }
                else
                {
                    rblAddressTypes.SelectedValue = SelectAddressTypeVal.ToString();
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        protected void dvAddress_ModeChanging(object sender, DetailsViewModeEventArgs e)
        {
            if (e.NewMode != DetailsViewMode.Insert)
            {
                int CustID = Convert.ToInt32(dvAddress.DataKey["CustomerID"]);
                int AddressID = Convert.ToInt32(dvAddress.DataKey["AddressID"]);
                System.Data.DataTable dsCustomerAddress = new System.Data.DataTable();
                WcfCustomersVB.ServiceCustomer client = new WcfCustomersVB.ServiceCustomer();

                int CountryVal = 0;
                int ProvinceVal = 0;
                int CityVal = 0;
                int AddressTypeVal = 0;

                if (CustID != 0 && AddressID!=0)
                {
                    dsCustomerAddress = client.GetCustomerAddress(CustID,AddressID);
                    foreach (System.Data.DataRow row in dsCustomerAddress.Rows)
                    {
                        CountryVal = int.Parse(row["CountryID"].ToString());
                        ProvinceVal = int.Parse(row["ProvinceID"].ToString());
                        CityVal = int.Parse(row["CityID"].ToString());
                        AddressTypeVal = int.Parse(row["AddressTypeID"].ToString());
                    }

                }

                dvAddress.DataSource = dsCustomerAddress;
                dvAddress.DataBind();

                if (e.NewMode == DetailsViewMode.Edit)
                {
                    SetupCountryDD(CountryVal);
                    SetupProvinceDD(ProvinceVal, CountryVal);
                    SetupCityDD(CityVal, CountryVal, ProvinceVal);
                    SetupAddressType(AddressTypeVal);
                }
            }
            else
            {
                SetupAddressType(0);
            }
        }