예제 #1
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            int UserId;

            if ((Session["LoggedInUserName"] != null))
            {
                Food aFood = new Food();
                UserId = aFood.getUserId(Session["loggedInUserName"].ToString());
                string RestId = Request.QueryString["RestaurantId"];

                try
                {
                    resConn.SqlConnectionObj.Open();
                    string query = String.Format("INSERT INTO Review_tbl(Review,ReviewDate,UserId,RestaurantId) VALUES('{0}',GetDate(),'{1}',{2})", TextBox1.Text, UserId, RestId);
                    resConn.SqlCommandObj.CommandText = query;
                    resConn.SqlCommandObj.ExecuteNonQuery();
                    resConn.SqlConnectionObj.Close();

                    msgLabel.Text = "Your post was successfully added";
                    TextBox1.Text = "";
                }

                catch (Exception ex)
                {
                    throw new Exception("Error occurred during user save operation. Try again", ex);
                }


                GetReviews();
            }
            else
            {
                string RestId = Request.QueryString["RestaurantId"];
                var    url    = String.Format("~/Login_Page.aspx?RestaurantId={0}&from=review", RestId);
                Response.Redirect(url);
            }
        }
예제 #2
0
        //int total = 0;


        //protected void Button1_Click(object sender, EventArgs e)
        //{

        //    int N = Convert.ToInt32(NoOfItem.Text);
        //    int total = 0;
        //    for (int i = 1; i <= N; i++)
        //    {
        //        if (i == 1)
        //        {
        //            total = (Convert.ToInt32(item1DropdownList.SelectedIndex) + 1) * Convert.ToInt32(P1.Text);
        //        }
        //        else if (i == 2)
        //        {
        //            total = total + (Convert.ToInt32(item2DropdownList.SelectedIndex) + 1) * Convert.ToInt32(P2.Text);
        //        }
        //        else if (i == 3)
        //        {
        //            total = total + (Convert.ToInt32(item3DropdownList.SelectedIndex) + 1) * Convert.ToInt32(P3.Text);
        //        }
        //        else if (i == 4)
        //        {
        //            total = total + (Convert.ToInt32(item4DropdownList.SelectedIndex) + 1) * Convert.ToInt32(P4.Text);
        //        }
        //        else if (i == 5)
        //        {
        //            total = total + (Convert.ToInt32(item5DropdownList.SelectedIndex) + 1) * Convert.ToInt32(P5.Text);
        //        }
        //    }
        //    Total.Text = total + "";
        //    //Label3.Text = item1DropdownList.SelectedValue.ToString();
        //}



        protected void GetFoodButton_Click(object sender, EventArgs e)
        {
            string FoodName = "";
            int    Id;
            int    quantity;
            int    UserId;
            string BkAccNo = "";
            string BkTrxId = "";



            if (RadioButtonList1.SelectedValue == "Cash on Delivery")
            {
                bkAccNoTextBox.Text = "";
                BkTrxTextBox.Text   = "";
            }
            else if (RadioButtonList1.SelectedValue == "Pay by BKash")
            {
                BkAccNo = bkAccNoTextBox.Text;
                BkTrxId = BkTrxTextBox.Text;
            }



            if (Convert.ToInt32(Total.Text) == 0)
            {
                //Response.Redirect("~/Login_page.aspx");
                Alert.Text = "No food added to cart!!!";
            }
            else if (Convert.ToInt32(Total.Text) < Convert.ToInt32(Label12.Text))
            {
                Alert.Text = "You have add more to cart!!!";
            }
            else
            {
                string DeliveryAddress;
                double TotalAmount = Convert.ToDouble(Total.Text);
                Order  anOrder     = new Order();
                Food   aFood       = new Food();
                UserId          = aFood.getUserId(Session["loggedInUserName"].ToString());
                DeliveryAddress = aFood.getDeliveryAddress(Session["loggedInUserName"].ToString());

                try
                {
                    resConn.SqlConnectionObj.Open();
                    string query = String.Format("INSERT INTO Order_tbl(UserId,TotalAmount,DeliveryAddress,OrderDate,BKashNum,BKashTrxId) VALUES('{0}','{1}','{2}',GetDate(),'{3}','{4}')", UserId, TotalAmount, DeliveryAddress, BkAccNo, BkTrxId);
                    resConn.SqlCommandObj.CommandText = query;
                    resConn.SqlCommandObj.ExecuteNonQuery();

                    Label2.Text = "Successfully Done!!!!";



                    resConn.SqlConnectionObj.Close();
                }

                catch (Exception Ex)
                {
                }

                int OrderId = 0;
                try
                {
                    resConn.SqlConnectionObj.Open();
                    string query2 = String.Format("Select Max(OrderId) from Order_tbl");
                    resConn.SqlCommandObj.CommandText = query2;
                    SqlDataReader reader = resConn.SqlCommandObj.ExecuteReader();
                    while (reader.Read())
                    {
                        OrderId = reader.GetInt32(0);
                    }
                    resConn.SqlConnectionObj.Close();
                }
                catch (Exception Ex)
                {
                }


                //resConn.SqlConnectionObj.Open();
                for (int i = 0; i < Convert.ToInt32(NoOfItem.Text); i++)
                {
                    if (i == 0)
                    {
                        resConn.SqlConnectionObj.Open();
                        FoodName = I1.Text;
                        Id       = aFood.getId(FoodName);
                        quantity = Convert.ToInt32(item1DropdownList.SelectedIndex) + 1;
                        //quantity = Convert.ToInt32(n1.Text);
                        string query = String.Format("INSERT INTO Sold_tbl(OrderId,FoodId,UserId,Quantity) VALUES('{0}','{1}','{2}','{3}')", OrderId, Id, UserId, quantity);
                        resConn.SqlCommandObj.CommandText = query;
                        resConn.SqlCommandObj.ExecuteNonQuery();
                        resConn.SqlConnectionObj.Close();

                        /* to update food table for top items*/
                        resConn.SqlConnectionObj.Open();

                        int    a      = 0;
                        string query2 = String.Format("Select FoodSaleTotal from Food_tbl where FoodId='{0}'", Id);
                        resConn.SqlCommandObj.CommandText = query2;
                        SqlDataReader reader1 = resConn.SqlCommandObj.ExecuteReader();
                        while (reader1.Read())
                        {
                            //if (reader1.GetString(0) == "{}")
                            //    a = 0;
                            //else
                            a = Convert.ToInt32(reader1.GetString(0));
                        }


                        a = a + quantity;

                        resConn.SqlConnectionObj.Close();
                        resConn.SqlConnectionObj.Open();


                        string query3 = String.Format("Update Food_tbl Set FoodSaleTotal='{0}' where FoodId='{1}'", a, Id);
                        resConn.SqlCommandObj.CommandText = query3;
                        resConn.SqlCommandObj.ExecuteNonQuery();
                        resConn.SqlConnectionObj.Close();
                    }
                    else if (i == 1)
                    {
                        resConn.SqlConnectionObj.Open();
                        FoodName = I2.Text;
                        Id       = aFood.getId(FoodName);
                        //quantity = Convert.ToInt32(n2.Text);
                        quantity = Convert.ToInt32(item2DropdownList.SelectedIndex) + 1;
                        string query = String.Format("INSERT INTO Sold_tbl(OrderId,FoodId,UserId,Quantity) VALUES('{0}','{1}','{2}','{3}')", OrderId, Id, UserId, quantity);
                        resConn.SqlCommandObj.CommandText = query;
                        resConn.SqlCommandObj.ExecuteNonQuery();
                        resConn.SqlConnectionObj.Close();

                        /* to update food table for top items*/
                        resConn.SqlConnectionObj.Open();
                        int    a      = 0;
                        string query2 = String.Format("Select FoodSaleTotal from Food_tbl where FoodId='{0}'", Id);
                        resConn.SqlCommandObj.CommandText = query2;
                        SqlDataReader reader1 = resConn.SqlCommandObj.ExecuteReader();
                        while (reader1.Read())
                        {
                            //if (reader1.GetString(0) == "NULL")
                            //    a = 0;
                            //else
                            a = Convert.ToInt32(reader1.GetString(0));
                        }

                        a = a + quantity;

                        resConn.SqlConnectionObj.Close();
                        resConn.SqlConnectionObj.Open();

                        string query3 = String.Format("Update Food_tbl Set FoodSaleTotal='{0}' where FoodId='{1}'", a, Id);
                        resConn.SqlCommandObj.CommandText = query3;
                        resConn.SqlCommandObj.ExecuteNonQuery();
                        resConn.SqlConnectionObj.Close();
                    }
                    else if (i == 2)
                    {
                        resConn.SqlConnectionObj.Open();
                        FoodName = I3.Text;
                        Id       = aFood.getId(FoodName);
                        quantity = Convert.ToInt32(item3DropdownList.SelectedIndex) + 1;
                        //quantity = Convert.ToInt32(n3.Text);
                        string query = String.Format("INSERT INTO Sold_tbl(OrderId,FoodId,UserId,Quantity) VALUES('{0}','{1}','{2}','{3}')", OrderId, Id, UserId, quantity);
                        resConn.SqlCommandObj.CommandText = query;
                        resConn.SqlCommandObj.ExecuteNonQuery();
                        resConn.SqlConnectionObj.Close();


                        /* to update food table for top items*/
                        resConn.SqlConnectionObj.Open();
                        int    a      = 0;
                        string query2 = String.Format("Select FoodSaleTotal from Food_tbl where FoodId='{0}'", Id);
                        resConn.SqlCommandObj.CommandText = query2;
                        SqlDataReader reader1 = resConn.SqlCommandObj.ExecuteReader();
                        while (reader1.Read())
                        {
                            //if (reader1.GetString(0) == "NULL")
                            //    a = 0;
                            //else
                            a = Convert.ToInt32(reader1.GetString(0));
                        }

                        resConn.SqlConnectionObj.Close();
                        resConn.SqlConnectionObj.Open();
                        a = a + quantity;

                        string query3 = String.Format("Update Food_tbl Set FoodSaleTotal='{0}' where FoodId='{1}'", a, Id);
                        resConn.SqlCommandObj.CommandText = query3;
                        resConn.SqlCommandObj.ExecuteNonQuery();
                        resConn.SqlConnectionObj.Close();
                    }
                    else if (i == 3)
                    {
                        resConn.SqlConnectionObj.Open();
                        FoodName = I4.Text;
                        Id       = aFood.getId(FoodName);
                        quantity = Convert.ToInt32(item4DropdownList.SelectedIndex) + 1;
                        //quantity = Convert.ToInt32(n4.Text);
                        string query = String.Format("INSERT INTO Sold_tbl(OrderId,FoodId,UserId,Quantity) VALUES('{0}','{1}','{2}','{3}')", OrderId, Id, UserId, quantity);
                        resConn.SqlCommandObj.CommandText = query;
                        resConn.SqlCommandObj.ExecuteNonQuery();
                        resConn.SqlConnectionObj.Close();


                        /* to update food table for top items*/
                        resConn.SqlConnectionObj.Open();
                        int    a      = 0;
                        string query2 = String.Format("Select FoodSaleTotal from Food_tbl where FoodId='{0}'", Id);
                        resConn.SqlCommandObj.CommandText = query2;
                        SqlDataReader reader1 = resConn.SqlCommandObj.ExecuteReader();
                        while (reader1.Read())
                        {
                            //if (reader1.GetString(0) == "NULL")
                            //    a = 0;
                            //else
                            a = Convert.ToInt32(reader1.GetString(0));
                        }
                        resConn.SqlConnectionObj.Close();
                        a = a + quantity;
                        resConn.SqlConnectionObj.Open();
                        string query3 = String.Format("Update Food_tbl Set FoodSaleTotal='{0}' where FoodId='{1}'", a, Id);
                        resConn.SqlCommandObj.CommandText = query3;
                        resConn.SqlCommandObj.ExecuteNonQuery();
                        resConn.SqlConnectionObj.Close();
                    }
                    else if (i == 4)
                    {
                        resConn.SqlConnectionObj.Open();
                        FoodName = I5.Text;
                        Id       = aFood.getId(FoodName);
                        quantity = Convert.ToInt32(item5DropdownList.SelectedIndex) + 1;
                        //quantity = Convert.ToInt32(n5.Text);
                        string query = String.Format("INSERT INTO Sold_tbl(OrderId,FoodId,UserId,Quantity) VALUES('{0}','{1}','{2}','{3}')", OrderId, Id, UserId, quantity);
                        resConn.SqlCommandObj.CommandText = query;
                        resConn.SqlCommandObj.ExecuteNonQuery();
                        resConn.SqlConnectionObj.Close();


                        /* to update food table for top items*/
                        resConn.SqlConnectionObj.Open();
                        int    a      = 0;
                        string query2 = String.Format("Select FoodSaleTotal from Food_tbl where FoodId='{0}'", Id);
                        resConn.SqlCommandObj.CommandText = query2;
                        SqlDataReader reader1 = resConn.SqlCommandObj.ExecuteReader();
                        while (reader1.Read())
                        {
                            //if (reader1.GetString(0) == "NULL")
                            //    a = 0;
                            //else
                            a = Convert.ToInt32(reader1.GetString(0));
                        }
                        resConn.SqlConnectionObj.Close();
                        a = a + quantity;
                        resConn.SqlConnectionObj.Open();
                        string query3 = String.Format("Update Food_tbl Set FoodSaleTotal='{0}' where FoodId='{1}'", a, Id);
                        resConn.SqlCommandObj.CommandText = query3;
                        resConn.SqlCommandObj.ExecuteNonQuery();
                        resConn.SqlConnectionObj.Close();
                    }
                }
                //resConn.SqlConnectionObj.Close();

                string RestId = Request.QueryString["RestaurantId"];
                var    url    = String.Format("~/MyOrders.aspx?userId={0}&orderId={1}&RestId={2}&tAmt={3}", UserId, OrderId, RestId, Total.Text);
                Response.Redirect(url);
            }
        }