コード例 #1
0
 public string signContract(string username, int storeId)
 {
     try
     {
         int session = UserService.getInstance().getUserByHash(System.Web.HttpContext.Current.Request.Cookies["HashCode"].Value);
         StoreService.getInstance().signContract(storeId, username, session);
         return("ok");
     }
     catch (ClientException e)
     {
         SystemLogger.getEventLog().Error("Error in signing a contract : " + e.Message.ToString());
         return(e.Message.ToString());
     }
     catch (ConnectionException e)
     {
         SystemLogger.getEventLog().Error("Database Error : " + e.Message.ToString());
         return("There has been a problem with the connection to the database. Please try again.");
     }
     catch (Exception e)
     {
         SystemLogger.getErrorLog().Error("An Error has occured. Function: signContract; Stack Trace: " + e.StackTrace);
         throw e;
     }
 }
コード例 #2
0
 public string SetProductInformation(int storeID, int productID, int price, int rank, int quantityLeft, string productName)
 {
     try
     {
         int session = UserService.getInstance().getUserByHash(System.Web.HttpContext.Current.Request.Cookies["HashCode"].Value);
         StoreService.getInstance().SetProductInformation(storeID, productID, price, rank, quantityLeft, productName, session);
         return("ok");
     }
     catch (ConnectionException e)
     {
         SystemLogger.getEventLog().Error("Database Error : " + e.Message.ToString());
         return("There has been a problem with the connection to the database. Please try again.");
     }
     catch (ClientException e)
     {
         SystemLogger.getEventLog().Error("Edit product error : " + e.Message.ToString());
         return(e.Message.ToString());
     }
     catch (Exception e)
     {
         SystemLogger.getErrorLog().Error("An Error has occured. Function: Edit Product; Stack Trace: " + e.StackTrace);
         throw e;
     }
 }
コード例 #3
0
        public Store getStore(int storeId)
        {
            foreach (Store s in stores)
            {
                if (s.getStoreID() == storeId)
                {
                    return(s);
                }
            }
            /////////////////////////////////////////////////////
            try
            {
                // SqlConnection connection = Connector.getInstance().getSQLConnection();
                lock (connection)
                {
                    connection.Open();
                    LinkedList <Store> newStores = new LinkedList <Store>();
                    var StoreResult     = connection.Query <StoreEntry>("SELECT * FROM [dbo].[Stores] WHERE storeId=@storeId ", new { storeId = storeId });
                    var StoreRoleResult = connection.Query <StoreRoleEntry>("SELECT * FROM [dbo].[StoreRoles] WHERE storeId=@storeId ", new { storeId = storeId });
                    var ContractResult  = connection.Query <Contract>("SELECT * FROM [dbo].[Contracts] WHERE storeId = @storeId", new { storeId = storeId });
                    var pendingResult   = connection.Query <string>("SELECT userName FROM [dbo].[PendingOwners] WHERE storeId = @storeId", new { storeId = storeId }).AsList();
                    var policyEntries   = connection.Query <PolicyEntry>("SELECT * FROM [dbo].[PurchasePolicy] WHERE storeID=@storeId", new { storeID = storeId });
                    connection.Close();

                    StoreEntry se = StoreResult.ElementAt(0);
                    Store      s  = new Store(se.getStoreId(), se.getName(), se.getDescription());
                    foreach (Contract c in ContractResult)
                    {
                        s.getContracts().AddFirst(c);
                    }
                    foreach (string pending in pendingResult)
                    {
                        s.getPending().AddFirst(pending);
                    }

                    LinkedList <Product> lst = DBProduct.getInstance().getAllProducts();
                    foreach (Product p in lst)
                    {
                        if (p.getStoreID() == s.getStoreID())
                        {
                            s.addProduct(p);
                        }
                    }
                    s.setPolicyList(parsePolicy(policyEntries));
                    foreach (StoreRoleEntry element in StoreRoleResult)
                    {
                        if (element.getStoreId() == s.getStoreID() && element.getIsOwner() == 1)
                        {
                            SubscribedUser appointedBy = null;
                            try
                            {
                                appointedBy = DBSubscribedUser.getInstance().getSubscribedUserForInitStore(element.getAppointedBy());
                            }
                            catch (Exception) { }
                            SubscribedUser user = DBSubscribedUser.getInstance().getSubscribedUserForInitStore(element.getUserName());
                            StoreOwner     so   = new StoreOwner(appointedBy, user, s);
                            s.addStoreRoleFromInitOwner(so);
                            storeRole.AddLast(so);
                        }
                        else if (element.getStoreId() == s.getStoreID() && element.getIsOwner() == 0)
                        {
                            SubscribedUser appointedBy = DBSubscribedUser.getInstance().getSubscribedUserForInitStore(element.getAppointedBy());
                            SubscribedUser user        = DBSubscribedUser.getInstance().getSubscribedUserForInitStore(element.getUserName());
                            Permissions    p           = new Permissions(false, false, false);
                            if (element.getEditDiscount() == 1)
                            {
                                p.setEditDiscount(true);
                            }
                            if (element.getEditPolicy() == 1)
                            {
                                p.setEditPolicy(true);
                            }
                            if (element.getEditProduct() == 1)
                            {
                                p.setEditProduct(true);
                            }
                            StoreManager sm = new StoreManager(appointedBy, s, user, p);
                            s.addStoreRoleFromInitManager(sm);
                            storeRole.AddLast(sm);
                        }
                    }
                    stores.AddLast(s);
                    LinkedList <DiscountComponent> discountList = DBDiscount.getInstance().getStoreDiscountsList(storeId);
                    s.setDiscountList(discountList);
                    return(s);
                }
            }
            catch (Exception e)
            {
                connection.Close();
                SystemLogger.getErrorLog().Error("Connection error in function getStore in DB Store store id " + storeId);
                throw new ConnectionException();
            }


            ///////////////////////////////////////////////////
        }
