Sunday, January 31, 2010

Databinding with combobox in C# windows application

It is quite similar to the databinding with dropdown list in ASP.NET. Anyway, here is the code for databinding.
# code for databinding with combobox

try {
SqlConnection conn = new SqlConnection();
conn.ConnectionString = Properties.Settings.Default["MyConnStr"].ToString();
conn.Open();

string select_cats="select * from BusinessCategory";
SqlDataAdapter sda=new SqlDataAdapter(select_cats,conn);
DataTable dt=new DataTable();
sda.Fill(dt);

//databinding to the combobox
TestcomboBox.DataSource = dt.DefaultView;
TestcomboBox.DisplayMember = "Description";
TestcomboBox.ValueMember = "BusCatID";





}
catch (Exception exc) {

//MessageBox.Show(exc.Message);
}

Here we see 'Description' is used here as text property and 'BusCatID' is used here as value property with combo box.


Creating paypal shopping cart

Before finishing the my project http://www.biznesmakler.pl I found that client wants me to change payment procedure through paypal. He wants a way to perform payment by buyer to paypal without login to paypal account that means payment with credit card only. Apparently I found that there is no available way for payment without login to paypal account. Actually, if anyone has a paypal account he wont be able to make payment to paypal without login according to current strategy...that if paypal checks a credit card for once it has a record for that card and it will prompt for registration next time. As I was trying to integrate with paypal in express checkout and it needed login to paypal for account confirmation.

Anyway, I thought there is no way to pay without login..but there is. And the only exclusive way to make payment is payment with shopping cart. And its quite east to integrate the site paypal shopping cart techniques. Lets summarize the way of paypal shopping cart integration.

1. Login to paypal business account
2. Click Merchant service tab
3. Select create New Button Link. After a process of creating button you will be provided with the button code with a button id.
4. Now you can redirect your buyer for payment in this way. Here is the code.


//redirect to option 1 button
StringBuilder builder = new StringBuilder();
builder.Append(bizcart.scartPostURL);
builder.Append("&cmd=_s-xclick");
builder.Append("&hosted_button_id=" + bizcart.valuationOption1ButtonID);
paypal_redirect_url = builder.ToString();


Here bizcart.valuationOption1ButtonID is the button id we have generated.
Thats the way to work with paypal shopping cart.

Masud. (31.1.2010)

Friday, January 8, 2010

Creating PDF using ASPpdf service

Here I will be discussing about creating pdf document using asppdf service. Here are some steps to be followed:
1. downloading and installing asppdf
2. Integration with application
3. coding for creation the pdf document

Mainly I prefer asppdf for creating PDF directly from a web URL. When I tried to use iTextSharp for converting a html or aspx page to PDF then it got stuck and my project exposed to risk of failing to satisfying some basic needs. However, here I am going to describe them in details

1. downloading and installing asppdf
one can download a 30-days free trial from the following URL:
http://asppdf.com/download.html
and then will provide a key which should be used during installation. After installing you will get a .dll in Bin folder of the installation directory.This dll is the object to work with.

2. Integration with application
You can get the dll from such a path:E:\Program Files\Persits Software\AspPDF\Bin\
Now you have to create a reference to that dll suing VS-200x

3. coding for creation the pdf document

using ASPPDFLib; //this is the required namespace of the dll

public string createAspPDF(string sourceURL, string destdirectory, string filename)
{
string created_pdf_url = string.Empty;
try {
HttpContext.Current.Session["access"] = "yes";
IPdfManager mymanager = new PdfManager();
IPdfDocument mydocument = mymanager.CreateDocument(System.Reflection.Missing.Value);
mydocument.ImportFromUrl(sourceURL, Missing.Value, Missing.Value, Missing.Value);
String myfilename = mydocument.Save(HttpContext.Current.Server.MapPath(destdirectory) + filename, true);
created_pdf_url = destdirectory + myfilename;
}
catch (Exception exc) {
return exc.Message;
}
return created_pdf_url;

}

where, sourceURL="http://www.nochallenge.net/biznesmakler"
destdirectory=destination directory in biznesmakler,
filename=file name for the pdf file,
created_pdf_url=the url of pdf file just created.

So that is the way to deal with pdf directly from a web url.

thx
Masud (1-9-2009)