Ejemplo n.º 1
0
        public string updateRecomsSystem(RecommendationsSystem recmosSystem)
        {
            bool updateResult = database.updateRecomsSystem(recmosSystem);

            if (updateResult)
            {
                return("System updated");
            }
            return("Failure while writting to database");
        }
        public UserControlRecommendationsSystem(INavReccomendationsSystem navigation, IRecomsSystem adminFunctions)
        {
            InitializeComponent();
            this.navigation     = navigation;
            this.adminFunctions = adminFunctions;
            recSys = adminFunctions.getRecomsSystem();
            LinkedList <ScoreModuleInfo> modules = recSys.ModulesInfo;

            foreach (ScoreModuleInfo s in modules)
            {
                ContainerScoreModuleInfo cont = new ContainerScoreModuleInfo(s);
                listBoxModules.Items.Add(cont);
            }
        }
Ejemplo n.º 3
0
        public bool updateRecomsSystem(RecommendationsSystem recSys)
        {
            SqlCommand     command = cnn.CreateCommand();
            SqlTransaction transaction;

            // Start a local transaction.
            transaction = cnn.BeginTransaction("SampleTransaction");

            // Must assign both transaction object and connection
            // to Command object for a pending local transaction
            command.Connection  = cnn;
            command.Transaction = transaction;

            try
            {
                foreach (ScoreModuleInfo module in recSys.ModulesInfo)
                {
                    command.CommandText =
                        "Update RecommendationsModules set active=@arg_active, multiplicator=@arg_multi " +
                        " where descriptor =@arg_desc ";

                    command.Parameters.AddWithValue("@arg_desc", module.Name);
                    command.Parameters.AddWithValue("@arg_active", module.charActive);
                    command.Parameters.AddWithValue("@arg_multi", module.MainMultiplicator);

                    command.ExecuteNonQuery();
                    command.Parameters.RemoveAt("@arg_active");
                    command.Parameters.RemoveAt("@arg_multi");
                    command.Parameters.RemoveAt("@arg_desc");
                    foreach (SubMultiplicator subMulti in module.SubMultiplicators)
                    {
                        command.CommandText =
                            "Update subRecommendators set multpicator=@arg_multi " +
                            " where descriptor =@arg_desc  and  moduleDescriptor =@arg_mod_desc";
                        command.Parameters.AddWithValue("@arg_desc", subMulti.name);
                        command.Parameters.AddWithValue("@arg_mod_desc", module.Name);
                        command.Parameters.AddWithValue("@arg_multi", subMulti.multiplicationValue);
                        command.ExecuteNonQuery();
                        command.Parameters.RemoveAt("@arg_desc");
                        command.Parameters.RemoveAt("@arg_mod_desc");
                        command.Parameters.RemoveAt("@arg_multi");
                    }
                }


                transaction.Commit();
                return(true);
            }
            catch (Exception ex)
            {
                makeConsoleLog("Commit Exception Type: " + ex.GetType().ToString());
                makeConsoleLog("exception message: " + ex.Message);

                // Attempt to roll back the transaction.
                try
                {
                    transaction.Rollback();
                    return(false);
                }
                catch (Exception ex2)
                {
                    makeConsoleLog("Commit Exception Type: " + ex2.GetType().ToString());
                    makeConsoleLog("exception message: " + ex2.Message);
                    // This catch block will handle any errors that may have occurred
                    // on the server that would cause the rollback to fail, such as
                    // a closed connection.
                    return(false);
                }
            }
        }