Exemplo n.º 1
0
        protected void add_Click(object sender, EventArgs e)
        {
            carrentalEntities db      = new carrentalEntities();
            string            role    = DropDownList1.SelectedItem.Text;
            customer          c       = new customer();
            string            fname   = firstname.Text;
            string            lname   = lastname.Text;
            string            mno     = (mobileno.Text);
            string            mail    = email.Text;
            string            license = licenceno.Text;
            string            add     = address.Text;

            if (DropDownList1.SelectedItem.Text == "Customer")
            {
                //Login l = new Login();
                var already = from x in db.Logins
                              where x.LoginId == email.Text && x.Role == role
                              select x;
                int count = 0;
                foreach (var a in already)
                {
                    count++;
                }


                if (count > 0)
                {
                    msg.Text      = "You Have Already Registered, Please Login!!";
                    msg.ForeColor = System.Drawing.Color.Red;
                    return;
                }
                else
                {
                    Login l = new Login();
                    l.Role      = DropDownList1.SelectedItem.Text.ToString();
                    l.LoginId   = email.Text.ToString();
                    l.Password  = pwd.Text;
                    c.email     = email.Text;
                    c.firstname = fname;
                    c.lastname  = lname;
                    c.licenceno = license;
                    c.address   = add;
                    c.mobileno  = mno;
                    db.customers.Add(c);
                    db.Logins.Add(l);
                    try
                    {
                        int n = db.SaveChanges();
                        sendmail("Successfully registered");
                        msg.Text      = "Successfully registered";
                        msg.ForeColor = System.Drawing.Color.Green;
                    }
                    catch (Exception err)
                    {
                        msg.Text      = "Some Error Occured";
                        msg.ForeColor = System.Drawing.Color.Red;
                    }
                }
            }
            else if (DropDownList1.SelectedItem.Text == "Owner")
            {
                var already = from x in db.Logins
                              where x.LoginId == email.Text && x.Role == role
                              select x;
                int count = 0;
                foreach (var a in already)
                {
                    count++;
                }


                if (count > 0)
                {
                    msg.Text      = "You Have Already Registered, Please Login!!";
                    msg.ForeColor = System.Drawing.Color.Red;
                }
                else
                {
                    Login p = new Login();
                    owner o = new owner();
                    p.Role      = DropDownList1.SelectedItem.Text.ToString();
                    p.LoginId   = email.Text.ToString();
                    p.Password  = pwd.Text;
                    o.email     = email.Text;
                    o.firstname = fname;
                    o.lastname  = lname;
                    o.address   = add;
                    o.phone     = mno;
                    db.owners.Add(o);
                    db.Logins.Add(p);
                }
                try
                {
                    int k = db.SaveChanges();
                    sendmail("Successfully registered");
                    msg.Text      = "Successfully registered";
                    msg.ForeColor = System.Drawing.Color.Green;
                }
                catch (Exception err)
                {
                    msg.Text      = "Some Error Occured";
                    msg.ForeColor = System.Drawing.Color.Red;
                }
            }
        }
Exemplo n.º 2
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            Label2.Visible  = true;
            Label3.Visible  = true;
            Label4.Visible  = true;
            Label5.Visible  = true;
            Label6.Visible  = true;
            Label7.Visible  = true;
            Label8.Visible  = true;
            Label9.Visible  = true;
            Label10.Visible = false;
            string            s  = Session["loginid"].ToString();
            carrentalEntities db = new carrentalEntities();
            customer          cc = db.customers.Where(x => x.email == s).FirstOrDefault <customer>();
            int ci = cc.cid;
            int cid1 = 0, cid2 = 1;
            int bi = Int32.Parse(bid.Text.ToString());
            //  var q = from x in db.bookings where x.cid == ci select x;
            var p = from n in db.bookings where n.bookingid == bi select n;

            /*  if(q.Any())
             * {
             *    foreach(var y in q)
             *    {
             *        cid1 = y.cid;
             *    }
             * }*/
            if (p.Any())
            {
                foreach (var z in p)
                {
                    cid2 = z.cid;
                }
            }
            if (ci == cid2)
            {
                if (p.Any())
                {
                    foreach (var y in p)
                    {
                        Label6.Text = y.carno.ToString();
                        Label7.Text = y.startdate.ToString();
                        Label8.Text = y.enddate.ToString();
                        Label9.Text = y.rentalamount.ToString();
                    }
                }
            }
            else
            {
                Label2.Visible = false;
                Label3.Visible = false;
                Label4.Visible = false;
                Label5.Visible = false;
                Label6.Visible = false;
                Label7.Visible = false;
                Label8.Visible = false;
                Label9.Visible = false;

                Label10.Visible = true;
                Label10.Text    = "Invalid booking id";
            }
        }