如何在C#中使用if语句来检查成员资格级别 [英] How to use if statement in C# to check the membership level

查看:110
本文介绍了如何在C#中使用if语句来检查成员资格级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个项目。我必须根据用户在注册时选择的会员级别给用户打折。如果用户选择银然后10%折扣,如果青铜然后20%,如果黄金然后30%折扣。我使用下面的代码,但我无法弄清楚如何使用if语句。 textbox4显示数据库中的值。如果textbox4中的值是银,则为10%折扣,或者如果textbox4中的值为青铜,则为20%,或者如果textbox4中的值为金,则为30%。请帮忙。



我的尝试:



 十进制 disc1 =  10 ; 
decimal disc2 = 20 ;
decimal disc3 = 30 ;
string s,t;

string [] a = new string [ 5 ];
SqlConnection con = new SqlConnection();
con.ConnectionString = 数据源=。\\sqlexpress;初始目录= college_education;用户ID = SA;密码=体系;;
con.Open();

SqlCommand com = new SqlCommand( 选择C.User_name,sum(C.qty * P.product_price)TAmount,CR.ADDRESS,CR.membership_level ML来自购物车C,Customer_registration CR,产品P,其中C.product_id = P.id和C.user_name = ' + Session [ user] + '和status ='ATC'和C.user_name = CR.user_name group by C.user_Name,CR.membership_level,CR.ADDRESS ,con);

SqlDataReader sdr = com.ExecuteReader();
sdr.Read();

TextBox5.Text = sdr [ TAmount]。ToString() ;
TextBox2.Text = sdr [ User_name]。ToString();
TextBox4.Text = sdr [ ML]。ToString();
TextBox3.Text = sdr [ ADDRESS]。ToString();

if (TextBox4.Text == silver
{

}

else if (TextBox4.Text == bronze
{

}
else if ( TextBox4.Text == gold
{


}

解决方案

这样做:

  double  discount =  1  0 ; 
string membership = textBox4.Text.Trim.ToLower();
开关(会员资格)
{
案例 bronze:discount = 0 10 ; break ;
case silver :discount = 0 20 ; break ;
case gold :discount = 0 30 ; break ;
}



然后将原价乘以(1.0 - 折扣)以获得新值。


i am developing a project. i have to give discount to the user based on the level of membership the user chooses at the time of registration. if the user selects silver then 10 % discount, if bronze then 20% and if gold then 30% discount. i am using the below code but i am not able to figure out how to use the if statement. textbox4 is showing the value from the database. if the value in textbox4 is silver then 10% discount or if the value in textbox4 is bronze then 20% or if the value in textbox4 is gold then 30%. please help.

What I have tried:

decimal disc1=10;
decimal disc2 = 20;
decimal disc3=30;
string s, t;

string[] a = new string[5];
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=.\\sqlexpress;Initial Catalog=college_education;User ID=sa;Password=system;";
con.Open();

SqlCommand com = new SqlCommand("Select C.User_name,sum(C.qty*P.product_price) TAmount,CR.ADDRESS,CR.membership_level ML  from cart C,Customer_registration CR, prod P where C.product_id = P.id and C.user_name='" + Session["user"] + "' and status='ATC' and C.user_name=CR.user_name group by C.user_Name,CR.membership_level,CR.ADDRESS", con);

SqlDataReader sdr=com.ExecuteReader();
sdr.Read();

TextBox5.Text=sdr["TAmount"].ToString();
TextBox2.Text = sdr["User_name"].ToString();
TextBox4.Text = sdr["ML"].ToString();
TextBox3.Text = sdr["ADDRESS"].ToString();

if(TextBox4.Text=="silver")
{

}

else if (TextBox4.Text=="bronze")
{

}
else if (TextBox4.Text=="gold")
{


}

解决方案

Do this:

double discount = 1.0;
string membership = textBox4.Text.Trim.ToLower();
switch (membership)
   {
   case "bronze": discount = 0.10; break;
   case "silver": discount = 0.20; break;
   case "gold": discount = 0.30; break;
   }


Then multiply the original price by (1.0 - discount) to get the new value.


这篇关于如何在C#中使用if语句来检查成员资格级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