Exemplo n.º 1
0
    private bool IsMaterialEnough(ItemPair pair)
    {
        var item = ConfigManager.Get <PropItemInfo>(pair.itemId);

        if (item == null)
        {
            return(true);
        }

        switch (item.itemType)
        {
        case PropType.Currency:
            return(modulePlayer.GetMoneyCount((CurrencySubType)item.subType) >= pair.count);
        }

        var  list = moduleEquip.GetBagProps(item.itemType, item.subType);
        uint num  = 0;

        if (list != null && list.Count > 0)
        {
            foreach (var m in list)
            {
                num += m.num;
            }
        }

        return(num >= pair.count);
    }
Exemplo n.º 2
0
    private void _Packet(ScTeamPveTaskInfo rInfo)
    {
        if (rInfo.type != 2)
        {
            return;
        }
        process       = rInfo.nowProcess;
        maxProcess    = rInfo.maxProcess;
        buyTimes      = rInfo.buyTimes;
        maxbuyTimes   = rInfo.maxbuyTimes;
        maxEnterTimes = rInfo.maxenterTimes;
        enterTimes    = rInfo.enterTimes;

        if (costItem == null)
        {
            costItem = new ItemPair[rInfo.cost.Length];
        }
        else
        {
            Array.Resize(ref costItem, rInfo.cost.Length);
        }
        for (var i = 0; i < costItem.Length; i++)
        {
            costItem[i] = new ItemPair()
            {
                itemId = rInfo.cost[i].itemTypeId, count = rInfo.cost[i].price
            }
        }
        ;

        HandleTasks(rInfo.stageInfo);

        DispatchModuleEvent(Response_MatchInfo);
    }
Exemplo n.º 3
0
        private void CustomTestForm_Load(object sender, EventArgs e)
        {
            //Update form text to name of test
            this.Text = "You are now customizing the " + currentTest.TestName + " test!";
            //update ListView with items in the current test
            foreach (Item item in itemList)
            {
                itemsListBox.Items.Add(item);
            }
            //check to see if custom test already exists, if so populate the information
            List <ItemPair> itemPairs = new List <ItemPair>();

            itemPairs = ItemPair.getCustomItemPair(currentTest.TestID);
            if (itemPairs != null)
            {
                isExisting = true;
                foreach (ItemPair listItem in itemPairs)
                {
                    item1ListBox.Items.Add(listItem.Item1);
                    item2ListBox.Items.Add(listItem.Item2);
                }
            }
            if (currentTest.Shuffle == 1)
            {
                shuffleCheckBox.Checked = true;
            }
        }
Exemplo n.º 4
0
        void GoGroups()
        {
            try
            {
                UpdateStatus("Getting group list\r\n");

                XmlDocument xmlDocument = GetAsyncAll("root", "me/groups", "fields=name,id,description");

                XmlNode data = xmlDocument.FirstChild.FirstChild.FirstChild;

                if (data == null)
                {
                    EnableAll();
                    return;
                }

                XmlNodeList list = xmlDocument.FirstChild.ChildNodes;

                foreach (XmlNode nod in list)
                {
                    XmlNodeList lst = nod.ChildNodes;
                    foreach (XmlNode node in lst)
                    {
                        if (node.Name == "data")
                        {
                            XmlNodeList l           = node.ChildNodes;
                            XmlNode     nod1        = GetNode(l, "description");
                            string      description = "";
                            if (nod1 != null)
                            {
                                description = nod1.InnerText;
                            }
                            ItemPair pair = new ItemPair(GetNode(l, "name").InnerText, description, GetNode(l, "id").InnerText);
                            groupList.Add(pair);
                        }
                    }
                }

                Invoke(new Action(() =>
                {
                    foreach (ItemPair group in groupList)
                    {
                        comboBox1.Items.Add(group.text);
                    }

                    EnableAll();

                    comboBox1.SelectedIndex = 0;

                    UpdateStatus("Getting group list done\r\n");
                }));
            }
            catch
            {
                EnableAll();
                ClearAll();

                MessageBox.Show("Probably missing or expired access token");
            }
        }
