Exemplo n.º 1
0
    public void Set(DXFStructure dxf, INSERT insert)
    {
        gameObject.name = "Insert_" + insert.C2;

        var block = dxf.BLOCKS.BLOCKList.FirstOrDefault(x => x.C2 == insert.C2);

        if (block == null)
        {
            Debug.Log(insert.C2);
            return;
        }

        DrawLINEList(dxf, block.LINEList, (float)insert.C41, (float)insert.C42);
        DrawLWPOLYLINEList(dxf, block.LWPOLYLINEList, (float)insert.C41, (float)insert.C42);
        DrawTEXTList(dxf, block.TEXTList, (float)insert.C41, (float)insert.C42);
        DrawCIRCLEList(dxf, block.CIRCLEList, (float)insert.C41, (float)insert.C42);
        DrawARCList(dxf, block.ARCList, (float)insert.C41, (float)insert.C42);
        //DrawINSERTList(dxf, block.INSERTList, (float)insert.C41, (float)insert.C42);
        DrawELLIPSEList(dxf, block.ELLIPSEList, (float)insert.C41, (float)insert.C42);

        this.transform.position         = new Vector3((float)insert.C10, (float)insert.C20, (float)insert.C30);
        this.transform.localEulerAngles = new Vector3(0, 0, (float)insert.C50);

        this.gameObject.isStatic = true;
    }
Exemplo n.º 2
0
        //must use the stack to navigate to the appropriate leaf so that
        //splits can word back up the tree
        public bool AddValue(int n)
        {
            stack = new Stack <Node>(500 / NodeSize);   //make the stack about the right size based on a 500 value tree
            if (Root.Indexes.Count == 0)
            {
                Leaf firstLeaf = new Leaf(NodeSize);
                firstLeaf.Insert(n);
                Root.Insert(n, firstLeaf);
                return(true);
            }
            //TODO somehting isnt right here
            else
            {
                Leaf leaf = FindLeaf(n);

                INSERT result = leaf.Insert(n);
                if (result == INSERT.SUCCESS)
                {
                    //an unfinished thought. Might need to resort back up the tree if lowest value changed
                    //stack.Pop();
                    //while (stack.Count > 0)
                    //{
                    //    stack.
                    //}
                    return(true);
                }
                if (result == INSERT.NEEDSPLIT)
                {
                    SplitLeaf(leaf);
                }

                return(true);
            }
        }
Exemplo n.º 3
0
		}//End BTree (int)

		#endregion Constructors

		#region Methods

		/// <summary>
		/// Adds the value.
		/// </summary>
		/// <param name="nValueToAdd">The n value to add.</param>
		/// <returns>If value was successfully added</returns>
		public bool AddValue (int nValueToAdd)
		{
			if (FindValue (nValueToAdd))
			{
				return false;
			}//End if statement
			 //Used for the start of the program when root is a leaf
			if (Root.IsLeaf)
			{
				Root = (Leaf) stack.Pop ( );
				INSERT temp = Root.Insert (nValueToAdd);
				switch (temp)
				{
					case INSERT.NEEDSPLIT:
						Leaf tempLeaf = (Leaf) Root;
						Root = new Index (NodeSize);
						SplitLeaf (tempLeaf, nValueToAdd);
						stack.Push (Root);
						IndexCount++;
						Index tempIndex = (Index) Root;
						break;

					case INSERT.SUCCESS:
						stack.Push (Root);
						break;

					default:
						break;
				}//End switch statement
			}//End if statement	TEST
			else
			{
				Leaf addLeaf = FindLeaf (nValueToAdd);
				INSERT temp = addLeaf.Insert (nValueToAdd);
				switch (temp)
				{
					case INSERT.NEEDSPLIT:
						;
						SplitLeaf (addLeaf, nValueToAdd);
						break;

					case INSERT.SUCCESS:
						break;

					default:
						break;
				}//End switch statement
			}//End else statement TEST
			if (!Root.IsLeaf || trace)
			{
				ReturnToTop ( );
			}//End if statement
			Count++;
			return true;
		}//End AddValue (int)
