Beispiel #1
0
        public int InsertRow(OracleConnection connection, STRowAssistDataCsv item, out string msg)
        {
            int ret = 0;

            msg = null;
            try
            {
                string query = "INSERT INTO RCD.VALID_ASSISTDATA_CSV (SHIFTDATA, BILNUMBER, AMOUNT, AMOUNTWC, COMMISSION, FILENAME, ORDERNUMBER, ORDERDATE, TAGS, FILEDATE) " +
                               "values (:1, :2, :3, :4, :5, :6, :7, :8, :9, :10)";
                OracleCommand command = new OracleCommand(query, connection);

                command.Parameters.Add(crp(OracleType.DateTime, item.ltime, "1", false));
                command.Parameters.Add(crp(OracleType.Char, item.bilnumber, "2", false));
                command.Parameters.Add(crp(OracleType.Number, Math.Round(item.amount, 2), "3", false));
                command.Parameters.Add(crp(OracleType.Number, Math.Round(item.amount_wc, 2), "4", false));
                command.Parameters.Add(crp(OracleType.Number, Math.Round(item.commision, 2), "5", false));
                command.Parameters.Add(crp(OracleType.Char, item.filename, "6", false));
                command.Parameters.Add(crp(OracleType.Char, item.ordernumber, "7", false));
                command.Parameters.Add(crp(OracleType.DateTime, item.orderdate, "8", false));
                command.Parameters.Add(crp(OracleType.Char, item.tags, "9", false));
                command.Parameters.Add(crp(OracleType.DateTime, item.filedate, "10", false));
                command.ExecuteNonQuery();
            }
            catch (Exception ex) { msg = ex.Message; return(-1); }
            return(ret);
        }
Beispiel #2
0
        public int ReadFile(string filename, out List <STRowAssistDataCsv> container, out string msg)
        {
            int ret = 0;

            msg       = null;
            container = new List <STRowAssistDataCsv>();
            STRowAssistDataCsv item;
            int    i = 0;
            string text;

            try
            {
                string FilePath = Path.Combine(m_app.PathIN, filename);
                if (File.Exists(FilePath))
                {
                    DateTime c_date    = getfiledate(filename);
                    string[] arr_lines = File.ReadAllLines(FilePath);
                    // если файл пустой  - ошибка
                    if (arr_lines.Length <= 0)
                    {
                        msg = "Empty file."; return(1);
                    }

                    for (i = 1; i < arr_lines.Length; i++)
                    {
                        item = new STRowAssistDataCsv();

                        string[] words = arr_lines[i].Split(';');

                        item.filename = filename;
                        item.filedate = c_date;

                        int      day   = 0;
                        int      month = 0;
                        int      year  = 0;
                        DateTime dt;
                        //дата
                        if (words[0].Length == 6)
                        {
                            int.TryParse(words[0].Substring(0, 2), out day);
                            int.TryParse(words[0].Substring(2, 2), out month);
                            int.TryParse(words[0].Substring(4, 2), out year);
                        }
                        else if (words[0].Length == 5)
                        {
                            int.TryParse(words[0].Substring(0, 1), out day);
                            int.TryParse(words[0].Substring(1, 2), out month);
                            int.TryParse(words[0].Substring(3, 2), out year);
                        }
                        else
                        {
                            msg = string.Format("Not the correct date in a line {0}.\r\n", i + 1); continue;
                        }

                        dt         = new DateTime(2000 + year, month, day, 0, 0, 0, 0);
                        item.ltime = dt;

                        // bilnumber
                        item.bilnumber = words[1].Trim();

                        double.TryParse(words[2].Replace('.', ','), out item.amount);
                        double.TryParse(words[3].Replace('.', ','), out item.amount_wc);
                        double.TryParse(words[4].Replace('.', ','), out item.commision);

                        item.ordernumber = words[5].Trim();

                        DateTime.TryParse(words[7].Trim(), out item.orderdate);

                        if (!string.IsNullOrEmpty(words[6]))
                        {
                            item.tags += string.Format("<ORS={0}>", words[6]);
                        }
                        if (!string.IsNullOrEmpty(words[8]))
                        {
                            item.tags += string.Format("<CN={0}>", words[8]);
                        }
                        if (!string.IsNullOrEmpty(words[9]))
                        {
                            item.tags += string.Format("<CARD={0}>", words[9]);
                        }
                        if (!string.IsNullOrEmpty(words[10]))
                        {
                            item.tags += string.Format("<CH={0}>", words[10]);
                        }
                        if (!string.IsNullOrEmpty(words[11]))
                        {
                            item.tags += string.Format("<BC={0}>", words[11]);
                        }
                        if (!string.IsNullOrEmpty(words[12]))
                        {
                            item.tags += string.Format("<BANK={0}>", words[12]);
                        }
                        if (!string.IsNullOrEmpty(words[13]))
                        {
                            item.tags += string.Format("<RRN={0}>", words[13]);
                        }

                        container.Add(item);
                    }
                }
            }
            catch (Exception ex) { msg = ex.Message; return(-1); }
            return(ret);
        }
