Untitled
unknown
plain_text
a year ago
2.6 kB
5
Indexable
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace show8
{
public partial class Form1 : Form
{
int recordcount = 0;
string[,] List = new string[100,4];
public Form1()
{
InitializeComponent();
comboBox1.Text = "History";
comboBox1.Items.Add("English");
comboBox1.Items.Add("Math");
comboBox1.Items.Add("Khmer");
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
string id = txtID.Text;
string name = txtName.Text;
string type = txtType.Text;
string title = comboBox1.Text;
List[recordcount, 0] = id;
List[recordcount, 1] = name;
List[recordcount, 2] = type;
List[recordcount, 3] = title;
recordcount++;
listBox1.Items.Add($"{txtID.Text} | {comboBox1.SelectedItem} | {txtName.Text} | {txtType.Text}"); ;
}
private void button3_Click(object sender, EventArgs e)
{
string bookID = txtID.Text.Trim();
if (string.IsNullOrEmpty(bookID))
{
MessageBox.Show("Please enter a Book ID to delete.", "Error");
return;
}
for (int i = 0; i < recordcount; i++)
{
if (List[i, 0] == bookID)
{
for (int j = i; j < recordcount - 1; j++)
{
List[j, 0] = List[j + 1, 0];
List[j, 1] = List[j + 1, 1];
List[j, 2] = List[j + 1, 2];
List[j, 3] = List[j + 1, 3];
}
recordcount--;
comboBox1.Items.RemoveAt(i);
MessageBox.Show($"Book with ID '{bookID}' deleted successfully.", "Success");
}
}
}
private void button2_Click(object sender, EventArgs e)
{
string bookID = txtID.Text;
for (int i = 0; i < recordcount; i++)
{
if (List[i, 0] == bookID)
{
MessageBox.Show($"Record found:\nBook ID: {List[i, 0]}\nTitle: {List[i, 1]}\nBorrower Name: {List[i, 2]}\nDate: {List[i, 3]}", "Search Result");
}
}
}
}
}
Editor is loading...
Leave a Comment