Trang 1 trên 1

Mình ko bik đổ dữ liệu của radionbutton nam nữ vào gridview

Đã gửi: T.Ba 26/06/2018 11:40 pm
gửi bởi foxnova1234
Patient Management System.rar
(217.46 KiB) Đã tải 6 lần

namespace Patient_Management_System
{
public partial class frmMain : Form
{
string flag;
DataTable dtPR;
int index;
public frmMain()
{
InitializeComponent();
}
public DataTable createTable()
{
DataTable dt = new DataTable();
dt.Columns.Add("FullName");
dt.Columns.Add("Address");
dt.Columns.Add("Telephone");
dt.Columns.Add("Sex");
dt.Columns.Add("DOB");

return dt;
}
public void LockControl()
{
btnAdd.Enabled = true;
btnEdit.Enabled = true;
btnDelete.Enabled = true;
btnUpdate.Enabled = false;
btnCancel.Enabled = false;

txtAddress.ReadOnly = true;
txtFullName.ReadOnly = true;
txtTelephone.ReadOnly = true;


btnAdd.Focus();
}
public void UnlockControl()
{
btnAdd.Enabled = false;
btnEdit.Enabled = false;
btnDelete.Enabled = false;
btnUpdate.Enabled = true;
btnCancel.Enabled = true;

txtAddress.ReadOnly = false;
txtFullName.ReadOnly = false;
txtTelephone.ReadOnly = false;

txtFullName.Focus();
}

private void frmMain_Load(object sender, EventArgs e)
{
LockControl();
dtPR = createTable();
}

private void btnAdd_Click(object sender, EventArgs e)
{
UnlockControl();
flag = "add";
txtAddress.Text = "";
txtFullName.Text = "";
txtTelephone.Text = "";

}

private void btnEdit_Click(object sender, EventArgs e)
{
UnlockControl();
flag = "edit";
}

private void btnUpdate_Click(object sender, EventArgs e)
{
if(flag == "add")
{
if(checkdata())
{
dtPR.Rows.Add(txtFullName.Text, txtAddress.Text, txtTelephone.Text,pictureBox1);
dataGridView1.DataSource = dtPR;
dataGridView1.RefreshEdit();
}
}
else if(flag=="edit")
{
if(checkdata())
{
dtPR.Rows[index][0] = txtAddress.Text;
dtPR.Rows[index][1] = txtFullName.Text;
dtPR.Rows[index][2] = txtTelephone.Text;
dataGridView1.DataSource = dtPR;
dataGridView1.RefreshEdit();
}
}
LockControl();
}
public bool checkdata()
{
if(string.IsNullOrWhiteSpace(txtFullName.Text))
{
MessageBox.Show("Please enter full information", "notification", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtFullName.Focus();
return false;
}
if(string.IsNullOrWhiteSpace(txtAddress.Text))
{
MessageBox.Show("Please enter full information", "notification", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtAddress.Focus();
return false;
}
if (string.IsNullOrWhiteSpace(txtTelephone.Text))
{
MessageBox.Show("Please enter full information", "notification", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtTelephone.Focus();
return false;

}

return true;
}

private void btnBrowse_Click(object sender, EventArgs e)
{

FileDialog file = new OpenFileDialog();
file.Filter = "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*";
file.ShowDialog();


}

private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
index = dataGridView1.CurrentCell == null ? -1 : dataGridView1.CurrentCell.RowIndex;
if (index != -1)
{
txtFullName.Text = dataGridView1.Rows[index].Cells[0].Value.ToString();
txtAddress.Text = dataGridView1.Rows[index].Cells[1].Value.ToString();
txtTelephone.Text = dataGridView1.Rows[index].Cells[2].Value.ToString();
}
}

private void btnDelete_Click(object sender, EventArgs e)
{
if(MessageBox.Show("do you want to delete this information ?","Warning",MessageBoxButtons.YesNo,MessageBoxIcon.Warning) == DialogResult.Yes)
{
dtPR.Rows.RemoveAt(index);
dataGridView1.RefreshEdit();
}
}

private void txtSearch_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
doSearchByKeyWord();
}
}
private void doSearchByKeyWord()
{

}

private void btnSave_Click(object sender, EventArgs e)
{

}

private void pictureBox1_Click(object sender, EventArgs e)
{

}

Re: Mình ko bik đổ dữ liệu của radionbutton nam nữ vào gridview

Đã gửi: T.Tư 27/06/2018 9:31 am
gửi bởi nhatlinh0207
sửa lại bài viết cho vào thẻ C#