Exemplo n.º 4
0
        public static void RegisterProfile(string data)
        {
            try
            {
                var req = INSERT.InsertRequest("users", Items.GetRegisterList(), Items.SetRegisterList(data));
                RequestToDB.CreateRequest(req, "RegistrationRequest");
            }

            catch (Exception ex)
            {
                FormsManaging.TextGenerator(ex.ToString());
            }
        }
Exemplo n.º 5
0
        private void SplitIndex(Node overFilledNode)
        {
            int   halfCount = (overFilledNode.Value.Count + 1) / 2;
            Index newIndex  = new Index(NodeSize);

            overFilledNode = (Index)overFilledNode;


            //if stack count = 1 then top of stack = root
            if (stack.Count == 1)
            {
                //do root splitting specific stuff
                Index newRoot = new Index(NodeSize);
                //Console.WriteLine("halfcount" + halfCount);

                for (int i = 0; i < halfCount; i++)
                {
                    //Console.WriteLine("i: " + i);
                    newIndex.Insert(overFilledNode.Value[overFilledNode.Value.Count - 1], overFilledNode.Indexes[overFilledNode.Indexes.Count - 1]); //add last from overloaded indexes
                    overFilledNode.Value.RemoveAt(overFilledNode.Value.Count - 1);                                                                   //remove last from overloaded index values
                    overFilledNode.Indexes.RemoveAt(overFilledNode.Indexes.Count - 1);                                                               //remove last from overloaded index indexes
                }



                stack.Pop();
                INSERT result = (newRoot.Insert(overFilledNode.Value[0], overFilledNode));
                result = (newRoot.Insert(newIndex.Value[0], newIndex));
                Root   = newRoot;
            }

            if (stack.Count > 1)
            {
                //do regular index split
                //Console.WriteLine("halfcount" + halfCount);
                for (int i = 0; i < halfCount; i++)
                {
                    //  Console.WriteLine("i: " + i);
                    newIndex.Insert(overFilledNode.Value[overFilledNode.Value.Count - 1], overFilledNode.Indexes[overFilledNode.Indexes.Count - 1]); //add last from overloaded indexes
                    overFilledNode.Value.RemoveAt(overFilledNode.Value.Count - 1);                                                                   //remove last from overloaded index values
                    overFilledNode.Indexes.RemoveAt(overFilledNode.Indexes.Count - 1);                                                               //remove last from overloaded index indexes
                }

                stack.Pop();
                INSERT result = ((Index)stack.Peek()).Insert(newIndex.Value[0], newIndex);
                if (result == INSERT.NEEDSPLIT)
                {
                    SplitIndex(stack.Peek());
                }
            }
        }
