} //---------------------------------- //this function gets the employee image path private String GetEmployeeImagePath(CommonExchange.SysAccess userInfo, String patientId, String startUp) { String imagePath = startUp + _imagePath; if (!Directory.Exists(imagePath)) { //creates the directory DirectoryInfo dirInfo = new DirectoryInfo(imagePath); dirInfo.Create(); dirInfo.Attributes = FileAttributes.Hidden; } DataTable imageTable; using (DatabaseLib.DbLibPatientManager dbLib = new DatabaseLib.DbLibPatientManager()) { imageTable = dbLib.SelectImagePatientInformation(userInfo, patientId); } using (DataTableReader tableReader = new DataTableReader(imageTable)) { if (tableReader.HasRows) { Int32 picColumn = 2; while (tableReader.Read()) { if (!tableReader.IsDBNull(picColumn)) { imagePath += "\\" + tableReader["sysid_patient"].ToString() + tableReader["extension_name"].ToString(); if (!File.Exists(imagePath)) { Int64 len = tableReader.GetBytes(picColumn, 0, null, 0, 0); // Create a buffer to hold the bytes, and then // read the bytes from the DataTableReader. Byte[] buffer = new Byte[len]; tableReader.GetBytes(picColumn, 0, buffer, 0, (Int32)len); // Create a new Bitmap object, passing the array // of bytes to the constructor of a MemoryStream. using (Bitmap image = new Bitmap(new MemoryStream(buffer))) { image.Save(imagePath); } } } } } else { imagePath = null; } tableReader.Close(); } return(imagePath); } //------------------------------
static private void TestGetBytes() { // Set up the data adapter, using information from // the AdventureWorks sample database. SqlDataAdapter photoAdapter = SetupDataAdapter( "SELECT ThumbnailPhotoFileName, ThumbNailPhoto " + "FROM Production.ProductPhoto"); // Fill the DataTable. DataTable photoDataTable = new DataTable(); photoAdapter.Fill(photoDataTable); using (DataTableReader reader = new DataTableReader(photoDataTable)) { while (reader.Read()) { String productName = null; try { // Get the name of the file. productName = reader.GetString(0); // Get the length of the field. Pass null // in the buffer parameter to retrieve the length // of the data field. Ensure that the field isn't // null before continuing. if (reader.IsDBNull(1)) { Console.WriteLine(productName + " is unavailable."); } else { long len = reader.GetBytes(1, 0, null, 0, 0); // Create a buffer to hold the bytes, and then // read the bytes from the DataTableReader. Byte[] buffer = new Byte[len]; reader.GetBytes(1, 0, buffer, 0, (int)len); // Create a new Bitmap object, passing the array // of bytes to the constructor of a MemoryStream. using (Bitmap productImage = new Bitmap(new MemoryStream(buffer))) { String fileName = "C:\\" + productName; // Save in gif format. productImage.Save(fileName, ImageFormat.Gif); Console.WriteLine("Successfully created " + fileName); } } } catch (Exception ex) { Console.WriteLine(productName + ": " + ex.Message); } } } Console.WriteLine("Press Enter to finish."); Console.ReadLine(); }
}//-------------------------- //this function gets the student image path public String GetPersonImagePath(CommonExchange.SysAccess userInfo, String personSysIdList, String imagePath) { RemoteClient.ProcStatic.DeleteDirectory(imagePath); //creates the directory DirectoryInfo dirInfo = new DirectoryInfo(imagePath); dirInfo.Create(); dirInfo.Attributes = FileAttributes.Hidden; DataTable imageTable; using (RemoteClient.RemCntBaseManager remClient = new RemoteClient.RemCntBaseManager()) { imageTable = remClient.SelectPersonImagesPersonInformation(userInfo, personSysIdList); } using (DataTableReader tableReader = new DataTableReader(imageTable)) { if (tableReader.HasRows) { Int32 picColumn = 1; while (tableReader.Read()) { if (!tableReader.IsDBNull(picColumn)) { imagePath += tableReader["original_name"].ToString(); long len = tableReader.GetBytes(picColumn, 0, null, 0, 0); // Create a buffer to hold the bytes, and then // read the bytes from the DataTableReader. Byte[] buffer = new Byte[len]; tableReader.GetBytes(picColumn, 0, buffer, 0, (int)len); // Create a new Bitmap object, passing the array // of bytes to the constructor of a MemoryStream. using (Bitmap studentImage = new Bitmap(new MemoryStream(buffer))) { studentImage.Save(imagePath); } } } } else { imagePath = null; } tableReader.Close(); } return(imagePath); } //------------------------------
public long GetBytes(int i, long fieldOffset, byte[] buffer, int bufferOffset, int length) { return(_reader.GetBytes(i, fieldOffset, buffer, bufferOffset, length)); }
}//-------------------------- //this procedure gets the student image path public void InitializePersonImages(CommonExchange.SysAccess userInfo, String personSysIdList, String startUpPath, ProgressBar pgbBase, Label lblBase) { try { DataTable imageTable = new DataTable("ImageTable"); using (RemoteClient.RemCntBaseManager remClient = new RemoteClient.RemCntBaseManager()) { Int32 count = 0; String[] strSplit = personSysIdList.Split(','); String newPersonSysIdList = String.Empty; pgbBase.Maximum = strSplit.Length * 2; this.DeletePersonImagesDirectory(startUpPath); //creates the directory DirectoryInfo dirInfo = new DirectoryInfo(CommonExchange.SystemConfiguration.PersonImagesFolder(startUpPath)); dirInfo.Create(); dirInfo.Attributes = FileAttributes.Hidden; Int32 x = 0; foreach (String id in strSplit) { if (count <= 200) { newPersonSysIdList += id + ", "; strSplit[x] = String.Empty; pgbBase.PerformStep(); } else if (count > 200) { imageTable = remClient.SelectPersonImagesPersonInformation(userInfo, newPersonSysIdList); using (DataTableReader tableReader = new DataTableReader(imageTable)) { if (tableReader.HasRows) { Int32 picColumn = 1; while (tableReader.Read()) { if (!tableReader.IsDBNull(picColumn)) { String imagePath = CommonExchange.SystemConfiguration.PersonImagesFolder(startUpPath) + @"\"; imagePath += tableReader["original_name"].ToString(); long len = tableReader.GetBytes(picColumn, 0, null, 0, 0); // Create a buffer to hold the bytes, and then // read the bytes from the DataTableReader. Byte[] buffer = new Byte[len]; tableReader.GetBytes(picColumn, 0, buffer, 0, (int)len); // Create a new Bitmap object, passing the array // of bytes to the constructor of a MemoryStream. using (Bitmap studentImage = new Bitmap(new MemoryStream(buffer))) { if (!File.Exists(imagePath)) { studentImage.Save(imagePath); } } } pgbBase.PerformStep(); lblBase.Text = "Copying images..." + tableReader["original_name"].ToString(); lblBase.Refresh(); Application.DoEvents(); } } tableReader.Close(); } count = 0; newPersonSysIdList = String.Empty; imageTable.Rows.Clear(); Thread.Sleep(200); } //pgbBase.PerformStep(); count++; } if (!String.IsNullOrEmpty(newPersonSysIdList)) { imageTable = remClient.SelectPersonImagesPersonInformation(userInfo, newPersonSysIdList); using (DataTableReader tableReader = new DataTableReader(imageTable)) { if (tableReader.HasRows) { Int32 picColumn = 1; while (tableReader.Read()) { if (!tableReader.IsDBNull(picColumn)) { String imagePath = CommonExchange.SystemConfiguration.PersonImagesFolder(startUpPath) + @"\"; imagePath += tableReader["original_name"].ToString(); long len = tableReader.GetBytes(picColumn, 0, null, 0, 0); // Create a buffer to hold the bytes, and then // read the bytes from the DataTableReader. Byte[] buffer = new Byte[len]; tableReader.GetBytes(picColumn, 0, buffer, 0, (int)len); // Create a new Bitmap object, passing the array // of bytes to the constructor of a MemoryStream. using (Bitmap studentImage = new Bitmap(new MemoryStream(buffer))) { if (!File.Exists(imagePath)) { studentImage.Save(imagePath); } } } pgbBase.PerformStep(); lblBase.Text = "Coping images..." + tableReader["original_name"].ToString(); lblBase.Refresh(); Application.DoEvents(); } } tableReader.Close(); } //pgbBase.PerformStep(); } } } catch (Exception ex) { RemoteClient.ProcStatic.ShowErrorDialog(ex.Message, "Error"); //DataTable imageTable = new DataTable("ImageTable"); //using (RemoteClient.RemCntBaseManager remClient = new RemoteClient.RemCntBaseManager()) //{ // Int32 count = 0; // String[] strSplit = personSysIdList.Split(','); // String newPersonSysIdList = String.Empty; // Int32 x = 0; // foreach (String id in strSplit) // { // if (count <= 200) // { // newPersonSysIdList += id + ", "; // strSplit[x] = String.Empty; // pgbBase.PerformStep(); // } // else if (count > 200) // { // imageTable = remClient.SelectPersonImagesPersonInformation(userInfo, newPersonSysIdList); // using (DataTableReader tableReader = new DataTableReader(imageTable)) // { // if (tableReader.HasRows) // { // Int32 picColumn = 1; // while (tableReader.Read()) // { // if (!tableReader.IsDBNull(picColumn)) // { // String imagePath = CommonExchange.SystemConfiguration.PersonImagesFolder(startUpPath) + @"\"; // imagePath += tableReader["original_name"].ToString(); // long len = tableReader.GetBytes(picColumn, 0, null, 0, 0); // // Create a buffer to hold the bytes, and then // // read the bytes from the DataTableReader. // Byte[] buffer = new Byte[len]; // tableReader.GetBytes(picColumn, 0, buffer, 0, (int)len); // // Create a new Bitmap object, passing the array // // of bytes to the constructor of a MemoryStream. // using (Bitmap studentImage = new Bitmap(new MemoryStream(buffer))) // { // if (!File.Exists(imagePath)) // { // studentImage.Save(imagePath); // } // } // } // } // } // tableReader.Close(); // } // count = 0; // imageTable.Rows.Clear(); // pgbBase.PerformStep(); // Thread.Sleep(200); // } // count++; // x++; // } //} } }//------------------------------
}//------------------------------ //this function gets the student image path public void InitializePersonImages(CommonExchange.SysAccess userInfo, String personSysIdList, List <CommonExchange.Person> personInfoList, String startUp) { try { DataTable imageTable; using (RemoteClient.RemCntBaseManager remClient = new RemoteClient.RemCntBaseManager()) { imageTable = remClient.SelectPersonImagesPersonInformation(userInfo, personSysIdList); } using (DataTableReader tableReader = new DataTableReader(imageTable)) { if (tableReader.HasRows) { Int32 picColumn = 1; while (tableReader.Read()) { CommonExchange.Person personInfo = new CommonExchange.Person(); String imagePath = String.Empty; foreach (CommonExchange.Person list in personInfoList) { if (String.Equals(tableReader["sysid_person"].ToString(), list.PersonSysId)) { personInfo = list; imagePath = personInfo.PersonImagesFolder(startUp); break; } } RemoteClient.ProcStatic.DeleteDirectory(imagePath); //creates the directory DirectoryInfo dirInfo = new DirectoryInfo(imagePath); dirInfo.Create(); dirInfo.Attributes = FileAttributes.Hidden; if (!tableReader.IsDBNull(picColumn)) { imagePath += tableReader["original_name"].ToString(); long len = tableReader.GetBytes(picColumn, 0, null, 0, 0); // Create a buffer to hold the bytes, and then // read the bytes from the DataTableReader. Byte[] buffer = new Byte[len]; tableReader.GetBytes(picColumn, 0, buffer, 0, (int)len); // Create a new Bitmap object, passing the array // of bytes to the constructor of a MemoryStream. using (Bitmap studentImage = new Bitmap(new MemoryStream(buffer))) { if (!File.Exists(imagePath)) { studentImage.Save(imagePath); } } } } } tableReader.Close(); } } catch// (Exception ex) { //DataTable imageTable; //using (RemoteClient.RemCntBaseManager remClient = new RemoteClient.RemCntBaseManager()) //{ // imageTable = remClient.SelectPersonImagesPersonInformation(userInfo, personSysIdList); //} //using (DataTableReader tableReader = new DataTableReader(imageTable)) //{ // if (tableReader.HasRows) // { // Int32 picColumn = 1; // while (tableReader.Read()) // { // CommonExchange.Person personInfo = new CommonExchange.Person(); // String imagePath = String.Empty; // foreach (CommonExchange.Person list in personInfoList) // { // if (String.Equals(tableReader["sysid_person"].ToString(), list.PersonSysId)) // { // personInfo = list; // imagePath = personInfo.PersonImagesFolder(startUp); // break; // } // } // if (!tableReader.IsDBNull(picColumn)) // { // imagePath += tableReader["original_name"].ToString(); // long len = tableReader.GetBytes(picColumn, 0, null, 0, 0); // // Create a buffer to hold the bytes, and then // // read the bytes from the DataTableReader. // Byte[] buffer = new Byte[len]; // tableReader.GetBytes(picColumn, 0, buffer, 0, (int)len); // // Create a new Bitmap object, passing the array // // of bytes to the constructor of a MemoryStream. // using (Bitmap studentImage = new Bitmap(new MemoryStream(buffer))) // { // if (!File.Exists(imagePath)) // { // studentImage.Save(imagePath); // } // } // } // } // } // tableReader.Close(); //} } }//------------------------------