public ActionResult Edit([Bind(Include = "id,code_key,title,desc")] Models.item item_tmp) { if (ModelState.IsValid) { var item = db.items.Find(item_tmp.id); item.code_key = item_tmp.code_key; item.title = item_tmp.title; item.desc = item_tmp.desc; var file = TM.IO.FileDirectory.Upload(Request.Files, TM.Common.Directories.document, false); if (file != null) { item.attach = "," + file.UploadFileString() + ","; } item.updated_by = Authentication.Auth.AuthUser.id.ToString(); item.updated_at = DateTime.Now; db.Entry(item).State = EntityState.Modified; db.SaveChanges(); this.success(TM.Common.Language.msgUpdateSucsess); return(RedirectToAction("Index")); } else { this.danger(TM.Common.Language.msgUpdateError); } return(View(item_tmp)); }
public ActionResult Create([Bind(Include = "code_key,title,desc,flag,extras")] Models.item item, FormCollection collection) { if (ModelState.IsValid) { item.id = Guid.NewGuid(); item.started_at = collection["started_at"].StringToDatetime(); if (!string.IsNullOrEmpty(collection["ended_at"])) { item.ended_at = collection["ended_at"].StringToDatetime(); } item.quantity = 0; item.quantity_total = 0; item.author = ","; item.images = ","; var file = TM.IO.FileDirectory.Upload(Request.Files, TM.Common.Directories.document, false); if (file != null) { item.attach = "," + file.UploadFileString() + ","; } item.app_key = Common.Objects.groups.document; item.created_by = Authentication.Auth.AuthUser.id.ToString(); item.created_at = DateTime.Now; db.items.Add(item); db.SaveChanges(); this.success(TM.Common.Language.msgCreateSucsess); return(RedirectToAction("Create")); } else { this.danger(TM.Common.Language.msgCreateError); } return(View(item)); }
// // GET: /Xml2Model/ public ActionResult Index() { rss cars = null; // System.Net.WebClient client = new WebClient(); // byte[] page = client.DownloadData("http://rss.nytimes.com/services/xml/rss/nyt/US.xml"); // string path = System.Text.Encoding.UTF8.GetString(page); //string path = "cars.xml"; XmlSerializer serializer = new XmlSerializer(typeof(rss)); //HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://rss.nytimes.com/services/xml/rss/nyt/US.xml"); //使用Cookie设置AllowAutoRedirect属性为false,是解决“尝试自动重定向的次数太多。”的核心 // request.CookieContainer = new CookieContainer(); // request.AllowAutoRedirect = false; // WebResponse response = (WebResponse)request.GetResponse(); // Stream sm = response.GetResponseStream(); // System.IO.StreamReader streamReader = new System.IO.StreamReader(sm); //将流转换为字符串 // string html = streamReader.ReadToEnd(); // streamReader.Close(); // TextReader reader = new StreamReader(path); XmlReader reader = new XmlTextReader("http://rss.nytimes.com/services/xml/rss/nyt/US.xml"); cars = (rss)serializer.Deserialize(reader); /*var serializer = new XmlSerializer(typeof(rss)); * using (TextReader reader = new StringReader(html)) * { * cars = (rss)serializer.Deserialize(reader); * }*/ // reader.Close(); db.sources.Add(new Models.source("NYTimes", DateTime ???)); for (var i = 0; i < cars.item.Length; i++) { string httpTime = cars.item[i].pubDate; DateTime time = DateTime.Parse(httpTime); Models.item item = new Models.item(cars.item[i], time, "NYTimes"); db.channel.Add(item); //item include 4 elements //db.channel.Add(cars.item[i]); } db.SaveChanges(); return(View(db.channel.ToList())); }
public Viwer(Models.item _item, decimal _qty, int _sn, decimal rateamount, decimal discou) { for (int i = 0; i < 9; i++) { this.SubItems.Add(new ListViewSubItem()); } item = _item; qty = _qty; sn = _sn; rate = rateamount; item_dis = discou; refresh(); }
// GET: vanban/Manager/Details/5 public ActionResult Details(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Models.item item = db.items.Find(id); if (item == null) { return(HttpNotFound()); } return(View(item)); }
// GET: vanban/Manager/Edit/5 public ActionResult Edit(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Models.item item = db.items.Find(id); if (item == null) { return(HttpNotFound()); } //ViewBag.users = db.users.Where(d => d.roles == Authentication.Roles.mod && d.id != Authentication.Auth.AuthUser.id && d.flag > 0); return(View(item)); }
public ActionResult AddNewItem(Models.item items) { if (!checkName2(items.name)) { if (ModelState.IsValid) { using (var db = new ecm.Models.ecmEntities2()) { var newItem = db.items.Create(); newItem.catagory = items.catagory; newItem.name = items.name; newItem.description = items.description; newItem.unit_price = items.unit_price; newItem.quantity = items.quantity; string[] paths = new string[3]; for (int i = 0; i < Request.Files.Count; i++) { HttpPostedFileBase file = Request.Files[i]; var filename = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/images/items/"), filename); file.SaveAs(path); paths[i] = file.FileName; } newItem.photo1 = "items/" + paths[0]; newItem.photo2 = "items/" + paths[1]; newItem.photo3 = "items/" + paths[2]; db.items.Add(newItem); db.SaveChanges(); } } else { ModelState.AddModelError("", "Data is not correct"); } // after successfully uploading redirect the user return(RedirectToAction("Items", "Admin")); } else { TempData["error"] = "This Item Name already existe!"; } return(View()); }
public JsonResult LoadNotification() { try { var authID = Authentication.Auth.AuthUser.id.ToString(); var tmp = db.items.Where(d => d.app_key == Common.Objects.groups.document && d.created_by == authID && d.flag > 0).ToList(); Models.item item = null; var count = 0; foreach (var i in tmp) { var images = i.images.Trim(','); if (!string.IsNullOrEmpty(images)) { var list = images.Split(','); count = list.Length; if (count > i.quantity_total) { item = i; break; } } } if (item != null) { var UserConfirm = item.images.Trim(',').Split(','); item.quantity_total = item.quantity_total + 1; //if (count == item.extras.Trim(',').Split(',').Length) // item.quantity = 2; db.Entry(item).State = EntityState.Modified; db.SaveChanges(); return(Json(new { title = "Xác nhận văn bản!", content = "Văn bản số: " + item.code_key + " - " + item.title + " - " + GetUser(UserConfirm[UserConfirm.Length - 1]) + " Xác nhận", location = Url.Action("Edit", "Manager", new { area = "vanban" }) + "/" + item.id, success = TM.Common.Language.msgSucsess }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = TM.Common.Language.msgSucsess }, JsonRequestBehavior.AllowGet)); } } catch (Exception) { return(Json(new { danger = TM.Common.Language.msgError }, JsonRequestBehavior.AllowGet)); } }
// GET: vanban/Manager/Edit/5 public ActionResult Edit(Guid?id) { if (Authentication.Auth.AuthUser.roles == Authentication.Roles.director) { return(RedirectToAction("Index", "Manager", new { area = "vanban" })); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Models.item item = db.items.Find(id); if (item == null) { return(HttpNotFound()); } //ViewBag.users = db.users.Where(d => d.roles == Authentication.Roles.mod && d.id != Authentication.Auth.AuthUser.id && d.flag > 0); return(View(item)); }
// POST: api/Item public IHttpActionResult Post([FromBody] Models.item item) { //this can be accessed if the list is static in the shopingListctr Models.ShoppingList shoppingList = ShoppingListController. shoppingLists.Where(s => s.Id == item.ShoppingListId). FirstOrDefault(); if (shoppingList == null) { return(NotFound()); } //shoppingList.Items.Add(item); //to give unique id for the items item.Id = shoppingList.Items.Max(i => i.Id) + 1; shoppingList.Items.Add(item); return(Ok(shoppingList)); }
// PUT: api/Item/5 public IHttpActionResult Put(int id, [FromBody] Models.item item) { //this can be accessed if the list is static in the shopingListctr Models.ShoppingList shoppingList = ShoppingListController. shoppingLists.Where(s => s.Id == item.ShoppingListId). FirstOrDefault(); if (shoppingList == null) { return(NotFound()); } Models.item changedItem = shoppingList.Items.Where(i => i.Id == id).FirstOrDefault(); if (changedItem == null) { return(NotFound()); } //set the property of the value that was given by the api changedItem.Checked = item.Checked; return(Ok(shoppingList)); }
// // GET: /News/ public ActionResult Index() { //Linq 语法 计算在likes 中ItemID文章的总like数目,也可用EF方法实现,比较麻烦 // int x = db.likes.Count(like => like.ItemId ==101); /****************************** * 访问rss的地址,读取xml数据 ******************************/ rss cars = null; // System.Net.WebClient client = new WebClient(); // byte[] page = client.DownloadData("http://rss.nytimes.com/services/xml/rss/nyt/US.xml"); // string path = System.Text.Encoding.UTF8.GetString(page); //string path = "cars.xml"; XmlSerializer serializer = new XmlSerializer(typeof(rss)); //HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://rss.nytimes.com/services/xml/rss/nyt/US.xml"); //使用Cookie设置AllowAutoRedirect属性为false,是解决“尝试自动重定向的次数太多。”的核心 // request.CookieContainer = new CookieContainer(); // request.AllowAutoRedirect = false; // WebResponse response = (WebResponse)request.GetResponse(); // Stream sm = response.GetResponseStream(); // System.IO.StreamReader streamReader = new System.IO.StreamReader(sm); //将流转换为字符串 // string html = streamReader.ReadToEnd(); // streamReader.Close(); // TextReader reader = new StreamReader(path); XmlReader reader = new XmlTextReader("http://rss.nytimes.com/services/xml/rss/nyt/US.xml"); cars = (rss)serializer.Deserialize(reader); /*var serializer = new XmlSerializer(typeof(rss)); * using (TextReader reader = new StringReader(html)) * { * cars = (rss)serializer.Deserialize(reader); * }*/ // reader.Close(); /****************************** * 初始化最新时间newTime ******************************/ DateTime newTime; if (db.sources.Find("NYTimes") == null) { //db.sources.Add(new Models.source("NYTimes", new DateTime(2000,1,1))); //Initialize database db.sources.Add(new Models.source("NYTimes", DateTime.Parse("Sat, 07 Feb 2015 00:57:00 GMT"))); } //db.sources.Add(new source { srcName = "NYTimes", newDate = DateTime.Parse("Sat, 07 Feb 2015 00:57:00 GMT") }); //db.SaveChanges(); if (db.sources.Find("NYTimes").newDate.Value < DateTime.Parse("Sat, 07 Feb 2015 00:57:00 GMT")) { string httpTime = cars.item[cars.item.Length - 1].pubDate; newTime = DateTime.Parse(httpTime); Models.source src = new Models.source("NYTimes", newTime); db.sources.Add(src); } else { Models.source src = db.sources.Find("NYTimes"); newTime = src.newDate.Value; } /****************************** * 循环添加每一条新闻条目,只添加新条目 ******************************/ for (var i = cars.item.Length - 1; i >= 0; i--) //old item store into database first { string httpTime = cars.item[i].pubDate; DateTime time = DateTime.Parse(httpTime); // 每次添加新条目前,先与source里的最新时间对比 if (time <= newTime) //time值小于最新时间,舍弃 { continue; } else { Models.source src = db.sources.Find("NYTimes"); src.newDate = time; //更新时间 } // description里面会带有<和> 之间的多余内容,例如广告,使用正则表达式可以消除掉 cars.item[i].description = Regex.Replace(cars.item[i].description, "<.*?>", string.Empty); Models.item item = new Models.item(cars.item[i], time, "NYTimes", 0); db.items.Add(item); //item include 4 elements db.SaveChanges(); //save DB before calling other function !! /********************************** * 添加每篇文章同时对keyword表和artKey表进行统计 * ********************************/ KeywordAnalyzer ka = new KeywordAnalyzer(); ka.analyze(item); //这里保存的数据库结果,不会传到view的ToList里?TFIDF ka.TFIDF(item.Id); //随着数据越多,TFIDF效果会越来越精确 /***************************** * 把结果存进article表中。不能放在子函数,否则传不进View? *****************************/ var query2 = db.artKeys .Where(x => x.AId == item.Id) .OrderByDescending(x => x.TFIDF) .Take(3); //获得排序最高的三个关键词 string str = ""; foreach (var line in query2) { str = str + line.word + ","; } db.items.Find(item.Id).keyword = str; db.SaveChanges(); } //db.SaveChanges(); return(View(db.items.ToList())); }
public ActionResult Index() { /* HashSet<string> hs = new HashSet<string>(); * var query = from KeywordsTotal in db.keywordsTotal * select KeywordsTotal; * for (int i = 0; i < query.Count(); i++) * { * hs.Add(query.ElementAt(i).keyword); * * }*/ //Linq 语法 计算在likes 中ItemID文章的总like数目,也可用EF方法实现,比较麻烦 // int x = db.likes.Count(like => like.ItemId ==101); /****************************** * 访问rss的地址,读取xml数据 ******************************/ rss newsItems = null; // System.Net.WebClient client = new WebClient(); // byte[] page = client.DownloadData("http://rss.nytimes.com/services/xml/rss/nyt/US.xml"); // string path = System.Text.Encoding.UTF8.GetString(page); //string path = "cars.xml"; XmlSerializer serializer = new XmlSerializer(typeof(rss)); //HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://rss.nytimes.com/services/xml/rss/nyt/US.xml"); //使用Cookie设置AllowAutoRedirect属性为false,是解决“尝试自动重定向的次数太多。”的核心 // request.CookieContainer = new CookieContainer(); // request.AllowAutoRedirect = false; // WebResponse response = (WebResponse)request.GetResponse(); // Stream sm = response.GetResponseStream(); // System.IO.StreamReader streamReader = new System.IO.StreamReader(sm); //将流转换为字符串 // string html = streamReader.ReadToEnd(); // streamReader.Close(); // TextReader reader = new StreamReader(path); XmlReader reader = new XmlTextReader("http://rss.nytimes.com/services/xml/rss/nyt/US.xml"); newsItems = (rss)serializer.Deserialize(reader); /*var serializer = new XmlSerializer(typeof(rss)); * using (TextReader reader = new StringReader(html)) * { * cars = (rss)serializer.Deserialize(reader); * }*/ // reader.Close(); /****************************** * 初始化最新时间newTime ******************************/ DateTime newTime; if (db.sources.Find("NYTimes") == null) { string httpTime = newsItems.item[newsItems.item.Length - 1].pubDate; newTime = DateTime.Parse(httpTime); Models.source src = new Models.source("NYTimes", newTime); db.sources.Add(src); } else { Models.source src = db.sources.Find("NYTimes"); newTime = src.newDate.Value; } /****************************** * 循环添加每一条新闻条目,只添加新条目 ******************************/ for (var i = newsItems.item.Length - 1; i >= 0; i--) //old item store into database first { string httpTime = newsItems.item[i].pubDate; DateTime time = DateTime.Parse(httpTime); // 每次添加新条目前,先与source里的最新时间对比 if (time <= newTime) //time值小于最新时间,舍弃 { continue; } else { Models.source src = db.sources.Find("NYTimes"); src.newDate = time; //更新时间 } // description里面会带有<和> 之间的多余内容,例如广告,使用正则表达式可以消除掉 newsItems.item[i].description = Regex.Replace(newsItems.item[i].description, "<.*?>", string.Empty); string text = newsItems.item[i].title + " " + newsItems.item[i].description; text = text.ToLower(); text = non1.Replace(text, ""); text = non2.Replace(text, ""); text = non3.Replace(text, ""); text = non4.Replace(text, ""); text = non5.Replace(text, ""); text = non6.Replace(text, ""); text = non7.Replace(text, ""); text = non8.Replace(text, ""); text = non9.Replace(text, ""); text = non10.Replace(text, ""); text = non11.Replace(text, ""); text = non12.Replace(text, ""); text = non13.Replace(text, ""); text = non14.Replace(text, ""); text = non15.Replace(text, ""); text = non16.Replace(text, ""); text = non17.Replace(text, ""); text = non18.Replace(text, ""); text = non19.Replace(text, ""); text = non20.Replace(text, ""); char[] sp = new Char[] { ',', '.', ' ', '?', ':', '\'', '‘', '’', '|' }; string[] words = text.Split(sp, StringSplitOptions.RemoveEmptyEntries); // string[] words = text.Split(' '); words[0] = Regex.Replace(words[0], "[\\s\\p{P}\n\r=<>$>+¥^]", ""); words[1] = Regex.Replace(words[1], "[\\s\\p{P}\n\r=<>$>+¥^]", ""); words[2] = Regex.Replace(words[2], "[\\s\\p{P}\n\r=<>$>+¥^]", ""); Models.item item = new Models.item(newsItems.item[i], time, "NYTimes", 0, words[0], words[1], words[2]); // ""); db.items.Add(item); //item include 4 elements db.SaveChanges(); for (int j = 0; j < 3; j++) { db.articleKeyword.Add(new ArticleKeyword(words[j], item.Id)); if (db.keywordsTotal.Find(words[j]) != null) { db.keywordsTotal.Find(words[j]).keywordSum++; } else { db.keywordsTotal.Add(new KeywordsTotal(words[j], 1)); } //db.SaveChanges(); } //db.channel.Add(cars.item[i]); } db.SaveChanges(); /*var query = from item in db.items * where item.imgId == "" * select item; * * foreach (Models.item item in query) * { * item.imgId = "i" + item.Id; * } * db.SaveChanges();*/ return(View()); }
public ItemNameViwer(Models.item _item) { Item = _item; }
public BarcodeViwer(Models.item _item) { Item = _item; }
public ActionResult Edit(Models.item items, string photo_1_change, string photo_2_change, string photo_3_change) { var item = db.items.Find(items.Id); for (int i = 0; i < Request.Files.Count; i++) { HttpPostedFileBase file = Request.Files[i]; if (i == 0 && photo_1_change == "1") { if (!file.FileName.Equals("")) { // Case 1: Check if photo 1 has value? if yes remove old photo 1 and save new photo 1 var filename = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/images/items/"), filename); file.SaveAs(path); items.photo1 = "items/" + filename; deletePhoto(item.photo1); } else { // Case 2: if photo 1 has no value then remove the old photo 1 deletePhoto(item.photo1); } } else if (i == 0) { items.photo1 = item.photo1; } if (i == 1 && photo_2_change == "1") { if (!file.FileName.Equals("")) { // Case 1: Check if photo 2 has value? if yes remove old photo 2 and save new photo 2 var filename = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/images/items/"), filename); file.SaveAs(path); items.photo2 = "items/" + filename; deletePhoto(item.photo2); } else { // Case 2: if photo 2 has no value then remove the old photo 2 deletePhoto(item.photo2); } } else if (i == 1) { items.photo2 = item.photo2; } if (i == 2 && photo_3_change == "1") { if (!file.FileName.Equals("")) { // Case 1: Check if photo 3 has value? if yes remove old photo 3 and save new photo 3 var filename = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/images/items/"), filename); file.SaveAs(path); items.photo3 = "items/" + filename; deletePhoto(item.photo3); } else { // Case 2: if photo 3 has no value then remove the old photo 3 deletePhoto(item.photo3); } } else if (i == 2) { items.photo3 = item.photo3; } } if (Request.Files.Count == 2) { items.photo3 = item.photo3; } db.Entry(item).CurrentValues.SetValues(items); //db.Entry(items).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("items")); }
// // GET: /Xml2Model/ public ActionResult Index() { //Linq 语法 计算在likes 中ItemID文章的总like数目,也可用EF方法实现,比较麻烦 // int x = db.likes.Count(like => like.ItemId ==101); /****************************** * 访问rss的地址,读取xml数据 ******************************/ rss cars = null; // System.Net.WebClient client = new WebClient(); // byte[] page = client.DownloadData("http://rss.nytimes.com/services/xml/rss/nyt/US.xml"); // string path = System.Text.Encoding.UTF8.GetString(page); //string path = "cars.xml"; XmlSerializer serializer = new XmlSerializer(typeof(rss)); //HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://rss.nytimes.com/services/xml/rss/nyt/US.xml"); //使用Cookie设置AllowAutoRedirect属性为false,是解决“尝试自动重定向的次数太多。”的核心 // request.CookieContainer = new CookieContainer(); // request.AllowAutoRedirect = false; // WebResponse response = (WebResponse)request.GetResponse(); // Stream sm = response.GetResponseStream(); // System.IO.StreamReader streamReader = new System.IO.StreamReader(sm); //将流转换为字符串 // string html = streamReader.ReadToEnd(); // streamReader.Close(); // TextReader reader = new StreamReader(path); XmlReader reader = new XmlTextReader("http://rss.cnn.com/rss/cnn_us.rss"); cars = (rss)serializer.Deserialize(reader); /*var serializer = new XmlSerializer(typeof(rss)); * using (TextReader reader = new StringReader(html)) * { * cars = (rss)serializer.Deserialize(reader); * }*/ // reader.Close(); /****************************** * 初始化最新时间newTime ******************************/ DateTime newTime; if (db.sources.Find("CNN") == null) { string httpTime = cars.item[cars.item.Length - 1].pubDate; newTime = DateTime.ParseExact(httpTime, "ddd, dd MMM yyyy HH:mm:ss EST", new CultureInfo("en-US")).AddHours(-1); Models.source src = new Models.source("CNN", newTime); db.sources.Add(src); } else { Models.source src = db.sources.Find("CNN"); newTime = src.newDate.Value; } /****************************** * 循环添加每一条新闻条目,只添加新条目 ******************************/ for (var i = cars.item.Length - 1; i >= 0; i--) //old item store into database first { string httpTime = cars.item[i].pubDate; DateTime time = DateTime.ParseExact(httpTime, "ddd, dd MMM yyyy HH:mm:ss EST", new CultureInfo("en-US")).AddHours(-1); // 每次添加新条目前,先与source里的最新时间对比 if (time <= newTime) //time值小于最新时间,舍弃 { continue; } else { Models.source src = db.sources.Find("CNN"); src.newDate = time; //更新时间 } Models.item item = new Models.item(cars.item[i], time, "CNN", 0, "", "", ""); //, ""); db.items.Add(item); //item include 4 elements //db.channel.Add(cars.item[i]); } db.SaveChanges(); /*var query = from item in db.items * where item.imgId == "" * select item; * * foreach (Models.item item in query) * { * item.imgId = "i" + item.Id; * } * db.SaveChanges();*/ return(View()); }