Sandeep & Vicky’s Archive » Programming

Archive for the ‘Programming’ Category

Hi Guys,

I was working on mysms component today. Hats off to the person who made this component. I had installed jom-social also on the same site. The link is here : http://m4msakec.com/milenge.

The default process of mysms component is that it lists all the joomla users in the administrator section and from there we first need to enable the users to send sms and then assign them the credits. Only after that users can send sms from the front end. I wanted a small modification in this, the requirement was that whenever a user registers, he should by default be able to send sms and should get a default credit of 100 SMS.

I tried editing the mysms.backend.php file but it did not work out…..spent almost 2 hrs for this. Then I just saw the database tables of mysms  component and realized that mysms was just storing the users credit and their ability to send sms in one table .i.e. mysms_joomlauser.

I thought of making an entry into this table at the time of registration itself….and finally concluded that changing the code of the file that takes care of user registration in joomla will help me out. The file was user.php (JUser class)  in the directory libraries/joomla/user.

I just added the following code and a function in this file and things worked out perfectly fine….just as the way I wanted

Code : in the function save()

function save( $updateOnly = false )
{
// purged code of functionsave()

// registering as an sms sender —-added by vicky
$sql = “INSERT INTO #__mysms_joomlauser VALUES( 0, $this->id, ”,”,1, 100 )”;
$this->ExecuteSql( $sql );


        //purged code of functionsave()
}
Just after this when I registered a new user it gave me an error saying undefined function: JUser:Executesql()…….

and just three lines added more to the code and that was it………The function that I wrote for Juseris as follows

    function ExecuteSql($query)
{
$db =& JFactory::getDBO();

$db->setQuery($query);
$result = $db->query();

}

If you are trying to do the same then just donload this user.php and replace it in your site/libraries/joomla/user directory

Hope this helps others too….Please comment if it does

Hey Guys,

This is cool. The following code does a very simple and very important work for us. In all the programming languages, we follow a pattern of using capital letters to to differentiate between words while writing classes or making UI pages .i.e. instead of creating a class like class addnewstudent, we prefer class AddNewStudent. Now this can be easily understood by a programmer, but what abt a layman??????? The following code makes it easier for a layman and converts such strings into human readable format

Code

private string MakeStringReadable(string source)
{
StringBuilder sb = new StringBuilder();

char last = char.MinValue;
foreach (char c in source)
{
if (char.IsLower(last) &&
char.IsUpper(c))
{ sb.Append(‘ ‘); }
sb.Append(c);
last = c;
}
return sb.ToString();
}

Hi,

The following code connects to an access database “multilingual.mdb” located in the default folder of the java code. It does not requires to create a dsn for the same

CODE

try
{
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
String myDB = “jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=multilingual.mdb”;
Connection c = DriverManager.getConnection(myDB,”",”");

Statement s=c.createStatement();

ResultSet rss=s.executeQuery(“select naam from table1 where id=1″);

rss.next();
String st=rss.getString(1);

System.out.println(“string=”+st);
}
catch (Exception ex)

{
ex.printStackTrace();
}

Hi People, The following is my analysis on the Pricing and Promotion strategies of Sun Microsystems.

Pricing Strategy followed by Sun Microsystems: Java

Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems’ Java platform.

Java is an Open Source Language .i.e. One does not have to Pay Sun Microsystems for downloading the Source code of Java. But then the Questions is: How does Sun Microsystems generate revenue from Java?

In 1996, Sun created Java and the terms under which it is distributed. Since then, the Java Community Process (JCP) has emerged, allowing companies to participate in shaping language changes, but the ownership of trademarks, licensing agreements, branding, and other fundamental product issues remains unchanged. One is reminded of this fact every time the Sun MicrosystemsTM trademark appears alongside the Java coffee cup logo, or when one is greeted with the message “brought to you by Sun Microsystems” at www.java.com. For anyone to use the Java-compatible logo on a product requires verification against the test compatibility kit (TCK), for which one has to enter into negotiations with Sun. Java, the technology, the trademark, and the language, are owned by Sun.

The current licensing agreements for Java generate revenue for Sun in two ways; one is through direct fees to its licensees, and the other is through indirect revenue generated off the back end of Java’s success.

Besides the above Java also generates revenue by conducting certificate programs and certifications exams like SCJP, SCJD, etc. Clearing these examinations is just like getting a degree which shows that the degree holder has a good knowledge of Java and these certifications are very important for an IT Personnel’s CV. Sun Microsystems charges around 7200 INR for these examinations

When asked how much income is generated from Java, Jonathan Schwartz, CEO of Sun, replied, “about $13 billion.”

Conclusion

