Example #1
0
 public static List <Class.File> GetFiles(Class.User LoggedInUser)
 {
     StartConnection();
     try
     {
         if (LoggedInUser != null)
         {
             using (MySqlCommand = new MySqlCommand("select file_user.FileID, file_user.SendToID, file.Data, file.isText, file.DateTime, user.ID, user.Email, user.Name from file_user join file on file.ID=file_user.FileID join user on user.ID=file_user.UserID where file_user.SendToID=@sendTo", MySqlConnection))
             {
                 MySqlCommand.Parameters.AddWithValue("@sendTo", LoggedInUser.Email);
                 MySqlConnection.Open();
                 List <Class.File> Files  = new List <Class.File>();
                 MySqlDataReader   reader = MySqlCommand.ExecuteReader();
                 while (reader.Read())
                 {
                     Class.File file = new Class.File();
                     file.ID          = (int)reader["fileid"];
                     file.EmailToUser = (string)reader["sendtoid"];
                     file.Data        = (string)reader["data"];
                     file.isText      = (bool)reader["IsText"];
                     file.Datetime    = (DateTime)reader["datetime"];
                     file.FromUser    = new Class.User()
                     {
                         Email = (string)reader["email"],
                         ID    = (int)reader["ID"],
                         Name  = (string)reader["name"]
                     };
                     Files.Add(file);
                 }
                 if (MySqlConnection.State != System.Data.ConnectionState.Closed)
                 {
                     MySqlConnection.Close();
                 }
                 return(Files);
             }
         }
         else
         {
             throw new Exception("You need to be logged in to perform this action!");
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Example #2
0
 public static string SendData(Class.File file)
 {
     StartConnection();
     try
     {
         using (MySqlCommand = new MySqlCommand("select user.ID from user where user.email=@email", MySqlConnection))
         {
             MySqlCommand.Parameters.AddWithValue("@email", file.EmailToUser.ToLower());
             int SendToID = 0;
             MySqlConnection.Open();
             MySqlDataReader reader = MySqlCommand.ExecuteReader();
             while (reader.Read())
             {
                 SendToID = (int)reader["ID"];
             }
             if (MySqlConnection.State != System.Data.ConnectionState.Closed)
             {
                 MySqlConnection.Close();
             }
             if (SendToID != 0)
             {
                 using (MySqlCommand = new MySqlCommand("insert into file (ID,data,IsText,datetime) values('',@data,@istext,@datetime)", MySqlConnection))
                 {
                     if (!file.isText)
                     {
                         string fileLocation = UploadFile(file.Data);
                         MySqlCommand.Parameters.AddWithValue("@data", fileLocation ?? throw new Exception("Couldn't save file to server"));
                         MySqlCommand.Parameters.AddWithValue("@istext", file.isText);
                         MySqlCommand.Parameters.AddWithValue("@datetime", file.Datetime);
                     }
                     else
                     {
                         MySqlCommand.Parameters.AddWithValue("@data", file.Data);
                         MySqlCommand.Parameters.AddWithValue("@istext", file.isText);
                         MySqlCommand.Parameters.AddWithValue("@datetime", file.Datetime);
                     }
                     MySqlConnection.Open();
                     MySqlCommand.ExecuteScalar();
                     long FileID = MySqlCommand.LastInsertedId;
                     if (MySqlConnection.State != System.Data.ConnectionState.Closed)
                     {
                         MySqlConnection.Close();
                     }
                     if (FileID != 0)
                     {
                         using (MySqlCommand = new MySqlCommand("insert into file_user (fileid,userid,sendtoid) values(@fileid,@userid,@sendtoid)", MySqlConnection))
                         {
                             MySqlCommand.Parameters.AddWithValue("@fileid", FileID);
                             MySqlCommand.Parameters.AddWithValue("@userid", file.FromUser.ID);
                             MySqlCommand.Parameters.AddWithValue("@sendtoid", file.EmailToUser);
                             MySqlConnection.Open();
                             MySqlCommand.ExecuteScalar();
                             if (MySqlConnection.State != System.Data.ConnectionState.Closed)
                             {
                                 MySqlConnection.Close();
                             }
                             return("Send succesfully");
                         }
                     }
                     else
                     {
                         throw new Exception("File isn't saved");
                     }
                 }
             }
             else
             {
                 throw new Exception("No user found with the specified e-mailadress");
             }
         }
     }
     catch (Exception ex)
     {
         if (MySqlConnection.State != System.Data.ConnectionState.Closed)
         {
             MySqlConnection.Close();
         }
         return("Something went wrong: " + ex.Message);
     }
 }
Example #3
0
        public int SaveImage(string Path, string path)
        {
            DirectoryInfo d = new DirectoryInfo(Path);

            FileInfo[] files = d.GetFiles();
            int        i     = 1;



            foreach (FileInfo f in files)
            {
                string PathSave = HttpContext.Current.Server.MapPath("~/DicomImage/" + path);

                if (!Directory.Exists(PathSave))
                {
                    Directory.CreateDirectory(PathSave);
                }


                Class.File file = new Class.File();
                file.NameFile = f.Name;
                file.TypeFile = f.Extension;

                DicomDecoder dd = new DicomDecoder();
                dd.DicomFileName = f.FullName;
                double winCentre       = dd.windowCentre;
                double winWidth        = dd.windowWidth;
                int    samplesPerPixel = dd.samplesPerPixel;
                bool   signedImage     = dd.signedImage;
                int    minPixelValue   = 1;
                int    maxPixelValue   = 0;
                PathSave += i + ".png";


                TypeOfDicomFile typeOfDicomFile = dd.typeofDicomFile;

                int imageWidth  = dd.width;
                int imageHeight = dd.height;



                bmp = new Bitmap(imageWidth, imageHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

                dd.GetPixels8(ref pixels8);
                dd.GetPixels16(ref pixels16);
                dd.GetPixels24(ref pixels24);

                if (pixels8 != null)
                {
                    minPixelValue = pixels8.Min();
                    maxPixelValue = pixels8.Max();
                    // Bug fix dated 24 Aug 2013 - for proper window/level of signed images
                    // Thanks to Matias Montroull from Argentina for pointing this out.
                    if (dd.signedImage)
                    {
                        winCentre -= char.MinValue;
                    }

                    if (Math.Abs(winWidth) < 0.001)
                    {
                        winWidth = maxPixelValue - minPixelValue;
                    }

                    if ((winCentre == 0) ||
                        (minPixelValue > winCentre) || (maxPixelValue < winCentre))
                    {
                        winCentre = (maxPixelValue + minPixelValue) / 2;
                    }
                    ResetValues(winWidth, winCentre);
                    pix8 = pixels8;
                    ComputeLookUpTable8();

                    CreateImage8(imageWidth, imageHeight);
                }
                else if (pixels16 != null)
                {
                    minPixelValue = pixels16.Min();
                    maxPixelValue = pixels16.Max();

                    // Bug fix dated 24 Aug 2013 - for proper window/level of signed images
                    // Thanks to Matias Montroull from Argentina for pointing this out.
                    if (dd.signedImage)
                    {
                        winCentre -= short.MinValue;
                    }

                    if (Math.Abs(winWidth) < 0.001)
                    {
                        winWidth = maxPixelValue - minPixelValue;
                    }

                    if ((winCentre == 0) ||
                        (minPixelValue > winCentre) || (maxPixelValue < winCentre))
                    {
                        winCentre = (maxPixelValue + minPixelValue) / 2;
                    }

                    ResetValues(winWidth, winCentre);
                    pix16 = pixels16;
                    ComputeLookUpTable16();

                    CreateImage16(imageWidth, imageHeight);
                }
                else if (pixels24 != null)
                {
                    minPixelValue = pixels8.Min();
                    maxPixelValue = pixels8.Max();
                    // Bug fix dated 24 Aug 2013 - for proper window/level of signed images
                    // Thanks to Matias Montroull from Argentina for pointing this out.
                    if (dd.signedImage)
                    {
                        winCentre -= char.MinValue;
                    }

                    if (Math.Abs(winWidth) < 0.001)
                    {
                        winWidth = maxPixelValue - minPixelValue;
                    }

                    if ((winCentre == 0) ||
                        (minPixelValue > winCentre) || (maxPixelValue < winCentre))
                    {
                        winCentre = (maxPixelValue + minPixelValue) / 2;
                    }

                    ResetValues(winWidth, winCentre);
                    pix24 = pixels24;
                    ComputeLookUpTable8();

                    CreateImage24(imageWidth, imageHeight);
                }

                i++;
                if (bmp != null)
                {
                    bmp.Save(PathSave, ImageFormat.Png);
                }
            }

            return(i);
        }