Beispiel #3
0
        private bool read_file(string FileName, out string msg)
        {
            msg = null;
            int i = 0;

            try
            {
                string FilePath = Path.Combine(inpath, FileName);


                data = new List <STRowAssistDataCsv>();
                STRowAssistDataCsv item;

                string[] arr_lines = File.ReadAllLines(FilePath);
                // если файл пустой  - ошибка
                if (arr_lines.Length <= 0)
                {
                    msg = "Empty file."; return(false);
                }

                for (i = 1; i < arr_lines.Length; i++)
                {
                    item = new STRowAssistDataCsv();

                    string[] words = arr_lines[i].Split(';');

                    item.filename = FileName;
                    item.filedate = c_date;

                    int      day   = 0;
                    int      month = 0;
                    int      year  = 0;
                    DateTime dt;
                    //дата
                    if (words[0].Length == 6)
                    {
                        int.TryParse(words[0].Substring(0, 2), out day);
                        int.TryParse(words[0].Substring(2, 2), out month);
                        int.TryParse(words[0].Substring(4, 2), out year);
                    }
                    else if (words[0].Length == 5)
                    {
                        int.TryParse(words[0].Substring(0, 1), out day);
                        int.TryParse(words[0].Substring(1, 2), out month);
                        int.TryParse(words[0].Substring(3, 2), out year);
                    }
                    else
                    {
                        msg = string.Format("Not the correct date in a line {0}.\r\n", i + 1); continue;
                    }

                    dt         = new DateTime(2000 + year, month, day, 0, 0, 0, 0);
                    item.ltime = dt;

                    // bilnumber
                    item.bilnumber = words[1].Trim();

                    double.TryParse(words[2].Replace('.', ','), out item.amount);
                    double.TryParse(words[3].Replace('.', ','), out item.amount_wc);
                    double.TryParse(words[4].Replace('.', ','), out item.commision);

                    item.ordernumber = words[5].Trim();

                    DateTime.TryParse(words[7].Trim(), out item.orderdate);

                    if (!string.IsNullOrEmpty(words[6]))
                    {
                        item.tags += string.Format("<ORS={0}>", words[6]);
                    }
                    if (!string.IsNullOrEmpty(words[8]))
                    {
                        item.tags += string.Format("<CN={0}>", words[8]);
                    }
                    if (!string.IsNullOrEmpty(words[9]))
                    {
                        item.tags += string.Format("<CARD={0}>", words[9]);
                    }
                    if (!string.IsNullOrEmpty(words[10]))
                    {
                        item.tags += string.Format("<CH={0}>", words[10]);
                    }
                    if (!string.IsNullOrEmpty(words[11]))
                    {
                        item.tags += string.Format("<BC={0}>", words[11]);
                    }
                    if (!string.IsNullOrEmpty(words[12]))
                    {
                        item.tags += string.Format("<BANK={0}>", words[12]);
                    }
                    if (!string.IsNullOrEmpty(words[13]))
                    {
                        item.tags += string.Format("<RRN={0}>", words[13]);
                    }

                    data.Add(item);
                }
            }
            catch (Exception ex)
            {
                msg += string.Format("Not the correct number of fields in a line {0}.", i + 1);
                msg  = ex.Message;
                log.LogLine("File wasn't read.");
                return(false);
            }


            return(true);
        }