Ejemplo n.º 1
0
        private void btnNext_Click(object sender, EventArgs e)
        {
            List<DataImportTable> tableList = new List<DataImportTable>();
            foreach (DataGridViewRow row in dgvDataType.Rows)
            {
                string tableName = (string)row.Cells[0].Value;
                DataImportTable table;
                if (!tableList.Exists(t => t.Name == tableName))
                {
                    table = new DataImportTable() {
                        Name = tableName
                        , Order = tableList.Count+1
                        //, Count = (UInt64)tvObjects.Nodes[0].Nodes.Find(tableName, false)[0].Tag
                        , Columns = new List<DataImportColumn>()
                        , Loaded=false
                    };

                    tableList.Add(table);
                }
                else
                    table = tableList.Single(t => t.Name == tableName);

                if (row.Cells[4].Value == null)
                    row.ErrorText = "Vous devez sélectionner un type de données.\n";

                if(row.Cells[5].Value==null)
                    row.ErrorText += "Vous devez sélectionner une taille pour le type de données.";

                if (row.ErrorText != string.Empty)
                    return;

                DataImportColumn column = new DataImportColumn()
                    {
                        Name = (string)row.Cells[1].Value
                        ,
                        DataType = (string)row.Cells[4].Value
                        ,
                        Size = row.Cells[5].Value.ToString()
                        ,
                        Order = table.Columns.Count+1
                        ,
                        Loaded = false
                    };
                table.Columns.Add(column);
            }
            IConnector conn = Connector.GetConnector(_sgbdType);
            conn.Initialize(_connectionString);
            Cursor.Current = Cursors.WaitCursor;
            FrmDatabaseImportProcess frmImportProcess = new FrmDatabaseImportProcess(tableList, _db, _sgbdType, conn);
            frmImportProcess.ShowDialog(this);
            Cursor.Current = Cursors.Default;
        }
Ejemplo n.º 2
0
 public void GetMySqlData(DataImportTable table, ProgressBar pg, Label lbl)
 {
     using (MySqlConnection conn = new MySqlConnection(_conn.ConnectionString()))
     {
         MySqlCommand command = new MySqlCommand(getRequest(table), conn);
         command.CommandTimeout = 3600;
         conn.Open();
         MySqlDataReader dr = command.ExecuteReader();
         writeTableCsv(lbl, pg, table, dr);
         dr.Close();
         command.Dispose();
         conn.Close();
     }
     pbCsv.Invoke(new Action(() => { pbCsv.Value++; }));
 }
Ejemplo n.º 3
0
        private void writeTableCsv(Label lbl, ProgressBar pb, DataImportTable table, IDataReader dr)
        {
            lbl.Invoke(new Action(() => { lbl.Text = String.Format("Les données de la table {0} sont chargées... ", table.Name); }));
            pb.Invoke(new Action(() => { pb.Value = 0; }));
            pb.Invoke(new Action(() => { pb.Maximum = (int)table.Count; }));
            using (StreamWriter sw = new StreamWriter(_db.DataOrgaTablesPath + "\\" + table.Name + ".txt"))
            {
                StringBuilder sb = new StringBuilder(0, int.MaxValue);
                int columnCount = dr.FieldCount - 1;
                string sep = ",";

                while (dr.Read())
                {
                    if (sb.Length > 10000)
                    {
                        sw.Write(sb.ToString());
                        sb.Clear();
                    }

                    int i = 0;
                    while (i <= columnCount)
                    {
                        string str = dr[i].ToString();
                        if (
                            (table.Columns[i].DataType == "DATE1")
                            ||
                            (table.Columns[i].DataType == "DATE2")
                            ||
                            (table.Columns[i].DataType == "DATE3")
                            )
                        {
                            DateTime dt = DateTime.Parse(dr[i].ToString());
                            switch (table.Columns[i].DataType)
                            {
                                case "DATE1":
                                    str = dt.ToString("dd/MM/yyyy HH:mm:ss");
                                    break;
                                case "DATE2" :
                                    str = dt.ToString("dd/MM/yyyy");
                                    break;
                                case "DATE3":
                                    str = dt.ToString("dd/MM/yy");
                                    break;
                            }
                        }
                        str = str.Replace("\"", "\"\""); //on double les guillements pour les protéger
                        str = "\"" + str + "\""; //on encadre les champs par des guillemets

                        sb.Append(str);
                        if (i != columnCount)
                            sb.Append(sep);
                        i++;
                    }
                    sb.AppendLine();
                    pb.Invoke(new Action(() => { pb.Value++; }));
                }
                sw.Write(sb.ToString());
                sw.Flush();
            }
        }
Ejemplo n.º 4
0
 private string getRequest(DataImportTable table)
 {
     string request = "SELECT {0} FROM " + table.Name;
     string columnList = string.Empty;
     foreach (DataImportColumn column in table.Columns.OrderBy(v => v.Order))
     {
         if (columnList != string.Empty)
             columnList += ",";
         columnList += column.Name;
     }
     request = String.Format(request, columnList);
     return request;
 }