Exemple #1
0
        /// <summary>
        /// Creates a new mix with a few pathways and mixes references, then inserts that mix in the database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonNewMix_Click(object sender, EventArgs e)
        {
            //Hardcoded crude oil resource ID, could be fetched from the IData class instead
            int CRUDE_RES_ID = 23;
            //Hardcoded pathway IDs
            int CONV_CRD = 34, OILS_CRD = 36;
            //Hardcoded mix ID (for the fun of it)
            int MIX_CRD = 0;

            //Creating a new instance of a mix
            IMix mix = _dataHelper.CreateNewMix("Example4 Mix");

            //Set the resource ID produced by this mix
            _dataHelper.MixSetResource(mix, CRUDE_RES_ID);

            //Retriving pathways to be added to the mix
            IPathway path1 = _controller.CurrentProject.Data.Pathways.ValueForKey(CONV_CRD);
            IPathway path2 = _controller.CurrentProject.Data.Pathways.ValueForKey(OILS_CRD);
            IMix     mix1  = _controller.CurrentProject.Data.Mixes.ValueForKey(MIX_CRD);

            //Adding the different production items to the mix and define their shares
            bool success = _dataHelper.MixAddFeed(mix, path1, 0.3);

            success &= _dataHelper.MixAddFeed(mix, path2, 0.6);
            success &= _dataHelper.MixAddFeed(mix, mix1, 0.1);

            //Inserting the newly created mix to the database
            success &= _dataHelper.DataInsertOrUpdateMix(mix);

            if (success)
            {
                MessageBox.Show("Mix named : '" + mix.Name + "' inserted in dataset");
            }
            else
            {
                MessageBox.Show("Failure");
            }
        }