private void dgvTickets_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == -1) { return; } DataRowView rowView = (DataRowView)dgvTickets.Rows[e.RowIndex].DataBoundItem; if (rowView == null) { return; } Tickets.TicketData ticketData = new Tickets.TicketData { ticketNumber = rowView.Row["TicketNumber"].ToString(), description = rowView.Row["Description"].ToString(), status = rowView.Row["Status"].ToString(), comments = rowView.Row["Comments"].ToString() }; ViewFieldData(ticketData); recordAction = RecordAction.update.ToString(); EnableEditFields(true); DisplayStatus("Ready for update", StatusTypes.general); }
private void dgvTickets_SelectionChanged(object sender, EventArgs e) { DateTime lastDate; if ((dgvTickets.SelectedRows.Count) == 0) { return; } var row = dgvTickets.SelectedRows[0]; if (row == null) { return; } DataRowView rowView = (DataRowView)row.DataBoundItem; if (rowView == null) { return; } Tickets.TicketData ticketData = new Tickets.TicketData { ticketNumber = rowView.Row["TicketNumber"].ToString(), description = rowView.Row["Description"].ToString(), status = rowView.Row["Status"].ToString(), comments = rowView.Row["Comments"].ToString(), createdOn = (DateTime)rowView.Row["CreatedOn"] // completedOn = (DateTime)rowView.Row["CompletedOn"] }; try { lastDate = (rowView.Row["CompletedOn"] != DBNull.Value)? (DateTime)rowView.Row["CompletedOn"]:DateTime.Now; ticketData.completedOn = lastDate; } catch { lastDate = DateTime.Now; } ViewFieldData(ticketData); }
private void ViewFieldData(Tickets.TicketData data) { txtTicketNo.Text = data.ticketNumber; txtDescription.Text = data.description; cmbEditStatus.Text = data.status; rtbComments.Text = data.comments; btnDirectory.Enabled = true; btnMail.Enabled = true; btnShowObjects.Enabled = true; if (data.ticketNumber.Length > 0) { lblObjectCount.Text = objects.GetObjectCountForTicket(data.ticketNumber).ToString(); try { TimeSpan duration = data.completedOn - data.createdOn; lblDuration.Text = ((int)duration.TotalDays).ToString() + " days"; }catch { lblDuration.Text = "-"; } } }
private void btnSave_Click(object sender, EventArgs e) { if (txtTicketNo.Text.Length == 0) { errorProvider1.SetError(txtTicketNo, "Invalid Ticketnumber"); SetErrorProviderTimeOut(errorProvider1, txtTicketNo); return; } if (cmbEditStatus.SelectedIndex == -1) { errorProvider1.SetError(cmbEditStatus, "Invalid Status"); SetErrorProviderTimeOut(errorProvider1, cmbEditStatus); return; } bool result = false; Tickets.TicketData ticketData = new Tickets.TicketData { ticketNumber = txtTicketNo.Text, status = cmbEditStatus.Text, description = txtDescription.Text, comments = rtbComments.Text }; if (recordAction == RecordAction.insert.ToString()) { // INSERT result = tickets.Insert(ticketData); } else if (recordAction == RecordAction.update.ToString()) { // UPDATE result = tickets.Update(ticketData); } if (result) { //SUCCESS DisplayStatus(Tickets.LastError, StatusTypes.success); clearAllFields(); EnableEditFields(false); DisplayStatus(Tickets.LastError, StatusTypes.success); // Refresh grid view string status = cmbStatusFilter.Text; dgvTickets.DataSource = tickets.GetDataBasedStatus(status); // Status count refresh RefreshStatusCounts(); if (recordAction == RecordAction.insert.ToString()) { // Create ticket folder while creating ticket string ticketDirPath = projectDirectory + "\\" + ticketData.ticketNumber; try { if (Directory.Exists(ticketDirPath)) { DisplayStatus($"Directory : {ticketDirPath.Trim()} already exists!", StatusTypes.warning); } else { Directory.CreateDirectory(ticketDirPath); // Copy contents from template directory to ticket directory if (Directory.Exists(ticketDirPath) && Directory.Exists(templateDocDiretory)) { string[] filePathList = Directory.GetFiles(templateDocDiretory); foreach (var filepath in filePathList) { string fileName = Path.GetFileName(filepath); File.Copy(filepath, ticketDirPath + "\\" + fileName); } } } } catch (Exception ex) { DisplayStatus($"Error while setup directory {ticketDirPath}. {ex.Message}", StatusTypes.error); } } } else { DisplayStatus(Tickets.LastError, StatusTypes.error); } }