コード例 #4
0
        public void addStoreRole(StoreRole sr)
        {
            //SqlConnection connection = Connector.getInstance().getSQLConnection();
            lock (connection)
            {
                if (ownerTrans == null)
                {
                    connection.Open();
                }

                SqlTransaction transaction;
                if (ownerTrans != null)
                {
                    transaction = ownerTrans;
                }
                else
                {
                    transaction = connection.BeginTransaction();
                }

                try
                {
                    string sql = "INSERT INTO [dbo].[StoreRoles] (storeId, appointedBy,userName,isOwner,editProduct,editDiscount,editPolicy)" +
                                 " VALUES (@storeId, @appointedBy, @userName,@isOwner,@editProduct,@editDiscount,@editPolicy)";
                    int    storeId     = sr.getStore().getStoreID();
                    string appointedBy = null;
                    if (sr.getAppointedBy() != null)
                    {
                        appointedBy = sr.getAppointedBy().getUsername();
                    }
                    string userName     = sr.getUser().getUsername();
                    int    isOwner      = sr.getIsOwner();
                    int    editProduct  = 1;
                    int    editDiscount = 1;
                    int    editPolicy   = 1;
                    if (isOwner == 0)
                    {
                        editProduct  = sr.GetPermissions().getPermission("editProduct");
                        editDiscount = sr.GetPermissions().getPermission("editDiscount");
                        editPolicy   = sr.GetPermissions().getPermission("editPolicy");
                    }
                    connection.Execute(sql, new { storeId, appointedBy, userName, isOwner, editProduct, editDiscount, editPolicy }, transaction);
                    storeRole.AddFirst(sr);
                    if (ownerTrans == null)
                    {
                        transaction.Commit();
                        transaction.Dispose();
                        connection.Close();
                    }
                }
                catch (Exception e)
                {
                    if (ownerTrans == null)
                    {
                        transaction.Dispose();
                        connection.Close();
                    }
                    SystemLogger.getErrorLog().Error("Connection error in function add role in DB Store while adding " + sr.getUser().getUsername());
                    throw new ConnectionException();
                }
            }
        }
