📄 editform.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace 通讯录
{
public partial class EditForm : Form
{
private int id = 0;
private DataSet myDataSet = new DataSet();
private string xpath;
public EditForm(int myId,DataSet ds,string xmlpath)
{
InitializeComponent();
id = myId;
myDataSet = ds;
xpath = xmlpath;
lblID.Text = id.ToString();
string str = "序号='" + id.ToString() + "'";
DataRow[] rowList = myDataSet.Tables[0].Select(str);
foreach (DataRow row in rowList)
{
txtName.Text = row["姓名"].ToString();
cobSex.Text = row["性别"].ToString();
cobType.Text = row["类型"].ToString();
txtBirthday.Text = row["出生年月"].ToString();
txtAddr.Text = row["地址"].ToString();
txtCorp.Text = row["所在公司"].ToString();
txtJop.Text = row["职位"].ToString();
txtPhone.Text = row["联系电话"].ToString();
txtEmail.Text = row["电子邮箱"].ToString();
txtPage.Text = row["个人主页"].ToString();
if (row["性别"].ToString() == "女")
{
myPictureBox.Image = Image.FromFile(@"image\girl.jpg");
myPictureBox.Update();
}
else
{
myPictureBox.Image = Image.FromFile(@"image\boy.jpg");
myPictureBox.Update();
}
}
}
private void btnEdit_Click(object sender, EventArgs e)
{
string username = txtName.Text.Trim();
string sex = cobSex.SelectedItem.ToString();
string birthday = txtBirthday.Text.Trim();
string phone = txtPhone.Text.Trim();
string address = txtAddr.Text.Trim();
string corp = txtCorp.Text.Trim();
string jop = txtJop.Text.Trim();
string email = txtEmail.Text.Trim();
string page = txtPage.Text.Trim();
string type = cobType.Text;
string imageuri = "";
if (username == "")
{
lblNameValidate.Text = "姓名不能为空!";
lblNameValidate.Visible = true;
return;
}
foreach (DataRow row in myDataSet.Tables[0].Rows)
{
if (row["序号"].ToString() == id.ToString())
{
row["姓名"] = username;
row["性别"] = sex;
row["出生年月"] = birthday;
row["联系电话"] = phone;
row["地址"] = address;
row["所在公司"] = corp;
row["职位"] = jop;
row["电子邮箱"] = email;
row["个人主页"] = page;
row["类型"] = type;
row["头像"] = imageuri;
myDataSet.WriteXml(xpath);
MessageBox.Show("修改成功!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
}
}
}
private void cobSex_SelectedValueChanged(object sender, EventArgs e)
{
if (cobSex.Text == "女")
{
myPictureBox.Image = Image.FromFile(@"image\girl.jpg");
myPictureBox.Update();
}
else
{
myPictureBox.Image = Image.FromFile(@"image\boy.jpg");
myPictureBox.Update();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -