Monday, December 28, 2009

Big Fish Ever

Today I went for lunch I was thinking what I will eat. However, stomach was not in a good condition but I did not have breakfast that's the point. So, I have to eat something good that I was thinking. So I ordered a fish. But when the fish came, to my utter surprise, I found that it was a big fish. I am afraid whether I could finish it or not. Apparently, it was fish for at least 4 people and I started eating. I was eating slowly. I didn't finish good taste as it was not well-cooked. So, I felt bad to finish the fish..otherwise it will be counted as spoiling. However, finally I finished the eating and came out normally. However, I decided not to eat such mammoth fish again.
thx. (27-12-2009)
Masud

Big Fish Ever

Today I went for lunch I was thinking what I will eat. However, stomach was not in a good condition but I did not have breakfast that's the point. So, I have to eat something good that I was thinking. So I ordered a fish. But when the fish came, to my utter surprise, I found that it was a big fish. I am afraid whether I could finish it or not. Apparently, it was fish for at least 4 people and I started eating. I was eating slowly. I didn't finish good taste as it was not well-cooked. So, I felt bad to finish the fish..otherwise it will be counted as spoiling. However, finally I finished the eating and came out normally. However, I decided not to eat such mammoth fish again.
thx. (27-12-2009)
Masud

Saturday, December 26, 2009

Creating PDF file using ASP.NET,C#

This is an interesting thing to accomplish creating PDF file in ASP.NET ,C#. Let me share with you the techniques of creating PDF. Here are the following steps.
step-1: download the following itextsharp .dll from the following link
step-2: Add reference to the .dll in your project using Visual studio
step-3: Now use the following code only to create a simple paragraph in .pdf file.
//creating pdf source code
try {
Document mydoc = new Document(PageSize.A4.Rotate());
PdfWriter.GetInstance(mydoc,new FileStream("masud.pdf",FileMode.Create));
mydoc.Open();
mydoc.Add(new Paragraph("This is the first paragraph written by me"));
mydoc.Close();
MessageBox.Show("PDF created successfully!");

}
catch (Exception exc)
{
MessageBox.Show("Failed to create PDF file"+exc.Message);
}

This is how you can create PDF uisng some dll. So interesting!

thanks. Masud (26-12-2009)

Sunday, December 13, 2009

The First Day in KU in job career

All the time there may be some hesitation and unknown worries about the first day for a new job to start. Though I was not first to start a job but the matter is it was the first day for a govt. job and there are certain formalities I have to follow. However, the day before the joining my supervisor called me and informed me the result. After knowing the result I was excited but the moment I heard that the next day I have to join then it becomes really problematic for me. I then called head sir for the decision to be taken for the welfare of job career. He told me to join the next day. So I have to decide to catch the bus the within next 2 hours and I had to finish lots of works within a very short time. Mukta did a great job by collecting my ticket for the bus. However, when at the evening I was planning for the night having a company job, but at the night I had to run for a govt. job. When I reached khulna I found it was place of cold relative to dhaka. After the official works...we spent some time in the office...having some snacks in the afternoon and in the night again started for Dhaka in response to the responsibility of company's call. So this was my first day in KU job as a lecturer.
Thanks for reading!

Masud...(14/12/2009)

Thursday, November 12, 2009

Working With Google Checkout

Recently I have worked on shopping cart using Google checkout.This is quite easy to work with Google checkout rather than Paypal or others. However, I will be describing here in brief:

Steps:
1.Shopping cart account in Google
2.Downloading GCheckout.dll and installing in VS.
3.Working with GCheckout Button.

Here I will be describing in details.

1.Shopping cart account in Google
Generally for this you will have to have a google account. And using this account you can create shopping cart account. So if you have account then do the following.
a. log in to Google.
b. visit https://sandbox.google.com/checkout/main
c. Here you will find a control panel having 'Edit Payment Method'. Here you will put your credit card info to which customer will pay you. And also some other info you have to pay like country, city, shipping address etc.
d. Then go to main panel and collect Merchant ID, Merchant Key which will be used in your website for accessing the shopping cart account. Generally
these keys will be generated by Google.

2.GCheckout.dll
a.You can make a Google search and download this dll. For Asp.net developer, there is a .NET version of GCheckout. You have to download that. After downloading this dll you have to Add reference to this dll and in this way, the dll will be copied to website Bin directory.
b. Add reference: Solution Explorer>Website Name>Add Reference>browse the dll

3.Working With GCheckout Button
To work with GCheckout Button you have to do the following:


a.Toolbox>Choose Item>browse dll.
This way new controls (dll) will be shown up in toolbox (GCheckoutButton,GCheckoutDonateButton);
b. Now drag and drop the control to the .aspx page and you will see automatically the following code will be generated.
i. in directive section:
< %@ Register Assembly="GCheckout" Namespace="GCheckout.Checkout" TagPrefix="cc1" % / >
ii.in page body:
< cc1:GCheckoutButton ID="MyGCheckoutButton" runat="server"
onclick="MyGCheckoutButton_Click" / >

Here, we see that this button is clicked and handler is generated to handle the event.
c. Web configuration section:
You have to put the following configuration in app setting.
< appSettings >
< add key="GoogleMerchantID" value="XXXXXXXXXX" />
< add key="GoogleMerchantKey" value="YYYYYYYYYY" />
< add key="GoogleEnvironment" value="Sandbox" />
< /appSettings>

