Click here to Skip to main content
15,889,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
C#
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
        //candidateCasesString
        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
        //use candidateList to pull records out of mncisDetailList then update CandidateCase 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)
            {
                //if it found a record then edit Candidate details with case data
                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
            {
                //if it didn't find a record then change the rejection code on the Candidate
                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);
    }
}
Posted
Updated 3-Jan-20 17:06pm
Comments
Richard MacCutchan 30-Dec-19 16:19pm    
You need a complete redesign since the dropdownlist will be displayed on the web page not in the server code.
Member 11403304 31-Dec-19 11:14am    
Hi Richard. I do not really understand what you mean by complete redesign. Can you please explain for? I am new to web development.
Christian Graus 3-Jan-20 23:07pm    
Going from desktop to web is a complete rewrite. It's not much better from getting a spec and writing a website. The web works completely differently. If you don't know that, you should not be doing this.

You should tag your question with the technologies you're using. ASP.NET is horrific and obsolete for a decade. Some people still use Microsoft ASP.NET MVC but any serious web dev nowadays involves a javascript library like Angular or React IMO

1 solution

Going from desktop to web is a complete rewrite. It's not much better from getting a spec and writing a website. The web works completely differently. If you don't know that, you should not be doing this.

You should tag your question with the technologies you're using. ASP.NET is horrific and obsolete for a decade. Some people still use Microsoft ASP.NET MVC but any serious web dev nowadays involves a javascript library like Angular or React IMO
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900