📄 addform.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 AddForm : Form
{
private DataSet myDataSet = new DataSet();
private int id;
private string xpath;
public AddForm(DataSet ds,string xmlpath)
{
InitializeComponent();
xpath = xmlpath;
myDataSet = ds;
int cob = 0;
for (int i = 0; i < 100;i++ )
{
cob = 1910 + i;
cobYear.Items.Add(cob.ToString());
}
for (int i = 0; i < 12; i++)
{
cob = 1 + i;
cobMonth.Items.Add(cob.ToString());
}
for (int i = 0; i < 31; i++)
{
cob = 1 + i;
cobDay.Items.Add(cob.ToString());
}
txtPage.Text = "http://";
id = myDataSet.Tables[0].Rows.Count + 1;
lblID.Text = id.ToString();
if (cobSex.Text == "女")
{
myPictureBox.Image = Image.FromFile(@"image\girl.jpg");
myPictureBox.Update();
}
else
{
myPictureBox.Image = Image.FromFile(@"image\boy.jpg");
myPictureBox.Update();
}
}
private void btnAdd_Click(object sender, EventArgs e)
{
string username=txtName.Text.Trim();
string sex=cobSex.SelectedItem.ToString();
string birthday=cobYear.Text+"年"+cobMonth.Text+"月"+cobDay.Text+"日";
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;
}
DataRow newRow = myDataSet.Tables[0].NewRow();
newRow["序号"] = id.ToString();
newRow["姓名"] = username;
newRow["性别"] = sex;
newRow["出生年月"] = birthday;
newRow["联系电话"] = phone;
newRow["地址"] = address;
newRow["所在公司"] = corp;
newRow["职位"] = jop;
newRow["电子邮箱"] = email;
newRow["个人主页"] = page;
newRow["类型"] = type;
newRow["头像"] = imageuri;
myDataSet.Tables[0].Rows.Add(newRow);
myDataSet.WriteXml(xpath);
MessageBox.Show("添加成功!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
}
private void btnClear_Click(object sender, EventArgs e)
{
txtName.Text = "";
cobSex.Text = "男";
cobType.Text = "朋友";
cobYear.Text = "1990";
cobMonth.Text = "1";
cobDay.Text = "1";
txtPhone.Text = "";
txtAddr.Text = "";
txtCorp.Text = "";
txtJop.Text = "";
txtEmail.Text = "";
txtPage.Text = "http://";
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void txtName_KeyDown(object sender, KeyEventArgs e)
{
lblNameValidate.Visible = false;
}
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 + -