Jes Sie

Jes Sie

  • 737
  • 1.2k
  • 284.4k

Implementing Credit Limit

Feb 25 2017 4:39 AM
I have created a webforms application for a micro-insurance business. In one of my forms, I added a button which redirects a user to page where he can sell insurance. Each user has a credit limit. Once reached, the idea is that the button which redirects to selling will be invisible. 
 
I was able to get the credit limit from the database. My problem is how can I hide or show the button if the condition is satisfied. Below is my design and snipets of my code behind. I'm still new in programming.
 
  1. public partial class credit_limit : System.Web.UI.Page  
  2.     {  
  3.         protected void Page_Load(object sender, EventArgs e)  
  4.         {  
  5.             lblUserName.Text = Session["username"].ToString();  
  6.             lblDepartment.Text = Session["department"].ToString();  
  7.             
  8.             if(!IsPostBack)  
  9.             {  
  10.                 viewCreditLimit();  
  11.             }  
  12.   
  13.         }  
  14.   
  15.         protected void btnMotor_Click(object sender, EventArgs e)  
  16.         {  
  17.              
  18.         }  
  19.   
  20.   
  21.         private void viewCreditLimit()  
  22.         {  
  23.             using (SqlConnection con = DBConn.GetDbCon())  
  24.             {  
  25.                 con.Open();  
  26.                 SqlCommand cmd = new SqlCommand("select CreditLimit from Login where UserName = @UserName and DepartmentID=@DepartmentID", con);  
  27.                 cmd.CommandType = CommandType.Text;  
  28.                 cmd.Parameters.AddWithValue("@UserName", lblUserName.Text);  
  29.                 cmd.Parameters.AddWithValue("@DepartmentID", lblDepartment.Text);  
  30.                  
  31.                 using (SqlDataReader rdr = cmd.ExecuteReader())  
  32.                 {  
  33.                     try  
  34.                     {  
  35.                         while (rdr.Read())  
  36.                         {  
  37.                             lblcreditlimit.Text = rdr["CreditLimit"].ToString();  
  38.                         }  
  39.                               
  40.                     }  
  41.                     catch(Exception ex)  
  42.                     {  
  43.                         throw ex;  
  44.                     }  
  45.                 }  
  46.   
  47.             }  
  48.         }  
  49.   
  50.         private void showButton()  
  51.         {  
  52.             if (lblcreditlimit.Text < lblcreditlimit.Text)  
  53.             {  
  54.                 Panel1.Visible = true;  
  55.             }  
  56.             else  
  57.             {  
  58.                 Panel1.Visible = false;  
  59.                 lblMessage.Text = "Your credit limit is already reached.";  
  60.             }  
  61.         }  
  62.     }  

Answers (2)