private void Button_Click(object sender, RoutedEventArgs e)
 {
     System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog();
     if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         tbFileName.Text = ofd.FileName;
         using (GenericParserAdapter parser = new GenericParserAdapter(tbFileName.Text))
         {
             parser.Load("prediction-format.xml");
             System.Data.DataSet dsResult = parser.GetDataSet();
             DisplayData = dsResult.Tables[0];
             PopulateFromAndTo();
         }
     }
 }
示例#2
0
文件: Form1.cs 项目: cdcunha/ViewFile
        private void AbrirArquivoLaguraFixa()
        {
            if (!string.IsNullOrEmpty(labelXMLConfigFile.Text) && labelXMLConfigFile.Text != "Nenhum arquivo selecionado" &&
                !string.IsNullOrEmpty(labelFileName.Text) && labelFileName.Text != "Nenhum arquivo selecionado")
            {
                dataGridView1.DataSource = null;
                dataGridView1.Refresh();

                using (GenericParserAdapter parser = new GenericParserAdapter(labelFileName.Text, GetEncodingFromCombo()))
                {
                    parser.Load(labelXMLConfigFile.Text);
                    dataSet1 = parser.GetDataSet();

                    VerifyGridNumRowAndSetLabelReg(dataSet1.Tables[0].Rows.Count);

                    dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
                    dataGridView1.AutoGenerateColumns = true;
                    dataGridView1.DataSource          = dataSet1.Tables[0];
                    dataGridView1.Focus();
                }
            }
            else
            {
                string message = "";
                if (!string.IsNullOrEmpty(labelXMLConfigFile.Text) && labelXMLConfigFile.Text != "Nenhum arquivo selecionado")
                {
                    message += "Selecione o arquivo modelo (XML)\n";
                }
                if (!string.IsNullOrEmpty(labelFileName.Text) && labelFileName.Text != "Nenhum arquivo selecionado")
                {
                    {
                        message += "Selecione o arquivo texto\n";
                    }
                }
                MessageBox.Show(message);
            }
        }
示例#3
0
        private void buttonExecute_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(labelXMLConfigFile.Text) && !string.IsNullOrEmpty(labelFileName.Text))
            {
                dataGridView1.DataSource = null;
                using (GenericParserAdapter parser = new GenericParserAdapter(labelFileName.Text))
                {
                    parser.Load(labelXMLConfigFile.Text);
                    dataSet1 = parser.GetDataSet();

                    int qtdRegistros = dataSet1.Tables[0].Rows.Count;
                    if (qtdRegistros > 1)
                    {
                        labelQtdeRegistros.Text = String.Format("{0:#,##0} Registros", dataSet1.Tables[0].Rows.Count);
                    }
                    else
                    {
                        labelQtdeRegistros.Text = String.Format("{0:#,##0} Registro", dataSet1.Tables[0].Rows.Count);
                    }

                    dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
                    dataGridView1.AutoGenerateColumns = true;
                    dataGridView1.DataSource          = dataSet1.Tables[0];

                    dataSet1.Tables[0].Columns.Add("Existe", typeof(System.String));
                    List <String> listCpfFound = new List <String>();

                    if (!string.IsNullOrEmpty(textBoxConnectioString.Text) && !string.IsNullOrEmpty(textBoxQuery.Text))
                    {
                        try
                        {
                            //Password=sqluser;User ID=sqluser;Data Source=serverss003;Initial Catalog=COL_COLWEBACEITE;Persist Security Info=True
                            using (var con = new SqlConnection(textBoxConnectioString.Text))
                            {
                                string filtro = "";
                                foreach (DataRow row in dataSet1.Tables[0].Rows)
                                {
                                    string text = row[2].ToString();
                                    string cpf  = text.Substring(0, 3) + "." +
                                                  text.Substring(3, 3) + "." +
                                                  text.Substring(6, 3) + "-" +
                                                  text.Substring(9, 2);

                                    text = row[9].ToString();
                                    string data = text.Substring(4, 4) + text.Substring(2, 2) + text.Substring(0, 2);

                                    string propCia = row[11].ToString().TrimStart('0');

                                    if (string.IsNullOrEmpty(filtro))
                                    {
                                        filtro = string.Format(" (tc.Cgc_cpf = '{0}' and td.Inicio_vigencia = '{1}' and td.Proposta_cia = '{2}')\n", cpf, data, propCia);
                                    }
                                    else
                                    {
                                        filtro += string.Format(" or (tc.Cgc_cpf = '{0}' and td.Inicio_vigencia = '{1}' and td.Proposta_cia = '{2}')\n", cpf, data, propCia);
                                    }
                                }
                                con.Open();
                                using (SqlCommand command = new SqlCommand(string.Format(textBoxQuery.Text, filtro), con))
                                {
                                    command.CommandTimeout = 3000;
                                    using (SqlDataReader reader = command.ExecuteReader())
                                    {
                                        while (reader.Read())
                                        {
                                            listCpfFound.Add(reader.GetString(0).Replace("-", "").Replace(".", ""));
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Erro ao acessar o banco de dados: " + ex.Message);
                        }
                    }

                    foreach (DataRow row in dataSet1.Tables[0].Rows)
                    {
                        if (listCpfFound.Where(c => c == row[2].ToString()).Count() > 0)
                        {
                            row["Existe"] = "Sim";
                        }
                        else
                        {
                            row["Existe"] = "Não";
                        }
                    }

                    dataGridView1.Focus();
                }
            }
        }