Exemplo n.º 5
0
 public void addPair(ItemPair pair)
 {
     if (!pairs.ContainsKey(pair))
     {
         pairs.Add(pair, 0);
     }
     pairs[pair]++;
 }
        public double seq(string expectedItem, string givenItem)
        {
            ItemPair pair           = new ItemPair(givenItem, expectedItem);
            double   seqCount       = items.getSeqPairsCount(pair);
            double   givenItemCount = items.getSeqCount(givenItem);

            return(seqCount / givenItemCount);
        }
 private void OnSetData(RectTransform node, ItemPair data)
 {
     Util.SetItemInfo(node, ConfigManager.Get <PropItemInfo>(data.itemId), 0, data.count);
     if (currentNode == null)
     {
         OnSelectItem(node, data);
     }
 }
        private double cp(string expectedItem, string givenItem)
        {
            ItemPair pair           = givenItem.CompareTo(expectedItem) < 0 ? new ItemPair(givenItem, expectedItem) : new ItemPair(expectedItem, givenItem);
            double   pairCount      = items.getAllPairsCount(pair);
            double   givenItemCount = items.getAllCount(givenItem);

            return(pairCount / givenItemCount);
        }
 private void populateSeqPairs(ItemPairsCount seqPairs, string[] seq)
 {
     for (int i = 0; i < seq.Count() - 1; i++)
     {
         ItemPair pair = new ItemPair(seq[i], seq[i + 1]);
         seqPairs.addPair(pair);
     }
 }
Exemplo n.º 10
0
 private void SetClick(RectTransform rt, ItemPair item)
 {
     if (item == null)
     {
         return;
     }
     moduleGlobal.UpdateGlobalTip((ushort)item.itemId, true, false);
 }
Exemplo n.º 11
0
    public override bool Initialize(params object[] p)
    {
        if (!base.Initialize(p))
        {
            return(false);
        }

        confirmButton?.onClick.AddListener(OnConfirm);
        cancelButton?.onClick.AddListener(() => UnInitialize());
        closeButton?.onClick.AddListener(() => UnInitialize());

        if (moduleAwakeMatch.CurrentTask != null)
        {
            var      remainTime = moduleAwakeMatch.maxbuyTimes - moduleAwakeMatch.buyTimes;
            var      time       = moduleAwakeMatch.buyTimes;
            var      costNum    = 0;
            ItemPair costItem   = null;
            bool     isMyself   = moduleAwakeMatch.CurrentTask.taskType == TaskType.Nightmare || (moduleAwakeMatch.CurrentTask.taskType == TaskType.Awake && moduleAwakeMatch.CurrentTaskIsActive);
            if (isMyself)
            {
                remainTime = moduleAwakeMatch.CurrentTask.taskConfigInfo.dayRemainCount -
                             moduleAwakeMatch.CurrentTask.taskData.resetTimes;
                time = moduleAwakeMatch.CurrentTask.taskData.resetTimes;
                var arr = moduleAwakeMatch.CurrentTask.taskConfigInfo.costItem;
                if (arr != null)
                {
                    var index = Mathd.Clamp(time, 0, arr.Length - 1);
                    costItem = arr[index];
                }
            }
            else
            {
                var arr = moduleAwakeMatch.costItem;
                if (arr != null)
                {
                    var index = Mathd.Clamp(time, 0, arr.Length - 1);
                    costItem = arr[index];
                }
            }
            if (costItem != null)
            {
                costNum = costItem.count;
                var prop = ConfigManager.Get <PropItemInfo>(costItem.itemId);
                if (prop)
                {
                    AtlasHelper.SetIcons(costIcon, prop.icon);
                }
            }
            Util.SetText(remainText, Util.Format(ConfigText.GetDefalutString((int)TextForMatType.AwakeStage, 43), remainTime));
            Util.SetText(costText, Util.Format(ConfigText.GetDefalutString((int)TextForMatType.AwakeStage, 44), costNum, modulePlayer.gemCount));
            if (costText)
            {
                costText.color = ColorGroup.GetColor(ColorManagerType.IsMatrialEnough, costNum <= modulePlayer.gemCount);
            }
        }
        return(true);
    }
