Subhash Sharma

Subhash Sharma
Subhash Sharma

This is Subhash Sharma(Software Engineer) Blog

Welcome to this blog and find every solution.............

Search This Blog

Software Engineer(Subhash Sharma)

Software Engineer(Subhash Sharma)
Software Engineer

Thursday, January 27, 2011

Sorting in array wihout using sort method

public static int[] SortArray(int[] characters, string Order)
{
if (Order == "Desc")
{
for (int i = 0; i < characters.Length; i++) { for (int j = i; j < characters.Length; j++) { if ((int)characters[j] > (int)characters[i])
{
int tempChar = characters[i];
characters[i] = characters[j];
characters[j] = tempChar;
}
}
}
}
else
{
for (int i = 0; i < characters.Length; i++)
{
for (int j = i; j < characters.Length; j++)
{
if ((int)characters[j] < (int)characters[i])
{
int tempChar = characters[i];
characters[i] = characters[j];
characters[j] = tempChar;
}
}
}
}
return characters;
}



///calling function

int[] characters = new int[] { 1,9,2,10,5 };
characters = Program.SortArray(characters, "Asc");
string str = "";
for (int i = 0; i < characters.Length; i++)
{
str += characters[i].ToString();
}
Console.WriteLine(str);
Console.ReadLine();

Tuesday, January 25, 2011

what is axapta

Microsoft Dynamics Axapta is a customizable, multiple language ,multiple currency enterprise resources planning or ERP solution. Microsoft Dynamics AX is completely integrated solution. It’s a web enabled and support Microsoft SQL Server and Oracle with customizable source code. You can modify the solution however and whenever you want.

Difference Between Axapta and Navision

Axapta & Navison, both are the application of Microsoft Dynamics.

Axapta uses X++ as programming language & Navison uses CSL.

There are many differences & one such difference is that Axapta has a payroll but Nav doesnot have payroll functionality.

Thursday, January 20, 2011

webservices Bind GridView

//connectionStrings>
add name="Master" connectionString="Data Source=SF-74\SQLEXPRESS;user id=;pwd=;Trusted_Connection=true" />

/connectionStrings>

//use some NameSpaces

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Xml;
using System.Data;

[WebMethod]
public XmlDocument GetDataFromDB()
{
string errorMessage = "";
XmlDocument myDatas = new XmlDocument();
//Connection string is stored in the web.config file as an appSetting
string connectionString = ConfigurationManager.ConnectionStrings["Master"].ConnectionString;
SqlConnection dbConnection = null;
// Open a connection to the database
try
{
dbConnection = new SqlConnection(connectionString);
dbConnection.Open();
}
catch (Exception ex)
{
errorMessage = ex.Message;
}
if (errorMessage == "")
{
// Build an insert command
string SQL = "select * From sa";
SqlCommand GetCustomerCmd = new SqlCommand(SQL, dbConnection);

try
{
SqlDataAdapter custDA = new SqlDataAdapter();
custDA.SelectCommand = GetCustomerCmd;
DataSet custDS = new DataSet();
custDA.Fill(custDS, "ProfileContact");
myDatas.LoadXml(custDS.GetXml());
dbConnection.Close();

}
catch (System.Exception ex)
{
errorMessage = ex.Message;

}
finally
{
dbConnection.Dispose();
}
}
return myDatas;
}


////////////aspx.cs

localhost.WebService2 proxy = new WebApplication1.localhost.WebService2();

protected void Page_Load(object sender, EventArgs e)
{
XmlDocument myServiceDoc = new XmlDocument();
System.Xml.XmlNode neNode;
//Adding the resulting XML from WebMethod to a user created XmlNode
neNode = proxy.GetDataFromDB();
//Creating a Dataset
DataSet myDataSet = new DataSet();
//The XmlNode is added to a byte[]
byte[] buf = System.Text.ASCIIEncoding.ASCII.GetBytes(neNode.OuterXml);
System.IO.MemoryStream ms = new System.IO.MemoryStream(buf);
//The XML is readed from the MemoryStream
myDataSet.ReadXml(ms);

GridView1.DataSource = myDataSet.Tables[0];
GridView1.DataBind();

//GridView1.DataSource = proxy.GetDataFromDB();
//GridView1.DataBind();

}

Method Overloading in WebServices

When u overload a method than replace
//[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

[WebServiceBinding(ConformsTo = WsiProfiles.None)]


[WebMethod]
public int Add(int i, int j)
{
return i + j;
}
[WebMethod(MessageName = "Add2")]
public int Add(int i, int j, int k)
{
return i + j + k;
}

when u overload a method u hve to give the Mesaage name that would be unique from ur method name...

aspx.cs page

localhost.WebService1 proxy = new WebApplication1.localhost.WebService1();
proxy.Add(5,4,8);

Tuesday, January 18, 2011

HttpHandler vs HttpModule

//This link will help for read about HttpHandler and HttpModule

http://geekswithblogs.net/flanakin/articles/ModuleHandlerIntro.aspx

Introduction

