Monday, February 27, 2006

XPath in .Net

Hi, Recently, I was working on XML Parsing using ASP.Net. In this I have to AED (Add/edit/delete) Nodes as user enter data, I am comfortable with adding nodes as I have to create Element and just do... objXml.AppendChild(newchildnode) it works find, but when I have to delete which is more conditional and for me is not as simple to delete as adding new node... My XML is something like this <DEALS> <DEAL> <Products> <product>Product info</product> </Products> </DEAL> <DEAL> <Products> <product>Product info2</product> <product>Product info3</product> <product>Product info4</product> </Products> </DEAL> </DEALS> Now in this XML I have to delete the Product Info 3. One of my friends who has done it before suggest me to Iterate through each Deal and when my counter goes to node 2 just check and Loop (nested) for the products and if I found 2 item in the list delete that. I have the node Serial No for deal and product with me, infact thats the only data I have to delete the node as as many deals can have as many products as user enter in them... Secondly, I frequently getting error for the looping, error i got is Node I was delete is not a Child node of reference node. Than I look for Xpath and after searching and looking for xPath in W3C site I got this piece of code Dim file As String file = "C:\mydata.xml" Dim xmldoc As New XmlDocument xmldoc.Load(file) Dim node As XmlNode node = xmldoc.SelectSingleNode("//DEALS/DEAL[2]/Products/Product[2]") node.ParentNode.RemoveChild(node) xmldoc.Save(file) See the line node = xmldoc.SelectSingleNode("//DEALS/DEAL[2]/Products/Product[2]") It tells the Xml document object to naviagte to Second Deal in the Deals node and than goes to its product and Pick Second Product and than using node.ParentNode.RemoveChild(node) I go to node parent and remove "node" child from its list and save the Document again. Now I have deleted the XML node I want with just two line of code. Happy XMLing Sumit Gupta

Saturday, February 25, 2006

PHP and ASP.Net for Designer Studio

Hi, Lately, I have to work to make a T-Shirt designer Studio in two site, the difference is that two site were made in PHP and ASP.Net respectively. But the common this that comes as most difficult part in this is obviously designer studio itself. So, what exactly my problems are with studio, well both the language support Graphics with there own method and style, PHP provides a Extension to its platform called GD Library (yet another Good Open source Code) and ASP.Net has its well know System.Drawing Namespace to help me. With PHP Codes is very simple and sequential for me to write, just make a function call and it start creating Image, Quite ease and result are good. But when I start working on ASP.Net project, Image creation is much easier if you have idea on how to make bitmaps and know some theoritical knowledge about them, which I don't have but thanks to some good men work available on Internet, I am able to complete them. But whatever language you choose, you need to make the interface in FLASH, as I tried Javascript at first, but that was a sad story for me. Anyway more details on this will be posted soon. Sumit Gupta

Friday, February 24, 2006

Remember Me - A Common Mistake

Hi, Today I will be discussing common mistake I have seen new programmer does. You have observed often that there is a small Checkbox lying just below your Password field in most of the site. You often Check that box so that next time you visit that site you don't need to get yourself logged in again. I have seen programmer coding this with following Logic... 1) Check if User exists, If not raise an error. 2) If User exist but doesn't have its password match in database, raise an error. 3) if all goes well and User has selected that little checkbox Make a Cookie and Allow login process... to goes on. I guess that Logic is correct... Okay you are smart enough you get the error in the logic. Yes, While raising error Programmer often forget to check the Little "check box" called remember me... What if he hasn't select it, this means user doesn't want his information to be store on this computer even a login failure occurs. And if he doesn't select it you need to clear Cookie if already exist. That is what user indent most often. So, next time you program a Remember Me feature thing twice it is not just a matter of setting cookie, it is a Programming logic. Happy Coding Sumit Gupta

Tuesday, February 21, 2006

Talent Counts Nothing

I have been in Software industry for 2 years now, and this is what I feel. If you are "Talented" no one needs you. If you know how to solve problems and can do stuff that really doesn't matter, atleast this is what I feel. As employeer only need his company grow, no matter what way it grows. I have joined my company as "Web Developer" in PHP, But in last one year of so with my company, now I have been given a designation of "Project Manager". infact quite a while ago I was promoted to this designation. I have develop sites in ASP.Net on windows 2003 server, configure this server for few .Net related stuff, Configure IIS to host web services used in my ASP.Net application. Also, I am responsible for handling our In house Linux server, its configurations, installation etc. PHP, Perl ,ASP, ASP.Net are few languages I am currently working, not to mention HTML, Javascript , XML , CSS are basic for web development. A Web developer is nothing without these four things. Still, I am not the best in my company, Still I lack behind to many who are only able to develop application using other's code or Open Source Code, which i am not capable of logic. My biggest weakness is I am not able to find codes other can find on "Google". I only thing and write logics for them, only few time I get codes from google or yahoo or forums. To become a Successfully Developer this is very weak point that you cannot search free codes. Well I guess I should Start using open sources code, and become a Member of Proud Association called CAPPA ( Copy And Paste Programmer Association), because this is what Matter at the end. Sad story ends here..:o) Sumit Gupta