コード例 #5
0
        public static void init()
        {
            int addNewDataToDB = 0;
            int createTables   = 0;

            string[] linesConfig    = null;
            string   filePathConfig = null;
            string   fileName       = "";

            try
            {
                filePathConfig = Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory);
                linesConfig    = File.ReadAllLines(filePathConfig + "/config.txt");
                foreach (string line in linesConfig)
                {
                    string[] input = line.Split(' ');
                    if (input[0] == "inputFile")
                    {
                        fileName = input[1];
                    }
                    if (input[0] == "isTestMode")
                    {
                        if (input[1] == "true")
                        {
                            testsMode = true;
                        }
                        else
                        {
                            testsMode = false;
                        }
                    }
                    if (input[0] == "isFirstTime")
                    {
                        if (input[1] == "false")
                        {
                            addNewDataToDB = 0;
                        }
                        else
                        {
                            addNewDataToDB = 1;
                        }
                    }
                    if (input[0] == "CreateTables")
                    {
                        if (input[1] == "false")
                        {
                            createTables = 0;
                        }
                        else
                        {
                            createTables = 1;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                initWitOutRead();
                SystemLogger.getErrorLog().Error("Cant open config file " + e.StackTrace);
                return;
            }

            if (createTables == 1)
            {
                Connector c = new Connector();
                c.createAllTables();
            }

            if (testsMode == true)
            {
                initTestWitOutRead();
                return;
            }

            if (addNewDataToDB == 0)
            {
                initWitOutRead();
                return;
            }

            else
            {
                string   filePath = null;
                string[] lines    = null;
                try
                {
                    filePath = Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory);
                    lines    = File.ReadAllLines(filePath + "/" + fileName);
                }
                catch (Exception e)
                {
                    initWitOutRead();
                    SystemLogger.getErrorLog().Error("Cant open input file " + e.StackTrace);
                    return;
                }

                foreach (string line in lines)
                {
                    string[] input = line.Split(' ');

                    if (input[0] == "createSession")
                    {
                        int sessionid = DBSession.getInstance().generate();
                        DBSession.getInstance().getSession(sessionid);
                    }
                    else if (input[0] == "register")
                    {
                        //Session s = DBSession.getInstance().getSession(Int32.Parse(input[3]));
                        //s.register(input[1], input[2]);
                        UserService.getInstance().register(Int32.Parse(input[3]), input[1], input[2]);
                    }
                    else if (input[0] == "deleteDB")
                    {
                        Connector c = new Connector();
                        c.deleteAllTable();
                        //DBStore.getInstance().deleteAllTable();
                    }
                    else if (input[0] == "init")
                    {
                        initWitOutRead();
                    }
                    else if (input[0] == "login")
                    {
                        //Session s = DBSession.getInstance().getSession(Int32.Parse(input[3]));
                        //s.login(input[1], input[2]);
                        UserService.getInstance().login(Int32.Parse(input[3]), input[1], input[2]);
                    }
                    else if (input[0] == "createStore")
                    {
                        DomainBridge.getInstance().createStore(Int32.Parse(input[3]), input[1], input[2]);
                    }
                    else if (input[0] == "addProduct")
                    {
                        DomainBridge.getInstance().addProduct(input[1], input[2], Int32.Parse(input[3]), Int32.Parse(input[4]), Int32.Parse(input[5]), Int32.Parse(input[6]), Int32.Parse(input[7]));
                    }
                    else if (input[0] == "logout")
                    {
                        Session s = DBSession.getInstance().getSession(Int32.Parse(input[1]));
                        s.logout();
                    }
                    else if (input[0] == "addManager")
                    {
                        DomainBridge.getInstance().addManager(Int32.Parse(input[1]), input[2], Boolean.Parse(input[3]), Boolean.Parse(input[4]), Boolean.Parse(input[5]), Int32.Parse(input[6]));
                    }
                    else if (input[0] == "addOwner")
                    {
                        DomainBridge.getInstance().addOwner(Int32.Parse(input[1]), input[2], Int32.Parse(input[3]));
                    }
                    else if (input[0] == "setProductDiscount")
                    {
                        DomainBridge.getInstance().setProductDiscount(Int32.Parse(input[1]), Int32.Parse(input[2]), Int32.Parse(input[3]));
                    }
                    else if (input[0] == "addToCart")
                    {
                        DomainBridge.getInstance().addToCart(Int32.Parse(input[1]), Int32.Parse(input[2]), Int32.Parse(input[3]));
                    }
                    else if (input[0] == "setProductDiscount")
                    {
                        DomainBridge.getInstance().setProductDiscount(Int32.Parse(input[1]), Int32.Parse(input[2]), Int32.Parse(input[3]));
                    }
                    else if (input[0] == "addStoreVisibleDiscount")
                    {
                        DomainBridge.getInstance().addStoreVisibleDiscount(Int32.Parse(input[1]), Double.Parse(input[2]), input[3], Int32.Parse(input[4]));
                    }
                    else if (input[0] == "addProductVisibleDiscount")
                    {
                        DomainBridge.getInstance().addProductVisibleDiscount(Int32.Parse(input[1]), Double.Parse(input[2]), input[3], Int32.Parse(input[4]));
                    }
                    else if (input[0] == "addAdmin")
                    {
                        DomainBridge.getInstance().addAdmin(input[1], input[2]);
                    }
                    else if (input[0] == "removeUser")
                    {
                        Session s = DBSession.getInstance().getSession(Int32.Parse(input[1]));
                        //session id, username
                        DomainBridge.getInstance().removeUser(Int32.Parse(input[1]), input[2]);
                    }
                    else if (input[0] == "addSession")
                    {
                        DomainBridge.getInstance().addSession(input[1], Int32.Parse(input[2]));
                    }
                    else if (input[0] == "addToShoppingBasket")
                    {
                        DomainBridge.getInstance().addToShoppingBasket(Int32.Parse(input[1]), Int32.Parse(input[2]), Int32.Parse(input[3]));
                    }
                    else if (input[0] == "setProductRank")
                    {
                        DomainBridge.getInstance().setProductRank(Int32.Parse(input[1]), Int32.Parse(input[2]), Int32.Parse(input[3]));
                    }
                    else if (input[0] == "removeProduct")
                    {
                        DomainBridge.getInstance().removeProduct(Int32.Parse(input[1]), Int32.Parse(input[2]));
                    }
                    else if (input[0] == "setProductPrice")
                    {
                        DomainBridge.getInstance().setProductPrice(Int32.Parse(input[1]), Int32.Parse(input[2]), Int32.Parse(input[3]));
                    }
                    else if (input[0] == "setProductName")
                    {
                        DomainBridge.getInstance().setProductName(Int32.Parse(input[1]), input[2], Int32.Parse(input[3]));
                    }
                    else if (input[0] == "addToProductQuantity")
                    {
                        DomainBridge.getInstance().addToProductQuantity(Int32.Parse(input[1]), Int32.Parse(input[2]), Int32.Parse(input[3]));
                    }
                    else if (input[0] == "decFromProductQuantity")
                    {
                        DomainBridge.getInstance().decFromProductQuantity(Int32.Parse(input[1]), Int32.Parse(input[2]), Int32.Parse(input[3]));
                    }
                    else if (input[0] == "closeStore")
                    {
                        DomainBridge.getInstance().closeStore(Int32.Parse(input[1]), Int32.Parse(input[2]));
                    }
                    else if (input[0] == "addManager")
                    {
                        DomainBridge.getInstance().addManager(Int32.Parse(input[1]), input[2], Convert.ToBoolean(input[3]), Convert.ToBoolean(input[4]), Convert.ToBoolean(input[5]), Int32.Parse(input[6]));
                    }
                    else if (input[0] == "removeRole")
                    {
                        DomainBridge.getInstance().removeRole(Int32.Parse(input[1]), input[2], Int32.Parse(input[3]));
                    }
                    else if (input[0] == "addToCart")
                    {
                        DomainBridge.getInstance().addToCart(Int32.Parse(input[1]), Int32.Parse(input[2]), Int32.Parse(input[3]));
                    }
                    else if (input[0] == "removeFromCart")
                    {
                        DomainBridge.getInstance().removeFromCart(Int32.Parse(input[1]), Int32.Parse(input[2]));
                    }
                    else if (input[0] == "changeQuantity")
                    {
                        DomainBridge.getInstance().changeQuantity(Int32.Parse(input[1]), Int32.Parse(input[2]), Int32.Parse(input[3]));
                    }
                    else if (input[0] == "removeProductDiscount")
                    {
                        DomainBridge.getInstance().removeProductDiscount(Int32.Parse(input[1]), Int32.Parse(input[2]));
                    }
                    else if (input[0] == "addStoreVisibleDiscount")
                    {
                        DomainBridge.getInstance().addStoreVisibleDiscount(Int32.Parse(input[1]), Double.Parse(input[2]), input[3], Int32.Parse(input[4]));
                    }
                    else if (input[0] == "addProductVisibleDiscount")
                    {
                        DomainBridge.getInstance().addProductVisibleDiscount(Int32.Parse(input[1]), Double.Parse(input[2]), input[3], Int32.Parse(input[4]));
                    }
                    else if (input[0] == "addReliantdiscountSameProduct")
                    {
                        DomainBridge.getInstance().addReliantdiscountSameProduct(Int32.Parse(input[1]), Int32.Parse(input[2]), Double.Parse(input[3]), Int32.Parse(input[4]), input[5], Int32.Parse(input[6]));
                    }
                    else if (input[0] == "addReliantdiscountTotalAmount")
                    {
                        DomainBridge.getInstance().addReliantdiscountTotalAmount(Int32.Parse(input[1]), Double.Parse(input[2]), Int32.Parse(input[3]), input[4], Int32.Parse(input[5]));
                    }
                    else if (input[0] == "removeStoreDiscount")
                    {
                        DomainBridge.getInstance().removeStoreDiscount(Int32.Parse(input[1]), Int32.Parse(input[2]), Int32.Parse(input[3]));
                    }
                    else if (input[0] == "setProductDiscount")
                    {
                        DomainBridge.getInstance().setProductDiscount(Int32.Parse(input[1]), Int32.Parse(input[2]), Int32.Parse(input[3]));
                    }
                    else if (input[0] == "complexDiscount")
                    {
                        DomainBridge.getInstance().complexDiscount(input[1], Int32.Parse(input[2]), input[3], Double.Parse(input[4]), input[5], Int32.Parse(input[6]));
                    }
                    else if (input[0] == "removePolicy")
                    {//(string) policyID, storeID, session
                        DomainBridge.getInstance().removePolicy(input[1], Int32.Parse(input[2]), Int32.Parse(input[3]));
                    }
                    else if (input[0] == "setPolicyAmount")
                    {
                        DomainBridge.getInstance().setPolicyAmount(Int32.Parse(input[1]), Int32.Parse(input[2]), Int32.Parse(input[3]), Int32.Parse(input[4]));
                    }
                    else if (input[0] == "addMinPurchasePolicy")
                    {
                        DomainBridge.getInstance().addMinPurchasePolicy(Int32.Parse(input[1]), Int32.Parse(input[2]), Int32.Parse(input[3]));
                    }
                    else if (input[0] == "addMaxAmountPolicy")
                    {
                        DomainBridge.getInstance().addMaxPurchasePolicy(Int32.Parse(input[1]), Int32.Parse(input[2]), Int32.Parse(input[3]));
                    }
                    else if (input[0] == "addTotalPricePolicy")
                    {
                        DomainBridge.getInstance().addTotalPricePolicy(Int32.Parse(input[1]), Int32.Parse(input[2]), Int32.Parse(input[3]));
                    }
                    else if (input[0] == "addPendingOwner")
                    {
                        DomainBridge.getInstance().addPendingOwner(Int32.Parse(input[1]), input[2], Int32.Parse(input[3]));
                    }
                }
            }
        }