All requests to IIS are handled through Internet Server Application Programming Interface (ISAPI) extensions. ASP.NET has its own filter to ensure pages are processed appropriately. By default, the ASP.NET ISAPI filter (aspnet_isapi.dll) only handles ASPX, ASMX, and all other non-display file formats used by .NET and Visual Studio. However, this filter can be registered with other extensions in order to handle requests to those file types, too, but that will be covered later.

Every request flows through a number of HTTP modules, which cover various areas of the application (i.e. authentication and session intofmation). After passing through each module, the request is assigned to a single HTTP handler, which determines how the system will respond to the request. Upon completion of the request handler, the response flows back through the HTTP modules to the user.


HTTP Module

HTTP modules are executed before and after the handler and provide a method for interacting with the request. Custom modules must implement the System.Web.IHttpModule interface. Modules are typically synchronized with events of the System.Web.IHttpModule class (implemented within the Global.asax.cs or .vb file). The following consists of a list of events that should be considered when implementing your module:

BeginRequest
AuthenticateRequest
AuthorizeRequest
ResolveRequestCache
AcquireRequestState
PreRequestHandlerExecute
PostRequestHandlerExecute
ReleaseRequestState
UpdateRequestCache
EndRequest
PreSendRequestHeaders*
PreSendRequestContent*
Error*
The events identified by an asterisk (*) can occur at any time within the request; all others are listed in their calling order.

HTTP Handlers

HTTP handlers proces the request and are generally responsible for initiating necessary business logic tied to the request. Custom handlers must implement the System.Web.IHttpHandler interface. Additionally, a handler factory can be created which will analyze a request to determine what HTTP handler is appropriate. Custom handler factories implement the System.Web.IHttpHandlerFactory interface.

Dataset- Filter Row Through DefaultView

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["SchoolsConnectionString"].ConnectionString);
DataSet ds = new DataSet();
SqlDataAdapter adp = new SqlDataAdapter("select * from students", con);
Dataset ds = new DataSet();
adp.Fill(ds);
string message;
ds.Tables[0].DefaultView.RowFilter = "Name='Subhash'";
if (ds.Tables[0].DefaultView.Count != 0)
{
message = ds.Tables[0].DefaultView[0].Row["LastName"].ToString();
}
else
{
message = "";
}

Log4Net(for Making logger file)

//This is the link where you can read about log4Net
//open source provide by Microsoft

http://www.codeproject.com/KB/dotnet/Log4net_Tutorial.aspx
http://www.beefycode.com/post/Log4Net-Tutorial-pt-1-Getting-Started.aspx

http://shiman.wordpress.com/2008/07/09/how-to-log-in-c-net-with-log4net-a-tutorial/Here is
great example for sending logfile into mail......

use the logger to log a few statements with various severity levels. log4net defines 5 such levels:
Log4Net supports five levels of logs with five methods.

Debug: fine-grained statements concerning program state, typically used for debugging;

Info: informational statements concerning program state, representing program events or behavior tracking;

Warn: statements that describe potentially harmful events or states in the program;

Error: statements that describe non-fatal errors in the application; this level is used quite often for logging handled exceptions;

Fatal: statements representing the most severe of error conditions, assumedly resulting in program termination.

we have to add Log4Net Dll in Add reference section.

after that Inside the AssemblyInfo.cs

[assembly: log4net.Config.XmlConfigurator(ConfigFile = "Web.config", Watch = true)]

and add some code in web.config file..

section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net" requirePermission="false"/>


log4net debug="true">
appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
file value="Log4net\\log4net.txt"/>
appendToFile value="true"/>
rollingStyle value="Size"/>
maxSizeRollBackups value="10"/>
maximumFileSize value="50KB"/>
staticLogFileName value="true"/>
lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
layout type="log4net.Layout.PatternLayout">
conversionPattern value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n"/>
/layout>
/appender>
root>
level value="ALL"/>
appender-ref ref="RollingLogFileAppender"/>
/root>
/log4net>



add key="log4net.Internal.Debug" value="true" />
/appSettings>



//////////and Inside the .cs page

using log4net;//Add class in page

//Define Globally
private static readonly log4net.ILog log = log4net.LogManager.GetLogger("_Default");

//use like this
protected void Page_Load(object sender, EventArgs e)
{
try
{
int a = 0;
int b = 1;
int c = b / a;
}
catch (Exception ex)
{
log.Error(ex.Message, ex);//here is using
}
}

Friday, January 14, 2011

Compute with DataTable

DataTable Dtable=new DataTable();
DataColumn DColumn=new DataColumn("Salary",typeof(float));
DTable.Column.Add(DColumn);

DataRow DRow=DTable.NewRow();
DRow[0]=25000;
DTable.Rows.Add(DRow);

DRow=DTable.NewRow();
DRow[0]=30000;
DTable.Rows.Add(DRow);
//For Doolar Formate
string u= string.Format("{0:C}", ds.Tables[0].Compute("sum(Salary)", ""));
string u = string.Format("{0:0,000,000}", ds.Tables[0].Compute("sum(Salary)", ""));
//for Indian Rupee formate
string u = string.Format("{0:#,#.}", ds.Tables[0].Compute("sum(Salary)", ""));
Console.WriteLine(TotalSalary);

