Ejemplo n.º 1
0
        public override void Delete(object Obj)
        {
            book_issue Book_issue = (book_issue)Obj;

            dbEntities.book_issue.Remove(Book_issue);
            dbEntities.SaveChanges();
        }
Ejemplo n.º 2
0
        private List <object> ListWithSql(string sql, int limit = 0, int offset = 0)
        {
            List <object> book_IssuesList = new List <object>();
            var           book_issues     = dbEntities.book_issue
                                            .SqlQuery(sql
                                                      ).
                                            Select(book_issue => book_issue);

            if (limit > 0)
            {
                book_issues = book_issues.Skip(offset * limit).Take(limit).ToList();
            }
            else
            {
                book_issues = book_issues.ToList();
            }
            foreach (var bs in book_issues)
            {
                book_issue BookIssue = bs;
                book_IssuesList.Add(BookIssue);
            }

            /*  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;*/

            return(book_IssuesList);
        }
Ejemplo n.º 3
0
        public override object Add(object Obj)
        {
            book_issue Book_issue = (book_issue)Obj;

            if (Book_issue.id == null)
            {
                Book_issue.id = StringUtil.GenerateRandomChar(10);
            }
            if (Book_issue.qty == null || Book_issue.qty == 0)
            {
                Book_issue.qty = 1;
            }
            Book_issue.ref_issue = "not used";
            try
            {
                Book_issue.book_issue2 = null;
                Book_issue.issue       = null;
                Book_issue.book_issue1 = null;
                Book_issue.book_record = null;
                if (Book_issue.book_return == null)
                {
                    Book_issue.book_return = 0;
                }
                book_issue newclass = dbEntities.book_issue.Add(Book_issue);
                dbEntities.SaveChanges();
                return(newclass);
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
            {
                Exception raise = dbEx;
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        string message = string.Format("{0}:{1}",
                                                       validationErrors.Entry.Entity.ToString(),
                                                       validationError.ErrorMessage);
                        // raise a new exception nesting
                        // the current instance as InnerException
                        raise = new InvalidOperationException(message, raise);
                    }
                }
                throw raise;
                //  return null;
            }
            catch (System.Data.Entity.Infrastructure.DbUpdateException dbEx)
            {
                Exception raise = new Exception(dbEx.StackTrace);

                throw raise;
                //  return null;
            }
            catch (System.Exception dbEx)
            {
                Exception raise = new Exception(dbEx.StackTrace);

                throw raise;
                //  return null;
            }
        }
Ejemplo n.º 4
0
        private string GetBookIssueList()
        {
            BookIssueService = new book_issueService();
            List <object> book_issuesObj = BaseService.GetObjectList(BookIssueService, Request);

            BookIssueCount = BookIssueService.ObjectCount();
            if (book_issuesObj != null)
            {
                List <book_issue> book_issues            = (List <book_issue>)ObjectUtil.ConvertList(book_issuesObj, typeof(List <book_issue>));
                List <book_issue> book_issuesToSerialize = new List <book_issue>();
                if (book_issues.Count > 0)
                {
                    foreach (book_issue BookIssue in book_issues)
                    {
                        book_issue book_issue = (book_issue)ObjectUtil.GetObjectValues(new string[] {
                            "id", "book_record_id", "book_issue_id", "issue_id", "qty", "book_return"
                        }, BookIssue);

                        book_issuesToSerialize.Add(book_issue);
                    }

                    return(JsonConvert.SerializeObject(book_issuesToSerialize));
                }
                return("0");
            }
            return("0");
        }
Ejemplo n.º 5
0
        public override object Update(object Obj)
        {
            book_issue Book_issue = (book_issue)Obj;

            dbEntities.Entry(Book_issue).CurrentValues.SetValues(Book_issue);
            dbEntities.SaveChanges();
            return(Book_issue);
        }
Ejemplo n.º 6
0
        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");
        }
