Sunday, May 15, 2011

data layer

public Boolean ExecuteS1p(DataBO dbo)
{
Boolean flag = false;
DataConnection DC = new DataConnection(ConnString);
try
{
DC.OpenConnection();
DC.BegingTran();
DC.AppCommand.CommandType = CommandType.StoredProcedure;
DC.AppCommand.CommandText = "Sp_AppUsere1";
DC.AppCommand.Parameters.AddWithValue("@ActionID", dbo.ActionID1 );
DC.AppCommand.Parameters.AddWithValue("@Aref", dbo.Aref);
DC.AppCommand.Parameters.AddWithValue("@UserID", dbo.USerID1 );
DC.AppCommand.Parameters.AddWithValue("@Password", dbo.Password);
DC.AppCommand.Parameters.AddWithValue("@FirstName", dbo.FirstName );
DC.AppCommand.Parameters.AddWithValue("@LastName", dbo.LastName );
DC.AppCommand.Parameters.AddWithValue("@ImageData",dbo.Imagedata);
DC.AppDataAdapter.SelectCommand = DC.AppCommand;
DC.AppDataAdapter.Fill(DC.AppDataSet);
DC.CommitTran();
flag = true;
}
catch
{
DC.RollBackTran();
throw;
}
finally
{
DC.closeConnction();

}
return flag;

}

Regural Expression

Pincode:
"\d{5}

Fro Number Only:
"^[0-9]+$"
Fro Date :mm/dd/yyyy or mm.dd.yyyy or mm-dd-yyyy

"(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d"

how to stored Images

stored
byte[] imageBytes =(byte[]) Session["imgData"];



display
imageBytes = ((byte[])Session["imgData"]);
Response.BinaryWrite(imageBytes);

Inline Editing

