📄 mainform.cs
字号:
"6",
"7",
"8",
"9",
"10",
"11",
"12"});
this.comboBoxMonth.Location = new System.Drawing.Point(160, 56);
this.comboBoxMonth.Name = "comboBoxMonth";
this.comboBoxMonth.Size = new System.Drawing.Size(40, 20);
this.comboBoxMonth.TabIndex = 27;
//
// textBoxEmail
//
this.textBoxEmail.Location = new System.Drawing.Point(64, 288);
this.textBoxEmail.Name = "textBoxEmail";
this.textBoxEmail.Size = new System.Drawing.Size(208, 21);
this.textBoxEmail.TabIndex = 26;
this.textBoxEmail.Text = "";
//
// labelEmail
//
this.labelEmail.BackColor = System.Drawing.Color.Transparent;
this.labelEmail.Location = new System.Drawing.Point(8, 288);
this.labelEmail.Name = "labelEmail";
this.labelEmail.Size = new System.Drawing.Size(56, 23);
this.labelEmail.TabIndex = 25;
this.labelEmail.Text = "email";
this.labelEmail.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// buttonSaveChange
//
this.buttonSaveChange.Location = new System.Drawing.Point(376, 224);
this.buttonSaveChange.Name = "buttonSaveChange";
this.buttonSaveChange.Size = new System.Drawing.Size(80, 32);
this.buttonSaveChange.TabIndex = 24;
this.buttonSaveChange.Text = "保存修改";
this.buttonSaveChange.Click += new System.EventHandler(this.buttonSaveChange_Click);
//
// buttonDelete
//
this.buttonDelete.Location = new System.Drawing.Point(376, 272);
this.buttonDelete.Name = "buttonDelete";
this.buttonDelete.Size = new System.Drawing.Size(80, 32);
this.buttonDelete.TabIndex = 23;
this.buttonDelete.Text = "删除";
this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click);
//
// pictureBoxLook
//
this.pictureBoxLook.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.pictureBoxLook.Location = new System.Drawing.Point(288, 16);
this.pictureBoxLook.Name = "pictureBoxLook";
this.pictureBoxLook.Size = new System.Drawing.Size(184, 192);
this.pictureBoxLook.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBoxLook.TabIndex = 22;
this.pictureBoxLook.TabStop = false;
this.pictureBoxLook.DoubleClick += new System.EventHandler(this.pictureBoxLook_DoubleClick);
//
// textBoxMobile
//
this.textBoxMobile.Location = new System.Drawing.Point(64, 208);
this.textBoxMobile.Name = "textBoxMobile";
this.textBoxMobile.Size = new System.Drawing.Size(208, 21);
this.textBoxMobile.TabIndex = 20;
this.textBoxMobile.Text = "";
//
// labelMobile
//
this.labelMobile.BackColor = System.Drawing.Color.Transparent;
this.labelMobile.Location = new System.Drawing.Point(8, 208);
this.labelMobile.Name = "labelMobile";
this.labelMobile.Size = new System.Drawing.Size(56, 23);
this.labelMobile.TabIndex = 19;
this.labelMobile.Text = "手机";
this.labelMobile.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// comboBoxSex
//
this.comboBoxSex.Items.AddRange(new object[] {
"男",
"女"});
this.comboBoxSex.Location = new System.Drawing.Point(232, 16);
this.comboBoxSex.Name = "comboBoxSex";
this.comboBoxSex.Size = new System.Drawing.Size(40, 20);
this.comboBoxSex.TabIndex = 18;
//
// textBoxOicq
//
this.textBoxOicq.Location = new System.Drawing.Point(64, 248);
this.textBoxOicq.Name = "textBoxOicq";
this.textBoxOicq.Size = new System.Drawing.Size(208, 21);
this.textBoxOicq.TabIndex = 13;
this.textBoxOicq.Text = "";
//
// textBoxPhone
//
this.textBoxPhone.Location = new System.Drawing.Point(64, 168);
this.textBoxPhone.Name = "textBoxPhone";
this.textBoxPhone.Size = new System.Drawing.Size(208, 21);
this.textBoxPhone.TabIndex = 11;
this.textBoxPhone.Text = "";
//
// textBoxYear
//
this.textBoxYear.Location = new System.Drawing.Point(64, 56);
this.textBoxYear.Name = "textBoxYear";
this.textBoxYear.Size = new System.Drawing.Size(64, 21);
this.textBoxYear.TabIndex = 10;
this.textBoxYear.Text = "";
//
// textBoxAddress
//
this.textBoxAddress.Location = new System.Drawing.Point(64, 128);
this.textBoxAddress.Name = "textBoxAddress";
this.textBoxAddress.Size = new System.Drawing.Size(208, 21);
this.textBoxAddress.TabIndex = 9;
this.textBoxAddress.Text = "";
//
// textBoxName
//
this.textBoxName.Location = new System.Drawing.Point(64, 16);
this.textBoxName.Name = "textBoxName";
this.textBoxName.Size = new System.Drawing.Size(128, 21);
this.textBoxName.TabIndex = 8;
this.textBoxName.Text = "";
//
// labelDay
//
this.labelDay.BackColor = System.Drawing.Color.Transparent;
this.labelDay.Location = new System.Drawing.Point(208, 56);
this.labelDay.Name = "labelDay";
this.labelDay.Size = new System.Drawing.Size(16, 23);
this.labelDay.TabIndex = 7;
this.labelDay.Text = "日";
this.labelDay.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// labelOicq
//
this.labelOicq.BackColor = System.Drawing.Color.Transparent;
this.labelOicq.Location = new System.Drawing.Point(8, 248);
this.labelOicq.Name = "labelOicq";
this.labelOicq.Size = new System.Drawing.Size(56, 23);
this.labelOicq.TabIndex = 6;
this.labelOicq.Text = "oicq";
this.labelOicq.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// labelYear
//
this.labelYear.BackColor = System.Drawing.Color.Transparent;
this.labelYear.Location = new System.Drawing.Point(8, 56);
this.labelYear.Name = "labelYear";
this.labelYear.Size = new System.Drawing.Size(56, 23);
this.labelYear.TabIndex = 5;
this.labelYear.Text = "出生年份";
this.labelYear.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// labelAddress
//
this.labelAddress.BackColor = System.Drawing.Color.Transparent;
this.labelAddress.Location = new System.Drawing.Point(8, 128);
this.labelAddress.Name = "labelAddress";
this.labelAddress.Size = new System.Drawing.Size(56, 23);
this.labelAddress.TabIndex = 4;
this.labelAddress.Text = "家庭地址";
this.labelAddress.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// labelMonth
//
this.labelMonth.BackColor = System.Drawing.Color.Transparent;
this.labelMonth.Location = new System.Drawing.Point(136, 56);
this.labelMonth.Name = "labelMonth";
this.labelMonth.Size = new System.Drawing.Size(16, 23);
this.labelMonth.TabIndex = 3;
this.labelMonth.Text = "月";
this.labelMonth.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// labelPhone
//
this.labelPhone.BackColor = System.Drawing.Color.Transparent;
this.labelPhone.Location = new System.Drawing.Point(8, 168);
this.labelPhone.Name = "labelPhone";
this.labelPhone.Size = new System.Drawing.Size(56, 23);
this.labelPhone.TabIndex = 2;
this.labelPhone.Text = "电话";
this.labelPhone.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// labelSex
//
this.labelSex.BackColor = System.Drawing.Color.Transparent;
this.labelSex.Location = new System.Drawing.Point(192, 16);
this.labelSex.Name = "labelSex";
this.labelSex.Size = new System.Drawing.Size(32, 23);
this.labelSex.TabIndex = 1;
this.labelSex.Text = "性别";
this.labelSex.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// labelName
//
this.labelName.BackColor = System.Drawing.Color.Transparent;
this.labelName.Location = new System.Drawing.Point(8, 16);
this.labelName.Name = "labelName";
this.labelName.Size = new System.Drawing.Size(56, 23);
this.labelName.TabIndex = 0;
this.labelName.Text = "姓名";
this.labelName.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// treeViewMain
//
this.treeViewMain.BackColor = System.Drawing.SystemColors.Window;
this.treeViewMain.ImageIndex = -1;
this.treeViewMain.Location = new System.Drawing.Point(1, 29);
this.treeViewMain.Name = "treeViewMain";
this.treeViewMain.SelectedImageIndex = -1;
this.treeViewMain.Size = new System.Drawing.Size(159, 323);
this.treeViewMain.TabIndex = 23;
this.treeViewMain.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeViewMain_AfterSelect);
this.treeViewMain.AfterLabelEdit += new System.Windows.Forms.NodeLabelEditEventHandler(this.treeViewMain_AfterLabelEdit);
//
// statusBarMain
//
this.statusBarMain.Location = new System.Drawing.Point(0, 355);
this.statusBarMain.Name = "statusBarMain";
this.statusBarMain.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
this.sBPanelUser,
this.sBPanelCount});
this.statusBarMain.Size = new System.Drawing.Size(650, 24);
this.statusBarMain.TabIndex = 27;
//
// sBPanelUser
//
this.sBPanelUser.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;
this.sBPanelUser.Width = 83;
//
// sBPanelCount
//
this.sBPanelCount.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;
this.sBPanelCount.Width = 89;
//
// openFileDialogPic
//
this.openFileDialogPic.Filter = "(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF";
//
// menuItem1
//
this.menuItem1.Index = 1;
this.menuItem1.Text = "";
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(650, 379);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.statusBarMain,
this.labelRec,
this.labelTreeview,
this.panelMain,
this.treeViewMain});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.Menu = this.myMainMenu;
this.Name = "MainForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "个人通讯录";
this.Closing += new System.ComponentModel.CancelEventHandler(this.MainForm_Closing);
this.Load += new System.EventHandler(this.MainForm_Load);
this.panelMain.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.sBPanelUser)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.sBPanelCount)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void MainForm_Load(object sender, System.EventArgs e)
{
// 弹出登录对话框
formLogon = new LogForm(this);
formLogon.ShowDialog();
// 初始化数据连接控件
myDataAdapter = new SqlDataAdapter();
myDataAdapter.SelectCommand = new SqlCommand();
myDataSet = new DataSet();
// 初始化DataSet,DataAdapter等控件
myUpdate();
//为DataAdapter建立更新命令串
InitialDataAdapter();
treeViewMain.LabelEdit = true;
}
private void mIdeleteUser_Click(object sender, System.EventArgs e)
{
DialogResult result;
// 弹出确认信息
result = MessageBox.Show(this,"确定要删除新用户吗?", "提示", MessageBoxButtons.YesNo,
MessageBoxIcon.Question, MessageBoxDefaultButton.Button1,
MessageBoxOptions.RightAlign);
if(result == DialogResult.Yes)
{
// 删除Users表里面的用户信息
string sDelete = "DELETE FROM Users WHERE 用户名='" + currentUser + "'";
SqlCommand myCommand = new SqlCommand();
myCommand.CommandText = sDelete;
myCommand.Connection = myConnection;
myCommand.ExecuteNonQuery();
// 删除Records表里面的用户信息
sDelete = "DELETE FROM Records WHERE 用户名='" + currentUser + "'";
myCommand.CommandText = sDelete;
myCommand.ExecuteNonQuery();
// 设置当前用户为空
currentUser = "";
formLogon.ShowDialog();
myUpdate();
}
}
private void mIchangeUser_Click(object sender, System.EventArgs e)
{
formChangeUser = new CUserForm(this);
formChangeUser.ShowDialog();
myUpdate();
}
public void InitialDataAdapter()
{
myDataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
myDataAdapter.InsertCommand = new SqlCommand("INSERT INTO Records (用户名," +
"姓名,性别,出生日期,星座,生肖,家庭地址,电话,手机,Oicq,电子邮件) " +
"VALUES (@用户名,@姓名,@性别,@出生日期,@星座,@生肖,@家庭地址,@电话," +
"@手机,@Oicq,@电子邮件)", myConnection);
myDataAdapter.UpdateCommand = new SqlCommand("UPDATE Records SET 用户名 = @用户名,"+
"姓名 = @姓名,性别 = @性别,出生日期 = @出生日期,星座 = @星座,生肖 = @生肖," +
"家庭地址 = @家庭地址,电话 = @电话,手机 = @手机,Oicq = @Oicq,电子邮件 = @电子邮件,图片 = @图片" +
" WHERE 姓名 = @旧姓名", myConnection);
myDataAdapter.DeleteCommand = new SqlCommand("DELETE FROM Records WHERE" +
" 姓名 = @姓名",myConnection);
myDataAdapter.InsertCommand.Parameters.Add("@用户名", SqlDbType.Char, 50, "用户名");
myDataAdapter.InsertCommand.Parameters.Add("@姓名", SqlDbType.Char, 50, "姓名");
myDataAdapter.InsertCommand.Parameters.Add("@性别", SqlDbType.Char, 10, "性别");
myDataAdapter.InsertCommand.Parameters.Add("@出生日期", SqlDbType.DateTime, 8, "出生日期");
myDataAdapter.InsertCommand.Parameters.Add("@星座", SqlDbType.Char, 10, "星座");
myDataAdapter.InsertCommand.Parameters.Add("@生肖", SqlDbType.Char, 10, "生肖");
myDataAdapter.InsertCommand.Parameters.Add("@家庭地址", SqlDbType.Char, 100, "家庭地址");
myDataAdapter.InsertCommand.Parameters.Add("@电话", SqlDbType.Char, 50, "电话");
myDataAdapter.InsertCommand.Parameters.Add("@手机", SqlDbType.Char, 20, "手机");
myDataAdapter.InsertCommand.Parameters.Add("@Oicq", SqlDbType.Char, 10, "Oicq");
myDataAdapter.InsertCommand.Parameters.Add("@电子邮件", SqlDbType.Char, 100, "电子邮件");
myDataAdapter.InsertCommand.Parameters.Add("@图片", SqlDbType.Image).SourceColumn = "图片";
myDataAdapter.UpdateCommand.Parameters.Add("@用户名", SqlDbType.Char, 50, "用户名");
myDataAdapter.UpdateCommand.Parameters.Add("@姓名", SqlDbType.Char, 50, "姓名");
myDataAdapter.UpdateCommand.Parameters.Add("@性别", SqlDbType.Char, 10, "性别");
myDataAdapter.UpdateCommand.Parameters.Add("@出生日期", SqlDbType.DateTime, 8, "出生日期");
myDataAdapter.UpdateCommand.Parameters.Add("@星座", SqlDbType.Char, 10, "星座");
myDataAdapter.UpdateCommand.Parameters.Add("@生肖", SqlDbType.Char, 10, "生肖");
myDataAdapter.UpdateCommand.Parameters.Add("@家庭地址", SqlDbType.Char, 100, "家庭地址");
myDataAdapter.UpdateCommand.Parameters.Add("@电话", SqlDbType.Char, 50, "电话");
myDataAdapter.UpdateCommand.Parameters.Add("@手机", SqlDbType.Char, 20, "手机");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -