private company FindCompany(string CompanyName)
        {
            try
            {
                company toReturn           = new company();
                string  trimmedCompanyName = CommonFunctions.TrimSpaces(CompanyName);
                toReturn.name = trimmedCompanyName;

                toReturn.SearchType = DataObject.SearchTypes.Exact;
                DataTable results = toReturn.Search("SELECT * FROM companies WHERE name = '" + trimmedCompanyName + "'");
                if (results.Rows.Count > 0)
                {
                    toReturn.Load(results.Rows[0]);
                }

                toReturn.created_on = DateTime.Now;
                toReturn.name       = trimmedCompanyName;

                toReturn.Save();
                return(toReturn);
            }
            catch (Exception err)
            {
                // Somewhat dangerous, but it ensures that the import won't crash
                LoggingHelper.Log("Error in frmImportData.FindCompany", LogSeverity.Critical, err, true);
                return(null);
            }
        }
        private company_contact_info FindContactInfo(string addressField, int companyId, string phoneNum)
        {
            try
            {
                company_contact_info toReturn = new company_contact_info();
                string trimmedAddress         = CommonFunctions.TrimSpaces(addressField);

                toReturn.address = trimmedAddress;
                toReturn.phone   = phoneNum;

                DataTable results = toReturn.Search("SELECT * FROM company_contact_info WHERE company_id = " + companyId +
                                                    " AND address = '" + trimmedAddress + "' AND phone = '" + phoneNum + "'");
                if (results.Rows.Count > 0)
                {
                    toReturn.Load(results.Rows[0]);
                }

                toReturn.address = trimmedAddress;
                return(toReturn);
            }
            catch (Exception err)
            {
                // Somewhat dangerous, but it ensures that the import won't crash
                LoggingHelper.Log("Error in frmImportData.FindContactInfo", LogSeverity.Critical, err, true);
                return(null);
            }
        }
Exemple #3
0
        private void CreateQuestion(int parentID, string currentLine, int orderID)
        {
            question newQ        = new question();
            string   workingText = currentLine;

            workingText = workingText.Replace("==", "|");
            string[] splitText = workingText.Split("|".ToCharArray());
            // [0] = text, [1] = type, [2] = question text or if combo, drop down options

            if ((splitText.Length < 2) || (splitText.Length > 4))
            {
                System.Diagnostics.Debug.Print("Length is wrong (" + splitText.Length + ")");
                return;
            }

            newQ.order_id = orderID;
            newQ.parent   = parentID;
            newQ.text     = CommonFunctions.TrimSpaces(splitText[0].Replace("- ", ""));

            newQ.type = GetQuestionType(CommonFunctions.TrimSpaces(splitText[1]));


            if (newQ.type == question.QuestionTypes.MultipleChoice)
            {
                if (splitText.Length == 3)
                {
                    newQ.popup_question_text = newQ.text;
                }
                else
                {
                    newQ.popup_question_text = CommonFunctions.TrimSpaces(splitText[2]);
                }
            }
            else
            {
                if (splitText.Length > 2)
                {
                    newQ.popup_question_text = CommonFunctions.TrimSpaces(splitText[2]);
                }
                else
                {
                    newQ.popup_question_text = newQ.text;
                }
            }

            newQ.Save();

            if (newQ.type == question.QuestionTypes.MultipleChoice)
            {
                GenerateMultipleChoiceAnswers(splitText[splitText.Length - 1], newQ.id);
            }
        }
Exemple #4
0
        private void GenerateMultipleChoiceAnswers(string answersToParse, int questionID)
        {
            string[] answers           = answersToParse.Split(",".ToCharArray());
            multiple_choice_answer mca = new multiple_choice_answer();

            mca.question_id = questionID;

            for (int i = 0; i < answers.Length; i++)
            {
                mca.order_id    = i;
                mca.answer_text = CommonFunctions.TrimSpaces(answers[i]);
                mca.Save();
            }
        }
        internal static FormattedName GetFormattedName(string unformattedName)
        {
            FormattedName toReturn;
            string        workingValue = unformattedName.Trim();

            if (workingValue.Contains(" "))
            {
                toReturn.FirstName = workingValue.Substring(0, workingValue.IndexOf(" "));
            }
            else
            {
                toReturn.FirstName     = workingValue;
                toReturn.MiddleInitial = "";
                toReturn.LastName      = "";
                return(toReturn);
            }

            // Remove everything up to the first space
            workingValue = workingValue.Remove(0, toReturn.FirstName.Length + 1);

            if (workingValue.Length > 1)
            {
                if (workingValue[1].ToString() == " ")
                {
                    // If the character is one "letter" long, then assume it's the middle initial
                    toReturn.MiddleInitial = workingValue[0].ToString();

                    workingValue = workingValue.Remove(0, 2);
                }
                else
                {
                    toReturn.MiddleInitial = "";
                }
            }
            else
            {
                toReturn.MiddleInitial = "";
            }

            toReturn.LastName = CommonFunctions.TrimSpaces(workingValue);

            return(toReturn);
        }
 internal static string FormatName(string firstName, string middleInitial, string lastName)
 {
     return(CommonFunctions.TrimSpaces(firstName + " " + middleInitial + " " + lastName));
 }
Exemple #7
0
        public void ImportFile(string filePath, int first_Order_ID)
        {
            StreamReader          sr = new StreamReader(filePath);
            int                   currentParentID = 0;
            Dictionary <int, int> orderIDs        = new Dictionary <int, int>();
            Dictionary <int, int> parentIDs       = new Dictionary <int, int>();
            question              q;
            string                currentLine;

            currentLine = sr.ReadLine();
            while (currentLine != null)
            {
                string currentLineNoSpace = CommonFunctions.TrimSpaces(currentLine);
                if (currentLine.StartsWith("#"))
                {
                    // Comment. Ignore it, just move to next line
                }
                else
                {
                    if (currentLineNoSpace == "-")
                    {
                        if (!parentIDs.ContainsKey(currentLine.Length))
                        {
                            parentIDs.Add(currentLine.Length, currentParentID);
                            if (currentLine == "-")
                            {
                                orderIDs.Add(currentLine.Length, first_Order_ID);
                            }
                            else
                            {
                                orderIDs.Add(currentLine.Length, 0);
                            }
                        }

                        currentParentID = parentIDs[currentLine.Length];
                    }
                    else if (currentLineNoSpace.StartsWith("question"))
                    {
                        // TODO: Requires changes to the 02-rejected .yml file. Everywhere else should be OK
                        // issue is "question" being used in a weird spot
                        // Need to rearrange the way it works so that instead of being a drop down, there are a
                        // number of Yes/No options followed by an "other" expand category

                        if (!orderIDs.ContainsKey(currentParentID))
                        {
                            orderIDs.Add(currentParentID, 0);
                        }

                        q = CreateCategoryQuestion(currentParentID, currentLineNoSpace, orderIDs[currentParentID]);

                        orderIDs[currentParentID] = orderIDs[currentParentID] + 1;

                        currentParentID = q.id;
                        if (!orderIDs.ContainsKey(currentParentID))
                        {
                            orderIDs.Add(currentParentID, 0);
                        }
                    }
                    else if (currentLineNoSpace == "choices")
                    {
                        // Seems like I can ignore it, but might be necessary for returning to other "levels" of questions
                    }
                    else if (currentLineNoSpace.StartsWith("-"))
                    {
                        CreateQuestion(currentParentID, currentLineNoSpace, orderIDs[currentParentID]);

                        orderIDs[currentParentID] = orderIDs[currentParentID] + 1;
                    }
                }


                currentLine = sr.ReadLine();
            }
        }