The Merchant ID and Merchant Keys will have to be inserted in the above section to make the system works.

d. Coding in the Button event handler function.
You have to put the following code in the function:



CheckoutShoppingCartRequest chkoutShoppingCartReq = MyGCheckoutButton.CreateRequest();
chkoutShoppingCartReq.AddItem("Business Plan: Plan No"+Session["PlanID"], "Business Plan Consultancy Fee", decimal.Parse(Session["PlanCost"].ToString()), 1);
GCheckoutResponse obtainedResponse = chkoutShoppingCartReq.Send();
Response.Redirect(obtainedResponse.RedirectUrl, true);


Here obtainedResponse.RedirectUrl is the URL to which website will be redirected for payment.
e.When you will be working in the Setting in Merchant Account you have to generally set the thank you page (for payment) as the redirect URL so that after successful payment, the user can be acknowledged that his/her payment is received successfully and he/she is free to go.


This is the way..Google Checkout works.

Thanks. Masud (13-11-2009)

Wednesday, November 4, 2009

Lecturer @ KU

Lastly..it is a matter of great joy that I am appointed as a lecturer of Khulna University. This brings lots of hopes with lots of responsibility. Lets see how it changes my life as people say like that.

thanks.
Masud (5-11-2009)

Lecturer @ KU

Lastly..it is a matter of great joy that I am appointed as a lecturer of Khulna University. This brings lots of hopes with lots of responsibility. Lets see how it changes my life as people say like that.

thanks.
Masud (5-11-2009)

Thursday, September 17, 2009

Some CSS tips I used

I was not that much recognized in CSS but nowadays I found that CSS has a great power to turn the website into an online space. Here is something I worked:

1. padding> padding used to shift the text from the original space it was supposed to stay.
padding-left:10px;
2. no wrap>It removes line break inside the text


my value


view:
myvalue

CSS File:

.mytext
{
padding-left:10px;
white-space:nowrap;
}

Often these two things are very useful.

Masud (17-07-2009)

Saturday, September 5, 2009

A bunch of tricky problems and solution

This weekend I faced a bunch of tricky problems that I solved after working hard on it. Here is a little description for that: Actually I am being a bit informal in case of description. I will be just copy and paste the report I used in my business.

1.a: Notorious problem for coping one whole page to other
Once upon a time I designed some pages according to some provided pages like
index.aspx buyabiz.aspx
I designed new pages like indexc.aspx or buyabizc.aspx. and so far I was working on it....
but the page name remain index.aspx....for it.which cause notorious problem to make ur head hung. It will give undefined errors. So we have to be careful.

2. I learned to use as in stored procedure that reduces the query size. Let me explain with an example:

select C.CityName, V.Voivodeship from City as C, VoivodeshipInfo as V where C.VoivodeshipID=V.VoivodeshipID order by C.CityName

3. Use of nvarchar(50) will save only 50 chars from the input taken
4. Negative balance showing:
This is a very typical problem. When u try to format in currency in this way:
string.Format("{0:C}",-25.50)..result is ($25.50)....:-)
This is a killing me problem. I used the picture format notation to solve this problem. The format I used is:

string.Format("{0:$#,#.00}",-25.50)..output is -$25.50 which I expected.

5.Look at this:
a.select DateTime, Name from Timetable as T where DateTime='2/9/2009': fails
b.select DateTime, Name from Timetable as T where T.DateTime='2/9/2009':works

here 5.a is incorrect but b will correct

6.To edit a column from SQL server Mgmt studio :
Table>Columns>Modify...

The column must allow null and have a default binding value
7. In CSS design:
display:none ---hides the control

lets look at it:

#menunav ul li:hover #submenu
{
display:block;
width:115px;
height:100px;
}
This is the hover syntax in css. when mouse is hovered on submneu-title then the
submenu is displayed and otherwise it is hidden.

8. when to redirect using the syntax in LinkButton or Response object:

Response.Redirect("www.cse.com"); won't work because it searches a page within ur website called www.cse.com.

Solution:
Response.Redirect("http://www.cse.com");

Tuesday, August 25, 2009

Adding command to Item in DataList

This is much simple and I did it without tutorial from the context of command knowledge.Lets make an overview here. Here is the HTML code that adds a command to the link button which is a control of a DataList Item:

1. HTML code
< asp:DataList >
< ItemTemplate >
< ItemTemplate >
< asp:LinkButton ID="hypTest" runat="server" CommandName="MySelect" >< strong >< %# DataBinder.Eval(Container.DataItem, "BusinessName") % >< /strong >< /asp:LinkButton >
< br / >
< asp:Label runat="server" Text='< %# DataBinder.Eval(Container.DataItem, "ShortDescription") % >' BorderStyle="None" Height="48px" Width="180px" >< /asp:Label >
< asp:Label ID="conidLabel" runat="server" Text='< %# "contractordetails.aspx?conid=" + DataBinder.Eval(Container.DataItem, "contractorid") % >' Visible="false" >< /asp:Label >
< asp:Label ID="contid" runat="server" Text='< %#Eval("contractorid") % >' Visible="false" >< /asp:Label >
< br / >
< /ItemTemplate >
< /ItemTemplate >
< /asp:DataList >

Here we can see that how a command is added to the link button for issuing command which we will use later.

2. Programmer's Task:
Here is the code what programmer will do. Actually here I have done a code for updating balance for a contractor for each client click.

