Exemplo n.º 1
0
        }// DeleteProduct()

        public bool AddRecord(Record dr)
        {
            hasError = false;
            ObjectParameter msg   = new ObjectParameter("msg", "");
            ObjectParameter idreg = new ObjectParameter("idreg", 0);

            try
            {
                SqlRecord    r  = new SqlRecord(dr);
                TESTEntities dc = new TESTEntities();
                dc.pTestTableAdd(msg, idreg, r.ElCampo1, r.ElCampo2);
                r.IdReg = (int)idreg.Value;
                dr.RecordAdded2DB(r);    //update corresponding Record ProductId using SqlProduct
            }
            catch (Exception ex)
            {
                errorMessage = "Add error, " + ex.Message;
                hasError     = true;
            }
            if (msg.Value.ToString() != "OK")
            {
                errorMessage = "Add error, " + msg.Value.ToString();
                hasError     = true;
            }
            return(!hasError);
        } //AddProduct()
Exemplo n.º 2
0
        private void initSqlHelper(string _providerName)
        {
            _cacheService    = new MemoryCacheService();
            _events          = new SqlEvents();
            _tableNameManger = new TableNameManger();
            _sqlConfig       = new SqlConfig(this);
            _sql             = new SqlRecord();
            _sqlMonitor      = new NullSqlMonitor();
            _sql.SqlMonitor  = _sqlMonitor;


            _connectionType = ConnectionType.Default;

            if (_providerName != null)
            {
                _sqlType = SqlConfig.GetSqlType(_providerName, _writeConnectionString);
                var _provider = DatabaseProvider.Resolve(_sqlType);
                _factory = _provider.GetFactory();
            }
            else
            {
                _sqlType = SqlConfig.GetSqlType(_factory.GetType().FullName, _writeConnectionString);
            }

            _provider = DatabaseProvider.Resolve(_sqlType);
        }
Exemplo n.º 3
0
 internal void OnExecutedCommand(string sql, object[] args)
 {
     if (AfterExecuteCommand != null)
     {
         SqlOperationEventArgs e = new SqlOperationEventArgs(sql, args, SqlRecord.FormatCommand(sql, args));
         AfterExecuteCommand(this, e);
     }
 }
Exemplo n.º 4
0
 internal bool OnException(string message, string sql, params object[] args)
 {
     if (ExecuteException != null)
     {
         SqlErrorEventArgs e = new SqlErrorEventArgs(sql, args, SqlRecord.FormatCommand(sql, args), message);
         ExecuteException(this, e);
         if (e.Handle)
         {
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 5
0
        private void initSqlHelper(string connectionString, string providerName)
        {
            _lastConnectionString = connectionString;
            _lastProviderName     = providerName;

            _connectionString = connectionString;
            var txts = connectionString.Split(';');

            foreach (var txt in txts)
            {
                var sp = txt.Split('=');
                if (sp.Length != 2)
                {
                    continue;
                }
                if (sp[0].ToLower() == "database")
                {
                    _schemaName = sp[1];
                    break;
                }
                if (sp[0].ToLower() == "data source")
                {
                    _schemaName = sp[1];
                    break;
                }
            }


            _cacheService = new MemoryCacheService();
            _events       = new SqlEvents();
            _sqlConfig    = new SqlConfig(this);
            _sql          = new SqlRecord();
            _sqlMonitor   = new NullSqlMonitor();


            if (_sqlType == SqlType.None)
            {
                _sqlType = DatabaseProvider.GetSqlType(providerName ?? _factory.GetType().FullName, _connectionString);
            }
            _provider = DatabaseProvider.Resolve(_sqlType);
            if (_factory == null)
            {
                _factory     = _provider.GetFactory();
                _lastFactory = _factory;
            }
            if (_lastSqlHelper == null || _lastSqlHelper._isDisposable)
            {
                _lastSqlHelper = this;
            }
        }
Exemplo n.º 6
0
        } //GetProducts()

        public bool UpdateRecord(Record r)
        {
            hasError = false;
            ObjectParameter msg = new ObjectParameter("@msg", "");

            try
            {
                SqlRecord    sr = new SqlRecord(r);
                TESTEntities ef = new TESTEntities();
                ef.pTestTableUpp(msg, sr.IdReg, sr.ElCampo1, sr.ElCampo2);
            }
            catch (Exception ex)
            {
                errorMessage = "Update error, " + ex.Message;
                hasError     = true;
            }
            if (msg.Value.ToString() != "OK")
            {
                errorMessage = "Update error, " + msg.Value.ToString();
                hasError     = true;
            }
            return(!hasError);
        } //UpdateProduct()