The error I get is
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
This points to
This is the last error i need to solve to get my complete application to work again but it all points to 1 webpage and i get different errors if i try different things so i dont now anymore what the best way is
please someone help me i only need to solve this page error so my complete application works.
i tried to put in different values but it shows the same error.
You can see the whole program in the attachment.
Could someone help me with this error I will be really thankful to you.please write the changed code.
I get the errors in line 8,37,67.
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
This points to
Code:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class ResHomePage : System.Web.UI.Page
{
SqlConnection cn;
SqlCommand cmd, cmd2;
SqlDataReader dr;
string d, sd;
Rest_RegisterClass ss;
int a, b, m, sum, f;
DataView dv = new DataView();
DataRow rec;
DataTable dt = new DataTable();
DataColumn col;
CheckBox c;
protected void Page_Load(object sender, EventArgs e)
{
NewConnection();
sd = Session["resname"].ToString();
Label2.Text = sd;
d = Request["a"];
Label4.Text = DateTime.Now.ToLongTimeString();
Label24.Text ="," + DateTime.Now.ToLongDateString();
//Label4.Text = Format(Now, "dddd, dd-MMM-yyyy<br>hh:mmtt");
//Label24.Text = Format(Now, "dddd");
ss = new Rest_RegisterClass();
ss.RestId = d;
lad.Text = ss.RAddress1 + ", " + ss.RAddress2 ;
lc.Text = ss.RCity;
ls.Text = ss.RState;
lz.Text = ss.RZipCode;
lph.Text = ss.RPhone;
Lot.Text = ss.ROTime;
lct.Text = ss.RCTime;
MenuClass obj = new MenuClass();
obj.RestId = d;
obj.Retrivedealb();
obj.retrivedeall();
obj.retrivedeald();
Label24.Text = obj.DayOfW;
Label27.Text = obj.StartTimeB;
Label28.Text = obj.EndTimeB;
Label29.Text = obj.StartTimeL;
Label30.Text = obj.EndTimeL;
Label31.Text = obj.StartTimeD;
Label32.Text = obj.EndTimeD;
cmd = new SqlCommand("select * from restaurant where restaurantid='" + d + "'", cn);
dr = cmd.ExecuteReader();
dr.Read();
img2.ImageUrl = dr["headerimage"].ToString();
img1.ImageUrl = dr["logo"].ToString();
dr.Close();
if (IsPostBack)
{
col = new DataColumn("itemno");
dt.Columns.Add(col);
col = new DataColumn("itemname");
dt.Columns.Add(col);
col = new DataColumn("qty");
dt.Columns.Add(col);
col = new DataColumn("itemprice");
dt.Columns.Add(col);
Cache["Tapas"] = dt;
}
Session["total"] = Label19.Text;
}
public void NewConnection()
{
cn = new SqlConnection(clsConnectionString.StrCon);
cn.Open();
}
protected void LinkButton8_Click(object sender, EventArgs e)
{
Panel1.Visible = true;
}
protected void LinkButton9_Click(object sender, EventArgs e)
{
Response.Redirect("SpMenu.aspx?a=" + Session["id11"]);
}
protected void mil1_Click(object sender, EventArgs e)
{
f = 0;
Label16.Visible = false;
Label17.Visible = false;
listb();
}
private ArrayList Timings(string mid)
{
NewConnection();
string s = "select StartTime,EndTime from menuavailability where description='" + mid + "' and DayofWeek='" + DateTime.Today.DayOfWeek.ToString() + "'";
cmd = new SqlCommand(s, cn);
dr = cmd.ExecuteReader();
ArrayList a = new ArrayList();
while (dr.Read())
{
a.Add(dr[0]);
a.Add(dr[1]);
}
dr.Close();
return a;
}
Code:
private void listb()
{
Label36.Visible = true;
string str = "breakfast";
ArrayList ar = Timings(str);
DateTime t, t1, t2;
t = DateTime.Now;
t1 = (DateTime)(ar[0])/I get a error here saying that the ArgumentOUtofRange exception unhandled by the usercode
[/B][/I]
t2 = (DateTime)(ar[1]);
double d = (t.Hour * 60) + t.Minute;
double stime = (t1.Hour * 60) + t1.Minute;
double etime = (t2.Hour * 60) + t2.Minute;
if (d < etime)
{
Label36.Text = "";
Label14.Visible = true;
MIB.Visible = true;
databreak();
}
else
{
Label36.Text = "Breakfast time over so not available";
MIB.Visible = false;
Label14.Visible = false;
}
}
private void listl()
{
Label36.Visible = true;
string str = "lunch";
ArrayList ar = Timings(str);
DateTime t, t1, t2;
t = DateTime.Now;
t1 = (DateTime)(ar[0]);[I][B]//I get a error here saying that the ArgumentOUtofRange exception unhandled by the usercode
[/B][/I]
t2 = (DateTime)(ar[1]);
double d = (t.Hour * 60) + t.Minute;
double stime = (t1.Hour * 60) + t1.Minute;
double etime = (t2.Hour * 60) + t2.Minute;
if (d < etime)
{
Label36.Text = "";
MIB.Visible = true;
Label6.Visible = true;
datalunch();
}
else
{
Label36.Text = "Lunch time over so not available";
MIB.Visible = false;
Label6.Visible = false;
}
}
private void listd()
{
Label36.Visible = true;
string str = "dinner";
ArrayList ar = Timings(str);
DateTime t, t1, t2;
t = DateTime.Now;
t1 = (DateTime)(ar[0]);//I get a error here saying that the ArgumentOUtofRange exception unhandled by the usercode
[/B][/I] t2 = (DateTime)(ar[1]);
double d = (t.Hour * 60) + t.Minute;
double stime = (t1.Hour * 60) + t1.Minute;
double etime = (t2.Hour * 60) + t2.Minute;
if (d < etime)
{
MIB.Visible = true;
Label36.Text = "";
Label7.Visible = true;
datadinner();
}
else
{
Label36.Text = "Dinner not available";
MIB.Visible = false;
Label7.Visible = false;
}
}
private void fun1()
{
dt =(DataTable)(Cache["Tapas"]);
string item1,item2;
int flag= 0;
foreach(DataGridItem i in MIB.Items)
{
c =(CheckBox )(i.FindControl("chk"));
if (c.Checked == true)
{
if(dt.Rows.Count == 0)
{
rec = dt.NewRow();
rec[0] = i.Cells[1].Text;
rec[1] = i.Cells[2].Text;
a = (int.Parse)(((TextBox)(i.Cells[5].Controls[1])).Text);
rec[2] = a ;//qty
b = (int.Parse)(i.Cells[4].Text); //Item price
dt.Rows.Add(rec);
if (a >= 1)
{
rec[3] = b * a; //Total price
m = a * b;
}
else
{
rec[3] = b * 1;
m = 1 * b;
}
}
else
{
foreach(DataRow drw in dt.Rows)
{
item1 = drw["itemno"].ToString();
item2 = i.Cells[1].Text;
if(item1 == item2)
{
drw["qty"] = ((int.Parse)(drw["qty"].ToString()))+ ((int.Parse)(((TextBox)(i.Cells[5].Controls[1] )).Text));
b =((int.Parse) (i.Cells[4].Text)); //item price
a = ((int.Parse)(((TextBox)(i.Cells[5].Controls[1])).Text));
drw["itemprice"] = ((int.Parse)(drw["itemprice"].ToString())) + (b * a);
flag = 1;
}
}
if (flag == 0)
{
rec = dt.NewRow();
rec[0] = i.Cells[1].Text; //item no
rec[1] = i.Cells[2].Text; //item name
b =((int.Parse)( i.Cells[4].Text)); //item price
a = ((int.Parse)(((TextBox)(i.Cells[5].Controls[1])).Text));
rec[2] = a;
//b=qty
rec[3] = a * b;
m = a * b;
dt.Rows.Add(rec);
}
}
}
}
foreach(DataRow drw in dt.Rows)
{
sum = sum + ((int.Parse)(drw["itemprice"].ToString()));
Label19.Text = sum.ToString();
}
Label7.Text = "";
DataGrid1.Visible = true;
DataGrid1.DataSource = dt;
Cache["Tapas"] = dt;
DataGrid1.DataBind();
Cache["ItemAdded"] = dt;
}
please someone help me i only need to solve this page error so my complete application works.
i tried to put in different values but it shows the same error.
You can see the whole program in the attachment.
Could someone help me with this error I will be really thankful to you.please write the changed code.
I get the errors in line 8,37,67.
Comment