Exemplo n.º 12
0
 public WarriorPanel(PictureBox show, WarriorList warrior)
 {
     this.show     = show;
     this.warrior  = warrior;
     this.hp       = new ItemPair(ItemPair.key.hp);
     this.speed    = new ItemPair(ItemPair.key.speed);
     this.power    = new ItemPair(ItemPair.key.power);
     this.distance = new ItemPair(ItemPair.key.distance);
 }
Exemplo n.º 13
0
    private void SetInfo(RectTransform rt, ItemPair item)
    {
        if (item == null)
        {
            return;
        }
        var prop = ConfigManager.Get <PropItemInfo>(item.itemId);

        Util.SetItemInfo(rt, prop, 0, item.count);
    }
Exemplo n.º 14
0
    private void OnSetMatrial(RectTransform node, ItemPair data)
    {
        var propInfo = ConfigManager.Get <PropItemInfo>(data.itemId);

        Util.SetItemInfo(node, propInfo, 0, data.count);
        var countText = node.GetComponent <Text>("numberdi/count");

        Util.SetText(countText, Util.Format("{0}/{1}", moduleEquip.GetPropCount(data.itemId), data.count));
        countText.color = ColorGroup.GetColor(ColorManagerType.IsMatrialEnough, IsMatrialEnough(data));
    }
Exemplo n.º 15
0
        /// <summary>
        /// Checks another ItemPair{T1, T2} for equality.
        /// </summary>
        /// <param name="obj">The other instance to check.</param>
        /// <returns>Returns true if the other instance equals this one, false otherwise.</returns>
        public override bool Equals(object obj)
        {
            if (!(obj is ItemPair <T1, T2>))
            {
                return(false);
            }

            ItemPair <T1, T2> other = (ItemPair <T1, T2>)obj;

            return(Equals(other.A, A) && Equals(other.B, B));
        }
Exemplo n.º 16
0
 public int getPairCount(ItemPair pair)
 {
     if (pairs.ContainsKey(pair))
     {
         return(pairs[pair]);
     }
     else
     {
         return(0);
     }
 }
Exemplo n.º 17
0
 private void populateAllPairs(ItemPairsCount allPairs, string[] seq)
 {
     string[] distinctSeq = seq.Distinct().ToArray();
     for (int i = 0; i < distinctSeq.Count() - 1; i++)
     {
         for (int j = i + 1; j < distinctSeq.Count(); j++)
         {
             ItemPair pair = seq[i].CompareTo(seq[j]) < 0 ? new ItemPair(seq[i], seq[j]) : new ItemPair(seq[j], seq[i]);
             allPairs.addPair(pair);
         }
     }
 }
Exemplo n.º 18
0
    private void OnSetData(RectTransform node, ItemPair data)
    {
        if (data == null)
        {
            return;
        }
        var prop = ConfigManager.Get <PropItemInfo>(data.itemId);

        Util.SetItemInfo(node, prop);

        Util.SetText(node.GetComponent <Text>("numberdi/count"), data.count.ToString());
    }
