Пример #1
0
        protected void button2_Click(object sender, EventArgs e)
        {
            ReturnDA k = new ReturnDA();

            CirculatedCopy c = new CirculatedCopy();
            try
            {
                c.Id = int.Parse(GridView1.SelectedRow.Cells[1].Text);
                c.CopyNumber = int.Parse(GridView1.SelectedRow.Cells[2].Text);
                c.BorrowerNumber = int.Parse(GridView1.SelectedRow.Cells[3].Text);
                c.DueDate = DateTime.ParseExact(GridView1.SelectedRow.Cells[5].Text, "d/M/yyyy", null);
                c.BorrowedDate = DateTime.ParseExact(GridView1.SelectedRow.Cells[4].Text, "d/M/yyyy", null);
            }
            catch (Exception)
            {
                lbError.Text = "You must select a book !";
                lbError.Visible = true;
                return;
            }

            try
            {
                c.ReturnedDate = DateTime.ParseExact(textBox3.Text, "d/M/yyyy", null);
            }
            catch (Exception ex)
            {
                lbError.Text = ex.Message;
                lbError.Visible = true;

                return;
            }
            if (c.ReturnedDate.Date < c.BorrowedDate)
            {
                lbError.Text = "BorrowedDate must less than ReturnedDate !";
                lbError.Visible = true;
                //MessageBox.Show("BorrowedDate must less than ReturnedDate !");
                return;
            }
            TimeSpan dayLater = c.ReturnedDate.Date - c.DueDate;
            double ngay = dayLater.TotalDays;
            if (ngay > 0)
            {
                c.FineAmount = (int)ngay;
            }
            else c.FineAmount = 0;
            k.returnUpdate(c.CopyNumber);
            k.cirUpdate(c);
            button2.Enabled = false;
            DataSet ds = k.SelectDS(c.CopyNumber);
            DataView dv = new DataView(ds.Tables[0]);
            GridView1.DataSource = dv;
            GridView1.DataBind();
            Label4.Text = "" + ds.Tables[0].Rows.Count;
            lbError.Text = ("Return Successfully !");
            lbError.Visible = true;
        }
Пример #2
0
        public void cirUpdate(CirculatedCopy c)
        {
            try
            {
                string cm = "Update CirculatedCopy set returnedDate = @returnedDate, fineAmount = @fineAmount " + "where copyNumber = "
                            + c.CopyNumber + "AND ID =" + c.Id;

                string conn = ConfigurationManager.ConnectionStrings["LibraryConnectionString"].ConnectionString;
                SqlConnection cn = new SqlConnection(conn);
                SqlCommand cmd = new SqlCommand(cm, cn);
                cmd.Parameters.AddWithValue("@returnedDate", c.ReturnedDate);
                cmd.Parameters.AddWithValue("@fineAmount", c.FineAmount);

                cn.Open();
                cmd.ExecuteNonQuery();
                cn.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }
Пример #3
0
        protected void button3_Click(object sender, EventArgs e)
        {
            BorrowBL a = new BorrowBL();
            BorrowDA b = new BorrowDA();
            //DateTime returnDate = new DateTime();

            CirculatedCopy c = new CirculatedCopy();
            try
            {
                c.Id = int.Parse(GridView1.SelectedRow.Cells[1].Text);
                c.CopyNumber = int.Parse(GridView1.SelectedRow.Cells[2].Text);
                c.BorrowerNumber = int.Parse(GridView1.SelectedRow.Cells[3].Text);
                c.DueDate = DateTime.ParseExact(GridView1.SelectedRow.Cells[5].Text, "d/M/yyyy", null);
                c.BorrowedDate = DateTime.ParseExact(GridView1.SelectedRow.Cells[4].Text, "d/M/yyyy", null);
            }
            catch (Exception)
            {
                lbError.Text = "You must select a book !";
                lbError.Visible = true;

                return;
            }

            try
            {
                c.ReturnedDate = DateTime.ParseExact(textBox3.Text, "d/M/yyyy", null);
            }
            catch (Exception ex)
            {

                lbError.Text = (ex.Message);
                lbError.Visible = true;
                return;
            }
            if (c.ReturnedDate.Date < c.BorrowedDate)
            {
                lbError.Text = ("BorrowedDate must less than ReturnedDate !");
                lbError.Visible = true;
                return;
                //MessageBox.Show("BorrowedDate must less than ReturnedDate !");
            }
            TimeSpan dayLater = c.ReturnedDate.Date - c.DueDate;
            double ngay = dayLater.TotalDays;
            if (ngay > 0)
            {
                textBox4.Text = "" + ngay;
            }
            else textBox4.Text = "0";

            GridView1.Enabled = false;
            textBox3.Enabled = false;
            button3.Enabled = false;
            button2.Enabled = true;
        }
Пример #4
0
        protected void button3_Click(object sender, EventArgs e)
        {
            BorrowBL a = new BorrowBL();
            BorrowDA b = new BorrowDA();
            DateTime brDate = new DateTime();
            try
            {
                brDate = DateTime.ParseExact(textBox4.Text, "d/M/yyyy", null);
            }
            catch (Exception ex)
            {
                Label1.Text = "Please enter a corect date!";
                Label1.Visible = true;
                return;
            }

            DateTime dueDate = brDate.AddDays(14);
            textBox5.Text = dueDate.ToShortDateString();
            int copyNum = int.Parse(textBox3.Text);
            int brNum = int.Parse(textBox1.Text);
            CirculatedCopy h = new CirculatedCopy();
            a.SetIdMax();
            h.Id = ++a.idMax;
            h.CopyNumber = copyNum;
            h.BorrowerNumber = brNum;
            h.BorrowedDate = brDate;
            h.DueDate = dueDate;
            b.insertBorrow(h);
            b.borrowUpdate(copyNum);
            FillBorrow(brNum);
            bool test2 = a.checkReserve1(copyNum);
            bool test3 = a.checkReserve(copyNum, b.getBoNum(copyNum), int.Parse(textBox1.Text));
            if (test2 && test3)
            {
                b.borrowReUpdate(b.getBoNum(copyNum), int.Parse(textBox1.Text));
            }
            button3.Enabled = false;
            textBox4.Enabled = false;
        }
Пример #5
0
        public void insertBorrow(CirculatedCopy a)
        {
            try
            {
                string conn = ConfigurationManager.ConnectionStrings["LibraryConnectionString"].ConnectionString;
                SqlConnection cn = new SqlConnection(conn);
                SqlCommand cmd = new SqlCommand("SET IDENTITY_INSERT [dbo].[CirculatedCopy] ON" + "\n" + "Insert into CirculatedCopy(ID, copyNumber, borrowerNumber, borrowedDate,dueDate,returnedDate,fineAmount) " +
                "values(@ID, @copyNumber,@borrowerNumber, @borrowedDate,@dueDate,NULL,NULL)", cn);

                cmd.Parameters.AddWithValue("@ID", a.Id);
                cmd.Parameters.AddWithValue("@copyNumber", a.CopyNumber);
                cmd.Parameters.AddWithValue("@borrowerNumber", a.BorrowerNumber);
                cmd.Parameters.AddWithValue("@borrowedDate", a.BorrowedDate);
                cmd.Parameters.AddWithValue("@dueDate", a.BorrowedDate.AddDays(14));
                //cmd.Parameters.AddWithValue("@returnedDate", null);
                //cmd.Parameters.AddWithValue("@fineAmount", 0);
                cn.Open();

                cmd.ExecuteNonQuery();
                cn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }