private void btnSave_Click(object sender, EventArgs e) { if (txtCode.Text.Trim( ) == "") { MessageBox.Show("单位代码没有指定!", "", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (txtName.Text.Trim( ) == "") { MessageBox.Show("单位名称没有指定!", "", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } WorkUnit workunit = new WorkUnit( ); workunit.Code = txtCode.Text.Trim( ); workunit.Name = txtName.Text.Trim( ); workunit.PyCode = txtPym.Text.Trim( ); workunit.WbCode = txtWbm.Text.Trim( ); try { if (btnAdd.Enabled == false) { WorkUnitController.AddWorkUnit(workunit); btnAdd.Enabled = true; } else { WorkUnitController.UpdateWorkUnit(workunit); } dgvWorkUnit.DataSource = WorkUnitController.GetWorkunitList( ).DefaultView; } catch (Exception err) { MessageBox.Show(err.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void FrmWorkUnit_Load(object sender, EventArgs e) { dgvWorkUnit.DataSource = WorkUnitController.GetWorkunitList( ).DefaultView; }