Exemplo n.º 19
0
 public EPListRandomPivotsPriorized(MetricDB DB, int seed, int num_pivs)
 {
     var n = DB.Count;
     this.Items = new ItemPair[n];
     var pivs = new List<EPivot> (32);
     var rand = new Random (seed);
     var pivsel = new PivotSelector (n, rand);
     var piv = pivsel.NextPivot ();
     var pivOBJ = DB [piv];
     for (int objID = 0; objID < n; ++objID) {
         var d = DB.Dist(pivOBJ, DB[objID]);
         this.Items[objID] = new ItemPair(0, d);
     }
     double mean, variance;
     this.Statistics (out mean, out variance);
     pivs.Add(new EPivot(piv, Math.Sqrt(variance), mean, 0, 0, 0, 0));
     var item_cmp = new Comparison<ItemPair>((x,y) => {
         var diff_x = Math.Abs (x.dist - pivs[x.objID].mean);
         var diff_y = Math.Abs (y.dist - pivs[y.objID].mean);
         return diff_x.CompareTo(diff_y);
     });
     var queue = new SkipList2<int> (0.5, (x,y) => item_cmp (this.Items [x], this.Items [y]));
     for (int objID = 0; objID < n; ++objID) {
         queue.Add(objID, null);
     }
     var max_review = 2 * n / num_pivs;
     var list = new List<int> ();
     for (int i = 0; i < num_pivs; ++i) {
         Console.WriteLine("XXXXXX BEGIN {0} i: {1}", this, i);
         piv = pivsel.NextPivot();
         double piv_mean, piv_variance, qrad;
         PivotSelector.EstimatePivotStatistics(DB, rand, DB[piv], 256, out piv_mean, out piv_variance, out qrad);
         var pivID = pivs.Count;
         pivs.Add(new EPivot(piv, Math.Sqrt(piv_variance), mean, 0, 0, 0, 0));
         list.Clear();
         for (int s = 0; s < max_review; ++s) {
             var objID = queue.RemoveFirst();
             var d = DB.Dist(DB[objID], pivOBJ);
             var new_item = new ItemPair(pivID, d);
             if (item_cmp(new_item, this.Items[objID]) > 0) {
                 this.Items[objID] = new_item;
             }
             list.Add (objID);
         }
         foreach (var objID in list) {
             queue.Add(objID, null);
         }
         Console.WriteLine("XXXXXX END {0} i: {1}", this, i);
     }
     this.Pivs = pivs.ToArray ();
     Console.WriteLine("Number of pivots per group: {0}", this.Pivs.Length);
 }
Exemplo n.º 20
0
        private void OnSearch(object sender, TextChangedEventArgs e)
        {
            List <ItemPair> _listFiltered = new List <ItemPair>();


            if (string.IsNullOrEmpty(e.NewTextValue))
            {
                ListItems1.ItemsSource = ItemList;
            }

            else
            {
                List <Item> _itemSearch = new List <Item>();

                foreach (var prod in ItemList)
                {
                    if (prod.Item1.Name.ToLower().Contains(e.NewTextValue))
                    {
                        _itemSearch.Add(prod.Item1);
                    }

                    try
                    {
                        if (prod.Item2.Name.ToLower().StartsWith(e.NewTextValue))
                        {
                            _itemSearch.Add(prod.Item2);
                            //prod.Item1.IsVisible = false;
                        }
                    }
                    catch
                    {
                    }
                }


                for (int i = 0; i <= _itemSearch.Count; i = i + 1)
                {
                    if (i < _itemSearch.Count - 1)
                    {
                        ItemPair pp = new ItemPair(_itemSearch[i], _itemSearch[i + 1]);
                        _listFiltered.Add(pp);
                    }
                    else if (i == _itemSearch.Count - 1)
                    {
                        ItemPair pp = new ItemPair(_itemSearch[i], null);
                        _listFiltered.Add(pp);
                    }
                }

                ListItems1.ItemsSource = _listFiltered;
            }
        }
