Example #1
0
    protected void OnBtnNewDbClicked(object sender, EventArgs e)
    {
        //**********************************************************************

        //***Path do banco de dados***//
        String path       = System.IO.Directory.GetCurrentDirectory() + "/";
        String dbName     = "sigomDb.db";
        String dbPathFile = path + dbName;
        DbLite dbl        = new DbLite();

        dbl.showMessage(dbPathFile);
        //***Criando o banco de dados***//
        //dbl.dbCreate(dbPathFile);

        //***criando a tabela de login***//
        //string createTable = @"CREATE TABLE Login (ID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,Nome VARCHAR(100) NOT NULL,Senha VARCHAR (10) NOT NULL )";
        //dbl.dbSetCommand(dbPathFile, createTable);


        //***Inserir o administrador do login***//
        //String Nome = "admin";
        //String Senha = "123456";
        //String insertCommand = "INSERT INTO Login (Nome, Senha)"+
        //    "VALUES('"+Nome+"','"+Senha+"')";
        //dbl.dbSetCommand(dbPathFile, insertCommand);
    }
Example #2
0
        /// <summary>
        ///    Adds a key/value pair to the System.Collections.Concurrent.ConcurrentDictionary<TKey,TValue>
        ///     if the key does not already exist, or updates a key/value pair in the System.Collections.Concurrent.ConcurrentDictionary<TKey,TValue>
        ///     if the key already exists.
        /// </summary>
        /// <param name="key">The key to be added or whose value should be updated</param>
        /// <param name="value">The value to be added or updated for an absent key</param>
        /// <returns></returns>
        public override int AddOrUpdate(string key, IPersistItem value)
        {
            int res = 0;

            //dictionary.AddOrUpdate(key, value, (oldkey, oldValue) =>
            //{
            //    isExists = true;
            //    return value;
            //});

            bool iscommited = false;

            try
            {
                switch (_CommitMode)
                {
                case CommitMode.OnDisk:
                    using (var db = new DbLite(ConnectionString, DBProvider.SQLite))
                    {
                        var cmdText = DbUpsertCommand();
                        res = db.ExecuteTransCommandNonQuery(cmdText, DataParameter.Get <SQLiteParameter>("Identifier", value.Identifier, "Body", value.ItemBinary, "Header", value.Header, "Retry", value.Retry, "ArrivedTime", value.ArrivedTime, "Expiration", value.Duration, "MessageState", (byte)value.MessageState), (result, trans) =>
                        {
                            if (result > 0)
                            {
                                dictionary[key] = value;
                                trans.Commit();
                                iscommited = true;
                            }
                        });
                    }
                    break;

                default:
                    dictionary.AddOrUpdate(key, value, (oldkey, oldValue) =>
                    {
                        return(value);
                    });
                    if (_CommitMode == CommitMode.OnMemory)
                    {
                        var cmdText = DbUpsertCommand();
                        res = ExecuteAsync(cmdText, DataParameter.Get <SQLiteParameter>("Identifier", value.Identifier, "Body", value.ItemBinary, "Header", value.Header, "Retry", value.Retry, "ArrivedTime", value.ArrivedTime, "Expiration", value.Duration, "MessageState", (byte)value.MessageState));
                    }
                    res        = 1;
                    iscommited = true;
                    break;
                }

                if (iscommited)
                {
                    OnItemChanged("AddOrUpdate", null, null);
                }
            }
            catch (Exception ex)
            {
                OnErrorOcurred("AddOrUpdate", ex.Message);
            }

            return(res);
        }
Example #3
0
        public static void Main(string[] args)
        {
            DbLite  db             = new DbLite(new DBConfig("test"));
            Message messageByCarsN = db.GetMessageByCarsN(args[0])[0];

//            messageByCarsN.Status = Status.Saved;
//            db.UpdateMessage(messageByCarsN);
            Console.WriteLine(messageByCarsN);
        }
