Exemple #1
0
        private void listBoxControls_SelectedIndexChanged(object sender, EventArgs e)
        {
            //Loads all the control info into the control viewer
            if (listBoxControls.SelectedItem.ToString() == "")
            {
                return;
            }
            string controlOptions;

            //AutoNoteControls.RefreshControlEdit(listBoxControls.SelectedIndex.ToString());
            AutoNoteControls.Refresh();
            ControlCur = AutoNoteControls.Listt[listBoxControls.SelectedIndex];
            textBoxTypeControl.Text        = ControlCur.ControlType;
            textBoxDescriptControl.Text    = ControlCur.Descript;
            textBoxLabelControl.Text       = ControlCur.ControlLabel;
            textBoxTextControl.Text        = ControlCur.MultiLineText;
            textBoxTextPrefaceControl.Text = ControlCur.PrefaceText;
            listBoxOptionsControl.Items.Clear();
            controlOptions = ControlCur.ControlOptions;
            string[] lines = controlOptions.Split(new char[] { ',' });
            for (int i = 0; i < lines.Length; i++)
            {
                listBoxOptionsControl.Items.Add(lines[i].ToString());
            }
            ControlContentViewerVisible(true);
        }
Exemple #2
0
        private void butOK_Click(object sender, EventArgs e)
        {
            string AutoNoteOutput = "";
            int    currentControl = 0;

            for (int x = 0; x < this.Controls.Count; x++)
            {
                if (this.Controls[x].Name.ToString() != "listBoxAutoNotes" &&
                    this.Controls[x].Name.ToString() != "butOK" &&
                    this.Controls[x].Name.ToString() != "listBoxControls")
                {
                    string Text        = "";
                    string prefaceText = "";
                    if (currentControl < listBoxControls.Items.Count)
                    {
                        if (this.Controls[x].Text != "")
                        {
                            AutoNoteControls.RefreshControl(listBoxControls.Items[currentControl].ToString());
                            ControlCur     = AutoNoteControls.Listt[0];
                            prefaceText    = ControlCur.PrefaceText;
                            Text           = this.Controls[x].Text;
                            AutoNoteOutput = AutoNoteOutput + " " + prefaceText + " " + Text;
                        }
                        currentControl++;
                    }
                }
            }
            AutoNoteCur.AutoNoteOutput = AutoNoteOutput;
            this.DialogResult          = DialogResult.OK;
        }
Exemple #3
0
 /// <summary>
 /// Refreshes the listBoxControls
 /// </summary>
 private void fillListBoxControls()
 {
     listBoxControls.Items.Clear();
     AutoNoteControls.Refresh();
     for (int i = 0; i < AutoNoteControls.Listt.Count; i++)
     {
         listBoxControls.Items.Add(AutoNoteControls.Listt[i].Descript);
     }
     if (!IsNew)
     {
         listBoxControlsToIncl.Items.Clear();
         listBoxControlToIncNum.Items.Clear();
         string   controls = AutoNoteCur.ControlsToInc;
         string[] lines    = controls.Split(new char[] { ',' });
         for (int i = 0; i < lines.Length; i++)
         {
             if (lines[i].ToString() != "")
             {
                 listBoxControlToIncNum.Items.Add(lines[i].ToString());
                 ControlsList = AutoNoteControls.ControlNumToName(lines[i].ToString());
                 listBoxControlsToIncl.Items.Add(AutoNoteControls.Listt[0].Descript);
             }
         }
     }
 }
 private void butImport_Click(object sender, EventArgs e)
 {
     try {
         using (OpenFileDialog openDialog = ImportDialogSetup()) {
             if (openDialog.ShowDialog() != DialogResult.OK)
             {
                 return;                         //User cancelled out of OpenFileDialog
             }
             string fileContents          = File.ReadAllText(openDialog.FileName);
             TransferableAutoNotes import = JsonConvert.DeserializeObject <TransferableAutoNotes>(fileContents);
             AutoNoteControls.RemoveDuplicatesFromList(import.AutoNoteControls, import.AutoNotes);
             AutoNoteControls.InsertBatch(import.AutoNoteControls);
             AutoNotes.InsertBatch(import.AutoNotes);
             DataValid.SetInvalid(InvalidType.AutoNotes);
             AutoNoteL.FillListTree(treeNotes, _userOdCurPref);
             SecurityLogs.MakeLogEntry(Permissions.AutoNoteQuickNoteEdit, 0,
                                       $"Auto Note Import. {import.AutoNotes.Count} new Auto Notes, {import.AutoNoteControls.Count} new Prompts");
             MsgBox.Show(Lans.g(this, "Auto Notes successfully imported!") + "\r\n" + import.AutoNotes.Count + " " + Lans.g(this, "new Auto Notes")
                         + "\r\n" + import.AutoNoteControls.Count + " " + Lans.g(this, "new Prompts"));
         }
     }
     catch (Exception err) {
         FriendlyException.Show(Lans.g(this, "Auto Note(s) failed to import."), err);
     }
 }
 private void butOK_Click(object sender, EventArgs e)
 {
     if (textBoxControlDescript.Text.ToString() == "" ||
         comboType.SelectedIndex == -1)
     {
         MsgBox.Show(this, "Please make sure that the Description and Type are not blank");
         return;
     }
     if (!Regex.IsMatch(textBoxControlDescript.Text, "^[a-zA-Z_0-9 ]*$"))
     {
         MsgBox.Show(this, "The description can only contain letters, numbers, underscore, and space.");
         return;
     }
     ControlCur.Descript       = textBoxControlDescript.Text.ToString();
     ControlCur.ControlLabel   = textBoxControlLabel.Text.ToString();
     ControlCur.ControlType    = comboType.SelectedItem.ToString();
     ControlCur.ControlOptions = textOptions.Text;
     if (IsNew)
     {
         AutoNoteControls.Insert(ControlCur);
     }
     else
     {
         AutoNoteControls.Update(ControlCur);
     }
     DialogResult = DialogResult.OK;
 }
        private void FillGrid()
        {
            AutoNoteControls.RefreshCache();
            gridMain.BeginUpdate();
            gridMain.Columns.Clear();
            ODGridColumn col = new ODGridColumn(Lan.g("FormAutoNoteControls", "Description"), 100);

            gridMain.Columns.Add(col);
            col = new ODGridColumn(Lan.g("FormAutoNoteControls", "Type"), 100);
            gridMain.Columns.Add(col);
            col = new ODGridColumn(Lan.g("FormAutoNoteControls", "Prompt Text"), 100);
            gridMain.Columns.Add(col);
            col = new ODGridColumn(Lan.g("FormAutoNoteControls", "Options"), 100);
            gridMain.Columns.Add(col);
            gridMain.Rows.Clear();
            ODGridRow row;

            for (int i = 0; i < AutoNoteControls.Listt.Count; i++)
            {
                row = new ODGridRow();
                row.Cells.Add(AutoNoteControls.Listt[i].Descript);
                row.Cells.Add(AutoNoteControls.Listt[i].ControlType);
                row.Cells.Add(AutoNoteControls.Listt[i].ControlLabel);
                row.Cells.Add(AutoNoteControls.Listt[i].ControlOptions);
                gridMain.Rows.Add(row);
            }
            gridMain.EndUpdate();
        }