Exemplo n.º 6
0
        private void Button_Them_Click(object sender, RoutedEventArgs e)
        {
            PHIEUHANG phieuHang = new PHIEUHANG();

            if (tbMaHang.Text != "" && tbMaKhach.Text != "" && tbSoCT.Text != "" &&
                tbSoLuong.Text != "" && tbDienGiai.Text != "" && datePicker.Text != "")
            {
                phieuHang.NGAY        = datePicker.SelectedDate.Value;
                phieuHang.SOCHUNGTU   = tbSoCT.Text;
                phieuHang.MAKHACHHANG = tbMaKhach.Text;
                phieuHang.DIENGIAI    = tbDienGiai.Text;
                phieuHang.MAHANG      = tbMaHang.Text;
                if (LoaiPhieu == 1)
                {
                    phieuHang.SOLUONG = Int32.Parse(tbSoLuong.Text);
                }
                else
                {
                    phieuHang.SOLUONG = -Int32.Parse(tbSoLuong.Text);
                }
                phieuHang.LOAIPHIEU = (byte)LoaiPhieu;

                // Kiểm tra dữ liệu nhập
                if (QUERY.KiemTraSoChungTu(phieuHang.SOCHUNGTU))
                {
                    MessageBox.Show("Số chứng từ đã tồn tại", "Thông báo");
                }
                else if (QUERY.KiemTraMaKhachHang(phieuHang.MAKHACHHANG) == false)
                {
                    MessageBox.Show("Không tồn tại mã khách hàng", "Thông báo");
                }
                else if (QUERY.KiemTraMaHang(phieuHang.MAHANG) == false)
                {
                    MessageBox.Show("Không tồn tại mã hàng", "Thông báo");
                }
                else   // Thêm phiếu hàng
                {
                    INSERT.ThemPhieuHang(phieuHang);
                    UPDATE.SuaSoLuongSanPham(phieuHang.MAHANG, (int)phieuHang.SOLUONG);
                    MessageBox.Show("Thêm thành công", "Thông báo");
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show("Chưa nhập đủ thông tin", "Thông báo");
            }
        }
Exemplo n.º 7
0
		}//End SplitIndex (Index, Node, int)

		 /// <summary>
		 /// Splits the leaf.
		 /// </summary>
		 /// <param name="leaf">The leaf.</param>
		 /// <param name="nInsertedValue">The n inserted value.</param>
		public void SplitLeaf (Leaf leaf, int nInsertedValue)
		{
			Index newRoot = (Index) Root;
			Leaf leafLess = new Leaf (NodeSize);
			Leaf leafMore = new Leaf (NodeSize);
			List<int> values = new List<int> (NodeSize);
			double half = (double) (NodeSize) / 2.0;
			int postion = (int) Math.Ceiling (half) - 1;
			int numberofSplit;
			for (int i = 0 ; i < NodeSize - 1 ; i++)
			{
				values.Add (leaf.Value [i]);
			}//end for loop
			values.Add (nInsertedValue);
			values.Sort ( );
			numberofSplit = values [(int) half];
			for (int i = 0 ; i < (int) Math.Ceiling (half) - 1 ; i++)
			{
				leafLess.Insert (values [i]);
			}//end for loop
			for (int i = (int) Math.Ceiling (half) ; i < NodeSize ; i++)
			{
				leafMore.Insert (values [i]);
			}//end for loop
			INSERT results = newRoot.Insert (numberofSplit);
			if (IndexCount > 0)
			{
				int pos = newRoot.Indexes.IndexOf (leaf);
				newRoot.Indexes.RemoveAt (pos);
			}//End if statement
			if (results == INSERT.NEEDSPLIT)
			{
				Index OverPacked = new Index (NodeSize);
				OverPacked.Insert (leafLess);
				OverPacked.Insert (leafMore);
				SplitIndex (newRoot, OverPacked, values [(int) half]);
			}//End if statement
			else
			{
				newRoot.Insert (leafLess);
				newRoot.Insert (leafMore);
			}//End else statement
			LeafCount++;
		}//End SplitLeaf (Leaf, int)
Exemplo n.º 8
0
        private void SplitLeaf(Leaf leaf)
        {
            Leaf newLeaf   = new Leaf(leaf);
            int  halfCount = (leaf.Value.Count + 1) / 2;

            Console.WriteLine("halfcount" + halfCount);
            for (int i = 0; i < halfCount; i++)
            {
                Console.WriteLine("i: " + i);
                newLeaf.Insert(leaf.Value[leaf.Value.Count() - 1]); //add last from overloaded leaf
                newLeaf.Value.RemoveAt(0);
                leaf.Value.RemoveAt(leaf.Value.Count - 1);          //remove last from overloaded leaf
            }

            stack.Pop();
            Index  parent = (Index)stack.Peek();
            INSERT result = parent.Insert(newLeaf.Value[0], newLeaf);

            if (result == INSERT.NEEDSPLIT)
            {
                SplitIndex(stack.Peek());
            }
        }
Exemplo n.º 9
0
 public static void SetUserScores(string data, int id)
 {
     var request = INSERT.InsertRequest("scores", "score", data);
     //RequestToDB.CreateRequest(request,"SetScoreRequest", id);
 }
Exemplo n.º 10
0
 public static void CreateTable(string username, int id)
 {
     var data = INSERT.InsertRequest("scores", "username", username);
     //RequestToDB.CreateRequest(data, "CreateTable", id);
 }
