コード例 #1
0
        protected void EditProfile()
        {
            //try
            //{
            var MobileString  = txtPhoneNo.Text.Trim();
            var mobileBuilder = new StringBuilder(MobileString);

            mobileBuilder.Remove(0, 1);      //Trim one character from position 1
            mobileBuilder.Insert(0, "+254"); // replace position 0 with +254
            MobileString = mobileBuilder.ToString();

            DateTime dTOfBth;
            var      gentype = 0;
            var      usname  = Session["username"].ToString();
            var      fname   = txtfNname.Text.Trim();
            var      mname   = txtMname.Text.Trim();
            var      lname   = txtLname.Text.Trim();
            var      idno    = txtIDNo.Text.Trim();
            var      resid   = txtResidence.Text.Trim();
            var      gender  = lstGender.SelectedItem.Text;

            var mycounty    = "";
            var mysubcounty = "";

            if (ddlSelCounty.SelectedIndex == 0)
            {
                ddlSelCounty.Focus();
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "thisBitchcode",
                                                        "alert('Please select your county!');", true);
                return;
            }
            else
            {
                mycounty = ddlSelCounty.SelectedItem.Text;
            }

            if (ddlConstituency.SelectedIndex == 0)
            {
                ddlConstituency.Focus();
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "thisBitchcode",
                                                        "alert('Please select your subcounty!');", true);
                return;
            }
            else
            {
                mysubcounty = ddlConstituency.SelectedItem.Text;
            }

            if (lstGender.SelectedIndex == 0)
            {
                KCDFAlert.ShowAlert("Please select a valid gender type!");
                return;
            }
            if (gender.Equals("Male"))
            {
                gentype = 0;
            }
            else
            {
                gentype = 1;
            }
            var dtofBirth = dateOFBirth.Value;

            if (string.IsNullOrWhiteSpace(dtofBirth))
            {
                dateOFBirth.Focus();
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "thisBitchcode",
                                                        "alert('Please select valid date');", true);
                return;
            }
            else
            {
                dTOfBth = DateTime.Parse(dtofBirth);
            }

            if (string.IsNullOrEmpty(idno))
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "thisBitchcode",
                                                        "alert('Fill in ID Number!');", true);
                txtIDNo.Focus();
                txtIDNo.BorderColor = Color.Red;
                return;
            }
            if (string.IsNullOrEmpty(MobileString))
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "thisBitchcode",
                                                        "alert('Fill in Mobile Number!');", true);
                txtPhoneNo.Focus();
                txtPhoneNo.BorderColor = Color.Red;
                return;
            }

            var credentials = new NetworkCredential(ConfigurationManager.AppSettings["W_USER"],
                                                    ConfigurationManager.AppSettings["W_PWD"], ConfigurationManager.AppSettings["DOMAIN"]);
            var sup = new Portals();

            sup.Credentials     = credentials;
            sup.PreAuthenticate = true;
            if (
                sup.FnRegisterStudent(fname, mname, lname, idno, resid, MobileString, usname, gentype, dTOfBth, mycounty,
                                      mysubcounty) == true)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "thisBitchcode",
                                                        "alert('Your account succcessfully Edited!');", true);
            }

            //}
            //catch (Exception ex)
            //{
            //    KCDFAlert.ShowAlert("Select Valid Date");
            // ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "thisBitchcode", "alert('Error!');", true);

            //}
        }