Exemplo n.º 21
0
Arquivo: KVP.cs Projeto: sadit/natix
        /// <summary>
        /// Build the index
        /// </summary>
        public virtual void Build(MetricDB db, int k, int m)
        {
            this.DB = db;
            var n = this.DB.Count;
            this.K = k;
            this.pivs.AddRange (RandomSets.GetRandomSubSet (m, n));

            this.ispivot.Capacity = this.assocpivots.Capacity = n;
            this.ispivot.Clear ();
            this.assocpivots.Clear ();

            for (int objID = 0; objID < n; ++objID) {
                this.assocpivots.Add (new ItemPair[k + k]);
                this.ispivot.Add (0);
            }

            for (int pivID = 0; pivID < m; ++pivID) {
                var objID = this.pivs [pivID];
                this.ispivot [objID] = 1;
            }

            for (int objID = 0; objID < n; ++objID) {
                var near = new Result (k);
                var far = new Result (k);
                var obj = this.DB [objID];
                for (int pivID = 0; pivID < m; ++pivID) {
                    var piv = this.DB [this.pivs [pivID]];
                    var d = this.DB.Dist (obj, piv);
                    near.Push (pivID, d); // this can be buggy when k * 2 < n or dist() is too flat
                    far.Push (pivID, -d);
                }
                var _assoc = this.assocpivots [objID];

                {
                    int i = 0;
                    foreach (var p in near) {
                        _assoc [i] = new ItemPair (p.ObjID, p.Dist);
                        ++i;
                    }
                    foreach (var p in far) {
                        _assoc [i] = new ItemPair (p.ObjID, -p.Dist);
                        ++i;
                    }
                }
                if (objID % 5000 == 0) {
                    Console.WriteLine ("=== db: {0}, k: {1}, available: {2}, advance: {3}/{4}, timestamp: {5}",
                                       Path.GetFileName(db.Name), k, m, objID+1, n, DateTime.Now);
                }
            }
        }
Exemplo n.º 22
0
    private void OnSetData(RectTransform node, ItemPair data)
    {
        var prop = ConfigManager.Get <PropItemInfo>(data.itemId);

        if (prop == null)
        {
            Logger.LogError($"无效的道具ID = {data.itemId}");
            return;
        }
        Util.SetItemInfo(node, prop, 0, data.count, false);

        var b = node.GetComponentDefault <Button>();

        b.onClick.RemoveAllListeners();
        b.onClick.AddListener(() => { Module_Global.instance.UpdateGlobalTip((ushort)data.itemId, true, false); });
    }
Exemplo n.º 23
0
        private void Form1_Load(object sender, EventArgs e)
        {
            testButton.Enabled = false;
            //Load itemPairs that was selected in test selection form
            if (currentTest.CustomTest == 1)
            {
                itemPairList = ItemPair.getCustomItemPair(currentTest.TestID);
            }
            else
            {
                UserTestLogic.getItemPair(currentTest.TestID, itemPairList);
            }
            // Get Item Pairs and populate groupbox
            populateGroupBox(itemPairList, itemPairListIndex);

            // Load denominator for Progress Bar
            denominatorChange(itemPairList.Count);
        }
Exemplo n.º 24
0
        private void change(object sender, EventArgs e)
        {
            Button      tmp      = sender as Button;
            ItemPair    obj      = findButtonIndex(tmp);
            WarriorList warr     = findWarriorFromItem(obj);
            int         errValue = 0;

            switch (obj.item)
            {
            case ItemPair.key.hp:
                errValue = Program.player.UpHp(warr);
                break;

            case ItemPair.key.speed:
                errValue = Program.player.UpSpeed(warr);
                break;

            case ItemPair.key.power:
                errValue = Program.player.UpPower(warr);
                break;

            case ItemPair.key.distance:
                errValue = Program.player.UpDistance(warr);
                break;
            }

            if (errValue > 0)
            {
                _coin.Text = "Coin:" + Program.player.coin;
                warriorsPanels[(int)warr - 1].update();
                //  message
                message.Enqueue("消耗了 " + errValue + " Coin");
            }
            else if (errValue < 0)
            {
                message.Enqueue("你的錢不夠,需要" + (-errValue).ToString() + "Coin");
            }
            else
            {
                message.Enqueue("這項不能升級");
            }
            showMessage();
        }
    private void OnSelectItem(RectTransform node, ItemPair data)
    {
        drawingItem = data;
        currentNode = node;
        var prop = ConfigManager.Get <PropItemInfo>(data.itemId);

        if (null == prop)
        {
            return;
        }

        selectBox?.SetParent(node);
        selectBox?.SafeSetActive(true);
        if (null != selectBox)
        {
            selectBox.localPosition = Vector3.zero;
        }
        Util.SetText(itemName, prop.itemName);
        Util.SetText(itemDesc, prop.desc);
    }
