如何在C#中使用if语句来检查成员资格级别 [英] How to use if statement in C# to check the membership level
本文介绍了如何在C#中使用if语句来检查成员资格级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的尝试:
十进制 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屋!
查看全文