示例#1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            projectId = Convert.ToInt32(HttpContext.Current.Session["project_id"].ToString());

            #region hit the DB

            using (SqlConnection aConnection = new SqlConnection(sdsDBConnection.ConnectionString))
            {

                aConnection.Open();
                SqlCommand aCommand = aConnection.CreateCommand();
                SqlTransaction aTransaction;
                SqlDataReader aReader;

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

                // Must assign both transaction object and connection
                // to Command object for a pending local transaction
                aCommand.Connection = aConnection;
                aCommand.Transaction = aTransaction;

                try
                {
                    //get number of walls floors and roofs
                    aCommand.CommandText = "SELECT number_walls, number_floors, number_roofs FROM sunrooms WHERE project_id = '" + projectId + "'";
                    aReader = aCommand.ExecuteReader();

                    if (aReader.HasRows)
                    {
                        aReader.Read();

                        wallCount = Convert.ToInt32(aReader[0]);
                        floorCount = Convert.ToInt32(aReader[1]);
                        roofCount = Convert.ToInt32(aReader[2]);
                    }
                    aReader.Close();

                    #region walls
                    //for each wall in the project

                    //aCommand.CommandText = "SELECT wall_type, model_type, total_length, orientation, set_back, name, first_item_index, last_item_index, start_height, end_height, soffit_length, gable_peak, obstructions, fire_protection, wall_index "
                    //    + "FROM walls WHERE project_id = '" + projectId + "'";

                    //SqlDataReader wallReader = aCommand.ExecuteReader();

                    //if (wallReader.HasRows)
                    //{
                    //    while (wallReader.Read())
                    for (int i = 0; i < wallCount; i++)
                    {
                            aCommand.CommandText = "SELECT wall_type, model_type, total_length, orientation, set_back, name, first_item_index, last_item_index, start_height, end_height, soffit_length, gable_peak, obstructions, fire_protection, wall_index "
                            + "FROM walls WHERE project_id = '" + projectId + "' AND wall_index = '" + i + "'";

                            aReader = aCommand.ExecuteReader();
                            aReader.Read();

                            //create a new instance of a wall and set all its attributes from the db
                            Wall aWall = new Wall();
                            aWall.WallType = Convert.ToString(aReader[0]);
                            aWall.ModelType = Convert.ToString(aReader[1]);
                            aWall.Length = Convert.ToSingle(aReader[2]);
                            aWall.Orientation = Convert.ToString(aReader[3]);
                            aWall.SetBack = Convert.ToSingle(aReader[4]);
                            aWall.Name = Convert.ToString(aReader[5]);
                            aWall.FirstItemIndex = Convert.ToInt32(aReader[6]);
                            aWall.LastItemIndex = Convert.ToInt32(aReader[7]);
                            aWall.StartHeight = Convert.ToSingle(aReader[8]);
                            aWall.EndHeight = Convert.ToSingle(aReader[9]);
                            aWall.SoffitLength = Convert.ToSingle(aReader[10]);
                            aWall.GablePeak = Convert.ToSingle(aReader[11]);
                            aWall.FireProtection = Convert.ToBoolean(aReader[13]);
                            int wallIndex = Convert.ToInt32(aReader[14]);

                            aReader.Close();

                            List<LinearItem> listOfLinearItems = new List<LinearItem>();

                            //Get linear items
                            //aCommand.CommandText = "SELECT linear_index, linear_type, start_height, end_height, length, frame_colour, sex, fixed_location, attached_to "
                            //                        + "FROM linear_items WHERE project_id = '" + projectId + "' AND last_item_index < '" + aWall.LastItemIndex + "' AND first_item_index > '" + aWall.FirstItemIndex + "'";
                            //aReader = aCommand.ExecuteReader();

                            //for each linear item/mod in the wall

                            //if (linearItemReader.HasRows)
                            //{
                            //    while (linearItemReader.Read())
                            //    {
                        for (int j = aWall.FirstItemIndex; j < aWall.LastItemIndex; j++)
                        {
                                    //Get linear items
                                    aCommand.CommandText = "SELECT linear_index, linear_type, start_height, end_height, length, frame_colour, sex, fixed_location, attached_to "
                                                            + "FROM linear_items WHERE project_id = '" + projectId + "' AND linear_index = '" + j + "'";
                                    aReader = aCommand.ExecuteReader();
                                    aReader.Read();

                                    int linearIndex = Convert.ToInt32(aReader[0]);
                                    string linearItemType = Convert.ToString(aReader[1]);
                                    float startHeight = Convert.ToSingle(aReader[2]);
                                    float endHeight = Convert.ToSingle(aReader[3]);
                                    float length = Convert.ToSingle(aReader[4]);
                                    string frameColour = Convert.ToString(aReader[5]);
                                    string sex = Convert.ToString(aReader[6]);
                                    float fixedLocation = Convert.ToSingle(aReader[7]);
                                    bool attachedTo = Convert.ToBoolean(aReader[8]);

                                    aReader.Close();

                                    switch (linearItemType)
                                    {
                                        case "Mod":
                                            #region Mod

                                            List<ModuleItem> listOfModuleItems = new List<ModuleItem>();

                                            Mod aMod = new Mod();

                                            aMod.LinearIndex = linearIndex;
                                            aMod.ItemType = linearItemType;
                                            aMod.StartHeight = startHeight;
                                            aMod.EndHeight = endHeight;
                                            aMod.Length = length;
                                            aMod.FrameColour = frameColour;
                                            aMod.Sex = sex;
                                            aMod.FixedLocation = fixedLocation;
                                            aMod.AttachedTo = attachedTo;

                                            //get number of mods
                                            aCommand.CommandText = "SELECT COUNT(*) FROM module_items WHERE project_id = '" + projectId + "' "
                                                                                    + " AND linear_index = '" + aMod.LinearIndex + "'";
                                            aReader = aCommand.ExecuteReader();
                                            aReader.Read();
                                            int modCount = Convert.ToInt32(aReader[0]); //get the number of walls in the project

                                            aReader.Close();

                                            //aCommand.CommandText = "SELECT module_index, item_type, start_height, end_height, length FROM moduleItems "
                                            //                    + "WHERE project_id = '" + projectId + "' AND linear_index = '" + aMod.LinearIndex + "'";

                                            //SqlDataReader moduleItemReader = aCommand.ExecuteReader();

                                            //for each modular item in the mod

                                            //if (moduleItemReader.HasRows)
                                            //{
                                            //    while (moduleItemReader.Read())
                                            for (int k = 0; k < modCount; k++)
                                            {
                                                    //Get module items
                                                     aCommand.CommandText = "SELECT module_index, item_type, start_height, end_height, length FROM module_items "
                                                                    + "WHERE project_id = '" + projectId + "' AND linear_index = '" + aMod.LinearIndex + "' AND module_index = '" + k + "'";

                                                    aReader = aCommand.ExecuteReader();
                                                    aReader.Read();

                                                    int moduleIndex = Convert.ToInt32(aReader[0]);
                                                    string itemType = Convert.ToString(aReader[1]);
                                                    float fStartHeight = Convert.ToSingle(aReader[2]);
                                                    float fEndHeight = Convert.ToSingle(aReader[3]);
                                                    float fLength = Convert.ToSingle(aReader[4]);

                                                    aReader.Close();

                                                    //different types of mods
                                                    switch (itemType)
                                                    {
                                                        case "Kneewall":
                                                        case "Window":
                                                            #region Window
                                                            //Get window
                                                            aCommand.CommandText = "SELECT window_type, screen_type, start_height, end_height, length, window_colour, number_vents FROM windows "
                                                                                    + "WHERE project_id = '" + projectId + "' AND linear_index = '" + aMod.LinearIndex + "' AND module_index = '" + moduleIndex + "'";

                                                            aReader = aCommand.ExecuteReader();

                                                            //if (windowReader.HasRows)
                                                            //{
                                                                aReader.Read();

                                                                string windowStyle = Convert.ToString(aReader[0]);
                                                                string screenType = Convert.ToString(aReader[1]);
                                                                float windowStartHeight = Convert.ToSingle(aReader[2]);
                                                                float windowEndHeight = Convert.ToSingle(aReader[3]);
                                                                float windowLength = Convert.ToSingle(aReader[4]);
                                                                string windowColour = Convert.ToString(aReader[5]);
                                                                int numVents = Convert.ToInt32(aReader[6]);

                                                                aReader.Close();

                                                                //types of windows
                                                                switch (windowStyle)
                                                                {
                                                                    case "Double Slider": //glass model 300
                                                                    case "Single Slider": //glass model 400
                                                                    case "Horizontal Roller XX": //glass model 300
                                                                    case "Horizontal Roller":
                                                                    case "Horizontal 2 Track":
                                                                    case "H2T":
                                                                    case "Vertical 4 Track":
                                                                    case "Vertical Four Track":
                                                                    case "V4T":
                                                                    case "Vinyl":
                                                                        #region Vinyl Window

                                                                        VinylWindow aVinylWindow = new VinylWindow();
                                                                        aVinylWindow.ModuleIndex = moduleIndex;
                                                                        aVinylWindow.ItemType = itemType;
                                                                        aVinylWindow.FStartHeight = fStartHeight;
                                                                        aVinylWindow.FEndHeight = fEndHeight;
                                                                        aVinylWindow.FLength = fLength;
                                                                        //aVinylWindow.Colour = windowColour; //replaced by FrameColour
                                                                        aVinylWindow.WindowStyle = windowStyle;
                                                                        aVinylWindow.ScreenType = screenType;
                                                                        aVinylWindow.LeftHeight = windowStartHeight;
                                                                        aVinylWindow.RightHeight = windowEndHeight;
                                                                        aVinylWindow.Width = windowLength;
                                                                        aVinylWindow.FrameColour = windowColour; //
                                                                        aVinylWindow.VinylTint = ""; // tint of each vent will be concatenated
                                                                        //numVents = (numVents == 0) ? 1 : numVents;
                                                                        aVinylWindow.NumVents = numVents;
                                                                        List<float> listOfVentHeights = new List<float>();

                                                                        //Get vinyl item
                                                                        //aCommand.CommandText = "SELECT start_height, vinyl_tint, spreader_bar FROM vinyl_items "
                                                                        //                        + "WHERE project_id = '" + projectId + "' AND linear_index = '" + aMod.LinearIndex + "' AND module_index = '" + moduleIndex + "'";

                                                                        //aReader = aCommand.ExecuteReader();

                                                                        //if (vinylReader.HasRows)
                                                                        //{
                                                                            //while (vinylReader.Read())
                                                                            //for each vinyl item in the in the vinyl window
                                                                            for (int l = 0; l < numVents; l++)
                                                                            {
                                                                                aCommand.CommandText = "SELECT start_height, vinyl_tint, spreader_bar FROM vinyl_items "
                                                                                                + "WHERE project_id = '" + projectId + "' AND linear_index = '" + aMod.LinearIndex + "' AND module_index = '" + moduleIndex + "' AND vent_index = '" + l + "'";

                                                                        aReader = aCommand.ExecuteReader();
                                                                        aReader.Read();

                                                                                listOfVentHeights.Add(Convert.ToSingle(aReader[0]));
                                                                                aVinylWindow.VinylTint += Convert.ToString(aReader[1]);
                                                                                aVinylWindow.SpreaderBar = Convert.ToSingle(aReader[2]);

                                                                        aReader.Close();
                                                                            }

                                                                        //vinylReader.Close();

                                                                        aVinylWindow.VentHeights = listOfVentHeights;

                                                                        listOfModuleItems.Add(aVinylWindow);

                                                                        #endregion
                                                                        break;
                                                                    case "Screen":
                                                                        #region Screen Window

                                                                        Window aWindow = new Window();
                                                                        aWindow.ModuleIndex = moduleIndex;
                                                                        aWindow.ItemType = itemType;
                                                                        aWindow.FStartHeight = fStartHeight;
                                                                        aWindow.FEndHeight = fEndHeight;
                                                                        aWindow.FLength = fLength;
                                                                        //aWindow.Colour = windowColour; //replaced by FrameColour
                                                                        aWindow.WindowStyle = windowStyle;
                                                                        aWindow.ScreenType = screenType;
                                                                        aWindow.LeftHeight = windowStartHeight;
                                                                        aWindow.RightHeight = windowEndHeight;
                                                                        aWindow.Width = windowLength;
                                                                        aWindow.FrameColour = windowColour; //
                                                                        //aWindow.VinylTint = ""; // tint of each vent will be concatenated
                                                                        //aWindow.NumVents = numVents;

                                                                        listOfModuleItems.Add(aWindow);

                                                                        #endregion
                                                                        break;
                                                                    case "Glass":
                                                                    case "Fixed Glass 2\"":
                                                                        #region Glass Window

                                                                        GlassWindow aGlassWindow = new GlassWindow();
                                                                        aGlassWindow.ModuleIndex = moduleIndex;
                                                                        aGlassWindow.ItemType = itemType;
                                                                        aGlassWindow.FStartHeight = fStartHeight;
                                                                        aGlassWindow.FEndHeight = fEndHeight;
                                                                        aGlassWindow.FLength = fLength;
                                                                        //aGlassWindow.Colour = windowColour; //replaced by frameColour
                                                                        aGlassWindow.WindowStyle = windowStyle;
                                                                        aGlassWindow.ScreenType = screenType;
                                                                        aGlassWindow.LeftHeight = windowStartHeight;
                                                                        aGlassWindow.RightHeight = windowEndHeight;
                                                                        aGlassWindow.Width = windowLength;
                                                                        aGlassWindow.FrameColour = windowColour; //
                                                                        aGlassWindow.GlassTint = ""; // tint of each vent will be concatenated
                                                                        aGlassWindow.Operation = ""; // XX, XO, OX will be concatenated
                                                                        aGlassWindow.NumVents = numVents;

                                                                        //Get glass item
                                                                        //aCommand.CommandText = "SELECT glass_type, glass_tint, tempered, operation FROM glass_items "
                                                                        //                        + "WHERE project_id = '" + projectId + "' AND linear_index = '" + aMod.LinearIndex + "' AND module_index = '" + moduleIndex + "'";

                                                                        //SqlDataReader glassReader = aCommand.ExecuteReader();

                                                                        for (int l = 0; l < numVents; l++)
                                                                        {
                                                                        //if (glassReader.HasRows)
                                                                        //{
                                                                        //    while (glassReader.Read())
                                                                        //    {

                                                                             aCommand.CommandText = "SELECT glass_type, glass_tint, tempered, operation FROM glass_items "
                                                                                                + "WHERE project_id = '" + projectId + "' AND linear_index = '" + aMod.LinearIndex + "' AND module_index = '" + moduleIndex + "' AND vent_index = '" + l + "'";

                                                                            aReader = aCommand.ExecuteReader();
                                                                            aReader.Read();
                                                                                aGlassWindow.GlassType = Convert.ToString(aReader[0]);
                                                                                aGlassWindow.GlassTint += Convert.ToString(aReader[1]);
                                                                                aGlassWindow.Tempered = Convert.ToBoolean(aReader[2]);
                                                                                aGlassWindow.Operation += Convert.ToString(aReader[3]);

                                                                            aReader.Close();
                                                                            }

                                                                        //glassReader.Close();

                                                                        listOfModuleItems.Add(aGlassWindow);

                                                                        #endregion
                                                                        break;
                                                                    case "Open":
                                                                        #region Open Window
                                                                        Window openWindow = new Window();
                                                                        openWindow.ModuleIndex = moduleIndex;
                                                                        openWindow.ItemType = itemType;
                                                                        openWindow.FStartHeight = fStartHeight;
                                                                        openWindow.FEndHeight = fEndHeight;
                                                                        openWindow.FLength = fLength;
                                                                        openWindow.WindowStyle = windowStyle;
                                                                        openWindow.ScreenType = screenType;
                                                                        openWindow.LeftHeight = windowStartHeight;
                                                                        openWindow.RightHeight = windowEndHeight;
                                                                        openWindow.Width = windowLength;
                                                                        openWindow.FrameColour = windowColour;

                                                                        listOfModuleItems.Add(openWindow); //add the modular item to the list
                                                                        #endregion
                                                                        break;
                                                                    case "Panel":
                                                                    case "Solid Wall":
                                                                        #region Open Window
                                                                        Window panel = new Window();
                                                                        panel.ModuleIndex = moduleIndex;
                                                                        panel.ItemType = itemType;
                                                                        panel.FStartHeight = fStartHeight;
                                                                        panel.FEndHeight = fEndHeight;
                                                                        panel.FLength = fLength;
                                                                        panel.WindowStyle = windowStyle;
                                                                        panel.ScreenType = screenType;
                                                                        panel.LeftHeight = windowStartHeight;
                                                                        panel.RightHeight = windowEndHeight;
                                                                        panel.Width = windowLength;
                                                                        panel.FrameColour = windowColour;

                                                                        listOfModuleItems.Add(panel); //add the modular item to the list
                                                                        #endregion
                                                                        break;
                                                                }

                                                            //windowReader.Close();
                                                            #endregion
                                                            break;
                                                        case "Door":
                                                            #region Door
                                                            //Get door
                                                            //aCommand.CommandText = "SELECT door_type, door_style, screen_type, height, length, door_colour, kick_plate FROM doors "
                                                            //                        + "WHERE project_id = '" + projectId + "' AND linear_index = '" + aMod.LinearIndex + "' AND module_index = '" + moduleIndex + "'";

                                                            //SqlDataReader doorReader = aCommand.ExecuteReader();

                                                            //if (doorReader.HasRows)
                                                            //{
                                                            //    while (doorReader.Read())

                                                                    aCommand.CommandText = "SELECT door_type, door_style, screen_type, height, length, door_colour, kick_plate FROM doors "
                                                                                    + "WHERE project_id = '" + projectId + "' AND linear_index = '" + aMod.LinearIndex + "' AND module_index = '" + moduleIndex + "'";

                                                                    aReader = aCommand.ExecuteReader();
                                                                    aReader.Read();

                                                                    string doorType = Convert.ToString(aReader[0]);
                                                                    string doorStyle = Convert.ToString(aReader[1]);
                                                                    string doorScreenType = Convert.ToString(aReader[2]);
                                                                    float doorFrameHeight = Convert.ToSingle(aReader[3]);
                                                                    float doorFrameLength = Convert.ToSingle(aReader[4]);
                                                                    string doorColour = Convert.ToString(aReader[5]);
                                                                    float doorKickPlate = Convert.ToSingle(aReader[6]);

                                                                    aReader.Close();

                                                                    //get the window in this door
                                                                    aCommand.CommandText = "SELECT door_index, window_type, screen_type, start_height, end_height, length, window_colour, number_vents FROM windows "
                                                                                            + "WHERE project_id = '" + projectId + "' AND linear_index = '" + aMod.LinearIndex + "' AND module_index = '" + moduleIndex + "'";

                                                                    aReader = aCommand.ExecuteReader();

                                                                    VinylWindow aDoorWindow = new VinylWindow();

                                                                    if (aReader.HasRows)
                                                                    {
                                                                        while (aReader.Read())
                                                                        {
                                                                            //int doorIndex = Convert.ToInt32(aReader[0]);
                                                                            aDoorWindow.WindowStyle = Convert.ToString(aReader[1]);
                                                                            aDoorWindow.ScreenType = Convert.ToString(aReader[2]);
                                                                            aDoorWindow.LeftHeight = Convert.ToSingle(aReader[3]);
                                                                            aDoorWindow.RightHeight = Convert.ToSingle(aReader[4]);
                                                                            aDoorWindow.Width = Convert.ToSingle(aReader[5]);
                                                                            aDoorWindow.FrameColour = Convert.ToString(aReader[6]);
                                                                            aDoorWindow.NumVents = Convert.ToInt32(aReader[7]);
                                                                        }
                                                                    }
                                                                    aReader.Close();

                                                                    switch (aDoorWindow.WindowStyle) //door/window style
                                                                    {
                                                                        case "Full Screen": //screen
                                                                            break;
                                                                        case "Vertical Four Track": //vinyl
                                                                            #region V4T
                                                                            List<float> listOfV4TVentHeights = new List<float>();

                                                                            //for each vinyl item in the in the vinyl window
                                                                            //for (int l = 0; l < aDoorWindow.NumVents; l++)
                                                                            //Get vinyl item
                                                                            aCommand.CommandText = "SELECT start_height, vinyl_tint, spreader_bar FROM vinyl_items "
                                                                                                    + "WHERE project_id = '" + projectId + "' AND linear_index = '" + aMod.LinearIndex + "' AND module_index = '" + moduleIndex + "'";

                                                                            SqlDataReader vinylReader = aCommand.ExecuteReader();

                                                                            if (vinylReader.HasRows)
                                                                            {
                                                                                while (vinylReader.Read())
                                                                                {
                                                                                    listOfV4TVentHeights.Add(Convert.ToSingle(vinylReader[0]));
                                                                                    aDoorWindow.VinylTint += Convert.ToString(vinylReader[1]);
                                                                                    aDoorWindow.SpreaderBar = Convert.ToSingle(vinylReader[2]);
                                                                                }
                                                                            }
                                                                            vinylReader.Close();

                                                                            aDoorWindow.VentHeights = listOfV4TVentHeights;
                                                                            #endregion
                                                                            break;
                                                                        case "Full View": //glass
                                                                            break;
                                                                        case "Full View Colonial": //glass
                                                                            break;
                                                                        case "Half Lite": //glass
                                                                            break;
                                                                        case "Half Lite Venting": //glass
                                                                            break;
                                                                        case "Half Lite with Mini Blinds": //glass
                                                                            break;
                                                                        case "Full View with Mini Blinds": //glass
                                                                            break;
                                                                        case "Aluminum Storm Screen": //screen
                                                                            break;
                                                                        case "Aluminum Storm Glass": //glass
                                                                            break;
                                                                        case "Vinyl Guard": //vinyl
                                                                            break;
                                                                    }
                                                                    //types of doors
                                                                    switch (doorType)
                                                                    {
                                                                        case "Cabana":
                                                                        case "Cabana Door":
                                                                            #region Cabana Door

                                                                            aCommand.CommandText = "SELECT glass_tint, hinge, swing, hardware_type, screen_type FROM cabana_doors "
                                                                                            + "WHERE project_id = '" + projectId + "' AND linear_index = '" + aMod.LinearIndex + "' AND module_index = '" + moduleIndex + "'";

                                                                            SqlDataReader cabanaReader = aCommand.ExecuteReader();

                                                                            if (cabanaReader.HasRows)
                                                                            {
                                                                                cabanaReader.Read();

                                                                                CabanaDoor aCabanaDoor = new CabanaDoor();
                                                                                aCabanaDoor.ModuleIndex = moduleIndex;
                                                                                aCabanaDoor.ItemType = itemType;
                                                                                aCabanaDoor.FStartHeight = fStartHeight;
                                                                                aCabanaDoor.FEndHeight = fEndHeight;
                                                                                aCabanaDoor.FLength = fLength;
                                                                                aCabanaDoor.DoorType = doorType;
                                                                                aCabanaDoor.DoorStyle = doorStyle;
                                                                                aCabanaDoor.ScreenType = doorScreenType;
                                                                                aCabanaDoor.Height = doorFrameHeight;
                                                                                aCabanaDoor.Length = doorFrameLength;
                                                                                aCabanaDoor.Colour = doorColour; //
                                                                                aCabanaDoor.Kickplate = doorKickPlate; //
                                                                                aCabanaDoor.GlassTint = Convert.ToString(cabanaReader[0]);
                                                                                aCabanaDoor.Hinge = Convert.ToString(cabanaReader[1]);
                                                                                aCabanaDoor.Swing = Convert.ToString(cabanaReader[2]);
                                                                                aCabanaDoor.HardwareType = Convert.ToString(cabanaReader[3]);
                                                                                aCabanaDoor.ScreenType = Convert.ToString(cabanaReader[4]);

                                                                                aCabanaDoor.DoorWindow = aDoorWindow;

                                                                                listOfModuleItems.Add(aCabanaDoor); //add the modular item to the list
                                                                            }
                                                                            cabanaReader.Close();

                                                                            #endregion
                                                                            break;
                                                                        case "French":
                                                                        case "French Door":
                                                                            #region French Door

                                                                            aCommand.CommandText = "SELECT glass_tint, swing, operator, hardware_type, screen_type FROM french_doors "
                                                                                            + "WHERE project_id = '" + projectId + "' AND linear_index = '" + aMod.LinearIndex + "' AND module_index = '" + moduleIndex + "'";

                                                                            SqlDataReader frenchReader = aCommand.ExecuteReader();

                                                                            if (frenchReader.HasRows)
                                                                            {

                                                                                frenchReader.Read();

                                                                                FrenchDoor aFrenchDoor = new FrenchDoor();
                                                                                aFrenchDoor.ModuleIndex = moduleIndex;
                                                                                aFrenchDoor.ItemType = itemType;
                                                                                aFrenchDoor.FStartHeight = fStartHeight;
                                                                                aFrenchDoor.FEndHeight = fEndHeight;
                                                                                aFrenchDoor.FLength = fLength;
                                                                                aFrenchDoor.DoorType = doorType;
                                                                                aFrenchDoor.DoorStyle = doorStyle;
                                                                                aFrenchDoor.ScreenType = doorScreenType;
                                                                                aFrenchDoor.Height = doorFrameHeight;
                                                                                aFrenchDoor.Length = doorFrameLength;
                                                                                aFrenchDoor.Colour = doorColour; //
                                                                                aFrenchDoor.Kickplate = doorKickPlate; //
                                                                                aFrenchDoor.GlassTint = Convert.ToString(frenchReader[0]);
                                                                                aFrenchDoor.Swing = Convert.ToString(frenchReader[1]);
                                                                                aFrenchDoor.OperatingDoor = Convert.ToString(frenchReader[2]); ///this needs to be fixed, operator in db is bool and C# is string
                                                                                aFrenchDoor.HardwareType = Convert.ToString(frenchReader[3]);
                                                                                aFrenchDoor.ScreenType = Convert.ToString(frenchReader[4]);

                                                                                aFrenchDoor.DoorWindow = aDoorWindow;

                                                                                listOfModuleItems.Add(aFrenchDoor); //add the modular item to the list
                                                                            }
                                                                            frenchReader.Close();

                                                                            #endregion
                                                                            break;
                                                                        case "Patio":
                                                                        case "Patio Door":
                                                                            #region Patio Door

                                                                            aCommand.CommandText = "SELECT glass_tint, moving_door FROM patio_doors "
                                                                                            + "WHERE project_id = '" + projectId + "' AND linear_index = '" + aMod.LinearIndex + "' AND module_index = '" + moduleIndex + "'"; //change k to moduleIndex. Couldn't compile other pages.

                                                                            SqlDataReader patioReader = aCommand.ExecuteReader();

                                                                            if (patioReader.HasRows)
                                                                            {
                                                                                patioReader.Read();

                                                                                PatioDoor aPatioDoor = new PatioDoor();
                                                                                aPatioDoor.ModuleIndex = moduleIndex;
                                                                                aPatioDoor.ItemType = itemType;
                                                                                aPatioDoor.FStartHeight = fStartHeight;
                                                                                aPatioDoor.FEndHeight = fEndHeight;
                                                                                aPatioDoor.FLength = fLength;
                                                                                aPatioDoor.DoorType = doorType;
                                                                                aPatioDoor.DoorStyle = doorStyle;
                                                                                aPatioDoor.ScreenType = doorScreenType;
                                                                                aPatioDoor.Height = doorFrameHeight;
                                                                                aPatioDoor.Length = doorFrameLength;
                                                                                aPatioDoor.Colour = doorColour; //
                                                                                aPatioDoor.Kickplate = doorKickPlate; //
                                                                                aPatioDoor.GlassTint = Convert.ToString(patioReader[0]);
                                                                                aPatioDoor.MovingDoor = Convert.ToString(patioReader[1]); ///this needs to be fixed, operator in db is bool and C# is string

                                                                                aPatioDoor.DoorWindow = aDoorWindow;

                                                                                listOfModuleItems.Add(aPatioDoor); //add the modular item to the list
                                                                            }
                                                                            patioReader.Close();

                                                                            #endregion
                                                                            break;
                                                                        case "Half Lite":
                                                                        case "Half Lite Venting":
                                                                        case "Half Lite With Mini Blinds":
                                                                        case "Full View With Mini Blinds":
                                                                            break;
                                                                        case "NoDoor":
                                                                        case "No Door":
                                                                            #region No Door

                                                                            Door aDoor = new Door();
                                                                            aDoor.ModuleIndex = moduleIndex;
                                                                            aDoor.ItemType = itemType;
                                                                            aDoor.FStartHeight = fStartHeight;
                                                                            aDoor.FEndHeight = fEndHeight;
                                                                            aDoor.FLength = fLength;
                                                                            aDoor.DoorType = doorType;
                                                                            //aDoor.DoorStyle = doorStyle;
                                                                            //aDoor.ScreenType = doorScreenType;
                                                                            aDoor.Height = doorFrameHeight;
                                                                            aDoor.Length = doorFrameLength;
                                                                            //aDoor.Colour = doorColour; //
                                                                            //aDoor.Kickplate = doorKickPlate; //

                                                                            listOfModuleItems.Add(aDoor); //add the modular item to the list

                                                                            //aReader.Close();

                                                                            #endregion
                                                                            break;
                                                                    }

                                                            //doorReader.Close();
                                                            #endregion
                                                            break;
                                                        case "Box Header": //
                                                            #region H BoxHeader
                                                            HBoxHeader hBoxHeader = new HBoxHeader();
                                                            hBoxHeader.ModuleIndex = moduleIndex;
                                                            hBoxHeader.ItemType = itemType;
                                                            hBoxHeader.FStartHeight = fStartHeight;
                                                            hBoxHeader.FEndHeight = fEndHeight;
                                                            hBoxHeader.FLength = fLength;

                                                            listOfModuleItems.Add(hBoxHeader); //add the modular item to the list
                                                            #endregion
                                                            break; //
                                                        case "Receiver": //
                                                            #region H Receiver
                                                            HReceiver hReceiver = new HReceiver();
                                                            hReceiver.ModuleIndex = moduleIndex;
                                                            hReceiver.ItemType = itemType;
                                                            hReceiver.FStartHeight = fStartHeight;
                                                            hReceiver.FEndHeight = fEndHeight;
                                                            hReceiver.FLength = fLength;

                                                            listOfModuleItems.Add(hReceiver); //add the modular item to the list
                                                            #endregion
                                                            break;
                                                        case "Panel": // same as open wall window
                                                            #region Solid Wall Window
                                                            Window solid = new Window();
                                                            solid.ModuleIndex = moduleIndex;
                                                            solid.ItemType = itemType;
                                                            solid.FStartHeight = fStartHeight;
                                                            solid.FEndHeight = fEndHeight;
                                                            solid.FLength = fLength;

                                                            listOfModuleItems.Add(solid); //add the modular item to the list
                                                            #endregion
                                                            break;
                                                    }
                                                    aMod.ModularItems = listOfModuleItems;
                                                }
                                                listOfLinearItems.Add(aMod);//add the linear item to the list

                                            //moduleItemReader.Close();
                                            #endregion
                                            break;
                                        case "Receiver":
                                        case "Receiever":
                                            #region Receiver
                                            BoxHeader aBoxHeader = new BoxHeader();
                                            aBoxHeader.LinearIndex = linearIndex;
                                            aBoxHeader.ItemType = linearItemType;
                                            aBoxHeader.StartHeight = startHeight;
                                            aBoxHeader.EndHeight = endHeight;
                                            aBoxHeader.Length = length;
                                            aBoxHeader.FrameColour = frameColour;
                                            aBoxHeader.Sex = sex;
                                            aBoxHeader.FixedLocation = fixedLocation;
                                            aBoxHeader.AttachedTo = attachedTo;
                                            aBoxHeader.IsReceiver = true;
                                            aBoxHeader.IsTwoPiece = false;

                                            listOfLinearItems.Add(aBoxHeader);//add the linear item to the list
                                            #endregion
                                            break;
                                        case "2 Piece Receiver":
                                        case "2PieceReceiver":
                                            #region 2 Piece Receiver
                                            aBoxHeader = new BoxHeader();
                                            aBoxHeader.LinearIndex = linearIndex;
                                            aBoxHeader.ItemType = linearItemType;
                                            aBoxHeader.StartHeight = startHeight;
                                            aBoxHeader.EndHeight = endHeight;
                                            aBoxHeader.Length = length;
                                            aBoxHeader.FrameColour = frameColour;
                                            aBoxHeader.Sex = sex;
                                            aBoxHeader.FixedLocation = fixedLocation;
                                            aBoxHeader.AttachedTo = attachedTo;
                                            aBoxHeader.IsReceiver = true;
                                            aBoxHeader.IsTwoPiece = true;

                                            listOfLinearItems.Add(aBoxHeader);//add the linear item to the list
                                            #endregion
                                            break;
                                        case "BoxHeader": //
                                        case "Box Header": //
                                            #region Box Header
                                            aBoxHeader = new BoxHeader();
                                            aBoxHeader.LinearIndex = linearIndex;
                                            aBoxHeader.ItemType = linearItemType;
                                            aBoxHeader.StartHeight = startHeight;
                                            aBoxHeader.EndHeight = endHeight;
                                            aBoxHeader.Length = length;
                                            aBoxHeader.FrameColour = frameColour;
                                            aBoxHeader.Sex = sex;
                                            aBoxHeader.FixedLocation = fixedLocation;
                                            aBoxHeader.AttachedTo = attachedTo;
                                            aBoxHeader.IsReceiver = false;
                                            //aBoxHeader.IsTwoPiece = false;

                                            listOfLinearItems.Add(aBoxHeader);//add the linear item to the list
                                            #endregion
                                            break;
                                        case "BoxHeaderReceiver":
                                        case "Box Header Receiver": //
                                            #region Box Header Receiver
                                            aBoxHeader = new BoxHeader();
                                            aBoxHeader.LinearIndex = linearIndex;
                                            aBoxHeader.ItemType = linearItemType;
                                            aBoxHeader.StartHeight = startHeight;
                                            aBoxHeader.EndHeight = endHeight;
                                            aBoxHeader.Length = length;
                                            aBoxHeader.FrameColour = frameColour;
                                            aBoxHeader.Sex = sex;
                                            aBoxHeader.FixedLocation = fixedLocation;
                                            aBoxHeader.AttachedTo = attachedTo;
                                            aBoxHeader.IsReceiver = true;
                                            //aBoxHeader.IsTwoPiece = false;

                                            listOfLinearItems.Add(aBoxHeader);//add the linear item to the list
                                            #endregion
                                            break;
                                        case "Filler":
                                            #region Filler
                                            Filler aFiller = new Filler();
                                            aFiller.LinearIndex = linearIndex;
                                            aFiller.ItemType = linearItemType;
                                            aFiller.StartHeight = startHeight;
                                            aFiller.EndHeight = endHeight;
                                            aFiller.Length = length;
                                            //aFiller.FrameColour = frameColour;
                                            aFiller.Sex = "MM";
                                            aFiller.FixedLocation = fixedLocation;
                                            aFiller.AttachedTo = attachedTo;

                                            listOfLinearItems.Add(aFiller);//add the linear item to the list
                                            #endregion
                                            break;
                                        case "Corner Post":
                                        case "Corner":
                                            #region Corner Post
                                            Corner aCorner = new Corner();
                                            aCorner.LinearIndex = linearIndex;
                                            aCorner.ItemType = linearItemType;
                                            aCorner.StartHeight = startHeight;
                                            aCorner.EndHeight = endHeight;
                                            aCorner.Length = length;
                                            aCorner.FrameColour = frameColour;
                                            aCorner.Sex = sex;
                                            aCorner.FixedLocation = fixedLocation;
                                            aCorner.AttachedTo = attachedTo;
                                            //aCorner.AngleIs90 = true; //hard coded, because I don't know where its coming from
                                            //aCorner.OutsideCorner = true; // hard coded because I don't know where its coming from

                                            listOfLinearItems.Add(aCorner); //add the linear item to the list
                                            #endregion
                                            break;
                                        case "ElectricalChase":
                                        case "Electrical Chase":
                                            #region ElectricalChase
                                            ElectricalChase aElectricalChase = new ElectricalChase();
                                            aElectricalChase.LinearIndex = linearIndex;
                                            aElectricalChase.ItemType = linearItemType;
                                            aElectricalChase.StartHeight = startHeight;
                                            aElectricalChase.EndHeight = endHeight;
                                            aElectricalChase.Length = length;
                                            //aElectricalChase.FrameColour = frameColour;
                                            aElectricalChase.Sex = "MM";
                                            aElectricalChase.FixedLocation = fixedLocation;
                                            aElectricalChase.AttachedTo = attachedTo;

                                            listOfLinearItems.Add(aElectricalChase);//add the linear item to the list
                                            #endregion
                                            break;
                                        case "HChannel":
                                        case "H Channel":
                                            #region H Channel
                                            HChannel aHChannel = new HChannel();
                                            aHChannel.LinearIndex = linearIndex;
                                            aHChannel.ItemType = linearItemType;
                                            aHChannel.StartHeight = startHeight;
                                            aHChannel.EndHeight = endHeight;
                                            aHChannel.Length = length;
                                            aHChannel.FrameColour = frameColour;
                                            aHChannel.Sex = sex;
                                            aHChannel.FixedLocation = fixedLocation;
                                            aHChannel.AttachedTo = attachedTo;

                                            listOfLinearItems.Add(aHChannel);//add the linear item to the list
                                            #endregion
                                            break;
                                    }
                                }

                                aWall.LinearItems = listOfLinearItems;

                                listOfWalls.Add(aWall); //add the wall to the list
                            }
                            //linearItemReader.Close();

                    //wallReader.Close();
                    #endregion

                    #region floors
                    if (floorCount != 0)
                    {

                    }
                    #endregion

                    #region roofs
                    //if there is a roof in the project

                    if (roofCount != 0)
                    {
                        for(int i = 0; i < roofCount; i++)
                        {
                        aCommand.CommandText = "SELECT roof_type, interior_skin, exterior_skin, thickness, fire_protection, thermadeck, acrylic, gutter, gutter_pro, gutter_colour, number_supports, stripe_colour, projection, width, roof_index "
                                + "FROM roofs WHERE project_id = '" + projectId + "' roof_index = '" + i + "'";

                        aReader = aCommand.ExecuteReader();
                        aReader.Read();

                        //if (roofReader.HasRows)
                        //{
                        //    while (roofReader.Read())
                        //    {

                                //create a new instance of a wall and set all its attributes from the db
                                aRoof = new Roof();
                                aRoof.Type = Convert.ToString(aReader[0]);
                                aRoof.InteriorSkin = Convert.ToString(aReader[1]);
                                aRoof.ExteriorSkin = Convert.ToString(aReader[2]);
                                aRoof.Thickness = Convert.ToDouble(aReader[3]);
                                aRoof.FireProtection = Convert.ToBoolean(aReader[4]);
                                aRoof.Thermadeck = Convert.ToBoolean(aReader[5]);
                                aRoof.Acrylic = Convert.ToBoolean(aReader[6]);
                                aRoof.Gutters = Convert.ToBoolean(aReader[7]);
                                aRoof.GutterPro = Convert.ToBoolean(aReader[8]);
                                aRoof.GutterColour = Convert.ToString(aReader[9]);
                                aRoof.NumberSupports = Convert.ToInt32(aReader[10]);
                                aRoof.StripeColour = Convert.ToString(aReader[11]);
                                aRoof.Projection = Convert.ToDouble(aReader[12]); //how do we deal with obstructions
                                aRoof.Width = Convert.ToDouble(aReader[13]);
                                int roofIndex = Convert.ToInt32(aReader[14]);

                            aReader.Close();
                                List<RoofModule> listOfRoofModules = new List<RoofModule>();

                                aCommand.CommandText = "SELECT COUNT(*) FROM roof_modules WHERE project_id = '" + projectId + "' AND roof_index = '" + roofIndex + "'";
                                aReader = aCommand.ExecuteReader();
                                aReader.Read();
                                int roofModCount = Convert.ToInt32(aReader[0]);

                                //aCommand.CommandText = "SELECT projection, width, interior_skin, exterior_skin, roof_view "
                                //+ "FROM roof_modules WHERE project_id = '" + projectId + "' AND roof_index = '" + roofIndex + "'";

                                //SqlDataReader moduleReader = aCommand.ExecuteReader();

                                //if (moduleReader.HasRows)
                                //{
                                //    while (moduleReader.Read())
                                    for(int j = 0; j < roofModCount; j++)
                                    {

                                        aCommand.CommandText = "SELECT projection, width, interior_skin, exterior_skin, roof_view "
                                                    + "FROM roof_modules WHERE project_id = '" + projectId + "' AND roof_index = '" + roofIndex + "'";

                                         aReader = aCommand.ExecuteReader();
                                         aReader.Read();

                                        RoofModule aModule = new RoofModule();
                                        aModule.Projection = Convert.ToDouble(aReader[0]);
                                        aModule.Width = Convert.ToDouble(aReader[1]);
                                        aModule.InteriorSkin = Convert.ToString(aReader[2]);
                                        aModule.ExteriorSkin = Convert.ToString(aReader[3]);
                                        int roofView = Convert.ToInt32(aReader[4]);

                                        aReader.Close();

                                        List<RoofItem> listOfRoofItems = new List<RoofItem>();

                                        aCommand.CommandText = "SELECT COUNT(*) FROM roof_modules WHERE project_id = '" + projectId + "' AND roof_index = '" + roofIndex + "' AND roof_view = '" + roofView + "'";
                                        aReader = aCommand.ExecuteReader();
                                        aReader.Read();
                                        int roofItemCount = Convert.ToInt32(aReader[0]);

                                        //aCommand.CommandText = "SELECT roof_item, projection, width, item_index "
                                        //+ "FROM roof_modules WHERE project_id = '" + projectId + "' AND roof_index = '" + roofIndex + "' AND roof_view = '" + roofView + "'";

                                        //SqlDataReader itemReader = aCommand.ExecuteReader();

                                        //if (itemReader.HasRows)
                                        //{
                                        //    while(itemReader.Read())
                                            for (int k = 0; k < roofItemCount; k++)
                                            {

                                                aCommand.CommandText = "SELECT roof_item, projection, width, item_index "
                                                    + "FROM roof_modules WHERE project_id = '" + projectId + "' AND roof_index = '" + roofIndex + "' AND roof_view = '" + roofView + "' AND item_index = '" + k + "'";

                                                aReader = aCommand.ExecuteReader();
                                                aReader.Read();

                                                // store in an object
                                                RoofItem aRoofItem = new RoofItem();
                                                aRoofItem.ItemType = Convert.ToString(aReader[0]);
                                                aRoofItem.Projection = Convert.ToSingle(aReader[1]);
                                                aRoofItem.Width = Convert.ToSingle(aReader[2]);
                                                int itemIndex = Convert.ToInt32(aReader[3]);

                                                aReader.Close();

                                                ///different types of roof items
                                                switch (aRoofItem.ItemType)
                                                {
                                                    case "Receiver": //no class.. what to do .. same as panel receiver?
                                                        break;
                                                    case "Awning Track": //no class.. what to do
                                                        break;
                                                    case "I-Beam": //no class.. what to do
                                                        break;
                                                    case "Pressure Cap I-Beam": //no class.. what to do
                                                        break;
                                                    case "T-Bar": //no class.. what to do
                                                        break;
                                                    case "Acrylic Panel": //no class.. no class ... where is colour, width, setback, projection being stored?
                                                        break;
                                                    case "Foam Panel": //no class ... where is colour, width, setback, projection being stored?
                                                        //accordding the to db, this is the only item in which you can have fanbeams and skylight
                                                        //check for skylight in this roof item

                                                        //are all skylights the same? length/width etc? ..
                                                        //there is no skylight object.. roof item should have a attribute for a skylight object

                                                        aCommand.CommandText = "SELECT skylight_type, set_back, operator "
                                                        + "FROM skylights WHERE project_id = '" + projectId + "' AND roof_index = '" + roofIndex + "' AND roof_view = '" + roofView + "' AND item_index '" + itemIndex + "'";

                                                        SqlDataReader skylightReader = aCommand.ExecuteReader();

                                                        if (skylightReader.HasRows)
                                                        {
                                                            while (skylightReader.Read())
                                                            {
                                                                //Skylight aSkylight = new Skylight(); //create object and set attribute if required
                                                                aRoofItem.SkyLight = Convert.ToSingle(skylightReader[1]);
                                                            }

                                                        }
                                                        else
                                                        {
                                                            aRoofItem.SkyLight = -1;
                                                        }
                                                        skylightReader.Close();

                                                        //check for fanbeams in this roof item
                                                        //no info in the db or in C#
                                                        aCommand.CommandText = "SELECT skylight_type, set_back, operator "
                                                        + "FROM fanbeams WHERE project_id = '" + projectId + "' AND roof_index = '" + roofIndex + "' AND roof_view = '" + roofView + "' AND item_index = '" + itemIndex + "'";

                                                        SqlDataReader fanbeamReader = aCommand.ExecuteReader();

                                                        if (fanbeamReader.HasRows)
                                                        {
                                                            while (fanbeamReader.Read())
                                                            {
                                                                //Skylight aSkylight = new Skylight(); //create object and set attribute if required
                                                                aRoofItem.FanBeam = Convert.ToSingle(skylightReader[1]);
                                                            }

                                                        }
                                                        else
                                                        {
                                                            aRoofItem.FanBeam = -1;
                                                        }
                                                        fanbeamReader.Close();
                                                        break;
                                                }

                                                listOfRoofItems.Add(aRoofItem);
                                            }

                                        //itemReader.Close();

                                        aModule.RoofItems = listOfRoofItems;

                                        listOfRoofModules.Add(aModule);
                                    }

                                //moduleReader.Close();

                                aRoof.RoofModules = listOfRoofModules;
                            }

                        //roofReader.Close();
                    }

                    #endregion

                    aTransaction.Commit();

                    hidJsonObjects.Value = JsonConvert.SerializeObject(listOfWalls);
            }

                 catch (Exception ex)
                {
                    //lblError.Text = "Commit Exception Type: " + ex.GetType();
                    //lblError.Text += "  Message: " + ex.Message;

                    // Attempt to roll back the transaction.
                    try
                    {
                        aTransaction.Rollback();
                    }
                    catch (Exception ex2)
                    {
                         //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.
                        //lblError.Text = "Rollback Exception Type: " + ex2.GetType();
                        //lblError.Text += "  Message: " + ex2.Message;
                    }
                }
            }

            #endregion

            hidJsonObjects.Value = JsonConvert.SerializeObject(listOfWalls);
            PopulateDropdown(floorCount, roofCount);
            PopulateModOptions();
            //lnkUpdateSunroom.Attributes.Add("onclick", "updateSunroom()");
            //lnkSubmitSunroom.Attributes.Add("onclick", "submitSunroom()");
            //lnkEditorNavMods.Attributes.Add("onclick", "$('.overlayContainer').slideToggle()");
            //lnkEditorNavTools.Attributes.Add("onclick", "$('#saveButtons').fadeToggle(); $('.btnTools').slideToggle();");
            lnkEditorNavSave.Attributes.Add("onclick", "updateSunroom()");
            lnkEditorNavUndo.Attributes.Add("onclick", "undo()");
            lnkEditorNavRedo.Attributes.Add("onclick", "redo()");

            //Add list of all objects to session, for use by other pages accessed through project editor
            try
            {
                Session.Add("listOfWalls", listOfWalls);
            }
            catch (Exception ex)
            {
                Session["listOfWalls"] = listOfWalls;
            }
        }
