public void CanUpdateProductsFromImport() { string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"..\..\TestData\"); // Create new products PriceImport pi = ControllerManager.PriceImport.Create("9.csv", "9", true, ';', path, "9.csv"); Assert.IsNotNull(pi); Assert.IsTrue(pi.ImportStatus != ImportStatus.Invalid, "Import Status Is Invalid."); Assert.IsTrue(ControllerManager.PriceImport.Import(pi.ID, Guid.NewGuid()), "Products could not be imported."); pi = ControllerManager.PriceImport.GetById(pi.ID); Assert.IsTrue(pi.ImportStatus == ImportStatus.Processed); ControllerManager.CurrentSession.Flush(); // Update products PriceImport pi2 = ControllerManager.PriceImport.Create("9.csv", "9u", true, ';', path, "9.csv"); Assert.IsNotNull(pi2); Assert.IsTrue(pi2.ImportStatus != ImportStatus.Invalid, "Import Status Is Invalid."); Assert.IsTrue(ControllerManager.PriceImport.Import(pi2.ID, Guid.NewGuid()), "Products could not be imported."); pi2 = ControllerManager.PriceImport.GetById(pi2.ID); Assert.IsTrue(pi2.ImportStatus == ImportStatus.Processed); }
protected void btnDownloadOriginalFile_Click(object sender, EventArgs e) { PriceImport pi = ControllerManager.PriceImport.GetById(Id); Byte[] imageBytes; imageBytes = File.ReadAllBytes(Server.MapPath(Config.ImportFileFolder) + "\\" + pi.ID + ".csv"); Response.ContentType = "application/octet-stream"; Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", Server.UrlEncode(pi.File))); Response.OutputStream.Write(imageBytes, 0, imageBytes.Length); Response.OutputStream.Flush(); Response.End(); }
public void CanCreateProductsFromImport() { string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"..\..\TestData\"); PriceImport pi = ControllerManager.PriceImport.Create("9.csv", "9", true, ';', path, "9.csv"); Assert.IsNotNull(pi); Assert.IsTrue(pi.ImportStatus != ImportStatus.Invalid, "Import Status Is Invalid."); Assert.IsTrue(ControllerManager.PriceImport.Import(pi.ID, Guid.NewGuid()), "Products could not be imported."); // Verify is marked as processed pi = ControllerManager.PriceImport.GetById(pi.ID); Assert.IsTrue(pi.ImportStatus == ImportStatus.Processed); //TODO: Verify the amount of products inserted is equal to the amount of products validated Assert.AreEqual(10772, pi.LogResults.Count); }
public override string GetTitle() { if (!string.IsNullOrEmpty(Request.QueryString["id"])) { Guid Id = new Guid(Request.QueryString["id"]); PriceImport pi = ControllerManager.PriceImport.GetById(Id); if (pi != null) { return((!string.IsNullOrEmpty(pi.Description)) ? pi.Number.ToString() + " - " + pi.Description : pi.Number.ToString()); } else { return(Resource.Business.GetString("ImportTitle")); } } else { return(Resource.Business.GetString("ImportTitle")); } }
public void LoadInfo() { PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); PageNumber = 1; priceImportLogStatus = PriceImportLogStatus.Error; liError.Attributes["class"] = "pressed"; FillRepeater(); PriceImport priceImport = ControllerManager.PriceImport.GetById(Id); lblPriceImport.Text = priceImport.Description; lblCod.Text = priceImport.Number.ToString(); lblFile.Text = priceImport.File; lblNew.Text = priceImport.ImportView.AmountNew.ToString(); lblModified.Text = priceImport.ImportView.AmountChange.ToString(); lblErrors.Text = priceImport.ImportView.AmountError.ToString(); MembershipHelperUser mhu = MembershipHelper.GetUser(priceImport.TimeStamp.ModifiedBy); if (mhu != null) { lblUser.Text = mhu.UserName; } if (priceImport.TimeStamp.ModifiedOn.HasValue) { lblDate.Text = priceImport.TimeStamp.ModifiedOn.Value.ToShortDateString(); } lblStatus.Text = EnumHelper.GetDescription(priceImport.ImportStatus); if (priceImport.ImportStatus != ImportStatus.Verified && priceImport.ImportStatus != ImportStatus.VerifiedSomeInvalid) { btnImport.Visible = false; } if (priceImport.ImportView.AmountError == 0) { btnErrorExport.Visible = false; } }
protected void Button3_Click(object sender, EventArgs e) { HttpPostedFile uploadedfile = fuArchImp.PostedFile; string mimeType = uploadedfile.ContentType; if (mimeType == "application/vnd.ms-excel") { string originalfilename = Path.GetFileName(uploadedfile.FileName); if (originalfilename.EndsWith(".csv")) { string newfilename = DateTime.Now.Ticks.ToString() + ".csv"; uploadedfile.SaveAs(Server.MapPath(Config.ImportFileFolder) + "\\" + newfilename); DateTime start = DateTime.Now; Label2.Text = start.ToShortTimeString(); try { PriceImport pi = ControllerManager.PriceImport.Create(newfilename, TextBox2.Text, CheckBox1.Checked, Convert.ToChar(TextBox4.Text), Server.MapPath(Config.ImportFileFolder) + "\\", originalfilename); DateTime finish = DateTime.Now; Label3.Text = finish.ToShortTimeString(); TimeSpan ts = new TimeSpan(); ts = finish - start; Label4.Text = ts.TotalSeconds.ToString(); FillGrids(pi.ID); ListBox1.DataSource = ControllerManager.PriceImport.GetAll(); ListBox1.DataTextField = "ID"; ListBox1.DataValueField = "ID"; ListBox1.DataBind(); } catch (Exception) { Label5.Text = "Hubo un error en la carga del archivo por favor reviselo y vuelva a intentarlo"; } } } }
public ActionResult UploadXML(HttpPostedFileBase file) { if (ModelState.IsValid) { Client user = null; if (file.ContentType.Equals("application/xml") || file.ContentType.Equals("text/xml")) { try { var xmlPath = Server.MapPath("~/Content/Files" + file.FileName); file.SaveAs(xmlPath); XDocument xDoc = XDocument.Load(xmlPath); PriceImport price1 = new PriceImport(); List <PriceImport> price = (from c in xDoc.Descendants("Items") select new PriceImport() { Brand = c.Element("Brand").Value, Articul = c.Element("Articul").Value, Description = c.Element("Description").Value, BasePrice = Convert.ToDecimal(c.Element("BasePrice").Value), Quantity = Convert.ToInt32(c.Element("Quantity").Value) }).ToList(); //дописать проверку на логин using (EFDbContext db = new EFDbContext()) { user = db.Clients.SingleOrDefault(u => u.Login == User.Identity.Name); } if (user != null) { using (EFDbContext db = new EFDbContext()) { foreach (var i in price) { db.Prices.Add(new Price { Brand = i.Brand, Articul = i.Articul, Description = i.Description, BasePrice = i.BasePrice, Quantity = i.Quantity, ClientId = user.Id }); } db.SaveChanges(); ViewBag.Result = price; } } return(PartialView("Success")); } catch { ViewBag.Error = "Не импортировался файл"; return(View("Index")); } } else { ViewBag.Error = "Не импортировался файл"; return(View("Index")); } } return(View("Index")); }