Exemple #1
0
        private IEnumerable <CustomDataColumn> CreateCustomDataColumn(DataTable dataTable, bool setType)
        {
            if (dataTable == null || dataTable.Columns.Count == 0)
            {
                return(null);
            }

            var dataColumnList = new List <CustomDataColumn>();
            int index          = 1;

            foreach (DataColumn dtCol in dataTable.Columns)
            {
                CustomDataColumn customDtCol;
                if (setType)
                {
                    customDtCol = new CustomDataColumn(dtCol.ColumnName, dtCol.DataType, index);
                }
                else
                {
                    customDtCol = new CustomDataColumn(dtCol.ColumnName, index);
                }

                index++;
                dataColumnList.Add(customDtCol);
            }

            return(dataColumnList);
        }
Exemple #2
0
        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            if (customDataColumnSource == null || customDataColumnSource.Count == 0 || bankImportFormat == null)
            {
                DialogResult = true;
                return;
            }
            var bankformatPositionProps = UtilFunctions.GetDisplayAttributeNonReadOnlyPropertiesFromType(bankImportFormat.GetType(), true);

            var strSplit = new StringSplit('(');

            foreach (var propInfo in bankformatPositionProps)
            {
                if (propInfo.PropertyType == typeof(byte))
                {
                    var propName = propInfo.Name;

                    if (propName == "SkipLines")
                    {
                        continue;
                    }

                    CustomDataColumn selectedCustomCol = null;
                    foreach (var col in customDataColumnSource)
                    {
                        if (col.ActualDataColumnName != null && col.ActualDataColumnName.Contains(propName))
                        {
                            selectedCustomCol = col;
                            break;
                        }
                    }

                    if (selectedCustomCol != null)
                    {
                        var selectedItem = selectedCustomCol.ActualDataColumnName;
                        var propertyName = strSplit.Split(selectedItem).First();

                        var prop = bankImportFormat.GetType().GetProperty(propertyName);
                        if (prop != null)
                        {
                            prop.SetValue(bankImportFormat, (byte)selectedCustomCol.DataColumnIndex, null);
                        }
                    }
                    else
                    {
                        propInfo.SetValue(bankImportFormat, (byte)0, null); // reset the value
                    }
                }
            }

            //Setting the delimiter value from the file to the bankformat
            if (updateDelimiter)
            {
                var seperatorProp = bankImportFormat.GetType().GetProperty("Seperator");
                if (seperatorProp != null)
                {
                    var sepValue = (char)seperatorProp.GetValue(bankImportFormat);
                    if (sepValue.CompareTo(fileDelimiter) != 0)
                    {
                        seperatorProp.SetValue(bankImportFormat, fileDelimiter, null);
                    }
                }
            }

            DialogResult = true;
        }