Beispiel #1
0
        public async Task <string> UploadRAWFileAsync(HttpPostedFileBase rawFile, string patientNumber)
        {
            string PatientRawFilePath = null;

            if (rawFile == null)
            {
                return(null);
            }
            try
            {
                CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference(PSScansRAW);

                string PatientRawFileName = Guid.NewGuid().ToString() + "-" + patientNumber + "-RAWSCAN";

                CloudBlockBlob cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference(PatientRawFileName);

                cloudBlockBlob.Properties.ContentType = rawFile.GetType().Name;

                await cloudBlockBlob.UploadFromStreamAsync(rawFile.InputStream);

                PatientRawFilePath = cloudBlockBlob.Uri.ToString();
            }
            catch (Exception)
            {
                return(null);
            }
            return(PatientRawFilePath);
        }
Beispiel #2
0
        /// <summary>
        /// 压缩并保存图片
        /// </summary>
        /// <returns></returns>
        public static string CompressImg(HttpPostedFileBase file, int size)
        {
            var    type      = file.GetType();
            string directory = HttpRuntime.AppDomainAppPath.ToString();
            string path      = "/Upload";
            string extension = Path.GetExtension(file.FileName);

            CreateCatalog(directory, path);

            path = string.Format("{0}/{1}", path, DateTime.Now.ToString("yyyyMMdd"));

            CreateCatalog(directory, path);

            path = string.Format("{0}/{1}{2}{3}", path, DateTime.Now.ToString("yyyyMMddHHmmssfff"), new Random(GetRandomSeed()).Next(1, 1000), extension);

            GC.Collect();

            return(CreateThumbnail(GetLocalPath(path), size, file.InputStream) ? path : "");
        }
