// Обработка сообщения файлом книги private void OnBookMessage(BookMessage book) { // 1. Сохраняем книгу как файл string path = @"C:\Users\" + Environment.UserName.ToString() + @"\SmartReader\" + Config.GetValue("Username"); string fullPath = path + @"\" + book.Title + ".txt"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } File.WriteAllBytes(fullPath, book.Content); // 2. Добавляем ссылку на книгу в LocalStorage Storage.AddBook(new BookRecord() { Path = fullPath, Offset = 0, Owner = Config.GetValue("Username") }); // 3. Отобразить ее в dataGridView (поствить галочку LocalBooks) //DrawBooksTable(); UpdateCheckBox(true, true); MessageBox.Show("Book successfully downloaded!", "Download book.", MessageBoxButtons.OK, MessageBoxIcon.Information); //UpdateStatusLabel(); }
//获取作品排序 public IList <BookMessage> SortBooks(string judge) { List <BookMessage> sort_books = new List <BookMessage>(); //定义书本数组 //根据书本的ISBN、书名、作者 关键字 进行查询 var result = from r in BookDB.Book select r; foreach (var r in result) { BookMessage bookmessage = new BookMessage(); bookmessage.ISBN = r.ISBN; //ISBN bookmessage.BookName = r.BookName; //书名 bookmessage.Writer = r.Writer; //作者 bookmessage.Time = r.Time; //上传时间 bookmessage.Page = r.Page; //页数 bookmessage.PublishingHouse = r.PublishingHouse; //出版社 bookmessage.Price = (float)r.price; //价钱 ??(不强转float报错)?? bookmessage.Photo = r.Photo; //书本图片路径 bookmessage.Introduction = r.Introduction; //简介 bookmessage.Score = (float)r.Score; //评分默认为0 sort_books.Add(bookmessage); //增加这个书本到数组 } //当为time时,按时间排序,当为score时,按评分排序,否则按默认排序 if (judge == "time") { sort_books.Sort(CompareTime); } else if (judge == "score") { sort_books.Sort(CompareScore); } return(sort_books); }
protected void Page_Load(object sender, EventArgs e) { if (Session["User"] == null || Session["User"] == "") { ClientScript.RegisterStartupScript(GetType(), "LoginOverTime", "<script>alert('登录超时,请重新登录');window.location.href ='HomeLogin.aspx'</script>"); string url = Request.Url.ToString(); Response.Redirect("Login.aspx?url=" + url); } string ISBN = Request.QueryString["ISBN"] as string; BookMessage book = new BookMessage(); book = (new BookOperation().GetBook(ISBN)); //Response.Write("<script>alert('"+book.BookName+"')</script>"); bookName.InnerText = book.BookName; img.Src = book.Photo; writer.InnerText += book.Writer; pubic.InnerText += book.PublishingHouse; time.InnerText += book.Time; isbn.InnerText += book.ISBN; string filepath = Server.MapPath(book.Introduction); FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(fs, UnicodeEncoding.GetEncoding("GB2312")); string read = sr.ReadToEnd(); if (read != "null") { ShowTxt.InnerText = read + "\r\n"; } }
//模糊查询(ISBN,书名,作者) public IList <BookMessage> Fuzzy_Search(string text) { List <BookMessage> search_books = new List <BookMessage>(); //定义书本数组 //根据书本的ISBN、书名、作者 关键字 进行查询 var result = from r in BookDB.Book where (r.ISBN.Contains(text)) || (r.BookName.Contains(text)) || (r.Writer.Contains(text)) select r; foreach (var r in result) { BookMessage bookmessage = new BookMessage(); bookmessage.ISBN = r.ISBN; //ISBN bookmessage.BookName = r.BookName; //书名 bookmessage.Writer = r.Writer; //作者 bookmessage.Time = r.Time; //上传时间 bookmessage.Page = r.Page; //页数 bookmessage.PublishingHouse = r.PublishingHouse; //出版社 bookmessage.Price = (float)r.price; //价钱 ??(不强转float报错)?? bookmessage.Photo = r.Photo; //书本图片路径 bookmessage.Introduction = r.Introduction; //简介 bookmessage.Score = (float)r.Score; //评分默认为0 search_books.Add(bookmessage); //增加这个书本到数组 } return(search_books); //返回书本BookMessage的数组 }
//根据书本的ISBN获取书本 public BookMessage GetBook(string text) { BookMessage getbook = new BookMessage(); //定义书本 //根据书本的ISBN var result = from r in BookDB.Book where r.ISBN == text.Trim() select r; foreach (var r in result) { BookMessage bookmessage = new BookMessage(); bookmessage.ISBN = r.ISBN; //ISBN bookmessage.BookName = r.BookName; //书名 bookmessage.Writer = r.Writer; //作者 bookmessage.Time = r.Time; //上传时间 bookmessage.Page = r.Page; //页数 bookmessage.PublishingHouse = r.PublishingHouse; //出版社 bookmessage.Price = (float)r.price; //价钱 ??(不强转float报错)?? bookmessage.Photo = r.Photo; //书本图片路径 bookmessage.Introduction = r.Introduction; //简介 bookmessage.Score = (float)r.Score; //评分默认为0 getbook = bookmessage; } return(getbook); //返回书本BookMessage的数组 }
public List <BookMessage> GetBooksResult(object jsonResult) { List <BookMessage> list = new List <BookMessage>(); try { var obj = JObject.Parse(jsonResult.ToString()); var result = obj["row"].Children().ToList(); int i = 1; foreach (var temp in result) { BookMessage message = new BookMessage() { Number = i, FileName = temp["fileName"].ToString(), AlarmTime = Convert.ToDateTime(temp["createTime"].ToString()) }; list.Add(message); i++; } return(list); } catch (Exception ex) { return(list); } }
//获取今年的书本 public IList <BookMessage> GetNewsBook() { DateTime years = new DateTime(); //根据今年时间查询 var result = from r in BookDB.Book where r.Time.Year >= years.Year - 1 select r; List <BookMessage> new_books = new List <BookMessage>(); //定义最新书本数组 foreach (var r in result) { BookMessage bookmessage = new BookMessage(); bookmessage.ISBN = r.ISBN; //ISBN bookmessage.BookName = r.BookName; //书名 bookmessage.Writer = r.Writer; //作者 bookmessage.Time = r.Time; //上传时间 bookmessage.Page = r.Page; //页数 bookmessage.PublishingHouse = r.PublishingHouse; //出版社 bookmessage.Price = (float)r.price; //价钱 ??(不强转float报错)?? bookmessage.Photo = r.Photo; //书本图片路径 bookmessage.Introduction = r.Introduction; //简介 bookmessage.Score = (float)r.Score; //评分默认为0 new_books.Add(bookmessage); //增加这个书本到数组 } return(new_books); //返回书本BookMessage的数组 }
//评分计算 public void Average_Score(BookMessage book) { var result = from r in BookDB.LeaveWord where r.ISBN == book.ISBN select r; float sum = 0; //总分 float aver; //平均分 foreach (var r in result) { sum = sum + (float)r.Score; } aver = sum / (result.Count()); //算出平均分数 //找出图书 var result_book = from r in BookDB.Book where r.ISBN == book.ISBN select r; foreach (Book r in result_book) { r.Score = aver; //修改评分 } BookDB.SubmitChanges(); }
protected void Page_Load(object sender, EventArgs e) { if (Session["User"] == null || Session["User"] == "") { ClientScript.RegisterStartupScript(GetType(), "LoginOverTime", "<script>alert('登录超时,请重新登录')</script>"); string url = Request.Url.ToString(); Response.Redirect("Login.aspx?url=" + url); } string ISBN = Request.QueryString["ISBN"] as string; BookMessage book = new BookMessage(); book = (new BookOperation().GetBook(ISBN)); bookName.InnerText = book.BookName; img.Src = book.Photo; writer.InnerText += book.Writer; pubic.InnerText += book.PublishingHouse; time.InnerText += book.Time; isbn.InnerText += book.ISBN; IList <LWord> LWords = new List <LWord>(); LWords = (new BookOperation().GetLeaveWord(ISBN)); LWordsShow.DataSource = LWords; LWordsShow.DataBind(); }
public async Task UpdateAsync(BookMessage message) { var book = await _db.Books.FirstOrDefaultAsync(x => x.Title == message.Title); if (book != null) { book.Author = message.Author; book.Language = message.Language; _db.Update(book); await _db.SaveChangesAsync(); } }
private BookUpdateMessage SaveAsync(BookMessage model, Settings settings = null) { settings = settings ?? Settings.Empty; var config = ConfigurationStub.Create(() => { return(settings); }); var bus = BusPublisherStub.Create(); var service = new BookService(Db, bus, config, TenantAccessorStub.Create()); service.SaveAsync(model).Wait(); return(bus.DequeueExchange <BookUpdateMessage>(ExchangeNames.Book)); }
private void btnBookAdd_Click(object sender, EventArgs e) { Book book = new Book(); book.BookName = txtBookName.Text; book.AuthorId = ((Author)cmbBookAuthor.SelectedItem).Id; book.CategoryId = ((Category)cmbBookCategory.SelectedItem).Id; book.PublisherId = ((Publisher)cmbBookPublisher.SelectedItem).Id; book.Summary = rtxtSummary.Text; book.PublishDate = dpPublishedDate.Value; book.UnitPrice = nudUnitPrice.Value; book.AmountSold = Convert.ToInt32(nudAmountSold.Value); _bookManager.Add(book); MessageBox.Show(BookMessage.AddMessage()); GetBooks(); }
//获取最新作品 //添加图书 public void Add(BookMessage bookmessage) { Book book = new Book(); //建立Book实体例book book.ISBN = bookmessage.ISBN; //ISBN book.BookName = bookmessage.BookName; //书名 book.Writer = bookmessage.Writer; //作者 book.PublishingHouse = bookmessage.PublishingHouse; //出版社 book.Time = bookmessage.Time; //上传时间 book.Page = bookmessage.Page; //页数 book.price = bookmessage.Price; //价钱 book.Photo = bookmessage.Photo; //书本图片路径 book.Introduction = bookmessage.Introduction; //简介 book.Score = 0; //评分默认为0 BookDB.Book.InsertOnSubmit(book); //插入实体book BookDB.SubmitChanges(); //提交更改 }
protected void Submit_Click(object sender, EventArgs e) { //Response.Write("<script>alert('" + hiddenMessage.Value + "')</script>"); Customer user = new Customer(); user = Session["User"] as Customer; //user = (new UserOperation().GetCustomer("00001")); //Response.Write("<script>alert('" + Session["User"] as string + "')</script>"); BookMessage book = new BookMessage(); book = (new BookOperation().GetBook((Request.QueryString["ISBN"] as string))); LWord lword = new LWord(); lword.Getbook.ISBN = book.ISBN; lword.Getcustomer.UserID = user.UserID; lword.Leave_word = lytext.InnerText; lword.Score = (float)Convert.ToDouble(hiddenMessage.Value); (new UserOperation()).PostLWord(lword); ClientScript.RegisterStartupScript(GetType(), "PostSuccess", "<script>alert('发送成功');window.location.href ='Comment.aspx?ISBN=" + book.ISBN + "'</script>"); }
private void btnBookUpdate_Click(object sender, EventArgs e) { _selectedBook.BookName = txtBookName.Text; Author author = (Author)cmbBookAuthor.SelectedItem; _selectedBook.AuthorId = author.Id; Category category = (Category)cmbBookCategory.SelectedItem; _selectedBook.CategoryId = category.Id; Publisher publisher = (Publisher)cmbBookPublisher.SelectedItem; _selectedBook.PublisherId = publisher.Id; _selectedBook.AmountSold = Convert.ToInt32(nudAmountSold.Value); _selectedBook.UnitPrice = nudUnitPrice.Value; _selectedBook.Summary = rtxtSummary.Text; _bookManager.Update(_selectedBook); MessageBox.Show(BookMessage.UpdateMessage()); GetBooks(); }
/// <summary> /// 获取报警档案记录 /// </summary> public List <BookMessage> GetNewestMessage() { string HDid = ""; ManagementClass mc = new ManagementClass("Win32_Processor"); ManagementObjectCollection moc = mc.GetInstances(); foreach (ManagementObject mo in moc) { HDid = (string)mo.Properties["ProcessorId"].Value; break; } string url = string.Format(@"http://{0}:{1}/entranceGuard/log/getStoTbEntranceGuardAlarm?fkEntranceGuardName=" + Dns.GetHostName() + "&&fkEntranceGuardNum=" + HDid, PublicData.PublicData.serverIp, PublicData.PublicData.serverSite); List <BookMessage> list = new List <BookMessage>(); try { Http http = new Http(url, null); object jsonResult = http.HttpGet(url); var result = JToken.Parse(jsonResult.ToString()); var row = result["row"].Children().ToList(); List <BookMessage> books = new List <BookMessage>(); int i = 1; foreach (var temp in row) { BookMessage bookMessage = new BookMessage() { AlarmTime = Convert.ToDateTime(temp["createTime"].ToString()), FileName = temp["fkFileName"].ToString(), Number = i }; books.Add(bookMessage); i++; } return(books); } catch { PublicData.PublicData.state = "未连接服务器"; return(list); } }
public List <BookMessage> GetBooksResult(object jsonResult) { List <BookMessage> list = new List <BookMessage>(); var obj = JObject.Parse(jsonResult.ToString()); foreach (JToken jToken in obj.Children()) { var p = jToken as JProperty; if (p.Name == "rows") { List <JToken> jTokens = p.Value.ToList(); foreach (JToken jT in jTokens) { BookMessage book = new BookMessage(); List <JToken> pp = jT.Children().ToList(); foreach (JToken jj in pp) { var js = jj as JProperty; switch (js.Name.ToLower()) { case "rfid": book.EPC = js.Value.ToString(); break; case "fileName": book.FileName = js.Value.ToString(); break; default: break; } } list.Add(book); } } } return(list); }
static void OnMessage(object sender, MessageEventArgs args) { Console.WriteLine("Ответ получен: тип=" + (int)args.Message.Type); switch (args.Message.Type) { case MessageTypes.AuthenticateResponse: Console.WriteLine("Status: " + (args.Message as AuthenticationResponseMessage).Status); Console.WriteLine("Token: " + (args.Message as AuthenticationResponseMessage).Token); Console.WriteLine("Message: " + (args.Message as AuthenticationResponseMessage).Message); Console.WriteLine(); if (!(args.Message as AuthenticationResponseMessage).Token.IsEmpty()) { TOKEN = (args.Message as AuthenticationResponseMessage).Token; Console.WriteLine(TOKEN); } break; case MessageTypes.Status: Console.WriteLine("Status: " + (args.Message as StatusMessage).Status); Console.WriteLine("Message: " + (args.Message as StatusMessage).Text); break; case MessageTypes.BookList: BookListMessage m = args.Message as BookListMessage; Console.WriteLine("Count: " + m.Books.Count); ID = m.Books[0].Id; Console.WriteLine("ID = " + ID); Console.WriteLine("ID's title: " + m.Books[0].Title); break; case MessageTypes.Book: BookMessage mm = args.Message as BookMessage; Console.WriteLine("Content of a book: " + Encoding.Default.GetString(mm.Content)); break; } }
private void btnBookDelete_Click(object sender, EventArgs e) { _bookManager.Delete(_selectedBook); MessageBox.Show(BookMessage.DeleteMessage()); GetBooks(); }
//评分比较 int CompareScore(BookMessage a, BookMessage b) { return(b.Score.CompareTo(a.Score)); }
public async Task SaveAsync(BookMessage model) { bool inserted = false; var book = await _db.Books.FilterTitle(model.Title).FirstOrDefaultAsync(); if (book == null) { inserted = true; book = new Entities.Book(); } book.Title = model.Title; book.Language = model.Language; if (model.Category != null) { var category = await _db.Categories.FirstOrDefaultAsync(x => x.Name == model.Category); if (category == null) { category = new Entities.BookCategory(); category.Name = model.Category; } if (!book.Categories.Any(x => x.Category.Name == category.Name)) { book.Categories.Add(new Entities.BookCategoryBook() { Category = category }); } } var authorName = model.Author; if (FeatureAddTableAtuthor.Get()) { book.Author = await _db.Authors.FirstOrDefaultAsync(x => x.Name == authorName); if (book.Author == null) { book.Author = new Entities.BookAuthor(); book.Author.Name = authorName; } } else { book.AuthorName = authorName; } if (inserted) { await _db.AddAsync(book); } else { _db.Update(book); } await _db.SaveChangesAsync(); var message = new BookUpdateMessage { Id = book.Id, Title = book.Title, Author = authorName, Language = book.Language }; await _bus.PublishAsync(ExchangeNames.Book, message); }
public void DealRF100(byte[] data, MainControl control) { lock (this) { if (PublicData.PublicData.TJDate == Convert.ToDateTime("2018-1-1")) { PublicData.PublicData.TJDate = DateTime.Now; } else { if ((DateTime.Now - PublicData.PublicData.TJDate).TotalSeconds > 5) { PublicData.PublicData.TempEPCList.Clear(); } } int start = 0; if (data.Length < 2) { return; } List <string> j = byteToHexStr(data, data.Length); bool result = false; foreach (string strEPC in j) { lock (strEPC) { if (PublicData.PublicData.TempEPCList.Contains(strEPC)) { // return; } else { PublicData.PublicData.TJDate = DateTime.Now; PublicData.PublicData.TempEPCList.Add(strEPC); PublicData.PublicData.EPC.Enqueue(strEPC); SelectDAL select = new SelectDAL(); ReturnInfo returnInfo = select.Select(strEPC); BookMessage message = new BookMessage() { EPC = strEPC }; ///添加档案进出记录 if (returnInfo.stateCode != "202") { result = true; AddArchivesInOrOutList addArchivesIn = new AddArchivesInOrOutList(message); addArchivesIn.GetArchivesInOrOut(); } ///报警记录判断 if (returnInfo.stateCode == "201") { ///添加报警记录 AddAlarmList addAlarmList = new AddAlarmList(message); addAlarmList.AddAlarm(); } } } } if (result) { Task.Run(() => { GetArchivesAccessList getArchivesAccessList = new GetArchivesAccessList(); List <Archives> list = GetArchivesListByList(getArchivesAccessList.GetNewestMessage()); ////报警记录 GetNewestAlarmList getNewestAlarmList = new GetNewestAlarmList(); List <Alarm> alarms = GetAlarmListByList(getNewestAlarmList.GetNewestMessage()); control.Dispatcher.Invoke(() => { control.message.ItemsSource = list; control.AlarmList.ItemsSource = alarms; }); }); } } }
BookShopDataClassesDataContext BookDB = new BookShopDataClassesDataContext(); //定义这个类实例 //时间比较 int CompareTime(BookMessage a, BookMessage b) { return(b.Time.CompareTo(a.Time)); }
private void UpdateAsync(BookMessage message) { var service = new BookService(Db); service.UpdateAsync(message).Wait(); }
public AddAlarmList(BookMessage message) { parament = message; }
public AddArchivesInOrOutList(BookMessage message) { book = message; }
/// <summary> /// 扫描信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void rp_PaketReceived(object sender, StrArrEventArgs e) { string[] packetRx = e.Data; string strPacket = string.Empty; for (int i = 0; i < packetRx.Length; i++) { strPacket += packetRx[i] + " "; } if (packetRx[1] == ConstCode.FRAME_TYPE_INFO && packetRx[2] == ConstCode.CMD_INVENTORY) { int PCEPCLength = ((Convert.ToInt32((packetRx[6]), 16)) / 8 + 1) * 2; string pc = packetRx[6] + " " + packetRx[7]; string epc = string.Empty; for (int i = 0; i < PCEPCLength - 2; i++) { epc = epc + packetRx[8 + i]; } epc = Commands.AutoAddSpace(epc); TempData = epc; book = new BookMessage() { EPC = TempData }; bool isSave = false; if (bookList != null && bookList.Count > 0) { foreach (BookMessage message in bookList) { if (message.EPC == book.EPC) { isSave = true; } } } if (!isSave) { bookList.Add(book); PublicData.PublicData.bookList.Add(book); } if (epc.Contains("E2 00 68 0A")) { foreach (BookMessage bookMessage in bookList) { if (bookMessage.EPC == epc && bookMessage.User == null) { parameter = epc; ChangeVistsRegion(); } } } else { // ChangeVistsRegion(); } } if (packetRx[2] == ConstCode.CMD_READ_DATA) { string strInvtReadData = ""; int dataLen = Convert.ToInt32(packetRx[3], 16) * 256 + Convert.ToInt32(packetRx[4], 16); int pcEpcLen = Convert.ToInt32(packetRx[5], 16); for (int i = 0; i < dataLen - pcEpcLen - 1; i++) { strInvtReadData = strInvtReadData + packetRx[i + pcEpcLen + 6]; } ReturnUser = Commands.AutoAddSpace(strInvtReadData); switch (region) { case VisitRegion.User: for (int i = 0; i < bookList.Count; i++) { if (bookList[i].EPC == parameter && bookList[i].User == null) { bookList[i].User = Commands.AutoAddSpace(strInvtReadData); } } break; case VisitRegion.TID: for (int i = 0; i < bookList.Count; i++) { if (bookList[i].EPC == parameter && bookList[i].TID == null) { bookList[i].TID = Commands.AutoAddSpace(strInvtReadData); } } region = VisitRegion.User; break; default: break; } } }