Beispiel #1
0
        public static Piece FindAngleBar(int height, string color)
        {
            AngleBar angleBar, shortestAngleBar = null;

            foreach (Piece piece in pieceList)
            {
                if (piece is AngleBar)
                {
                    angleBar = piece as AngleBar;
                    if (angleBar.Height >= height && angleBar.Color == color)
                    {
                        if (shortestAngleBar.Height > angleBar.Height)
                        {
                            shortestAngleBar = angleBar;
                        }
                    }
                }
            }

            return(shortestAngleBar);
        }
Beispiel #2
0
        /// <summary>
        /// Find an existing AngleBar based on its inner caracteristics
        /// </summary>
        /// <param name="height"></param>
        /// <param name="color"></param>
        /// <returns>The existing AngleBar if existing, or null</returns>
        public static Piece FindAngleBar(int height, string color)
        {
            AngleBar angleBar, shortestAngleBar = null;

            foreach (Piece piece in pieceList)
            {
                if (piece is AngleBar)
                {
                    angleBar = piece as AngleBar;
                    if (angleBar.Height >= height && angleBar.Color == color)
                    {
                        // As the angle bars can be cut, we try to find the shortest angle bar that fits with the required height
                        if (shortestAngleBar == null || shortestAngleBar.Height > angleBar.Height)
                        {
                            // If a shorther angle bar matching the caracteristics exists, it replaces the longer one
                            shortestAngleBar = angleBar;
                        }
                    }
                }
            }

            return(shortestAngleBar);
        }
Beispiel #3
0
        private static List <Piece> pieceList = new List <Piece>();  //liste avec les piece pour chaque élément, chaque piece a un type


        /// <summary>
        /// This method imports pieces from the DB to add them to the catalog
        /// All the pieces will be created according to their type (Cleat, AngleBar, ...)
        /// </summary>
        public static void GetPieces()
        {
            List <String> pieces = new List <String>();

            using (SQLiteConnection connect = new SQLiteConnection("Data Source=..\\..\\..\\..\\Kitbox.db"))
            {
                connect.Open();
                using (SQLiteCommand fmd = connect.CreateCommand())
                {
                    fmd.CommandText = @"SELECT * FROM Piece 
                                        INNER JOIN Reference 
                                        ON Piece.ID_Piece = Reference.ID_Piece
                                        LEFT OUTER JOIN Color 
                                        ON Piece.ID_Color = Color.PK_Color ";
                    SQLiteDataReader q = fmd.ExecuteReader();

                    while (q.Read())
                    {
                        string reference = Convert.ToString(q["Reference"]);
                        int    price     = Convert.ToInt32(q["Price_Client"]);
                        string id        = Convert.ToString(q["Piece_Code"]);

                        if (reference == "Angle bar")
                        {
                            int    height   = Convert.ToInt16(q["Height"]);
                            string color    = Convert.ToString(q["Color"]);
                            Piece  AngleBar = new AngleBar(height, color, price, id);
                            pieceList.Add(AngleBar);
                        }

                        else if (reference == "B_Panel")
                        {
                            int    length = Convert.ToInt16(q["Length"]);
                            int    height = Convert.ToInt16(q["Height"]);
                            int    depth  = Convert.ToInt16(q["Depth"]);
                            string color  = Convert.ToString(q["Color"]);
                            string type   = "B";
                            Piece  Panel  = new Panel(length, height, depth, color, type, price, id);
                            pieceList.Add(Panel);
                        }

                        else if (reference == "LR_Panel")
                        {
                            int    length = Convert.ToInt16(q["Length"]);
                            int    height = Convert.ToInt16(q["Height"]);
                            int    depth  = Convert.ToInt16(q["Depth"]);
                            string color  = Convert.ToString(q["Color"]);
                            string type   = "LR";
                            Piece  Panel  = new Panel(length, height, depth, color, type, price, id);
                            pieceList.Add(Panel);
                        }

                        else if (reference == "TB_Panel")
                        {
                            int    length = Convert.ToInt16(q["Length"]);
                            int    height = Convert.ToInt16(q["Height"]);
                            int    depth  = Convert.ToInt16(q["Depth"]);
                            string color  = Convert.ToString(q["Color"]);
                            string type   = "TB";//Top Bottom panel
                            Piece  Panel  = new Panel(length, height, depth, color, type, price, id);
                            pieceList.Add(Panel);
                        }

                        else if (reference == "Door")
                        {
                            int    length = Convert.ToInt16(q["Length"]);
                            int    height = Convert.ToInt16(q["Height"]);
                            string color  = Convert.ToString(q["Color"]);
                            Piece  Door   = new Door(length, height, color, price, id);
                            pieceList.Add(Door);
                        }

                        else if (reference == "Cleat")
                        {
                            int   height = Convert.ToInt16(q["Height"]);
                            Piece Cleat  = new Cleat(height, price, id);
                            pieceList.Add(Cleat);
                        }

                        else if (reference == "B_Rail")
                        {
                            string type   = "B";
                            int    length = Convert.ToInt16(q["Length"]);
                            Piece  Rail   = new Rail(type, length, price, id);
                            pieceList.Add(Rail);
                        }

                        else if (reference == "F_Rail")
                        {
                            string type   = "F";
                            int    length = Convert.ToInt16(q["Length"]);
                            Piece  Rail   = new Rail(type, length, price, id);
                            pieceList.Add(Rail);
                        }

                        else if (reference == "LR_Rail")
                        {
                            string type   = "LR";
                            int    length = Convert.ToInt16(q["Depth"]);
                            Piece  Rail   = new Rail(type, length, price, id);
                            pieceList.Add(Rail);
                        }

                        else if (reference == "Knob")
                        {
                            int   diameter = Convert.ToInt16(q["Dimensions"]); //ATTENTION changer le diamètre dans la table par juste le chiffre
                            Piece Knob     = new Knob(diameter, price, id);
                            pieceList.Add(Knob);
                        }
                    }
                }
            }
        }