Thus Sun Microsystems have not priced their actual product, but they have priced the services that people would require after using their product.

The reason Sun Microsystems could do this is that there a very few competitors in the market and in spite of the competition, Java is the best among them.

Promotion Strategy followed by Sun Microsystems: Java

Promotion through developers

Prior to java there were many programming languages for different Operating systems, Examples include C, C++, FoxPro, Visual Basic, etc. But there was one major common problem with all these languages; these languages were Platform Dependent .i.e. They had to be compiled differently on different Operating Systems .i.e. If a developer develops a code in C language and compiles the code on say Windows Operating System, then that code would not work on Linux Operating system, thus increasing the burden of the developer to compile the code again for Linux and Other Operating System.

Thus there was a great demand for a Programming Language that is Platform independent during the 1990’s. Sun Microsystems soon captured this Niche Segment of the Developers through its Platform Independent Language Java. On top of that the source code of Java was made open source to the developers all over the world. Any developer could download the source code from the website of Sun and use the code free of cost. Sun Microsystems used the fastest means of distribution .i.e. the Internet as their distribution Channel.

The main idea behind making the source code open source was to push the brand to the developers. Sun Microsystems was aware of the fact that the developers will in turn push the brand to many customers and enterprises, thus creating a cumulative effect, and Sun would earn through Licensing and Certifications. That is what Sun Microsystems is doing these days.

Sun Microsystems has also started a Developer network (SDN) to solve the problem faced by the developers that are using Java. This is to give their target audience a better service and support.

Promotion through software applications and Web servers

Soon after the launch of Java, Sun Microsystems also launched its Internet surfing browser Netscape Navigator which was developed totally on the Java Programming language. This move was taken to show the developers the extent to which Java can be used and how developers can add new features in their software using Java.

Sun Microsystems also developed a Web server called Apache Tomcat server to handle web requests in the form of HTTP. This also facilitated the promotion of Java, as the server was built on the Java Platform. (Please note that: A web server is a computer with equipped softwares where the web sites are hosted).

Again, all these facilitated pushing the Java brand to the Developers which was Sun Microsystems’ Main target.

Publicity

Soon after the launch, the Java source code became very popular among the developers. Many people started discussion forums, blogs & eLearning websites on Java Programming on the Internet. Thus, Java gained a lot of Publicity through its developer network and soon became very popular. Also, the increasing popularity of Java triggered the publishing of articles on Java in the Newspaper and online News portals like Forbes Newsletter, etc.

Conclusion

Thus, Sun Microsystems targeted only the Developer network and pushed the brand to Developers who in turn pushed it to the rest of the world.

I was trying to set default focus to a textfield which was placed in a joptionpane, but it wast working with the following code

cvendor.requestFocus();

whereas the same code worked perfectly when the textfield was placed in a jpanel. On research i found that the default focus in a joptionpane is always on the OK button and it cannot be changed statically, it can only b changed during runtime using the Runnable interface. Here is the code that did the trick

javax.swing.SwingUtilities.invokeLater(new Runnable() {//<—–add
public void run() { cvendor.requestFocus(); }});//<—-add

nn=JOptionPane.showConfirmDialog(null,Jop,”Please enter details”,JOptionPane.CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE);

kool na………..

30
Sep

Accessing windows registry using java

   Posted by: admin

Hi guys,

You can edit, change or delete any windows registry key values using java.

All you need to do is download d JNI interface for Windows registry from the following link

Click  JNI Registry to download the package

This package has many classes through which we can access the registry.

27
Sep

How to convert String to double in ASP.Net

   Posted by: admin

Hi guys,

Converting a string to integer or double in .Net is very much similar to that in java.

Here is the code

double x=Double.Parse(“”+100.1);

Output

x=100.1

Hi Folks,

This is really interesting about flash. It can just read, but never write. We can read XML files in flash as well as data can be read, but we cannot write using flash. Due, to security reason, We cannot write anything into any file on neither the local file system nor the server file system using flash. Flash is not authorized to do so. Same is the case with databases. Flash cannot connect to databases as well. The problem seems to be a very serious one, but isnt. There is a very simple solution to this

Solution

Just use any scripting language like ASP, PHP, ASPX, etc. All you need to do is pass the variables that you wanna save to any scripting page and that scripting page would do the needful of connecting to database, or writing into any file. The action script code and the asp (i used asp as my scripting language) code for doing this is as follows

Flash Action Script Code

import mx.controls.*;

var send_lv:LoadVars = new LoadVars();
// define the component instances on the Stage.
var uname:TextInput;
var email:TextInput;
var phone:TextInput;
var address:TextArea;
var btnReset:Button;

