📄 doctorframe.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Youzi.Model;
using Youzi.BLL;
namespace Youzi.View
{
public partial class DoctorFrame : Form
{
public DoctorFrame()
{
InitializeComponent();
}
private void DoctorFrame_Load(object sender, EventArgs e)
{
try
{
ShuaXin();
DoctorSex.Items.Add("男");
DoctorSex.Items.Add("女");
DoctorSex.SelectedItem = "男"; //默认显示的
DoctorDegree.Items.Add("大专");
DoctorDegree.Items.Add("本科");
DoctorDegree.Items.Add("研究生");
DoctorDegree.Items.Add("博士");
DoctorDegree.Items.Add("其他");
DoctorDegree.SelectedItem = "本科";
DoctorPosition.Items.Add("医师");
DoctorPosition.Items.Add("主治医师");
DoctorPosition.Items.Add("副主任医师");
DoctorPosition.Items.Add("主任医师");
DoctorPosition.Items.Add("其他");
DoctorPosition.SelectedItem = "医师";
OfficeBLL obll = new OfficeBLL();
DataSet dds = obll.SelectAll();
OfficeName.DataSource = dds.Tables[0];
OfficeName.DisplayMember = "科室名称";
OfficeName.ValueMember = "科室名称";
OperateDate.Text = DateTime.Now.ToString();
Operator.Text = Users.userName;
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
return;
}
}
private void ShuaXin()
{
DoctorBLL bll = new DoctorBLL();
DataSet ds = bll.SelectAll();
dataGridView1.DataSource = ds.Tables[0];
dataGridView1.ReadOnly = true;
butDelete.Enabled = false;
butUpdate.Enabled = false;
butSave.Enabled = false;
}
private void dataGridView1_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
int index = dataGridView1.CurrentRow.Index;
DoctorName.Text = dataGridView1[1, index].Value.ToString();
DoctorSex.SelectedItem = dataGridView1[2, index].Value.ToString();
DoctorAge.Text=dataGridView1[3,index].Value.ToString();
DoctorDegree.SelectedItem = dataGridView1[4, index].Value.ToString();
DoctorPosition.SelectedItem = dataGridView1[5, index].Value.ToString();
OfficeName.SelectedItem = dataGridView1[6, index].Value.ToString();
OperateDate.Text = dataGridView1[7, index].Value.ToString();
Operator.Text = dataGridView1[8, index].Value.ToString();
DoctorName.Enabled = true;
DoctorAge.Enabled = true;
butDelete.Enabled = true;
butUpdate.Enabled = true;
butCancel.Enabled = true;
butAdd.Enabled = true;
butSave.Enabled = false;
}
private void butClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
int index = dataGridView1.CurrentRow.Index;
DoctorName.Text = dataGridView1[1, index].Value.ToString();
DoctorSex.SelectedItem = dataGridView1[2, index].Value.ToString();
DoctorAge.Text = dataGridView1[3, index].Value.ToString();
DoctorDegree.SelectedItem = dataGridView1[4, index].Value.ToString();
DoctorPosition.SelectedItem = dataGridView1[5, index].Value.ToString();
OfficeName.SelectedItem = dataGridView1[6, index].Value.ToString();
OperateDate.Text = dataGridView1[7, index].Value.ToString();
Operator.Text = dataGridView1[8, index].Value.ToString();
DoctorName.Enabled = true;
DoctorAge.Enabled = true;
butDelete.Enabled = true;
butUpdate.Enabled = true;
butCancel.Enabled = true;
butAdd.Enabled = true;
butSave.Enabled = false;
}
private void butCancel_Click(object sender, EventArgs e)
{
ClearField();
butAdd.Enabled = true;
butDelete.Enabled = false;
butSave.Enabled = false;
OperateDate.Text = "";
Operator.Text = "";
DoctorName.Enabled = false;
DoctorAge.Enabled = false;
}
private void ClearField()
{
DoctorName.Text = "";
DoctorAge.Text = "";
}
private void butAdd_Click(object sender, EventArgs e)
{
ClearField();
butDelete.Enabled = false;
butUpdate.Enabled = false;
butSave.Enabled = true;
butCancel.Enabled = true;
DoctorName.Enabled = true;
DoctorAge.Enabled = true;
OperateDate.Text = DateTime.Now.ToString();
Operator.Text = Users.userName;
butAdd.Enabled = !butAdd.Enabled;
}
private void butSave_Click(object sender, EventArgs e)
{
try
{
if (DoctorName.Text == string.Empty)
{
MessageBox.Show("医师姓名不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (DoctorAge.Text == string.Empty)
{
MessageBox.Show("医师年龄不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
DoctorBLL bll = new DoctorBLL();
DoctorInfo entity = new DoctorInfo();
entity.DoctorName = DoctorName.Text;
entity.DoctorSex = DoctorSex.SelectedItem.ToString();
entity.DoctorAge = DoctorAge.Text;
entity.DoctorDegree = DoctorDegree.SelectedItem.ToString();
entity.DoctorPosition = DoctorPosition.SelectedItem.ToString();
entity.OfficeInfo.OfficeName = OfficeName.SelectedValue.ToString();
entity.OperateDate = OperateDate.Text;
entity.Operator = Operator.Text;
int ii=bll.Insert(entity);
if (ii > 0)
{
ShuaXin();
MessageBox.Show("保存成功");
ClearField();
OperateDate.Text = "";
Operator.Text = "";
DoctorName.Enabled = false;
DoctorAge.Enabled = false;
butAdd.Enabled = true;
}
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
}
private void butDelete_Click(object sender, EventArgs e)
{
try
{
DialogResult dr = MessageBox.Show("确认要删除吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dr == DialogResult.No)
{
return;
}
int index = dataGridView1.CurrentRow.Index;
int id = int.Parse(dataGridView1[0, index].Value.ToString());
DoctorBLL bll = new DoctorBLL();
int ii = bll.Delete(id);
if (ii > 0)
{
ShuaXin();
MessageBox.Show("删除成功");
}
ClearField();
OperateDate.Text = "";
Operator.Text = "";
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
}
private void butUpdate_Click(object sender, EventArgs e)
{
try
{
DoctorBLL bll = new DoctorBLL();
DoctorInfo entity = new DoctorInfo();
int index = dataGridView1.CurrentRow.Index; //index 获得当前所选中行的下标(下标从0开始)
entity.DoctorID = int.Parse(dataGridView1[0, index].Value.ToString());
entity.DoctorName = DoctorName.Text;
entity.DoctorSex = DoctorSex.SelectedItem.ToString();
entity.DoctorAge = DoctorAge.Text;
entity.DoctorDegree = DoctorDegree.SelectedItem.ToString();
entity.DoctorPosition = DoctorPosition.SelectedItem.ToString();
entity.OfficeInfo.OfficeName = OfficeName.SelectedValue.ToString();
entity.OperateDate = OperateDate.Text;
entity.Operator = Operator.Text;
int ii = bll.Update(entity);
if (ii > 0)
{
ShuaXin();
MessageBox.Show("更新成功");
ClearField();
OperateDate.Text = "";
Operator.Text = "";
}
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -