Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,
I'm Tarun.. I'm working as a core programmer.

I've a medical ebook portal in which user can also order COD(cash-On-Delivery).And, the portal is running on VB.net platform. Now, the problem is that when a user goes for COD order then discounted amount doesn't reflect in the mail content. So, i want to add discounted amount after deduct discount in email content. But we don't maintain discounted amount in our cart table (database). We maintain only book price and total order amount in cart table. and i also want to add shipping charge in total payable amount including discounted amount.

Please find below mentioned my code:
C#
Private Sub prcSaveData()
        Try
            'Add Author detail on 17th July 2015
            VppOrderDetail = "Order Id: " & Session("SesID")
            Dim D_amt As String
            Dim totalpay As String
            Dim totalpaywithPromo As String
            If (Session("PromoCode") = "") Then
                Dim shippingcharge As Integer
                Dim totalbookprice As Integer
                shippingcharge = totalbookprice / 10
                totalpay = shippingcharge + totalbookprice
                D_amt = ""
                'Dim totalpaywithPromo As String
                Dim promoDiscPrice As String
                'Dim DisAmount As String
                promoDiscPrice = Session("promoDiscPrice")
                promoDiscPrice = totalpay / 10
                totalpaywithPromo = totalpay - promoDiscPrice
                'D_amt = totalpaywithPromo
            End If

            CmdTmp2 = New OleDbCommand("spTmpDetails2", Con)
            CmdTmp2.CommandType = CommandType.StoredProcedure
            CmdTmp2.Parameters.AddWithValue("@SID", Session("SesID"))
            Rs = CmdTmp2.ExecuteReader
            While Rs.Read()
                CmdInsetCart = New OleDbCommand("spInsertCart", Con)
                CmdInsetCart.CommandType = CommandType.StoredProcedure
                CmdInsetCart.Parameters.AddWithValue("@SID", Session("SesID"))
                CmdInsetCart.Parameters.AddWithValue("@UN", txtUName.Text)
                CmdInsetCart.Parameters.AddWithValue("@PID", Rs("ISBN").ToString)
                CmdInsetCart.Parameters.AddWithValue("@Name", Rs("Title").ToString)
                CmdInsetCart.Parameters.AddWithValue("@Desc1", Rs("Author").ToString)
                CmdInsetCart.Parameters.AddWithValue("@Price", Rs("Price"))
                CmdInsetCart.Parameters.AddWithValue("@Qty", Rs("Qty"))
                CmdInsetCart.Parameters.AddWithValue("@Amt", Rs("Amt"))
                CmdInsetCart.Parameters.AddWithValue("@Status", "VPPOrder")
                CmdInsetCart.Parameters.AddWithValue("@PDate", Date.Now())
                CmdInsetCart.ExecuteReader()
                VppOrderDetail = VppOrderDetail & vbCrLf & "ISBN: " & Rs("ISBN").ToString & vbCrLf & "Title: " & Rs("Title").ToString & vbCrLf & "Author: " & Rs("Author").ToString & vbCrLf & "Price: " & Rs("Price").ToString & vbCrLf & "QTY: " & Rs("Qty").ToString & vbCrLf & "Amount: " & Rs("Amt").ToString & vbCrLf & "Order Date: " & Date.Now()
                'VppOrderDetail = VppOrderDetail & vbCrLf & "Total Amount to be paid: " & totalpaywithPromo
            End While
        Catch ex As Exception
        End Try
    End Sub
Posted
Updated 19-Jul-15 23:09pm
v2
Comments
Richard MacCutchan 20-Jul-15 7:07am    
Think about the steps required to do this.
1. Create the order using the information in the database.
2. Build the basic email message fromn the order.
3. Add the discount line (if any) to the message.
4. Change the total price to the discounted price.
5. Add the shipping charge line (if any) to the message.
6. Change the total price to the discounted price plus shipping
7. Add the total line to the message.
8. Send the mail.
Tarun Mittal Delhi 20-Jul-15 8:01am    
Thank you so much for your comments.... Mr. Richard MacCutchan.

