コード例 #1
0
    protected void Button3_Click(object sender, EventArgs e)
    {
        if (Session["id"] == null)
        {
            ScriptManager.RegisterStartupScript(Button3, Button3.GetType(), "alert", "alert('Sorry you stay too long!')", true);
            Response.Redirect("home.aspx");
        }
        else
        {
            string uid = Session["id"].ToString();

            string real_first_name        = real_first_name_TextBox.Text.Replace("\'", "").Replace("\"", "").Replace("`", "").Trim();
            string real_second_name       = real_second_name_TextBox.Text.Replace("\'", "").Replace("\"", "").Replace("`", "").Trim();
            string real_spell_first_name  = real_spell_first_name_TextBox.Text.Replace("\'", "").Replace("\"", "").Replace("`", "").Trim();
            string real_spell_second_name = real_spell_second_name_TextBox.Text.Replace("\'", "").Replace("\"", "").Replace("`", "").Trim();
            bool   check_Sex_radio        = false;
            string Sex = "";
            if (Sex_radio.SelectedIndex > -1)
            {
                check_Sex_radio = true;
                Sex             = Sex_radio.SelectedValue;
                sex_Label.Text  = "";
            }
            else
            {
                check_Sex_radio = false;
                Sex             = "";
                sex_Label.Text  = "性別を選択してください。";
            }
            string birth_year = ddlYear.SelectedValue;
            string birth_mon  = ddlMonth.SelectedValue;
            string birth_day  = ddlDay.SelectedValue;

            string work_state = work_DropDownList.SelectedValue;

            string postal_code        = postal_code_TextBox.Text.Replace("\'", "").Replace("\"", "").Replace("`", "").Trim();
            string country            = City_DropDownList.SelectedValue;
            string city               = add_TextBox.Text.Replace("\'", "").Replace("\"", "").Replace("`", "").Trim();
            string chome              = add_TextBox1.Text.Replace("\'", "").Replace("\"", "").Replace("`", "").Trim();
            string house_number       = apartment_TextBox.Text.Replace("\'", "").Replace("\"", "").Replace("`", "").Trim();
            string station_line       = train_line_TextBox.Text.Replace("\'", "").Replace("\"", "").Replace("`", "").Trim();
            string station_name       = train_station_TextBox.Text.Replace("\'", "").Replace("\"", "").Replace("`", "").Trim();
            string phone_number       = phone_TextBox.Text.Replace("\'", "").Replace("\"", "").Replace("`", "").Trim();
            string other_phone_number = other_phone_TextBox.Text.Replace("\'", "").Replace("\"", "").Replace("`", "").Trim();
            string relationship       = relationship_DropDownList.SelectedValue;

            bool check_real_first_name = false, check_real_second_name = false, check_real_spell_first_name = false
            , check_real_spell_second_name = false, check_postal_code = false
            , check_city = false, check_chome = false, check_phone_number = false;

            if (real_first_name != "")
            {
                check_real_first_name = true;
                rfname_Label.Text     = "";
            }
            else
            {
                check_real_first_name = false;
                rfname_Label.Text     = "姓を入力してください";
            }

            if (real_second_name != "")
            {
                check_real_second_name = true;
                rsname_Label.Text      = "";
            }
            else
            {
                check_real_second_name = false;
                rsname_Label.Text      = "名を入力してください。";
            }

            if (real_spell_first_name != "")
            {
                check_real_spell_first_name = true;
                rsfname_Label.Text          = "";
            }
            else
            {
                check_real_spell_first_name = false;
                rsfname_Label.Text          = "名を入力してください。";
            }

            if (real_spell_second_name != "")
            {
                check_real_spell_second_name = true;
                rssname_Label.Text           = "";
            }
            else
            {
                check_real_spell_second_name = false;
                rssname_Label.Text           = "名の読みをカタカナで入力してください。";
            }

            if (postal_code != "")
            {
                check_postal_code = true;
                poc_Label.Text    = "";
            }
            else
            {
                check_postal_code = false;
                poc_Label.Text    = "郵便番号をハイフンをつけて入力してください。";
            }
            if (city != "")
            {
                check_city      = true;
                city_Label.Text = "";
            }
            else
            {
                check_city      = false;
                city_Label.Text = "市区町村を入力してください";
            }
            if (chome != "")
            {
                check_chome      = true;
                chome_Label.Text = "";
            }
            else
            {
                check_chome      = false;
                chome_Label.Text = "番地を入力してください。";
            }
            if (phone_number != "")
            {
                check_phone_number = true;
                phone_Label.Text   = "";
            }
            else
            {
                check_phone_number = false;
                phone_Label.Text   = "電話番号を入力してください";
            }


            if (check_Sex_radio && check_real_first_name && check_real_second_name && check_real_spell_first_name &&
                check_real_spell_second_name && check_postal_code && check_city && check_chome && check_phone_number)
            {
                bool check_db = true;

                Query  = "select uid from user_information";
                Query += " where uid='" + uid + "';";
                DataView ict_f = gc.select_cmd(Query);
                if (ict_f.Count > 0)
                {
                    check_db = false;
                }

                if (check_db)
                {
                    Query  = "insert into user_information(uid,real_first_name,real_second_name,real_spell_first_name,real_spell_second_name";
                    Query += ",Sex,birthday_year,birthday_month,birthday_day,live_postal_code,country,city,Chome,phone_number,work_state,relationship";
                    if (house_number != "")
                    {
                        Query += ",house_number";
                    }
                    if (station_line != "")
                    {
                        Query += ",station_line";
                    }
                    if (station_name != "")
                    {
                        Query += ",station_name";
                    }
                    if (other_phone_number != "")
                    {
                        Query += ",other_phone_number";
                    }

                    Query += ") values('" + uid + "','" + real_first_name + "','" + real_second_name + "','" + real_spell_first_name + "'";
                    Query += ",'" + real_spell_second_name + "','" + Sex + "','" + birth_year + "','" + birth_mon + "'";
                    Query += ",'" + birth_day + "','" + postal_code + "','" + country + "','" + city + "'";
                    Query += ",'" + chome + "','" + phone_number + "','" + work_state + "','" + relationship + "'";
                    if (house_number != "")
                    {
                        Query += ",'" + house_number + "'";
                    }
                    if (station_line != "")
                    {
                        Query += ",'" + station_line + "'";
                    }
                    if (station_name != "")
                    {
                        Query += ",'" + station_name + "'";
                    }
                    if (other_phone_number != "")
                    {
                        Query += ",'" + other_phone_number + "'";
                    }
                    Query += ")";
                    resin  = gc.insert_cmd(Query);

                    Session["id"] = uid;


                    real_first_name_TextBox.Text        = "";
                    real_second_name_TextBox.Text       = "";
                    real_spell_first_name_TextBox.Text  = "";
                    real_spell_second_name_TextBox.Text = "";

                    Sex_radio.SelectedIndex = -1;
                    this.PopulateYear();
                    this.PopulateMonth();
                    this.PopulateDay();

                    work_DropDownList.SelectedIndex = 0;
                    postal_code_TextBox.Text        = "";
                    City_DropDownList.Items.FindByValue("神奈川県").Selected = true;
                    City_DropDownList.Items.FindByText("神奈川県").Selected  = true;
                    add_TextBox.Text           = "";
                    add_TextBox1.Text          = "";
                    apartment_TextBox.Text     = "";
                    train_line_TextBox.Text    = "";
                    train_station_TextBox.Text = "";
                    phone_TextBox.Text         = "";
                    other_phone_TextBox.Text   = "";
                    relationship_DropDownList.SelectedIndex = 0;


                    result_Label.Text = "Success registered.";
                    Response.Redirect("registered_2.aspx");
                }
                else
                {
                    result_Label.Text = "登録に失敗しました。";
                }
            }
            else
            {
                result_Label.Text = "登録に失敗しました。";
            }


            //Response.Redirect("registered_2.aspx");
        }
    }