try {
DataListItem myselectedItem = e.Item;
Label myLabel = myselectedItem.FindControl("conidLabel") as Label;
Label contid = myselectedItem.FindControl("contid") as Label;


if (e.CommandName == "MySelect")
{

/*click fee handling code:here*/
try
{

int catid = int.Parse(Session["catid"].ToString());
float clickfee = 0;

/*getting click fee*/
try {
Category category = new Category();
if (category.LoadByPrimaryKey(catid))
{
clickfee =float.Parse( category.ClickFee.ToString());
}
/*click fee obtained*/

}
catch (Exception exc) {
StatusLabel.ForeColor = Color.Red;
StatusLabel.Text = "Failed to retrieve click fee!";
}

/*subtracting from balance*/
try {
Contractor contractor = new Contractor();
int contractorid = int.Parse(contid.Text);
if (contractor.LoadByPrimaryKey(contractorid))
{
float currentBalance =float.Parse( contractor.PrepaidAmount.ToString());
currentBalance = currentBalance - clickfee;
contractor.PrepaidAmount = currentBalance;
/*saving change*/
contractor.Save();
}

}
catch (Exception exc)
{
StatusLabel.ForeColor = Color.Red;
StatusLabel.Text = "Failed to subtract click fee from balance!";
}


}
catch (Exception exc) { }

/*Redirecting to the contractor details page*/
string redirect_url = myLabel.Text;
Response.Redirect(redirect_url);

}

//StatusLabel.Text = "done!";
}
catch (Exception exc)
{
StatusLabel.ForeColor = Color.Red;
StatusLabel.Text = exc.Message;
}


Here we can see we can get the selected item using
DataListItem myselectedItem=e.Item;
whereas for getting the selected row from GridView we had to do a lot of work.
However, Now we can access this item for further operation like getting some hidden value and use them for further operatiuons:

Label myLabel = myselectedItem.FindControl("conidLabel") as Label;
Label contid = myselectedItem.FindControl("contid") as Label;

I think this will help.

Thanks
Masud (25-08-2009)

Saturday, August 15, 2009

Selecting a item from Dropdownlist

This is an interesting thing I did few days ago while I was working in my office. Suppose the DDL(Dropdownlist) is containing some items. You wanna select one from the list programmatically at runtime. Generally at first I tried to do in this way:

MyDDL.Text="item text";
But this will not work and actually it will not also show any error. You will just try and try but nothing will happen. So we need to click the right way.

As we already saw the two things for databound DDL is:
* DataTextField
* DataValueField

Suppose Subcategorydesc=dataTextField
SubCatID=datavaluefield

And we want to select a subcategory called "Marketing" having subcatid=3. Then the code will be like this:

MyDDL.Items.getByValue("3").Selected=true;

thanks
Masud.

Wednesday, August 5, 2009

Gridview editing problem: Textbox cant store new value in the editing mode

This is a common problem I have faced during my work. Every events are properly handled you will not get the new value in the update time. This is ridiculous thing and often your head can be cracked. But the solution to this problem is quite simple. Lets look at the example that I did....

Suppose this is the code for Update:

protected void ImgGridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
/*Image info to be updated*/
try {
/*Extracting different elements from Gridview*/
GridViewRow myRow = ImgGridView.Rows[e.RowIndex];
/*getting pic id*/
Label PicIDLabel = myRow.Cells[2].FindControl("PicIDLabel") as Label;
/*getting image title*/
TextBox titleTextBox = myRow.Cells[1].FindControl("ImgTitleTextBox") as TextBox;


/*updating ad image*/
AdImage adImage = new AdImage();
adImage.ConnectionString = ConfigurationManager.ConnectionStrings["BIZNESConnectionString"].ConnectionString;
if(adImage.LoadByPrimaryKey(short.Parse(PicIDLabel.Text)))
{
adImage.ImgTitle=titleTextBox.Text;

adImage.Save();

}

ImgGridView.EditIndex = -1;
showAdImageInfo();

StatusLabel.ForeColor=Color.Green;
StatusLabel.Text="Image information updated successfully!";
StatusImage.ImageUrl = "adimages/ok.gif";


}
catch (Exception exc)
{
StatusLabel.Text = exc.Message;

}

}

