Calculation in code behind

前端 未结 5 1185
悲哀的现实
悲哀的现实 2021-01-28 04:50

Chauffeur service cost $30. It is an option to user whether they want the service or not. When they already select car, and day of rental, I store it in session.



        
相关标签:
5条回答
  • 2021-01-28 05:01

    Store the dropdown value into another session variable say IsChaffeurUsed. Make it a boolean.

    bool IsChauffeurUsed= dropDown.SelectedValue=="Yes" ? true :false;
    Session["IsChauffeurUsed"]= IsChauffeurUsed;
    
    
    //Your logic to compute total
    
    int totalValue = 0;
    totalValue = int.Parse(Session["price"].ToString()) *
                 int.Parse(Session["day"].ToString());
    
    //check if chaffeur service is used
    
    bool isChaffeurUsed = (bool) Session["IsChaffeurUsed"]; 
    
        if(isChaffeurUsed)
            {
            total += 30;
            }
    Label8.Text = (totalValue).ToString();
    
    0 讨论(0)
  • 2021-01-28 05:08

    totalValue = int.Parse(Session["price"].ToString()) * int.Parse(Session["day"].ToString()) + ShowFerInUse ? 30 : 0;

    This way you can use iif equivalent in c# and do ShowFerInUse at same time.

    0 讨论(0)
  • 2021-01-28 05:18

    Why don't you create a custom class, add the properties like Car, Price, Day, ChaffterUsed etc. Create the object of the class, fill the properties and store the object into session. On next page, load the object from session and use it.

    0 讨论(0)
  • 2021-01-28 05:19

    I suggest use Server.Transfer() instead of Response.Redirect() and use PreviousPage to fetch your required values.

    This will save you from using Session as Session should not be used in this scenario.

    To know how to use PreviousPage see below link.

    http://msdn.microsoft.com/en-us/library/system.web.ui.page.previouspage.aspx

    0 讨论(0)
  • 2021-01-28 05:23

    When you provide to select the service in a dropdown, why not store that status in session as well ? Like

    bool chauffeurService= YourServiceDropDown.SelectedValue=="1" ? true :false;
    Session["chauffeurStatus"]=chauffeurService;
    

    Then inside your form where to process values

    // Check if Chauffer service status is 1 add 30 dollars else don't add anything
    
    0 讨论(0)
提交回复
热议问题