/// <summary> /// Hàm thực hiện lệnh /// </summary> /// <param name="pMyAction">Action pMyAction</param> private void PerformAction(Action pMyAction) { try { //CreateDeviceList(); switch (pMyAction) { case Action.Insert: DevicesListBusiness.InsertDevice(CreateDeviceList()); break; case Action.Update: DevicesListBusiness.UpdateDevice(CreateDeviceList()); break; case Action.Delete: DevicesListBusiness.DeleteDevice(CreateDeviceList()); break; } } catch (Exception) { throw; } }
/// <summary> /// Hàm dùng để set thuộc tính cho các control /// </summary> /// <param name="pMyAction"></param> private void SetControlStatus(Action pMyAction) { switch (pMyAction) { case Action.Insert: btnAdd.Enabled = false; btnDelete.Enabled = false; btnEdit.Enabled = false; btnSave.Enabled = true; txtDeviceID.Enabled = false; txtDeviceID.Text = string.Empty; txtDeviceName.Focus(); txtDeviceName.SelectAll(); grpInfor.Enabled = true; cboDeviceClass.Enabled = true; cboDeviceNameSpace.Enabled = true; btnExit.Text = StrCancel; txtComputerName.Enabled = true; txtConnectorId.Enabled = true; break; case Action.Update: btnAdd.Enabled = false; btnDelete.Enabled = false; btnEdit.Enabled = false; btnSave.Enabled = true; txtDeviceName.Focus(); txtDeviceName.SelectAll(); grpInfor.Enabled = true; cboDeviceClass.Enabled = true; cboDeviceNameSpace.Enabled = true; btnExit.Text = StrCancel; txtComputerName.Enabled = true; txtConnectorId.Enabled = true; txtDeviceID.Enabled = false; break; case Action.Delete: break; case Action.Normal: btnAdd.Enabled = true; btnEdit.Enabled = true; btnDelete.Enabled = true; btnSave.Enabled = true; btnExit.Enabled = true; btnExit.Text = StrExit; txtDeviceLib.Enabled = false; txtComputerName.Enabled = false; txtConnectorId.Enabled = false; cboDeviceClass.Enabled = false; cboDeviceNameSpace.Enabled = false; grpInfor.Enabled = false; txtDeviceID.Enabled = false; break; } }
private void btnExit_Click(object sender, EventArgs e) { if (_myAction == Action.Normal) { Dispose(); } _myAction = Action.Normal; SetControlStatus(_myAction); }
private void frmDeviceList_Load(object sender, EventArgs e) { LoadAllDevices(); LoadAllManufacture(); LoadAllTestTypeList(); LoadPortList(); _myAction = Action.Normal; SetControlStatus(_myAction); }
private void btnDelete_Click(object sender, EventArgs e) { _myAction = Action.Delete; SetControlStatus(_myAction); DialogResult result = MessageBox.Show("Do you sure delete this record?", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (result == DialogResult.OK) { PerformAction(_myAction); frmDeviceList_Load(this, new EventArgs()); } }
private void btnEdit_Click(object sender, EventArgs e) { _myAction = Action.Update; SetControlStatus(_myAction); }
private void btnAdd_Click(object sender, EventArgs e) { _myAction = Action.Insert; SetControlStatus(_myAction); }