コード例 #1
0
        }//--------------------------

        //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);
        } //------------------------------
コード例 #2
0
        }//--------------------------

        //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++;
                //    }
                //}
            }
        }//------------------------------
コード例 #3
0
        }//------------------------------

        //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();
                //}
            }
        }//------------------------------