Monday, 19 May 2014
Saturday, 17 May 2014
Text box has to allow only characters in Asp.Net
In Text box Design Coding:
Font-Names="Verdana" Font-Size="9pt" Height="18px" Width="190px"
MaxLength="50"></asp:TextBox>
Text box has to allow only characters:
function isNameKey(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if ((charCode <= 93 && charCode >= 65) || (charCode <= 122 && charCode >= 97){
return true;
}
else {
return false;
}
}
Text box has to allow only characters with Space:
function isNameKey(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if ((charCode <= 93 && charCode >= 65) || (charCode <= 122 && charCode >= 97) || (charCode == 32) ){
return true;
}
else {
return false;
}
}
Text box has to allow only numbers:
function isNumberKey1(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode < 48 || charCode > 57) {
return false;
}
else {
return true;
}
}
Text box has to allow only numbers with dots:
function isNumberKey(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode != 46 && (charCode < 48 || charCode > 57)) {
return false;
}
else {
return true;
}
}
jQuery - Allow Alphanumeric (Alphabets & Numbers)
Characters in Textbox using JavaScript
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery Allow only alphanumeric characters in textbox</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function () {
$('#txtNumeric').keydown(function (e) {
if (e.shiftKey || e.ctrlKey || e.altKey) {
e.preventDefault();
} else {
var key = e.keyCode;
if (!((key == 8) || (key == 32) || (key == 46) || (key >= 35 && key <= 40) || (key >= 65 && key <= 90) || (key >= 48 && key <= 57) || (key >= 96 && key <= 105))) {
e.preventDefault();
}
}
});
});
</script>
</head>
<body>
<div>
<b>Enter Text:</b><input type="text" id="txtNumeric" />
</div>
</body>
</html>
Friday, 9 May 2014
In School Attendance Report For Month Wise
Design Page
Default.aspx.cs
int GetDaysInMonth(int month, int year)
{
if (month < 1 || month > 12)
{
throw new System.ArgumentOutOfRangeException("month", month, "month mustbe between 1 and 12");
}
if (1 == month || 3 == month || 5 == month || 7 == month || 8 == month || 10 == month || 12 == month)
{
return 31;
}
else if (2 == month)
{
if (0 == (year % 4))
{
if (0 == (year % 400))
{
return 29;
}
else if (0 == (year % 100))
{
return 28;
}
return 29;
}
return 28;
}
return 30;
}
protected void btnReport_Click(object sender, EventArgs e)
{
string bno = DrpBatchNo.SelectedValue.ToString().Trim();
string icode = DrpInsName.SelectedValue.ToString().Trim();
string year21 = txtYear.Text.ToString().Trim();
string month21 = DrpMonth.SelectedValue.ToString().Trim();
int year = 0;
if (year21 != "")
{
year = Convert.ToInt32(year21);
}
int month = 0;
if (month21 != "")
{
month = Convert.ToInt32(month21);
}
if (year21.Length == 4)
{
if ((bno != "All" || bno != "") && (icode != "All" || icode != ""))
{
//Check No Of Days
int days = GetDaysInMonth(Convert.ToInt32(DrpMonth.SelectedValue), Convert.ToInt32(txtYear.Text.ToString().Trim()));
//Create a DataTable
DataTable myDT = new DataTable();
for (int i = 1; i <= days; i++)
{
if (i == 1)
{
DataColumn id2 = new DataColumn("id");
//Create a First column Name
id2.ColumnName = "Member Code";
id2.MaxLength = 60;
myDT.Columns.Add(id2);
DataColumn id1 = new DataColumn("id");
//Create a First Second Name
id1.ColumnName = "Member Name";
id1.MaxLength = 60;
myDT.Columns.Add(id1);
}
// loop end after i < = days
DataColumn id = new DataColumn("id");
// i is a day 1 column until end of days
id.ColumnName = i.ToString("#00");
id.MaxLength = 4;
myDT.Columns.Add(id);
}
for (int i = 1; i <= 1; i++)
{
// This Datatable is used to select all members from member table
DataTable dt = TRN.RGetAttendance(bno);
if (dt.Rows.Count > 0)
{
for (int j = 0; j < dt.Rows.Count; j++)
{
DataRow dr = myDT.NewRow();
string name = dt.Rows[j][1].ToString();
string mcode = dt.Rows[j][0].ToString();
// single Member code until end of month days
for (int ii = 0; ii <= days + 1; ii++)
{
if (ii == 0)
{
dr[ii] = mcode;
}
if (ii == 1)
{
dr[ii] = name;
}
else if (ii > 1)
{
string attdate = (ii - 1).ToString("#00") + "/" + month.ToString("#00") + "/" + year.ToString("#0000");
string day1 = attdate.Substring(0, 2);
string month1 = attdate.Substring(3, 2);
string year1 = attdate.Substring(6, 4);
int day11 = 0;
int month11 = 0;
int year11 = 0;
if (day1 != "" && month1 != "" && year1 != "")
{
day11 = Convert.ToInt32(day1);
month11 = Convert.ToInt32(month1);
year11 = Convert.ToInt32(year1);
attdate = datetimeconvert(year11, month11, day11);
}
// This Datatable is used to select a data from member code
DataTable dt1 = TRN.RGetAttendance1(mcode, attdate);
if (dt1.Rows.Count > 0)
{
string status = dt1.Rows[0][3].ToString();
dr[ii] = status;
}
}
}
// add a name, code, no of days present or absent
myDT.Rows.Add(dr);
}
}
}
//Bind All rows in Gridview
GrdAttendance.DataSource = myDT;
GrdAttendance.DataBind();
}
else
{
ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('" + "Select Valid Institute and Batch Name" + "');</script>", false);
}
}
else
{
ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('" + "Enter a Valid Year" + "');</script>", false);
}
}
public static string datetimeconvert(int a, int b, int c)
{
string ye2 = Convert.ToString(a);
string mo2 = Convert.ToString(b);
string da2 = Convert.ToString(c);
if (mo2.Length == 1)
{
mo2 = "0" + mo2;
}
if (da2.Length == 1)
{
da2 = "0" + da2;
}
string[] allStr = new String[] { mo2, da2, ye2 };
string datetime = String.Join("/", allStr);
return datetime;
}
Table
CREATE TABLE [dbo].[attendance_dtl](
[attend_date] [smalldatetime] NULL,
[attend_time] [varchar](20) NULL,
[attend_membercode] [varchar](25) NULL,
[attend_status] [char](1) NULL,
[attend_batchno] [varchar](20) NULL,
[attend_institute_code] [int] NULL
)
Stored Procedure in Sql
CREATE PROCEDURE [dbo].[Sp_RGetAttendance]
@bno varchar(100)
AS
BEGIN
Select trainee_dtl.trainee_membercode, trainee_dtl.trainee_membername from trainee_dtl
where trainee_dtl.trainee_course_batchno = @bno
END
CREATE PROCEDURE [dbo].[Sp_RGetAttendance1]
@mcode varchar(100),
@attdate smalldatetime
AS
BEGIN
Select tnpvp_attendance_dtl.* from attendance_dtl
where attendance_dtl.attend_membercode = @mcode and attendance_dtl.attend_date = @attdate
END
Output
Example of XML with XSLT
In Books.xml
<?xml version="1.0"?>
<Books>
<Book>
<Title>Beginning XML</Title>
<Author>John</Author>
</Book>
<Book>
<Title>Mastering XML</Title>
<Author>Peter</Author>
</Book>
</Books>
In Books.xml
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Books">
<HTML>
<BODY>
<TABLE>
<TR>
<TD>Title</TD>
<TD>Author</TD>
</TR>
<xsl:for-each select="Book">
<TR>
<TD><xsl:value-of select="Title"/></TD>
<TD><xsl:value-of select="Author"/></TD>
</TR>
</xsl:for-each>
</TABLE>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
In Default.aspx Page
Add Xml icon From the toolbox
In Default.aspx.cs Page
//coding type 1
string xmlPath = Server.MapPath("Books.xml");
string xsltPath = Server.MapPath("Books.xslt");
XmlReader objXMlReader = XmlReader.Create(xmlPath);
XslCompiledTransform objXSLCompTransform =
new XslCompiledTransform();
objXSLCompTransform.Load(xsltPath);
StringBuilder objStrBuil = new StringBuilder();
TextWriter objTextWri = new StringWriter(objStrBuil);
objXSLCompTransform.Transform(objXMlReader, null, objTextWri);
Literal1.Text = objStrBuil.ToString();
objXMlReader.Close();
(Or)
//coding type 2
Xml1.DocumentSource = Request.QueryString[0];
Xml1.TransformSource = Request.QueryString[1];
Output For Coding Type1
Output For Coding Type2
Friday, 21 March 2014
How to Display without using Crystal Report(Windows Print)
- Select a Print Document, Print Preview Dialog, Print Dialog(all selected) under Printing Tools in Toolbox.
- In Print Button
//Create a PrintDocument object
PrintDocument pd = new PrintDocument();
////Add print-page event handler
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
//Set Document property of PrintPreviewDialog
printPreviewDialog1.Document = pd;
((Form)printPreviewDialog1).WindowState = FormWindowState.Maximized;
DialogResult dr = printPreviewDialog1.ShowDialog();
3. public void pd_PrintPage(object sender, PrintPageEventArgs e)
{
SqlConnection con = new SqlConnection(conn);
con.Open();
Font font = new Font("Microsoft Sans Serif", 14F,
System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point,
((byte)(0)));
Font font2 = new Font("Microsoft Sans Serif", 14F,
System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point,
((byte)(0)));
Graphics g = e.Graphics;
string vouno = txtCDNo.Text.ToString().Trim();
string transdate = dtpDate.Value.ToString().Trim();
transdate = transdate.Substring(0, 10);
string recname = txtCSName.Text.ToString().Trim();
string amount = txtAmount.Text.ToString().Trim();
double amt = 0;
if (amount != "")
{
amt = Convert.ToDouble(amount);
}
string narr1 = txtNarration.Text.ToString().Trim();
string narr2 = txtNarration2.Text.ToString().Trim();
string custoname = "";
string addres1 = "";
string addres2 = "";
string addres3 = "";
string city = "";
string pincode = "";
if (radioCredit.Checked == true)
{
g.DrawString("CREDIT NOTE", font, System.Drawing.Brushes.Black, 50, 25);
string find = "select * from IBS_CUSTOMER_MST where Cust_Id = '" + cid + "'";
SqlCommand findquery = new SqlCommand(find, con);
SqlDataReader dr = findquery.ExecuteReader();
if (dr.Read())
{
custoname = dr["Cust_Name"].ToString();
addres1 = dr["Cust_Add1"].ToString();
addres2 = dr["Cust_Add2"].ToString();
addres3 = dr["Cust_Add3"].ToString();
city = dr["Cust_City"].ToString();
pincode = dr["Cust_Pin"].ToString();
}
dr.Close();
}
else
{
g.DrawString("DEBIT NOTE", font, System.Drawing.Brushes.Black, 50, 25);
string find = "select * from IBS_SUPPLIER_MST where Sup_Id = '" + cid + "'";
SqlCommand findquery = new SqlCommand(find, con);
SqlDataReader dr = findquery.ExecuteReader();
if (dr.Read())
{
custoname = dr["Sup_Name"].ToString();
addres1 = dr["Sup_Add1"].ToString();
addres2 = dr["Sup_Add2"].ToString();
addres3 = dr["Sup_Add3"].ToString();
city = dr["Sup_City"].ToString();
pincode = dr["Sup_Pin"].ToString();
}
dr.Close();
}
g.DrawString("Ledger Name", font, System.Drawing.Brushes.Black, 0, 75);
g.DrawString("Address", font, System.Drawing.Brushes.Black, 0, 125);
g.DrawString("Voucher No", font, System.Drawing.Brushes.Black, 450, 75);
g.DrawString("Date", font, System.Drawing.Brushes.Black, 450, 125);
g.DrawString("S.No", font, System.Drawing.Brushes.Black, 30, 230);
g.DrawString("Descripation", font, System.Drawing.Brushes.Black, 90, 230);
g.DrawString("Amount", font, System.Drawing.Brushes.Black, 400, 230);
//g.DrawString("Address", font, System.Drawing.Brushes.Black, 300, 300);
int place = 150;
g.DrawString(custoname, font2, System.Drawing.Brushes.Black, place, 75);
g.DrawString(addres1, font2, System.Drawing.Brushes.Black, place, 125);
g.DrawString(addres2, font2, System.Drawing.Brushes.Black, place, 145);
g.DrawString(addres3, font2, System.Drawing.Brushes.Black, place, 165);
g.DrawString(city, font2, System.Drawing.Brushes.Black, place, 185);
g.DrawString(pincode, font2, System.Drawing.Brushes.Black, place, 205);
g.DrawString(vouno, font2, System.Drawing.Brushes.Black, place + 450, 75);
g.DrawString(transdate, font2, System.Drawing.Brushes.Black, place + 450, 125);
g.DrawString(vouno, font2, System.Drawing.Brushes.Black, 30, 270);
g.DrawString(narr1, font2, System.Drawing.Brushes.Black, 90, 270);
g.DrawString(narr2, font2, System.Drawing.Brushes.Black, 90, 290);
g.DrawString(amt.ToString("#0.00"), font2, System.Drawing.Brushes.Black, 400, 270);
e.HasMorePages = false;
Thursday, 27 February 2014
Crystal Report With DataSet in Web Application .aspx Page(With Database)
1. Open Project solution
2. Create a Table and Insert Data's into a Table.
3. Example
4. Coding added to place of Web.config
<appSettings>
<add key="ConnString" value="Data Source=SAMITECHPC1\SQL2008R2;Initial Catalog=test;Integrated Security=True" />
<add key="CrystalImageCleaner-AutoStart" value="true" />
<add key="CrystalImageCleaner-Sleep" value="60000" />
<add key="CrystalImageCleaner-Age" value="120000" />
</appSettings>
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=SAMITECHPC1\SQL2008R2;Initial Catalog=test;Integrated Security=True"/>
</connectionStrings>
5. Example:
6.Solution Name To Right Click --> Add New Item --> Select DataSet and Add Button is Clicked
7. Now Open DataSet1.xsd page and Right Click --> Add --> DataTable
and now open DataTable again Add a column in DataTable
and Click a Properties to change a Datatype( same as Database column name and datatype) and click a
Save to DataSet1.xsd
8. Now Add a Crystal Report into Solution.
9. Now You Add a New Class into Solution
Coding:
public class Class1
{
//Connection Strings
string strConnection = System.Configuration.ConfigurationSettings.AppSettings["ConnString"];
//DataSet1 is .xsd file name
public DataSet1 GetValues()
{
try
{
DataSet1 alldatas = null;
using (SqlConnection connection = new SqlConnection(strConnection))
{
using (SqlCommand command = connection.CreateCommand())
{
alldatas = new DataSet1();
// best practies ingore inline query
command.CommandText = "SELECT * FROM empdetails;";
command.CommandType = System.Data.CommandType.Text;
using (SqlDataAdapter adapter = new SqlDataAdapter(command))
{
//DataTable1 is Datatable name of DataSet1
adapter.Fill(alldatas.DataTable1);
}
}
}
return alldatas;
}
catch (Exception ex)
{
throw ex;
}
}
}
10. Now You add a New Form into Solution
11. Now You Add a Crystal Report Viewer From Tool Box
12. To Open a PrintScreen.cs File and type a Following Coding
In Page Load Event
//Class1 is a file name of .cs
Class1 ps = new Class1();
ReportDocument report = new ReportDocument();
report.Load(Server.MapPath("CrystalReport.rpt"));
//DataSet is a .xsd File Name
DataSet1 Result = ps.GetAll();
if (Result != null)
{
report.SetDataSource(Result);
CrystalReportViewer1.ReportSource = report;
}
13. Now to Open a Crystal Report
Click Field Explorer of DataBase Fields --> right click --> DataBase Expert clicked
14. DataBase Expert Window is Opened and Now Click Project Data --> ADO.NET DataSets --> Select DataTable1 to Moved To another Box.
15. Now Click Field Explorer of Database Fields all DataTable1 Fileds are here.
16. And open a Page Print Click Event
17. To click Print to Type a Coding
protected void butPrint_Click(object sender, EventArgs e)
{
Response.Redirect("PrintScreen.aspx");
}
18.Output:
Subscribe to:
Posts (Atom)