Esempio n. 1
0
 internal string CreateBulkInsertStatementWithParameter(ITableData data, string tableName, List <OdbcParameter> parameters)
 {
     QueryText.Clear();
     TableName = tableName;
     GetSourceAndDestColumnNames(data);
     AppendBeginSql(tableName);
     while (data.Read())
     {
         QueryText.Append("(");
         string[] placeholder = new string[DestColumnNames.Count];
         QueryText.Append(string.Join(",", placeholder.Select(s => s + "?")));
         QueryText.AppendLine(")");
         foreach (string destColumnName in DestColumnNames)
         {
             int    colIndex     = data.GetOrdinal(destColumnName);
             string dataTypeName = data.GetDataTypeName(colIndex);
             if (data.IsDBNull(colIndex))
             {
                 parameters.Add(new OdbcParameter(destColumnName, DBNull.Value));
             }
             else
             {
                 parameters.Add(new OdbcParameter(destColumnName, data.GetValue(colIndex)));
             }
         }
         if (data.NextResult())
         {
             QueryText.Append(",");
         }
     }
     AppendEndSql();
     return(QueryText.ToString());
 }
Esempio n. 2
0
        private void SearchButton_Click(object sender, RoutedEventArgs e)
        {
            QueryText.Clear();
            string[] InputStrings = File.ReadAllLines(@"../../Information.txt");

            List <Person> people = new List <Person>();

            for (int i = 0; i < InputStrings.Length; i += 6)
            {
                people.Add(new Person(InputStrings[i], InputStrings[i + 1], InputStrings[i + 2], int.Parse(InputStrings[i + 3]), InputStrings[i + 4], InputStrings[i + 5]));
            }

            string firstname = FirstNameText.Text.ToLower();
            string lastname  = LastNameText.Text.ToLower();
            string city      = CityText.Text.ToLower();
            int    overage;

            try
            {
                overage = int.Parse(OverAgeText.Text);
            }
            catch
            {
                overage = -1;
            }
            int lowerage;

            try
            {
                lowerage = int.Parse(LowerAgeText.Text);
            }
            catch
            {
                lowerage = -1;
            }

            string        eqution1 = Equation1Text.Text.ToLower();
            string        eqution2 = Equation2Text.Text.ToLower();
            string        answers  = AnswersText.Text.ToLower();
            List <Person> searched = people;

            if (firstname != "")
            {
                searched = searched.Where(d => d.FirstName == firstname).ToList();
            }
            if (lastname != "")
            {
                searched = searched.Where(d => d.LastName == lastname).ToList();
            }
            if (city != "")
            {
                searched = searched.Where(d => d.City == city).ToList();
            }
            if (overage != -1)
            {
                searched = searched.Where(d => d.Age > overage).ToList();
            }
            if (lowerage != -1)
            {
                searched = searched.Where(d => d.Age < lowerage).ToList();
            }
            if (eqution1 != "")
            {
                if (eqution2 != "")
                {
                    searched = searched.Where(d => (d.Equation1 == eqution1 && d.Equation2 == eqution2) || (d.Equation2 == eqution1 && d.Equation1 == eqution2)).ToList();
                }
                else
                {
                    searched = searched.Where(d => (d.Equation1 == eqution1) || (d.Equation2 == eqution1)).ToList();
                }
            }
            else
            {
                if (eqution2 != "")
                {
                    searched = searched.Where(d => (d.Equation1 == eqution2) || (d.Equation2 == eqution2)).ToList();
                }
            }

            if (answers != "")
            {
                string[] s = answers.Split(',');
                double[] a = new double[2];
                a[0] = double.Parse(s[0]);
                a[1] = double.Parse(s[1]);
                Array.Sort(a);
                searched = searched.Where(d => d.Answers[0].answer == a[0] && d.Answers[1].answer == a[1]).ToList();
            }

            for (int i = 0; i < searched.Count; i++)
            {
                QueryText.Text += $"Person {i + 1} :\n";
                QueryText.Text += $"  First Name : {searched[i].FirstName}\n";
                QueryText.Text += $"  Last Name : { searched[i].LastName}\n";
                QueryText.Text += $"  City : {searched[i].City}\n";
                QueryText.Text += $"  Age : {searched[i].Age}\n";
                QueryText.Text += $"  Equation 1 : {searched[i].Equation1}\n";
                QueryText.Text += $"  Equation 2 : {searched[i].Equation2}\n";
            }
        }