I need help from the community. I have a CaseNumbersTextBox that I want to populate with a case/s number when button GetCasesButton is clicked.
The code I have is from a different desktop windows application. My application is a web app.
The old code uses ComboboxItem from RequestorComboBox. Here is what is happening in old app. A user selects a name from RequestorComboBox, then enters a court case number/s into the CaseNumbersTextBox. Then user clicks on GetCasesButton. The app looks for the case number entered from a database table. If the case number is not found an error message is displayed to the user as a popup.
I need to change RequestorComboBox to use RequestorDropDownList.
How do I do this?
What I have tried:
Here is the code that I need to make changes to so that instead of RequestorComboBox, I use RequestorDropDownList.
private async void GetCasesButton_Click(object sender, EventArgs e)
{
#region Required Field Validation
if (CaseNumbersTextBox.Text.Length < 1)
{
MessageBox.Show("Casenumber textbox cannot be empty.", "Search Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
ComboboxItem requestorItem = new ComboboxItem();
requestorItem = (ComboboxItem)RequestorComboBox.SelectedItem;
ComboboxItem reasonItem = new ComboboxItem();
reasonItem = (ComboboxItem)ReasonComboBox.SelectedItem;
if (requestorItem.Value < 1)
{
MessageBox.Show("Please select a Requestor.", "Search Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (reasonItem.Value < 1)
{
MessageBox.Show("Please select a Reason.", "Search Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
#endregion
#region Parse case number entries
string userEnteredCaseNumbers = CaseNumbersTextBox.Text;
userEnteredCaseNumbers = userEnteredCaseNumbers.Replace("\r", ",");
userEnteredCaseNumbers = userEnteredCaseNumbers.Replace("\n", ",");
while (userEnteredCaseNumbers.Contains(",,"))
userEnteredCaseNumbers = userEnteredCaseNumbers.Replace(",,", ",");
List<string> userEnteredCaseNumberList = new List<string>();
userEnteredCaseNumberList = userEnteredCaseNumbers.Split(',').Where(x => x.Length > 0).ToList();
userEnteredCaseNumberList = userEnteredCaseNumberList.Select(s => s.Trim()).ToList();
#endregion
try
{
#region Get Batch Number
int newBatchNumber = await CandidateCaseController.GetNextBatchNumber();
#endregion
#region Insert entered case numbers in database
foreach (string caseNumber in userEnteredCaseNumberList)
{
EditCandidateCaseModel newCandidate = new EditCandidateCaseModel();
newCandidate.CaseNbr = caseNumber;
newCandidate.RequestorInfoID = requestorItem.Value;
newCandidate.ReasonID = reasonItem.Value;
newCandidate.BatchNumber = newBatchNumber;
newCandidate.EntryStaffUserName = this._loggedInUserName;
await CandidateCaseController.PostCandidate(newCandidate);
}
#endregion
#region Get everything in Candidate table now that the new search has been entered
List<GetCandidateCaseModel> candidateList = await CandidateCaseController.GetAllCandidates();
candidateList = candidateList.Where(x => x.BatchNumber == newBatchNumber).ToList();
string candidateCasesString = string.Empty;
Regex rgxDash = new Regex("[^a-zA-Z0-9 ,]");
candidateCasesString = string.Join(",", candidateList.Select(p => p.CaseNbr.ToString()));
candidateCasesString = rgxDash.Replace(candidateCasesString, "").ToString();
#endregion
#region Get info on cases
List<string> smallEnoughStrings = new List<string>();
while (candidateCasesString.Length > 0)
{
int sendLength = 200;
bool isLastString = false;
if (candidateCasesString.Length < sendLength)
{
sendLength = candidateCasesString.Length;
isLastString = true;
}
string smallChunk = candidateCasesString.Substring(0, sendLength);
if (!isLastString)
{
int lastComma = smallChunk.LastIndexOf(',');
smallChunk = smallChunk.Substring(0, lastComma);
candidateCasesString = candidateCasesString.Remove(0, lastComma);
if (candidateCasesString[0] == ',')
candidateCasesString = candidateCasesString.Remove(0, 1);
}
else
candidateCasesString = candidateCasesString.Remove(0, sendLength);
smallEnoughStrings.Add(smallChunk);
}
List<AcceptCaseNumbersModel> mncisDetailList = new List<AcceptCaseNumbersModel>();
List<AcceptCaseNumbersModel> smallEnoughMncisDetailList = new List<AcceptCaseNumbersModel>();
foreach (string smallEnoughString in smallEnoughStrings)
{
smallEnoughMncisDetailList = await FTACaseReset.Controllers.JusticeController.GetAllAcceptCaseNumbers(smallEnoughString);
mncisDetailList.AddRange(smallEnoughMncisDetailList);
}
#endregion
#region Parse data from MNCIS and add it to Candidate table
foreach (GetCandidateCaseModel candidateCase in candidateList)
{
string caseNbrWODash = rgxDash.Replace(candidateCase.CaseNbr, "").ToString();
AcceptCaseNumbersModel mncisDetail = mncisDetailList.Where(x => x.CaseNbrSrch.ToLower() == caseNbrWODash.ToLower()).FirstOrDefault();
if (mncisDetail != null)
{
candidateCase.FirstPenalty = mncisDetail.FirstPenaltyFlag == 1 ? true : false;
candidateCase.SecondPenalty = mncisDetail.SecondPenaltyFlag == 1 ? true : false;
if (candidateCase.CaseNbr.ToLower().Contains("vb") == false)
candidateCase.RejectionReason = await FTACaseReset.Controllers.RejectionController.GetRejectionByDescription(Enumerations.Rejections.No_Records_To_Reset.ToString().Replace("_", " "));
else if (candidateCase.FirstPenalty == false && candidateCase.SecondPenalty == false)
candidateCase.RejectionReason = await FTACaseReset.Controllers.RejectionController.GetRejectionByDescription(Enumerations.Rejections.No_Records_To_Reset.ToString().Replace("_", " "));
if (candidateCase.RejectionReason == null)
candidateCase.RejectionReason = await FTACaseReset.Controllers.RejectionController.GetRejectionByDescription(Enumerations.Rejections.Valid.ToString());
candidateCase.Title = mncisDetail.Style;
await FTACaseReset.Controllers.CandidateCaseController.PutCandidate(candidateCase);
}
else
{
candidateCase.RejectionReason = await FTACaseReset.Controllers.RejectionController.GetRejectionByDescription(Enumerations.Rejections.Invalid_Case_Number.ToString().Replace("_", " "));
await FTACaseReset.Controllers.CandidateCaseController.PutCandidate(candidateCase);
}
}
#endregion
this.ClearForm();
#region Populate Results
ValidTabPage.Controls.Clear();
InvalidTabPage.Controls.Clear();
DiscardedTabPage.Controls.Clear();
ValidTabPage.Text = "Valid Cases";
InvalidTabPage.Text = "Invalid Cases";
DiscardedTabPage.Text = "Discarded Cases";
#region Repopulate Batch ComboBox
this.PopulateBatchComboBox();
#endregion
List<GetCandidateCaseModel> thisBatchCasesList = new List<GetCandidateCaseModel>();
thisBatchCasesList = await Controllers.CandidateCaseController.GetCandidateByBatchID(newBatchNumber);
if (thisBatchCasesList.Count > 0)
this.EmailButton.Enabled = true;
else
{
this.EmailButton.Enabled = false;
return;
}
this.PopulateTabs(thisBatchCasesList, true);
this.GetCasesPanel.Visible = false;
this.UpdateExistingPanel.Visible = true;
ComboboxItem batchItem = new ComboboxItem(thisBatchCasesList[0].BatchNumber);
SelectBatch(batchItem);
ComboboxItem requestorUpdateItem = new ComboboxItem(thisBatchCasesList[0].RequestorInfo);
SelectRequestorUpdate(requestorUpdateItem);
ComboboxItem reasonUpdateItem = new ComboboxItem(thisBatchCasesList[0].Reason);
SelectReasonUpdate(reasonUpdateItem);
#endregion
}
catch (Exception ex)
{
string errorMsg = string.Format("An error has occured in {0}. \nException:\n{1}", "GetCasesButton_Click()", ex.Message);
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + errorMsg + "');", true);
}
}