Vous êtes sur la page 1sur 8

INTERNET TECHONOLOGIES

ASSIGNMENT 3

SUBMITTED TO
Department of Computer Science & Engineering

by

SAMYAK GUPTA
140905260
7th Semester, CSE-D
E-mail: samyak.gupta@learner.manipal.edu
Mobile: 9663600683

Mr. Shyam Karanth

1
CODE:
deliverypersons.aspx
<%@ Page Language="C#" MasterPageFile="~/masterfile.master" AutoEventWireup="true"
CodeBehind="deliverypersons.aspx.cs" Inherits="IT_Project.deliverypersons" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<a href="FrontPage.aspx">Home</a>
<a href="#">See Deliveries</a>
<a href="#">Generate Bill</a>
<a href="FrontPage.aspx">Logout</a>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">


<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>

<asp:DropDownList ID="ddlEmployee" runat="server">


<asp:ListItem Text="Delivery Boy 1" Value="0"></asp:ListItem>
<asp:ListItem Text="Delivery Boy 2" Value="1"></asp:ListItem>
<asp:ListItem Text="Delivery Boy 3" Value="2"></asp:ListItem>
</asp:DropDownList>

<asp:Button OnClick="Button_Click" runat="server"/>

<asp:GridView ID="GridView1" runat="server"></asp:GridView>


</ContentTemplate>
</asp:UpdatePanel>

</form>
</asp:Content>

deliverypersons.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data;

