Esempio n. 1
0
        public DataTable BindGrid()
        {
            string    fileName = this.selectDialog.Text;
            DataTable dt       = new DataTable();

            if (!string.IsNullOrEmpty(fileName))
            {
                string   ext           = Path.GetExtension(fileName).ToLower();
                FileType fileType      = FileHelper.GetFileType(ext);
                bool     isFirstColumn = true;
                string[] columns       = new string[] { "联系人", "号码", "号码类型" };
                this.grid1.AutoGenerateColumns = true;
                this.grid1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
                this.grid1.ReadOnly            = true;
                this.grid1.DataSource          = null;
                if (fileType == FileType.Txt)
                {
                    dt = TxtHelper.ParseDataTable(fileName, columns, isFirstColumn);
                }
                else if (fileType == FileType.Excel)
                {
                    ITransferData t = TransferDataFactory.GetTransferData(fileName);
                    dt = t.GetData(fileName, columns, isFirstColumn);
                }
                else
                {
                    dt = TxtHelper.ToDataTable(AddressBook.Parse(fileName), columns, isFirstColumn);
                }
                this.grid1.DataSource = dt;
            }
            return(dt);
        }
Esempio n. 2
0
 public System.Data.DataTable GetData(string fileName, string[] columnNames = null, bool isFirstColumn = false)
 {
     return(TxtHelper.ParseDataTable(fileName, columnNames, isFirstColumn));
 }