Dear Sir,
Need your help here, while i have capture and upload image form web cam, its been saved in capture folder but i unable to display same in GridView row.
Please sir help me.
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="WebCam.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
Webcam.set({
width: 90,
height: 90,
image_format: 'jpeg',
jpeg_quality: 90
});
Webcam.attach('#webcam');
$("#btnCapture").click(function () {
Webcam.snap(function (data_uri) {
$("#imgCapture")[0].src = data_uri;
$("#btnUpload").removeAttr("disabled");
});
});
$("#btnUpload").click(function () {
$.ajax({
type: "POST",
url: "WebForm1.aspx/SaveCapturedImage",
data: "{data: '" + $("#imgCapture")[0].src + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) { }
});
});
});
</script>
<script type="text/javascript">
function printPage() {
window.print();
}
</script>
namespace ash_vhcl_entry
{
public partial class cgp : System.Web.UI.Page
{
int empno = 0;
protected void Page_Load(object sender, EventArgs e)
{
empno = Convert.ToInt32(Request.QueryString["Id"].ToString());
Session["EmpId"] = empno;
if (!IsPostBack)
//if(Page.IsPostBack)
{
BindTextBoxvalues();
}
}
[WebMethod()]
public static bool SaveCapturedImage(string data)
{
string fileName = DateTime.Now.ToString("dd-MM-yy hh-mm-ss");
//Convert Base64 Encoded string to Byte Array.
byte[] imageBytes = Convert.FromBase64String(data.Split(',')[1]);
//Save the Byte Array as Image File.
string filePath = HttpContext.Current.Server.MapPath(string.Format("~/Captures/{0}.jpg", fileName));
File.WriteAllBytes(filePath, imageBytes);
return true;
}
}
}
namespace ash_vhcl_entry
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
if (Session["emp_nm"] == null)
Response.Redirect("lgn.aspx");
else
{
String EmplooyeId = Session["emp_id"].ToString();
Label1.Text = " " + EmplooyeId + "";
String emp_nm = Session["emp_nm"].ToString();
Label2.Text = "" + emp_nm + " ";
String dept = Session["dept"].ToString();
Label3.Text = "" + dept + " ";
}
this.BindGrid();
foreach (GridViewRow row in GridView1.Rows)
{
(row.FindControl("Button2") as Button).Visible = false;
if (row.Cells[6].Text == "Entry")
{
(row.FindControl("Button2") as Button).Visible = true;
(row.FindControl("LinkButton1") as Button).Visible = false;
}
}
}
TextBox1.Text = TextBox1.Text = System.DateTime.Now.ToString("dd/MM/yyyy");
// Label3.Text = System.DateTime.Now.ToString();
}
private void BindGrid()
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand())
{
//cmd.CommandText = "SELECT Id,emp_id,dept, emp_nm,vst_nm,idtyp,idnm,fa_hu_nm,gndr,crnt_add,pur_pos,cisf_in_flag,cisf_out_flag,vstd_dt FROM vstr2 WHERE emp_id LIKE '%' + @emp_id + '%' and cisf_out_flag='No' and vstd_dt =CAST(GETDATE() AS DATE)";
cmd.CommandText = "SELECT Id,emp_id,dept, emp_nm,agncynm,enrtydt,drvrnm,gndr,phn,vhclno,mrkout,Gt_Ps_Isd FROM ashpss WHERE mrkout='No' ";
cmd.Connection = con;
//cmd.Parameters.AddWithValue("@emp_id", txtSearch.Text.Trim());
//cmd.Parameters.AddWithValue("@dept", txtSearch0.Text.Trim());
// cmd.Parameters.AddWithValue("@vst_nm", TextBox1.Text.Trim());
DataTable dt = new DataTable();
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
}
}
}
CREATE TABLE [dbo].[ashpss] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[emp_id] NVARCHAR (10) NULL,
[emp_nm] VARCHAR (100) NULL,
[dept] VARCHAR (20) NULL,
[agncynm] VARCHAR (MAX) NULL,
[enrtydt] VARCHAR (50) NULL,
[drvrnm] VARCHAR (50) NULL,
[gndr] VARCHAR (10) NULL,
[phn] VARCHAR (12) NULL,
[vhclno] VARCHAR (MAX) NULL,
[Gt_Ps_Isd] VARCHAR (10) DEFAULT ('No') NULL,
[mrkout] VARCHAR (10) DEFAULT ('No') NULL,
[Entery] VARCHAR (10) DEFAULT ('No') NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);