示例#2
0
        public void FillSpaceWithWindows(string windowType, string windowColour, string framingColour, int numberOfVents, float kneewallHeight, string kneewallType, string transomType, 
            bool sunshade, string valance, string fabric, string openness, string chain, string screenType, double railing)
        {
            float currentLocation = 0f;

            //Loop through linear items using currentLocation to keep track
            for (int i = 0; i <= LinearItems.Count; i++)//
            {
                try
                {
                    //If an item starts at this location, we aren't in a workable area
                    if (LinearItems[i].FixedLocation == currentLocation)
                    {
                        //We set the location equal to the length of the linear item, which is the end of it
                        currentLocation += LinearItems[i].Length;
                    }
                    //Item must start after current
                    else if (LinearItems[i].FixedLocation > currentLocation)
                    {
                        //The space is equal to where the next item starts - current location
                        float space = LinearItems[i].FixedLocation - currentLocation;
                        float numOfWindowsInThisSpace = 1; //If the space is too large for one window mod, we need this many
                        float eachSpace = space; //If the space is too large for one window mod, we'll have a # of mods of this size

                        float MAX_MOD_WIDTH = 0;
                        float MIN_MOD_WIDTH = 0;

                        switch (windowType)
                        {
                            case "Fixed Vinyl":
                                MIN_MOD_WIDTH = Constants.VINYL_TRAP_MIN_WIDTH_WARRANTY; //We use the trap version because they can have both
                                MAX_MOD_WIDTH = Constants.VINYL_TRAP_MAX_WIDTH_WARRANTY;
                                break;

                            case "Fixed Glass 2\"":
                                MIN_MOD_WIDTH = Constants.VINYL_TRAP_MIN_WIDTH_WARRANTY; //We use the trap version because they can have both
                                MAX_MOD_WIDTH = Constants.VINYL_TRAP_MAX_WIDTH_WARRANTY;
                                break;

                            case "Fixed Glass 3\"":
                                MIN_MOD_WIDTH = Constants.VINYL_TRAP_MIN_WIDTH_WARRANTY; //We use the trap version because they can have both
                                MAX_MOD_WIDTH = Constants.VINYL_TRAP_MAX_WIDTH_WARRANTY;
                                break;

                            case "Vertical 4 Track":
                                MIN_MOD_WIDTH = Constants.V4T_4V_MIN_WIDTH_WARRANTY; //We use the trap version because they can have both
                                MAX_MOD_WIDTH = Constants.V4T_4V_MAX_WIDTH_WARRANTY;
                                break;

                            case "Horizontal 2 Track":
                            case "Horizontal Roller":
                                MIN_MOD_WIDTH = Constants.HORIZONTAL_ROLLER_MIN_WIDTH_WARRANTY; //We use the trap version because they can have both
                                MAX_MOD_WIDTH = Constants.HORIZONTAL_ROLLER_MAX_WIDTH_WARRANTY;
                                break;

                            case "Single Slider":
                                MIN_MOD_WIDTH = Constants.SINGLE_SLIDER_MIN_WIDTH_WARRANTY; //We use the trap version because they can have both
                                MAX_MOD_WIDTH = Constants.SINGLE_SLIDER_MAX_WIDTH_WARRANTY;
                                break;

                            case "Double Slider":
                                MIN_MOD_WIDTH = Constants.DOUBLE_SLIDER_MIN_WIDTH_WARRANTY; //We use the trap version because they can have both
                                MAX_MOD_WIDTH = Constants.DOUBLE_SLIDER_MAX_WIDTH_WARRANTY;
                                break;

                            case "Open Wall":
                                MIN_MOD_WIDTH = Constants.V4T_4V_MIN_WIDTH_WARRANTY; //We use the trap version because they can have both
                                MAX_MOD_WIDTH = Constants.V4T_4V_MAX_WIDTH_WARRANTY;
                                break;

                            case "Solid Wall":
                                MIN_MOD_WIDTH = Constants.V4T_4V_MIN_WIDTH_WARRANTY; //We use the trap version because they can have both
                                MAX_MOD_WIDTH = Constants.V4T_4V_MAX_WIDTH_WARRANTY;
                                break;

                            case "Screen":
                                MIN_MOD_WIDTH = Constants.SCREEN_MIN_WIDTH_WARRANTY; //We use the trap version because they can have both
                                MAX_MOD_WIDTH = Constants.SCREEN_MAX_WIDTH_WARRANTY;
                                break;
                        }

                        //Find optimal lengths of window mods given space
                        float[] windowSpecifics = FindOptimalLengthOfWindowModsGivenSpace(space, MIN_MOD_WIDTH, MAX_MOD_WIDTH);

                        float height;

                        //Loop mod creation for each window counted in this space
                        for (int windowCounter = 0; windowCounter < windowSpecifics[1]; windowCounter++)
                        {
                            //We have a space, so create a window mod to fill it
                            Mod aMod = new Mod();
                            aMod.FixedLocation = currentLocation;
                            aMod.StartHeight = GetHeightAtLocation(currentLocation);
                            aMod.EndHeight = GetHeightAtLocation(currentLocation + windowSpecifics[0]);
                            aMod.ItemType = "Mod";
                            aMod.Length = windowSpecifics[0];
                            if (windowCounter == 0)
                            {
                                aMod.Length += windowSpecifics[2];
                            }
                            aMod.ModType = "Window";
                            aMod.Sunshade = sunshade;
                            aMod.SunshadeValance = valance;
                            aMod.SunshadeFabric = fabric;
                            aMod.SunshadeOpenness = openness;
                            aMod.SunshadeChain = chain;

                            height = Math.Max(aMod.StartHeight, aMod.EndHeight);

                            //Check for kneewall info
                            if (kneewallHeight > 0)
                            {
                                //Have one
                                Kneewall aKneewall = new Kneewall();
                                aKneewall.FEndHeight = aKneewall.FStartHeight = kneewallHeight;
                                aKneewall.EndHeight = aKneewall.StartHeight = kneewallHeight - 2.125f;
                                height -= kneewallHeight; //Remove this from usable height, as the kneewall takes it up
                                aKneewall.KneewallType = kneewallType;
                                aKneewall.ItemType = "Kneewall";
                                aKneewall.FLength = aMod.Length - 2;
                                aMod.ModularItems.Add(aKneewall);
                            }

                            float highestPunch = 0f;
                            //Kneewall will have been added now, or not, either way we add the window
                            //find highest punch
                            for (int j = 0; j < LinearItems.Count; j++)
                            {
                                if (LinearItems[j].ItemType == "Mod")
                                {
                                    Mod tempMod = (Mod)LinearItems[j];

                                    if (tempMod.ModType == "Door")
                                    {
                                        //check 0 because door will always be first item in door mod
                                        if (((Door)tempMod.ModularItems[0]).Punch > highestPunch)
                                        {
                                            highestPunch = ((Door)tempMod.ModularItems[0]).Punch;
                                        }
                                    }
                                }
                            }

                            //If punch is 0 at this point there are no doors, in such a case, we will set the punch to be a set distance below the min height of the wall
                            //That way we arbitrarily set a location for the transom to start and maintain consistency.
                            if (highestPunch == 0)
                            {
                                highestPunch = GlobalFunctions.RoundDownToNearestEighthInch(Math.Min(StartHeight, EndHeight) - 4.125F - Constants.KNEEWALL_PUNCH); //changeme based on type
                            }
                            //Now we know where the ending height is, so we subtract kneewall to get the height of the window
                            //Punch takes up space too, so subtract it as well
                            float windowHeight = highestPunch - kneewallHeight - Constants.KNEEWALL_PUNCH;
                            //Create the window
                            Window aWindow = new Window();
                            aWindow.FEndHeight = aWindow.FStartHeight = windowHeight; //CHANGEME hardcoded 2.125
                            aWindow.RightHeight = aWindow.LeftHeight = windowHeight - 2.125f;
                            aWindow.FLength = aMod.Length - 2;
                            aWindow.Width = aWindow.FLength - 2.125f; //CHANGEME hardcoded
                            aWindow.Colour = windowColour;
                            aWindow.FrameColour = framingColour;
                            aWindow.ItemType = "Window";
                            aWindow.NumVents = numberOfVents;
                            aWindow.ScreenType = screenType; //fixt
                            aWindow.WindowStyle = windowType;

                            //Check for spreader bar boolean
                            if (windowType == "Vertical 4 Track" && aWindow.FLength > Constants.V4T_SPREADER_BAR_NEEDED)
                            {
                                aWindow.SpreaderBar = (aWindow.FLength/2) - (Constants.SPREADER_BAR_SIZE/2); //Find center of window, then place center of spreader bar at that position (by subtracting half of it)
                            }
                            if (windowType == "Horizontal Roller" && aWindow.FLength > Constants.HORIZONTAL_ROLLER_SPREADER_BAR_NEEDED)
                            {
                                aWindow.SpreaderBar = (aWindow.FEndHeight/2) - (Constants.SPREADER_BAR_SIZE/2);
                                aWindow.WindowStyle = "Horizontal Roller XO";
                            }
                            if (windowType == "Vinyl")
                            {
                                if (aWindow.FLength > Constants.TRANSOM_SPREADER_BAR_REQUIRED || aWindow.FEndHeight > Constants.TRANSOM_SPREADER_BAR_REQUIRED || aWindow.FStartHeight > Constants.TRANSOM_SPREADER_BAR_REQUIRED)
                                {
                                    //If length is longer, vertical bar, else horizontal bar
                                    if (aWindow.Width >= aWindow.FEndHeight && aWindow.Width >= aWindow.FStartHeight)
                                    {
                                        aWindow.SpreaderBar = (aWindow.FLength / 2) - (Constants.SPREADER_BAR_SIZE / 2);
                                    }
                                    else
                                    {
                                        aWindow.SpreaderBar = (aWindow.FEndHeight / 2) - (Constants.SPREADER_BAR_SIZE / 2);
                                    }
                                    //If dimensions are equal?
                                }
                            }

                            aWindow.IntegratedRailing = railing;

                            aMod.ModularItems.Add(aWindow);

                            //Now we handle transom
                            float modStartWallHeight = GlobalFunctions.getHeightAtPosition(StartHeight, EndHeight, currentLocation, Length);
                            float modEndWallHeight = GlobalFunctions.getHeightAtPosition(StartHeight, EndHeight, (currentLocation + aMod.Length), Length);
                            float spaceAbovePunch = Math.Max(modStartWallHeight, modEndWallHeight) - highestPunch - .25f; //Punch physical space

                            float[] transomInfo = GlobalFunctions.findOptimalHeightsOfWindows(spaceAbovePunch, transomType);

                            if (StartHeight == EndHeight)
                            {
                                //rectangular window
                                for (int currentWindow = 0; currentWindow < transomInfo[0]; currentWindow++)
                                {
                                    //Set window properties
                                    Window aTransom = new Window();
                                    aTransom.FEndHeight = aTransom.FStartHeight = transomInfo[1]; //Window with frame
                                    aTransom.RightHeight = aTransom.LeftHeight = transomInfo[1] - 2.125f; //Window itself
                                    aTransom.Colour = windowColour;
                                    aTransom.ItemType = "Window";
                                    aTransom.FLength = aMod.Length - 2;
                                    aTransom.Width = aTransom.FLength - 2.125f;
                                    aTransom.WindowStyle = transomType;
                                    if (currentWindow == 0)
                                    {
                                        aTransom.FEndHeight += transomInfo[2];
                                        aTransom.FStartHeight += transomInfo[2];
                                        aTransom.RightHeight += transomInfo[2];
                                        aTransom.LeftHeight += transomInfo[2];
                                    }

                                    if (aTransom.FLength > Constants.TRANSOM_SPREADER_BAR_REQUIRED || aTransom.FEndHeight > Constants.TRANSOM_SPREADER_BAR_REQUIRED || aTransom.FStartHeight > Constants.TRANSOM_SPREADER_BAR_REQUIRED)
                                    {
                                        //If length is longer, vertical bar, else horizontal bar
                                        if (aTransom.Width > aTransom.FEndHeight && aTransom.Width > aTransom.FStartHeight)
                                        {
                                            aTransom.SpreaderBar = (aTransom.FLength / 2) - (Constants.SPREADER_BAR_SIZE / 2);
                                        }
                                        else
                                        {
                                            aTransom.SpreaderBar = (aTransom.FEndHeight / 2) - (Constants.SPREADER_BAR_SIZE / 2);
                                        }
                                        //If dimensions are equal?
                                    }
                                    aMod.ModularItems.Add(aTransom);
                                }
                            }
                            else
                            {
                                //trapezoid
                                float nextTransomHeight;

                                //If start wall is higher, lower end height
                                if (modStartWallHeight == Math.Max(modStartWallHeight, modEndWallHeight))
                                {
                                    nextTransomHeight = transomInfo[1];
                                }
                                else
                                {
                                    nextTransomHeight = transomInfo[1] - (Math.Max(modStartWallHeight, modEndWallHeight) - Math.Min(modStartWallHeight, modEndWallHeight));
                                }

                                for (int currentWindow = 0; currentWindow < transomInfo[0]; currentWindow++)
                                {
                                    //Set window properties
                                    Window aTransom = new Window();
                                    aTransom.Colour = windowColour;
                                    aTransom.ItemType = "Window";
                                    aTransom.FLength = aMod.Length - 2;
                                    aTransom.Width = aMod.Length - 2 - 2.125f;
                                    aTransom.WindowStyle = transomType;

                                    aTransom.FStartHeight = nextTransomHeight;
                                    aTransom.LeftHeight = aTransom.FStartHeight - 2.125f;
                                    //If start wall is higher, lower end height
                                    if (modStartWallHeight == Math.Max(modStartWallHeight, modEndWallHeight))
                                    {
                                        aTransom.FEndHeight = aTransom.FStartHeight - (modStartWallHeight - modEndWallHeight);
                                    }
                                    else
                                    {
                                        aTransom.FEndHeight = aTransom.FStartHeight + (modEndWallHeight - modStartWallHeight);
                                    }

                                    aTransom.RightHeight = aTransom.FEndHeight - 2.125f;
                                    nextTransomHeight = aTransom.FEndHeight;

                                    //Add remaining area to first window
                                    if (currentWindow == 0)
                                    {
                                        aTransom.FEndHeight += transomInfo[2];
                                        aTransom.FStartHeight += transomInfo[2];
                                        aTransom.RightHeight += transomInfo[2];
                                        aTransom.LeftHeight += transomInfo[2];
                                    }

                                    aTransom.FStartHeight = GlobalFunctions.RoundDownToNearestEighthInch(aTransom.FStartHeight);
                                    aTransom.FEndHeight = GlobalFunctions.RoundDownToNearestEighthInch(aTransom.FEndHeight);
                                    aTransom.LeftHeight = GlobalFunctions.RoundDownToNearestEighthInch(aTransom.LeftHeight);
                                    aTransom.RightHeight = GlobalFunctions.RoundDownToNearestEighthInch(aTransom.RightHeight);

                                    ////If last window, we need to change a height to make it sloped
                                    //if (currentWindow == transomInfo[0] - 1)
                                    //{
                                    //    //If start wall is higher, we lower end height
                                    //    if (modStartWallHeight == Math.Max(modStartWallHeight, modEndWallHeight))
                                    //    {
                                    //        aTransom.FEndHeight -= (modStartWallHeight - modEndWallHeight);
                                    //        aTransom.RightHeight -= (modStartWallHeight - modEndWallHeight);
                                    //    }
                                    //    //Otherwise we lower start height
                                    //    else
                                    //    {
                                    //        aTransom.FStartHeight -= (modEndWallHeight - modStartWallHeight);
                                    //        aTransom.LeftHeight -= (modEndWallHeight - modStartWallHeight);
                                    //    }
                                    //}
                                    aMod.ModularItems.Add(aTransom);
                                }
                            }

                            //float[] windowInfo = GlobalFunctions.findOptimalHeightsOfWindows
                            //Find where to place the mod, and place it
                            for (int j = 0; j < LinearItems.Count; j++)
                            {
                                if (LinearItems[j].FixedLocation > aMod.FixedLocation)
                                {
                                    //j is past, so we insert into j-1 and exit the loop
                                    LinearItems.Insert(j, aMod);
                                    break;
                                }
                            }
                            //Sets currentlocation to the ending location of current linear item
                            currentLocation = currentLocation + aMod.Length;
                        }
                    }
                }
                catch (Exception ex)
                {
                    //If caught, it's because we tried to touch the next linear item but it was past the last
                    //Check currentLocation to see if there is still space left
                }
            }
        }
        ///// <summary>
        ///// This is an event that is used to dynamically create wall objects with the appropriate details
        ///// </summary>
        ///// <param name="sender"></param>
        ///// <param name="e"></param>
        //protected void createWallObjects(object sender, EventArgs e)
        //{
        //    //there are issues with getting values from dynamically generated hidden fields
        //    //hard coded hidden fields work fine...
        //    //need to dynamically determine slope, and soffit length of each wall and store it in hidden fields
        //    float length, startHeight, endHeight, soffit;//, slope;
        //    string orientation, name, type, model;
        //    HiddenField wallLength, wallSoffit;
        //    for (int i = 0; i < strWalls.Count(); i++)
        //    {
        //        //find and store the dynamically created hidden fields
        //        wallLength = hiddenFieldsDiv.FindControl("hidWall" + i + "Length") as HiddenField; //wall length
        //        wallSoffit = hiddenFieldsDiv.FindControl("hidWall" + i + "SoffitLength") as HiddenField; //wall soffit length
        //        //length = wallLength.Value;
        //        //startHeight = Convert.ToSingle(hidHeight.Value);
        //        //endHeight = Convert.ToSingle(hidFrontWallHeight.Value);
        //        //soffit = Convert.ToSingle(wallSoffit.Value);
        //       // slope = Convert.ToSingle(hidRoofSlope.Value);
        //        orientation = wallDetails[i, 5];
        //        name = "wall " + i;
        //        type = wallDetails[i, 4];
        //        model = currentModel;
        //        //string sof = wallSoffit.Value;
        //        //create a wall object with the appropriate values in the fields and attributes of it and add it to the walls list
        //        //walls.Add(new Wall(Convert.ToSingle(wallLength.Value), wallDetails[i, 5], "Wall" + i, wallDetails[i, 4], Convert.ToSingle(hidBackWallHeight.Value), Convert.ToSingle(hidBackWallHeight.Value), /*Convert.ToSingle(wallSoffit.Value)*/ 0F, currentModel));
        //    }
        //}
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            //Create objects
            List<Wall> listOfWalls = new List<Wall>();

            int existingWallCount = 0;
            Session.Add("roomWidth", hidRoomWidth.Value);
            Session.Add("roomProjection", hidRoomProjection.Value);

            for (int i = 1; i <= strWalls.Length; i++)
            {
                //if blank its an existing wall, so skip it
                if (Request.Form["hidWall" + i + "Length"] != "")
                {
                    Wall aWall = new Wall();
                    aWall.Length = float.Parse(Request.Form["hidWall" + i + "Length"]);
                    aWall.Orientation = Request.Form["hidWall" + i + "Orientation"];
                    aWall.Name = "Wall " + (i-existingWallCount);
                    aWall.WallType = "Proposed";
                    aWall.ModelType = currentModel;
                    aWall.StartHeight = GlobalFunctions.RoundDownToNearestEighthInch(float.Parse(Request.Form["hidWall" + i + "StartHeight"]));
                    aWall.EndHeight = GlobalFunctions.RoundDownToNearestEighthInch(float.Parse(Request.Form["hidWall" + i + "EndHeight"]));
                    aWall.SoffitLength = float.Parse(Request.Form["hidWall" + i + "SoffitLength"]);
                    aWall.GablePeak = 0;

                    listOfWalls.Add(aWall);
                    //firstItemIndex,lastItemIndex handled below
                    //totalCornerLength,totalReceiverLength unhandled
                    //linearItems handled below
                }
                else
                {
                    existingWallCount++;
                }
            }

            //Loop for each wall
            int linearPosition = 0; //Current wall we're on
            int cheatCounter = 0;
            //If it's a gable, we need to start one element past the normal point to account for the gable post being part of the wall list
            int gableCompensation = 0;

            if (gableType != "")
            {
                gableCompensation = 1;
            }

            for (int i = 1 + gableCompensation; i <= strWalls.Length; i++)
            {
                //A list of linear items to be added to each wall
                List<LinearItem> linearItems = new List<LinearItem>();
                bool addReceiver = true;

                if (wallDetails[i - 1, 4] == "P" || wallDetails[i - 1, 4] == "G")
                {
                    #region Wall Creation
                    float wallStartHeight = (float.Parse(Request.Form["hidWall" + i + "StartHeight"]));
                    float wallEndHeight = (float.Parse(Request.Form["hidWall" + i + "EndHeight"]));
                    float wallLeftFiller = (float.Parse(Request.Form["hidWall" + i + "LeftFiller"]));
                    float wallRightFiller = (float.Parse(Request.Form["hidWall" + i + "RightFiller"]));
                    float wallDoorCount = Int32.Parse(Request.Form["hidWall" + i + "DoorCount"]);
                    bool gableCheck = false;

                    //If this is a gable front wall of some form (gbale wall, gablefrontwall)
                    //Then we have no need for the corners that would be added
                    if (gableType.Contains("Gable") && wallStartHeight < wallEndHeight)
                    {
                        gableCheck = true;

                        if (currentModel == "M400")
                        {
                            wallRightFiller -= 4.125f;
                        }
                        else
                        {
                            wallRightFiller -= 3.125f;
                        }
                    }

                    //The same for the right gable wall
                    if (gableType.Contains("Gable") && wallStartHeight > wallEndHeight)
                    {
                        gableCheck = true;

                        if (currentModel == "M400")
                        {
                            wallLeftFiller -= 4.125f;
                        }
                        else
                        {
                            wallLeftFiller -= 3.125f;
                        }
                    }
                    //if it has doors, do logic w/ doors, otherwise just directly go to window creation
                    //CHANGEME 2,125/2 are hardcoded instead of constants
                    if (wallDoorCount > 0)
                    {
                        //Left filler
                        //The current program hasn't considered the space receievers or corner posts take up in a wall's length
                        //So we're going to cheat it here by adding that 'space' to the fillers, and removing it later when the
                        //Wall objects are being built, which is here.
                        if (cheatCounter == 0)
                        {
                            wallLeftFiller -= 1;//CHANGEME receiver length
                            Receiver aReceiver = new Receiver();
                            aReceiver.ItemType = "Receiver";
                            aReceiver.StartHeight = aReceiver.EndHeight = GlobalFunctions.getHeightAtPosition(wallStartHeight, wallEndHeight, 0, listOfWalls[0].Length);
                            aReceiver.Length = 1f;
                            aReceiver.FixedLocation = 0;
                            linearItems.Insert(0,aReceiver);
                            cheatCounter++;
                        }
                        else
                        {
                            //If this is a gable front wall of some form (gbale wall, gablefrontwall)
                            //Then we have no need for the corners that would be added
                            if (!(gableType.Contains("Gable") && wallStartHeight > wallEndHeight))
                            {
                                if (currentModel == "M400")
                                {
                                    Corner aCorner = new Corner();
                                    aCorner.StartHeight = aCorner.EndHeight = GlobalFunctions.getHeightAtPosition(wallStartHeight, wallEndHeight, 0, listOfWalls[0].Length);
                                    aCorner.Length = 4.125f;
                                    aCorner.ItemType = "Corner";
                                    wallLeftFiller -= aCorner.Length;
                                    linearItems.Add(aCorner);
                                }
                                else
                                {
                                    Corner aCorner = new Corner();
                                    aCorner.StartHeight = aCorner.EndHeight = GlobalFunctions.getHeightAtPosition(wallStartHeight, wallEndHeight, 0, listOfWalls[0].Length);
                                    aCorner.Length = 3.125f;
                                    aCorner.ItemType = "Corner";
                                    wallLeftFiller -= aCorner.Length;
                                    linearItems.Add(aCorner);
                                }
                                cheatCounter++;
                            }
                        }

                        //loop for each door
                        for (int j = 1; j <= wallDoorCount; j++)
                        {
                            if (Request.Form["hidWall" + i + "Door" + j + "boxHeader"] == "Left" || Request.Form["hidWall" + i + "Door" + j + "boxHeader"] == "Both")
                            {
                                if (currentModel == "M400")
                                {
                                    HChannel anHChannel = new HChannel();
                                    anHChannel.ItemType = "HChannel";
                                    anHChannel.Length = Constants.HCHANNEL_LENGTH;
                                    //CHANGEME if driftwood
                                    anHChannel.FixedLocation = Convert.ToSingle(Request.Form["hidWall" + i + "Door" + j + "position"]) - anHChannel.Length;
                                    anHChannel.StartHeight = GlobalFunctions.getHeightAtPosition(wallStartHeight, wallEndHeight, anHChannel.FixedLocation, listOfWalls[linearPosition].Length);
                                    anHChannel.EndHeight = GlobalFunctions.getHeightAtPosition(wallStartHeight, wallEndHeight, anHChannel.FixedLocation + anHChannel.Length, listOfWalls[linearPosition].Length);
                                    linearItems.Add(anHChannel);
                                }
                                else
                                {
                                    BoxHeader aBoxHeader = new BoxHeader();
                                    aBoxHeader.ItemType = "BoxHeader";
                                    aBoxHeader.Length = Constants.BOXHEADER_LENGTH;
                                    aBoxHeader.FixedLocation = Convert.ToSingle(Request.Form["hidWall" + i + "Door" + j + "position"]) - aBoxHeader.Length;
                                    aBoxHeader.StartHeight = GlobalFunctions.getHeightAtPosition(wallStartHeight, wallEndHeight, aBoxHeader.FixedLocation, listOfWalls[linearPosition].Length);
                                    aBoxHeader.EndHeight = GlobalFunctions.getHeightAtPosition(wallStartHeight, wallEndHeight, aBoxHeader.FixedLocation + aBoxHeader.Length, listOfWalls[linearPosition].Length);
                                    linearItems.Add(aBoxHeader);
                                }
                            }

                            Mod aMod = new Mod();//
                            aMod.ItemType = "Mod";
                            aMod.ModType = Constants.MOD_TYPE_DOOR;
                            aMod.Length = float.Parse(Request.Form["hidWall" + i + "Door" + j + "mwidth"]);
                            aMod.FixedLocation = float.Parse(Request.Form["hidWall" + i + "Door" + j + "position"]);// +linearItems[0].Length;
                            aMod.StartHeight = GlobalFunctions.getHeightAtPosition(wallStartHeight, wallEndHeight, aMod.FixedLocation, float.Parse(Request.Form["hidWall" + i + "Length"]));
                            aMod.EndHeight = GlobalFunctions.getHeightAtPosition(wallStartHeight, wallEndHeight, (aMod.FixedLocation + aMod.Length), float.Parse(Request.Form["hidWall" + i + "Length"]));
                            aMod.Sunshade = Convert.ToBoolean(Request.Form["MainContent_hidSunshade"]);
                            aMod.SunshadeValance = (string)Request.Form["MainContent_hidValance"];
                            aMod.SunshadeFabric = (string)Request.Form["MainContent_hidFabric"];
                            aMod.SunshadeOpenness = (string)Request.Form["MainContent_hidOpenness"];
                            aMod.SunshadeChain = (string)Request.Form["MainContent_hidChain"];

                            List<ModuleItem> modularItems = new List<ModuleItem>();
                            string doorType = Request.Form["hidWall" + i + "Door" + j + "type"];
                            if (doorType == "Cabana")
                            {
                                //cast test? does it retain cabana info?
                                Door aDoor = getCabanaDoorFromForm(i, j);
                                aDoor.Punch = aDoor.FEndHeight;

                                Window doorWindow = new Window();
                                doorWindow.WindowStyle = Request.Form["hidWall" + i + "Door" + j + "style"];
                                doorWindow.FLength = aDoor.FLength - Constants.DOOR_PADDING; //11.5 is the amount of door between edge of door and start of window (both sides totalled to 11.5)
                                doorWindow.Width = doorWindow.FLength - 2.125f;
                                doorWindow.FStartHeight = doorWindow.FEndHeight = aDoor.FStartHeight - aDoor.Kickplate - Constants.KICKPLATE_PADDING; //4 corresponds to the amount of framing at a bottom of a door
                                doorWindow.LeftHeight = doorWindow.RightHeight = aDoor.FStartHeight - aDoor.Kickplate - Constants.KICKPLATE_PADDING - 2.125f;
                                doorWindow.ItemType = "Window";
                                doorWindow.FrameColour = Request.Form["MainContent_hidWindowFramingColour"];
                                doorWindow.SpreaderBar = -1;
                                doorWindow.ScreenType = "No Screen";

                                if (doorWindow.WindowStyle == "Vertical Four Track" || doorWindow.WindowStyle.Contains("Vinyl"))
                                {
                                    doorWindow.Colour = Request.Form["hidWall" + i + "Door" + j + "vinylTint"];
                                    doorWindow.NumVents = Convert.ToInt32(Request.Form["hidWall" + i + "Door" + j + "numberOfVents"]);
                                }
                                else if (!doorWindow.WindowStyle.Contains("Screen"))
                                {
                                    doorWindow.Colour = Request.Form["hidWall" + i + "Door" + j + "glassTint"];
                                }
                                else {
                                    doorWindow.ScreenType = Request.Form["hidWall" + i + "Door" + j + "screenOptions"];
                                }
                                if (doorWindow.WindowStyle == "Horizontal Roller")
                                {
                                    doorWindow.NumVents = 2;
                                    doorWindow.WindowStyle = "Horizontal Roller XO";
                                }

                                //Spreaderbar logic
                                if (doorWindow.WindowStyle == "Vertical 4 Track" && doorWindow.FLength > Constants.V4T_SPREADER_BAR_NEEDED)
                                {
                                    doorWindow.SpreaderBar = (doorWindow.FLength / 2) - (Constants.SPREADER_BAR_SIZE / 2); //Find center of window, then place center of spreader bar at that position (by subtracting half of it)
                                }
                                if (doorWindow.WindowStyle.Contains("Horizontal Roller") && doorWindow.FLength > Constants.HORIZONTAL_ROLLER_SPREADER_BAR_NEEDED)
                                {
                                    doorWindow.SpreaderBar = (doorWindow.FEndHeight / 2) - (Constants.SPREADER_BAR_SIZE / 2);
                                }
                                if (doorWindow.WindowStyle == "Vinyl")
                                {
                                    if (doorWindow.FLength > Constants.TRANSOM_SPREADER_BAR_REQUIRED || doorWindow.FEndHeight > Constants.TRANSOM_SPREADER_BAR_REQUIRED || doorWindow.FStartHeight > Constants.TRANSOM_SPREADER_BAR_REQUIRED)
                                    {
                                        //If length is longer, vertical bar, else horizontal bar
                                        if (doorWindow.Width >= doorWindow.FEndHeight && doorWindow.Width >= doorWindow.FStartHeight)
                                        {
                                            doorWindow.SpreaderBar = (doorWindow.FLength / 2) - (Constants.SPREADER_BAR_SIZE / 2);
                                        }
                                        else
                                        {
                                            doorWindow.SpreaderBar = (doorWindow.FEndHeight / 2) - (Constants.SPREADER_BAR_SIZE / 2);
                                        }
                                        //If dimensions are equal?
                                    }
                                }

                                aDoor.DoorWindow = doorWindow;
                                modularItems.Add(aDoor);
                            }
                            if (doorType == "Patio")
                            {
                                Door aDoor = getPatioDoorFromForm(i, j);
                                aDoor.Punch = aDoor.FEndHeight;

                                Window doorWindow = new Window();
                                doorWindow.FLength = aDoor.FLength - Constants.DOOR_PADDING; //11.5 is the amount of door between edge of door and start of window (both sides totalled to 11.5)
                                doorWindow.Width = doorWindow.FLength - 2.125f;
                                doorWindow.ItemType = "Window";
                                doorWindow.WindowStyle = Request.Form["hidWall" + i + "Door" + j + "style"];
                                doorWindow.FStartHeight = doorWindow.FEndHeight = aDoor.FStartHeight; //4 corresponds to the amount of framing at a bottom of a door
                                doorWindow.LeftHeight = doorWindow.RightHeight = aDoor.FStartHeight - 2.125f;
                                doorWindow.Colour = Request.Form["hidWall" + i + "Door" + j + "glassTint"];
                                doorWindow.ScreenType = Request.Form["hidWall" + i + "Door" + j + "screenOptions"];
                                doorWindow.FrameColour = Request.Form["MainContent_hidWindowFramingColour"];
                                doorWindow.SpreaderBar = -1;
                                aDoor.DoorWindow = doorWindow;

                                modularItems.Add(aDoor);
                            }
                            if (doorType == "French")
                            {
                                Door aDoor = getFrenchDoorFromForm(i, j);
                                aDoor.Punch = aDoor.FEndHeight;

                                Window doorWindow = new Window();
                                doorWindow.WindowStyle = Request.Form["hidWall" + i + "Door" + j + "style"];
                                doorWindow.FLength = aDoor.FLength - Constants.DOOR_PADDING;
                                doorWindow.Width = doorWindow.FLength - 2.125f;
                                doorWindow.FStartHeight = doorWindow.FEndHeight = aDoor.FStartHeight - aDoor.Kickplate - Constants.KICKPLATE_PADDING; //4 corresponds to the amount of framing at a bottom of a door;
                                doorWindow.LeftHeight = doorWindow.RightHeight = aDoor.FStartHeight - aDoor.Kickplate - Constants.KICKPLATE_PADDING - 2.125f; //4 corresponds to the amount of framing at a bottom of a door;
                                doorWindow.ItemType = "Window";
                                doorWindow.FrameColour = Request.Form["MainContent_hidWindowFramingColour"];
                                doorWindow.SpreaderBar = -1;

                                if (doorWindow.WindowStyle == "Vertical 4 Track" || doorWindow.WindowStyle == "Vertical Four Track" || doorWindow.WindowStyle.Contains("Vinyl"))
                                {
                                    doorWindow.Colour = Request.Form["hidWall" + i + "Door" + j + "vinylTint"];
                                    if (doorWindow.WindowStyle == "Vertical 4 Track" || doorWindow.WindowStyle == "Vertical Four Track")
                                    {
                                        doorWindow.NumVents = Convert.ToInt32(Request.Form["hidWall" + i + "Door" + j + "numberOfVents"]);
                                    }
                                }
                                else if (!doorWindow.WindowStyle.Contains("Screen"))
                                {
                                    doorWindow.Colour = Request.Form["hidWall" + i + "Door" + j + "glassTint"];
                                }
                                else
                                {
                                    doorWindow.Colour = "";
                                    doorWindow.ScreenType = Request.Form["hidWall" + i + "Door" + j + "screenOptions"];
                                }
                                if (doorWindow.WindowStyle == "Horizontal Roller")
                                {
                                    doorWindow.NumVents = 2;
                                    doorWindow.WindowStyle = "Horizontal Roller XO";
                                }

                                //Spreaderbar logic
                                if (doorWindow.WindowStyle == "Vertical 4 Track" && doorWindow.FLength > Constants.V4T_SPREADER_BAR_NEEDED)
                                {
                                    doorWindow.SpreaderBar = (doorWindow.FLength / 2) - (Constants.SPREADER_BAR_SIZE / 2); //Find center of window, then place center of spreader bar at that position (by subtracting half of it)
                                }
                                if (doorWindow.WindowStyle.Contains("Horizontal Roller") && doorWindow.FLength > Constants.HORIZONTAL_ROLLER_SPREADER_BAR_NEEDED)
                                {
                                    doorWindow.SpreaderBar = (doorWindow.FEndHeight / 2) - (Constants.SPREADER_BAR_SIZE / 2);
                                }
                                if (doorWindow.WindowStyle == "Vinyl")
                                {
                                    if (doorWindow.FLength > Constants.TRANSOM_SPREADER_BAR_REQUIRED || doorWindow.FEndHeight > Constants.TRANSOM_SPREADER_BAR_REQUIRED || doorWindow.FStartHeight > Constants.TRANSOM_SPREADER_BAR_REQUIRED)
                                    {
                                        //If length is longer, vertical bar, else horizontal bar
                                        if (doorWindow.Width >= doorWindow.FEndHeight && doorWindow.Width >= doorWindow.FStartHeight)
                                        {
                                            doorWindow.SpreaderBar = (doorWindow.FLength / 2) - (Constants.SPREADER_BAR_SIZE / 2);
                                        }
                                        else
                                        {
                                            doorWindow.SpreaderBar = (doorWindow.FEndHeight / 2) - (Constants.SPREADER_BAR_SIZE / 2);
                                        }
                                        //If dimensions are equal?
                                    }
                                }

                                aDoor.DoorWindow = doorWindow;
                                modularItems.Add(aDoor);
                            }
                            if (doorType == "NoDoor")
                            {
                                Door aDoor = getNoDoorFromForm(i, j);
                                aDoor.Punch = aDoor.FEndHeight;

                                Window doorWindow = new Window();
                                doorWindow.WindowStyle = Request.Form["hidWall" + i + "Door" + j + "style"];
                                //doorWindow.FLength = aDoor.FLength - SOMEVALUE;
                                doorWindow.Width = doorWindow.FLength - 2.125f;
                                //doorWindow.FStartHeight = doorWindow.FStartHeight = SOMEVALUE;
                                //doorWindow.StartHeight = doorWindow.EndHeight = SOMEVALUE;
                                doorWindow.ItemType = "Window";
                                doorWindow.SpreaderBar = -1;

                                aDoor.DoorWindow = doorWindow;
                                modularItems.Add(aDoor);
                            }

                            //Extra door stuff here

                            //now we add transom windows
                            //The height of the wall at mod end and mod start
                            float modStartHeight = GlobalFunctions.getHeightAtPosition(wallStartHeight, wallEndHeight, aMod.FixedLocation, float.Parse(Request.Form["hidWall" + i + "Length"]));//
                            float modEndHeight = GlobalFunctions.getHeightAtPosition(wallStartHeight, wallEndHeight, (aMod.FixedLocation + aMod.Length), float.Parse(Request.Form["hidWall" + i + "Length"]));

                            //The space left is the total height of the wall at the highest point of the mod minus the current built mod's space (aMod.StartHeight which equals aMod.endHeight at this point
                            //Minus the space the door punch takes up.
                            float sendableHeight = Math.Max(modStartHeight, modEndHeight);
                            float[] windowInfo = GlobalFunctions.findOptimalHeightsOfWindows((sendableHeight - modularItems[0].FStartHeight - .25f), ddlTransomType.SelectedValue);
                            if (modStartHeight == modEndHeight)
                            {
                                //rectangular window
                                for (int currentWindow = 0; currentWindow < windowInfo[0]; currentWindow++)
                                {
                                    //Set window properties
                                    Window aWindow = new Window();
                                    aWindow.FEndHeight = aWindow.FStartHeight = windowInfo[1];
                                    aWindow.RightHeight = aWindow.LeftHeight = windowInfo[1] - 2.125f; //Framing size
                                    aWindow.Colour = Request.Form["MainContent_hidWindowColour"]; //CHANGEME if v4t will be XXXX, can't use hidWallWindowColour need to ask elsewhere
                                    aWindow.FrameColour = Request.Form["MainContent_hidWindowFramingColour"];
                                    aWindow.ItemType = "Window";
                                    aWindow.FLength = aMod.Length - Constants.MOD_FRAMING_OFFSET;
                                    aWindow.Width = aWindow.FLength - Constants.WINDOW_FRAMING_OFFSET;

                                    aWindow.WindowStyle = ddlTransomType.SelectedValue;
                                    aWindow.SpreaderBar = -1;

                                    //Add remaining area to first window
                                    if (currentWindow == 0)
                                    {
                                        aWindow.FEndHeight += windowInfo[2];
                                        aWindow.FStartHeight += windowInfo[2];
                                        aWindow.RightHeight += windowInfo[2];
                                        aWindow.LeftHeight += windowInfo[2];
                                    }
                                    modularItems.Add(aWindow);
                                }
                            }
                            else
                            {
                                //trap/triangle
                                for (int currentWindow = 0; currentWindow < windowInfo[0]; currentWindow++)
                                {
                                    //Set window properties
                                    Window aWindow = new Window();
                                    aWindow.FEndHeight = aWindow.FStartHeight = windowInfo[1];
                                    aWindow.RightHeight = aWindow.LeftHeight = windowInfo[1] - 2.125f;
                                    aWindow.Colour = Request.Form["MainContent_hidWindowColour"]; //CHANGEME if v4t will be XXXX, can't use hidWallWindowColour need to ask elsewhere
                                    aWindow.FrameColour = Request.Form["MainContent_hidWindowFramingColour"];
                                    aWindow.ItemType = "Window";
                                    aWindow.FLength = aMod.Length - Constants.MOD_FRAMING_OFFSET;
                                    aWindow.Width = aWindow.FLength - Constants.WINDOW_FRAMING_OFFSET;

                                    aWindow.WindowStyle = ddlTransomType.SelectedValue;
                                    aWindow.SpreaderBar = -1;

                                    //Add remaining area to first window
                                    if (currentWindow == 0)
                                    {
                                        aWindow.FEndHeight += windowInfo[2];
                                        aWindow.FStartHeight += windowInfo[2];
                                        aWindow.RightHeight += windowInfo[2];
                                        aWindow.LeftHeight += windowInfo[2];
                                    }
                                    //If last window, we need to change a height to make it sloped
                                    if (currentWindow == windowInfo[0] - 1)
                                    {
                                        //If start wall is higher, we lower end height
                                        if (wallStartHeight == Math.Max(wallStartHeight, wallEndHeight))
                                        {
                                            aWindow.FEndHeight = aWindow.FEndHeight - (modStartHeight - modEndHeight);
                                            aWindow.RightHeight = aWindow.RightHeight - (modStartHeight - modEndHeight);
                                        }
                                        //Otherwise we lower start height
                                        else
                                        {
                                            aWindow.FStartHeight = aWindow.FStartHeight - (modEndHeight - modStartHeight);
                                            aWindow.LeftHeight = aWindow.LeftHeight - (modEndHeight - modStartHeight);
                                        }
                                    }
                                    modularItems.Add(aWindow);
                                }
                            }
                            aMod.ModularItems = modularItems;
                            linearItems.Add(aMod);

                            if (Request.Form["hidWall" + i + "Door" + j + "boxHeader"] == "Right" || Request.Form["hidWall" + i + "Door" + j + "boxHeader"] == "Both")
                            {
                                if (currentModel == "M400")
                                {
                                    HChannel anHChannel = new HChannel();
                                    anHChannel.StartHeight = anHChannel.EndHeight = Convert.ToSingle(Request.Form["hidWall" + i + "Door" + j + "mheight"]);
                                    anHChannel.Length = 2.5f;
                                    //CHANGEME if driftwood
                                    anHChannel.ItemType = "HChannel";//
                                    anHChannel.FixedLocation = Convert.ToSingle(Request.Form["hidWall" + i + "Door" + j + "position"]) - anHChannel.Length;
                                    linearItems.Add(anHChannel);
                                }
                                else
                                {
                                    BoxHeader aBoxHeader = new BoxHeader();
                                    aBoxHeader.StartHeight = aBoxHeader.EndHeight = Convert.ToSingle(Request.Form["hidWall" + i + "Door" + j + "mheight"]);
                                    aBoxHeader.Length = Constants.BOXHEADER_LENGTH;
                                    aBoxHeader.FixedLocation = Convert.ToSingle(Request.Form["hidWall" + i + "Door" + j + "position"]) - aBoxHeader.Length;
                                    aBoxHeader.ItemType = "BoxHeader";
                                    linearItems.Add(aBoxHeader);
                                }
                            }
                        }

                        int numberOfVents = 0;
                        if (hidWindowType.Value == "Vertical 4 Track" || hidWindowType.Value == "Vertical Four Track")
                        {
                            numberOfVents = hidWindowColour.Value.Length;
                        }
                        if (hidWindowType.Value == "Horizontal Roller" || hidWindowType.Value == "Horizontal 2 Track")
                        {
                            numberOfVents = 2;
                        }
                        ////Now we add the windows that fill the rest of the space
                        //string windowInfoString = Request.Form["hidWall" + i + "WindowInfo"];
                        //string[] windowInfoArray = windowInfoString.Split(detailsDelimiter, StringSplitOptions.RemoveEmptyEntries);

                        //Right filler
                        //Since we don't want to add the same corner post that is shared between walls twice, at this point we're just going to remove from filler
                        //and from wall length, so for example, a 130 length wall will actually be 126.875 and 'go into' the next corner post

                        //We try to check next wall.  If it exists, this rightside will be a corner post. If it throws an error
                        //this must be the last wall, so we only remove a receiver's worth from the right side.
                        //try
                        //{
                        //    if (wallDetails[i - 1, 4] == "P")
                        //    {
                        //        if (currentModel == "M400")
                        //        {
                        //            wallRightFiller -= 4.125f;
                        //        }
                        //        else
                        //        {
                        //            wallRightFiller -= 3.125f;
                        //        }
                        //    }
                        //}
                        //catch (Exception ex)
                        //{
                        //    wallRightFiller -= 1f;
                        //}

                        //Now add the filler itself
                        if (wallLeftFiller > 0)
                        {
                            Filler leftFiller = new Filler();
                            leftFiller.Length = wallLeftFiller;
                            //Surround this in a try, because partial gable right walls will not have an element 0.
                            //In that case, the fixedlocation would be the start, 0.
                            try
                            {
                                leftFiller.FixedLocation = linearItems[0].Length;
                                leftFiller.StartHeight = GlobalFunctions.getHeightAtPosition(wallStartHeight, wallEndHeight, leftFiller.FixedLocation, listOfWalls[linearPosition].Length);//position corresponds to this wall's first item's start point
                                leftFiller.EndHeight = GlobalFunctions.getHeightAtPosition(wallStartHeight, wallEndHeight, leftFiller.FixedLocation + leftFiller.Length, listOfWalls[linearPosition].Length);//position corresponds to this wall's first item's length
                                leftFiller.ItemType = "Filler";
                                linearItems.Insert(1, leftFiller); //Inserted as second element, after receiever or post
                            }
                            catch (Exception ex)
                            {
                                leftFiller.FixedLocation = 0;
                                leftFiller.StartHeight = GlobalFunctions.getHeightAtPosition(wallStartHeight, wallEndHeight, leftFiller.FixedLocation, listOfWalls[linearPosition].Length);//position corresponds to this wall's first item's start point
                                leftFiller.EndHeight = GlobalFunctions.getHeightAtPosition(wallStartHeight, wallEndHeight, leftFiller.FixedLocation + leftFiller.Length, listOfWalls[linearPosition].Length);//position corresponds to this wall's first item's length
                                leftFiller.ItemType = "Filler";
                                linearItems.Add(leftFiller); //Inserted as first element
                            }
                        }

                        if (wallRightFiller > 0)
                        {

                            Filler rightFiller = new Filler();
                            rightFiller.Length = wallRightFiller;
                            rightFiller.FixedLocation = listOfWalls[linearPosition].Length - wallRightFiller;
                            rightFiller.StartHeight = GlobalFunctions.getHeightAtPosition(wallStartHeight, wallEndHeight, rightFiller.FixedLocation, listOfWalls[linearPosition].Length);//position corresponds to this wall's first item's start point
                            rightFiller.EndHeight = GlobalFunctions.getHeightAtPosition(wallStartHeight, wallEndHeight, rightFiller.FixedLocation + rightFiller.Length, listOfWalls[linearPosition].Length);//position corresponds to this wall's first item's length
                            rightFiller.ItemType = "Filler";
                            linearItems.Add(rightFiller);
                        }
                        //if (currentModel == "M400")
                        //{
                        //    Corner aCorner = new Corner();
                        //    aCorner.StartHeight = aCorner.EndHeight = GlobalFunctions.getHeightAtPosition(wallStartHeight, wallEndHeight, 0, listOfWalls[0].Length);
                        //    aCorner.Length = 4.125f;
                        //    wallRightFiller -= aCorner.Length;
                        //    linearItems.Add(aCorner);
                        //}
                        //else
                        //{
                        //    Corner aCorner = new Corner();
                        //    aCorner.StartHeight = aCorner.EndHeight = GlobalFunctions.getHeightAtPosition(wallStartHeight, wallEndHeight, 0, listOfWalls[0].Length);
                        //    aCorner.Length = 4.125f;
                        //    wallRightFiller -= aCorner.Length;
                        //    linearItems.Add(aCorner);
                        //}

                        //Now that we have all the linear items, we add to each wall
                        double iRailing = -1;

                        if (hidRailing.Value == "Yes")
                        {
                            iRailing = Convert.ToDouble(hidRailingHeight.Value);
                        }

                        listOfWalls[linearPosition].LinearItems = linearItems;

                        listOfWalls[linearPosition].FillSpaceWithWindows(hidWindowType.Value, hidWindowColour.Value, hidWindowFramingColour.Value, numberOfVents, Convert.ToSingle(txtKneewallHeight.Text),
                                                                         ddlKneewallType.SelectedValue.ToString(), ddlTransomType.SelectedValue.ToString(), bool.Parse(hidSunshade.Value), hidValance.Value,
                                                                         hidFabric.Value, hidOpenness.Value, hidChain.Value, hidScreenType.Value, iRailing);

                        linearPosition++;
                    }
                    //This is a wall without doors
                    else
                    {
                        //Left filler
                        //The current program hasn't considered the space receievers or corner posts take up in a wall's length
                        //So we're going to cheat it here by adding that 'space' to the fillers, and removing it later when the
                        //Wall objects are being built, which is here.
                        if (cheatCounter == 0)
                        {
                            wallLeftFiller -= 1;//CHANGEME receiver length
                            Receiver aReceiver = new Receiver();
                            aReceiver.ItemType = "Receiver";
                            aReceiver.StartHeight = aReceiver.EndHeight = GlobalFunctions.getHeightAtPosition(wallStartHeight, wallEndHeight, 0, listOfWalls[0].Length);
                            aReceiver.Length = 1f;
                            aReceiver.FixedLocation = 0;
                            linearItems.Insert(0, aReceiver);
                            cheatCounter++;
                        }
                        else
                        {
                            //If this is a gable front wall of some form (gbale wall, gablefrontwall)
                            //Then we have no need for the corners that would be added
                            if (!(gableType.Contains("Gable") && wallStartHeight > wallEndHeight))
                            {
                                if (currentModel == "M400")
                                {
                                    Corner aCorner = new Corner();
                                    aCorner.StartHeight = aCorner.EndHeight = GlobalFunctions.getHeightAtPosition(wallStartHeight, wallEndHeight, 0, listOfWalls[0].Length);
                                    aCorner.Length = 4.125f;
                                    aCorner.ItemType = "Corner";
                                    wallLeftFiller -= aCorner.Length;
                                    linearItems.Add(aCorner);
                                }
                                else
                                {
                                    Corner aCorner = new Corner();
                                    aCorner.StartHeight = aCorner.EndHeight = GlobalFunctions.getHeightAtPosition(wallStartHeight, wallEndHeight, 0, listOfWalls[0].Length);
                                    aCorner.Length = 3.125f;
                                    aCorner.ItemType = "Corner";
                                    wallLeftFiller -= aCorner.Length;
                                    linearItems.Add(aCorner);
                                }
                                cheatCounter++;
                            }
                        }

                        int numberOfVents = 0;
                        if (hidWindowType.Value == "Vertical 4 Track" || hidWindowType.Value == "Vertical Four Track")
                        {
                            numberOfVents = hidWindowColour.Value.Length;
                        }
                        if (hidWindowType.Value == "Horizontal Roller" || hidWindowType.Value == "Horizontal 2 Track")
                        {
                            numberOfVents = 2;
                        }
                        ////Now we add the windows that fill the rest of the space
                        //string windowInfoString = Request.Form["hidWall" + i + "WindowInfo"];
                        //string[] windowInfoArray = windowInfoString.Split(detailsDelimiter, StringSplitOptions.RemoveEmptyEntries);

                        //Right filler
                        //Since we don't want to add the same corner post that is shared between walls twice, at this point we're just going to remove from filler
                        //and from wall length, so for example, a 130 length wall will actually be 126.875 and 'go into' the next corner post

                        //We try to check next wall.  If it exists, this rightside will be a corner post. If it throws an error
                        //this must be the last wall, so we only remove a receiver's worth from the right side.
                        //try
                        //{
                        //    if (wallDetails[i - 1, 4] == "P")
                        //    {
                        //        if (currentModel == "M400")
                        //        {
                        //            wallRightFiller -= 4.125f;
                        //        }
                        //        else
                        //        {
                        //            wallRightFiller -= 3.125f;
                        //        }
                        //    }
                        //}
                        //catch (Exception ex)
                        //{
                        //    wallRightFiller -= 1f;
                        //}

                        //Now add the filler itself
                        if (wallLeftFiller > 0)
                        {
                            Filler leftFiller = new Filler();
                            leftFiller.Length = wallLeftFiller;
                            //Surround this in a try, because partial gable right walls will not have an element 0.
                            //In that case, the fixedlocation would be the start, 0.
                            try
                            {
                                leftFiller.FixedLocation = linearItems[0].Length;
                                leftFiller.StartHeight = GlobalFunctions.getHeightAtPosition(wallStartHeight, wallEndHeight, leftFiller.FixedLocation, listOfWalls[linearPosition].Length);//position corresponds to this wall's first item's start point
                                leftFiller.EndHeight = GlobalFunctions.getHeightAtPosition(wallStartHeight, wallEndHeight, leftFiller.FixedLocation + leftFiller.Length, listOfWalls[linearPosition].Length);//position corresponds to this wall's first item's length
                                leftFiller.ItemType = "Filler";
                                linearItems.Insert(1, leftFiller); //Inserted as second element, after receiever or post
                            }
                            catch (Exception ex)
                            {
                                leftFiller.FixedLocation = 0;
                                leftFiller.StartHeight = GlobalFunctions.getHeightAtPosition(wallStartHeight, wallEndHeight, leftFiller.FixedLocation, listOfWalls[linearPosition].Length);//position corresponds to this wall's first item's start point
                                leftFiller.EndHeight = GlobalFunctions.getHeightAtPosition(wallStartHeight, wallEndHeight, leftFiller.FixedLocation + leftFiller.Length, listOfWalls[linearPosition].Length);//position corresponds to this wall's first item's length
                                leftFiller.ItemType = "Filler";
                                linearItems.Add(leftFiller); //Inserted as first element
                            }
                        }

                        if (wallRightFiller > 0)
                        {

                            Filler rightFiller = new Filler();
                            rightFiller.Length = wallRightFiller;
                            rightFiller.FixedLocation = listOfWalls[linearPosition].Length - wallRightFiller;
                            rightFiller.StartHeight = GlobalFunctions.getHeightAtPosition(wallStartHeight, wallEndHeight, rightFiller.FixedLocation, listOfWalls[linearPosition].Length);//position corresponds to this wall's first item's start point
                            rightFiller.EndHeight = GlobalFunctions.getHeightAtPosition(wallStartHeight, wallEndHeight, rightFiller.FixedLocation + rightFiller.Length, listOfWalls[linearPosition].Length);//position corresponds to this wall's first item's length
                            rightFiller.ItemType = "Filler";
                            linearItems.Add(rightFiller);
                        }

                        //if last wall, we have right side receiver
                        if (i == strWalls.Length)
                        {
                            wallRightFiller -= 1;//CHANGEME receiver length
                            Receiver aReceiver = new Receiver();
                            aReceiver.StartHeight = aReceiver.EndHeight = GlobalFunctions.getHeightAtPosition(wallStartHeight, wallEndHeight, listOfWalls[listOfWalls.Count - 1].Length - 1, listOfWalls[listOfWalls.Count - 1].Length);
                            aReceiver.Length = 1f;
                            aReceiver.FixedLocation = listOfWalls[listOfWalls.Count - 1].Length - 1;
                            listOfWalls[listOfWalls.Count - 1].LinearItems.Add(aReceiver);
                            cheatCounter++;
                        }

                        double iRailing = -1;

                        if (hidRailing.Value == "Yes")
                        {
                            iRailing = Convert.ToDouble(hidRailingHeight.Value);
                        }

                        listOfWalls[linearPosition].LinearItems = linearItems;

                        listOfWalls[linearPosition].FillSpaceWithWindows(hidWindowType.Value, hidWindowColour.Value, hidWindowFramingColour.Value, numberOfVents, Convert.ToSingle(txtKneewallHeight.Text),
                                                                         ddlKneewallType.SelectedValue.ToString(), ddlTransomType.SelectedValue.ToString(), bool.Parse(hidSunshade.Value), hidValance.Value,
                                                                         hidFabric.Value, hidOpenness.Value, hidChain.Value, hidScreenType.Value, iRailing);//
                        linearPosition++;
                    }
                    #endregion
                }
            }

            ////Add Area
            //char[] areaStringDelimeter = { ',' };
            //string areaString = Request.Form["hidWall" + i + "WindowInfo" + j];
            //string[] areaInfo = areaString.Split(areaStringDelimeter, StringSplitOptions.RemoveEmptyEntries);

            //Mod aMod = new Mod();
            //aMod.ModType = "Window";
            ////Height of the mod will be the minimum height for now, CHANGEME
            //aMod.Height = Math.Min(float.Parse(Request.Form["hidWall" + i + "StartHeight"]), float.Parse(Request.Form["hidWall" + i + "EndHeight"]));
            //aMod.Length = float.Parse(areaInfo[2]);

            ////loop for 'number of windows'
            //for (int k = 0; k <= Int32.Parse(areaInfo[1]); k++)
            //{
            //    List<Object> aModItems = new List<Object>();
            //    Window aWindow = new Window();
            //}

            //Add objects to session
            //Forward to next page

            //Last check, if it's a sunspace gable wall, the two gable walls are not seperate, but one entity, so we combine them
            if (gableType == "Sunspace Gable")
            {
                for (int i = 0; i < listOfWalls.Count; i++)
                {
                    //If this is one of the walls touching the gable peak
                    if (listOfWalls[i].StartHeight == listOfWalls[i+1].EndHeight)
                    {
                        //If start height is smaller, it's the first gable wall
                        if (listOfWalls[i].StartHeight < listOfWalls[i].EndHeight)
                        {

                            //Add the boxheader/receiever
                            BoxHeader aBoxHeader = new BoxHeader();
                            aBoxHeader.IsReceiver = true;
                            aBoxHeader.FixedLocation = listOfWalls[i].Length;
                            aBoxHeader.Length = Constants.BOXHEADER_LENGTH;
                            aBoxHeader.ItemType = "BoxHeader";
                            aBoxHeader.StartHeight = GlobalFunctions.getHeightAtPosition(listOfWalls[i].StartHeight, listOfWalls[i].EndHeight, aBoxHeader.FixedLocation, listOfWalls[i].Length);
                            aBoxHeader.EndHeight = GlobalFunctions.getHeightAtPosition(listOfWalls[i].StartHeight, listOfWalls[i].EndHeight, aBoxHeader.FixedLocation + aBoxHeader.Length, listOfWalls[i].Length);
                            listOfWalls[i].LinearItems.Add(aBoxHeader);
                            listOfWalls[i].Length += 3.25f;
                            listOfWalls[i].GablePeak = listOfWalls[i + 1].StartHeight;

                            //Loop through next wall adding items
                            //Remove corner post of second wall
                            for (int j = 0; j < listOfWalls[i+1].LinearItems.Count; j++)
                            {
                                //Set the fixed location to the current length of the first wall, because we 'add on' to it.
                                listOfWalls[i + 1].LinearItems[j].FixedLocation += listOfWalls[i].Length;
                                //Now that location is changed, add the item to the wall itself
                                listOfWalls[i].LinearItems.Add(listOfWalls[i + 1].LinearItems[j]);
                                //Now that the item is in the wall, the wall is longer, so increase its length
                                listOfWalls[i].Length += listOfWalls[i + 1].LinearItems[j].Length;
                                //Adjust endheight to endheight of second wall
                                listOfWalls[i].EndHeight = listOfWalls[i + 1].EndHeight;
                            }

                            //remove second wall entirely
                            listOfWalls.RemoveAt(i + 1);
                        }

                        //We found it, now break out of loop before we out of range exception
                        break;
                    }
                }
            }

            //Indexes
            //Loop for each wall to set its linear indexes
            int linearCounter=0;

            for (int i = 0; i < listOfWalls.Count; i++)
            {
                listOfWalls[i].FirstItemIndex = linearCounter;
                for (int j = 0; j < listOfWalls[i].LinearItems.Count; j++)
                {
                    //First, lets set modular indexes
                    if (listOfWalls[i].LinearItems[j].ItemType == "Mod")
                    {
                        //Get the mod, then loop for all its items
                        Mod aMod = (Mod)listOfWalls[i].LinearItems[j];
                        for (int k = 0; k < aMod.ModularItems.Count; k++)
                        {
                            aMod.ModularItems[k].ModuleIndex = (k+1);
                        }
                        listOfWalls[i].LinearItems[j] = aMod;
                    }

                    //now set this item's linear index
                    listOfWalls[i].LinearItems[j].LinearIndex = linearCounter;
                    linearCounter++;
                }

                listOfWalls[i].LastItemIndex = linearCounter;
                listOfWalls[i].Name = "Wall " + (i + 1);
            }

            Receiver endReceiver = new Receiver();
            endReceiver.FixedLocation = listOfWalls[listOfWalls.Count - 1].Length - 1f;
            endReceiver.IsTwoPiece = false;
            listOfWalls[listOfWalls.Count - 1].LastItemIndex++;
            endReceiver.ItemType = "Receiver";
            endReceiver.Length = 1f;
            endReceiver.LinearIndex = listOfWalls[listOfWalls.Count - 1].LastItemIndex + 1;
            endReceiver.StartHeight = GlobalFunctions.getHeightAtPosition(listOfWalls[listOfWalls.Count - 1].StartHeight, listOfWalls[listOfWalls.Count - 1].EndHeight, listOfWalls[listOfWalls.Count - 1].Length - 1f, listOfWalls[listOfWalls.Count - 1].Length);
            endReceiver.EndHeight = GlobalFunctions.getHeightAtPosition(listOfWalls[listOfWalls.Count - 1].StartHeight, listOfWalls[listOfWalls.Count - 1].EndHeight, listOfWalls[listOfWalls.Count - 1].Length, listOfWalls[listOfWalls.Count - 1].Length);

            listOfWalls[listOfWalls.Count - 1].LinearItems.Add(endReceiver);

            //linear item sexes
            for (int i = 0; i < listOfWalls.Count; i++)
            {
                for (int j = 0; j < listOfWalls[i].LinearItems.Count; j++)
                {
                    if (listOfWalls[i].LinearItems[j].ItemType == "Receiver")
                    {
                        //Receiver at start of wall is MF, but at end of wall is FM
                        if (j == 0)
                        {
                            listOfWalls[i].LinearItems[j].Sex = "MF";
                        }
                        else
                        {
                            listOfWalls[i].LinearItems[j].Sex = "FM";
                        }
                    }
                    //Corners are always FF to allow the walls to 'go into' them
                    else if (listOfWalls[i].LinearItems[j].ItemType == "Corner")
                    {
                        listOfWalls[i].LinearItems[j].Sex = "FF";
                    }
                    else if (listOfWalls[i].LinearItems[j].ItemType == "BoxHeader" || listOfWalls[i].LinearItems[j].ItemType == "HChannel")
                    {
                        listOfWalls[i].LinearItems[j].Sex = "FF";
                    }
                    //Filler is always MM
                    else if (listOfWalls[i].LinearItems[j].ItemType == "Filler")
                    {
                        listOfWalls[i].LinearItems[j].Sex = "MM";
                    }
                    else if (listOfWalls[i].LinearItems[j].ItemType == "Mod")
                    {
                        //If previous linear item ends with male receiever, this mod must be female
                        if (listOfWalls[i].LinearItems[j - 1].Sex.Substring(1) == "M")
                        {
                            listOfWalls[i].LinearItems[j].Sex = "FF";
                        }
                        else
                        {
                            listOfWalls[i].LinearItems[j].Sex = "MM";
                        }

                        try
                        {
                            //If a filler is after this mod, we must make the mod end in female
                            if (listOfWalls[i].LinearItems[j + 1].ItemType == "Filler")
                            {
                                listOfWalls[i].LinearItems[j].Sex = listOfWalls[i].LinearItems[j].Sex.Substring(0, 1) + "F";
                            }
                            //If a receiver is after this mod, we must make the mod end in male
                            else if (listOfWalls[i].LinearItems[j + 1].ItemType == "Receiver")
                            {
                                listOfWalls[i].LinearItems[j].Sex = listOfWalls[i].LinearItems[j].Sex.Substring(0, 1) + "M";
                            }
                            //If a boxheader is after this mod, we must make the mod end in male
                            else if (listOfWalls[i].LinearItems[j + 1].ItemType == "BoxHeader")
                            {
                                listOfWalls[i].LinearItems[j].Sex = listOfWalls[i].LinearItems[j].Sex.Substring(0, 1) + "M";
                            }
                        }
                        catch (Exception ex)
                        {
                            //if we throw an exception, this is the very last linear item in the wall
                            //If it is the last linear item in the wall, that means that a mod goes directly into a corner post
                            //Adjust mod to end male to go into corner post
                            listOfWalls[i].LinearItems[j].Sex = listOfWalls[i].LinearItems[j].Sex.Substring(0, 1) + "M";
                        }
                    }
                }
            }

            Session.Add("listOfWalls", listOfWalls);
            Session.Add("sunroomProjection", hidRoomProjection.Value);
            Session.Add("sunroomWidth", hidRoomWidth.Value);

            if (Session["newProjectHasRoof"].ToString() == "Yes")
            {
                Response.Redirect("RoofWizard.aspx");
            }
            else if (Session["newProjectPrefabFloor"].ToString() == "Yes")
            {
                Response.Redirect("WizardFloors.aspx");
            }
            else
            {
                Response.Redirect("ProjectPreview.aspx");
            }
        }