Пример #1
0
        public static bool Insert(Borrower b)
        {
            try
            {
                string conn = ConfigurationManager.ConnectionStrings["LibraryConnectionString"].ConnectionString;
                SqlConnection cn = new SqlConnection(conn);
                SqlCommand cmd = new SqlCommand("Insert into Borrower(borrowerNumber, name, sex, address,telephone,email) " +
                "values(@borrowerNumber, @name, @sex, @address,@telephone,@email)", cn);
                cmd.Parameters.AddWithValue("@borrowerNumber", b.BorrowerNumber);
                cmd.Parameters.AddWithValue("@name", b.Name);
                cmd.Parameters.AddWithValue("@sex", b.Sex);
                cmd.Parameters.AddWithValue("@address", b.Address);
                cmd.Parameters.AddWithValue("@telephone", b.Telephone);
                cmd.Parameters.AddWithValue("@email", b.Email);

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

                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
        }
Пример #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["borrowerNumber"] != null && !IsPostBack)
            {
                tbBorrowerNum.Enabled = false;
                string s = (string)Session["borrowerNumber"];
                Borrower b = new Borrower();
                b = MemberBL.SelectByID(s);
                tbBorrowerNum.Text = b.BorrowerNumber.ToString();
                tbName.Text = b.Name.ToString();
                tbSex.Text = b.Sex.ToString();
                tbAddress.Text = b.Address;
                tbTelephone.Text = b.Telephone;
                tbEmail.Text = b.Email;

            }
        }
Пример #3
0
 protected void gvBook_RowDeleting(object sender, GridViewDeleteEventArgs e)
 {
     GridViewRow row = gvMember.SelectedRow;
     if (row != null)
     {
         {
             string s = gvMember.Rows[e.RowIndex].Cells[1].Text;
             Borrower b = new Borrower();
             b.BorrowerNumber = int.Parse(s);
             MemberBL.Delete(b);
             FillMember();
         }
     }
     else
     {
         ClientScript.RegisterClientScriptBlock(this.GetType(), "wtf", "alert('Please select a member!');", true);
     }
 }
Пример #4
0
        public static bool Delete(Borrower b)
        {
            try
            {
                string conn = ConfigurationManager.ConnectionStrings["LibraryConnectionString"].ConnectionString;
                SqlConnection cn = new SqlConnection(conn);
                SqlCommand cmd = new SqlCommand("Delete Borrower where borrowerNumber = @borrowerNumber", cn);
                cmd.Parameters.AddWithValue("@borrowerNumber", b.BorrowerNumber);

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

                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
        }
Пример #5
0
        protected void btSave_Click(object sender, EventArgs e)
        {
            lbSex.Visible = false;
            if (tbName.Text != "")
            {
                lbName.Visible = false;

                if (tbSex.Text == "F" || tbSex.Text == "M")
                {
                    Borrower b = new Borrower(int.Parse(tbBorrowerNum.Text), tbName.Text, char.Parse(tbSex.Text), tbAddress.Text, tbTelephone.Text, tbEmail.Text);
                    MemberBL.Insert(b);
                    Response.Redirect("~/GUI/MemberUI.aspx");
                }
                else
                {
                    lbSex.Visible = true;
                }
            }
            else
            {
                lbName.Visible = true;
            }
        }
Пример #6
0
 public static Borrower SelectByID(string s)
 {
     try
     {
         string conn = ConfigurationManager.ConnectionStrings["LibraryConnectionString"].ConnectionString;
         string sql = "SELECT * FROM Borrower where borrowerNumber = " + s;
         SqlDataAdapter da = new SqlDataAdapter(sql, conn);
         DataSet ds = new DataSet();
         da.Fill(ds);
         Borrower br = new Borrower();
         br.BorrowerNumber = int.Parse(ds.Tables[0].Rows[0][0].ToString());
         br.Name = ds.Tables[0].Rows[0][1].ToString();
         br.Sex = char.Parse(ds.Tables[0].Rows[0][2].ToString());
         br.Address = ds.Tables[0].Rows[0][3].ToString();
         br.Telephone = ds.Tables[0].Rows[0][4].ToString();
         br.Email = ds.Tables[0].Rows[0][5].ToString();
         return br;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         return new Borrower();
     }
 }
Пример #7
0
        public static bool Update(Borrower b)
        {
            try
            {
                string conn = ConfigurationManager.ConnectionStrings["LibraryConnectionString"].ConnectionString;
                SqlConnection cn = new SqlConnection(conn);
                SqlCommand cmd = new SqlCommand("Update Borrower set name = @name, "
                + "sex = @sex, address = @address,telephone = @telephone,email = @email where borrowerNumber = @borrowerNumber", cn);
                cmd.Parameters.AddWithValue("@borrowerNumber", b.BorrowerNumber);
                cmd.Parameters.AddWithValue("@name", b.Name);
                cmd.Parameters.AddWithValue("@sex", b.Sex);
                cmd.Parameters.AddWithValue("@telephone", b.Telephone);
                cmd.Parameters.AddWithValue("@email", b.Email);
                cmd.Parameters.AddWithValue("@address", b.Address);

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

                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
        }
Пример #8
0
 public static bool Update(Borrower b)
 {
     return MemberDA.Update(b);
 }
Пример #9
0
 public static bool Insert(Borrower b)
 {
     return MemberDA.Insert(b);
 }
Пример #10
0
 public static bool Delete(Borrower b)
 {
     return MemberDA.Delete(b);
 }