示例#1
0
        public Context(bool hasSqlAccess)
        {
            SqlConnectorManager sqlCon = new SqlConnectorManager();

            if (hasSqlAccess)//else if web we should give the URL to the data access
            {
                sqlCon.InitializeConnection(@"C:\PosLite\PosLite.s3db");
            }

            BusinessEntities = new Dictionary <Type, IBusinessBase>();
            DataEntities     = new Dictionary <Type, IDataBase>();
            var typeOfDataBase     = typeof(IDataBase);
            var typeOfBusinessBase = typeof(IBusinessBase);

            //Loads all Data Entities
            foreach (var type in ExistingIDataBase)
            {
                var entity = hasSqlAccess?(IDataBase)Activator.CreateInstance(type) : (IDataBase)Activator.CreateInstance(type, sqlCon);

                //get interface that is not a base (isgeneric refers to iblentity<T>)
                var first = type.GetInterfaces().First(x => x.IsGenericType == false && !(x.Equals(typeOfDataBase)));
                DataEntities.Add(first, entity);
            }

            foreach (var type in ExistingIBusinessBase)
            {
                //get interface that is not a base
                var first       = type.GetInterfaces().First(x => x.IsGenericType == false && !(x.Equals(typeOfBusinessBase)));
                var transaction = (IBusinessBase)Activator.CreateInstance(type);
                BusinessEntities.Add(first, transaction);
            }
        }
示例#2
0
        /// <summary>
        /// Executes all that happens in action inside a transaction
        /// </summary>
        /// <param name="action">the action that will be executed inside a transaction</param>
        /// <returns></returns>
        public void ExecuteInTransaction(Action action, SqlConnectorManager connector, params ModelBase[] models)
        {
            var            ids   = models.Select(x => x.Id).ToArray();
            IDbTransaction trans = null;

            try
            {
                trans = connector.BeginTransaction();
                action();
                connector.CommitTransaction(trans);
            }
            catch (Exception e)
            {
                if (trans != null)
                {
                    trans.Rollback();
                }
                for (int i = 0; i < models.Length; i++)
                {
                    models[i].Id = ids[i];
                }
                LogHelper.Logger.Error(e);
                throw e;
            }
        }
示例#3
0
        public Context(string dbLocation)
        {
            SqlConnectorManager sqlCon = null;

            sqlCon = new SqlConnectorManager();
            sqlCon.InitializeConnection(dbLocation);

            DbAccess = new Dictionary <Type, IDgvDbAccess>
            {
                { typeof(IPrinterBillsHistoryDE), new PrinterBillsHistoryDE(sqlCon) },
                { typeof(IFamiliesDE), new FamiliesDE(sqlCon) },
                { typeof(IMenuProductsDE), new MenuProductsDE(sqlCon) },
                { typeof(IOrderItemsDE), new OrderItemsDE(sqlCon) },
                { typeof(IOrderItemsHistoryDE), new OrderItemsHistoryDE(sqlCon) },
                { typeof(IOrdersDE), new OrdersDE(sqlCon) },
                { typeof(IOrdersHistoryDE), new OrdersHistoryDE(sqlCon) },
                { typeof(IProductsDE), new ProductsDE(sqlCon) },
                { typeof(ITablesDE), new TablesDE(sqlCon) },
                { typeof(IUsersDE), new UsersDE(sqlCon) },
                { typeof(ILanguagesDE), new LanguagesDE(sqlCon) },
                { typeof(ITranslationsDE), new TranslationsDE(sqlCon) },
                { typeof(IMenusDE), new MenusDE(sqlCon) }
            };
        }
示例#4
0
 public PrinterBillsHistoryDE(SqlConnectorManager sqlConManager) : base(sqlConManager)
 {
 }
 public OrdersHistoryDE(SqlConnectorManager sqlConManager) : base(sqlConManager)
 {
 }
示例#6
0
 public DataBase(SqlConnectorManager sqlConManager)
 {
     this.Connector = sqlConManager;
 }
 public TranslationsDE(SqlConnectorManager sqlConManager) : base(sqlConManager)
 {
 }
示例#8
0
 public ProductsDE(SqlConnectorManager sqlConManager) : base(sqlConManager)
 {
 }
示例#9
0
 public MenusDE(SqlConnectorManager sqlConManager) : base(sqlConManager)
 {
 }
示例#10
0
 public TablesDE(SqlConnectorManager sqlConManager) : base(sqlConManager)
 {
 }
示例#11
0
 public UsersDE(SqlConnectorManager sqlConManager) : base(sqlConManager)
 {
 }
示例#12
0
 public LanguagesDE(SqlConnectorManager sqlConManager) : base(sqlConManager)
 {
 }
示例#13
0
 public FamiliesDE(SqlConnectorManager sqlConManager) : base(sqlConManager)
 {
 }
示例#14
0
 public OrderItemsDE(SqlConnectorManager sqlConManager) : base(sqlConManager)
 {
 }