  | 
		 		   | 
	  	    
          
            
			
	
			
			 
                1	/A1001	/4.00 	/NULL	/50.00	/1	 
2	/A1001	/1000.00	/2999.99	/250.00	/2	 
3	/A1001	/3000.00	/NULL	/500.00	/2	 
4	/C1001	/2500.00	/4999.99	/150.00	/2	 
5	/C1001	/5000.00	/NULL	/300.00	/2	 
6	/C1001	/500.00	/999.99	/50.00	/2	 
7	/C1002	/1000.00	/3999.99	/100.00	/2	 
 
 
 
ช่องสุดท้าย เป็นตัวบอกว่า เป็นบาทหรือ เป็นชิ้น 1 ชิ้น / 2 บาท 
 
 
ตัวโปรแกรมทำงานประมาณว่า เลือก สินค้า ใส่ราคา ใส่จำนวน 
พอกดปุ่มคำนวณ ก็จะคิดราคาสินค้าทั้งหมด (ราคา * สินค้า ) 
                            เเสดงส่วนลดจากโปรโมชั่น ที่เข้ากับเงื่อนไขนั้น (  เเต่ถ้าสมมุติว่า ซื้อของ A1001 1000 บาท 4 ชิ้น มันจะตรงกับ 2 โปรโมชั่น ให้เอาส่วนลด บวกกันเลย) 
                           จากนั้นเเสดง จำนวณเงินที่ต้องชำระ (สินค้าทั้งหมด -ส่วนลด) 
 
 
 
Code ที่เราทำได้เเบบมึนๆ = = 
 
Code (VB.NET) 
 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim product_code As String = product.SelectedItem.Value
        Dim price As Decimal = txt_price.Text
        Dim unit As Decimal = txt_NumProduct.Text
        Dim PriceIncludes As Decimal = price * unit
     Dim dis As String = Calculate(product_code, PriceIncludes, unit)
            Dim total As Decimal = PriceIncludes - dis
            price = (Math.Truncate(price * 100)) / 100
            If IsNumeric(txt_price.Text) Then
                TextBox2.Text = ("" & PriceIncludes)
                TextBox3.Text = (" " & dis)
                TextBox4.Text = (" " & total)
     
        End If
    End Sub
 
 
 
อันนี้เราลองแก้จากโค้ดที่ไปเจอมา ทำได้แล้วค่ะ เเต่มันจะมีกรณีที่ ส่วนลด ซ้ำกันอยู่ นั่นคือเงื่อนไขที่ว่า 
เเต่ถ้าว่า ซื้อของ A1001 1000 บาท 4 ชิ้น มันจะตรงกับ 2 โปรโมชั่น ให้เอาส่วนลด บวกกันเลย นั่นคือเอา 250 +50) 
Code (VB.NET) 
Function Calculate(ByVal product_code As String, ByVal PriceIncludes As Decimal, ByVal Unit As Decimal) As Decimal
        Dim dis As Decimal = 0
        Dim dt As New DataTable
        Dim sqlconn As New OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
        Dim reader As OleDbDataReader
        Dim comm As New StringBuilder
        comm.Append(" select discount ")
        comm.Append(" from promotion ")
        comm.Append(" where product = ? ")
        comm.Append(" and ( ( minmax_type_id = '2' and ((min_price <=  ? )  and  (isnull(max_price,9999999 ) >=  ?)))")
        comm.Append(" or( minmax_type_id = '1' and ((min_price <=   ? )  and  (isnull(max_price,9999999 ) >= ?)) ) ) ")
        Dim OleComm As New OleDbCommand(comm.ToString, sqlconn)
        OleComm.Parameters.AddWithValue("@00", product_code)
        OleComm.Parameters.AddWithValue("@01", PriceIncludes)
        OleComm.Parameters.AddWithValue("@02", PriceIncludes)
        OleComm.Parameters.AddWithValue("@03", Unit)
        OleComm.Parameters.AddWithValue("@04", Unit)
        sqlconn.Open()
        reader = OleComm.ExecuteReader(CommandBehavior.CloseConnection)
        If reader.HasRows Then
            dt.Load(reader)
            dis = dt.Rows(0).Item("discount")
        End If
        'Dim a As New Page4
        'a.MinMax()
        Return dis
    End Function
 
 
Error message : Additional information: Command text was not set for the command object.
 
 
  Tag : .NET, Web (ASP.NET), VB.NET, VS 2013 (.NET 4.x)               
                        | 
           
          
            
		
  ประวัติการแก้ไข 2017-08-07 14:32:33 2017-08-07 14:35:03 2017-08-07 14:42:24 2017-08-07 15:24:01	
                             | 
           
          
            
              
                   | 
                   | 
                   | 
               
              
                   | 
                
                    
                      | Date :
                          2017-08-07 14:27:23 | 
                      By :
                          NumWhan | 
                      View :
                          1328 | 
                      Reply :
                          1 | 
                     
                  | 
                   | 
               
              
                   | 
                   | 
                   | 
               
              | 
           
          
            | 
			 | 
           
         
	    
		             | 
		
			  |