Exemplo n.º 1
0
        /// <summary>
        /// Imports data from a csv file
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="separator"></param>
        public static void FromCsvStream(this C2dArray c2DArray, Stream stream, char separator = ',')
        {
            using var sr = new StreamReader(stream);

            // first line is the header
            c2DArray.Headers.Clear();
            var headerline = sr.ReadLine();

            if (string.IsNullOrEmpty(headerline))
            {
                return;
            }

            var array = headerline.Split(separator);

            for (var i = 0; i < array.Length; i++)
            {
                c2DArray.Headers.Add(array[i]);
                c2DArray.CompiledHeaders.Add(array[i]);
            }

            // read elements
            string line;
            var    cnt = 0;

            while ((line = sr.ReadLine()) != null)
            {
                // check if same columns as header
                var columns = line.Split(separator);
                if (columns.Length != c2DArray.Headers.Count)
                {
                    throw new SerializationException();
                }

                var row = new CArray <CString>();
                for (var i = 0; i < columns.Length; i++)
                {
                    row.Add(columns[i]);
                }

                c2DArray.Data.Add(row);
                c2DArray.CompiledData.Add(row);
                cnt++;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Parses whatever comes until the specified stop symbol is reached.
        /// </summary>
        void ParseObject(CSequence sequence, CSymbol stop)
        {
            CSymbol symbol;

            while ((symbol = ScanNextToken()) != CSymbol.Eof)
            {
                if (symbol == stop)
                {
                    return;
                }

                CString   s;
                COperator op;
                switch (symbol)
                {
                case CSymbol.Comment:
                    // ignore comments
                    break;

                case CSymbol.Integer:
                    CInteger n = new CInteger();
                    n.Value = _lexer.TokenToInteger;
                    _operands.Add(n);
                    break;

                case CSymbol.Real:
                    CReal r = new CReal();
                    r.Value = _lexer.TokenToReal;
                    _operands.Add(r);
                    break;

                case CSymbol.String:
                case CSymbol.HexString:
                case CSymbol.UnicodeString:
                case CSymbol.UnicodeHexString:
                    s       = new CString();
                    s.Value = _lexer.Token;
                    _operands.Add(s);
                    break;

                case CSymbol.Dictionary:
                    s             = new CString();
                    s.Value       = _lexer.Token;
                    s.CStringType = CStringType.Dictionary;
                    _operands.Add(s);
                    op = CreateOperator(OpCodeName.Dictionary);
                    //_operands.Clear();
                    sequence.Add(op);

                    break;

                case CSymbol.Name:
                    CName name = new CName();
                    name.Name = _lexer.Token;
                    _operands.Add(name);
                    break;

                case CSymbol.Operator:
                    op = CreateOperator();
                    //_operands.Clear();
                    sequence.Add(op);
                    break;

                case CSymbol.BeginArray:
                    CArray array = new CArray();
                    if (_operands.Count != 0)
                    {
                        ContentReaderDiagnostics.ThrowContentReaderException("Array within array...");
                    }

                    ParseObject(array, CSymbol.EndArray);
                    array.Add(_operands);
                    _operands.Clear();
                    _operands.Add((CObject)array);
                    break;

                case CSymbol.EndArray:
                    ContentReaderDiagnostics.HandleUnexpectedCharacter(']');
                    break;

#if DEBUG
                default:
                    Debug.Assert(false);
                    break;
#endif
                }
            }
        }
Exemplo n.º 3
0
    }    //FOLD00

    //  Процедура построения выписки//FOLD00
    public bool    Build()
    {
        bool Result    = false;
        long OldRootId = 0;

        OldBranchId       = -1;
        OldUserId         = -1;
        FileName1         = "";
        FileName2         = "";
        NeedNewFileCreate = true;
        Accounts          = new   CRecordSet(Conn1);
        if (Accounts.Open(GetCmdText(1)))
        {
            if (Accounts.Read())
            {
                CArray AccountList = new   CArray();
                do
                {
                    MapAccountFields();
                    AccountList.Add(
                        __.Left(Accounts_Code, 32)
                        + __.Left(Accounts_Tag, 8)
                        + __.Left(Accounts_Id.ToString().Trim(), 20)
                        + __.Left(Accounts_ExtId.ToString().Trim(), 20)
                        + __.Left(Accounts_RootId.ToString().Trim(), 20)
                        + __.Left(Accounts_UserId.ToString().Trim(), 20)
                        + __.Left(Accounts_BranchId.ToString().Trim(), 20)
                        + Accounts_Path
                        );
                } while (Accounts.Read());
                Accounts.Close();
                BankInfo = new   CRecordSet(Conn1);
                if (BankInfo.Open(" select Code,Name,MainCrncyTag from dbo.vMega_Common_MyBankInfo "))
                {
                    if (BankInfo.Read())
                    {
                        BankCode     = BankInfo["Code"].Trim();
                        BankName     = __.FixUkrI(BankInfo["Name"]);
                        MainCrncyTag = BankInfo["MainCrncyTag"].Trim();
                    }
                }
                BankInfo.Close();
                BankInfo  = null;
                Amounts   = new   CRecordSet(Conn1);
                Transfers = new   CRecordSet(Conn2);
                foreach (string Account in AccountList)
                {
                    Accounts_Code     = Account.Substring(0, 32).Trim();
                    Accounts_Tag      = Account.Substring(32, 8).Trim();
                    Accounts_Id       = __.CLng(Account.Substring(40, 20).Trim());
                    Accounts_ExtId    = __.CLng(Account.Substring(60, 20).Trim());
                    Accounts_RootId   = __.CLng(Account.Substring(80, 20).Trim());
                    Accounts_UserId   = __.CLng(Account.Substring(100, 20).Trim());
                    Accounts_BranchId = __.CLng(Account.Substring(120, 20).Trim());
                    Accounts_Path     = Account.Substring(140);
                    OpenOutputStreams();
                    if (Accounts_RootId == 0)
                    {
                        PrintAccount();
                    }
                    if ((Accounts_RootId != 0) &&
                        (Accounts_RootId != OldRootId)
                        )
                    {
                        OldRootId = Accounts_RootId;
                        PrintAccount();
                    }
                }
                ;
                AccountList.Clear();
                AccountList = null;
                CloseOutputStreams();
                Transfers.Close();
                Amounts.Close();
                Result = true;
            }
            else
            {
                Accounts.Close();
            }
        }
        else
        {
            Accounts.Close();
        }
        Transfers = null;
        Accounts  = null;
        Amounts   = null;
        return(Result);
    }                            //FOLD00
Exemplo n.º 4
0
        /// <summary>
        /// Parses whatever comes until the specified stop symbol is reached.
        /// </summary>
        void ParseObject(CSequence sequence, CSymbol stop)
        {
            CSymbol symbol;

            while ((symbol = ScanNextToken()) != CSymbol.Eof)
            {
                if (symbol == stop)
                {
                    return;
                }

                switch (symbol)
                {
                case CSymbol.Comment:
                    // ignore comments
                    break;

                case CSymbol.Integer:
                    CInteger n = new CInteger();
                    n.Value = lexer.TokenToInteger;
                    operands.Add(n);
                    break;

                case CSymbol.Real:
                    CReal r = new CReal();
                    r.Value = lexer.TokenToReal;
                    operands.Add(r);
                    break;

                case CSymbol.String:
                case CSymbol.HexString:
                case CSymbol.UnicodeString:
                case CSymbol.UnicodeHexString:
                    CString s = new CString();
                    s.Value = lexer.Token;
                    operands.Add(s);
                    break;

                case CSymbol.Name:
                    CName name = new CName();
                    name.Name = lexer.Token;
                    operands.Add(name);
                    break;

                case CSymbol.Operator:
                    COperator op = CreateOperator();
                    operands.Clear();
                    sequence.Add(op);
                    break;

                case CSymbol.BeginArray:
                    CArray array = new CArray();
                    Debug.Assert(operands.Count == 0, "Array within array...");
                    ParseObject(array, CSymbol.EndArray);
                    array.Add(operands);
                    operands.Clear();
                    operands.Add((CObject)array);
                    break;

                case CSymbol.EndArray:
                    throw new ContentReaderException("Unexpected: ']'");
                }
            }
        }
Exemplo n.º 5
0
 internal void Sync(Action callback, bool persistent)
 => _callbacks.Add(new CAction(callback, persistent));
Exemplo n.º 6
0
    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    //	Запуск  списка регламентных процедур на Sql-сервере
    static bool    StartSqlRoutine(string CmdText)
    {
        CConnection Connection2;
        bool        Result = true;

        if (CmdText == null)
        {
            return(false);
        }
        if (CmdText.Trim() == "")
        {
            return(false);
        }
        CArray CommandList = new   CArray();
        CArray NamesList   = new   CArray();

        CConsole.ShowBox("", "Выполнение команды на сервере", "");
        Connection = new   CConnection(ConnectionString);
        RecordSet  = new   CRecordSet(Connection);
        if (RecordSet.Open(CmdText))
        {
            while (RecordSet.Read())
            {
                NamesList.Add(RecordSet["Name"]);
                CommandList.Add(RecordSet["Command"]);
            }
        }
        else
        {
            Result = false;
        }
        CConsole.Clear();
        RecordSet.Close();
        string Cmd       = CAbc.EMPTY
        , Msg            = CAbc.EMPTY
        , Results        = CAbc.EMPTY;
        CCommand Command = new   CCommand(Connection);

        for (int I = 0; I < NamesList.Count; I++)
        {
            CCommon.Print(NamesList[I] + " - выполняется.");
            CConsole.ShowBox("", "Выполнение команды на сервере", "");
            Cmd     = DateSubstitution((string)CommandList[I]);
            CmdText = " exec  dbo.Mega_Common_WriteToLoginfo "
                      + " @TaskCode='Mega_Day_Routine-" + Mode.ToString().Trim() + "'"
                      + ",@Info='start : " + Cmd + "'";
            Command.Execute(CmdText);
            Connection2       = new   CConnection(ConnectionString);
            RecordSet         = new   CRecordSet(Connection2);
            RecordSet.Timeout = 599;
            if (RecordSet.Open(Cmd))
            {
                Msg = (string)NamesList[I];
                int Count = 0;
                if (RecordSet.Read())
                {
                    do
                    {
                        Count++;
                    }while   (RecordSet.Read());
                }
                Msg = NamesList[I] + " - OK."
                      + ((Count > 0) ? " ( " + Count.ToString() + " row(s) affected )" : "");
            }
            else
            {
                Result = false;
                Msg    = NamesList[I] + " - Ошибка !";
            }
            RecordSet.Close();
            Connection2.Close();
            CmdText = " exec  dbo.Mega_Common_WriteToLoginfo "
                      + " @TaskCode='Mega_Day_Routine-" + Mode.ToString().Trim() + "'"
                      + ",@Info='stop  : " + Cmd + "'";
            Command.Execute(CmdText);
            CmdText = " exec  dbo.Mega_Common_WriteToLoginfo "
                      + " @TaskCode='Mega_Day_Routine-" + Mode.ToString().Trim() + "'"
                      + ",@Info='" + Msg.Replace("'", "`") + "'";
            Command.Execute(CmdText);
            Err.Print(CAbc.TAB + CAbc.TAB + Msg + CAbc.CRLF);
            CConsole.Clear();
            Results += Msg + CAbc.CRLF;
            CCommon.Write(Results);
        }
        Connection.Close();
        CCommon.Print(CAbc.EMPTY, CAbc.EMPTY, "Готово. Для продолжения нажмите Enter.");
        CConsole.ClearKeyboard();
        CConsole.Flash();
        CConsole.ReadChar();
        return(Result);
    }
Exemplo n.º 7
0
    // - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    //	Вычитка списка пунктов открытия/закрытия дня
    static bool    LoadHistory(int Mode)
    {
        int MenuItemWidth = (Mode == 1) ? 32 : 25;

        Connection = new CConnection(ConnectionString);
        RecordSet  = new   CRecordSet(Connection);
        bool Result = false;

        if (RecordSet.Open("exec Mega_Day_Close;10  @DayDate=" + DayDate.ToString() + " , @Mode= " + Mode.ToString()))
        {
            while (RecordSet.Read())
            {
                if (CCommon.CInt(RecordSet["Cnt"]) == 0)
                {
                    MNames.Add(CCommon.Left(RecordSet["Name"], MenuItemWidth) + "*");
                }
                else
                {
                    MNames.Add(CCommon.Left(RecordSet["Name"], MenuItemWidth) + "* " + RecordSet["Cnt"].Trim());
                }
                MCommands.Add(RecordSet["Command"]);
                MParams.Add(RecordSet["Params"]);
                MKinds.Add(RecordSet["Kind"]);
                Result = true;
            }
        }
        else
        {
            Result = false;
        }
        RecordSet.Close();
        int MenuCount = MNames.Count;

        MenuNames    = new   string[MenuCount];
        MenuKinds    = new   string[MenuCount];
        MenuParams   = new   string[MenuCount];
        MenuCommands = new   string[MenuCount];
        MenuCount    = 0;
        foreach (string MenuName in MNames)
        {
            MenuNames[MenuCount++] = MenuName;
        }
        MenuCount = 0;
        foreach (string MenuKind in MKinds)
        {
            MenuKinds[MenuCount++] = MenuKind;
        }
        MenuCount = 0;
        foreach (string MenuParam in MParams)
        {
            MenuParams[MenuCount++] = MenuParam;
        }
        MenuCount = 0;
        foreach (string MenuCommand in MCommands)
        {
            MenuCommands[MenuCount++] = MenuCommand;
        }
        MCommands.Clear();
        MParams.Clear();
        MKinds.Clear();
        MNames.Clear();
        Connection.Close();
        return(Result);
    }