write student management system in csharp

Here is a basic implementation of a student management system in C# that uses OOP concepts and performs CRUD operations in a WinForms application:

main.cs
// Student class to encapsulate student information
public class Student
{
    public int ID { get; set; }
    public string Name { get; set; }
    public string Email { get; set; }
    public int Age { get; set; }
}

// Main form to display and interact with student data
public partial class MainForm : Form
{
    private List<Student> students = new List<Student>();
    private int selectedStudentIndex = -1;

    public MainForm()
    {
        InitializeComponent();
    }

    private void MainForm_Load(object sender, EventArgs e)
    {
        // Load initial student data from file or database
        LoadStudentData();
    }

    private void LoadStudentData()
    {
        // Code to load student data and populate the students list
    }

    private void SaveStudentData()
    {
        // Code to save student data from the students list to file or database
    }

    private void DisplayStudentData()
    {
        lvStudents.Items.Clear();
        foreach (var student in students)
        {
            ListViewItem item = new ListViewItem(student.ID.ToString());
            item.SubItems.Add(student.Name);
            item.SubItems.Add(student.Email);
            item.SubItems.Add(student.Age.ToString());
            lvStudents.Items.Add(item);
        }
    }

    private void lvStudents_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (lvStudents.SelectedIndices.Count > 0)
        {
            // Update selected student index based on list view selection
            selectedStudentIndex = lvStudents.SelectedIndices[0];
            // Display selected student data in text boxes
            txtID.Text = students[selectedStudentIndex].ID.ToString();
            txtName.Text = students[selectedStudentIndex].Name;
            txtEmail.Text = students[selectedStudentIndex].Email;
            txtAge.Text = students[selectedStudentIndex].Age.ToString();
        }
    }

    private void btnAdd_Click(object sender, EventArgs e)
    {
        // Create new student object with entered data
        Student newStudent = new Student
        {
            ID = int.Parse(txtID.Text),
            Name = txtName.Text,
            Email = txtEmail.Text,
            Age = int.Parse(txtAge.Text)
        };

        // Add new student to list and update display
        students.Add(newStudent);
        DisplayStudentData();
        SaveStudentData();
    }

    private void btnEdit_Click(object sender, EventArgs e)
    {
        if (selectedStudentIndex >= 0)
        {
            // Update selected student object with edited data
            students[selectedStudentIndex].Name = txtName.Text;
            students[selectedStudentIndex].Email = txtEmail.Text;
            students[selectedStudentIndex].Age = int.Parse(txtAge.Text);

            // Update display and save data
            DisplayStudentData();
            SaveStudentData();
        }
    }

    private void btnDelete_Click(object sender, EventArgs e)
    {
        if (selectedStudentIndex >= 0)
        {
            // Remove selected student from list and update display
            students.RemoveAt(selectedStudentIndex);
            selectedStudentIndex = -1;
            DisplayStudentData();
            SaveStudentData();
        }
    }
}
3270 chars
108 lines

This basic implementation provides functionality to add, edit, and delete student records and stores the data in a list. More advanced features could be added such as searching or sorting the data, adding validation to input fields, or connecting to a database backend.

gistlibby LogSnag