Exemplo n.º 1
0
        public ColumnWindow(FileSetting setting)
        {
            InitializeComponent();
            Settings = setting;
            var items = Helper.GetEncodingList();

            comboBoxEncoding.ItemsSource = items;
            if (Settings != null)
            {
                comboBoxEncoding.SelectedValue = items.FirstOrDefault(x => x.ID == Settings.FileEncoding).ID;
                var row = Settings.GetRow();
                if (row != null)
                {
                    Columns = row.Select(x => new ColumnSetting()
                    {
                        Column = x,
                        Export = true,
                        Key    = false
                    }).ToArray();
                    bool excelIndex = checkBoxExcelIndex.IsChecked == true;
                    for (int i = 0; i < Columns.Length; i++)
                    {
                        Columns[i].Index       = i;
                        Columns[i].ColumnIndex = (excelIndex) ? Helper.GetExcelColumnName(i + 1).PadRight(5) : (i + 1).ToString().PadRight(5);
                        if (Settings.Output != null && Settings.Output.Any())
                        {
                            if (Settings.KeyColumn.SourceNumber == i)
                            {
                                Columns[i].Key = true;
                            }
                            var col = Settings.Output.FirstOrDefault(x => x.SourceNumber == i);
                            Columns[i].Export     = col != null;
                            Columns[i].ColumnName = col?.Name;
                            Columns[i].EmptyTest  = col?.IsEmptyTest == true;
                        }
                    }
                    if (Columns != null && Columns.Any() && !Columns.Any(x => x.Key))
                    {
                        Columns[0].Key = true;
                    }
                }
            }
            CheckSelectAll();
            RefreshGrid();
        }
Exemplo n.º 2
0
        private void ReadFirstRow(bool force = false)
        {
            if (FileSetting != null)
            {
                try
                {
                    if (force || ColumnNames == null || !ColumnNames.Any())
                    {
                        if (force || ColumnNames == null)
                        {
                            ColumnNames = new List <string>();
                        }

                        var row = FileSetting.GetRow();
                        if (row != null && row.Any())
                        {
                            ColumnNames.AddRange(row);
                        }
                    }
                }
                catch (IOException ex)
                {
                    var owner = (MainWindow)Owner;
                    owner.ShowException(ex, (String.Format("Could not read file: {0}. Check if is is not open by another program or deleted.", FileSetting.Source + "/" + FileSetting.FileName)));
                }
                finally
                {
                    comboBoxKeyColumn.Items.Clear();
                    comboBoxColumn.Items.Clear();
                    if (ColumnNames != null && ColumnNames.Any())
                    {
                        bool excelIndex = checkBoxExcelIndex.IsChecked == true;
                        for (int i = 0; i < ColumnNames.Count; i++)
                        {
                            string columnIndex = (excelIndex) ? Helper.GetExcelColumnName(i + 1).PadRight(5) : (i + 1).ToString().PadRight(5);
                            string columnName  = (!string.IsNullOrEmpty(ColumnNames[i])) ? ColumnNames[i] : "NO NAME";
                            comboBoxKeyColumn.Items.Add(string.Format("{0} - {1}", columnIndex, ColumnNames[i]));
                            comboBoxColumn.Items.Add(string.Format("{0} - {1}", columnIndex, ColumnNames[i]));
                        }
                    }
                    comboBoxKeyColumn.SelectedIndex = FileSetting.KeyColumn.SourceNumber;
                }
            }
        }