Example #4
0
        /// <summary>
        /// Summary:
        ///     Attempts to remove and return the value with the specified key from the System.Collections.Concurrent.ConcurrentDictionary<TKey,TValue>.
        ///
        /// Parameters:
        ///   key:
        ///     The key of the element to remove and return.
        ///
        ///   value:
        ///     When this method returns, value contains the object removed from the System.Collections.Concurrent.ConcurrentDictionary<TKey,TValue>
        ///     or the default value of if the operation failed.
        ///
        /// Returns:
        ///     true if an object was removed successfully; otherwise, false.
        ///
        /// Exceptions:
        ///   System.ArgumentNullException:
        ///     key is a null reference (Nothing in Visual Basic).
        /// </summary>
        public override bool TryRemove(string key, out IPersistItem value)
        {
            bool         iscommited = false;
            IPersistItem outval     = value = null;

            try
            {
                switch (_CommitMode)
                {
                case CommitMode.OnDisk:
                    using (var db = new DbLite(ConnectionString, DBProvider.SQLite))
                    {
                        var cmdText = DbDeleteCommand();
                        db.ExecuteTransCommandNonQuery(cmdText, DataParameter.Get <SQLiteParameter>("Identifier", value.Identifier), (result, trans) =>
                        {
                            if (result > 0)
                            {
                                if (dictionary.TryRemove(key, out outval))
                                {
                                    trans.Commit();
                                    iscommited = true;
                                }
                            }
                        });
                    }
                    break;

                default:
                    if (dictionary.TryRemove(key, out outval))
                    {
                        if (_CommitMode == CommitMode.OnMemory)
                        {
                            var cmdText = DbDeleteCommand();
                            var res     = ExecuteAsync(cmdText, DataParameter.Get <SQLiteParameter>("Identifier", value.Identifier));
                        }
                        iscommited = true;
                    }
                    break;
                }

                value = outval;

                if (iscommited)
                {
                    OnItemChanged("TryRemove", key, value);
                }
            }
            catch (Exception ex)
            {
                OnErrorOcurred("TryRemove", ex.Message);
            }
            return(iscommited);
        }
Example #5
0
        /// <summary>
        /// Summary:
        ///     Compares the existing value for the specified key with a specified value,
        ///     and if they are equal, updates the key with a third value.
        ///
        /// Parameters:
        ///   key:
        ///     The key whose value is compared with comparisonValue and possibly replaced.
        ///
        ///   newValue:
        ///     The value that replaces the value of the element with key if the comparison
        ///     results in equality.
        ///
        ///   comparisonValue:
        ///     The value that is compared to the value of the element with key.
        ///
        /// Returns:
        ///     true if the value with key was equal to comparisonValue and replaced with
        ///     newValue; otherwise, false.
        ///
        /// Exceptions:
        ///   System.ArgumentNullException:
        ///     key is a null reference.
        /// </summary>
        public override bool TryUpdate(string key, IPersistItem newValue, IPersistItem comparisonValue)
        {
            bool iscommited = false;

            try
            {
                switch (_CommitMode)
                {
                case CommitMode.OnDisk:
                    using (var db = new DbLite(ConnectionString, DBProvider.SQLite))
                    {
                        var cmdText = DbUpdateCommand();
                        db.ExecuteTransCommandNonQuery(cmdText, DataParameter.Get <SQLiteParameter>("Identifier", newValue.Identifier, "Body", newValue.ItemBinary, "Header", newValue.Header, "Retry", newValue.Retry, "ArrivedTime", newValue.ArrivedTime, "Expiration", newValue.Duration, "MessageState", newValue.MessageState), (result, trans) =>
                        {
                            if (result > 0)
                            {
                                if (dictionary.TryUpdate(key, newValue, comparisonValue))
                                {
                                    trans.Commit();
                                    iscommited = true;
                                }
                            }
                        });
                    }
                    break;

                default:

                    if (dictionary.TryUpdate(key, newValue, comparisonValue))
                    {
                        if (_CommitMode == CommitMode.OnMemory)
                        {
                            var cmdText = DbUpdateCommand();
                            var res     = ExecuteAsync(cmdText, DataParameter.Get <SQLiteParameter>("Identifier", newValue.Identifier, "Body", newValue.ItemBinary, "Header", newValue.Header, "Retry", newValue.Retry, "ArrivedTime", newValue.ArrivedTime, "Expiration", newValue.Duration, "MessageState", newValue.MessageState));
                        }
                        iscommited = true;
                    }
                    break;
                }

                if (iscommited)
                {
                    OnItemChanged("TryUpdate", key, newValue);
                }
            }
            catch (Exception ex)
            {
                string err = ex.Message;
                OnErrorOcurred("TryUpdate", ex.Message);
            }
            return(iscommited);
        }