Exemplo n.º 26
0
    public void ShowDetail(PReward reward)
    {
        List <ItemPair> list = new List <ItemPair>();

        if (reward.diamond > 0)
        {
            var p = new ItemPair
            {
                itemId = 2,
                count  = reward.diamond
            };
            list.Add(p);
        }

        if (reward.coin > 0)
        {
            var p = new ItemPair
            {
                itemId = 1,
                count  = reward.coin
            };
            list.Add(p);
        }

        if (reward.fatigue > 0)
        {
            var p = new ItemPair
            {
                itemId = 15,
                count  = reward.fatigue
            };
            list.Add(p);
        }
        foreach (var p in reward.rewardList)
        {
            list.Add(new ItemPair {
                itemId = p.itemTypeId, count = (int)p.num
            });
        }
        ShowDetail(list);
    }
Exemplo n.º 27
0
 private WarriorList findWarriorFromItem(ItemPair obj)
 {
     foreach (WarriorPanel each in warriorsPanels)
     {
         if (each.hp == obj)
         {
             return(each.warrior);
         }
         if (each.speed == obj)
         {
             return(each.warrior);
         }
         if (each.power == obj)
         {
             return(each.warrior);
         }
         if (each.distance == obj)
         {
             return(each.warrior);
         }
     }
     return(WarriorList.Castle);
 }
Exemplo n.º 28
0
        static int CompareItemPair(ItemPair x, ItemPair y)
        {
            string x1 = "";
            string y1 = "";

            int pos = 0;

            for (int i = 0; i < x.text.Length; i++)
            {
                if (x.text[i] != ' ')
                {
                    pos = i;
                    break;
                }
            }
            for (int i = pos; i < x.text.Length; i++)
            {
                x1 += x.text[i];
            }

            pos = 0;
            for (int i = 0; i < y.text.Length; i++)
            {
                if (y.text[i] != ' ')
                {
                    pos = i;
                    break;
                }
            }
            for (int i = pos; i < y.text.Length; i++)
            {
                y1 += y.text[i];
            }

            return(x1.CompareTo(y1));
        }
Exemplo n.º 29
0
        public string this[string key]
        {
            get
            {
                lock (_syncRoot)
                {
                    ItemPair item = _innerSettings.FirstOrDefault(t => t.Key == key);
                    if (item != null)
                    {
                        return(item.Value);
                    }

                    return(null);
                }
            }
            set
            {
                lock (_syncRoot)
                {
                    ItemPair item = _innerSettings.FirstOrDefault(t => t.Key == key);
                    if (item != null)
                    {
                        item.Value = value;
                    }
                    else
                    {
                        _innerSettings.Add(new ItemPair()
                        {
                            Key = key, Value = value
                        });
                    }

                    _changed = true;
                }
            }
        }
Exemplo n.º 30
0
 protected bool Equals(ItemPair other)
 {
     return((Equals(A, other.A) && Equals(B, other.B)) ||
            (Equals(A, other.B) && Equals(B, other.A)));
 }
Exemplo n.º 31
0
Arquivo: KVP.cs Projeto: sadit/natix
        public override void Load(BinaryReader Input)
        {
            base.Load(Input);
            var n = this.DB.Count;
            this.K = Input.ReadInt32();
            int m = Input.ReadInt32 ();
            PrimitiveIO<int>.LoadVector (Input, m, this.pivs);
            PrimitiveIO<byte>.LoadVector (Input, n, this.ispivot);

            var kk = this.K + this.K;
            for (int i = 0; i < n; ++i) {
                var parray = new ItemPair[kk];
                CompositeIO<ItemPair>.LoadVector (Input, kk, parray);
                this.assocpivots.Add (parray);
            }
        }