Now, i need another help in this case... My code is workng on single order. But when an user order more than 1 book in a single session then my code takes only final selected book in mail content but entry of all order is inserted in the databse.
So, please help me.... how to manage more than 1 books order in a single mail.
Sergey Alexandrovich Kryukov 20-Jul-15 14:27pm    
If you maintain wrong data model, manipulations with mail won't help too much. :-)
—SA
Tarun Mittal Delhi 21-Jul-15 1:09am    
Hello,... Mr. SA.

Greetings from Tarun..!!!
Thank you so much for your kind response.

Data model of project is maintained properly. I just want to add the " total amount to be paid with discount " in mail content. In our database, we don't maintain discounted amount because the offer doesn't valid on all books always. That's why, we maintain the discount offers only in mail content.

Now, i've found some solution of code by myself.

Now, the code is running on single order[means: if an user place a single book order via COD(cash-on-delivery...) then code is running good. ] But when an user place more than 1 order then it works only on last selected book (means: if an user select a book which has cost of 500 Rupees and then select another book which has cost of 1000 rupees then my code is add the amount and details of second book which has 1000 rupees cost in mail content with discounted price,.. but entry of both books are inserted in the database in user's session or order id.)
So, please give me solution for this problem that my code should also work for more than 1 order in a single session.

Please find below mentioned my new code:



Private Sub prcSaveData()
Try
'Add Author detail on 17th July 2015
CmdTmp2 = New OleDbCommand("spTmpDetails2", Con)
CmdTmp2.CommandType = CommandType.StoredProcedure
CmdTmp2.Parameters.AddWithValue("@SID", Session("SesID"))
Rs = CmdTmp2.ExecuteReader
While Rs.Read()
CmdInsetCart = New OleDbCommand("spInsertCart", Con)
CmdInsetCart.CommandType = CommandType.StoredProcedure
CmdInsetCart.Parameters.AddWithValue("@SID", Session("SesID"))
CmdInsetCart.Parameters.AddWithValue("@UN", txtUName.Text)
CmdInsetCart.Parameters.AddWithValue("@PID", Rs("ISBN").ToString)
CmdInsetCart.Parameters.AddWithValue("@Name", Rs("Title").ToString)
CmdInsetCart.Parameters.AddWithValue("@Desc1", Rs("Author").ToString)
CmdInsetCart.Parameters.AddWithValue("@Price", Rs("Price"))
CmdInsetCart.Parameters.AddWithValue("@Qty", Rs("Qty"))
CmdInsetCart.Parameters.AddWithValue("@Amt", Rs("Amt"))
CmdInsetCart.Parameters.AddWithValue("@Status", "VPPOrder")
CmdInsetCart.Parameters.AddWithValue("@PDate", Date.Now())
CmdInsetCart.ExecuteReader()

Dim Temp As String

Temp = Rs("Amt")
VppOrderDetail = "Order Id: " & Session("SesID")
Dim totalpaywithPromo As String

If (Session("PromoCode") = "") Then
Dim promoDiscPrice As String
promoDiscPrice = Session("promoDiscPrice")
promoDiscPrice = Temp / 10
totalpaywithPromo = Temp - promoDiscPrice
End If

VppOrderDetail = VppOrderDetail & vbCrLf & "ISBN: " & Rs("ISBN").ToString & vbCrLf & "Title: " & Rs("Title").ToString & vbCrLf & "Author: " & Rs("Author").ToString & vbCrLf & "Price: " & Rs("Price").ToString & vbCrLf & "QTY: " & Rs("Qty").ToString & vbCrLf & "Amount: " & Rs("Amt").ToString & vbCrLf & "Order Date: " & Date.Now() & vbCrLf & "Total Amount to be paid with discount: " & totalpaywithPromo

End While

Catch ex As Exception
End Try

End Sub
Sergey Alexandrovich Kryukov 21-Jul-15 1:19am    
Great, thank you for the note.

I did not mean that you should maintain discounted amount, but, if you have discounts, you certainly have to have it in the adequate database model. It does not have to be "discounted amount", moreover, it's important to avoid redundancy. "Does not valid on all books always" is not a reason for not maintaining something, because the predicate "valid" can also be computable, and because the database state is being changed in time (if this is what you mean by "not always").

Anyway, I hope it was just about the implementation detail.

Cheers,
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900