private void GridViewDataBind() { User user = (User)Session["AuthenticatedUserData"]; if (user != null) { GridViewAdmin.DataSource = BorrowDataProcess.GetUserBorrows(user.UserId); //Görüldüğü gibi GridView’e DataSet nesnesi atanıyor. GridViewAdmin.DataBind(); //this.DataBind() değil GridView’in DataBind()’i çağrıldı } else { GridViewAdmin.DataSource = BorrowDataProcess.GetBorrows(); //Görüldüğü gibi GridView’e DataSet nesnesi atanıyor. GridViewAdmin.DataBind(); //this.DataBind() değil GridView’in DataBind()’i çağrıldı } }
protected bool controlReturning(string receiveDate, string returnDate, int memberId, int itemId, string curDate) { if ((User)Session["AuthenticatedUserData"] == null) { return(false); } if (receiveDate.Contains('/')) { string[] temp1 = receiveDate.Split('/'); string[] temp2 = returnDate.Split('/'); receiveDate = temp1[2] + temp1[1] + temp1[0]; returnDate = temp2[2] + temp2[1] + temp2[0]; string[] temp = DateTime.Now.ToShortDateString().Split('/'); curDate = temp[2] + temp[1] + temp[0]; } return(BorrowDataProcess.controlBill(receiveDate, returnDate, memberId, itemId, curDate)); }
protected void Page_Load(object sender, EventArgs e) { if (Session["AuthenticatedUserData"] != null)//Normal User { User user = (User)Session["AuthenticatedUserData"]; LabelWelcome.Text = "Welcome To DEU Library " + user.Name; if (BorrowDataProcess.GetUserBorrows(user.UserId) != null) { ButtonReturn.Visible = true; ButtonExtend.Visible = true; } else { ButtonReturn.Visible = false; ButtonExtend.Visible = false; } ButtonRent.Visible = true; ButtonEditAdmin.Visible = false; ButtonEditBorrow.Visible = false; ButtonEditCategory.Visible = false; ButtonEditItem.Visible = false; ButtonEditMember.Visible = false; ButtonEditPublisher.Visible = false; } else if (Session["AuthenticatedAdminData"] != null)//Admin { User admin = (User)Session["AuthenticatedAdminData"]; LabelWelcome.Text = "Welcome To DEU Library " + admin.Name; LabelAdmin.Text = "Admin Functions"; ButtonRent.Visible = false; ButtonReturn.Visible = false; ButtonExtend.Visible = false; ButtonEditAdmin.Visible = true; ButtonEditBorrow.Visible = true; ButtonEditCategory.Visible = true; ButtonEditItem.Visible = true; ButtonEditMember.Visible = true; ButtonEditPublisher.Visible = true; } }
protected void GridViewAdmin_RowCommand(object sender, GridViewCommandEventArgs e) { User user = (User)Session["AuthenticatedUserData"]; if (e.CommandName == "ExtendTime") { int rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex; GridViewAdmin.EditIndex = rowIndex; GridViewAdmin.DataSource = BorrowDataProcess.GetUserBorrows(user.UserId); //Görüldüğü gibi GridView’e DataSet nesnesi atanıyor. GridViewAdmin.DataBind(); //this.DataBind() değil GridView’in DataBind()’i çağrıldı } else if (e.CommandName == "Extend") { int rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex; String Returndate = ((DropDownList)GridViewAdmin.Rows[rowIndex].FindControl("ddlReturnTime")).SelectedValue; String RecieveDate = ((Label)GridViewAdmin.Rows[rowIndex].FindControl("LabelRecieve")).Text; String name = ((Label)GridViewAdmin.Rows[rowIndex].FindControl("LabelUserName")).Text; String itemName = ((Label)GridViewAdmin.Rows[rowIndex].FindControl("LabelEditName")).Text; int userId = BorrowDataProcess.getUserIdByNickName(name).UserId; int itemId = ItemDataProcess.getItemIdByItemName(itemName); Borrow borrow = new Borrow(); string oldDate = (e.CommandArgument).ToString().Substring(0, 10); string[] tempDate = oldDate.Split('.'); int coeff = Convert.ToInt32(Returndate.Split(' ')[0]); int day = Convert.ToInt32(tempDate[0]) + (coeff * 7); int month = Convert.ToInt32(tempDate[1]); int year = Convert.ToInt32(tempDate[2]); if (day > 30) { day = day % 30; month++; } if (month > 12) { month = month % 12; year++; } Returndate = year.ToString() + month.ToString().PadLeft(2, '0') + day.ToString().PadLeft(2, '0'); borrow.ReturnDate = Returndate.ToString(); borrow.UserId = userId; borrow.ItemId = itemId; BorrowDataProcess.UpdateBorrow(borrow); GridViewAdmin.EditIndex = -1; GridViewAdmin.DataSource = BorrowDataProcess.GetUserBorrows(user.UserId); //Görüldüğü gibi GridView’e DataSet nesnesi atanıyor. GridViewAdmin.DataBind(); //this.DataBind() değil GridView’in DataBind()’i çağrıldı } else if (e.CommandName == "ReturnItem") { int rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex; String Returndate = ((Label)GridViewAdmin.Rows[rowIndex].FindControl("LabelReturn")).Text; String name = ((Label)GridViewAdmin.Rows[rowIndex].FindControl("LabelUserName")).Text; String itemName = ((Label)GridViewAdmin.Rows[rowIndex].FindControl("LabelName")).Text; String RecieveDate = ((Label)GridViewAdmin.Rows[rowIndex].FindControl("LabelReceive")).Text; int userId = BorrowDataProcess.getUserIdByNickName(name).UserId; int itemId = ItemDataProcess.getItemIdByItemName(itemName); int memberId = MemberDataProcess.getMemberByUserId(userId).MemberId; //controlReturning(RecieveDate,Returndate); string[] cRetDate = Returndate.Split('/'); string tempRet = cRetDate[2] + cRetDate[1] + cRetDate[0]; string[] cRecDate = RecieveDate.Split('/'); string tempRec = cRecDate[2] + cRecDate[1] + cRecDate[0]; Bill bill = new Bill(); string[] temp = DateTime.Now.ToShortDateString().Split('/'); bill.BillDate = temp[2] + temp[1] + temp[0]; bill.ItemID = itemId; bill.MemberID = memberId; bill.BillValue = calculateBillValue(tempRet).ToString(); BorrowDataProcess.InsertBill(bill); Response.Redirect("HomeLibrary.aspx"); } else if (e.CommandName == "CancelUpdate") { GridViewAdmin.EditIndex = -1; GridViewAdmin.DataSource = BorrowDataProcess.GetUserBorrows(user.UserId); //Görüldüğü gibi GridView’e DataSet nesnesi atanıyor. GridViewAdmin.DataBind(); //this.DataBind() değil GridView’in DataBind()’i çağrıldı } }
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "EditRow") { int rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex; GridViewAdmin.EditIndex = rowIndex; GridViewDataBind(); } else if (e.CommandName == "DeleteRow") { int memberID = Convert.ToInt32(e.CommandArgument); int userID = MemberDataProcess.getUserIdByMemberId(memberID); MemberDataProcess.DeleteBillByMemberID(memberID); BorrowDataProcess.DeleteBorrowByUserID(userID);//Önce kiralamaları varsa onları siliyoruz. MemberDataProcess.DeleteMemberByID(Convert.ToInt32(e.CommandArgument)); GridViewDataBind(); } else if (e.CommandName == "CancelUpdate") { GridViewAdmin.EditIndex = -1; GridViewDataBind(); } else if (e.CommandName == "UpdateRow") { int rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex; Member member = new Member(); User user = new User(); member.MemberId = Convert.ToInt32(e.CommandArgument); member.FacultyName = ((DropDownList)GridViewAdmin.Rows[rowIndex].FindControl("ddlFacultyName")).SelectedItem.Text; member.MemberType = ((DropDownList)GridViewAdmin.Rows[rowIndex].FindControl("ddlMemberType")).SelectedItem.Text; member.IsActive = true; user.Name = ((TextBox)GridViewAdmin.Rows[rowIndex].FindControl("TextBoxMemberName")).Text; user.Gender = ((DropDownList)GridViewAdmin.Rows[rowIndex].FindControl("ddlGender")).SelectedItem.Text; user.Address = ((TextBox)GridViewAdmin.Rows[rowIndex].FindControl("TextBoxMemberAddress")).Text; user.Password = ((TextBox)GridViewAdmin.Rows[rowIndex].FindControl("TextBoxMemberPassword")).Text; user.NickName = ((TextBox)GridViewAdmin.Rows[rowIndex].FindControl("TextBoxMemberNickName")).Text; user.IsOnline = false; user.Mail = ((TextBox)GridViewAdmin.Rows[rowIndex].FindControl("TextBoxMemberMail")).Text; GridViewAdmin.EditIndex = -1; member.UserId = MemberDataProcess.getUserIdByMemberId(member.MemberId); user.UserId = MemberDataProcess.getUserIdByMemberId(member.MemberId); UserDataProcess.UpdateUsers(user); MemberDataProcess.UpdateMembers(member); GridViewDataBind(); } else if (e.CommandName == "InsertRow") { Member member = new Member(); User user = new User(); member.FacultyName = ((DropDownList)GridViewAdmin.FooterRow.FindControl("ddlMemberInsertFacultyName")).SelectedItem.Text; member.MemberType = ((DropDownList)GridViewAdmin.FooterRow.FindControl("ddlMemberInsertType")).SelectedItem.Text; member.IsActive = true; user.Name = ((TextBox)GridViewAdmin.FooterRow.FindControl("txtName")).Text; user.Gender = ((DropDownList)GridViewAdmin.FooterRow.FindControl("ddlMemberInsertGender")).SelectedItem.Text; user.Address = ((TextBox)GridViewAdmin.FooterRow.FindControl("txtAddress")).Text; user.Password = ((TextBox)GridViewAdmin.FooterRow.FindControl("txtPassword")).Text; user.NickName = ((TextBox)GridViewAdmin.FooterRow.FindControl("txtNickName")).Text; user.IsOnline = false; user.Mail = ((TextBox)GridViewAdmin.FooterRow.FindControl("txtMail")).Text; UserDataProcess.InsertUser(user); member.UserId = MemberDataProcess.getUserIdByNickName(user.NickName); MemberDataProcess.InsertMember(member); GridViewDataBind(); } }
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "EditRow") { int rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex; GridViewAdminDistinct.EditIndex = rowIndex; FillGridView(); } else if (e.CommandName == "DeleteRow") { if (ItemDataProcess.type == bookType) { ItemDataProcess.DeleteBookByID(Convert.ToInt32(e.CommandArgument)); } else if (ItemDataProcess.type == journalType) { ItemDataProcess.DeleteJournalByID(Convert.ToInt32(e.CommandArgument)); } else if (ItemDataProcess.type == newspaperType) { ItemDataProcess.DeleteNewspaperByID(Convert.ToInt32(e.CommandArgument)); } else if (ItemDataProcess.type == videoType) { ItemDataProcess.DeleteVideoByID(Convert.ToInt32(e.CommandArgument)); } FillGridView(); } else if (e.CommandName == "CancelUpdate") { GridViewAdminDistinct.EditIndex = -1; FillGridView(); } else if (e.CommandName == "UpdateRow") { int rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex; Item item = new Item(); item.Name = ((TextBox)GridViewAdminDistinct.Rows[rowIndex].FindControl("TextBoxDistinctItemName")).Text; String state = ((DropDownList)GridViewAdminDistinct.Rows[rowIndex].FindControl("ddlDistinctItemState")).SelectedValue; if (state == "Available") { item.State = 1; } else if (state == "Unavailable") { item.State = 0; } item.ProductionDate = deConvertDate(((TextBox)GridViewAdminDistinct.Rows[rowIndex].FindControl("TextBoxDistinctItemProductionDate")).Text);//Date aldıktan sonra işlem yapppppp..... item.CategoryId = ItemDataProcess.getCategoryIDByName(((DropDownList)GridViewAdminDistinct.Rows[rowIndex].FindControl("ddlDistinctItemCategory")).SelectedItem.Text); item.PublisherId = ItemDataProcess.getPublisherIDByName(((DropDownList)GridViewAdminDistinct.Rows[rowIndex].FindControl("ddlDistinctItemPublisher")).SelectedItem.Text); item.Type = ((Label)GridViewAdminDistinct.Rows[rowIndex].FindControl("LabelDistinctEditType")).Text; if (ItemDataProcess.type == bookType) { Book book = new Book(); book.BookId = Convert.ToInt32(e.CommandArgument); book.Author = ((TextBox)GridViewAdminDistinct.Rows[rowIndex].FindControl("TextBoxDistinctItemKolon")).Text; item.ItemId = ItemDataProcess.getBookByBookId(book.BookId).ItemId; ItemDataProcess.UpdateItems(item); book.ItemId = ItemDataProcess.getItemIdByItemName(item.Name); ItemDataProcess.UpdateBook(book); } else if (ItemDataProcess.type == journalType) { Journal journal = new Journal(); journal.JournalId = Convert.ToInt32(e.CommandArgument); journal.TimeRange = ((TextBox)GridViewAdminDistinct.Rows[rowIndex].FindControl("TextBoxDistinctItemKolon")).Text; item.ItemId = ItemDataProcess.getJournalByJournalId(journal.JournalId).ItemId; ItemDataProcess.UpdateItems(item); journal.ItemId = ItemDataProcess.getItemIdByItemName(item.Name); ItemDataProcess.UpdateJournal(journal); } else if (ItemDataProcess.type == newspaperType) { Newspaper news = new Newspaper(); news.NewspaperId = Convert.ToInt32(e.CommandArgument); news.Period = ((TextBox)GridViewAdminDistinct.Rows[rowIndex].FindControl("TextBoxDistinctItemKolon")).Text; item.ItemId = ItemDataProcess.getNewspaperByNewspaperId(news.NewspaperId).ItemId; ItemDataProcess.UpdateItems(item); news.ItemId = ItemDataProcess.getItemIdByItemName(item.Name); ItemDataProcess.UpdateNewspaper(news); } else if (ItemDataProcess.type == videoType) { Video video = new Video(); video.VideoId = Convert.ToInt32(e.CommandArgument); video.Format = ((TextBox)GridViewAdminDistinct.Rows[rowIndex].FindControl("TextBoxDistinctItemKolon")).Text; item.ItemId = ItemDataProcess.getVideoByVideoId(video.VideoId).ItemId; ItemDataProcess.UpdateItems(item); video.ItemId = ItemDataProcess.getItemIdByItemName(item.Name); ItemDataProcess.UpdateVideo(video); } GridViewAdminDistinct.EditIndex = -1; FillGridView(); } else if (e.CommandName == "InsertRow") { Item item = new Item(); item.Name = ((TextBox)GridViewAdminDistinct.FooterRow.FindControl("txtDistinctName")).Text; String state = ((DropDownList)GridViewAdminDistinct.FooterRow.FindControl("ddlDistinctItemInsertState")).SelectedValue; if (state == "Available") { item.State = 1; } else if (state == "Unavailable") { item.State = 0; } string date = ((DropDownList)GridViewAdminDistinct.FooterRow.FindControl("ddlDistinctItemYear")).Text + ((DropDownList)GridViewAdminDistinct.FooterRow.FindControl("ddlDistinctItemMonth")).Text.PadLeft(2, '0') + ((DropDownList)GridViewAdminDistinct.FooterRow.FindControl("ddlDistinctItemDay")).Text.PadLeft(2, '0'); item.ProductionDate = date; item.CategoryId = ItemDataProcess.getCategoryIDByName(((DropDownList)GridViewAdminDistinct.FooterRow.FindControl("ddlDistinctFooterItemCategory")).SelectedItem.Text); item.PublisherId = ItemDataProcess.getPublisherIDByName(((DropDownList)GridViewAdminDistinct.FooterRow.FindControl("ddlDistinctFooterItemPublisher")).SelectedItem.Text); string types = returnPrimaryKey(); item.Type = types.Substring(0, types.Length - 2); if (ItemDataProcess.type == bookType) { Book book = new Book(); book.Author = ((TextBox)GridViewAdminDistinct.FooterRow.FindControl("txtDistinctKolon")).Text; ItemDataProcess.InsertItems(item); book.ItemId = ItemDataProcess.getItemIdByItemName(item.Name); ItemDataProcess.InsertBook(book); } else if (ItemDataProcess.type == journalType) { Journal jor = new Journal(); jor.TimeRange = ((TextBox)GridViewAdminDistinct.FooterRow.FindControl("txtDistinctKolon")).Text; ItemDataProcess.InsertItems(item); jor.ItemId = ItemDataProcess.getItemIdByItemName(item.Name); ItemDataProcess.InsertJournal(jor); } else if (ItemDataProcess.type == newspaperType) { Newspaper news = new Newspaper(); news.Period = ((TextBox)GridViewAdminDistinct.FooterRow.FindControl("txtDistinctKolon")).Text; ItemDataProcess.InsertItems(item); news.ItemId = ItemDataProcess.getItemIdByItemName(item.Name); ItemDataProcess.InsertNewspaper(news); } else if (ItemDataProcess.type == videoType) { Video video = new Video(); video.Format = ((TextBox)GridViewAdminDistinct.FooterRow.FindControl("txtDistinctKolon")).Text; ItemDataProcess.InsertItems(item); video.ItemId = ItemDataProcess.getItemIdByItemName(item.Name); ItemDataProcess.InsertVideo(video); } FillGridView(); } else if (e.CommandName == "Rent")/*Kiralama Kısmı*/ { User user = (User)Session["AuthenticatedUserData"]; Item item = new Item(); int id = Convert.ToInt16(e.CommandArgument);//book ise bookId, video ise video id ..... string[] tempItem = new string[10]; if (ItemDataProcess.type == bookType) { tempItem = ItemDataProcess.getBookByItemId(id); } else if (ItemDataProcess.type == journalType) { tempItem = ItemDataProcess.getJournalByItemId(id); } else if (ItemDataProcess.type == newspaperType) { tempItem = ItemDataProcess.getNewspaperByItemId(id); } else if (ItemDataProcess.type == videoType) { tempItem = ItemDataProcess.getVideoByItemId(id); } item.ItemId = Convert.ToInt32(tempItem[0]); item.Name = tempItem[1]; item.State = Convert.ToInt32(tempItem[2]); item.ProductionDate = tempItem[3]; item.CategoryId = Convert.ToInt32(tempItem[4]); item.PublisherId = Convert.ToInt32(tempItem[5]); item.Type = tempItem[6]; Borrow borrow = new Borrow(); borrow.ItemId = item.ItemId; borrow.UserId = user.UserId; string dateReceive = ""; string dateReturn = ""; string[] temp = DateTime.Now.ToShortDateString().Split('-'); dateReceive = temp[2] + temp[1].PadLeft(2, '0') + temp[0].PadLeft(2, '0'); int day = Convert.ToInt32(temp[0]) + 7; int month = Convert.ToInt32(temp[1]); int year = Convert.ToInt32(temp[2]); if (day > 30) { day = day % 30; month++; } if (month > 12) { month = month % 12; year++; } dateReturn = year + month.ToString().PadLeft(2, '0') + day.ToString().PadLeft(2, '0'); borrow.ReceiveDate = dateReceive; borrow.ReturnDate = dateReturn; BorrowDataProcess.InsertBorrow(borrow); Response.Redirect("BorrowList.aspx"); } }