コード例 #1
0
ファイル: StringHelper.cs プロジェクト: zh7262703/Emr_MySql
        public static string[] Split(string vStr, string[] separator, StringSplitOptions options)
        {
            return(vStr.Split(separator, options));

#if other
            return(StringSplit.Split(vStr, separator, options));
#endif
        }
コード例 #2
0
        public DataTable FromCsv(string strFilePath)
        {
            fileDelimiter = GetDelimiter(strFilePath);
            DataSet oDS = new DataSet();

            oDS.Tables.Add("Property");
            var oTable = oDS.Tables[0];

            using (var stream = new System.IO.FileStream(strFilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read))
            {
                var    oSR = UtilFunctions.CreateStreamReader(stream);
                string line;
                int    cellCount   = 0;
                var    stringSplit = new StringSplit(fileDelimiter);
                var    lineValues  = new List <string>(10);

                while ((line = oSR.ReadLine()) != null)
                {
                    stringSplit.Split(line, lineValues);

                    bool skipRow = false;
                    if (!hasHeaderColumnGenerated)
                    {
                        oTable.Columns.AddRange(GenerateColumnHeader(lineValues, out skipRow));
                    }

                    if (!skipRow)
                    {
                        int intCounter = 0;
                        var oRows      = oTable.NewRow();
                        var colCount   = Math.Min(oTable.Columns.Count, 20);
                        foreach (string str in lineValues)
                        {
                            if (intCounter < colCount)
                            {
                                oRows[intCounter] = str;
                                intCounter++;
                            }
                        }

                        if (cellCount < intCounter)
                        {
                            cellCount = intCounter;
                        }
                        oTable.Rows.Add(oRows);
                    }
                }

                //Removing if Extra Columns were created
                int colIndex = 20;
                while (cellCount < oTable.Columns.Count)
                {
                    oTable.Columns.RemoveAt(--colIndex);
                }
            }
            return(oTable);
        }
コード例 #3
0
        async public Task <List <GLDailyJournalLineClient> > CreateJournalLines(FileStream fileStream)
        {
            var reader = Uniconta.ClientTools.Util.UtilFunctions.CreateStreamReader(fileStream);

            var sp   = new StringSplit(';');
            var line = new List <string>();

            var rawLine = reader.ReadLine();

            sp.Split(rawLine, line);
            if (!await ValidateHeader(line))
            {
                return(null);
            }

            var year   = GetYearFromHeader(line);
            var AccLen = SetLimits(line);

            var vats = VATCache.GetRecords as GLVat[];

            // After header we have an empty line.
            reader.ReadLine();

            var _journalLines = new List <GLDailyJournalLineClient>(2000);

            for (;;)
            {
                rawLine = await reader.ReadLineAsync().ConfigureAwait(false);

                if (rawLine == null)
                {
                    break;
                }

                sp.Split(rawLine, line);

                var account       = testAccount(line[6], AccLen);
                var contraAccount = testAccount(line[7], AccLen);

                string vatcode = null;
                var    extcode = line[8];
                if (!string.IsNullOrEmpty(extcode))
                {
                    for (int i = 0; (i < vats.Length); i++)
                    {
                        var v = vats[i];
                        if (string.Compare(v._ExternalCode, extcode, true) == 0)
                        {
                            vatcode = v._Vat;
                            break;
                        }
                    }
                }

                var journalLine = GetJournalLine(line, year, account, contraAccount, vatcode);
                journalLine.SetMaster(GLDailyJournal);
                _journalLines.Add(journalLine);
            }
            reader.Dispose();

            return(_journalLines);
        }
コード例 #4
0
        public static DataTable FromCsv(string strFilePath)
        {
            try
            {
                fileDelimiter = GetDelimiter(strFilePath);
                DataSet oDS = new DataSet();
                oDS.Tables.Add("Property");
                var oTable = oDS.Tables[0];
                hasHeaderColumnGenerated = false;
                using (var stream = new System.IO.FileStream(strFilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read))
                {
                    var    oSR = UtilFunctions.CreateStreamReader(stream);
                    string line;
                    int    cellCount   = 0;
                    var    stringSplit = new StringSplit(fileDelimiter);
                    var    lineValues  = new List <string>(10);

                    while ((line = oSR.ReadLine()) != null)
                    {
                        stringSplit.Split(line, lineValues);

                        bool skipRow = false;
                        if (!hasHeaderColumnGenerated)
                        {
                            oTable.Columns.AddRange(GenerateColumnHeader(lineValues, out skipRow));
                        }

                        if (!skipRow)
                        {
                            int intCounter = 0;
                            var oRows      = oTable.NewRow();
                            var colCount   = oTable.Columns.Count;
                            foreach (string str in lineValues)
                            {
                                if (intCounter < colCount)
                                {
                                    oRows[intCounter] = str;
                                    intCounter++;
                                }
                            }

                            if (cellCount < intCounter)
                            {
                                cellCount = intCounter;
                            }
                            oTable.Rows.Add(oRows);
                        }
                    }

                    //Removing Columns not required
                    int           colIndex       = 0;
                    List <string> coltoBeRemoved = new List <string>();;
                    while (colIndex < oTable.Columns.Count)
                    {
                        var col = oTable.Columns[colIndex].ColumnName;
                        if (col != "Action" && col != "Item" &&
                            col != "EAN" && col != "AlternativeItem" &&
                            col != "Name" && col != "SupplierItemId" &&
                            col != "Supplier" && col != "Unit" &&
                            col != "SalesPrice" && col != "SalesPrice" &&
                            col != "ItemGroup" && col != "DiscountGroup" &&
                            col != "WebArg")
                        {
                            coltoBeRemoved.Add(oTable.Columns[colIndex].ColumnName);
                        }
                        colIndex++;
                    }
                    foreach (var col in coltoBeRemoved)
                    {
                        oTable.Columns.Remove(col);
                    }
                }
                return(oTable);
            }
            catch
            {
                return(null);
            }
        }
コード例 #5
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;
        }