Exemple #7
0
 private void FormAutoNoteCompose_Load(object sender, EventArgs e)
 {
     AutoNotes.RefreshCache();
     AutoNoteControls.RefreshCache();
     listMain.Items.Clear();
     for (int i = 0; i < AutoNotes.Listt.Count; i++)
     {
         listMain.Items.Add(AutoNotes.Listt[i].AutoNoteName);
     }
 }
 private void butDelete_Click(object sender, EventArgs e)
 {
     if (IsNew)
     {
         DialogResult = DialogResult.Cancel;
         return;
     }
     if (!MsgBox.Show(this, MsgBoxButtons.OKCancel, "Completely delete this prompt?  It will not be available from any AutoNote."))
     {
         return;
     }
     AutoNoteControls.Delete(ControlCur.AutoNoteControlNum);
     DialogResult = DialogResult.OK;
 }
Exemple #9
0
        private void butCreateControl_Click(object sender, EventArgs e)
        {
            FormAutoNoteControlEdit form = new FormAutoNoteControlEdit();

            form.IsNew      = true;
            form.ControlCur = new AutoNoteControl();
            form.ShowDialog();
            if (form.DialogResult == DialogResult.OK)
            {
                ControlContentViewerVisible(false);
                AutoNoteControls.Refresh();
                listBoxControls.Items.Clear();
                for (int i = 0; i < AutoNoteControls.Listt.Count; i++)
                {
                    listBoxControls.Items.Add(AutoNoteControls.Listt[i].Descript);
                }
            }
        }
Exemple #10
0
        ///<summary></summary>
        private void FillGrid()
        {
            AutoNoteControls.RefreshCache();
            gridMain.BeginUpdate();
            gridMain.Columns.Clear();
            ODGridColumn col = new ODGridColumn("", 100);

            gridMain.Columns.Add(col);
            gridMain.Rows.Clear();
            ODGridRow row;

            for (int i = 0; i < AutoNoteControls.Listt.Count; i++)
            {
                row = new ODGridRow();
                row.Cells.Add(AutoNoteControls.Listt[i].Descript);
                gridMain.Rows.Add(row);
            }
            gridMain.EndUpdate();
        }
Exemple #11
0
 private void FormAutoNoteEdit_Load(object sender, EventArgs e)
 {
     if (!IsNew)
     {
         string controls;
         textBoxAutoNoteName.Text = AutoNoteCur.AutoNoteName;
         controls = AutoNoteCur.ControlsToInc;
         string[] lines = controls.Split(new char[] { ',' });
         for (int i = 0; i < lines.Length; i++)
         {
             if (lines[i].ToString() != "")
             {
                 listBoxControlToIncNum.Items.Add(lines[i].ToString());
                 ControlsList = AutoNoteControls.ControlNumToName(lines[i].ToString());
                 listBoxControlsToIncl.Items.Add(AutoNoteControls.Listt[0].Descript);
             }
         }
     }
     fillListBoxControls();
 }
        ///<summary></summary>
        private void FillGrid()
        {
            AutoNoteControls.RefreshCache();
            _listAutoNoteControls = AutoNoteControls.GetDeepCopy(false);
            gridMain.BeginUpdate();
            gridMain.ListGridColumns.Clear();
            GridColumn col = new GridColumn("", 100);

            gridMain.ListGridColumns.Add(col);
            gridMain.ListGridRows.Clear();
            GridRow row;

            for (int i = 0; i < _listAutoNoteControls.Count; i++)
            {
                row = new GridRow();
                row.Cells.Add(_listAutoNoteControls[i].Descript);
                gridMain.ListGridRows.Add(row);
            }
            gridMain.EndUpdate();
        }