namespace IT_Project
{
public partial class deliverypersons : System.Web.UI.Page
{
int deliveryperson_id=0;
int flag = 1;
protected void Page_Load(object sender, EventArgs e)
2
{
if (Session["deliveryboydata"] != null || flag==0)
deliveryperson_id = (int)Session["deliveryboydata"]-1;
flag = 1;
SqlConnection conn = new SqlConnection();
SqlConnection conn1 = new SqlConnection();

conn.ConnectionString= @"Data Source=(localDB)\MSSQLLocalDB;Initial


Catalog=NewspaperSystem;Integrated Security=True";
conn1.ConnectionString = @"Data Source=(localDB)\MSSQLLocalDB;Initial
Catalog=NewspaperSystem;Integrated Security=True";
SqlCommand command = new SqlCommand("Select count(*) from Delivery_Persons",
conn);
SqlCommand command1 = new SqlCommand("Select count(*) from Customer", conn);
SqlCommand command2 = new SqlCommand("Select * from Customer", conn);

SqlDataAdapter adapter;
SqlDataReader reader=null;
DataSet ds = new DataSet();

using (conn)
{
conn.Open();

adapter = new SqlDataAdapter(command);


adapter.Fill(ds, "NoOfDeliveryBoys");

adapter = new SqlDataAdapter(command1);


adapter.Fill(ds, "NoOfCustomers");

adapter = new SqlDataAdapter(command2);


adapter.Fill(ds, "CustomerDetails");
}

int noofcustomers = Convert.ToInt32(ds.Tables["NoOfCustomers"].Rows[0][0]);


int noofdeliveryboys =
Convert.ToInt32(ds.Tables["NoOfDeliveryBoys"].Rows[0][0]);
int noofdeliveries = noofcustomers / noofdeliveryboys;

int[] id = new int[ds.Tables["CustomerDetails"].Rows.Count];


int[] address = new int[ds.Tables["CustomerDetails"].Rows.Count];
int[] weights = new int[ds.Tables["CustomerDetails"].Rows.Count];
int i = 0, j=0, temp=0;

conn1.Open();

SqlCommand command6 = new SqlCommand("Select * from Address where a_id=@a_id",


conn1);
command6.Parameters.Add("@a_id", SqlDbType.Int);

for (i = 0; i < ds.Tables["CustomerDetails"].Rows.Count; i++)


{
id[i] = Convert.ToInt32(ds.Tables["CustomerDetails"].Rows[i][0]);
address[i] = Convert.ToInt32(ds.Tables["CustomerDetails"].Rows[i][2]);

command6.Parameters["@a_id"].Value = Convert.ToInt32(address[i]);
reader = command6.ExecuteReader();
if (reader.Read())
{
3
weights[i] = Convert.ToInt32(reader["weight"]);
}
reader.Close();
}

conn1.Close();

for (i = 0; i < ds.Tables["CustomerDetails"].Rows.Count-1; i++)


{
for (j = 0; j < ds.Tables["CustomerDetails"].Rows.Count -i-1; j++)
{
if(weights[j]>weights[j+1])
{
temp = address[j];
address[j] = address[j + 1];
address[j + 1] = temp;

temp = id[j];
id[j] = id[j + 1];
id[j + 1] = temp;

temp = weights[j];
weights[j] = weights[j + 1];
weights[j + 1] = temp;
}
}
}

SqlCommand command3 = new SqlCommand("Select name from Publications where p_id=@p_id",


conn1);
command3.Parameters.Add("@p_id", SqlDbType.Int);

SqlCommand command4 = new SqlCommand("Select * from Customer where c_id=@c_id", conn1);


command4.Parameters.Add("@c_id", SqlDbType.Int);

SqlCommand command5 = new SqlCommand("Select * from Address where a_id=@a_id", conn1);


command5.Parameters.Add("@a_id", SqlDbType.Int);

DataTable dt = new DataTable();


dt.Columns.AddRange(new DataColumn[5] { new DataColumn("Delivery Order",
typeof(int)),new DataColumn("Name", typeof(string)),new DataColumn("Address",
typeof(string)), new DataColumn("E-Mail", typeof(string)),new DataColumn("Publications
Recieved",typeof(string)) });

string customername = "";


string customeraddress = "";
string customeraddressid = "";
string customeremail = "";
string pub_names = "";
string[] pub_ids=null;

try
{
conn1.Open();
int k = 1;
for (i = deliveryperson_id*noofdeliveries+1, k=1 ; i <=
(deliveryperson_id+1) * noofdeliveries; i++,k++)
{
4
command4.Parameters["@c_id"].Value = Convert.ToInt32(id[i-1]);
reader = command4.ExecuteReader();

if(reader.Read())
{
customername = reader["name"].ToString();
customeraddressid = reader["address"].ToString();
customeremail = reader["email"].ToString();
pub_ids = reader["publication_ids"].ToString().Split(',');
}
reader.Close();

command5.Parameters["@a_id"].Value = Convert.ToInt32(customeraddressid);
reader = command5.ExecuteReader();

if (reader.Read())
{
customeraddress = reader["address"].ToString();
}
reader.Close();

pub_names = "";
for (j = 0; j < pub_ids.Length; j++)
{
command3.Parameters["@p_id"].Value = Convert.ToInt32(pub_ids[j]);
reader = command3.ExecuteReader();
if (reader.Read())
pub_names += reader["name"] + ", ";
reader.Close();
}
pub_names = pub_names.Substring(0, pub_names.Length - 2);
dt.Rows.Add(k, customername, customeraddress, customeremail, pub_names);
}

GridView1.DataSource = dt;
GridView1.DataBind();
}
catch (Exception excep)
{
string debug = excep.Message;
}
finally
{
conn.Close();
}
}

protected void Button_Click(object sender, EventArgs e)


{
deliveryperson_id = Convert.ToInt32(ddlEmployee.SelectedValue);
Page_Load(null, EventArgs.Empty);
flag = 0;
}
}
}

5
SCREENSHOTS:

By making use of AJAX we can view the delivery schedules of any Delivery Boy on
a single page without reloading the whole page again, which was earlier done by
using Sessions.

6
7
By logging into their the respective accounts, the Delivery Boys can see their own
schedule only. The login information is stored in the session variable and the next
page shows the schedule.

Using this method we can only see the schedule of the person who is logged in because
the information fetched from the database is only for that person and the information
to be fetched via the session variables which store the login information and maps the
delivery boy.

If we compare to this the method used with AJAX, we can set the particular delivery
boy from the dropdown list and the GridView is update accordingly without reloading
the whole page.

Vous aimerez peut-être aussi