protected void Page_Load(object sender, EventArgs e) { try { string ID = (Request.QueryString["ID"] != null) ? Request.QueryString["ID"] : ""; string Type = (Request.QueryString["Type"] != null) ? Request.QueryString["Type"] : ""; if (Type == "Visitors") { dt = DBFun.FetchData("SELECT TOP 1 VisImage FROM VisitorsCard WHERE VisIdentityNo='" + ID + "' ORDER BY VisCardID DESC"); } if (Type == "VisitorsTmp") { dt = DBFun.FetchData("SELECT photo FROM TempImage WHERE Type = 'Visitors' AND EmpID ='" + ID + "'"); } if (Type == "Employee") { dt = DBFun.FetchData("SELECT image FROM EmployeeMaster WHERE EmpNationalID ='" + ID + "'"); } if (Type == "EmployeeTmp") { dt = DBFun.FetchData("SELECT photo FROM TempImage WHERE Type = 'Employee' AND EmpID ='" + ID + "'"); } if (Type == "Logo") { dt = DBFun.FetchData("SELECT AppLogo FROM ApplicationSetup"); } if (Type == "LogoTmp") { dt = DBFun.FetchData("SELECT photo FROM TempImage WHERE Type = 'Logo' AND EmpID ='" + ID + "'"); } //ReadImage if (DBFun.IsNullOrEmpty(dt)) { return; } if (Type == "Visitors" || Type == "Company" || Type == "Student" || Type == "Employee") { Response.BinaryWrite(CryptoImage.DecryptBytes((Byte[])dt.Rows[0][0])); Response.End(); } else { Response.BinaryWrite((Byte[])dt.Rows[0][0]); Response.End(); } } catch (Exception e1) { } }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public void GetImage(out byte[] pImage, out string pImageContentType, out int pImageLength) { pImage = new Byte[0]; pImageContentType = ""; pImageLength = 0; string fileName = FindID() + ".jpeg"; string path = Server.MapPath(FindTempImagePath()) + fileName; bool available = System.IO.File.Exists(path); try { dt = DBFun.FetchData("SELECT * FROM TempImage WHERE Type = '" + Type + "' AND EmpID='" + FindID() + "'"); if (DBFun.IsNullOrEmpty(dt)) { if (available) { try { int len = System.IO.Path.GetFullPath(path).Length; byte[] imageData = new Byte[100000]; System.IO.FileStream newFile = new System.IO.FileStream(path, System.IO.FileMode.Open); newFile.Read(imageData, 0, imageData.Length); pImage = (byte[])imageData; pImageContentType = "image/pjpeg"; pImageLength = imageData.Length; } catch (Exception e1) { System.IO.File.Delete(path); } } else { DataTable imgdt = DBFun.FetchData(FindQuery()); if (!DBFun.IsNullOrEmpty(imgdt)) { if (!IsEncryption) { pImage = (Byte[])imgdt.Rows[0]["Image"]; } else { pImage = CryptoImage.DecryptBytes((Byte[])imgdt.Rows[0]["Image"]); } pImageContentType = imgdt.Rows[0]["ImageType"].ToString(); pImageLength = Convert.ToInt32(imgdt.Rows[0]["ImageLen"]); } } } else { pImage = (Byte[])dt.Rows[0]["photo"]; pImageContentType = dt.Rows[0]["PhotoType"].ToString(); pImageLength = Convert.ToInt32(dt.Rows[0]["PhotoLength"]); } int returnValue = DBFun.ExecuteData("DELETE FROM TempImage WHERE Type = '" + Type + "' AND EmpID='" + FindID() + "'"); } catch (Exception e2) { int returnValue = DBFun.ExecuteData("DELETE FROM TempImage WHERE Type = '" + Type + "' AND EmpID='" + FindID() + "'"); } }