private void cmdDelete_Click(object sender, EventArgs e) { if (cmbName.SelectedItem != null) { ComboBoxItem item = (ComboBoxItem)cmbName.SelectedItem; DepartmentValue value = (DepartmentValue)item.Value; Department dept = new Department(); dept.Id = Int32.Parse(value.Id); dept.Description = value.Description; try { if (MessageBox.Show("Do you really want to delete?", "Delete?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { if (NpgsqlDatabaseImpl.GetInstance().DeleteObject(dept)) { MessageBox.Show("Department deleted!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); cmbName.SelectedItem = null; txtDescription.Text = null; } } } catch (Exception ex) { if (ex.Message.Contains("constraint")) { MessageBox.Show("Can't delete this department. It has doctor/patient records attached ", "Deletion not allowed!", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Failed to delete Department: " + ex.Message, "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
public async Task <IActionResult> Edit(int id, [Bind("departmentValueId,departmentId,departmentAttributeId,departmentValue")] DepartmentValue departmentValue) { if (id != departmentValue.departmentValueId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(departmentValue); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DepartmentValueExists(departmentValue.departmentValueId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["departmentId"] = new SelectList(_context.Department, "departmentId", "departmentName", departmentValue.departmentId); ViewData["departmentAttributeId"] = new SelectList(_context.DepartmentAttributes, "departmentAttributeId", "departmentAttributeName", departmentValue.departmentAttributeId); return(View(departmentValue)); }
private void cmbName_SelectedIndexChanged(object sender, EventArgs e) { if (cmbName.SelectedItem != null) { ComboBoxItem item = (ComboBoxItem)cmbName.SelectedItem; DepartmentValue value = (DepartmentValue)item.Value; txtDescription.Text = value.Description; } }
private void cmdSave_Click(object sender, EventArgs e) { if (!this.ValidateData()) { MessageBox.Show("Fill all the fields", "Missing Data", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } Department department = new Department(); try { if (cmbName.SelectedItem == null) { department.Name = cmbName.Text; department.Id = 0; } else { ComboBoxItem item = (ComboBoxItem)cmbName.SelectedItem; department.Name = item.Text; DepartmentValue value = (DepartmentValue)item.Value; department.Id = int.Parse(value.Id); } department.Description = txtDescription.Text; if (NpgsqlDatabaseImpl.GetInstance().AddObject(department)) { ComboBoxItem item = new ComboBoxItem(); item.Text = department.Name; DepartmentValue value = new DepartmentValue(); value.Id = department.Id.ToString(); value.Description = department.Description; item.Value = value; if (!this.FindDepartment(item)) { cmbName.Items.Insert(0, item); cmbName.SelectedIndex = 0; } MessageBox.Show("Department Saved ...", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Failed to save Department", "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show("Failed to save Department: " + ex.Message, "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public async Task <IActionResult> Create([Bind("departmentValueId,departmentId,departmentAttributeId,departmentValue")] DepartmentValue departmentValue) { if (ModelState.IsValid) { _context.Add(departmentValue); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["departmentId"] = new SelectList(_context.Department, "departmentId", "departmentName", departmentValue.departmentId); ViewData["departmentAttributeId"] = new SelectList(_context.DepartmentAttributes, "departmentAttributeId", "departmentAttributeName", departmentValue.departmentAttributeId); return(View(departmentValue)); }
public int SyncValueTable(int?departmentid) { var novalue = _context.DepartmentAttributes.Where(n => !_context.DepartmentValue.Where(m => m.departmentId == departmentid).Select(m => m.departmentAttributeId).Contains(n.departmentAttributeId)); foreach (var value in novalue.ToList()) { DepartmentValue v = new DepartmentValue { departmentId = (int)departmentid, departmentAttributeId = value.departmentAttributeId }; _context.Add(v); } _context.SaveChanges(); return(0); }
private void frmRegisterDept_Load(object sender, EventArgs e) { DbRecord record = NpgsqlDatabaseImpl.GetInstance().GetData("SELECT id, name, description FROM department ORDER BY name"); foreach (List <object> row in record.Records) { ComboBoxItem item = new ComboBoxItem(); item.Text = row[1].ToString(); DepartmentValue value = new DepartmentValue(); value.Id = row[0].ToString(); value.Description = row[2].ToString(); item.Value = value; cmbName.Items.Add(item); } if (cmbName.Items != null && cmbName.Items.Count > 0) { cmbName.SelectedIndex = 0; } }
private bool FindDepartment(ComboBoxItem item) { bool result = false; if (item != null) { DepartmentValue value = (DepartmentValue)item.Value; foreach (object it in cmbName.Items) { ComboBoxItem dept = (ComboBoxItem)it; DepartmentValue val = (DepartmentValue)dept.Value; if (val.Id.Equals(value.Id)) { result = true; break; } } } return(result); }
public async Task <IActionResult> Edit(int id, [Bind("departmentId,departmentName")] Department department, IDictionary <int, string> dictionary) { step = ActionStep.edit; if (id != department.departmentId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(department); var departmentValues = _context.DepartmentValue.Where(v => v.departmentId == id); foreach (KeyValuePair <int, string> value in dictionary) { DepartmentValue dv = departmentValues.SingleOrDefault(v => v.departmentValueId == value.Key); if (dv != null) { dv.departmentValue = value.Value; _context.Update(dv); } } await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DepartmentExists(department.departmentId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(department)); }
private void frmRegisterDocs_Load(object sender, EventArgs e) { string qualification = ""; string specialization = ""; string dept = ""; if (_doctorid != null) { string query = "SELECT id, doctor_id, name, address, " + " qualification, specialization, phone, " + " email, schedule, gender, department_id " + " FROM doctor WHERE doctor_id = '" + _doctorid + "'"; DbRecord rec = NpgsqlDatabaseImpl.GetInstance().GetData(query); if (rec != null && rec.RowCount == 1) { txtId.Text = rec.Records[0][1].ToString(); txtId.Enabled = false; txtName.Text = rec.Records[0][2].ToString(); txtAddress.Text = rec.Records[0][3].ToString(); qualification = rec.Records[0][4].ToString(); specialization = rec.Records[0][5].ToString(); txtPhone.Text = rec.Records[0][6].ToString(); txtEmail.Text = rec.Records[0][7].ToString(); txtSchedule.Text = rec.Records[0][8].ToString(); if (rec.Records[0][9].ToString().Equals("Male")) { optMale.Checked = true; } else { optFemale.Checked = true; } dept = rec.Records[0][9].ToString(); } } DbRecord record = NpgsqlDatabaseImpl.GetInstance().GetData("SELECT id, name, description FROM department ORDER BY name"); foreach (List <object> row in record.Records) { ComboBoxItem item = new ComboBoxItem(); item.Text = row[1].ToString(); DepartmentValue value = new DepartmentValue(); value.Id = row[0].ToString(); value.Description = row[2].ToString(); item.Value = value; cmbDept.Items.Add(item); if (row[0].ToString().Equals(dept)) { cmbDept.SelectedItem = item; } } if (cmbDept.Items != null && cmbDept.Items.Count > 0 && cmbDept.SelectedItem == null) { cmbDept.SelectedIndex = 0; } record = NpgsqlDatabaseImpl.GetInstance().GetData("SELECT DISTINCT specialization FROM doctor ORDER BY 1"); foreach (List <object> row in record.Records) { cmbSpecialization.Items.Add(row[0].ToString()); if (row[0].ToString().Equals(specialization)) { cmbSpecialization.SelectedItem = cmbSpecialization.Items[cmbSpecialization.Items.Count - 1]; } } if (cmbSpecialization.Items != null && cmbSpecialization.Items.Count > 0 && cmbSpecialization.SelectedItem == null) { cmbSpecialization.SelectedIndex = 0; } record = NpgsqlDatabaseImpl.GetInstance().GetData("SELECT DISTINCT qualification FROM doctor ORDER BY 1"); foreach (List <object> row in record.Records) { cmbQualification.Items.Add(row[0].ToString()); if (row[0].ToString().Equals(qualification)) { cmbQualification.SelectedItem = cmbQualification.Items[cmbQualification.Items.Count - 1]; } } if (cmbQualification.Items != null && cmbQualification.Items.Count > 0 && cmbQualification.SelectedItem == null) { cmbQualification.SelectedIndex = 0; } }