コード例 #1
0
ファイル: Form1.cs プロジェクト: marta8917/prova_mysql
        private void btnCerca_Click(object sender, EventArgs e)
        {
            var filters = new List <ISqlFilter>();

            if (_textBoxPlaceHolderEmail.GetValue() != "")
            {
                filters.Add(new StringTextFilter("email", txtEmail.Text, _comboTextSettings.GetValue()));
            }
            if (_textBoxPlaceHolderPhone.GetValue() != "")
            {
                filters.Add(new StringTextFilter("phone", txtPhone.Text, _comboTextSettings.GetValue()));
            }
            if (_textBoxPlaceHolderName.GetValue() != "")
            {
                filters.Add(new StringTextFilter("name", txtName.Text, _comboTextSettings.GetValue()));
            }
            if (numericUpDown1.Value != 0)
            {
                int val = (int)numericUpDown1.Value;
                filters.Add(new IntFilter("counter", val, _comboIntSettings.GetValue()));
            }
            if (_textBoxPlaceHolderNotes.GetValue() != "")
            {
                filters.Add(new StringTextFilter("notes", txtNotes.Text, _comboTextSettings.GetValue()));
            }
            if (checkBox1.Checked)
            {
                filters.Add(new DateTimeFilter("timestamp", dateTimePicker.Value, _comboDateTimeSettings.GetValue()));
            }



            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // SELEZIONE FILEPATH
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.DefaultExt = "csv";
            saveFileDialog.Filter     = "Csv files|*.csv";
            saveFileDialog.ShowDialog();
            var filePath = saveFileDialog.FileName;


            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // SCRIVO
            var filter         = new AndCompositeFilter(filters.ToArray());
            var userRepo1      = new UserRepository();
            var usersList      = userRepo1.GetUsers(filter);
            var csvWriter      = new CsvWriter();
            var userListString = csvWriter.GetCsvRows(usersList);

            using (var file = System.IO.File.CreateText(filePath))//using = dispose (chiude)
            {
                foreach (var row in userListString)
                {
                    file.WriteLine(row);
                }
            }
        }
コード例 #2
0
ファイル: FilterTests.cs プロジェクト: marta8917/prova_mysql
        public void when_requesting_after_datetime_and_equal_mail_returns_correct_sql_string()
        {
            var datetime = new DateTime(2018, 04, 16, 13, 24, 32);

            ISqlFilter[] isqlFilter = { new DateTimeFilter("timestamp", datetime,              DateTimeFilterMode.After),
                                        new StringTextFilter("email",   "*****@*****.**", StringTextFilterMode.Equal) };

            var andCompositeFilter = new AndCompositeFilter(isqlFilter);
            var result             = andCompositeFilter.GetMySqlString();

            Assert.That(result, Is.EqualTo("timestamp > '20180416 13:24:32' AND email = '*****@*****.**'"));
        }
コード例 #3
0
ファイル: FilterTests.cs プロジェクト: marta8917/prova_mysql
        public void when_requesting_before_datetime_or_contains_string_and_major_int_returns_correct_sql_string()
        {
            var datetime = new DateTime(2018, 04, 16, 13, 24, 32);

            ISqlFilter[] isqlFilter = { new DateTimeFilter("timestamp", datetime, DateTimeFilterMode.Before),
                                        new StringTextFilter("phone",   "2",      StringTextFilterMode.Contains) };

            var orCompositeFilter = new OrCompositeFilter(isqlFilter);
            var andFilter         = new AndCompositeFilter(orCompositeFilter, new IntFilter("counter", 1, IntFilterMode.Major));
            var result            = andFilter.GetMySqlString();

            Assert.That(result, Is.EqualTo("timestamp < '20180416 13:24:32' OR phone LIKE '%2%' AND counter > 1"));
        }