Exemple #13
0
        private void butEditControl_Click(object sender, EventArgs e)
        {
            //should launch FormAutoNoteControlEdit
            //I did not have time to look closely at this:

            /*
             * ControlsToInc=new string[listBoxControlsToIncl.Items.Count];
             * for (int i=0; i<listBoxControlsToIncl.Items.Count; i++) {
             *      if (listBoxControlsToIncl.Items[i].ToString()!="") {
             *              ControlsList=AutoNoteControls.ControlNameToNum(listBoxControlsToIncl.Items[i].ToString());
             *              ControlsToInc[i]=ControlsList[0].AutoNoteControlNum.ToString();
             *      }
             * }
             * RefreshControlsToIncEdit=true;*/
            if (listBoxControls.SelectedIndex == -1)
            {
                return;
            }
            FormAutoNoteControlEdit form = new FormAutoNoteControlEdit();

            form.IsNew      = false;
            form.ControlCur = AutoNoteControls.Listt[listBoxControls.SelectedIndex];
            form.ShowDialog();
            if (form.DialogResult == DialogResult.OK)
            {
                ControlContentViewerVisible(false);
                AutoNoteControls.Refresh();
                listBoxControls.Items.Clear();
                for (int i = 0; i < AutoNoteControls.Listt.Count; i++)
                {
                    listBoxControls.Items.Add(AutoNoteControls.Listt[i].Descript);
                }
                listBoxControlsToIncl.Items.Clear();
                for (int i = 0; i < listBoxControlToIncNum.Items.Count; i++)
                {
                    ControlsList = AutoNoteControls.ControlNumToName(listBoxControlToIncNum.Items[i].ToString());
                    listBoxControlsToIncl.Items.Add(ControlsList[0].Descript);
                }
            }
        }
        private void butExport_Click(object sender, System.EventArgs e)
        {
            List <AutoNote> listCheckedAutoNotes = GetCheckedAutoNotes(treeNotes.Nodes);

            if (listCheckedAutoNotes.Count == 0)
            {
                MsgBox.Show(this, "You must select at least one Auto Note to export.");
                return;
            }
            try {
                string fileName;
                if (ODBuild.IsWeb())
                {
                    //file download dialog will come up later, after file is created.
                    fileName = "autonotes.json";
                }
                else
                {
                    using (SaveFileDialog saveDialog = ExportDialogSetup()) {
                        if (saveDialog.ShowDialog() != DialogResult.OK)
                        {
                            return;                            //user canceled out of SaveFileDialog
                        }
                        fileName = saveDialog.FileName;
                    }
                }
                List <SerializableAutoNote>        serializableAutoNotes        = AutoNotes.GetSerializableAutoNotes(listCheckedAutoNotes);
                List <AutoNoteControl>             listAutoNoteControls         = AutoNoteControls.GetListByParsingAutoNoteText(serializableAutoNotes);
                List <SerializableAutoNoteControl> serializableAutoNoteControls = AutoNoteControls.GetSerializableAutoNoteControls(listAutoNoteControls);
                AutoNotes.WriteAutoNotesToJson(serializableAutoNotes, serializableAutoNoteControls, fileName);
                SecurityLogs.MakeLogEntry(Permissions.AutoNoteQuickNoteEdit, 0, "Auto Note Export");
                MsgBox.Show(this, "Auto Note(s) successfully exported.");
            }
            catch (Exception err) {
                FriendlyException.Show("AutoNote(s) failed to export.", err);
            }
        }