Exemplo n.º 32
0
        // Changes the radio buttons based content in array
        public List <Item> populateRadio(ItemPair itemPair)
        {
            // Randomizes where the item pairs are assigned to the userChoice Radio boxes: Kevin Khlom Sprint 2
            List <Item> itemToAssign = new List <Item>();

            // Function that randomizes the pairings
            UserTestLogic.itemToAssign(itemPair, itemToAssign, currentTest);
            //Gets the test type and sets the text/images accordingly
            int    i           = 0;
            string errorString = "Error getting test type: ";

            if (TestList.getTestType(ref testType, currentTest.TestID, ref errorString))
            {
                if (testType == "T")
                {
                    //
                    // userChoiceOne
                    //
                    this.userChoiceOne.Location = new System.Drawing.Point(61, 49);
                    //
                    // userChoiceTwo
                    //
                    this.userChoiceTwo.Location = new System.Drawing.Point(165, 49);
                    //
                    // userChoiceThree
                    //
                    this.userChoiceThree.Location = new System.Drawing.Point(269, 49);
                    //
                    // testButton
                    //
                    this.testButton.Location = new System.Drawing.Point(214, 275);
                    //
                    // directionLabel
                    //
                    this.directionLabel.Location = new System.Drawing.Point(150, 96);
                    //
                    // finishedLabel
                    //
                    this.finishedLabel.Location = new System.Drawing.Point(54, 44);
                    //
                    // testProgressBar
                    //
                    this.testProgressBar.Location = new System.Drawing.Point(197, 372);
                    //
                    // numeratorLabel
                    //
                    this.numeratorLabel.Location = new System.Drawing.Point(416, 372);
                    //
                    // slashLabel
                    //
                    this.slashLabel.Location = new System.Drawing.Point(433, 372);
                    //
                    // denominatorLabel
                    //
                    this.denominatorLabel.Location = new System.Drawing.Point(449, 372);
                    //
                    // itemGroupBox
                    //
                    this.itemGroupBox.Location = new System.Drawing.Point(79, 142);
                    this.itemGroupBox.Size     = new System.Drawing.Size(440, 100);
                    //
                    // UserTest
                    //
                    this.ClientSize = new System.Drawing.Size(600, 426);
                }
                foreach (Control control in itemGroupBox.Controls)
                {
                    if (control is RadioButton)
                    {
                        control.Width = 300;
                        ((RadioButton)control).BackColor = Color.Transparent;
                        if (currentTest.TestType == "T")
                        {
                            control.Text = itemToAssign[i].Name;
                        }
                        else if (currentTest.TestType == "I")
                        {
                            if (itemToAssign[i].ItemImage != null)
                            {
                                ((RadioButton)control).TextImageRelation = TextImageRelation.TextAboveImage;
                                ((RadioButton)control).Image             = itemToAssign[i].getImage();
                            }
                            else
                            {
                                ((RadioButton)control).Image = Properties.Resources.Undecided;
                            }
                        }
                        else if (currentTest.TestType == "TI")
                        {
                            if (itemToAssign[i].ItemImage != null)
                            {
                                ((RadioButton)control).TextImageRelation = TextImageRelation.TextAboveImage;
                                ((RadioButton)control).Image             = itemToAssign[i].getImage();
                            }
                            else
                            {
                                ((RadioButton)control).Image = Properties.Resources.Undecided;
                            }
                            control.Text = itemToAssign[i].Name;
                        }
                    }
                    i++;
                }
            }
            return(itemToAssign);
        }