Example #6
0
    protected void OnBtnOsAbertasClicked(object sender, EventArgs e)
    {
        String        path       = System.IO.Directory.GetCurrentDirectory() + "/";
        String        dbName     = "sigomDb.db";
        String        dbPathFile = path + dbName;
        DbLite        dbl        = new DbLite();
        List <String> getData    = new List <String>();

        String tableName = "OrdemServico";

        getData = dbl.dbGetCommand(dbPathFile, tableName, "numOs", "Status", "ABERTO");

        sigom.fifoService fs = new fifoService(getData);
    }
Example #7
0
    protected void OnBtnLoginClicked(object sender, EventArgs e)
    {
        String path       = System.IO.Directory.GetCurrentDirectory() + "/";
        String dbName     = "sigomDb.db";
        String dbPathFile = path + dbName;
        DbLite dbl        = new DbLite();

        dbl.showMessage(dbPathFile);

        String tableName = "Login";

        etrUser.Text = etrUser.Text.Trim();
        etrPsw.Text  = etrPsw.Text.Trim();

        if ((etrUser.Text != "") && (etrPsw.Text != ""))
        {
            String getData = dbl.dbGetCommand(dbPathFile, tableName, "Nome", "Nome", etrUser.Text);

            if (etrUser.Text == getData)
            {
                getData = dbl.dbGetCommand(dbPathFile, tableName, "Senha", "Senha", etrPsw.Text);
                if (etrPsw.Text == getData)
                {
                    sigom.WorkshopWindow ww = new sigom.WorkshopWindow();
                    ww.Show();
                    this.Destroy();
                }
                else
                {
                    dbl.showMessage("Usuário e/ou Senha incorreto!");
                }
            }
            else
            {
                dbl.showMessage("Usuário e/ou Senha incorreto!");
            }
        }
        else
        {
            dbl.showMessage("Usuário e/ou Senha é obrigatório!");
        }
    }
Example #8
0
        /// <summary>
        ///    updates a key/value pair to the System.Collections.Concurrent.ConcurrentDictionary<TKey,TValue>
        ///    if the key already exists.
        /// </summary>
        /// <param name="key">The key to be added or whose value should be updated</param>
        /// <param name="value">The value to be added or updated for an absent key</param>
        /// <returns></returns>
        public int UpdateState(string key, int state)
        {
            bool         iscommited = false;
            int          res        = 0;
            IPersistItem val        = null;

            try
            {
                switch (_CommitMode)
                {
                case CommitMode.OnDisk:
                    using (var db = new DbLite(ConnectionString, DBProvider.SQLite))
                    {
                        var cmdText = DbUpdateStateCommand();
                        res = db.ExecuteTransCommandNonQuery(cmdText, DataParameter.Get <SQLiteParameter>("Identifier", key, "MessageState", state), (result, trans) =>
                        {
                            if (result > 0)
                            {
                                if (dictionary.TryGetValue(key, out val))
                                {
                                    val.MessageState = (MessageState)state;
                                    dictionary[key]  = val;
                                }
                                //if (dictionary.ContainsKey(key))
                                //    dictionary[key].State = state;
                                trans.Commit();
                                iscommited = true;
                            }
                        });
                    }

                    break;

                default:
                    //if (dictionary.ContainsKey(key))
                    //    dictionary[key].State = state;
                    if (dictionary.TryGetValue(key, out val))
                    {
                        val.MessageState = (MessageState)state;
                        dictionary[key]  = val;
                    }
                    if (_CommitMode == CommitMode.OnMemory)
                    {
                        var task = new PersistanceTask()
                        {
                            CommandText      = DbUpdateStateCommand(),
                            CommandType      = "DbUpdateState",
                            ConnectionString = ConnectionString,
                            Parameters       = DataParameter.Get <SQLiteParameter>("Identifier", key, "MessageState", state)
                        };
                        task.ExecuteTask(_EnableTasker);
                    }
                    res        = 1;
                    iscommited = true;
                    break;
                }
                if (iscommited)
                {
                    OnItemChanged("Update", null, val);
                }
            }
            catch (Exception ex)
            {
                OnErrorOcurred("Update", ex.Message);
            }

            return(res);
        }