Ejemplo n.º 7
0
        public static issue SubmitReturn(List <book_issue> BookIssues, string StudentId, AppUser AppUser)
        {
            string BookRecs = ObjectUtil.ListToDelimitedString(BookIssues, ";", "-", "book_record_id", "book_issue_id");

            Dictionary <string, object> Params = MixParamWithUnP(
                new Dictionary <string, object>()
            {
                { "Action", "returnBook" },
                { "student_id", StudentId },
                { "book_recs", BookRecs }
            },
                AppUser);
            Dictionary <string, object> RespParams = Request.PostReq(Transaction.URL, Params);

            if (RespParams != null && RespParams["result"] != null && RespParams["result"].ToString() == "0")
            {
                Dictionary <string, object> DataMap = StringUtil.JSONStringToMap(RespParams["data"].ToString());
                string IssueId = DataMap["issue_id"].ToString();
                string Date    = DataMap["date"].ToString();
                if (DataMap["items"] == null || DataMap["items"].ToString().Equals(""))
                {
                    return(null);
                }
                string[]          BookIssuesString = DataMap["items"].ToString().Split(';');
                List <book_issue> BookIssuesList   = new List <book_issue>();
                if (BookIssuesString.Length > 0)
                {
                    foreach (string Item in BookIssuesString)
                    {
                        string[]   Ids = Item.Split('~');
                        book_issue BS  = new book_issue()
                        {
                            id             = Ids[1],
                            book_record_id = Ids[0]
                        };
                        BookIssuesList.Add(BS);
                    }
                }
                Date = Date.Replace("PM", "");
                Date = Date.Replace("AM", "");

                issue Issue = new issue()
                {
                    id         = IssueId,
                    date       = StringUtil.StringToDateTime(Date),
                    book_issue = BookIssuesList
                };
                return(Issue);
            }
            return(null);
        }
Ejemplo n.º 8
0
        private List <object> ListWithSql(string sql, int limit = 0, int offset = 0)
        {
            List <object> issueList = new List <object>();
            var           issues    = dbEntities.issues
                                      .SqlQuery(sql
                                                ).
                                      Select(issue => new
            {
                issue,
                book_issue = dbEntities.book_issue.Where(b => b.issue_id.Equals(issue.id)).Select(bi => new
                {
                    bi,
                    book_record = dbEntities.book_record.Where(br => br.id.Equals(bi.book_record_id)).FirstOrDefault()
                }).ToList(),
            });

            if (limit > 0)
            {
                issues = issues.Skip(offset * limit).Take(limit).ToList();
            }
            else
            {
                issues = issues.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 i in issues)
            {
                issue Issue = new issue();
                Issue            = i.issue;
                Issue.book_issue = new List <book_issue>();
                foreach (var bi in i.book_issue)
                {
                    book_issue BookIssue = new book_issue();
                    BookIssue             = bi.bi;
                    BookIssue.book_record = bi.book_record;
                    Issue.book_issue.Add(BookIssue);
                }
                //   Debug.WriteLine("title:"+Book.title+", cat:"+Book.category.category_name+", auth:"+Book.author.name);
                issueList.Add(Issue);
            }

            return(issueList);
        }
        private void SearchBookRec(object sender, EventArgs e)
        {
            string     RecId     = InputRecId.Text.Trim();
            book_issue BookIssue = UserClient.GetByStudentAndRecId(Student, RecId, appUser);

            if (BookIssue != null && !IsExistInList(RecId, BookIssues))
            {
                BookIssue.book_issue_id = BookIssue.id;
                BookIssue.id            = null;
                BookIssues.Add(BookIssue);
            }
            else
            {
                MessageBox.Show("Book Record Not Found");
            }
            UpdateForm();
        }
Ejemplo n.º 10
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");
            }
        }
        private void SubmitIssue(object sender, EventArgs e)
        {
            var Confirm = MessageBox.Show("Are You Sure To Submit Return Transaction ??",
                                          "Confirm Return!!",
                                          MessageBoxButtons.YesNo);

            if (Confirm == DialogResult.No)
            {
                return;
            }
            if (Student == null || BookIssues.Count == 0)
            {
                MessageBox.Show("Complete the field!");
                return;
            }
            issue Issue = UserClient.SubmitReturn(BookIssues, Student.id, appUser);

            if (Issue == null)
            {
                MessageBox.Show("Return Failed");
                return;
            }
            BookIssues.ForEach(b =>
            {
                book_issue ExistInRecordedIssue = (GetByRecId(b.book_record_id, Issue.book_issue));
                if (ExistInRecordedIssue != null)
                {
                    b.id = ExistInRecordedIssue.id;
                }
                else
                {
                    b.id = "FAILED";
                }
            });

            MessageBox.Show("Return Success with ID: " + Issue.id);
            UpdateForm();
        }
Ejemplo n.º 12
0
        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();
        }
