public Admain_Opr_Books() { InitializeComponent(); oracleConnection = new OracleConnection(connectionString); ltCus = new List <BookUtil>(); Update(); bookUtil = new BookUtil(); }
private void Button_Click_2(object sender, RoutedEventArgs e) //借阅 { if (Convert.ToInt32(borrowUtil.Surplus) <= 0) { //MessageBox.Show(borrowUtil.Surplus); MessageBox.Show("该书已经全部借阅出去了"); } else { int result = 0; try { oracleConnection.Open(); OracleCommand oracleCommand = oracleConnection.CreateCommand(); string cmdStr = @"insert into borrow values('" + user.Id + "' ,'" + borrowUtil.Id + "',to_date('" + DateTime.Now.ToString("yyyy-MM-dd") + "','yyyy-mm-dd'),to_date('" + DateTime.Now.AddDays(30).ToString("yyyy-MM-dd") + "','yyyy-mm-dd'))"; oracleCommand.CommandText = cmdStr; result = oracleCommand.ExecuteNonQuery(); DataTable dt = new DataTable("table1"); cmdStr = @"select * from book "; OracleCommand command = new OracleCommand(cmdStr, oracleConnection); OracleDataAdapter adapter = new OracleDataAdapter(command); adapter.Fill(dt); adapter.Dispose(); listView.ItemsSource = null; ltCus.Clear(); foreach (DataRow dataRow in dt.Rows) { BookUtil bookUtil = new BookUtil(); bookUtil.Id = dataRow["BOOK_ID"].ToString(); bookUtil.Name = dataRow["BOOK_NAME"].ToString(); bookUtil.Writer = dataRow["book_writer"].ToString(); bookUtil.Price = dataRow["book_price"].ToString(); bookUtil.Count = ltCus.Count + 1; bookUtil.Number = dataRow["book_count"].ToString(); bookUtil.PublicTime = dataRow["publish_time"].ToString(); bookUtil.Surplus = dataRow["book_surplus"].ToString(); ltCus.Add(bookUtil); } listView.ItemsSource = ltCus; } catch { MessageBox.Show("借阅失败!"); } finally { oracleConnection.Close(); } if (result == 1) { MessageBox.Show("借阅成功!"); } button.IsEnabled = false; } }
public Adaim_add_book(BookUtil bookUtil) { InitializeComponent(); oracleConnection = new OracleConnection(connectionString); id.Text = bookUtil.Id; name.Text = bookUtil.Name; writer.Text = bookUtil.Writer; publishTime.Text = bookUtil.PublicTime; price.Text = bookUtil.Price; number.Text = bookUtil.Number; surplus.Text = bookUtil.Surplus; id.IsEnabled = false; flag = false; }
private void Button_Click_2(object sender, RoutedEventArgs e) //查询 { if (name.Text == "") { Update(); } else { DataTable dt = new DataTable("table1"); try { oracleConnection.Open(); OracleCommand oracleCommand = oracleConnection.CreateCommand(); string cmdStr = @"select * from book where book_name='" + name.Text + "'"; OracleCommand command = new OracleCommand(cmdStr, oracleConnection); OracleDataAdapter adapter = new OracleDataAdapter(command); adapter.Fill(dt); adapter.Dispose(); listView.ItemsSource = null; oracleConnection.Close(); ltCus.Clear(); foreach (DataRow dataRow in dt.Rows) { BookUtil bookUtil = new BookUtil { Id = dataRow["BOOK_ID"].ToString(), Name = dataRow["BOOK_NAME"].ToString(), Writer = dataRow["book_writer"].ToString(), Price = dataRow["book_price"].ToString(), Count = ltCus.Count + 1, Number = dataRow["book_count"].ToString(), PublicTime = dataRow["publish_time"].ToString(), Surplus = dataRow["book_surplus"].ToString() }; ltCus.Add(bookUtil); } listView.ItemsSource = ltCus; } catch { MessageBox.Show("查询失败"); } } button1.IsEnabled = false; button2.IsEnabled = false; }
public void Update() { if (oracleConnection == null) { oracleConnection = new OracleConnection(connectionString); } DataTable dt = new DataTable("table1"); try { oracleConnection.Open(); string cmdStr = @"select * from book "; OracleCommand command = new OracleCommand(cmdStr, oracleConnection); OracleDataAdapter adapter = new OracleDataAdapter(command); adapter.Fill(dt); adapter.Dispose(); oracleConnection.Close(); } catch { //MessageBox.Show(e.ToString()); } listView.ItemsSource = null; ltCus.Clear(); foreach (DataRow dataRow in dt.Rows) { BookUtil util = new BookUtil { Count = ltCus.Count + 1, Id = dataRow["book_id"].ToString(), Name = dataRow["book_name"].ToString(), Writer = dataRow["book_writer"].ToString(), PublicTime = dataRow["publish_time"].ToString(), Price = dataRow["book_price"].ToString(), Number = dataRow["book_count"].ToString(), Surplus = dataRow["book_surplus"].ToString() }; ltCus.Add(util); } listView.ItemsSource = ltCus; }
public Student_Borrow(User user) { InitializeComponent(); oracleConnection = new OracleConnection(connectionString); ltCus = new List <BookUtil>(); button.IsEnabled = false; this.user = user; DataTable dt = new DataTable("table1"); oracleConnection.Open(); _ = oracleConnection.CreateCommand(); string cmdStr = @"select * from book "; OracleCommand command = new OracleCommand(cmdStr, oracleConnection); OracleDataAdapter adapter = new OracleDataAdapter(command); adapter.Fill(dt); adapter.Dispose(); listView.ItemsSource = null; oracleConnection.Close(); ltCus.Clear(); foreach (DataRow dataRow in dt.Rows) { BookUtil bookUtil = new BookUtil { Id = dataRow["BOOK_ID"].ToString(), Name = dataRow["BOOK_NAME"].ToString(), Writer = dataRow["book_writer"].ToString(), Price = dataRow["book_price"].ToString(), Count = ltCus.Count + 1, Number = dataRow["book_count"].ToString(), PublicTime = dataRow["publish_time"].ToString(), Surplus = dataRow["book_surplus"].ToString() }; ltCus.Add(bookUtil); } listView.ItemsSource = ltCus; }
private void listView_SelectionChanged(object sender, SelectionChangedEventArgs e) { button.IsEnabled = true; borrowUtil = (BookUtil)listView.SelectedItem; }