Exemple #15
0
        private void butOK_Click(object sender, EventArgs e)
        {
            //bool IsUsed=AutoNoteControls.ControlNameUsed(textBoxControlDescript.Text.ToString(), textBoxDescriptControl.Text.ToString());
            //if (IsUsed==true) {
            //	MessageBox.Show(Lan.g(this, "This name is already used please choose a different name"));
            //	return;
            //}
            if (textBoxControlDescript.Text.ToString() == "" || comboBoxControlType.SelectedIndex == -1)
            {
                MessageBox.Show(Lan.g(this, "Please make sure that the Name and Type field are not blank"));
                return;
            }
            //converts the items in ListBoxControlOptions into a string with a comma between each option
            string ControlOptions = "";

            for (int i = 0; i < listBoxControlOptions.Items.Count; i++)
            {
                ControlOptions = ControlOptions + listBoxControlOptions.Items[i].ToString() + ",";
            }
            ControlCur.ControlType    = comboBoxControlType.SelectedItem.ToString();
            ControlCur.Descript       = textBoxControlDescript.Text.ToString();
            ControlCur.ControlLabel   = textBoxControlLabel.Text.ToString();
            ControlCur.PrefaceText    = textBoxTextPreface.Text.ToString();
            ControlCur.MultiLineText  = textBoxMultiLineText.Text.ToString();
            ControlCur.ControlOptions = ControlOptions;
            if (IsNew)
            {
                AutoNoteControls.Insert(ControlCur);
            }
            else
            {
                AutoNoteControls.ControlUpdate(ControlCur);
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
        ///<summary>Returns the length prompt responses added to textMain.Text.</summary>
        private int PromptForAutoNotes(string noteToParse, List <AutoNoteListItem> listAutoNoteItem)
        {
            //AutoNote.MainText which should have all text and the prompts.
            string note = noteToParse;

            #region Insert Auto Note Text
            //Logic for determining where the note should go based on the users cursor location.
            int selectionStart = textMain.SelectionStart;
            if (selectionStart == 0)           //Cursor is at the beginning of the textbox.
            {
                textMain.Text = note + textMain.Text;
            }
            else if (selectionStart == textMain.Text.Length - 1)         //Cursor at end of textbox
            {
                textMain.Text = textMain.Text + note;
            }
            else if (selectionStart == -1)           //If cursor location is unknown just append the text to the end
            {
                textMain.Text = textMain.Text + note;
            }
            else              //Cursor is in between text. Insert at the selected position.
            {
                textMain.Text = textMain.Text.Substring(0, selectionStart) + note + textMain.Text.Substring(selectionStart);
            }
            #endregion
            //List of prompts for the auto note
            List <AutoNoteControl> prompts = new List <AutoNoteControl>();
            //Prompts are stored in the form [Prompt: "PromptName"]
            List <Match> listPrompts = AutoNoteControls.GetPrompts(note);
            //Remove all matched prompts that do not exist in the database.
            listPrompts.RemoveAll(x => AutoNoteControls.GetByDescript(x.Value.Substring(9, x.Value.Length - 11)) == null);
            //Holds the PromptName from [Prompt: "PromptName"]
            string          autoNoteDescript;
            AutoNoteControl control;
            string          promptResponse;
            int             matchloc;     //This is the index of the Prompt location in textMain.
            int             startLoc = 0;
            int             retVal   = 0; //the length of the notes added to textMain.Text.
            //used to keep track of the start position. This is needed set matchloc. Without this, match loc might find the wrong index.
            Stack <int> stackLoc = new Stack <int>();
            stackLoc.Push(startLoc);
            bool isAutoNote = false;
            //Loop through all valid prompts for the given auto note.
            for (int i = 0; i < listPrompts.Count; i++)
            {
                //Find prompt location in the text and highlight yellow.
                matchloc = textMain.Text.IndexOf(listPrompts[i].Value, startLoc);
                if (matchloc == -1 || matchloc > textMain.TextLength)                   //The value wasn't found
                {
                    continue;
                }
                startLoc = matchloc + 1;            //Add one to look after the last match location.
                textMain.Select(matchloc, listPrompts[i].Value.Length);
                textMain.SelectionBackColor = Color.Yellow;
                textMain.SelectionLength    = 0;
                Application.DoEvents();                //refresh the textbox so the yellow will show
                //Holds the PromptName from [Prompt: "PromptName"]
                autoNoteDescript = listPrompts[i].Value.Substring(9, listPrompts[i].Value.Length - 11);
                control          = AutoNoteControls.GetByDescript(autoNoteDescript); //should never be null since we removed nulls above
                promptResponse   = "";
                if (control.ControlType == "Text")                                   //Response just inserts text. No choosing options here.
                {
                    FormAutoNotePromptText FormT = new FormAutoNotePromptText(autoNoteDescript);
                    FormT.PromptText = control.ControlLabel;
                    FormT.ResultText = control.ControlOptions;
                    isAutoNote       = false;
                    if (i > 0)
                    {
                        FormT.IsGoBack = true;                      //user can go back if at least one item in the list exist
                    }
                    if (listAutoNoteItem.Count > i)
                    {
                        FormT.CurPromptResponse = listAutoNoteItem[i].AutoNotePromptResponseString;                      //pass the previous response to the form
                    }
                    FormT.ShowDialog();
                    if (FormT.DialogResult == DialogResult.Retry)                   //user clicked the go back button
                    {
                        GoBack(i, listAutoNoteItem);
                        stackLoc.Pop();                        //remove the start location
                        startLoc = stackLoc.Peek();            //set the new start location
                        i       -= 2;
                        continue;
                    }
                    if (FormT.DialogResult == DialogResult.OK)
                    {
                        promptResponse = FormT.ResultText;
                        if (listAutoNoteItem.Count > i)                       //reponse already exist for this control type. Update it
                        //We need to update retVal with the length of the new promptResponse. First, remove the previous prompts length.
                        {
                            retVal -= listAutoNoteItem[i].AutoNoteTextEndPos;
                            //Update the retVal with the new promptResponse.Length.
                            retVal += promptResponse.Length;
                            //Update the rest of the AutoNoteItem with the new promptResponse.
                            listAutoNoteItem[i].AutoNotePromptResponseString = promptResponse;
                            listAutoNoteItem[i].AutoNoteTextStartPos         = matchloc;
                            listAutoNoteItem[i].AutoNoteTextEndPos           = promptResponse.Length;
                        }
                        else
                        {
                            //This is a new response. Create a new AutoNoteListItem and add to retVal.
                            retVal += promptResponse.Length;
                            listAutoNoteItem.Add(new AutoNoteListItem(listPrompts[i].Value, promptResponse, matchloc, promptResponse.Length));                         //add new response to the list
                        }
                    }
                    else                      //User cancelled out of the auto note prompt text form or auto log off.
                    {
                        ResetTextMain();
                        return(-1);
                    }
                }
                else if (control.ControlType == "OneResponse")
                {
                    FormAutoNotePromptOneResp FormOR = new FormAutoNotePromptOneResp(autoNoteDescript);
                    FormOR.PromptText    = control.ControlLabel;
                    FormOR.PromptOptions = control.ControlOptions;
                    if (i > 0)
                    {
                        FormOR.IsGoBack = true;                      //user can go back if at least one item in the list exist
                    }
                    if (listAutoNoteItem.Count > i)
                    {
                        FormOR.CurPromptResponse = listAutoNoteItem[i].AutoNotePromptResponseString;                      //pass the previous response if exist to the form.
                    }
                    FormOR.ShowDialog();
                    if (FormOR.DialogResult == DialogResult.Retry)                   //user clicked the go back button
                    {
                        GoBack(i, listAutoNoteItem);
                        stackLoc.Pop();                        //remove the start location
                        startLoc = stackLoc.Peek();            //set the new start location
                        i       -= 2;
                        continue;
                    }
                    if (FormOR.DialogResult == DialogResult.OK)
                    {
                        promptResponse = FormOR.ResultText;
                        //The promptResponse will have the AutoNoteName in the format "Auto Note Response : {AutoNoteName}". Use the name to get the note that
                        //will be used in the recursive call below.
                        string autoNoteString = "";
                        isAutoNote = false;
                        string autoNoteName = GetAutoNoteName(promptResponse);
                        if (!string.IsNullOrEmpty(autoNoteName))
                        {
                            isAutoNote = true;
                            //For some reason the Auto Note string always contains a new line and a return character at the end of the note. Must be trimmed
                            autoNoteString = AutoNotes.GetByTitle(autoNoteName).TrimEnd('\n').TrimEnd('\r'); //Returns empty string If no AutoNote is found.
                        }
                        if (listAutoNoteItem.Count > i && !isAutoNote)                                       //The response already exist for this control type and it is note an AutoNote. Update it
                        //We need to update retval with the length of the new promptResponse. First, remove the previous promptResponse length.
                        {
                            retVal -= listAutoNoteItem[i].AutoNoteTextEndPos;
                            //Update the retval with the new promptResponse.Length.
                            retVal += promptResponse.Length;
                            //Update the rest of the AutoNoteItem with the new promptResponse.
                            listAutoNoteItem[i].AutoNotePromptResponseString = promptResponse;
                            listAutoNoteItem[i].AutoNoteTextStartPos         = matchloc;
                            listAutoNoteItem[i].AutoNoteTextEndPos           = promptResponse.Length;
                        }
                        else if (isAutoNote)                         //The response is an auto note. Recursively call this method.
                        //Remove the response from textMain.Text. The response was already saved. Since this is an AutoNote, the response does not need to stay
                        //in the textMain.Text since more than likely more prompts will happen after we call the recursive method below.
                        {
                            string textMainWithoutResponse = textMain.Text.Substring(0, matchloc) + GetAutoNoteResponseText(promptResponse);
                            if (textMain.Text.Length > matchloc + listPrompts[i].Value.Length)
                            {
                                textMainWithoutResponse += textMain.Text.Substring(matchloc + listPrompts[i].Value.Length);
                            }
                            matchloc += GetAutoNoteResponseText(promptResponse).Length;
                            //set the textMain.Text to the new result. This removes the promptResponse.
                            textMain.Text           = textMainWithoutResponse;
                            textMain.SelectionStart = matchloc;                          //This is needed in order for the recursive method call below.
                            //Pass in the AutoNotes note in the recursive call.
                            int lenthOfAutoNoteAdded = PromptForAutoNotes(autoNoteString, new List <AutoNoteListItem>());
                            if (lenthOfAutoNoteAdded == -1)
                            {
                                return(-1);
                            }
                            //When we get back from the recursive method, we need to figure out what was added so we can create the AutoNoteListItem
                            promptResponse = textMain.Text.Substring(matchloc, lenthOfAutoNoteAdded);
                            //Update the retVal with the new promptResponse.Length.
                            retVal += promptResponse.Length;
                            //if response already exist, update it.
                            if (listAutoNoteItem.Count > i)
                            {
                                //We need to update retVal with the length of the new promptResponse. First, remove the previous prompts length.
                                retVal -= listAutoNoteItem[i].AutoNoteTextEndPos;
                                //Update the rest of the AutoNoteItem with the new promptResponse.
                                listAutoNoteItem[i].AutoNotePromptResponseString = promptResponse;        //should be the same. Updating just in case.
                                listAutoNoteItem[i].AutoNoteTextStartPos         = matchloc;
                                listAutoNoteItem[i].AutoNoteTextEndPos           = promptResponse.Length; //This is the length of what was added.
                            }
                            else                                                                          //New Response. Add a new AutoNoteListItem.
                                                                                                          //Add the response to listAutoNoteItem. This will allow the user to go back. Make the end position equal to the length of the AutoNote
                            {
                                listAutoNoteItem.Add(new AutoNoteListItem(listPrompts[i].Value, promptResponse, matchloc, promptResponse.Length));
                            }
                        }
                        else
                        {
                            //This is a new response. Create a new AutoNoteListItem and add to retVal.
                            retVal += promptResponse.Length;
                            listAutoNoteItem.Add(new AutoNoteListItem(listPrompts[i].Value, promptResponse, matchloc, promptResponse.Length));                         //add new response to the list
                        }
                    }
                    else                      //User cancelled out of the auto note response form or auto log off.
                    {
                        ResetTextMain();
                        return(-1);
                    }
                }
                else if (control.ControlType == "MultiResponse")
                {
                    FormAutoNotePromptMultiResp FormMR = new FormAutoNotePromptMultiResp(autoNoteDescript);
                    FormMR.PromptText    = control.ControlLabel;
                    FormMR.PromptOptions = control.ControlOptions;
                    isAutoNote           = false;
                    if (i > 0)
                    {
                        FormMR.IsGoBack = true;                      //user can go back if at least one item in the list exist
                    }
                    if (listAutoNoteItem.Count > i)
                    {
                        FormMR.CurPromptResponse = listAutoNoteItem[i].AutoNotePromptResponseString;                      //pass the previous response if exist to the form.
                    }
                    FormMR.ShowDialog();
                    if (FormMR.DialogResult == DialogResult.Retry)                   //user clicked the go back button
                    {
                        GoBack(i, listAutoNoteItem);
                        stackLoc.Pop();                        //remove the start location
                        startLoc = stackLoc.Peek();            //set the new start location
                        i       -= 2;
                        continue;
                    }
                    if (FormMR.DialogResult == DialogResult.OK)
                    {
                        promptResponse = FormMR.ResultText;
                        if (listAutoNoteItem.Count > i)                       //reponse already exist for this control type. Update it
                        //We need to update retval with the length of the new promptresponse.First, remove the previous prompts length.
                        {
                            retVal -= listAutoNoteItem[i].AutoNoteTextEndPos;
                            //update the retval with the new promptResponse.Length.
                            retVal += promptResponse.Length;
                            //Update the rest of the AutoNoteItem with the new promptResponse.
                            listAutoNoteItem[i].AutoNotePromptResponseString = promptResponse;
                            listAutoNoteItem[i].AutoNoteTextStartPos         = matchloc;
                            listAutoNoteItem[i].AutoNoteTextEndPos           = promptResponse.Length;
                        }
                        else
                        {
                            //This is a new response. Create a new AutoNoteListItem and add to retVal.
                            retVal += promptResponse.Length;
                            listAutoNoteItem.Add(new AutoNoteListItem(listPrompts[i].Value, promptResponse, matchloc, promptResponse.Length));                         //add new response to the list
                        }
                    }
                    else                      //User cancelled out of the auto note response form or auto log off.
                    {
                        ResetTextMain();
                        return(-1);
                    }
                }
                string resultstr = textMain.Text.Substring(0, matchloc) + promptResponse;
                if (!isAutoNote && textMain.Text.Length > matchloc + listPrompts[i].Value.Length)
                {
                    resultstr += textMain.Text.Substring(matchloc + listPrompts[i].Value.Length);
                }
                else if (isAutoNote && textMain.Text.Length > matchloc + promptResponse.Length)
                {
                    //if any of the prompts had an AutoNote and textmain has more text, add the rest of textMain.
                    resultstr += textMain.Text.Substring(matchloc + promptResponse.Length);
                    //update the startLoc to include the promptResponse of the AutoNote.
                    startLoc += promptResponse.Length - 1;
                }
                textMain.Text = resultstr;
                ResetTextMain();
                if (string.IsNullOrEmpty(promptResponse))
                {
                    //if prompt was removed, add the previous start location onto the stack.
                    startLoc = stackLoc.Peek();
                }
                stackLoc.Push(startLoc);
                Application.DoEvents();                //refresh the textbox
            }
            ResetTextMain();
            listAutoNoteItem.Clear();
            return(retVal);
        }
Exemple #17
0
        private void DrawControls()
        {
            int TextBoxCount  = 0;
            int ComboBoxCount = 0;

            for (int i = 0; i < listBoxControls.Items.Count; i++)
            {
                AutoNoteControls.RefreshControl(listBoxControls.Items[i].ToString());
                ControlCur = AutoNoteControls.Listt[0];
                switch (ControlCur.ControlType)
                {
                case "TextBox":
                    TextBoxCount++;
                    break;

                case "MultiLineTextBox":
                    TextBoxCount++;
                    break;

                case "ComboBox":
                    ComboBoxCount++;
                    break;
                }
            }
            System.Windows.Forms.ComboBox[] comboBox = new ComboBox[ComboBoxCount];
            System.Windows.Forms.TextBox[]  textBox  = new TextBox[TextBoxCount];
            System.Windows.Forms.Label[]    label    = new Label[listBoxControls.Items.Count];
            for (int l = 0; l < listBoxControls.Items.Count; l++)
            {
                AutoNoteControls.RefreshControl(listBoxControls.Items[l].ToString());
                ControlCur        = AutoNoteControls.Listt[0];
                label[l]          = new Label();
                label[l].AutoSize = true;
                label[l].Text     = ControlCur.ControlLabel;
            }
            int CurText  = 0;
            int CurCombo = 0;
            int spacing  = 140;

            for (int l = 0; l < listBoxControls.Items.Count; l++)
            {
                AutoNoteControls.RefreshControl(listBoxControls.Items[l].ToString());
                ControlCur = AutoNoteControls.Listt[0];
                switch (ControlCur.ControlType)
                {
                case "TextBox":
                    textBox[CurText]          = new TextBox();
                    textBox[CurText].TabIndex = this.Controls.Count;
                    textBox[CurText].Location = new Point(label[l].Text.Length * 6 + 15, spacing);
                    this.Controls.Add(textBox[CurText]);
                    label[l].Location = new Point(10, spacing);
                    spacing           = spacing + 30;
                    CurText++;
                    break;

                case "MultiLineTextBox":
                    textBox[CurText]           = new TextBox();
                    textBox[CurText].Multiline = true;
                    textBox[CurText].Size      = new Size(177, 67);
                    textBox[CurText].Location  = new Point(label[l].Text.Length * 6 + 15, spacing);
                    textBox[CurText].Text      = ControlCur.MultiLineText;
                    this.Controls.Add(textBox[CurText]);
                    label[l].Location = new Point(10, spacing);
                    spacing           = spacing + 77;
                    CurText++;
                    break;

                case "ComboBox":
                    comboBox[CurCombo] = new ComboBox();
                    string[] lines = ControlCur.ControlOptions.Split(new char[] { ',' });
                    for (int i = 0; i < lines.Length; i++)
                    {
                        comboBox[CurCombo].Items.Add(lines[i]);
                    }
                    comboBox[CurCombo].AutoCompleteMode   = AutoCompleteMode.SuggestAppend;
                    comboBox[CurCombo].AutoCompleteSource = AutoCompleteSource.ListItems;
                    this.Controls.Add(comboBox[CurCombo]);
                    label[l].Location           = new Point(10, spacing);
                    comboBox[CurCombo].Location = new Point(label[l].Text.Length * 6 + 15, spacing);
                    spacing = spacing + 30;
                    CurCombo++;
                    break;
                }
                for (int xl = 0; xl < listBoxControls.Items.Count; xl++)
                {
                    this.Controls.Add(label[xl]);
                }
            }
            butOK.Visible  = true;
            butOK.Location = new Point(330, spacing);
        }
        void PromptForAutoNotes(string noteToParse)
        {
            string note           = noteToParse;
            int    selectionStart = textMain.SelectionStart;

            if (selectionStart == 0)
            {
                textMain.Text = note + textMain.Text;
            }
            else if (selectionStart == textMain.Text.Length - 1)
            {
                textMain.Text = textMain.Text + note;
            }
            else if (selectionStart == -1)           //?is this even possible?
            {
                textMain.Text = textMain.Text + note;
            }
            else
            {
                textMain.Text = textMain.Text.Substring(0, selectionStart) + note + textMain.Text.Substring(selectionStart);
            }
            List <AutoNoteControl> prompts     = new List <AutoNoteControl>();
            List <Match>           listMatches = Regex.Matches(note, @"\[Prompt:""[a-zA-Z_0-9 ]+""\]").OfType <Match>().ToList();

            listMatches.RemoveAll(x => AutoNoteControls.GetByDescript(x.Value.Substring(9, x.Value.Length - 11)) == null);
            string          autoNoteDescript;
            AutoNoteControl control;
            string          promptResponse;
            int             matchloc;
            int             startLoc = 0;
            Stack <int>     stackLoc = new Stack <int>();

            stackLoc.Push(startLoc);
            for (int i = 0; i < listMatches.Count; i++)
            {
                //highlight the current match in red
                matchloc = textMain.Text.IndexOf(listMatches[i].Value, startLoc);
                startLoc = matchloc + 1;
                textMain.Select(matchloc, listMatches[i].Value.Length);
                textMain.SelectionBackColor = Color.Yellow;
                textMain.SelectionLength    = 0;
                Application.DoEvents();                                              //refresh the textbox
                autoNoteDescript = listMatches[i].Value.Substring(9, listMatches[i].Value.Length - 11);
                control          = AutoNoteControls.GetByDescript(autoNoteDescript); //should never be null since we removed nulls above
                promptResponse   = "";
                if (control.ControlType == "Text")
                {
                    FormAutoNotePromptText FormT = new FormAutoNotePromptText(autoNoteDescript);
                    FormT.PromptText = control.ControlLabel;
                    FormT.ResultText = control.ControlOptions;
                    if (i > 0)
                    {
                        FormT.IsGoBack = true;                      //user can go back if at least one item in the list exist
                    }
                    if (_listAutoNotePrompts.Count > i)
                    {
                        FormT.CurPromptResponse = _listAutoNotePrompts[i].AutoNoteTextString;                      //pass the previous response to the form
                    }
                    FormT.ShowDialog();
                    if (FormT.DialogResult == DialogResult.Retry)                   //user clicked the go back button
                    {
                        GoBack(i);
                        stackLoc.Pop();
                        startLoc = stackLoc.Peek();
                        i       -= 2;
                        continue;
                    }
                    if (FormT.DialogResult == DialogResult.OK)
                    {
                        promptResponse = FormT.ResultText;
                        if (_listAutoNotePrompts.Count > i)                       //reponse already exist for this control type. Update it
                        {
                            _listAutoNotePrompts[i].AutoNoteTextString   = promptResponse;
                            _listAutoNotePrompts[i].AutoNoteTextStartPos = matchloc;
                        }
                        else
                        {
                            _listAutoNotePrompts.Add(new AutoNoteListItem(listMatches[i].Value, promptResponse, matchloc));                          //add new response to the list
                        }
                    }
                    else
                    {
                        textMain.SelectAll();
                        textMain.SelectionBackColor = Color.White;
                        textMain.Select(textMain.Text.Length, 0);
                        return;
                    }
                }
                else if (control.ControlType == "OneResponse")
                {
                    FormAutoNotePromptOneResp FormOR = new FormAutoNotePromptOneResp(autoNoteDescript);
                    FormOR.PromptText    = control.ControlLabel;
                    FormOR.PromptOptions = control.ControlOptions;
                    if (i > 0)
                    {
                        FormOR.IsGoBack = true;                      //user can go back if at least one item in the list exist
                    }
                    if (_listAutoNotePrompts.Count > i)
                    {
                        FormOR.CurPromptResponse = _listAutoNotePrompts[i].AutoNoteTextString;                      //pass the previous response if exist to the form.
                    }
                    FormOR.ShowDialog();
                    if (FormOR.DialogResult == DialogResult.Retry)                   //user clicked the go back button
                    {
                        GoBack(i);
                        stackLoc.Pop();
                        startLoc = stackLoc.Peek();
                        i       -= 2;
                        continue;
                    }
                    if (FormOR.DialogResult == DialogResult.OK)
                    {
                        promptResponse = FormOR.ResultText;
                        if (_listAutoNotePrompts.Count > i)                       //reponse already exist for this control type. Update it
                        {
                            _listAutoNotePrompts[i].AutoNoteTextString   = promptResponse;
                            _listAutoNotePrompts[i].AutoNoteTextStartPos = matchloc;
                        }
                        else
                        {
                            _listAutoNotePrompts.Add(new AutoNoteListItem(listMatches[i].Value, promptResponse, matchloc));                          //add new response to the list
                        }
                    }
                    else
                    {
                        textMain.SelectAll();
                        textMain.SelectionBackColor = Color.White;
                        textMain.Select(textMain.Text.Length, 0);
                        return;
                    }
                }
                else if (control.ControlType == "MultiResponse")
                {
                    FormAutoNotePromptMultiResp FormMR = new FormAutoNotePromptMultiResp(autoNoteDescript);
                    FormMR.PromptText    = control.ControlLabel;
                    FormMR.PromptOptions = control.ControlOptions;
                    if (i > 0)
                    {
                        FormMR.IsGoBack = true;                      //user can go back if at least one item in the list exist
                    }
                    if (_listAutoNotePrompts.Count > i)
                    {
                        FormMR.CurPromptResponse = _listAutoNotePrompts[i].AutoNoteTextString;                      //pass the previous response if exist to the form.
                    }
                    FormMR.ShowDialog();
                    if (FormMR.DialogResult == DialogResult.Retry)                   //user clicked the go back button
                    {
                        GoBack(i);
                        stackLoc.Pop();
                        startLoc = stackLoc.Peek();
                        i       -= 2;
                        continue;
                    }
                    if (FormMR.DialogResult == DialogResult.OK)
                    {
                        promptResponse = FormMR.ResultText;
                        if (_listAutoNotePrompts.Count > i)                       //reponse already exist for this control type. Update it
                        {
                            _listAutoNotePrompts[i].AutoNoteTextString   = promptResponse;
                            _listAutoNotePrompts[i].AutoNoteTextStartPos = matchloc;
                        }
                        else
                        {
                            _listAutoNotePrompts.Add(new AutoNoteListItem(listMatches[i].Value, promptResponse, matchloc));                          //add new response to the list
                        }
                    }
                    else
                    {
                        textMain.SelectAll();
                        textMain.SelectionBackColor = Color.White;
                        textMain.Select(textMain.Text.Length, 0);
                        return;
                    }
                }
                string resultstr = textMain.Text.Substring(0, matchloc) + promptResponse;
                if (textMain.Text.Length > matchloc + listMatches[i].Value.Length)
                {
                    resultstr += textMain.Text.Substring(matchloc + listMatches[i].Value.Length);
                }
                textMain.Text = resultstr;
                textMain.SelectAll();
                textMain.SelectionBackColor = Color.White;
                textMain.Select(textMain.Text.Length, 0);
                if (string.IsNullOrEmpty(promptResponse))
                {
                    //if prompt was removed, add the previous start location onto the stack.
                    startLoc = stackLoc.Peek();
                }
                stackLoc.Push(startLoc);
                Application.DoEvents();                //refresh the textbox
            }
            textMain.SelectAll();
            textMain.SelectionBackColor = Color.White;
            textMain.Select(textMain.Text.Length, 0);
            _listAutoNotePrompts.Clear();
        }
Exemple #19
0
        private void listMain_DoubleClick(object sender, EventArgs e)
        {
            if (listMain.SelectedIndex == -1)
            {
                return;
            }
            string note           = AutoNotes.Listt[listMain.SelectedIndex].MainText;
            int    selectionStart = textMain.SelectionStart;

            if (selectionStart == 0)
            {
                textMain.Text = note + textMain.Text;
            }
            else if (selectionStart == textMain.Text.Length - 1)
            {
                textMain.Text = textMain.Text + note;
            }
            else if (selectionStart == -1)           //?is this even possible?
            {
                textMain.Text = textMain.Text + note;
            }
            else
            {
                textMain.Text = textMain.Text.Substring(0, selectionStart) + note + textMain.Text.Substring(selectionStart);
            }
            List <AutoNoteControl> prompts = new List <AutoNoteControl>();
            MatchCollection        matches = Regex.Matches(note, @"\[Prompt:""[a-zA-Z_0-9 ]+""\]");
            string          autoNoteDescript;
            AutoNoteControl control;
            string          promptResponse;
            int             matchloc;

            for (int i = 0; i < matches.Count; i++)
            {
                //highlight the current match in red
                matchloc = textMain.Text.IndexOf(matches[i].Value);
                textMain.Select(matchloc, matches[i].Value.Length);
                textMain.SelectionBackColor = Color.Yellow;
                textMain.SelectionLength    = 0;
                Application.DoEvents();                //refresh the textbox
                autoNoteDescript = matches[i].Value.Substring(9, matches[i].Value.Length - 11);
                control          = AutoNoteControls.GetByDescript(autoNoteDescript);
                if (control == null)
                {
                    continue;                    //couldn't find a prompt with that name, so just ignore it.
                }
                promptResponse = "";
                if (control.ControlType == "Text")
                {
                    FormAutoNotePromptText FormT = new FormAutoNotePromptText();
                    FormT.PromptText = control.ControlLabel;
                    FormT.ResultText = control.ControlOptions;
                    FormT.ShowDialog();
                    if (FormT.DialogResult == DialogResult.OK)
                    {
                        promptResponse = FormT.ResultText;
                    }
                    else
                    {
                        textMain.SelectAll();
                        textMain.SelectionBackColor = Color.White;
                        textMain.Select(textMain.Text.Length, 0);
                        return;
                    }
                }
                else if (control.ControlType == "OneResponse")
                {
                    FormAutoNotePromptOneResp FormOR = new FormAutoNotePromptOneResp();
                    FormOR.PromptText    = control.ControlLabel;
                    FormOR.PromptOptions = control.ControlOptions;
                    FormOR.ShowDialog();
                    if (FormOR.DialogResult == DialogResult.OK)
                    {
                        promptResponse = FormOR.ResultText;
                    }
                    else
                    {
                        textMain.SelectAll();
                        textMain.SelectionBackColor = Color.White;
                        textMain.Select(textMain.Text.Length, 0);
                        return;
                    }
                }
                else if (control.ControlType == "MultiResponse")
                {
                    FormAutoNotePromptMultiResp FormMR = new FormAutoNotePromptMultiResp();
                    FormMR.PromptText    = control.ControlLabel;
                    FormMR.PromptOptions = control.ControlOptions;
                    FormMR.ShowDialog();
                    if (FormMR.DialogResult == DialogResult.OK)
                    {
                        promptResponse = FormMR.ResultText;
                    }
                    else
                    {
                        textMain.SelectAll();
                        textMain.SelectionBackColor = Color.White;
                        textMain.Select(textMain.Text.Length, 0);
                        return;
                    }
                }
                string resultstr = textMain.Text.Substring(0, matchloc) + promptResponse;
                if (textMain.Text.Length > matchloc + matches[i].Value.Length)
                {
                    resultstr += textMain.Text.Substring(matchloc + matches[i].Value.Length);
                }
                textMain.Text = resultstr;
                textMain.SelectAll();
                textMain.SelectionBackColor = Color.White;
                textMain.Select(textMain.Text.Length, 0);
                Application.DoEvents();                //refresh the textbox
            }
            textMain.SelectAll();
            textMain.SelectionBackColor = Color.White;
            textMain.Select(textMain.Text.Length, 0);
        }