Exemplo n.º 33
0
        private void finishButton_Click(object sender, EventArgs e)
        {
            //Time to validate data.

            /* Validate Requirements
             * 1) Item1.Count == Item2.Count
             * 2) Item1.Name != Item2.Name on the same index
             * 3) If 0 pairs given, no custom pairs written
             * 4) if 3 or more pairs, write to database
             * 5) if 1 or 2 pairs, throw error message
             */

            if (item1ListBox.Items.Count < 1 || item2ListBox.Items.Count < 1)
            {
                //validation 3, 0 pairs are given. save shuffle option only
                if (isExisting)
                {
                    bool delResult = ItemPair.delCustomItemPair(currentTest.TestID, strError);
                    if (!delResult)
                    {
                        MetroMessageBox.Show(this, "The following error has occurred: " + strError, "Error Adding Items!",
                                             MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                Test.updateCustomTest(currentTest.TestID, 0, intShuffleBit);
                //shuffle option successfully saved. Party up!
                myNotifyIcon.BalloonTipTitle = "Custom Test Saved";
                myNotifyIcon.BalloonTipText  = "The changes to " + currentTest.TestName + " Test have been saved!";
                myNotifyIcon.Icon            = SystemIcons.Information;
                myNotifyIcon.Visible         = true;
                myNotifyIcon.ShowBalloonTip(2000);
                return;
            }
            if (item1ListBox.Items.Count != item2ListBox.Items.Count)
            {
                //validation 1 failed, items mismatch
                //Remove extra items and save?
                DialogResult result = MetroMessageBox.Show(this, "The number of items don't match, would you like to remove extra items?",
                                                           "Remove Extra Items?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (result == DialogResult.Yes)
                {
                    //remove extra results
                    if (item1ListBox.Items.Count > item2ListBox.Items.Count)
                    {
                        for (int i = item1ListBox.Items.Count; i > item2ListBox.Items.Count; i--)
                        {
                            item1ListBox.Items.RemoveAt(i - 1);
                        }
                    }
                    else
                    {
                        for (int i = item2ListBox.Items.Count; i > item1ListBox.Items.Count; i--)
                        {
                            item2ListBox.Items.RemoveAt(i - 1);
                        }
                    }
                    //Continue validation to ensure number of pairs is still valid
                }
                else
                {
                    return;
                }
            }
            if (item1ListBox.Items.Count < 3 || item2ListBox.Items.Count < 3)
            {
                //validation 5 failed, throw error
                MetroMessageBox.Show(this, "You must enter at least 3 pairs of items!", "Not Enough Pairs",
                                     MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            for (int x = 0; x < item1ListBox.Items.Count; x++)
            {
                Item item1 = (Item)item1ListBox.Items[x];
                Item item2 = (Item)item2ListBox.Items[x];
                if (item1.ItemID == item2.ItemID)
                {
                    MetroMessageBox.Show(this, "You cannot compare an item against itself!", "Invalid Comparison",
                                         MessageBoxButtons.OK, MessageBoxIcon.Error);
                    item1ListBox.SelectedIndex = x;
                    item2ListBox.SelectedIndex = x;
                    return;
                }
            }
            //All validation has been made, we will write items to database
            List <ItemPair> pairList = new List <ItemPair>();

            for (int x = 0; x < item1ListBox.Items.Count; x++)
            {
                ItemPair pair = new ItemPair();
                pair.Item1 = (Item)item1ListBox.Items[x];
                pair.Item2 = (Item)item2ListBox.Items[x];
                pairList.Add(pair);
            }
            if (isExisting)
            {
                bool delResult = ItemPair.delCustomItemPair(currentTest.TestID, strError);
                if (!delResult)
                {
                    MetroMessageBox.Show(this, "The following error has occurred: " + strError, "Error Adding Items!",
                                         MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            if (item1ListBox.Items.Count > 0)
            {
                bool addResult = ItemPair.addCustomItemPair(pairList, currentTest.TestID, strError);
                if (!addResult)
                {
                    MetroMessageBox.Show(this, "The following error has occurred: " + strError, "Error Adding Items!",
                                         MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                Test.updateCustomTest(currentTest.TestID, 1, intShuffleBit);
                isExisting = true;
                //items successfully saved. Party up!
                myNotifyIcon.BalloonTipTitle = "Custom Test Saved";
                myNotifyIcon.BalloonTipText  = "The changes to " + currentTest.TestName + " Test have been saved!";
                myNotifyIcon.Icon            = SystemIcons.Information;
                myNotifyIcon.Visible         = true;
                myNotifyIcon.ShowBalloonTip(2000);
            }
        }