public void clearDocumentData() { try { cmbStatus.SelectedIndex = 0; txtDocument.Text = ""; txtEmployee.Text = ""; cmbSubDOc.SelectedIndex = -1; prevdoc = new subdocreceiver(); } catch (Exception) { } }
private void grdList_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0) { return; } try { string columnName = grdList.Columns[e.ColumnIndex].Name; if (columnName.Equals("Edit")) { clearDocumentData(); prevdoc = new subdocreceiver(); int rowID = e.RowIndex; btnSave.Text = "Update"; pnlDocumentInner.Visible = true; pnlDocumentOuter.Visible = true; pnlDocumentList.Visible = false; prevdoc.RowID = Convert.ToInt32(grdList.Rows[e.RowIndex].Cells["RowID"].Value); prevdoc.DocumentID = grdList.Rows[e.RowIndex].Cells["DocumentID"].Value.ToString(); prevdoc.EmployeeID = grdList.Rows[e.RowIndex].Cells["EmployeeID"].Value.ToString(); prevdoc.SubDocID = grdList.Rows[e.RowIndex].Cells["SubDocumentID"].Value.ToString(); cmbSubDOc.SelectedIndex = Structures.ComboFUnctions.getComboIndex(cmbSubDOc, prevdoc.SubDocID); txtDocument.Text = grdList.Rows[e.RowIndex].Cells["DocumentName"].Value.ToString() + "-" + grdList.Rows[e.RowIndex].Cells["DocumentID"].Value.ToString(); txtEmployee.Text = grdList.Rows[e.RowIndex].Cells["Employee"].Value.ToString() + "-" + grdList.Rows[e.RowIndex].Cells["EmployeeID"].Value.ToString(); cmbStatus.SelectedIndex = cmbStatus.FindString(grdList.Rows[e.RowIndex].Cells["Status"].Value.ToString()); txtDocument.Enabled = false; btnSelDoc.Enabled = false; disableBottomButtons(); } } catch (Exception) { } }
private void btnSave_Click(object sender, EventArgs e) { try { subdocreceiver drrec = new subdocreceiver(); SubDocumentReceiverDB drDB = new SubDocumentReceiverDB(); try { string[] docmts = txtDocument.Text.Split('-'); string[] emply = txtEmployee.Text.Split('-'); drrec.DocumentID = docmts[1]; drrec.EmployeeID = emply[1]; drrec.SubDocID = ((Structures.ComboBoxItem)cmbSubDOc.SelectedItem).HiddenValue; } catch (Exception) { drrec.DocumentID = ""; drrec.DocumentName = ""; drrec.EmployeeName = ""; drrec.EmployeeID = ""; drrec.SubDocID = ""; } drrec.Status = getStatusCode(cmbStatus.SelectedItem.ToString()); System.Windows.Forms.Button btn = sender as System.Windows.Forms.Button; string btnText = btn.Text; { if (btnText.Equals("Update")) { if (drDB.updateSubdocReceiver(drrec, prevdoc)) { MessageBox.Show("Sub Document Receiver Status updated"); closeAllPanels(); ListSubDocumentReceiver(); } else { MessageBox.Show("Failed to update Document Receiver Status"); } } else if (btnText.Equals("Save")) { if (drDB.validateDocument(drrec)) { if (drDB.insertSubDocumentReceivers(drrec)) { MessageBox.Show("Sub Document Receiver Added"); closeAllPanels(); ListSubDocumentReceiver(); } else { MessageBox.Show("Failed to Insert Sub Document Receiver"); } } else { MessageBox.Show("Sub Document Receiver Validation failed"); } } } } catch (Exception) { MessageBox.Show("Failed Adding / Editing Sub Document Receiver"); } }