protected void firstButton_Click(object sender, EventArgs e)
        {
            BookReject bookReject = bookRejectManager.GetBookReject(0);

            GetData(bookReject);
            Session["active"] = 0;
        }
        protected void saveButton_Click(object sender, EventArgs e)
        {
            BookReject bookReject = new BookReject();

            bookReject.Date       = dateTextBox.Value;
            bookReject.DistrictId = int.Parse(districtNameDropDownList.SelectedValue);
            bookReject.PartyId    = int.Parse(partyNameDropDownList.SelectedValue);
            bookReject.RejectNo   = rejectNoTextBox.Text;
            bookReject.Year       = yearTextBox.Text;
            bookReject.GroupId    = int.Parse(groupNameDropDownList.SelectedValue);
            bookReject.BookId     = int.Parse(bookNameDropDownList.SelectedValue);
            string quantity   = quantityTextBox.Text;
            string rejectRate = rejectRateTextBox.Text;
            string total      = totalTextBox.Text;

            if (dateTextBox.Value == "" || rejectNoTextBox.Text == "" || yearTextBox.Text == "" ||
                quantityTextBox.Text == "" || rejectRateTextBox.Text == "" || totalTextBox.Text == "")
            {
                messageLabel.InnerText = "All Fields are Required!!";
            }
            else
            {
                bookReject.Quantity    = Convert.ToDouble(quantity);
                bookReject.RejectRate  = Convert.ToDouble(rejectRate);
                bookReject.Total       = Convert.ToDouble(total);
                messageLabel.InnerText = bookRejectManager.Save(bookReject);
            }
            ClearTextBoxes();
        }
 public string Save(BookReject bookReject)
 {
     if (bookRejectGateway.Insert(bookReject) > 0)
     {
         return("Saved Successfully!!");
     }
     return("Could Not Save data in Database!!");
 }
        protected void lastButton_Click(object sender, EventArgs e)
        {
            List <BookReject> bookRejectList = (List <BookReject>)(Session["bookReject"]);
            int        x          = bookRejectList.Count - 1;
            BookReject bookReject = bookRejectManager.GetBookReject(x);

            GetData(bookReject);
            Session["active"] = x;
        }
 private void GetData(BookReject bookReject)
 {
     dateTextBox.Value             = bookReject.Date;
     districtNameDropDownList.Text = bookReject.DistrictName;
     partyNameDropDownList.Text    = bookReject.PartyName;
     rejectNoTextBox.Text          = bookReject.RejectNo;
     yearTextBox.Text           = bookReject.Year;
     groupNameDropDownList.Text = bookReject.GroupName;
     bookNameDropDownList.Text  = bookReject.BookId.ToString();
     bookRateTextBox.Text       = bookReject.BookRate.ToString();
     commissionTextBox.Text     = bookReject.Commission.ToString();
     quantityTextBox.Text       = bookReject.Quantity.ToString();
     rejectRateTextBox.Text     = bookReject.RejectRate.ToString();
     totalTextBox.Text          = bookReject.Total.ToString();
 }
        public int Insert(BookReject bookReject)
        {
            SqlConnection connection = new SqlConnection(connectionString);
            string        query      = "INSERT INTO tbl_bookReject VALUES('" + bookReject.Date + "','" + bookReject.DistrictId +
                                       "','" + bookReject.PartyId + "','" + bookReject.RejectNo + "','" + bookReject.Year + "','" +
                                       bookReject.GroupId + "','" + bookReject.BookId + "','" + bookReject.Quantity + "','" +
                                       bookReject.RejectRate + "','" + bookReject.Total + "')";
            SqlCommand command = new SqlCommand(query, connection);

            connection.Open();
            int rowAffected = command.ExecuteNonQuery();

            connection.Close();
            return(rowAffected);
        }
        protected void searchButton_Click(object sender, EventArgs e)
        {
            var        m          = rejectTextBox.Value;
            BookReject bookReject = bookRejectManager.GetSearchInfo(m);

            if (bookReject.RejectNo == null)
            {
                message.InnerText = "Invalid Reject No!!";
                ClearTextBoxes();
            }
            else
            {
                GetData(bookReject);
                message.InnerText = "";
            }
        }
        protected void previousButton_Click(object sender, EventArgs e)
        {
            int active = (int)Session["active"];

            active--;
            List <BookReject> bookRejectList = (List <BookReject>)(Session["bookReject"]);

            if (active <= -1)
            {
                active = bookRejectList.Count - 1;
            }
            BookReject bookReject = bookRejectManager.GetBookReject(active);

            GetData(bookReject);
            Session["active"] = active;
        }
        protected void nextButton_Click(object sender, EventArgs e)
        {
            int active = (int)Session["active"];

            active++;
            List <BookReject> bookRejectList = (List <BookReject>)(Session["bookReject"]);

            if (active >= bookRejectList.Count)
            {
                active = 0;
            }
            BookReject bookReject = bookRejectManager.GetBookReject(active);

            GetData(bookReject);
            Session["active"] = active;
        }
        public BookReject GetSearchInfo(string s)
        {
            SqlConnection connection = new SqlConnection(connectionString);
            string        query      = "SELECT * FROM tbl_bookReject WHERE reject_no='" + s + "'";
            SqlCommand    command    = new SqlCommand(query, connection);

            connection.Open();
            BookReject    bookReject = new BookReject();
            SqlDataReader reader     = command.ExecuteReader();

            while (reader.Read())
            {
                GetValueFromDatabase(bookReject, reader);
            }
            reader.Close();
            connection.Close();
            return(bookReject);
        }
        public BookReject GetBookReject(int i)
        {
            SqlConnection connection = new SqlConnection(connectionString);
            string        query      = "SELECT * FROM tbl_bookReject ORDER BY id ASC OFFSET " + i + " ROWS FETCH NEXT 1 ROWS ONLY";
            SqlCommand    command    = new SqlCommand(query, connection);

            connection.Open();
            SqlDataReader reader     = command.ExecuteReader();
            BookReject    bookReject = new BookReject();

            while (reader.Read())
            {
                GetValueFromDatabase(bookReject, reader);
            }
            reader.Close();
            connection.Close();
            return(bookReject);
        }
        private void GetValueFromDatabase(BookReject bookReject, SqlDataReader reader)
        {
            bookReject.BookRejectId = int.Parse(reader["id"].ToString());
            bookReject.Date         = reader["date"].ToString();
            bookReject.DistrictName = reader["district_id"].ToString();
            bookReject.PartyName    = reader["party_id"].ToString();
            bookReject.RejectNo     = reader["reject_no"].ToString();
            bookReject.Year         = reader["year"].ToString();
            bookReject.GroupName    = reader["group_id"].ToString();
            bookReject.BookId       = int.Parse(reader["book_id"].ToString());
            BookInfo bookInfo = GetRejectBook(bookReject.BookId);

            bookReject.BookRate   = bookInfo.BookRate;
            bookReject.Commission = bookInfo.BookCommission;
            bookReject.Quantity   = Convert.ToDouble(reader["quantity"].ToString());
            bookReject.RejectRate = Convert.ToDouble(reader["reject_rate"].ToString());
            bookReject.Total      = Convert.ToDouble(reader["total"].ToString());
        }
        private string LoadNextRejectNo()
        {
            BookReject bookReject = bookRejectManager.GetNextRejectNo();
            string     rejectNo   = bookReject.RejectNo;
            int        count;

            if (rejectNo == null)
            {
                count = 1;
            }
            else
            {
                count = (rejectNo[4] - '0') * 10 + (rejectNo[5] - '0') + 1;
            }

            string nextRejectNo = "Rj-0" + count.ToString("00");

            return(nextRejectNo);
        }
        public BookReject GetNextRejectNo()
        {
            SqlConnection connection = new SqlConnection(connectionString);
            string        query      = "SELECT TOP 1 * FROM tbl_bookReject ORDER BY id DESC";
            SqlCommand    command    = new SqlCommand(query, connection);

            connection.Open();
            SqlDataReader reader     = command.ExecuteReader();
            BookReject    bookReject = new BookReject();

            while (reader.Read())
            {
                bookReject.BookRejectId = int.Parse(reader["id"].ToString());
                bookReject.RejectNo     = reader["reject_no"].ToString();
            }
            reader.Close();
            connection.Close();
            return(bookReject);
        }
        public List <BookReject> GetAllBookRejectList()
        {
            SqlConnection connection = new SqlConnection(connectionString);
            string        query      = "SELECT * FROM tbl_bookReject";
            SqlCommand    command    = new SqlCommand(query, connection);

            connection.Open();
            SqlDataReader     reader         = command.ExecuteReader();
            List <BookReject> bookRejectList = new List <BookReject>();

            while (reader.Read())
            {
                BookReject bookReject = new BookReject();
                GetValueFromDatabase(bookReject, reader);

                bookRejectList.Add(bookReject);
            }
            reader.Close();
            connection.Close();
            return(bookRejectList);
        }