示例#1
0
        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;
                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");
            }
        }