public async Task <IActionResult> Create(ImageCreateEditViewModel vm, IEnumerable <IFormFile> images) { vm.AppUserId = User.UserGuidId(); if (ModelState.IsValid) { if (images != null) { //Convert Image to byte and save to database foreach (var file in images) { using (var ms = new MemoryStream()) { //image.Save(ms, new PngEncoder()); var imageBLL = new ImageBLL(); imageBLL.AppUserId = User.UserGuidId(); await file.CopyToAsync(ms); imageBLL.Picture = ms.ToArray(); imageBLL.ItemId = vm.ItemId; _bll.Images.Add(imageBLL); } } await _bll.SaveChangesAsync(); } return(RedirectToAction(nameof(Index))); } vm.ItemSelectList = new SelectList(await _bll.Items.GetAllAsync(User.UserGuidId()), nameof(ItemBLL.Id), nameof(ItemBLL.Description), vm.ItemId); return(View(vm)); }
protected void btnUpload_Click(object sender, EventArgs e) { ImageBLL imageBLL = new ImageBLL(); PhotographModel ph = new PhotographModel(); HttpPostedFile postedFile = FileUpload1.PostedFile; string filename = Path.GetFileName(postedFile.FileName); string fileExtension = Path.GetExtension(filename); int fileSize = postedFile.ContentLength; if (fileExtension.ToLower() == ".jpg" || fileExtension.ToLower() == ".gif" || fileExtension.ToLower() == ".png" || fileExtension.ToLower() == ".bmp") { Stream stream = postedFile.InputStream; BinaryReader binaryReader = new BinaryReader(stream); Byte[] bytes = binaryReader.ReadBytes((int)stream.Length); ph.ImageName = filename; ph.ImageSize = fileSize; ph.ImageData = bytes; imageBLL.InsertImage(ph); lblMessage.Visible = true; lblMessage.ForeColor = System.Drawing.Color.Green; lblMessage.Text = "Upload Successful"; } }
public ImageModel(string connectionString, string databaseEngine) { if (databaseEngine.ToLower() == "mysql") { objImageBLL = new ImageBLL(DatabaseEngine.MySQL, connectionString); } }
public ResultModel <List <dynamic> > GetAllPersonalPic([FromBody] JObject Model, [FromUri] PageModel pm) { ResultModel <List <dynamic> > msg = new ResultModel <List <dynamic> >(); var picmanage = JsonConvert.DeserializeObject <PicManage>(JsonConvert.SerializeObject(Model)); if (picmanage == null) { msg.Code = 2001; msg.Message = "参数错误"; return(msg); } if (string.IsNullOrEmpty(picmanage.UserCode)) { msg.Code = 2001; msg.Message = "参数错误"; return(msg); } if (string.IsNullOrEmpty(picmanage.UserCode)) { msg.Code = 2001; msg.Message = "参数错误"; return(msg); } if (true) { msg = new ImageBLL().GetAllPersonalPic(picmanage, pm); } else { msg.Code = 2001; msg.Message = "未授权"; } return(msg); }
public void ImageLoad() { ImageBLL imageBLL = new ImageBLL(); //int id = 1; //DataTable da; //da = adapter.GetImage(id); //byte[] bytes = (byte[])da.Rows[0]["ImageData"]; //string strBase64 = Convert.ToBase64String(bytes); byte[] image = imageBLL.LoadImage(); string strBase64 = Convert.ToBase64String(image); //return strBase64; Image1.ImageUrl = "data:Image/png;base64," + strBase64; }
public ResultModel <object> SavePicToDB([FromBody] JObject Model, [FromUri] Encrypt encrypt) { ResultModel <object> msg = new ResultModel <object>(); var userImage = JsonConvert.DeserializeObject <UserImage>(JsonConvert.SerializeObject(Model)); if (true)//encrypt.AccessToken == EncrypteComm.Md5Hex32(encrypt.TimeSpan + WebConfigOperation.CommSecretToken) { msg = new ImageBLL().SavePicToDB(userImage); } else { msg.Code = 2001; msg.Message = "未授权"; } return(msg); }
protected void ChangeImagebtn_Click(object sender, EventArgs e) { ImageBLL imageBLL = new ImageBLL(); HttpPostedFile postedFile = FileUpload1.PostedFile; string filename = Path.GetFileName(postedFile.FileName); string fileExtension = Path.GetExtension(filename); int fileSize = postedFile.ContentLength; if (fileExtension.ToLower() == ".jpg" || fileExtension.ToLower() == ".gif" || fileExtension.ToLower() == ".png" || fileExtension.ToLower() == ".bmp") { Stream stream = postedFile.InputStream; BinaryReader binaryReader = new BinaryReader(stream); Byte[] bytes = binaryReader.ReadBytes((int)stream.Length); int id = 1; imageBLL.ChangeImage(bytes, id); lblMessage.Visible = true; lblMessage.ForeColor = System.Drawing.Color.Green; lblMessage.Text = "Upload Successful"; ImageLoad(); } }
public bool SelectNodeInMap(object JSlng, object JSlat) { Console.WriteLine(JSlng.ToString() + JSlat.ToString()); double dou_lng, dou_lat; if (double.TryParse(JSlng.ToString(), out dou_lng) && double.TryParse(JSlat.ToString(), out dou_lat)) { NodeBLL nodeBll = new NodeBLL(); NodeData nodeData = nodeBll.GetDetailByPoint(dou_lng, dou_lat); if (nodeData != null) { curSelectNode = nodeData; ImageBLL imageBll = new ImageBLL(); ImageData imageData = imageBll.GetDetailByLastTime(nodeData.id); if (imageData != null) { curImageInMap = imageData; } else { curImageInMap = null; } return(true); } return(false); } else { curSelectNode = null; curImageInMap = null; return(false); } }
private void Photoing(object o) { DateTime dt = DateTime.Now; int[] pictureAttribute = new int[6]; pictureAttribute[0] = Resolution; pictureAttribute[1] = Whitebalance; pictureAttribute[2] = Bright; pictureAttribute[3] = Saturation; pictureAttribute[4] = Contrast; pictureAttribute[5] = Quanlity; string savePath = imageSavePath + "\\capture\\"; string fileName = dt.Year.ToString() + "-"; fileName += dt.Month.ToString() + "-"; fileName += dt.Day.ToString() + " _"; fileName += dt.Hour.ToString() + "-"; fileName += dt.Minute.ToString() + "-"; fileName += dt.Second.ToString() + ".jpg"; string fileFullPath = savePath + fileName; ThreadPool.QueueUserWorkItem(new WaitCallback(OperateImageCapture), pictureAttribute); bool flag = false; try { flag = communicateArmClient.GetPicture(fileFullPath, pictureAttribute); } catch (SocketException ex) { DealwithSocketException dealEx = new DealwithSocketException(ex); MessageBox.Show(dealEx.errorMessage); if (ex.SocketErrorCode == SocketError.ConnectionAborted) { armClient.IsLoseConnect = true; } return; } finally { isBusy = false; } if (flag) { if (pb.Image != null) //先清除上一次的图片 { pb.Image.Dispose(); } pb.Image = Image.FromFile(fileFullPath); if (fileFullPath != null) { //Show(fileFullPath); //srcBitmap = (Bitmap)Bitmap.FromFile(fileFullPath, true); ImageBLL imageBll = new ImageBLL(); ImageData imageData = new ImageData(); imageData.nodeid = nodeData.id; imageData.datetime = DateTime.Now; imageData.path = savePath; imageData.fullpath = fileFullPath; imageData.fileName = fileName; imageData.status = 1; if (imageBll.Insert(imageData)) { ShowControlWarnInMessageBox(true, "插入图像记录成功"); } else { ShowControlWarnInMessageBox(false, "插入图像记录失败"); } } } }
public async Task <IActionResult> Create(ItemCreateEditViewModel vm, IEnumerable <IFormFile> images) { vm.AppUserId = User.UserGuidId(); if (ModelState.IsValid) { var bllEntity = _mapper.Map(vm); _bll.Items.Add(bllEntity); await _bll.SaveChangesAsync(); vm.Id = bllEntity.Id; // Add item ownership var itemOwnershipBLL = new ItemOwnershipBLL(); itemOwnershipBLL.AppUserId = User.UserGuidId(); itemOwnershipBLL.CompanyId = vm.CompanyId == Guid.Empty ? null : vm.CompanyId; itemOwnershipBLL.ItemId = bllEntity.Id; _bll.ItemOwnerships.Add(itemOwnershipBLL); await _bll.SaveChangesAsync(); if (images != null) { foreach (var file in images) { using (var ms = new MemoryStream()) { //image.Save(ms, new PngEncoder()); var imageBLL = new ImageBLL(); imageBLL.AppUserId = User.UserGuidId(); await file.CopyToAsync(ms); imageBLL.Picture = ms.ToArray(); imageBLL.ItemId = bllEntity.Id; _bll.Images.Add(imageBLL); } } await _bll.SaveChangesAsync(); } // Add category to item var itemCategoryBLL = new ItemCategoryBLL(); itemCategoryBLL.AppUserId = User.UserGuidId(); itemCategoryBLL.CategoryId = vm.CategoryId; itemCategoryBLL.ItemId = bllEntity.Id; _bll.ItemCategories.Add(itemCategoryBLL); await _bll.SaveChangesAsync(); // Add prices var priceDayBLL = new PriceBLL(); priceDayBLL.AppUserId = User.UserGuidId(); priceDayBLL.ItemPrice = vm.ItemDayPrice; priceDayBLL.ItemId = bllEntity.Id; priceDayBLL.RentalPeriodId = _bll.RentalPeriods.GetRentalPeriodId("Päev"); _bll.Prices.Add(priceDayBLL); var priceWeekBLL = new PriceBLL(); priceWeekBLL.AppUserId = User.UserGuidId(); priceWeekBLL.ItemPrice = vm.ItemWeekPrice; priceWeekBLL.ItemId = bllEntity.Id; priceWeekBLL.RentalPeriodId = _bll.RentalPeriods.GetRentalPeriodId("Nädal"); _bll.Prices.Add(priceWeekBLL); var priceMonthBLL = new PriceBLL(); priceMonthBLL.AppUserId = User.UserGuidId(); priceMonthBLL.ItemPrice = vm.ItemMonthPrice; priceMonthBLL.ItemId = bllEntity.Id; priceMonthBLL.RentalPeriodId = _bll.RentalPeriods.GetRentalPeriodId("Kuu"); _bll.Prices.Add(priceMonthBLL); await _bll.SaveChangesAsync(); // Add item descriptions if (vm.ItemDescription != null || vm.ItemDescription !.Length != 0) { var itemDescriptionBLL = new ItemDescriptionBLL() { AppUserId = User.UserGuidId(), Description = vm.ItemDescription, ProductDescriptionId = vm.ProductDescriptionId, ItemId = bllEntity.Id }; _bll.ItemDescriptions.Add(itemDescriptionBLL); } if (vm.Descriptions != null && vm.Descriptions !.Count != 0) { for (int i = 0; i < vm.Descriptions.Count; i++) { if (vm.Descriptions[i].Length != 0) { var itemDescriptionBLL = new ItemDescriptionBLL() { AppUserId = User.UserGuidId(), Description = vm.Descriptions[i], ProductDescriptionId = vm.ProductDescriptionIds ![i],