Ejemplo n.º 13
0
        protected override Panel ShowDetailPanel(object Object)
        {
            issue Issue       = (issue)Object;
            Panel DetailPanel = new Panel();

            Control[] DetailsCol = new Control[7 * (Issue.book_issue.Count + 1)];
            //update
            string[] ColumnLabels = { "No", "IssueId", "RecId", "Title", "", "Returned", Issue.type.Trim() + " item id" };
            for (int i = 0; i < ColumnLabels.Length; i++)
            {
                DetailsCol[i] = new TitleLabel(11)
                {
                    Text = ColumnLabels[i]
                };
            }
            int ControlIndex = 7;

            for (int i = 0; i < Issue.book_issue.Count; i++)
            {
                book_issue BS = Issue.book_issue[i];

                if (Issue.type.Trim().Equals("issue"))
                {
                    Dictionary <string, object> CheckReturnResponse = Transaction.FetchObj(0, 0, Transaction.URL, "checkReturnedBook", AppUser, new Dictionary <string, object>()
                    {
                        { "book_issue_id", BS.id }
                    });
                    if (CheckReturnResponse["result"].ToString() == "0")
                    {
                        BS.book_issue_id = StringUtil.JSONStringToMap(CheckReturnResponse["data"].ToString())["book_issue_id"].ToString();
                    }
                }

                DetailsCol[ControlIndex++] = new Label()
                {
                    Text = (i + 1).ToString()
                };
                DetailsCol[ControlIndex++] = new TextBoxReadonly()
                {
                    Text = BS.id
                };
                DetailsCol[ControlIndex++] = new TextBoxReadonly()
                {
                    Text = BS.book_record_id
                };
                DetailsCol[ControlIndex++] = new TextBoxReadonly()
                {
                    Text = BS.book_record.book.title
                };
                DetailsCol[ControlIndex++] = new BlankControl()
                {
                    Reserved = ReservedFor.BEFORE_HOR
                };
                string Type = Issue.type.ToLower().Trim();
                if (Type == ("return"))
                {
                    DetailsCol[ControlIndex++] = null;
                }
                else
                {
                    DetailsCol[ControlIndex++] = new Label()
                    {
                        Text = BS.book_return == 1 ? "yes " + BS.ref_issue : "No"
                    };
                }
                DetailsCol[ControlIndex++] = new Label()
                {
                    Text = BS.book_issue_id
                };
            }
            //
            DetailPanel = ControlUtil.GeneratePanel(7, DetailsCol, 5, 80, 20, Color.Orange, 5, 250);

            student Student = UserClient.StudentById(Issue.student_id, AppUser);

            Panel StudentDetail = ControlUtil.GeneratePanel(1, new Control[]
            {
                new Label()
                {
                    Text = Issue.type.ToUpper().Trim() + " ID"
                },
                new TextBoxReadonly(13)
                {
                    Text = Issue.id
                },
                new Label()
                {
                    Text = "Date"
                },
                new TextBoxReadonly(13)
                {
                    Text = Issue.date.ToString()
                },
                new Label()
                {
                    Text = "Student ID"
                },
                new TextBoxReadonly(13)
                {
                    Text = Student.id
                },
                new Label()
                {
                    Text = "Student Name"
                },
                new TextBoxReadonly(13)
                {
                    Text = Student.name
                },
                new Label()
                {
                    Text = "Student ClassId"
                },
                new TextBoxReadonly(13)
                {
                    Text = Student.class_id
                },
            }, 5, 200, 17, Color.Yellow, 5, 5, 500);

            Panel Wrapper = new Panel();

            Wrapper.Controls.Add(StudentDetail);
            Wrapper.Controls.Add(DetailPanel);
            Wrapper.SetBounds(5, 5, 500, 500);

            Wrapper.AutoScroll             = false;
            Wrapper.VerticalScroll.Visible = true;
            Wrapper.VerticalScroll.Enabled = true;
            Wrapper.AutoScroll             = true;

            return(Wrapper);
        }
Ejemplo n.º 14
0
        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();
        }
