保存和检索用户信息 [英] Save and retrieve user information

查看:75
本文介绍了保存和检索用户信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此,用户将在相关文本框中输入员工ID,姓名和薪水信息,然后按保留".当用户按下保持"按钮时,员工数据将保存到下一个组合框.

因此,如果用户输入三个雇员的信息,则会在组合框的下拉列表中添加三个雇员的姓名.

输入多个雇员的信息后,用户将从组合框的下拉列表中选择特定雇员,然后按显示"按钮,所选雇员的所有信息(Id,姓名,薪水)将以以下格式显示在消息框中:

员工信息:
编号:001
名称:alman
工资:1000

Here, user will enter employee Id, Name and Salary information in the related textboxes and press "Keep it". When user press "Keep it" button employee data will be saved to the next Combobox.

So, if user enters three employees information, three employees’ name will be added in the drop down list of Combobox.

After entering several employees’ information, user will select a particular employee from the drop down list of Combobox and press "Show" button, all information (Id, Name, Salary) of the selected employee will be displayed in the messagebox as following format:

Employee Information:
Id:001
name:alman
Salary:1000

namespace WindowsApplicationPraticeOne
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private string id;
        private string name;
        private double salary;
        private void keepItbutton_Click(object sender, EventArgs e)
        {
             id = idtextBox.Text;
             name = nametextBox.Text;
             salary =Convert.ToDouble(salarytextBox.Text);
             employecomboBox.Items.Add(name);
       }
        private void showbutton_Click(object sender, EventArgs e)
        {
        }
    }
}

推荐答案

将此类设为Employee类
make a class Employee like this
class Employee
{
  public string Id;
  public string Name;
  public double Salary; 
}



现在拿一个哈希表



now take a hash table

HashTable hsEmp=new HashTable();



现在将您的代码更改为



now change your code as

private void keepItbutton_Click(object sender, EventArgs e)
       {
            Empolyee objEmp=new Employee();
            objEmp.id = idtextBox.Text;
            objEmp.name = nametextBox.Text;
            objEmp.salary =Convert.ToDouble(salarytextBox.Text);
            hsEmp.Add(objEmp.Name,objEmp);
            employecomboBox.Items.Add(name);
      }
       private void showbutton_Click(object sender, EventArgs e)
       {
           Employee objEmp=hsEmp[cboEmp.SelectedValue];
// write code to show employee data;

       }




--Pankaj




--Pankaj


Class Emp
{
   string id;
   string name;
   doubl sal;
}

namespace WindowsApplicationPraticeOne
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        IDictionary empDic<string,emp> = new Dictionary<string,emp>();
        private void keepItbutton_Click(object sender, EventArgs e)
        {
             Emp temp=new Emp()
             temp.id = idtextBox.Text;
             temp.name = nametextBox.Text;
             temp.salary =Convert.ToDouble(salarytextBox.Text);
             employecomboBox.Items.Add(temp.name);
             empDic.add(temp.id,temp);
       }
        private void showbutton_Click(object sender, EventArgs e)
        {
             Emp temp2 = empDic[employecomboBox.SelectedText.toString()];
//Now you have you can use temp2 class to display data
        }
    }
}



P.S. :我尚未编译和测试代码,但应该可以正常工作



P.S. : I have not compiled and tested the code but should work


private void buttonKeepIt_Click(object sender, EventArgs e)
{
   comboxEmpList.Add.Items(textBoxName.Text);
   //If you are using the database as MySql then use this query to store
   //MySql code: insert into Emptable(id,name,salary) values("18","YYY","28487.87");

}

private void buttonShow_Click(object sender, EventArgs e)
{
    string selectedEmpName = comboboxEmpList.Text;
    //If you are using the database as MySql then use this query to store
    //MySql code: slect * from Emptable where name = selectedEmpName;
    //Use MySql Adapter to get datatable or dataset
     
    textBoxName.Text = dataTable.Rows[0]["name"].ToString();
    textBoxid.Text = dataTable.Rows[0]["id"].ToString(); 
    textBoxSalary.Text = dataTable.Rows[0]["salary"].ToString();
   
}


这篇关于保存和检索用户信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