コード例 #1
0
ファイル: CFormOptionsCSV2.cs プロジェクト: ykebaili/sc2idlls
        private void ValideColonneEnCours()
        {
            CParametreLectureCSV.CColonneCSV col = m_parametre.GetColonne(m_nColSel);
            if (m_cmbType.SelectedValue != null)
            {
                col.DataType = (Type)m_cmbType.SelectedValue;
            }

            //Nom Colonne
            string strNom = m_txtNomColonne.Text.Trim() != "" ? m_txtNomColonne.Text.Trim() : GetNomColonneDefaut(m_nColSel);

            if (!m_parametre.ValideNomPourColonne(m_nColSel, strNom))
            {
                CFormAlerte.Afficher(I.T("This name already exists|125"), EFormAlerteType.Exclamation);
            }
            else
            {
                col.Nom = strNom;
            }

            //Null Colonne
            col.HasNullMapping = m_chkMapperNull.Checked;
            if (m_chkMapperNull.Checked)
            {
                col.NullMapping       = m_txtNullValue.Text;
                col.NullCaseSensitive = m_chkNullCaseSensitive.Checked;
            }

            //Set Colonne
            m_parametre.SetColonne(m_nColSel, col);
            m_wndListeExemple.Columns[m_nColSel].Text = col.Nom;
        }
コード例 #2
0
ファイル: CFormOptionsCSV2.cs プロジェクト: ykebaili/sc2idlls
        private void SelectColonne(int nCol)
        {
            if (m_bInitialise)
            {
                ValideColonneEnCours();
            }
            m_nColSel = nCol;
            CParametreLectureCSV.CColonneCSV col = m_parametre.GetColonne(nCol);
            m_grpColonne.Text = I.T("Column n°@1|126", (nCol + 1).ToString());

            m_txtNomColonne.Text = col.Nom;
            if (col.DataType == null)
            {
                m_cmbType.SelectedValue = typeof(string);
            }
            else
            {
                m_cmbType.SelectedValue = col.DataType;
            }

            m_chkMapperNull.Checked = col.HasNullMapping;
            if (col.HasNullMapping)
            {
                m_txtNullValue.Text            = col.NullMapping;
                m_chkNullCaseSensitive.Checked = col.NullCaseSensitive;
            }
            else
            {
                m_txtNullValue.Text            = "";
                m_chkNullCaseSensitive.Checked = false;
            }

            m_panNull.Visible = m_chkMapperNull.Checked;
        }
コード例 #3
0
ファイル: CFormOptionsCSV2.cs プロジェクト: ykebaili/sc2idlls
        public static DialogResult FillOptions(CParametreLectureCSV parametre, string strFichierExemple)
        {
            CFormOptionsCSV2 form = new CFormOptionsCSV2();

            form.m_parametre = parametre;
            string strTexteExemple = "";

            if (strFichierExemple != "")
            {
                StreamReader reader = null;
                try
                {
                    reader = new StreamReader(strFichierExemple, new CEncoding(parametre.Encodage).GetEncoding());
                    int nLigne = 0;
                    //string strLigne = reader.ReadLine();
                    string strLigne = parametre.GetCSVLine(reader);
                    form.m_tableExemple = new DataTable();
                    form.m_nomsCol      = new Dictionary <int, string>();
                    //CREATION DES COLONNES
                    if (parametre.NomChampsSurPremiereLigne)
                    {
                        string[] strChamps = strLigne.Split(parametre.Separateur);
                        int      nChamp    = 0;
                        foreach (string strChamp in strChamps)
                        {
                            string strVal = strChamp;
                            if (strVal.Trim() == "")
                            {
                                strVal = form.GetNomColonneDefaut(nChamp);
                            }
                            nChamp++;
                            int    nCpt        = 0;
                            string strChampTmp = strVal;
                            while (form.m_tableExemple.Columns.Contains(strChampTmp))
                            {
                                strChampTmp = strChamp + nCpt.ToString();
                                nCpt++;
                            }
                            form.m_tableExemple.Columns.Add(strChampTmp, typeof(string));
                            form.m_nomsCol.Add(nChamp, strChampTmp);
                        }
                        //strLigne = reader.ReadLine();
                        strLigne = parametre.GetCSVLine(reader);
                    }
                    else
                    {
                        string[] strCols = parametre.GetDatas(strLigne);
                        for (int nCol = 0; nCol < strCols.Length; nCol++)
                        {
                            string strChamp = "";
                            if (parametre.Mappage != null &&
                                parametre.Mappage.StringsA != null &&
                                parametre.Mappage.StringsA.Count >= strCols.Length)
                            {
                                strChamp = parametre.Mappage.StringsA[nCol];
                            }
                            else
                            {
                                form.GetNomColonneDefaut(nCol);
                            }

                            int    nCpt        = 0;
                            string strChampTmp = strChamp;
                            while (form.m_tableExemple.Columns.Contains(strChampTmp))
                            {
                                strChampTmp = strChamp + nCpt.ToString();
                                nCpt++;
                            }
                            form.m_tableExemple.Columns.Add(strChampTmp, typeof(string));
                            form.m_nomsCol.Add(nCol, strChampTmp);
                        }
                    }

                    //LECTURE DU FICHIER
                    while (strLigne != null && nLigne++ < 100)
                    {
                        string[] strDatas = parametre.GetDatas(strLigne);
                        int      nCol     = 0;
                        DataRow  row      = form.m_tableExemple.NewRow();
                        foreach (string strData in strDatas)
                        {
                            if (nCol < form.m_tableExemple.Columns.Count)
                            {
                                row[nCol] = strData;
                            }
                            nCol++;
                        }
                        form.m_tableExemple.Rows.Add(row);
                        //strLigne = reader.ReadLine();
                        strLigne = parametre.GetCSVLine(reader);
                    }


                    //CREATION DU LISTVIEW
                    form.m_wndListeExemple.Columns.Clear();
                    foreach (DataColumn col in form.m_tableExemple.Columns)
                    {
                        ColumnHeader header = new ColumnHeader();
                        header.Text = col.ColumnName;
                        form.m_wndListeExemple.Columns.Add(header);
                    }
                    foreach (DataRow row in form.m_tableExemple.Rows)
                    {
                        ListViewItem item = new ListViewItem(row[0].ToString());
                        for (int n = 1; n < form.m_tableExemple.Columns.Count; n++)
                        {
                            item.SubItems.Add(row[n].ToString());
                        }
                        form.m_wndListeExemple.Items.Add(item);
                    }


                    //CREATION DES COLONNES CSV DANS FICHIER PARAMETRAGE
                    for (int nCol = 0; nCol < form.m_tableExemple.Columns.Count; nCol++)
                    {
                        CParametreLectureCSV.CColonneCSV col = form.m_parametre.GetColonne(nCol);
                        if (col == null || col.Nom != form.m_tableExemple.Columns[nCol].ColumnName)
                        {
                            col          = new CParametreLectureCSV.CColonneCSV();
                            col.Nom      = form.m_tableExemple.Columns[nCol].ColumnName;
                            col.DataType = typeof(string);
                            form.m_parametre.SetColonne(nCol, col);
                        }
                    }


                    reader.Close();

                    form.m_strTexteExemple = strTexteExemple;
                    DialogResult result = form.ShowDialog();
                    form.Dispose();
                    return(result);
                }
                catch
                {
                }
                finally
                {
                    try
                    {
                        reader.Close();
                    }

                    catch
                    {
                    }
                }
            }
            return(DialogResult.Abort);
        }