Beispiel #3
0
        public ActionResult addimage(PieceJoint model, HttpPostedFileBase image1)
        {
            var db = new HELPDESK3Entities();

            if (image1 != null)
            {
                model.img      = new byte[image1.ContentLength];
                model.filename = image1.FileName;
                model.type     = "" + image1.GetType();
                image1.InputStream.Read(model.img, 0, image1.ContentLength);
            }

            db.PieceJoint.Add(model);
            db.SaveChanges();
            ViewBag.filename = image1.FileName;
            List <file> list = new List <file>();

            const string connect = @"Server=WAHID;Database=HELPDESK3;Trusted_Connection=True;";

            using (var conn = new SqlConnection(connect))
            {
                var qry = "SELECT [IdPiece],[filename] FROM PieceJoint ";
                var cmd = new SqlCommand(qry, conn);

                conn.Open();
                SqlDataReader result = cmd.ExecuteReader();
                while (result.Read())
                {
                    list.Add(new file(
                                 result.GetInt32(0),
                                 result.GetString(1)
                                 ));
                }
            }


            ViewBag.list = list;


            return(View(model));
        }
        public ActionResult AddSave(Review review, HttpPostedFileBase upload)
        {
            // missing PublishDate
            if (review.PublishDate == DateTime.MinValue)
            {
                TempData["Error"] = TempData["Error"] + " Publish Date was empty";
            }


            // missing Type
            if (String.IsNullOrEmpty(review.ReviewType))
            {
                TempData["Error"] = TempData["Error"] + " Review Type was empty";
            }


            // Odd way to handle empty image, but it works
            try
            {
                if (upload.GetType() == typeof(HttpPostedFileBase))
                {
                    // This will never hit
                    TempData["Error"] = null;
                }
            }
            catch {
                TempData["Error"] = TempData["Error"] + " Image was not uploaded correctly";
            }

            // missing header
            if (String.IsNullOrEmpty(review.ReviewHeader))
            {
                TempData["Error"] = TempData["Error"] + " Title was empty";
            }


            // missing review
            if (String.IsNullOrEmpty(review.ReviewText))
            {
                TempData["Error"] = TempData["Error"] + " Review was empty";
            }

            // return with error
            if (TempData["Error"] != null)
            {
                return(View("Add"));
            }


            if (upload.ContentLength > 3500000)
            {
                TempData["Error"] = "File Size is Too Large";
                return(View("Add"));
            }


            // final catch if somehow there is an issue, but gets by other checks
            if (!ModelState.IsValid)
            {
                TempData["Error"] = "Unable to process, form data was missing";
                return(View("Add"));
            }

            reviewRepository = new ReviewRepository();

            if (upload != null && upload.ContentLength > 0)
            {
                var image = new Image
                {
                    ImageName   = System.IO.Path.GetFileName(upload.FileName),
                    ContentType = upload.ContentType
                };
                using (var reader = new System.IO.BinaryReader(upload.InputStream))
                {
                    image.ImageData = reader.ReadBytes(upload.ContentLength);
                }
                review.Image = image;
            }

            reviewRepository.Create(review);

            TempData["Success"] = "Successfully Added Review ";
            return(View("Index"));
            // If I ever wanted to show addition right away:
            // return RedirectToAction("Index", "Home");
        }
        public void UploadUser()
        {
            GridView           GridView1 = new GridView();
            int                r         = Request.Files.Count;
            HttpPostedFileBase file      = Request.Files[0]; //Uploaded file
            //Use the following properties to get file's name, size and MIMEType
            int    fileSize = file.ContentLength;
            string fileName = file.FileName;

            string[] values    = fileName.Split('.');
            string   SheetName = values[0];
            string   filetype  = file.GetType().ToString();

            //OleDbConnection objConn = null;
            //System.Data.DataTable dt1 = null;

            //fileName = Server.MapPath(Path.Combine("~/Content/",Path.ChangeExtension(fileName, ".xlsx")));
            //fileName = Server.MapPath(Path.Combine("~/Content/MyExcelFile_files/", Path.ChangeExtension(fileName, ".xlsx")));
            //file.SaveAs(fileName);
            fileName = Server.MapPath(Path.Combine("~/Content/", fileName));


            file.SaveAs(Path.ChangeExtension(fileName, ".xlsx"));
            using (SpreadsheetDocument doc = SpreadsheetDocument.Open(fileName, false))
            {
                //Read the first Sheet from Excel file.
                Sheet sheet = doc.WorkbookPart.Workbook.Sheets.GetFirstChild <Sheet>();

                //Get the Worksheet instance.
                Worksheet worksheet = (doc.WorkbookPart.GetPartById(sheet.Id.Value) as WorksheetPart).Worksheet;

                //Fetch all the rows present in the Worksheet.
                IEnumerable <Row> rows = worksheet.GetFirstChild <SheetData>().Descendants <Row>();

                //Create a new DataTable.
                DataTable dt = new DataTable();

                //Loop through the Worksheet rows.
                foreach (Row row in rows)
                {
                    //Use the first row to add columns to DataTable.
                    if (row.RowIndex.Value == 1)
                    {
                        foreach (Cell cell in row.Descendants <Cell>())
                        {
                            dt.Columns.Add(GetValue(doc, cell));
                        }
                    }
                    else
                    {
                        //Add rows to DataTable.
                        dt.Rows.Add();
                        int i = 0;
                        foreach (Cell cell in row.Descendants <Cell>())
                        {
                            dt.Rows[dt.Rows.Count - 1][i] = GetValue(doc, cell);
                            i++;
                        }
                    }
                }
                //GridView1.DataSource = dt;
                //GridView1.DataBind();
                int AlreadyExist = 0; string PhoneNumber = "", EmailAddress = "", PhoneNumberSaved = "", EmailAddressSaved = "";
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i][1].ToString() != string.Empty)
                    {
                        var user = new ApplicationUser {
                            UserName = admin.GenerateUserName(), Email = dt.Rows[i][2].ToString(), PhoneNumber = dt.Rows[i][1].ToString()
                        };
                        int count = admin.GetUserDetails(generic.GetSubscriberId(User.Identity.GetUserId())).Where(c => c.PhoneNumber == dt.Rows[i][1].ToString() || c.Email == dt.Rows[i][2].ToString()).Count();
                        if (count == 0)
                        {
                            rm.InsertBulkUser(user.Id, generic.GetSubscriberId(User.Identity.GetUserId()), dt.Rows[i][1].ToString(), dt.Rows[i][2].ToString(), dt.Rows[i][3].ToString(), dt.Rows[i][0].ToString(), dt.Rows[i][4].ToString());
                            PhoneNumberSaved  = PhoneNumberSaved + dt.Rows[i][1].ToString() + ",";
                            EmailAddressSaved = EmailAddressSaved + dt.Rows[i][2].ToString() + ",";
                        }
                        else
                        {
                            AlreadyExist = AlreadyExist + 1;
                            PhoneNumber  = PhoneNumber + dt.Rows[i][1].ToString() + ",";
                            EmailAddress = EmailAddress + dt.Rows[i][2].ToString() + ",";
                        }
                    }
                }

                doc.Close();
                if (PhoneNumberSaved != "" && EmailAddressSaved != "")
                {
                    ViewBag.BulkUserUpdated         = true;
                    ViewBag.ExistedPhoneNumberSaved = PhoneNumberSaved.TrimEnd(',');
                    ViewBag.ExistedEmailSaved       = PhoneNumberSaved.TrimEnd(',');
                }
                else if (PhoneNumber != "" && EmailAddress != "")
                {
                    ViewBag.AlreadyExist       = true;
                    ViewBag.ExistedPhoneNumber = PhoneNumber.TrimEnd(',');
                    ViewBag.ExistedEmail       = EmailAddress.TrimEnd(',');
                }
                System.GC.Collect();
                System.GC.WaitForPendingFinalizers();
                if (System.IO.File.Exists(fileName))
                {
                    if (System.IO.File.Exists(fileName))
                    {
                        System.IO.File.Delete(fileName);
                    }
                }
            }

            TempData["BulkUserUpdated"] = true;
        }
        public void importdatafromexcel(string excelfilepath)
        {
            GridView           GridView1 = new GridView();
            int                r         = Request.Files.Count;
            HttpPostedFileBase file      = Request.Files[0]; //Uploaded file
            //Use the following properties to get file's name, size and MIMEType
            int    fileSize = file.ContentLength;
            string fileName = file.FileName;

            string[] values    = fileName.Split('.');
            string   SheetName = values[0];
            string   filetype  = file.GetType().ToString();


            string ExistedNumber = string.Empty;

            //fileName = Server.MapPath(Path.Combine("~/Content/",Path.ChangeExtension(fileName, ".xlsx")));
            //fileName = Server.MapPath(Path.Combine("~/Content/MyExcelFile_files/", Path.ChangeExtension(fileName, ".xlsx")));
            //file.SaveAs(fileName);
            fileName = Server.MapPath(Path.Combine("~/Content/", fileName));


            file.SaveAs(Path.ChangeExtension(fileName, ".xlsx"));
            using (SpreadsheetDocument doc = SpreadsheetDocument.Open(fileName, false))
            {
                //Read the first Sheet from Excel file.
                Sheet sheet = doc.WorkbookPart.Workbook.Sheets.GetFirstChild <Sheet>();

                //Get the Worksheet instance.
                Worksheet worksheet = (doc.WorkbookPart.GetPartById(sheet.Id.Value) as WorksheetPart).Worksheet;

                //Fetch all the rows present in the Worksheet.
                IEnumerable <Row> rows = worksheet.GetFirstChild <SheetData>().Descendants <Row>();

                //Create a new DataTable.
                DataTable dt = new DataTable();

                //Loop through the Worksheet rows.
                foreach (Row row in rows)
                {
                    //Use the first row to add columns to DataTable.
                    if (row.RowIndex.Value == 1)
                    {
                        foreach (Cell cell in row.Descendants <Cell>())
                        {
                            dt.Columns.Add(GetValue(doc, cell));
                        }
                    }
                    else
                    {
                        //Add rows to DataTable.
                        dt.Rows.Add();
                        int i = 0;
                        foreach (Cell cell in row.Descendants <Cell>())
                        {
                            dt.Rows[dt.Rows.Count - 1][i] = GetValue(doc, cell);
                            i++;
                        }
                    }
                }
                GridView1.DataSource = dt;
                GridView1.DataBind();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    //DateTime today = System.DateTime.Now;
                    DateTime today     = Convert.ToDateTime(dt.Rows[i][4]);
                    bool     IsPresent = false;
                    if (dt.Rows[i][5].ToString() == "P" || dt.Rows[i][5].ToString() == "true")
                    {
                        IsPresent = true;
                    }
                    else
                    {
                        IsPresent = false;
                    }
                    if (!rm.IsStudentAttendenceExists(dt.Rows[i][1].ToString(), dt.Rows[i][2].ToString(), today))
                    {
                        rm.InsertStudentAttendence(dt.Rows[i][1].ToString(), dt.Rows[i][2].ToString(), today, IsPresent, dt.Rows[i][6].ToString());
                    }
                }
                doc.Close();
                System.GC.Collect();
                System.GC.WaitForPendingFinalizers();
                if (System.IO.File.Exists(fileName))
                {
                    if (System.IO.File.Exists(fileName))
                    {
                        System.IO.File.Delete(fileName);
                    }
                }
            }
            //string path = Path.ChangeExtension(excelfilepath, ".xlsx");
            ////string excelConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1;\"";
            //string excelConnection = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES;\"";
            ////string path = @"E:\Blink\Blink\Content\MyExcelFile.xls";
            ////string path = Server.MapPath(excelfilepath);
            //string ssqltable = "CandidateAttendances";
            //HttpPostedFileBase file = Request.Files[0]; //Uploaded file
            ////Use the following properties to get file's name, size and MIMEType
            //int fileSize = file.ContentLength;
            //string fileName = file.FileName;
            //string[] values = fileName.Split('.');
            //string SheetName = values[0];
            //string filetype = file.GetType().ToString();
            //OleDbConnection objConn = null;
            //System.Data.DataTable dt1 = null;
            //objConn = new OleDbConnection(excelConnection);
            //// Open connection with the database.
            //objConn.Open();
            //// Get the data table containg the schema guid.
            //dt1 = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);


            //String[] excelSheets = new String[dt1.Rows.Count];
            //int i1 = 0;

            //// Add the sheet name to the string array.
            //foreach (DataRow row in dt1.Rows)
            //{
            //    excelSheets[i1] = row["TABLE_NAME"].ToString();
            //    i1++;
            //}
            //// make sure your sheet name is correct, here sheet name is sheet1, so you can change your sheet name if have     different
            //string myexceldataquery = "select * from [" + excelSheets[0] + "]";
            //try
            //{
            //    //create our connection strings
            //    string ssqlconnectionstring = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
            //    //execute a query to erase any previous data from our destination table
            //    string sclearsql = "select * from " + ssqltable;
            //    SqlConnection sqlconn = new SqlConnection(ssqlconnectionstring);
            //    SqlCommand sqlcmd = new SqlCommand(sclearsql, sqlconn);
            //    sqlconn.Open();
            //    sqlcmd.ExecuteNonQuery();
            //    sqlconn.Close();


            //    using (OleDbDataAdapter adaptor = new OleDbDataAdapter(myexceldataquery, excelConnection))
            //    {
            //        DataSet ds = new DataSet();
            //        adaptor.Fill(ds);
            //        System.Data.DataTable dt = ds.Tables[0];
            //        for (int i = 0; i < dt.Rows.Count; i++)
            //        {
            //            //DateTime today = System.DateTime.Now;
            //            DateTime today = Convert.ToDateTime(dt.Rows[i][4]);
            //            bool IsPresent = false;
            //            if (dt.Rows[i][5].ToString() == "P" || dt.Rows[i][5].ToString() == "true")
            //            {
            //                IsPresent = true;
            //            }
            //            else
            //            {
            //                IsPresent = false;
            //            }
            //            if (!rm.IsStudentAttendenceExists(dt.Rows[i][1].ToString(), dt.Rows[i][2].ToString(), today))
            //                rm.InsertStudentAttendence(dt.Rows[i][1].ToString(), dt.Rows[i][2].ToString(), today, IsPresent, dt.Rows[i][6].ToString());
            //        }
            //    }
            //}
            //catch (Exception ex)
            //{
            //    ex.ToString();
            //    //handle exception
            //}
        }