so I have a sql table with columns such as driverid and drivername
The code below creates the order once the customer checks out.
string deliveryDate = DateTime.Now.AddDays(2).ToString("M/d/yyyy");
SqlConnection con = new SqlConnection(str);
if (Session["buyitems"] != null && Session["Orderid"] != null)
{
DataTable dt = (DataTable)Session["buyitems"];
for (int i = 0; i <= dt.Rows.Count - 1; i++)
{
string pId = dt.Rows[i]["pid"].ToString();
int pQuantity = Convert.ToInt16(dt.Rows[i]["pquantity"]);
SqlDataAdapter sda = new SqlDataAdapter("Select Pquantity from ProductShirt where ProductId ='" + pId + "' ", con);
DataTable dtbl = new DataTable();
sda.Fill(dtbl);
int quantity = Convert.ToInt32(dtbl.Rows[0][0]);
if (quantity > 0)
{
con.Open();
SqlCommand cmd = new SqlCommand("insert into OrderDetails(orderid,sno,productid,productname,price,quantity,orderdate,status,email,deliverydate,address, driverid) values('" + Session["Orderid"] + "',"
+ dt.Rows[i]["sno"] + "," + dt.Rows[i]["pid"] + ",'" + dt.Rows[i]["pname"] + "'," + (Convert.ToInt32(dt.Rows[i]["pprice"])) + "," + dt.Rows[i]["pquantity"] + ",'" + DateTime.Now.ToString("M/d/yyyy") + "','Pending', '" + Session["username"].ToString() + "', '" + deliveryDate + "', '" + TextBox1.Text + "', '" + driverid + '")", con);
cmd.ExecuteNonQuery();
con.Close();
}
}
decreaseQuantity();
clearCart();
Session["buyitems"] = null;
Session["deliverydate"] = deliveryDate;
Response.Redirect(url);
}
else
{
Response.Redirect("AddtoCart.aspx");
}
How would I go about assigning a different delivery driver to a new order, for example when the first order has been created, driver1 is assigned to it. When the third order has been created, driver3 is assigned to it but say if there's a fourth order, the list of drivers being assigned should start with driver 1 all over again.
