public override void Delete(object Obj) { book_record book_record = (book_record)Obj; dbEntities.book_record.Remove(book_record); dbEntities.SaveChanges(); }
private void InitPage() { if (!IsStudentValid()) { return; } CurrentStudent = ((student)Session["Student_Id"]); if (Session["BookIssues_" + CurrentStudent.id] != null) { BookIssues = (List <book_issue>)Session["BookIssues_" + CurrentStudent.id]; PopulateBookIssues(); } //if (Session["CurrentBook_"+CurrentStudent.id]!= null) //{ // Book = (book)Session["CurrentBook"]; // InputMasterBook.Text = Book.title; // LabelCurrentBook.Text = Book.title + " by " + Book.author.name; //} //else //{ // LabelCurrentBook.Text = ""; //} if (Session["CurrentBookRecord_" + CurrentStudent.id] != null) { BookRecord = (book_record)Session["CurrentBookRecord_" + CurrentStudent.id]; } // TextBoxStudentID.Text = CurrentStudent.id; idStd.InnerHtml = "id: " + CurrentStudent.id + " name: " + CurrentStudent.name; AlertMessage(null); }
protected void ButtonSubmitReturn_Click(object sender, EventArgs e) { if (BookIssuesReturn == null || BookIssuesReturn.Count == 0) { //info.InnerHtml = "Please choose book to issue"; return; } student Student = (student)StudentService.GetById(TextBoxStudentID.Text); if (Student != null) { string IssueID = StringUtil.GenerateRandomNumber(9); issue Issue = new issue(); Issue.user_id = LoggedUser.id; Issue.id = IssueID; Issue.type = "return"; Issue.date = DateTime.Now; Issue.student_id = Student.id; Issue.addtional_info = "RETURN INFO"; if (null == IssueService.Add(Issue)) { AlertMessage("Gagal tambah issue"); return; } foreach (book_issue BS in BookIssuesReturn) { BS.issue_id = Issue.id; if (null == BookIssueService.Add(BS)) { AlertMessage("Gagal tambah book_issue"); break; } book_record BR = (book_record)bookRecordService.GetById(BS.book_record_id); BR.available = 1; BS.book_issue2 = (book_issue)BookIssueService.GetById(BS.book_issue_id); BS.book_issue2.book_return = 1; if (null == bookRecordService.Update(BR) || null == BookIssueService.Update(BS.book_issue2)) { //info.InnerHtml = "Gagal update book_record "; break; } } ViewState["BookIssuesReturn"] = null; Issues = new List <issue>(); IssuesReturn = new List <issue>(); BookIssuesReturn = new List <book_issue>(); PopulateBooksToReturn(); AlertMessage("Sukses mengembalikan buku " + IssueID); //ButtonClearList_Click(sender, e); } else { AlertMessage("Siswa tdk ada"); } }
private string GetBookStudentIssue() { if (StringUtil.NotNullAndNotBlank(Request.Form["rec_id"]) && StringUtil.NotNullAndNotBlank(Request.Form["student_id"])) { BookIssueService = new book_issueService(); bookRecordService = new Book_recordService(); studentService = new StudentService(); student Std = studentService.GetByIdFull(Request.Form["student_id"].ToString()); if (Std == null) { return("0"); } List <object> BookIssuesOBJ = BookIssueService.SearchAdvanced(new Dictionary <string, object>() { { "student_id", Request.Form["student_id"].ToString() }, { "book_record_id", Request.Form["rec_id"].ToString() }, { "book_return", "0" }, { "issue_type", "issue" }, }); if (BookIssuesOBJ == null || BookIssuesOBJ.Count == 0) { return("0"); } book_issue StudentBookIssue = (book_issue)BookIssuesOBJ.ElementAt(0); if (StudentBookIssue == null) { return("0"); } book_record BookRecord = (book_record)bookRecordService.GetById(Request.Form["rec_id"]); if (BookRecord == null) { return("0"); } book_record BookRecordToSend = (book_record)ObjectUtil.GetObjectValues(new string[] { "id", "book_id", "available" }, BookRecord); if (BookRecord.book != null) { BookRecordToSend.book = (book)ObjectUtil.GetObjectValues(new string[] { "id", "title" }, BookRecord.book); } book_issue BookIssueToSend = (book_issue)ObjectUtil.GetObjectValues(new string[] { "id", "book_record_id", "book_return" }, StudentBookIssue); BookIssueToSend.book_record = BookRecordToSend; return(JsonConvert.SerializeObject(BookIssueToSend)); } return("0"); }
protected void ButtonSaveIssue_Click(object sender, EventArgs e) { if (BookIssues == null || BookIssues.Count == 0) { info.InnerHtml = "Please choose book to issue"; return; } student Student = (student)StudentService.GetById(TextBoxStudentID.Text); if (Student != null) { string IssueID = StringUtil.GenerateRandomNumber(9); issue Issue = new issue(); Issue.user_id = LoggedUser.id; Issue.id = IssueID; Issue.type = "issue"; Issue.date = DateTime.Now; Issue.student_id = Student.id; Issue.addtional_info = "test"; if (null == IssueService.Add(Issue)) { AlertMessage("Gagal tambah issue"); return; } foreach (book_issue BS in BookIssues) { //final check if (bookRecordService.FindByIdFull(BS.book_record_id).available == 0) { continue; } BS.issue_id = Issue.id; if (null == BookIssueService.Add(BS)) { AlertMessage("Gagal tambah book_issue"); break; } book_record BR = (book_record)bookRecordService.GetById(BS.book_record_id); BR.available = 0; if (null == bookRecordService.Update(BR)) { AlertMessage("Gagal update book_record "); break; } } ButtonClearList_Click(sender, e); AlertMessage("Sukses tambah issue " + IssueID); } else { AlertMessage("Siswa tdk ada"); } }
public override object Add(object Obj) { book_record book_record = (book_record)Obj; if (book_record.id == null) { book_record.id = StringUtil.GenerateRandomChar(7); } book_record newbook_record = dbEntities.book_record.Add(book_record); dbEntities.SaveChanges(); return(newbook_record); }
public override object Update(object Obj) { try { book_record book_record = (book_record)Obj; dbEntities.Entry(book_record).CurrentValues.SetValues(book_record); dbEntities.SaveChanges(); return(book_record); } catch (Exception e) { throw e; } }
private void SearchBookRec(object sender, EventArgs e) { string RecId = InputRecId.Text.Trim(); book_record BookRecord = UserClient.BookRecById(RecId, appUser); if (BookRecord != null && !IsExistInList(RecId, BookIssues)) { BookIssues.Add(new book_issue() { book_record_id = BookRecord.id, book_record = BookRecord }); } UpdateForm(); }
private string GetBookList() { bookService = new BookService(); List <object> BooksObj = BaseService.GetObjectList(bookService, Request); BookCount = bookService.ObjectCount(); if (BooksObj != null) { List <book> Books = (List <book>)ObjectUtil.ConvertList(BooksObj, typeof(List <book>)); List <book> BooksToSerialize = new List <book>(); if (Books.Count > 0) { foreach (book B in Books) { book Book = (book)ObjectUtil.GetObjectValues( new string[] { "id", "title", "page", "isbn", "img", "publisher_id", "author_id", "category_id", "review" }, B ); category newCat = (category)ObjectUtil.GetObjectValues(new string[] { "id", "category_name" }, B.category); B.publisher.books = null; B.author.books = null; B.category.books = null; ICollection <book_record> BRs = new List <book_record>(); foreach (book_record BR in B.book_record) { book_record BRNew = (book_record)ObjectUtil.GetObjectValues( new string[] { "id", "book_code", "available", "book_id" }, BR); BRs.Add(BRNew); } Book.category = newCat; Book.author = B.author; Book.publisher = B.publisher; Book.book_record = BRs; BooksToSerialize.Add(Book); } return(JsonConvert.SerializeObject(BooksToSerialize)); } return("0"); } return("0"); }
private string GetIssuesList() { issueService = new IssueService(); List <object> Issues = BaseService.GetObjectList(issueService, Request); IssueCount = issueService.ObjectCount(); if (Issues != null && Issues.Count > 0) { List <issue> IssuesToSerialize = new List <issue>(); foreach (issue Issue in Issues) { List <book_issue> BookIssues = new List <book_issue>(); foreach (book_issue BookIssue in Issue.book_issue) { book Book = (book)ObjectUtil.GetObjectValues( new string[] { "id", "title", "page", "isbn", "img", "publisher_id", "author_id", "category_id", "review" }, BookIssue.book_record.book ); book_record BRNew = (book_record)ObjectUtil.GetObjectValues( new string[] { "id", "book_code", "available", "book_id" }, BookIssue.book_record); book_issue BS = (book_issue)ObjectUtil.GetObjectValues(new string[] { "id", "book_record_id", "qty", "book_return", "book_issue_id", }, BookIssue); BRNew.book = Book; BS.book_record = BRNew; BookIssues.Add(BS); } issue IssueSerialize = (issue)ObjectUtil.GetObjectValues(new string[] { "id", "date", "type", "additional_info", "student_id" }, Issue); IssueSerialize.book_issue = BookIssues; IssuesToSerialize.Add(IssueSerialize); } return(JsonConvert.SerializeObject(IssuesToSerialize)); } else { return("0"); } }
protected void ButtonClearList_Click(object sender, EventArgs e) { Session["Student_Id"] = null; BookIssues = new List <book_issue>(); NameObjectCollectionBase.KeysCollection Keys = Session.Keys; for (int i = 0; i < Keys.Count; i++) { string key = Keys[i]; if (key.Contains("BookIssues_")) { Session[key] = null; Book = null; } if (key.Contains("CurrentBook_")) { Session[key] = null; BookRecord = null; } if (key.Contains("CurrentBookRecord_")) { Session[key] = null; } } /*Session["BookIssues_"+CurrentStudent.id] = null; * Book = null; * Session["CurrentBook_"+CurrentStudent.id]= null; * BookRecord = null; * Session["CurrentBookRecord_"+CurrentStudent.id] = null;*/ TextBoxStudentID.Text = ""; PanelBookIssues.Controls.Clear(); PanelBookList.Controls.Clear(); InitPage(); ShowCurrentBook(""); LabelRecordList.Text = ""; }
protected void ButtonSave_Click(object sender, EventArgs e) { if (!IsStudentValid()) { return; } book_issue BS = new book_issue(); BS.id = StringUtil.GenerateRandomChar(10); BS.book_record_id = (TextBoxRecordId.Text.Trim()); if (!ExistBookRecord(BS.book_record_id, BookIssues)) { book_record DBRecord = bookRecordService.FindByIdFull(BS.book_record_id); if (null != DBRecord && DBRecord.available == (1)) { BS.book_record = DBRecord; BookIssues.Add(BS); } } Session["BookIssues_" + CurrentStudent.id] = BookIssues; PopulateBookIssues(); }
private List <object> ListWithSql(string sql, int limit = 0, int offset = 0) { List <object> book_recordsList = new List <object>(); var book_records = dbEntities.book_record .SqlQuery(sql ). Select(book_record => new { book_record, book = dbEntities.books.Where(b => b.id.Equals(book_record.book_id)).Select(p => p).FirstOrDefault() }); if (limit > 0) { book_records = book_records.Skip(offset * limit).Take(limit).ToList(); } else { book_records = book_records.ToList(); } /* where b.author.name.Contains(val) || b.title.Contains(val) || b.review.Contains(val) || b.author.name.Contains(val) || || b.category.category_name.Contains(val) || b.publisher.name.Contains(val) || select b;*/ foreach (var b in book_records) { book_record Book = new book_record(); Book = b.book_record; Book.book = b.book; // Debug.WriteLine("title:"+Book.title+", cat:"+Book.category.category_name+", auth:"+Book.author.name); book_recordsList.Add(Book); } return(book_recordsList); }
private string GetBookRecordById() { if (StringUtil.NotNullAndNotBlank(Request.Form["Id"])) { bookRecordService = new Book_recordService(); book_record BookRecord = (book_record)bookRecordService.GetById(Request.Form["Id"]); if (BookRecord == null) { return("0"); } book_record toSend = (book_record)ObjectUtil.GetObjectValues(new string[] { "id", "book_id", "available" }, BookRecord); if (BookRecord.book != null) { toSend.book = (book)ObjectUtil.GetObjectValues(new string[] { "id", "title" }, BookRecord.book); } return(JsonConvert.SerializeObject(toSend)); } return("0"); }
public bool IsAvailable(string book_rec_id) { book_record BookRecord = (book_record)GetById(book_rec_id); return(BookRecord.available == 1); }
protected void ButtonReturn_Click(object sender, EventArgs e) { try { book_issue BS = new book_issue(); BS.id = StringUtil.GenerateRandomChar(10); //BS.book_issue_id = (TextBoxIssueRecordId.Text.Trim()); //add student Student = (student)StudentService.GetById(TextBoxStudentID.Text); if (Student == null) { return; } string Student_ID = Student.id; string RecId = (TextBoxIssueRecordId.Text.Trim()); List <object> BookIssuesOBJ = BookIssueService.SearchAdvanced(new Dictionary <string, object>() { { "student_id", Student_ID }, { "book_record_id", RecId }, { "issue_type", "issue" }, { "book_return", "0" } }); if (BookIssuesOBJ == null || BookIssuesOBJ.Count == 0) { return; } book_issue reffBookIssue = (book_issue)BookIssuesOBJ.ElementAt(0); if (reffBookIssue.book_return != 0) { return; } BS.book_issue_id = reffBookIssue.id; // book_issue reffBookIssue = (book_issue)BookIssueService.GetById(BS.book_issue_id); if (!BookIssue.ExistBookRecord(BS.book_issue_id, BookIssuesReturn) && null != reffBookIssue) { //Check book_isue where book_rec_id = rec book_return != null || 0 and issue.student_id = std_id string StudentId = TextBoxStudentID.Text; if (BookIssueService.GetByBookIssueIdReturned(reffBookIssue.id).Count == 0) { book_record BookRecord = (book_record)bookRecordService.GetById(reffBookIssue.book_record_id); //BS.book_issue2 = reffBookIssue; BS.book_record_id = BookRecord.id; book Book = (book)ObjectUtil.GetObjectValues(new string[] { "id", "title" }, BookRecord.book); book_record BookRec = (book_record)ObjectUtil.GetObjectValues(new string[] { "id", "book_id", "available" }, BookRecord); BookRec.book = Book; BS.book_record = BookRec; BookIssuesReturn.Add(BS); } } }catch (HttpUnhandledException ex) { throw ex; } ButtonSearch_Click(sender, e); ViewState["BookIssuesReturn"] = BookIssuesReturn; PopulateBooksToReturn(); }
private issue IssueBook() { if (StringUtil.NotNullAndNotBlank(Request.Form["student_id"]) && StringUtil.NotNullAndNotBlank(Request.Form["book_recs"])) { issueService = new IssueService(); studentService = new StudentService(); bookRecordService = new Book_recordService(); BookIssueService = new book_issueService(); string StudentId = Request.Form["student_id"]; student Student = (student)studentService.GetById(StudentId); if (Student == null) { return(null); } string IssueID = StringUtil.GenerateRandomNumber(9); issue Issue = new issue(); Issue.user_id = User.id; Issue.id = IssueID; Issue.type = "issue"; Issue.date = DateTime.Now; Issue.student_id = Student.id; Issue.addtional_info = "test"; string[] BookRecIds = Request.Form["book_recs"].Split(';'); if (BookRecIds.Length < 1) { return(null); } if (null == issueService.Add(Issue)) { return(null); } List <book_issue> BookIssues = new List <book_issue>(); foreach (string Id in BookRecIds) { book_record BR = (book_record)bookRecordService.GetById(Id); if (BR == null || BR.available == 0) { continue; } book_issue BookIssue = new book_issue(); BookIssue.id = StringUtil.GenerateRandomChar(10); BookIssue.issue_id = IssueID; BookIssue.book_record_id = Id; BookIssue.qty = 1; BookIssues.Add(BookIssue); BookIssueService.Add(BookIssue); BR.available = 0; bookRecordService.Update(BR); } Issue.book_issue = BookIssues; return(Issue); } return(null); }
public override object GetById(string Id) { book_record book_record = (from c in dbEntities.book_record where c.id.Equals(Id) select c).SingleOrDefault(); return(book_record); }
protected override Panel ShowDetailPanel(object Obj) { book Book = (book)Obj; Panel DetailPanel = new Panel(); Control[] DetailsCol = new Control[5 * (Book.book_record.Count + 1)]; //update string[] ColumnLabels = { "No", "RecId", "BookCode", "BookId", "Available" }; for (int i = 0; i < ColumnLabels.Length; i++) { DetailsCol[i] = new TitleLabel(9) { Text = ColumnLabels[i] }; } int ControlIndex = 5; for (int i = 0; i < Book.book_record.Count; i++) { book_record BR = Book.book_record.ElementAt(i); DetailsCol[ControlIndex++] = new Label() { Text = (i + 1).ToString() }; DetailsCol[ControlIndex++] = new TextBoxReadonly() { Text = BR.id }; DetailsCol[ControlIndex++] = new TextBoxReadonly() { Text = BR.book_code }; DetailsCol[ControlIndex++] = new TextBoxReadonly() { Text = BR.book_id }; DetailsCol[ControlIndex++] = new TextBoxReadonly() { Text = BR.available == 1 ? "yes" : "-" }; } // DetailPanel = ControlUtil.GeneratePanel(5, DetailsCol, 5, 80, 20, Color.Orange, 5, 5, 400, 500); //picturebox string URL = "http://" + Transaction.Host + "/Assets/Image/App/bookCover.jpg"; if (Book.img != null) { URL = "http://" + Transaction.Host + "/Assets/Image/Book/" + Book.img; } PictureBox Picture = new PictureBox(); // Picture.BorderStyle = BorderStyle.Fixed3D; Picture.ImageLocation = URL; Picture.SizeMode = PictureBoxSizeMode.StretchImage; Picture.SetBounds(100, 10, 150, 200); Picture.BackColor = Color.Aqua; DetailPanel.SetBounds(10, 250, DetailPanel.Width, DetailPanel.Height); TitleLabel BookTitle = new TitleLabel(15) { Text = Book.title }; BookTitle.TextAlign = ContentAlignment.MiddleCenter; BookTitle.SetBounds(10, 200, 350, 50); Panel Wrapper = new Panel(); Wrapper.Controls.Add(Picture); Wrapper.Controls.Add(BookTitle); Wrapper.Controls.Add(DetailPanel); Wrapper.SetBounds(5, 5, 500, 1000); return(Wrapper); }