Example #1
0
        protected void InsertLoan_Click(object sender, EventArgs e)
        {
            if (userIdValidation.IsValid && copyIdValidation.IsValid)
            {
                DataLibrary.Loan loan = new DataLibrary.Loan();

                // Get values from controls
                loan.CopyId = Convert.ToInt32(boxCopyId.Text);
                loan.UserId = Convert.ToInt32(boxUserId.Text);
                DateTime deliveryD = DateTime.ParseExact(boxDelivery.Text, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
                loan.DeliveryDate = Convert.ToDateTime(deliveryD);
                DateTime loanD = DateTime.ParseExact(boxLoanDate.Text, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
                loan.LoanDate = Convert.ToDateTime(loanD);

                try
                {
                    // Insert Loan
                    int loanId = BLoan.insert(loan);
                    // Goest to mainLisLoan
                    Response.Redirect("~/Loan/MainListLoan.aspx");
                }
                catch (Exception generalException)
                {
                    PanelInsertLoan.Visible = true;
                    LiteralInsertLoan.Text  = generalException.Message;
                }
            }
        }
        protected void ButUpdate_Click(object sender, EventArgs e)
        {
            // Get the loanId to update
            loanId = Convert.ToInt32(Request.QueryString["loanId"]);

            // Get the loan by id
            DataLibrary.Loan loan = new DataLibrary.Loan();
            loan = BLoan.getById(loanId);

            // Set values to update from fields and update loan record
            DateTime deliveryD = DateTime.ParseExact(boxDelivery.Text, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);

            loan.DeliveryDate = Convert.ToDateTime(deliveryD);
            DateTime loanD = DateTime.ParseExact(boxLoanDate.Text, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);

            loan.LoanDate = Convert.ToDateTime(loanD);

            BLoan.update(loan);

            // Go to main list page
            Response.Redirect("~/Loan/MainListLoan.aspx");
        }