コード例 #1
0
ファイル: AddSighting.aspx.cs プロジェクト: rNdm74/Web3
    protected void Button2_Click(object sender, EventArgs e)
    {
        DatabaseManager dbManager = new DatabaseManager();

        // Strips strings from textboxes
        String englishName = Regex.Replace(tbEnglishName.Text, "<.*?>", string.Empty);
        String maoriName = Regex.Replace(tbMaoriName.Text, "<.*?>", string.Empty);
        String scientificName = Regex.Replace(tbScientificName.Text, "<.*?>", string.Empty);

        // Insert if there is data
        if (englishName != "" && maoriName != "" && scientificName != "")
        {
            // Add the record
            dbManager.InsertBirdRecord(englishName, maoriName, scientificName);

            // User feedback
            lbResult.ForeColor = Color.FromArgb(204, 102, 0);
            lbResult.Text = "Bird added to database";

            // Hides the div from the user
            bird.Visible = false;

            // Refreshes the dropdown
            ddlBird.Items.Clear();
            initBird();

            // Clears the textboxes
            tbEnglishName.Text = "";
            tbMaoriName.Text = "";
            tbScientificName.Text = "";
        }
        else
        {
            // User feedback if incorrect information entered
            lbResult.Text = "Please enter all bird fields to add a bird to the database";
            lbResult.ForeColor = Color.Red;
            tbEnglishName.Focus();
        }
    }