Example #1
0
 internal static BaseReport FromReportId(Guid ReportId)
 {
     //if there is a reportId in the ReportStore get the report data Deserialize and return
     using (System.Data.SqlClient.SqlConnection connection = ReportProvider.DatabaseConnection)
     {
         connection.Open();
         using (System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand("Select reportBinary from ReportStore Where reportId = @reportId", connection))
         {
             command.Parameters.AddWithValue("reportId", ReportId);
             using (System.Data.SqlClient.SqlDataReader reader = command.ExecuteReader())
             {
                 if (reader.Read())
                 {
                     return(Deserialize(reader.GetSqlBinary(0).Value));
                 }
                 else
                 {
                     return(null);
                 }
             }
         }
     }
 }
        private void LoadDB()
        {
            System.Data.SqlClient.SqlConnection sqlConnect = null;
            try
            {
                sqlConnect = new System.Data.SqlClient.SqlConnection("server=" + SQLServerAddress + "," + SQLServerPort + "; initial catalog=" + DatabaseName + "; Integrated Security=SSPI");
                sqlConnect.Open();

                System.Data.SqlClient.SqlCommand sqlCmd = new System.Data.SqlClient.SqlCommand("SELECT ImageFileName, FacePositionXc, FacePositionYc, FacePositionW, FacePositionAngle, Eye1X, Eye1Y, Eye2X, Eye2Y, Template, Image, FaceImage FROM FaceList", sqlConnect);

                System.Data.SqlClient.SqlDataReader reader = sqlCmd.ExecuteReader();
                while (reader.Read())
                {
                    TFaceRecord fr = new TFaceRecord();
                    fr.ImageFileName = reader.GetString(0);

                    fr.FacePosition       = new FSDK.TFacePosition();
                    fr.FacePosition.xc    = reader.GetInt32(1);
                    fr.FacePosition.yc    = reader.GetInt32(2);
                    fr.FacePosition.w     = reader.GetInt32(3);
                    fr.FacePosition.angle = reader.GetFloat(4);

                    fr.FacialFeatures      = new FSDK.TPoint[2];
                    fr.FacialFeatures[0]   = new FSDK.TPoint();
                    fr.FacialFeatures[0].x = reader.GetInt32(5);
                    fr.FacialFeatures[0].y = reader.GetInt32(6);
                    fr.FacialFeatures[1]   = new FSDK.TPoint();
                    fr.FacialFeatures[1].x = reader.GetInt32(7);
                    fr.FacialFeatures[1].y = reader.GetInt32(8);

                    fr.Template = new byte[FSDK.TemplateSize];
                    reader.GetBytes(9, 0, fr.Template, 0, FSDK.TemplateSize);

                    Image img      = Image.FromStream(new System.IO.MemoryStream(reader.GetSqlBinary(10).Value));
                    Image img_face = Image.FromStream(new System.IO.MemoryStream(reader.GetSqlBinary(11).Value));
                    fr.image     = new FSDK.CImage(img);
                    fr.faceImage = new FSDK.CImage(img_face);


                    FaceList.Add(fr);

                    imageList1.Images.Add(fr.faceImage.ToCLRImage());
                    string fn = fr.ImageFileName;
                    listView1.Items.Add((imageList1.Images.Count - 1).ToString(), fn.Split('\\')[fn.Split('\\').Length - 1], imageList1.Images.Count - 1);

                    textBox1.Text += "File '" + fn + "' read from database\r\n";

                    img.Dispose();
                    img_face.Dispose();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Exception on loading database");
            }
            finally
            {
                if (sqlConnect != null)
                {
                    sqlConnect.Close();
                }
            }
        }