Example #9
0
    /*
     * protected void OnBtnLoginClicked(object sender, EventArgs e)
     * {
     *  String path = System.IO.Directory.GetCurrentDirectory() + "/";
     *  String dbName = "sigomDb.db";
     *  String dbPathFile = path + dbName;
     *  DbLite dbl = new DbLite();
     *
     *  dbl.showMessage(dbPathFile);
     *
     *  String tableName = "Login";
     *
     *  etrUser.Text = etrUser.Text.Trim();
     *  etrPsw.Text = etrPsw.Text.Trim();
     *
     *      if ((etrUser.Text != "") && (etrPsw.Text != ""))
     *      {
     *
     *          String getData = dbl.dbGetCommand(dbPathFile, tableName, "Nome", "Nome", etrUser.Text);
     *
     *          if (etrUser.Text == getData)
     *          {
     *              getData = dbl.dbGetCommand(dbPathFile, tableName, "Senha", "Senha", etrPsw.Text);
     *              if (etrPsw.Text == getData)
     *              {
     *                  sigom.WorkshopWindow ww = new sigom.WorkshopWindow();
     *                  ww.Show();
     *                  this.Destroy();
     *              }
     *              else
     *              {
     *                  dbl.showMessage("Usuário e/ou Senha incorreto!");
     *              }
     *          }
     *          else
     *          {
     *              dbl.showMessage("Usuário e/ou Senha incorreto!");
     *          }
     *      }
     *      else{
     *          dbl.showMessage("Usuário e/ou Senha é obrigatório!");
     *      }
     *  }
     */
    protected void OnButton1Clicked(object sender, EventArgs e)
    {
        //***Path do banco de dados***//
        String path       = System.IO.Directory.GetCurrentDirectory() + "/";
        String dbName     = "sigomDb.db";
        String dbPathFile = path + dbName;
        DbLite dbl        = new DbLite();

        //dbl.showMessage(dbPathFile);
        //***Criando o banco de dados***//
        //dbl.dbCreate(dbPathFile);

        //***criando a tabela de login***//
        //string createTable = @"CREATE TABLE Login (ID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,Nome VARCHAR(100) NOT NULL,Senha VARCHAR (10) NOT NULL )";

        //createTable = @"CREATE TABLE OrdemServico(
        //numOs INTEGER PRIMARY KEY,
        //matricFunc INTEGER,
        //codCli INTEGER,
        //codCarro INTEGER,
        //codServ VARCHAR(2),
        //descricao VARCHAR(100),
        //Status VARCHAR(20)
        //)";

        //dbl.dbSetCommand(dbPathFile, createTable);


        //***Inserir o conteudo na tabela***//
        String numOs         = "6";      //int
        String matricFunc    = "103";    //int
        String codCli        = "100036"; //int
        String codCarro      = "234187"; //int
        String codServ       = "4E";     //1M 2S 3F 4E 5I
        String descricao     = "SUBSTITUIÇÃO DAS LAMPADAS DE FREIO";
        String status        = "ABERTO"; //ABERTO NEGOCIANDO EXECUTANDO  FECHADO
        String insertCommand = "INSERT INTO OrdemServico (numOs, matricFunc, codCli, " +
                               "codCarro, codServ, descricao, status)" +
                               "VALUES(" + numOs + "," + matricFunc + "," + codCli + "," + codCarro + ",'" + codServ + "','" + descricao + "','" + status + "')";

        dbl.dbSetCommand(dbPathFile, insertCommand);

        //***Inserir o conteudo na tabela***//
        numOs         = "7";      //int
        matricFunc    = "101";    //int
        codCli        = "100219"; //int
        codCarro      = "128475"; //int
        codServ       = "1M";     //1M 2S 3F 4E 5I
        descricao     = "TROCA DE ÓLEO DO MOTOR";
        status        = "ABERTO"; //ABERTO NEGOCIANDO EXECUTANDO  FECHADO
        insertCommand = "INSERT INTO OrdemServico (numOs, matricFunc, codCli, " +
                        "codCarro, codServ, descricao, status)" +
                        "VALUES(" + numOs + "," + matricFunc + "," + codCli + "," + codCarro + ",'" + codServ + "','" + descricao + "','" + status + "')";
        dbl.dbSetCommand(dbPathFile, insertCommand);

        //***Inserir o conteudo na tabela***//
        numOs         = "8";      //int
        matricFunc    = "103";    //int
        codCli        = "100481"; //int
        codCarro      = "234472"; //int
        codServ       = "3F";     //1M 2S 3F 4E 5I
        descricao     = "SUBSTITUIÇÃO DO CILINDRO MESTRE DO FREIO";
        status        = "ABERTO"; //ABERTO NEGOCIANDO EXECUTANDO  FECHADO
        insertCommand = "INSERT INTO OrdemServico (numOs, matricFunc, codCli, " +
                        "codCarro, codServ, descricao, status)" +
                        "VALUES(" + numOs + "," + matricFunc + "," + codCli + "," + codCarro + ",'" + codServ + "','" + descricao + "','" + status + "')";
        dbl.dbSetCommand(dbPathFile, insertCommand);

        //***Inserir o conteudo na tabela***//
        numOs         = "9";      //int
        matricFunc    = "102";    //int
        codCli        = "100518"; //int
        codCarro      = "384815"; //int
        codServ       = "5I";     //1M 2S 3F 4E 5I
        descricao     = "SUBSTITUIÇÃO DA BOBINA DE IGNIÇÃO ELETRÔNICA";
        status        = "ABERTO"; //ABERTO NEGOCIANDO EXECUTANDO  FECHADO
        insertCommand = "INSERT INTO OrdemServico (numOs, matricFunc, codCli, " +
                        "codCarro, codServ, descricao, status)" +
                        "VALUES(" + numOs + "," + matricFunc + "," + codCli + "," + codCarro + ",'" + codServ + "','" + descricao + "','" + status + "')";
        dbl.dbSetCommand(dbPathFile, insertCommand);

        //***Inserir o conteudo na tabela***//
        numOs         = "10";     //int
        matricFunc    = "101";    //int
        codCli        = "100918"; //int
        codCarro      = "718614"; //int
        codServ       = "2S";     //1M 2S 3F 4E 5I
        descricao     = "SUBASTITUIÇÃO DOS AMORTECEDORES TRASEIROS E DIANTEIROS";
        status        = "ABERTO"; //ABERTO NEGOCIANDO EXECUTANDO  FECHADO
        insertCommand = "INSERT INTO OrdemServico (numOs, matricFunc, codCli, " +
                        "codCarro, codServ, descricao, status)" +
                        "VALUES(" + numOs + "," + matricFunc + "," + codCli + "," + codCarro + ",'" + codServ + "','" + descricao + "','" + status + "')";
        dbl.dbSetCommand(dbPathFile, insertCommand);
    }
Example #10
0
        public static void Main(string[] args)
        {
            DbLite db = new DbLite(new DBConfig("test"));

            db.WriteMessage(args[0], args[1]);
        }