Exemplo n.º 11
0
        /// <summary>
        /// Method for adding a value to the BTree
        /// </summary>
        /// <param name="value">Represents the value to be added</param>
        /// <returns>Boolean representing if the value was added successfully or not</returns>
        public bool AddValue(int value)
        {
            #region Initialize first value and Root

            if (NodeCount == 0)
            {
                Index FirstIndex = new Index(NodeSize);
                Leaf  FirstLeaf  = new Leaf(NodeSize);

                //Add value to the first Index and Leaf
                FirstIndex.Items.Add(value);
                FirstLeaf.Items.Add(value);

                //Reference initial and first Leaf
                FirstIndex.LeafList.Add(new Leaf(NodeSize));
                FirstIndex.LeafList.Add(FirstLeaf);

                //Set IndexLevel
                FirstIndex.IndexLevel = 0;

                //Add index to IndexList and Root
                Root = new Index(FirstIndex);


                //Increment Counts
                NodeCount += 3;
                TreeIndexes++;
                TreeLeaves += 2;

                return(true);
            }

            #endregion

            #region Attempt to put value into a Leaf

            else
            {
                //Find Leaf to insert value
                Leaf   LeafToFill = FindLeaf(value);
                INSERT response   = LeafToFill.Insert(value);
                if (response == INSERT.DUPLICATE)
                {
                    //Do nothing since you need a unique new value
                    return(false);
                }
                else if (response == INSERT.NEEDSPLIT)
                {
                    //Split Leaf and Indexes if needed
                    SplitLeaf(LeafToFill);
                    return(true);
                }
                else
                {
                    //Success!
                    return(true);
                }
            }

            #endregion
        }
Exemplo n.º 12
0
        public static void SetUserScores(string data)
        {
            var request = INSERT.InsertRequest($"scores", "score", data);

            RequestToDB.CreateRequest(request, "SetScoreRequest");
        }