Ejemplo n.º 15
0
        protected Panel StudentDetailPanel(student Student, string Type, int X, int Y, int W, int H)
        {
            List <book_issue> BookIssues = new List <book_issue>();
            //fetch obj
            Dictionary <string, object> FilterParams = new Dictionary <string, object>();

            FilterParams.Add("student_id", Student.id);
            FilterParams.Add("orderby", "book_issue.book_return");
            FilterParams.Add("ordertype", "asc");
            FilterParams.Add("issue_type", Type);

            List <Dictionary <string, object> > ObjectMapList = Transaction.MapList(0, 0, Transaction.URL, "bookIssueList", AppUser, FilterParams);

            //generate panel
            Panel DetailPanel = new Panel();
            int   ListCount   = ObjectMapList == null ? 0 : ObjectMapList.Count;

            Control[] DetailsCol = new Control[8 * (ListCount + 2)];
            //update
            string[] ColumnLabels = { "No", "Id", "Trx Id", "RecId", /*"Title",*/ "", "Returned", "Book Issue Ref", "" };

            //generate title
            for (int i = 0; i < 8; i++)
            {
                if (i == 0)
                {
                    DetailsCol[i] = new TitleLabel(13)
                    {
                        Text = ("============" + Type.ToUpper() + " LIST============")
                    };
                }
                else
                {
                    DetailsCol[i] = new BlankControl()
                    {
                        Reserved = ReservedFor.BEFORE_HOR
                    };
                }
            }
            //generate column name
            for (int i = 8; i < ColumnLabels.Length + 8; i++)
            {
                if (ColumnLabels[i - 8] == "")
                {
                    DetailsCol[i] = new BlankControl()
                    {
                        Reserved = ReservedFor.BEFORE_HOR
                    };
                }
                else
                {
                    DetailsCol[i] = new Label()
                    {
                        Text = ColumnLabels[i - 8]
                    }
                };
            }
            int ControlIndex = 16;

            if (ObjectMapList == null)
            {
                goto End;
            }

            foreach (Dictionary <string, object> book_issueMap in ObjectMapList)
            {
                book_issue book_issue = (book_issue)ObjectUtil.FillObjectWithMap(new book_issue(), book_issueMap);
                BookIssues.Add(book_issue);
            }

            for (int i = 0; i < BookIssues.Count; i++)
            {
                book_issue BS = BookIssues[i];
                if (BS == null)
                {
                    continue;
                }
                if (BS.id == null)
                {
                    continue;
                }
                //if (type.Trim().Equals("issue"))
                //{
                //    Dictionary<string, object> CheckReturnResponse = Transaction.FetchObj(0, 0, Transaction.URL, "checkReturnedBook", new Dictionary<string, object>()
                //        {
                //            {"book_issue_id",BS.id }
                //        });
                //    if (CheckReturnResponse["result"].ToString() == "0")
                //    {
                //        BS.book_issue_id = StringUtil.JSONStringToMap(CheckReturnResponse["data"].ToString())["book_issue_id"].ToString();
                //    }
                //}
                bool NotReturned = Type == "issue" && BS.book_return == 0;

                DetailsCol[ControlIndex++] = new Label()
                {
                    Text = (i + 1).ToString() + (NotReturned ? "*" : "")
                };
                DetailsCol[ControlIndex++] = new TextBoxReadonly()
                {
                    Text = BS.id
                };
                DetailsCol[ControlIndex++] = new TextBoxReadonly()
                {
                    Text = BS.issue_id
                };
                DetailsCol[ControlIndex++] = new TextBoxReadonly()
                {
                    Text = BS.book_record_id
                };
                //DetailsCol[ControlIndex++] = new Label() { Text = BS.book_record.book.title };
                DetailsCol[ControlIndex++] = new BlankControl()
                {
                    Reserved = ReservedFor.BEFORE_HOR
                };
                //string Type = this.type.ToLower().Trim();
                //if (Type == ("return"))
                //{
                //    DetailsCol[ControlIndex++] = null;
                //}
                //else
                //{
                DetailsCol[ControlIndex++] = new TextBoxReadonly()
                {
                    Text = BS.book_return.ToString()
                };

                //}
                DetailsCol[ControlIndex++] = new TextBoxReadonly()
                {
                    Text = BS.book_issue_id
                };
                DetailsCol[ControlIndex++] = new BlankControl()
                {
                    Reserved = ReservedFor.BEFORE_HOR
                };
            }
            //
End:
            DetailPanel = ControlUtil.GeneratePanel(8, DetailsCol, 5, 70, 20, Color.Orange, X, Y, W, H);
            return(DetailPanel);
        }
Ejemplo n.º 16
0
        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);
        }