var name_label:Label;
var email_label:Label;
var url_label:Label;
var comments_label:Label;

//set color of labels
name_label.setStyle(“color”, “0xFFFFFF”);
email_label.setStyle(“color”, “0xFFFFFF”);
url_label.setStyle(“color”, “0xFFFFFF”);
comments_label.setStyle(“color”, “0xFFFFFF”);

// set the tabbing order for the components
this.uname.tabIndex = 1;
this.email.tabIndex = 2;
this.phone.tabIndex = 3;
this.address.tabIndex = 4;
this.btnReset.tabIndex = 5;

Selection.setFocus(uname);
// when the clear button is clicked, set the form fields to empty strings.
var clearBtnListener:Object = new Object();
clearBtnListener.click = function(evt:Object) {
uname.text = “”;
email.text = “”;
phone.text = “”;
address.text = “”;
};
this.btnReset.addEventListener(“click”, clearBtnListener);

// when the next button is clicked, send the form values to the server using a LoadVars object.
var nextBtnListner:Object = new Object();
nextBtnListner.click = function(evt:Object) {
// if the name is blank, display an error message using the Alert component.
if (uname.text.length == 0) {
Alert.show(“Please enter your Name.”, “Error”, Alert.OK);
Selection.setFocus(uname);
return false;
}
//if email
if (email.text.length == 0) {
Alert.show(“Please enter your Email.”, “Error”, Alert.OK);
Selection.setFocus(email);
return false;
}
// if phone
if (phone.text.length == 0) {
Alert.show(“Please enter your Contact No.”, “Error”, Alert.OK);
Selection.setFocus(phone);
return false;
}
// make sure the comments_ta TextArea instance isn’t blank.
if (address.text.length == 0) {
Alert.show(“Please enter your Address.”, “Error”, Alert.OK);
Selection.setFocus(address);
return false;
}

// if all the required fields have been filled in, create a LoadVars object instance and populate it.

send_lv.name = uname.text;
send_lv.email = email.text;
send_lv.phone = phone.text;
send_lv.address = address.text;

gotoAndStop(5);

};
this.btnNext.addEventListener(“click”, nextBtnListner);

ASP File code to insert records(data passed by flash) into a database

<%

Dim conn,rs
set conn=server.CreateObject(“ADODB.Connection”)

conn.Open “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” & Server.mappath(“opinionpoll.mdb”)
set rs=server.createobject(“ADODB.recordset”)
rs.open “opinion”,conn,0,2

rs.addnew
rs.Fields(“name”) = request.form(“name”)
rs.Fields(“email”) = request.form(“email”)
rs.Fields(“phone”) = request.form(“phone”)
rs.Fields(“address”) = request.form(“address”)
rs.Fields(“Q1″) = request.form(“q1″)
rs.Fields(“Q2″) = request.form(“q2″)
rs.Fields(“Q4″) = request.form(“q4″)
rs.Fields(“Q5″) = request.form(“q5″)
rs.Fields(“Q3″) = request.form(“q3″)
rs.update
rs.close()

conn.Close
Response.Write(“Done”)
%>

Hi guys,

I have  working with java for the past two years and never tried building application in.Net. Recently, we had a project which was to be done in .Net. We then just learned visual studio and found a very gr8 feature in it.

J#

.Net applications can be written in the java syntax by using J#.

It really kool…..all our database connectivity codes, server side codes which were written in java were easily transformed into a .Net application.

We can have .java extension files as well in our .Net web site.

That is the language independence feature of .Net….which makes it more user friendly and will obviously attract more developers to switch to .Net.

But still java rules

24
Aug

Commit and rollback in ASP.NET

   Posted by: admin

Database transactions can be committed and rolled back using front end tools like .Net or java. Here is a simple code to do so in c#.net

private void SQLCommandTransaction(string sServer, string sDB)
{
SqlConnection cn = new SqlConnection(“SERVER=” + sServer
+ “;INTEGRATED SECURITY=True;DATABASE=” + sDB);
SqlCommand cmd = new SqlCommand();
SqlTransaction trans;
// Start a local transaction

cn.Open();
trans = cn.BeginTransaction();
cmd.Connection = cn;
cmd.Transaction = trans;
try
{
// Insert a row transaction
cmd.CommandText =
“INSERT INTO Department VALUES(100, ‘Transaction 100′)”;
cmd.ExecuteNonQuery();
// This will result in an error
cmd.CommandText =
“INSERT INTO Department VALUES(100, ‘Transaction 101′)”;
cmd.ExecuteNonQuery();
trans.Commit();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
trans.Rollback();
}
finally
{
cn.Close();
}
}

Related Posts with Thumbnails