Exemplo n.º 13
0
		}//End FindValue (int)

		 /// <summary>
		 /// Splits the index.
		 /// </summary>
		 /// <param name="nodeToBeSplit">The node to be split.</param>
		 /// <param name="nodeToBeAddes">The node to be addes.</param>
		 /// <param name="valueToBeAdded">The value to be added.</param>
		public void SplitIndex (Index nodeToBeSplit, Node nodeToBeAddes, int valueToBeAdded)
		{
			#region Variables

			Index rootIndex = new Index (NodeSize);
			Index addIndex = new Index (NodeSize);
			try
			{
				addIndex = (Index) nodeToBeAddes;
			}
			catch (Exception e)
			{
				Console.WriteLine (e.Message);
			}
			int Size = (nodeToBeSplit.Indexes.Count + addIndex.Indexes.Count);
			List<int> values = new List<int> (Size);
			List<Node> indexes = new List<Node> (NodeSize + 1);
			Index IndexLess = new Index (NodeSize);
			Index IndexMore = new Index (NodeSize);
			double half = (double) (NodeSize) / 2.0;
			int postion = (int) Math.Ceiling (half) - 1;
			int numberofSplit;

			#endregion Variables

			#region Inner Methods

			/// <summary>
			/// Splits the index.
			/// </summary>
			/// <param name="size">The size.</param>
			/// <param name="list">The list.</param>
			/// <returns>List of values</returns>
			List<int> getValues (int size, List<int> list)
			{
				List<int> pulled = new List<int> (size);
				for (int i = 0 ; i < size - 1 ; i++)
				{
					pulled.Add (list [i]);
				}//end for loop
				return pulled;
			}
			/// <summary>
			/// Gets the indexes.
			/// </summary>
			/// <param name="size">The size.</param>
			/// <param name="list">The list.</param>
			/// <param name="listTwo">The list two.</param>
			/// <returns>List of indexes</returns>
			List<Node> getIndexes (int size, List<Node> list, List<Node> listTwo)
			{
				List<Node> pulled = new List<Node> (size);
				for (int i = 0 ; i < list.Count ; i++)
				{
					pulled.Add (list [i]);
					if (list [i].Value.Count > 1)
					{
					}//End if statement
				}//end for loop
				for (int i = 0 ; i < listTwo.Count ; i++)
				{
					pulled.Add (listTwo [i]);
				}//end for loop

				return pulled;
			}

			#region Sort

			/// <summary>
			/// Sinks the sort.
			/// </summary>
			/// <param name="list">The list.</param>
			void Sort ( )
			{
				List<int> indexValues = new List<int> ( );
				for (int i = 0 ; i < indexes.Count ; i++)
				{
					indexValues.Add (indexes [i].Value [0]);
				}//end for loop
				bool sorted = false;
				int pass = 0;

				while (!sorted && (pass < indexValues.Count))
				{
					//if (sorted)
					//{
					//	indexValues.Clear ( );
					//	for (int i = 0 ; i < indexes.Count ; i++)
					//	{
					//		indexValues.Add (indexes [i].Value [0]);
					//	}//end for loop
					//}//End if statement
					pass++;
					sorted = true;
					for (int i = 0 ; i < indexValues.Count - pass ; i++)
					{
						if (indexValues [i] > indexValues [i + 1])
						{
							Swap (indexValues, i, i + 1);
							sorted = false;
						}//End if statement
					}//End for loop
				}//End while loop
			}//End Sort (List<int>)
			 /// <summary>
			 /// Swaps the specified list.
			 /// </summary>
			 /// <param name="list">The list.</param>
			 /// <param name="i">The i.</param>
			 /// <param name="v">The v.</param>
			void Swap (List<int> list, int i, int v)
			{
				Node temp = indexes [i];
				int listTemp = list [i];
				indexes [i] = indexes [v];
				list [i] = list [v];
				indexes [v] = temp;
				list [v] = listTemp;
			}//End Swap (List<int>, int, int)

			#endregion Sort

			#endregion Inner Methods

			values = getValues (NodeSize, nodeToBeSplit.Value);
			values.Add (valueToBeAdded);
			values.Sort ( );
			numberofSplit = values [(int) half];
			indexes.AddRange (nodeToBeSplit.Indexes);
			indexes.AddRange (addIndex.Indexes);
			Sort ( );
			for (int i = 0 ; i < (int) Math.Ceiling (half) - 1 ; i++)
			{
				IndexLess.Insert (values [i]);
			}//end for loop
			for (int i = (int) Math.Ceiling (half) ; i < NodeSize ; i++)
			{
				IndexMore.Insert (values [i]);
			}//end for loop
			for (int i = 0 ; i < (int) Math.Ceiling (half) ; i++)
			{
				IndexLess.Insert (indexes [i]);
			}//end for loop
			for (int i = (int) Math.Ceiling (half) ; i < NodeSize + 1 ; i++)
			{
				IndexMore.Insert (indexes [i]);
			}//end for loop
			if (stack.Peek ( ) != null)
			{
				addIndex.Indexes.Clear ( );
				stack.Pop ( );
				rootIndex = (Index) stack.Pop ( );
				postion = rootIndex.Indexes.IndexOf (nodeToBeSplit);
				rootIndex.Indexes.RemoveAt (postion);
				INSERT results = rootIndex.Insert (numberofSplit);
				if (results == INSERT.NEEDSPLIT)
				{
					addIndex.Insert (IndexLess);
					addIndex.Insert (IndexMore);
					SplitIndex (rootIndex, addIndex, numberofSplit);
				}//End if statement
				else
				{
					rootIndex.Insert (IndexLess);
					rootIndex.Insert (IndexMore);
					Root = rootIndex;
				}//End else statement
			}//End if statement
			else
			{
				rootIndex.Insert (numberofSplit);
				rootIndex.Insert (IndexLess);
				rootIndex.Insert (IndexMore);
				Root = rootIndex;
				IndexCount++;
			}//End else statement
			IndexCount++;
		}//End SplitIndex (Index, Node, int)