Ejemplo n.º 17
0
        private void PopulateIssueList()
        {
            int No = 0;

            PanelIssueLis.Controls.Clear();
            int BookStillIssued = 0;

            foreach (issue Issue in Issues)
            {
                if (null == Issue.book_issue || Issue.book_issue.Count == 0)
                {
                    continue;
                }
                No++;
                Panel PanelIssue = new Panel();
                PanelIssue.Controls.Add(ControlUtil.GenerateLabel("<b>" + No + ". Issue ID: " + Issue.id + " (" + Issue.type + ")</b><br/>date: " + Issue.date + "<ol>"));
                Panel PanelIssueItem = new Panel();
                foreach (book_issue Bs in Issue.book_issue)
                {
                    List <book_issue> BooksReturned = BookIssueService.GetByBookIssueIdReturned(Bs.id);
                    bool   BookReturned             = BooksReturned.Count == 1;
                    string labelHtml = "<li class=\"book_issue-item\" id=\"Book_Issue_Rec_" + Bs.id
                                       + "\"> Issue Rec Id: " + Bs.id + "<br/>Book Rec Id: "
                                       + Bs.book_record_id + "<br/>"
                                       + Bs.book_record.book.title + " - returned: <code>" + BookReturned + "</code>";// + DateTime.Now.ToString();

                    if (!BookReturned)
                    {
                        string[] Attrs = new string[]
                        {
                            "href=\"#\"",
                            "onclick=SetTextInput('" + Bs.book_record_id + "','MainContent_TextBoxIssueRecordId')"
                        };
                        string anchor = ControlUtil.GenerateHtmlTag("a", Attrs, " return now ");
                        labelHtml += "<br/>" + anchor;
                        BookStillIssued++;
                    }
                    else
                    {
                        string[] Attrs = new string[] {
                            "class=\"pointerable\"",
                            "onclick=\"ScrollToElement('Book_Return_Rec_" + BooksReturned[0].id + "')\""
                        };
                        string anchor = ControlUtil.GenerateHtmlTag("span", Attrs, BooksReturned[0].id);
                        labelHtml += "<br/> Return ref: " + anchor;
                    }
                    labelHtml += "</li>";
                    PanelIssueItem.Controls.Add(ControlUtil.GenerateLabel(labelHtml));
                }
                PanelIssue.Controls.Add(PanelIssueItem);
                DateTime MaxReturn = DateUtil.PlusDay(Issue.date, int.Parse(TextBoxDuration.Text));
                bool     Late      = false;
                if (Issue.date.CompareTo(MaxReturn) > 0)
                {
                    Late = true;
                }
                PanelIssue.Controls.Add(ControlUtil.GenerateLabel("</ol>Max return: " + MaxReturn + ", Late:" + Late + "<hr/>"));
                PanelIssueLis.Controls.Add(PanelIssue);
            }

            issueCount.InnerHtml = BookStillIssued.ToString();

            //BOOK RETURNED
            No = 0;
            PanelIssueReturn.Controls.Clear();

            foreach (issue Issue in IssuesReturn)
            {
                if (null == Issue.book_issue || Issue.book_issue.Count == 0)
                {
                    continue;
                }
                No++;
                Panel PanelIssue = new Panel();
                PanelIssue.Controls.Add(ControlUtil.GenerateLabel("<b>" + No + ". Issue ID: " + Issue.id + " (" + Issue.type + ")</b><br/>date: " + Issue.date + "<ol>"));
                Panel PanelIssueItem = new Panel();

                foreach (book_issue Bs in Issue.book_issue)
                {
                    Bs.book_issue2 = (book_issue)BookIssueService.GetById(Bs.book_issue_id);
                    if (null != Bs.book_issue2)
                    {
                        book_issue BookIssueRef = Bs.book_issue2;
                        issue      IssueRef     = (issue)IssueService.GetById(BookIssueRef.issue_id);
                        DateTime   IssuedDate   = IssueRef.date;
                        DateTime   MaxReturn    = DateUtil.PlusDay(IssuedDate, int.Parse(TextBoxDuration.Text));

                        bool Late = false;
                        if (Issue.date.CompareTo(MaxReturn) > 0)
                        {
                            Late = true;
                        }

                        string[] Attrs = new string[] {
                            "class=\"pointerable\"",
                            "onclick=\"ScrollToElement('Book_Issue_Rec_" + Bs.book_issue_id + "')\""
                        };
                        string anchor = ControlUtil.GenerateHtmlTag("span", Attrs, Bs.book_issue_id);

                        PanelIssueItem.Controls.Add(ControlUtil.GenerateLabel("<li class=\"book_issue-item\" id=\"Book_Return_Rec_" + Bs.id
                                                                              + "\"> Return Rec Id: " + Bs.id + "<br/>Book Rec Id: "
                                                                              + Bs.book_record_id + " - Returned From Issue Rec Id: " + anchor +
                                                                              "<br/>" + Bs.book_record.book.title
                                                                              + "<br/>Issued: " + IssuedDate + "<br/>Max return: " + MaxReturn + " - late: <code>" + Late
                                                                              + "</code></li>"));
                    }
                }


                PanelIssue.Controls.Add(PanelIssueItem);
                PanelIssue.Controls.Add(ControlUtil.GenerateLabel("</ol><hr/>"));
                PanelIssueReturn.Controls.Add(PanelIssue);
            }
        }