Thursday, February 16, 2006

How to Check for Date Format using Javascript

One Small Example of how to validate a Input box content against a given mask using Javascript. For this example I have picked up "date" as our input for validation... Code Goes something like this... var tmpdate= document.getElementById("passport_expire_date").value; //Pick the Field Value to Validation var rgdate= new RegExp("[0-9]{2}/[0-9]{2}/[0-9]{4}"); //we need to validation date in mm-dd-yyyy format b=rgdate.test(tmpdate); if (!b) { alert("Please enter valid Passport expire date"); document.getElementById("passport_expire_date").focus(); return false; } tmpdate=tmpdate.split("/"); var mydate= new Date; if ( 1*tmpdate[0]>12 || 1*tmpdate[0]<1 || 1*tmpdate[1]>31 || 1*tmpdate[1]<1 || 1*tmpdate[2]>2100 || 1*tmpdate[2]<2005) //Check against the Validate Date, this piece can expand to validate against Leap year and more, but for me just a format is enough. { alert("Please enter valid Passport expire date"); document.getElementById("passport_expire_date").focus(); return false; } mydate.setDate(tmpdate[1]); mydate.setMonth((1 * tmpdate[0] )- 1); mydate.setFullYear(tmpdate[2]); var today= new Date; if (today >= mydate) { alert("Your Passport is expired!!!"); document.getElementById("passport_expire_date").focus(); return false; } I hope you all enjoy this piece of code in your web form... Sumit Gupta

Saturday, February 11, 2006

ASP.Net : Who am I?

I often require to know the script name currently executing to display certain features depending on page. For this I use this code for detecting the script name of the page that is executing .... Dim str As String str = Request.ServerVariables("SCRIPT_NAME") Dim allname() As String allname = str.Split("/") If allname(allname.GetUpperBound(0)) = "register.aspx" Then LoginBox1.Visible = False End If Run this code in Forms Page Load event to display controls you need to display or not... -Sumit Gupta

Tuesday, February 07, 2006

Today my friend celebrate my brithday..

Today my friend Rohit wishes my happy birthday, best I can imagine from my friends... he is currently in US and mail me this... happy birday 2 u golu molu dost achhey dost ek dusre ka birday ni bhulte golu molu dekh main ni bhula dost happy birday 2 u golu molu dost happy happy birday 2 u very very very happy happy happy birday mere dost bhagwan teri har muraad puri kare iss baar happy happy birday mere dost happy birday dost...tujhe dher saare paise...dher saara pyaar aur jo tu chahey wo dher saara miley iss happy birday ko happy birday mere dost yar very very gud vaala happy happy vala birday dost yar kitni baar bolun ab thak gaya thoda fir bhi le aur le happy birday mere achhey dost aur bhi le happy birday bhagwan aapko sukh shanti aur saphalta de sada sada khush rakhey tujhe mere achhey achhey dost happy happy happy birday chal ab last time aaj ke liye WISHING YOU A GREAT GREAT HAPPY N PROSPEROUS HAPPY BIRTHDAY I am so happy to recieve this mail, My friend i cannot explain in words how much precise this mail is for me. I wish i can celebrate my birthday with you... thanks a lot Sumit Gupta

Sunday, February 05, 2006

Chart Control for ASP.Net

For my current project I need to create charts and graphs, I know how to use Graphics class in ASP.Net and know few techniques to Create graphs as well. But, still as usual I look for free codes available for the same. I search and very quickly find my problems solution... http://carlosag.net/Tools/WebChart/Default.aspx A Free control for ASP.Net Charting requirement, It gives fair bit of customization as well. after testing it I said to myself, why waste time when I have ready to use solution without paying any thing to anyone. So, I just start using it. Take a look and decide your self. Good, easy to use, Bar graphs, pie chart creator control. Have your stats come to you in graphical format now... - Sumit Gupta

Friday, February 03, 2006

Shopping Carts: X-Cart and its template engine

Hi, As I start working on my X-Cart modification project, I learn few things. One of the most important thing among other is How a bad planning change the Good design patterns. X-Cart uses Smarty for Template handling. Smarty as you might know is a Template engine by PHP itself (http://smarty.php.net). It is based on concept to make Business Logic seperate from Display Interface. If you see ASP.Net does the same in almost all respect. But X-cart implementation to smarty is very unique in its kind. I don't know if they really required that complex file structure for their code. If I have to change the page logic I do need to change the Template files in some cases. And to my experience in Shopping carts with the features that X-Cart provide it can de done with less complexity than X-Cart has. When I first take a look at Oscommerce, I thought it is not perfect yet, But when I compare it to X-Cart (paid software) with free software like OsCommerce. I thought Oscommerce has much better implementation. Especially with its Template engines module you can easily change design in Oscommerce, But not in X-Cart. Anyways Both are Good software in view point of End Users. But If you are really looking for software that you want to customize please go with OsCommerce. Bye for now, I have to test Jaws Framework now, lets hope some good codes from them. Sumit Gupta