Thursday, January 13, 2011

C# IndexOf String Examples

IndexOf methods:

First, here we note that there are four IndexOf instance methods. The first two methods find the first indexes. They scan through the characters from the left to right. The second two find the last indexes, and they go from right to left.

IndexOf:This method finds the first index of the char argument. It returns -1 if the char was not found.

IndexOfAny:This method finds the first index of any of the char arguments. It returns -1 if none are found.

LastIndexOf:This finds the last index of the char argument. It returns -1 if the char was not found.

LastIndexOfAny:This finds the first index of any of the char arguments. It returns -1 if none are found.

Example:
string Path: C:\Documents and Settings\Jitendra\My Documents\Visual Studio 2008\Projects\WebApplication5\WebApplication5\

string k = stem.Web.HttpContext.Current.Request.PhysicalApplicationPath;
int o ;
k = k.Remove(k.LastIndexOf("\\"));
o = k.LastIndexOf("\\");
string appName1 = k.Substring(o+1);

Example:- string strFileName;
string strFile = strFileName.Substring(strFileName.LastIndexOf("\\")+1);

Wednesday, January 12, 2011

Special Character check through javascript

//The IndexOf method can be used to check if one character is inside of another. For example, suppose you want to check an email address to see if it contains the @ character. If it doesn't you can tell the user that it's an invalid email address.



script type="text/javascript" language ="javascript" >

function checkSpecialCharacters() {

var str = "'!#$%^&;*()";
var txtUserId = document.getElementById('txtUserId').value;
var txtPassword = document.getElementById('txtPassword').value;
var txt = txtUserId + txtPassword;

for (var i = 0; i < str.length; i++) { var char1 = str.substr(i, 1) if (txt.indexOf(char1) > -1) {
alert('special character(s) are not allowed in loginid/password');
//alert(obj.getMessage(196));
return false;
}
}
}
/script>

Tuesday, January 11, 2011

DefaultView

//DefaultView:filter a limited number of columns from a table:
//Distinct Data in DataTable with the Field of roleid,roleName,abbreviation........


DataSet infoDS=new DataSet();
DataTable dTable = infoDS.Tables[0].DefaultView.ToTable(true, "roleid", "roleName", "abbreviation");

for (int i = 0; i < dTable.Rows.Count; i++) { if (dTable.Rows.Count > 0)
{
string _RoleId = dTable.Rows[i]["roleid"].ToString();
string _RoleName = dTable.Rows[i]["roleName"].ToString();
string _Abbreviation = dTable.Rows[i]["abbreviation"].ToString();
}
}

Compute with DataTable

DataTable Dtable=new DataTable();
DataColumn DColumn=new DataColumn("Salary",typeof(float));
DTable.Column.Add(DColumn);

DataRow DRow=DTable.NewRow();
DRow[0]=25000;
DTable.Rows.Add(DRow);

DRow=DTable.NewRow();
DRow[0]=30000;
DTable.Rows.Add(DRow);

float TotalSalary=(float)DTable.Compute("Sum(Salary)","");
Console.WriteLine(TotalSalary);

Saturday, January 8, 2011

Dropdown bind through xml

XmlDocument xml = new XmlDocument();
string s =Server.MapPath("XMLfILE.xml");
string list = "/catalog/book";
xml.Load(s);
XmlNodeList xn = xml.SelectNodes(list);
foreach (XmlNode eleSourceNode in xn)
{
string ID = eleSourceNode.Attributes["id"].Value;
string author1 = eleSourceNode["author"].InnerText;
DRPLIST.Items.Add(new ListItem(author1 ,ID));
}


//XMLFILE.xml

?xml version="1.0"?>
catalog>
book id="bk101">
author>Gambardella, Matthew /author>
title>XML Developer's Guide /title>
genre>Computer /genre>
price>44.95 /price>
publish_date>2000-10-01 /publish_date>
description>
An in-depth look at creating applications
with XML.
/description>
/book>

book id="bk111">
author>O'Brien, Tim /author>
title>MSXML3: A Comprehensive Guide /title>
genre>Computer /genre>
price>36.95 /price>
publish_date>2000-12-01/publish_date>
description>
The Microsoft MSXML3 parser is covered in
detail, with attention to XML DOM interfaces, XSLT processing,
SAX and more.
/description>
/book>
book id="bk112">
author>Galos, Mike/author>
title>Visual Studio 7: A Comprehensive Guide/title>
genre>Computer /genre>
price>49.95 /price>
publish_date>2001-04-16/publish_date>
description>
Microsoft Visual Studio 7 is explored in depth,
looking at how Visual Basic, Visual C++, C#, and ASP+ are
integrated into a comprehensive development
environment.
/description>
/book>
/catalog>

Link for Asp.net Architecture(Isapi.dll,httpcontext,hpptmodule)

http://www.west-wind.com/presentations/howaspnetworks/howaspnetworks.asp

Boxing and Unboxing(Convert value type to ref type and ref type to value type.)

int Val = 1;
Object Obj = Val; //Boxing
int i = (int)Val; //Unboxing