Monday, December 7, 2015

Web page for Donors

the SQL for the DonorLogin

use Master;
Create Login DonorLogin with password='pass';
Use communityAssist;
Create user DonorLogin for login DonorLogin;
Create Role DonorRole;
Grant select, insert on Person to DonorRole;
Grant select, insert on PersonAddress to DonorRole;
Grant select, insert on PersonContact to DonorRole;
Grant select, insert on Donation to DonorRole;

exec sp_AddRoleMember 'DonorRole', 'DonorLogin'

Here is the asp.net code for the web page

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Donor Registration</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <h1>Donor Registration</h1>
        <table>
            <tr>
                <td>Enter First Name</td>
                <td>
                    <asp:TextBox ID="FirstNameTextBox" runat="server">
                    </asp:TextBox>

                </td>
                </tr>
            <tr>
                <td>Enter Last Name</td>
                <td>
                    <asp:TextBox ID="LastNameTextBox" runat="server">
                    </asp:TextBox>

                </td>
                </tr>
            <tr>
                <td>Enter Street Address</td>
                <td>
                    <asp:TextBox ID="StreetTextBox" runat="server">
                    </asp:TextBox>

                </td>
                </tr>
            <tr>
                <td>Enter Email</td>
                <td>
                    <asp:TextBox ID="EmailTextBox" runat="server">
                    </asp:TextBox>

                </td>
                </tr>
            <tr>
                <td>Enter password</td>
                <td>
                    <asp:TextBox ID="PasswordTextBox" runat="server" TextMode="Password">
                    </asp:TextBox>

                </td>
                </tr>
            <tr>
                <td>
                    <asp:Button ID="SaveDonor" runat="server" Text="Button" OnClick="SaveDonor_Click" /></td>
                <td>
                    <asp:Label ID="ErrorLabel" runat="server" Text="Label"></asp:Label>

                </td>
            </tr>

        </table>
    </div>
    </form>
</body>
</html>

Here is the C# code with the caveat that we never got to run it, and you would need to add all the parameters to make it work.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(Session["loggedInUser"] == null)
        {
            Response.Redirect("Login.aspx");
        }
    }

    protected void SaveDonor_Click(object sender, EventArgs e)
    {
        SqlConnection connect =
            new SqlConnection(ConfigurationManager.
            ConnectionStrings["CommunityAssistConnection"].ToString());
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = connect;
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "usp_NewDonorLogin";
        cmd.Parameters.AddWithValue("@lastName", LastNameTextBox.Text);
        cmd.Parameters.AddWithValue("@FirstName", FirstNameTextBox.Text);

        connect.Open();
        cmd.ExecuteNonQuery();
        connect.Close();

    }
}

And here is the web config file with the connections string

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
<connectionStrings>
  <add connectionString="Data source=.\sqlexpress; initial catalog=communityAssist; user=DonorLogin; password=pass"
       name="communityAssistConnection"/>
</connectionStrings>
    <system.web>
      <compilation debug="true" targetFramework="4.5.2" />
      <httpRuntime targetFramework="4.5.2" />
    </system.web>

</configuration>

No comments:

Post a Comment