protected void GVEmployee_RowUpdating(object sender, GridViewUpdateEventArgs e)
{

GridViewRow row;
row = GVEmployee.Rows[e.RowIndex];

Label Emp_code = row.FindControl("lblEMP_Code") as Label;
DropDownList Dept_Code= row.FindControl("DDLemp_CODE") as DropDownList;
TextBox Emp_Name = row.FindControl("txtIEmpName") as TextBox;
TextBox Address = row.FindControl("txtIAddress") as TextBox;
FileUpload image = row.FindControl("fuIIMage") as FileUpload;
Textbox Doj = row.FindControl("txtIDOJ") as Textbox;
Textbox Bdate = row.FindControl("txtIBDate") as Textbox;
txtNumber Phone = row.FindControl("txtIPhonw") as txtNumber;
DropDownList Status = row.FindControl("ddlIStatus") as DropDownList;
DropDownList Gender = row.FindControl("ddlIGender") as DropDownList;
DropDownList exp = row.FindControl("ddlIExp") as DropDownList;
TextBox NoofExp = row.FindControl("txtINOExp") as TextBox;

bl.EMP_Code = Emp_code.Text;
bl.DEP_Code = Dept_Code.SelectedValue;
bl.EMP_Name = Emp_Name.Text;
if (image.HasFile)
{
byte[] imageData = File.ReadAllBytes(image.FileName);
bl.IMage = imageData;
}
bl.Address = Address.Text;


bl.Doj = Doj.EmpDate;


bl.Doj = Bdate.EmpDate;

bl.Phone = Phone.NUmber;
bl.Status = Status.SelectedValue;
bl.Gender = Gender.SelectedValue;

if (exp.SelectedValue == "1")
{
bl.Exp = true;
}
else
{
bl.Exp = false;
}
if (NoofExp.Text != "")
{
bl.NOofexp = Convert.ToInt16(NoofExp.Text);
}
bl.update();
GVEmployee.EditIndex = -1;
bind();

}
protected void GVEmployee_RowEditing(object sender, GridViewEditEventArgs e)
{
GVEmployee.EditIndex = e.NewEditIndex;
bind();
}
protected void GVEmployee_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GVEmployee.EditIndex = -1;
bind();
}
protected void GVEmployee_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GVEmployee.PageIndex = e.NewPageIndex;
bind();
}
protected void GVEmployee_RowDeleting(object sender, GridViewDeleteEventArgs e)
{

string emp_code;
emp_code = GVEmployee.DataKeys[e.RowIndex].Value.ToString();
bl.EMP_Code = emp_code;
bl.Delete();
int i = bl.RET;
if (i == 1)
{
System.Windows.Forms.MessageBox.Show("Record Delete Successfully!", "Alert", System.Windows.Forms.MessageBoxButtons.OK);
}
if (i == 0)
{
System.Windows.Forms.MessageBox.Show("Record Delete Failed!", "Alert", System.Windows.Forms.MessageBoxButtons.OK);
}

bind();
}
protected void btnInsert_Click(object sender, EventArgs e)
{
TextBox Emp_code = GVEmployee.FooterRow.FindControl("txtEmpCode") as TextBox;
DropDownList Dept_Code = GVEmployee.FooterRow.FindControl("DDLIemp_CODE") as DropDownList;
TextBox Emp_Name = GVEmployee.FooterRow.FindControl("txtEmpName") as TextBox;
TextBox Address = GVEmployee.FooterRow.FindControl("txtAddress") as TextBox;
FileUpload image = GVEmployee.FooterRow.FindControl("fuIMage") as FileUpload;
Textbox Doj = GVEmployee.FooterRow.FindControl("txtDOJ") as Textbox;
Textbox Bdate = GVEmployee.FooterRow.FindControl("txtBDate") as Textbox;
txtNumber Phone = GVEmployee.FooterRow.FindControl("txtPhone") as txtNumber;
DropDownList Status = GVEmployee.FooterRow.FindControl("ddlStatus") as DropDownList;
DropDownList Gender = GVEmployee.FooterRow.FindControl("ddlGender") as DropDownList;
DropDownList exp = GVEmployee.FooterRow.FindControl("ddlExp") as DropDownList;
TextBox NoofExp = GVEmployee.FooterRow.FindControl("txtNOExp") as TextBox;

bl.EMP_Code = Emp_code.Text;
bl.DEP_Code = Dept_Code.SelectedValue;
bl.EMP_Name = Emp_Name.Text;
if (image.HasFile)
{
image.SaveAs(Server.MapPath("~/" + image.FileName));
byte[] imageData = File.ReadAllBytes(Server.MapPath("~/" + image.FileName));
bl.IMage =imageData;
}
bl.Address = Address.Text;


bl.Doj = Doj.EmpDate;
//if (Bdate.EmpDate == "")
//{
//
//}

bl.Bod = Bdate.EmpDate;
//if (Phone.NUmber != "")
//{
//
//}
bl.Phone = Phone.NUmber;
bl.Status = Status.SelectedValue;
bl.Gender = Gender.SelectedValue;

if (exp.SelectedValue == "1")
{
bl.Exp = true;
}
else
{
bl.Exp = false;
}

if (NoofExp.Text != "")
{
bl.NOofexp = Convert.ToInt16(NoofExp.Text);
}
bl.Insert();
int i;
i = bl.RET;
if (i == 2)
{
System.Windows.Forms.MessageBox.Show("Emp_code Already Exist","Warning", System.Windows.Forms.MessageBoxButtons.OK);
}
if (i == 0)
{
System.Windows.Forms.MessageBox.Show("Record Insert Successfully!", "Alert", System.Windows.Forms.MessageBoxButtons.OK);
}
if (i == 1)
{
System.Windows.Forms.MessageBox.Show("Record Insert Failed!", "Alert", System.Windows.Forms.MessageBoxButtons.OK);
}

bind();


}

DataConnection

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
///
/// Summary description for DataConnection
///
public class DataConnection
{
public string ConString = "Data Source=devsvr1;Initial Catalog=EMPDB;User ID=Sa;Password=Password00";
public SqlConnection AppConnection = new SqlConnection();
public SqlDataAdapter AppDataAdapter = new SqlDataAdapter();
public SqlCommand AppCommand = new SqlCommand();
public DataSet AppDataSet = new DataSet();
public SqlTransaction AppTran;
public DataConnection(string Constr)
{
ConString = Constr;

}

public void OpenConnection()
{
try
{
AppConnection.ConnectionString = ConString;
AppConnection.Open();
AppCommand.Connection = AppConnection;
}
catch (SqlException Ex)
{
throw;
}
}
public void BegingTran()
{
AppTran = AppConnection.BeginTransaction(IsolationLevel.ReadCommitted);
AppCommand.Transaction = AppTran;
}

public void RollBackTran()
{ AppTran.Rollback(); }

public void CommitTran()
{
AppTran.Commit();
}
public void closeConnction()
{
AppConnection.Close();
}
}