So found no problem in update code every time I debug the code ....I spend the whole day on it and at last I found a forum that probably I have to check for autopostback option of the page.
So my Page_Load was like this:
protected void Page_Load(object sender, EventArgs e)
{



string access = (string)Session["access"];
/*checking access*/
if (access != "yes")
Response.Redirect("SellerAdminLogin.aspx"

/*showing images*/
showAdImageInfo();


}
For that killing problem to resolve we have to check the postback option. Lets look at the editing function:

protected void ImgGridView_RowEditing(object sender, GridViewEditEventArgs e)
{

/*Image editing code*/
ImgGridView.EditIndex = e.NewEditIndex;
showAdImageInfo();

}

If autopost-back is not checked every time gridview will loaded with values from databse so when update command will be clicked then data will be loaded from database to the textbox and new value in the textbox will be lost. So we need to check the auto-postback option:

protected void Page_Load(object sender, EventArgs e)
{


if(!Page.IsAutoPostBack)
{
string access = (string)Session["access"];
/*checking access*/
if (access != "yes")
Response.Redirect("SellerAdminLogin.aspx"

/*showing images*/
showAdImageInfo();

}
}

Thus update will easily work and we will be able to update the gridview data

thanks.
Masud

Tuesday, August 4, 2009

Image Carousel Tools

I came to learn a very interesting thing which is implemented using JQuery and named as Image carousel. I came to learn from my mentor while doing the project
http://nochallenge.net/biznesmakler.
Here I have made some cosmetic customization which evolves the existing carousel to a professional level as said by project manager. However I will be dealing with next couple of my posting with image carousel as well as lightBox slideshow

thanks.
Masud

Adding Select text in databound Dropdownlist

To create a data-bound dropdownlist we have to follow several steps. This time we are using Business entity which is CSharp Business Entity template and it is same as creating the business object. Suppose a business entity Category having three fields.

Category:
CatID
CatDescription
Active

Now we want to make a databound dropdownlist(DDL). Lets call the dropdownlist is CatDropDownList. So we have 2 steps:
1. Creating databound DDL
2. Inserting select text

Here we go:
1. Creating databound DDL.
try
{
Category category=new Category();

/*Generating and executing query*/
category.Query.AddResultColumn(Category.ColumnNames.CatID);
category.Query.AddResultColumn(Category.ColumnNames.CatDescription);
category.Query.Load();

/*databinding*/
this.CatDropDownList.Datasource=category.DefaultView;
this.CatDropDownList.DataTextField=Category.ColumnNames.CatDescription;
this.CatDropDownList.DataValueField=Category.ColumnNames.CatID;
this.CatDropDownList.DataBind();

2.Inserting Select text:
Generally if you add item now then DDL will not retain that item. this time you have to insert the values in the DDL. The required code is:
this.CatDropDownList.Items.Insert(0,"select a category");

}
catch(Exception exc){}

Now comes how use the value selected by the DDL.This is quite simple.
int selectedCatID=Convert.ToInt32(CatDropDownList.SelectedValue);
here selectedCatID will give the selected CatID of the category you selected....

Thanks.
Masud (5.8.9)

Friday, July 24, 2009

Adding cc and bcc in MailMessage

This is a pretty little thing but it may cause sometimes a lot of problem when you are implementing the email function. Suppose you are using System.Net.Mail namespace for implementing email functionality.So code is:

using System.Net.Mail;

MailMessage msg=new MailMessage("from@gmail.com","to@gmail.com");
msg.CC="masudcseku@gmail.com"; /*Error*/
msg.CC.Add("masudcseku@gmail.com");/*correct*/

msg.bcc="masud_mnthk@yahoo.com"; /*Error*/
msg.bcc.Add("masud_mnthk@yahoo.com");/*correct*/

This is a pretty little thing huh!...but often this will be useful.
**************************************
Masud(7.25.2009)

Issuing a javascript object by ASP.NET at load time

This is a nice feature ASP.NET provides that ASP.NET is providing a javascript object populated with data which can be used by client-side script very effectively. Let see this step by step.
Steps:
1. Suppose in ASP.NET you are using some variable (ex:testaskingprices) having some value. Now you want to transfer this value to access by the client-side code. So then you have execute this code in Page_Load event of page

this.ClientScript.RegisterArrayDeclaration("myAskPriceList", testaskingprices);

where
testaskingprices=the ASP.NET variable
myAskPriceList=the javascript variable issued for use

**************************************
Masud (25.7.9)

I am living bugs life

Ohh...I cant sleep at night. I found my legs and hands are punctured at different places and I was surprised this could be. Every night I keep up myself up to 6.00 AM. when it is about to morning I get sleep being tired. To my utter surprise I found that I am living with bugs...(charpoka). Wooh...this fucking insect is killing me. I writing this blog also keeping myself awake and often I am killing them.....I need to change this mess.

Masud

I am living bugs life

Ohh...I cant sleep at night. I found my legs and hands are punctured at different places and I was surprised this could be. Every night I keep up myself up to 6.00 AM. when it is about to morning I get sleep being tired. To my utter surprise I found that I am living with bugs...(charpoka). Wooh...this fucking insect is killing me. I writing this blog also keeping myself awake and often I am killing them.....I need to change this mess.

Masud

Friday, July 17, 2009

Getting some hand over web technology

After serving 2-3 months in my company I found some changes in my thought regarding my works and I found that really professionalism needs an environment to develop. I, who could not develop an entire web site properly during my university years properly...that guy is about to complete a professional website within few days.This time I have found some ideas. Lets code it down.
1. Learn controls of AJAX and Silver light ASAP..download toolkit. Download IDE if needed...
2. Download Jquery library and execute the controls and enhance to a professional level
3. Have a good concept on WPF,WCF...
4. Learn different application of XML....

These are the ideas so far I have got...
masud
(17.7.9)

Getting some hand over web technology

After serving 2-3 months in my company I found some changes in my thought regarding my works and I found that really professionalism needs an environment to develop. I, who could not develop an entire web site properly during my university years properly...that guy is about to complete a professional website within few days.This time I have found some ideas. Lets code it down.
1. Learn controls of AJAX and Silver light ASAP..download toolkit. Download IDE if needed...
2. Download Jquery library and execute the controls and enhance to a professional level
3. Have a good concept on WPF,WCF...
4. Learn different application of XML....

These are the ideas so far I have got...
masud
(17.7.9)

Difference between ametuership & professionalism

There are of course some differences between these two which I come to realize after 2 or 3 months of my job career. let me point out some things:
1. professionalism demands pure concentration
2. professionalism demands more broad outlook towards work, customer-needs etc.
3. professionalism demands more dedication & responsibility and accountability
4. it demands aspiration for learning, higher position.
5. it demands expected level of contribution to the company
..............................................................
These are the things I have got so far.

thanks.
masud (17.7.9)

Difference between ametuership & professionalism

There are of course some differences between these two which I come to realize after 2 or 3 months of my job career. let me point out some things:
1. professionalism demands pure concentration
2. professionalism demands more broad outlook towards work, customer-needs etc.
3. professionalism demands more dedication & responsibility and accountability
4. it demands aspiration for learning, higher position.
5. it demands expected level of contribution to the company
..............................................................
These are the things I have got so far.

thanks.
masud (17.7.9)

Tuesday, July 14, 2009

Allowing paging in Gridview when datasource is not predefined

Suppose you are not setting predefined data source means you are not using sqldatasource as the data source then this article is helpful for enabling the paging option. Suppose you will determine data source at run-time means you are using SqldataAdapter then u are welcome:

In the html code of Gridview you have to set AllowPaging="true"

Here is the code for handling paging manualy:
protected void TestGV_pageIndexChanging(object sender, GridViewPageEvent e)
{
TestGV.pageIndex=e.NewPageIndex;
TestGV.dataBind();
}

Here we see page index is updated as the index of page changes. By default page size=10 however it can be changed in the html code of Gridview.

Thats for today
Masud (15.7.9)

Removing underline from a hyper link

This is a nice thing and expected attribute often. This time we have to take the help of Cascading Style sheet. Here we should follow 2 steps:
1. define a class in css file
2. apply the class to the control

Lets discuss:
1.class hyp in css file:
.hyp
{
font-weight:bold;
display:run-in;
text-decoration:none;
cursor:pointer;
}
Here text-decoration is set to none therefore underline will not be shown.
2. using class to the control:
<asp:HyperLink ID="mylink" runat="server" CssClass="hyp" NavigateUrl="mypage.aspx">
Go to my page
</asp:HyperLink>

Here we see that css class is set to the control but one thing must be done while using the css class. Css file must be linked to the page in head section. Here is that code

<link href="default.css" type="text/css" rel="Stylesheet"/>

I think this will be helpful.

thanks.
Masud (15.7.9)

Formatting data in Gridview cell

This is an important thing u need when working with grid-view. Suppose u want to format the numerical data in currency form or date form then you have to do a little trick.
Suppose your column name is
"Amount" should be shown as currency (ex: $100)
"PaymentDate" should be shown as date (ex:7/12/2009), generally SQL 2005 will show it as (7/12/2009 12.00 AM) which is a bad format.

so lets check it out. Suppose we are using TemplatedField in GridView and as field we are using labels ..so the code like this.

<asp:GridView ID="TestGV" runat="server">
<Columns>
<asp:TemplatedField>
<ItemTemplate>
<asp:Label ID="CurrencyLabel" runat="server" Text='<%#String.Format("{0:c}",Eval("Amount"))%>' > </asp:Label>
</ItemTemplate>
</asp:TemplatedField>
<asp:TemplatedField>
<ItemTemplate>
<asp:Label ID="PaymentDateLabel" runat="server" Text='<%#String.Format("{0:d}",Eval("PaymentDate"))%>' > </asp:Label>
</ItemTemplate>
</asp:TemplatedField>
</Columns>
</asp:GridView>

So this is the required code for converting into the desired format of data.

thanks.
Masud (15.7.9)

Monday, July 13, 2009

I could not sleep tonight (14.7.9)

Creation of this blog has an eventual cause. Tonight 14.7.9. I could not sleep for a while. A few days ago (7.6.09) I had Appendix operation and after that operation I found myself very helpless and probably I got mentally sick to some extent. Often I became afraid of becoming great sick and losing something valuable part of my body.

Let me tell u a very dangerous event during my operation.I had local anesthesia during my operation and I was injected in the Spinal chord and I found my better half just dead during my operation. My operation was over but I could not make any sense of my better half for 6+ hours and first 3-4 hours I was lying in post-op room without the presence of my family members. That was tragic matter as I found none and I felt if I lose my better half.That fear still remains in me. I have become mentally weak about my physical condition.

I know some tips...people get scared when something they cant explain. That time one should breathe properly so that fresh oxygen can enters the body and the brain can work properly and empowers one to think logically...but this I cant follow all the time. I should regain this strongly....nothing to fear. Allah is always with us. Tonight I worked for company up to 3.00 am ...then went to sleep but could not sleep and started blogging. I blogged in my professional blog http://masudcseku.blogspot.com. However this blog is going to be my personal blog.

thanks.
Masud(14.7.9)

.

I could not sleep tonight (14.7.9)

Creation of this blog has an eventual cause. Tonight 14.7.9. I could not sleep for a while. A few days ago (7.6.09) I had Appendix operation and after that operation I found myself very helpless and probably I got mentally sick to some extent. Often I became afraid of becoming great sick and losing something valuable part of my body.

Let me tell u a very dangerous event during my operation.I had local anesthesia during my operation and I was injected in the Spinal chord and I found my better half just dead during my operation. My operation was over but I could not make any sense of my better half for 6+ hours and first 3-4 hours I was lying in post-op room without the presence of my family members. That was tragic matter as I found none and I felt if I lose my better half.That fear still remains in me. I have become mentally weak about my physical condition.

I know some tips...people get scared when something they cant explain. That time one should breathe properly so that fresh oxygen can enters the body and the brain can work properly and empowers one to think logically...but this I cant follow all the time. I should regain this strongly....nothing to fear. Allah is always with us. Tonight I worked for company up to 3.00 am ...then went to sleep but could not sleep and started blogging. I blogged in my professional blog http://masudcseku.blogspot.com. However this blog is going to be my personal blog.

thanks.
Masud(14.7.9)

.

Adding client side (javascript) function to ASP.NET server contorl

This is critical things I was looking for many days..that is how to add javascript event to the server side ASP.NET control. This is very needed often but I could not manage it for a long time. However, this time I got some. We have to follow 2 steps.
1. Define client side function
2. Add function/event to the control.

1. Define the client side function
Suppose a text box...I want to limit total chars in it is 100. If we want to use javascript for this then code will be like this. This code will be scripted in the .aspx page...that means will be in the script tag in the main page.

function allowInsert(total) /*here total=100*/
{
var mybox=document.getElementById("mytextbox"); /* server control ID="mytextbox"*/
var text=mybox.value;
var len=text.length;
int mylen=0;
mylen=parseInt(len);

/*testing condition*/
if(mylen< total)return true;
else return false;
}

2. Adding function to the server control
In Page_Load event of .aspx.cs (code-behind) page we have to add the following line
Let mytextbox is the ID of the control.So....
mytextbox.Attributes.Add("onkeyup","javascript:return allowInsert(100)");

Now when a char will be entered in mytextbox then each time this function will be checked
whether it is allowed or not.

thanks.
Masud(14.7.9)



Use of stored procedure in a table data show

Most of us heard about the stored procedure. I also heard about it but I could not know how to use it. However stored procedure is very helpful for the big queries which is tough to build every time we use. So centrally a function/procedure is stored and called when we need that certain actions it perform....so this is called stored procedure. Here are some tips about stored procedure.

1.create a stored procedure:
How to build a stored procedure: Suppose u want to show info of the students of CSE discipline.
So the code is:

CREATE procedure dbo.showAllInfo
(
/*parameter list*/
@discipline varchar(50)

)
as
select * from Student where discipline=@discipline

EXEC dbo.showAllInfo

Now save the document using any name and execute this sql in VS or any other tools that has access to DB. When it is executed successfully then you will see a new entry called showAllInfo in the stored procedure folder of your DB.

2. Use of stored procedure
Here is how to use stored procedure. Lets take a glance on it. Let we are using SqlConnection object.

try
{
SqlConnection conn=new SqlConnection(ConfigurationManager.ConnectionStrings["MASUDDBConnectionString"].ConnectionString);
conn.open();
SqlCommand comm=new SqlCommand();
comm.Connection=conn;
comm.CommandText="showAllInfo";
comm.CommandType=CommandType.StoredProcedure;
comm.Parameters.AddWithValue("discipline","ParamValue"); /*paramvalue=CSE*/

SqlDataAdapter sda=new SqlDataAdapter(comm);
DataTable dt=new DataTable();
sda.Fill(dt);

/*databinding*/
SomeGridView.dataSource=dt;
SomeGridView.dataBind();

/*results rendered successfully*/

/*closing conn*/
sda.Dispose();
conn.Close();

}
catch(Exception exc)
{
}


Updating an entry of table using mygeneration tool

To change an entry of the table is also interesting and easy. You don't need to write an update query or even think of creating and closing a sql connection...even no chance to hurt a primary key also. Just follow these steps. Lets consider the Admin table. Suppose Admin wants to change the password having AdminID=5. So here lies the following code:

try
{
Admin admin=new Admin();
admin.ConnectionString=ConfigurationManager.ConnectionStrings["MASUDDBConnectionString"].
ConnectionString;
if(admin.LoadByPrimaryKey(5))
{
admin.AdminPassword="new password";
admin.Save();
/*entry updated successfully*/
}


}
catch(Exception exc)
{
/*error notification*/
}

So this is the easiest way to update a table entry as I believe. what do you think about this?

thanks
Masud(14.7.9)



How to show a table data with mygeneration business object?

As from the last blog we came to learn about how to add a new entry in the table without any touch to the table. Lets consider the admin table. So we have got the following things already in hand:
1. _Admin.cs (Abstract class)
2. Admin.cs (Extension of _Admin)
3. Admin.sql (All doodad's stored procedures)

And it is expected we have already added some rows to the table. Now comes how we can show the value from the table. This is the most interesting part of mygeneration tool. You have 2 options
a. show values of one item
b. show values of all items in table

show values of one item:

This is quite easy. Here is the code following.
Suppose AdminID of Admin table is 5. So the following code shows Admin's info having AdminID=5.

try
{
Admin admin=new Admin();
admin.ConnectionString=ConfiguraionManager.ConnectionStrings["MASUDDBConnectionString"].
ConnectionString;
if(admin.LoadByPrimaryKey(5))
{
/*Loaded the single instance*/

Response.write("Email:"+admin.AdminEmail+" Admin Pass:"+admin.AdminPassword+"
");

}

}
catch(Exception exc)
{}

show values for all items:

try
{
--------
same as previous
--------
if(admin.LoadByAll())
{
/*All instances loaded*/
admin.Rewind(); /*setting pointer to 0th row*/
do
{
Response.write("Email:"+admin.AdminEmail+" Admin Pass:"+admin.AdminPassword+"
");

}while(admin.MoveNext());


}
}
catch(Exception exc)
{}

So these are the way to access rows in the table. I think it is quite interesting, isn't it?

thanks.
Masud (14.7.9)



Tuesday, July 7, 2009

Adding a new entry in tha table (using Mygeneration)

If you want to add a new entry in the database table then this topic is going to help you. Let us consider that we have a table in the database called Student and schema like this

table name: Student
Fields:
{
name varchar(50),
roll varchar(10),
cgpa float,
address varchar(50),
email varchar(50),
birthDate smalldatetime
}

During the creation of table two things must be done:
1. setting a column as an identity element with auto-increment 1
2. setting that column as the primary key.
Lets consider how this can be done. Suppose Admin is table
lets create the table using a sql query:

USE BIZNES
go
create table Admin
(
AdminID smallint IDENTITY,
AdminEmail varchar(50),
AdminPassword varchar(50),
Primary key(AdminID)
)
go
SET IDENTITY_INSERT Admin ON

Another Process:
Suppose you have created table using GUI of SQL server 200x and you want add that constraint.Use the following steps:
a. Right click on table and do to table definition
b. Select the desired column and set
Identity=Yes
Autoincrement=1
Not for replication=Yes
c. Set this column as primary key


where BIZNES is the database name. So if you design a table like this using a query
the created table is perfectly suitable for input to mygeneration tool. So please design
your own table setting identity and primary key and generate business objects like _Admin.cs file or other stored procedures.

We have already learned how to create _Student.cs or Student.cs file. If you are not familiar with this please follow my previous blogs about mygeneration tool. So now a small snippet of code is needed for you to add an entry in the database. That is:

Student std=new Student();
std.ConnectionString=ConfigurationManager.ConnectionStrings["MASUDDB
ConnectionString"
].ConnectionString;
std.AddNew();
std.name="Masud";
std.roll="040201";
std.cgpa=4.63;
std.address="Farmgate,Dhaka";
std.email="test@gmail.com";
std.birthDate="25/04/1998";
std.Save();

This is how a new row or entry is created in database. You don't need an insert query for getting an entry. You can handle all this in a fine manner...isn't it?

thanks.
Masud
7.7.9

Thursday, July 2, 2009

Steps for working with Mygeneration tools

After installing the software you will have to follow the following steps to make it completely workable.
1. Create your tables (as per your database design)
2. Create abstract classes
3. Extend the abstract classes
4. Store them in App_Code folder in your website
5. Executing the dooDad's stored procedures

Now lets come step by step
1. Table creation
I think people already know this how to create a table in the a database. Let me remind one important thing those who are working SQL Server 2005 or higher. While connecting to the database then:
Server: (local)\sqlexpress
Here we often write (local)/sqlexpress and generally get an error number 40. Those who are suffering this problem it can be cure for them. Though it is expected people are acquainted with process of table creation however let me give a clear view.
a. Click Server Explorer from View
b. Find Data Connections
c. Data Connection>Create New SQL server database
d.Server: (local)\sqlexpress
e.
Now let database name Test..
f. Test>Tables>New Table
g. Generate different fields
h. Save the table

2. Create abstract class
When your expected tables are created then actually your interaction with database is really over. Now mygeneration tool will take care of all the things. So open mygeneration tool and follow the steps.
a.Open>Templates>C#>CSharp_SQL_BusinessObject
b. Execute
c. Now fill the following like these
Output File Path: C:/test folder/
Namespace: TestNamespace
Select a database:Test
Select Table: Maximus
Select Language: C# (default)
d. Press Ok
Now you will find an abstract class named Maximus.cs, but the class file in it named as
_Maximus. It will have following type of code

namespace TestNamespace
{
public class _Maximus
{
/* different codes*/

}

}


So rename the Maximus.cs to _Maximus.cs. And this is the abstract class file for you
which will be used for further database operations

3. Extend abstract class
This is very simple. Lets follow the steps
a. Create a Maximus.cs class file from VS
b. Now open the file and write the following code

public class Maximus: TestNamespace._Maximus
{


}
c. Now save the Maximus.cs file.

4. Store these files
Now an important thing is to store these files where. Follow these steps
a. Create/Open the App_Code folder in your website
b. Create two folder in it named DAL and BO
c. Now store _Maximus.cs in DAL
d. And store Maximus.cs in BO
e. As you storing these files in App_Code so these class files will be automatically complied.

5. Execute the stored procedure
a. Open Mygeneration tool
b. File>New>Mygeneration Project>Add template instance
A window will popup. Now insert the following info
name:test
Template: Microsoft SQL Server>d00Dads Stored Procedures
c. Now click Record Template input
Now another window will popup
d. Insert info like this
Output file path:C:/test/
Select a database: Test
Select table: Maximus
Press Button Ok. and return to previous window and also press Ok
e. You will discover test like
New Project >test
f. Now right click on test and select execure
Here you will find a black screen giving message that stored procedure created successfuly.
g. Now open C:/test. Here you will find a file Maximus.sql
h. Open this file using Mygeneration tool
i. Then execute from toolbar

Now your duty is finished. get relaxed and you can do all database works just calling Maximus class. Now from your website in any page you can create code like this:

Maximus maxOb=new Maximus();
maxOb.Name="Masud";
maxOb.Roll=040201;

where Name and Roll are fields of Maximus table you created. However thats all for today.
Next time I will be more specific using example.

thanks.
Masud(3.7.9)

Friday, June 26, 2009

My Generation Tools

Those people who want to create abstraction about database applications that means don't want to care about low level database application I have a nice suggestion for them----use mygeneration tool which can take care of all database operations. Those who are interested with this just visit the following link and download the softyware
http://www.mygenerationsoftware.com
I will continue how to use of mygeneration tool in next some blogs

thanks
Masud (26.06.09)

Saturday, June 20, 2009

How to send email from a website

This is a nice piece of task I get much pleasure. I think this is a very interesting task for a CSE student who is not yet recognized with the technique of sending an email. Let me state the process step by step. There are two sections:
a.Administrative part
b. Developer's part.

Administrative part:
For Administrative part you have to just set the configuration (shown above) in your web configuration (web.config) file. If you do it to the hosting company server's file then no need to think about other thing. But if you want to make local server (your computer) as the mail server then you have to do some other configuration:
1. Open Control Panel
2. Open Administrative tools
3. Select Internet Information Service (IIS)
4.Select Default SMTP>Properties
5. Click Access tab>Relay (Relay Restrictions)>Grant Access for 127.0.0.1

when you are done with this configuration you are ready to write the funtion for sending email. The required configuration is:

<!--Here Mailserver configuration-->
<system.net>
<mailSettings>
<smtp from="test@nochallenge.net">
<network host="localhost"
userName="test@company.net"
password="****"
port="25"
defaultCredentials="false"/>
</smtp>
</mailSettings>
</system.net>


Developer's Part:
As a developer you just have to write a function for sending email.
Here is the code


protected void SendingEMail()
{

string from="test@yahoo.com";
string to="test@gmail.com";
MailMessage msg=new MailMessage(from,to);
msg.Subject="This is test mail";
msg.Body="Please respond if you get this mail";
SmtpClient client=new SmtpClient("localhost");
client.Send(msg);
Response.write("Mail Sent successfully!");

}


thanks
Masud(26.06.09)


How to upload an Image to web server

In this blog I am going to discuss about how to upload an image in web server. Before you upload an image to the server at first you have to ensure that the web server gives you exact permission to upload the image. If permission is not set to true and you yourself are the web administrator here then you have to set that permission true by yourself. For that you have to use Plesk File Manager (or probably others) for granting permission.
Use the following steps:
1. Open Plesk file manager for web server (provided by Hosting company)
2. Login as administrator
3. Click edit/modify for a folder
4. For all users grant modify permission for the target folder you want to store in your image files.
5. Logout from the Plesk file Manager.

Now comes the user's task to do. He/she has small parts to do. Use the following steps.
1. Drag and drop FileUpload control from toolbox of visual studio. This control has a Browse button. Clicking this button you can select any file and path will be shown in the textbox of this control.
2. If you want to upload just image then you check file extension for images and allow to upload
3. Now look at the following snippet of code (C#).

protected void uploadImage()
{
try
{
string fileName=FileUpload1.FileName;
string serverPath=Server.MapPath("images/"); /*images is the folder in webserver you want to upload images */
if(FileUpload1.HasFile) /*already uploaded to server*/
{
FileUpload1.SaveAs(serverPath+fileName); /*image saved to web server folder*/

}
else StatusLabel.Text="No Image file selected";
}catch(Exception exc)
{
StatusLabel.Text=exc.Message;
}


}

Making alignment with table


<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td align="left">Masud</td>
<td align="left">Assad</td>
<td align="left">Mamun</td>
<td align="left">Sayed</td>
</tr>
<tr>
<td align="right">Shakila</td>
<td align="right">Shamima</td>
<td align="right">Shahnaz</td>
<td align="right">Tonni</td>
</tr>

<tr>
<td align="center">Grand father</td>
<td align="center">Grand Mother</td>
<td align="center">Father</td>
<td align="center">Mother</td>
</td>
</table>

Wednesday, June 17, 2009

Start design with table

If you want to start designing web page the start design with the table control. Nothing can be in a good shape without using table. During my university years, I spent a lot of time to discover that table is the key of all kind of design efficiently and with full control. Those who have little knowledge about HTML language they can easily realize my following code. Just start like this:

A Simple web page design:


<table>
<tr>
<td>First Column</td>
<td>Second Column</td>
<td>Third Colimn</td>
</tr>
</table>


This is a simple page design using a table which has three columns. Now each of these 3 columns can be further nested with other different controls like table, GridView, labels, buttons.....more and more.
However, just start with this ...you will be benifitted I am sure!

Thanks.
Masud (18.06.09)

Learn to design web form by coding

Those people are still designing the web pages based upon the design view of Visual studio I think I am suggesting those people to stop that jsut from now and start coding just from now. I was a design-view user of visual studio which made me just a fool with a tool. However, time passed and things changed. I started designing web pages using raw xhtml which made me comfortable with website designing and to be very frank this made faster in design and many things have become clearer of the mark-up language like xhtml. However, my later blogs will contain different tutorials and solutions of the problems I have faced during my job-life.

Thanks.
Masud (17.06.2009)