private void btnReturnItem_Click(object sender, EventArgs e) { if (dgvReturnItems.RowCount > 0 && dgvReturnItems.DataSource != null) { int rowIndex = -1; try { rowIndex = dgvReturnItems.CurrentCell.RowIndex; } catch (Exception) { MessageBox.Show(null, "Please select an item.", "Return item", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } String itemId = dgvReturnItems.Rows[rowIndex].Cells[0].Value.ToString(); String propertyNo = dgvReturnItems.Rows[rowIndex].Cells[3].Value.ToString(); if (cbStatus.SelectedIndex < 0) { cbStatus.Focus(); } else if (itemId == "") { MessageBox.Show(null, "Please select an item to return.", "Select an item", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { String dateReturn = dtpDateReturn.Value.ToString("yyyy-MM-dd"); DialogResult result = MessageBox.Show(null, "Does " + dgvReturnItems.Rows[rowIndex].Cells[6].Value.ToString() + " returned the " + dgvReturnItems.Rows[rowIndex].Cells[4].Value.ToString() + " to you on the date " + dateReturn + "?", "Return item", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result == DialogResult.Yes) { String statusId = ((ComboBoxItem)cbStatus.SelectedItem).HiddenValue; String holderId = dgvReturnItems.Rows[rowIndex].Cells[2].Value.ToString(); if (inventory.insertInventory(propertyNo, statusId, holderId, dateReturn, txtRemarks.Text, itemId, "1")) { MessageBox.Show(null, "Item was successfully returned to the wah office.", "Return item", MessageBoxButtons.OK, MessageBoxIcon.Information); loadReturnItems(); loadReturnHistory(); txtRemarks.Text = string.Empty; cbStatus.SelectedIndex = -1; tabControl1.SelectedIndex = 1; } } } } }
private void btnAssign_Click(object sender, EventArgs e) { String dateReceived = null; String holderId = null; String itemId = null; if (dgvItems.RowCount < 0) { MessageBox.Show(null, "Please select an item.", "Select item", MessageBoxButtons.OK, MessageBoxIcon.Warning); dgvItems.Focus(); return; } else { int index = dgvItems.CurrentCell.RowIndex; itemId = dgvItems.Rows[index].Cells[0].Value.ToString(); } if (cbStatus.SelectedIndex < 0) { cbStatus.Focus(); cbStatus.SelectAll(); } else if (String.IsNullOrEmpty(cbHolderName.Text)) { cbHolderName.Focus(); } else { DialogResult result = MessageBox.Show(null, "Are you sure you want to assign the item to " + cbHolderName.Text + "?", "Assign to person", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result == DialogResult.No) { return; } if (switchRecieved.Value == false) { dateReceived = "0000-00-00"; } else { dateReceived = dtpDateReceived.Value.ToString("yyyy-MM-dd"); } //Holders if (cbHolderName.SelectedIndex < 0) { String isEmployee = null; if (rbEmployee.Checked == true) { isEmployee = "1"; } else { isEmployee = "0"; } if (inventory.addHolders(cbHolderName.Text, isEmployee)) { holderId = inventory.getLastHolderId(); cbHolderName.Items.Add(new ComboBoxItem(cbHolderName.Text, holderId)); cbHolderName.SelectedIndex = cbHolderName.Items.Count - 1; } } else { holderId = ((ComboBoxItem)cbHolderName.SelectedItem).HiddenValue; } //Inventory String statusId = ((ComboBoxItem)cbStatus.SelectedItem).HiddenValue; if (inventory.insertInventory(propertyNo, statusId, holderId, dateReceived, txtRemarks.Text, itemId, "0")) { MessageBox.Show(null, "Item was successfully assigned to " + cbHolderName.Text + ".", "Assign to person", MessageBoxButtons.OK, MessageBoxIcon.Information); loadInventory(); loadItems(); txtRemarks.Text = String.Empty; cbHolderName.SelectedIndex = -1; cbHolderName.Text = string.Empty; pnlAssign.Visible = false; } } }