Ejemplo n.º 18
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.RequestType == "POST")
            {
                CheckUser();
                string Out    = "\"" + GetTime() + "\"";
                int    Result = 1;
                switch (Request.Form["Action"])
                {
                case "studentVisit":
                    Out = true || UserValid?GetStudentById() : "0";

                    if (Out != null && Out != "0")
                    {
                        string Visit = StudentVisit(Request.Form["Id"].ToString());
                        if (Visit != null && Visit != "0")
                        {
                            Out = "{" +
                                  "\"student\":" + Out + ", \"visit\":" + Visit
                                  + "}";
                            Result = 0;
                        }
                    }
                    break;

                case "addStudent":
                    Out = UserValid ? AddStudent() : "0";
                    if (Out != null && Out != "0")
                    {
                        Out    = "{\"student\":" + Out + "}";
                        Result = 0;
                    }
                    break;

                case "addAuthor":
                    Out = UserValid ? AddAuthor() : "0";
                    if (Out != null && Out != "0")
                    {
                        Out    = "{\"author\":" + Out + "}";
                        Result = 0;
                    }
                    break;

                case "addPublisher":
                    Out = UserValid ? AddPublisher() : "0";
                    if (Out != null && Out != "0")
                    {
                        Out    = "{\"publisher\":" + Out + "}";
                        Result = 0;
                    }
                    break;

                case "addClass":
                    Out = UserValid ? AddClass() : "0";
                    if (Out != null && Out != "0")
                    {
                        Out    = "{\"class\":" + Out + "}";
                        Result = 0;
                    }
                    break;

                case "addCategory":
                    Out = UserValid ? AddCategory() : "0";
                    if (Out != null && Out != "0")
                    {
                        Out    = "{\"category\":" + Out + "}";
                        Result = 0;
                    }
                    break;

                case "addBook":
                    Out = UserValid ? AddBook() : "0";
                    if (Out != null && Out != "0")
                    {
                        Out    = "{\"book\":" + Out + "}";
                        Result = 0;
                    }
                    break;

                case "studentById":
                    Out = UserValid ? GetStudentById() : "0";
                    if (Out != null && Out != "0")
                    {
                        Out    = "{\"student\":" + Out + "}";
                        Result = 0;
                    }
                    break;

                case "bookRecById":
                    Out = UserValid ? GetBookRecordById() : "0";
                    if (Out != null && Out != "0")
                    {
                        Out    = "{\"book_record\":" + Out + "}";
                        Result = 0;
                    }
                    break;

                case "bookList":
                    Out = UserValid ? GetBookList() : "0";
                    if (Out != null && Out != "0")
                    {
                        Out += (
                            ",\"offset\":" + Request.Form["offset"]
                            + ",\"count\":" + BookCount
                            + ",\"limit\":" + Request.Form["limit"]
                            );
                        Result = 0;
                    }
                    break;

                case "studentList":
                    Out = UserValid ? GetStudentList() : "0";
                    if (Out != null && Out != "0")
                    {
                        Out += (
                            ",\"offset\":" + Request.Form["offset"]
                            + ",\"count\":" + StudentCount
                            + ",\"limit\":" + Request.Form["limit"]
                            );
                        Result = 0;
                    }
                    break;

                case "issuesList":
                    Out = UserValid ? GetIssuesList() : "0";
                    if (Out != null && Out != "0")
                    {
                        Out += (
                            ",\"offset\":" + Request.Form["offset"]
                            + ",\"count\":" + IssueCount
                            + ",\"limit\":" + Request.Form["limit"]
                            );
                        Result = 0;
                    }
                    break;

                case "visitList":
                    Out = UserValid ? GetVisitsList() : "0";
                    if (Out != null && Out != "0")
                    {
                        Out += (
                            ",\"offset\":" + Request.Form["offset"]
                            + ",\"count\":" + VisitCount
                            + ",\"limit\":" + Request.Form["limit"]
                            );
                        Result = 0;
                    }
                    break;

                case "classList":
                    Out = UserValid ? GetClassList() : "0";
                    if (Out != null && Out != "0")
                    {
                        Out += (
                            ",\"offset\":" + Request.Form["offset"]
                            + ",\"count\":" + ClassCoount
                            + ",\"limit\":" + Request.Form["limit"]
                            );
                        Result = 0;
                    }
                    break;

                case "authorList":
                    Out = UserValid ? GetAuthorList() : "0";
                    if (Out != null && Out != "0")
                    {
                        Out += (
                            ",\"offset\":" + Request.Form["offset"]
                            + ",\"count\":" + AuthorCount
                            + ",\"limit\":" + Request.Form["limit"]
                            );
                        Result = 0;
                    }
                    break;

                case "publisherList":
                    Out = UserValid ? GetPublisherList() : "0";
                    if (Out != null && Out != "0")
                    {
                        Out += (
                            ",\"offset\":" + Request.Form["offset"]
                            + ",\"count\":" + PublisherCount
                            + ",\"limit\":" + Request.Form["limit"]
                            );
                        Result = 0;
                    }
                    break;

                case "categoryList":
                    Out = UserValid ? GetCategoryList() : "0";
                    if (Out != null && Out != "0")
                    {
                        Out += (
                            ",\"offset\":" + Request.Form["offset"]
                            + ",\"count\":" + CategoryCount
                            + ",\"limit\":" + Request.Form["limit"]
                            );
                        Result = 0;
                    }
                    break;

                case "bookIssueList":
                    Out = UserValid ? GetBookIssueList() : "0";
                    if (Out != null && Out != "0")
                    {
                        Out += (
                            ",\"offset\":" + Request.Form["offset"]
                            + ",\"count\":" + VisitCount
                            + ",\"limit\":" + Request.Form["limit"]
                            );
                        Result = 0;
                    }
                    break;

                case "checkReturnedBook":
                    book_issue ReturnBookIssue = UserValid ? GetBookIssue() : null;
                    if (ReturnBookIssue != null)
                    {
                        Out = (
                            "{\"book_issue_id\":\"" + ReturnBookIssue.id + "\"}"
                            );
                        Result = 0;
                    }
                    else
                    {
                        Result = 1;
                    }
                    break;

                case "getBookIssueByStudentId":
                    string StudentBookIssue = UserValid ? GetBookStudentIssue() : null;
                    if (StudentBookIssue != null && StudentBookIssue != "0")
                    {
                        Out = (
                            "{\"book_issue\":" + StudentBookIssue + "}"
                            );
                        Result = 0;
                    }
                    else
                    {
                        Result = 1;
                    }
                    break;

                case "issueBook":
                    issue Issue = UserValid ? IssueBook() : null;
                    if (Issue != null)
                    {
                        string RecIds = ObjectUtil.ListToDelimitedString(Issue.book_issue, ";", "~", "book_record_id", "id");
                        Out = (
                            "{\"issue_id\":\"" + Issue.id + "\",\"date\":\"" + Issue.date + "\", \"items\":\"" + RecIds + "\"}"
                            );
                        Result = 0;
                    }
                    else
                    {
                        Result = 1;
                    }
                    break;

                case "returnBook":
                    issue IssueReturn = UserValid ? ReturnBook() : null;
                    if (IssueReturn != null)
                    {
                        string RecIds = ObjectUtil.ListToDelimitedString(IssueReturn.book_issue, ";", "~", "book_record_id", "id");
                        Out = (
                            "{\"issue_id\":\"" + IssueReturn.id + "\",\"date\":\"" + IssueReturn.date + "\", \"items\":\"" + RecIds + "\"}"
                            );
                        Result = 0;
                    }
                    else
                    {
                        Result = 1;
                    }
                    break;
                }

                Response.Clear();
                Response.ContentType = "application/json; charset=utf-8";
                Response.Write("{\"result\":" + Result + ",\"data\":" + Out + "}");
                Response.End();
            }
            else
            {
                return;
            }
        }