protected void btn_Submit_Click(object sender, EventArgs e)
        {
            lbl_ErrorBaySpacing.Visible = false;

            double baySpacing        = 0;
            bool   baySpacingIsValid = double.TryParse(txt_BaySpacing.Text, out baySpacing);


            double width  = Length.From(double.Parse(txt_LandWidth.Text), selectedUnit).Millimeters;
            double length = Length.From(double.Parse(txt_LandLength.Text), selectedUnit).Millimeters;

            baySpacing = Length.From(baySpacing, selectedUnit).Millimeters;
            double eaveHeight = Length.From(double.Parse(txt_EaveHeight.Text), selectedUnit).Millimeters;

            if (!baySpacingIsValid || baySpacing < 5000 || baySpacing > 10000)//ToDo:need Revision
            {
                lbl_ErrorBaySpacing.Visible = true;
                return;
            }


            HndzFrame3D       finalFrame = null;
            HndzFrameTypeEnum type;
            HndzBuilding      bui    = new HndzBuilding(project);
            HndzStorey        storey = new HndzStorey(bui, 0);

            if (Enum.TryParse(Request.QueryString["FrameType"], out type))
            {
                switch (type)
                {
                case HndzFrameTypeEnum.Undefined:
                    throw new NotImplementedException("Undefined Frame");
                    break;

                case HndzFrameTypeEnum.ClearSpan:
                    finalFrame = new HndzFrameSingleBay3D(length, baySpacing, width,
                                                          eaveHeight, 2000, (HndzLocationEnum)ddl_Location.SelectedIndex, (HndzRoofSlopeEnum)ddl_RoofSlope.SelectedIndex
                                                          , (HndzRoofAccessibilityEnum)ddl_RoofAccessability.SelectedIndex, HndzBuildingEnclosingEnum.PartiallyEnclosed,
                                                          HndzImportanceFactorEnum.II, null, null, null, null, null, storey);
                    break;

                case HndzFrameTypeEnum.SingleSlope:
                    finalFrame = new HndzFrameMonoSlope3D(length, baySpacing, width,
                                                          eaveHeight, 2000, (HndzLocationEnum)ddl_Location.SelectedIndex, (HndzRoofSlopeEnum)ddl_RoofSlope.SelectedIndex
                                                          , (HndzRoofAccessibilityEnum)ddl_RoofAccessability.SelectedIndex, HndzBuildingEnclosingEnum.PartiallyEnclosed,
                                                          HndzImportanceFactorEnum.II, null, null, null, null, null, storey);
                    break;

                case HndzFrameTypeEnum.MultiSpan1:
                    finalFrame = new HndzFrameMultiSpan13D(length, baySpacing, width,
                                                           eaveHeight, 2000, (HndzLocationEnum)ddl_Location.SelectedIndex, (HndzRoofSlopeEnum)ddl_RoofSlope.SelectedIndex
                                                           , (HndzRoofAccessibilityEnum)ddl_RoofAccessability.SelectedIndex, HndzBuildingEnclosingEnum.PartiallyEnclosed,
                                                           HndzImportanceFactorEnum.II, null, null, null, null, null, storey);
                    break;

                case HndzFrameTypeEnum.MultiSpan2:
                    finalFrame = new HndzFrameMultiSpan23D(length, baySpacing, width,
                                                           eaveHeight, 2000, (HndzLocationEnum)ddl_Location.SelectedIndex, (HndzRoofSlopeEnum)ddl_RoofSlope.SelectedIndex
                                                           , (HndzRoofAccessibilityEnum)ddl_RoofAccessability.SelectedIndex, HndzBuildingEnclosingEnum.PartiallyEnclosed,
                                                           HndzImportanceFactorEnum.II, null, null, null, null, null, storey);
                    break;

                case HndzFrameTypeEnum.MultiSpan3:
                    finalFrame = new HndzFrameMultiSpan33D(length, baySpacing, width,
                                                           eaveHeight, 2000, (HndzLocationEnum)ddl_Location.SelectedIndex, (HndzRoofSlopeEnum)ddl_RoofSlope.SelectedIndex
                                                           , (HndzRoofAccessibilityEnum)ddl_RoofAccessability.SelectedIndex, HndzBuildingEnclosingEnum.PartiallyEnclosed,
                                                           HndzImportanceFactorEnum.II, null, null, null, null, null, storey);
                    break;

                case HndzFrameTypeEnum.MultiGable:
                    finalFrame = new HndzFrameMultiGable3D(length, baySpacing, width,
                                                           eaveHeight, 2000, (HndzLocationEnum)ddl_Location.SelectedIndex, (HndzRoofSlopeEnum)ddl_RoofSlope.SelectedIndex
                                                           , (HndzRoofAccessibilityEnum)ddl_RoofAccessability.SelectedIndex, HndzBuildingEnclosingEnum.PartiallyEnclosed,
                                                           HndzImportanceFactorEnum.II, null, null, null, null, null, storey);
                    break;

                default:
                    break;
                }

                finalFrame.FramesCount = Convert.ToInt32(txt_FramesCount.Text);
                finalFrame.Type        = type;

                DataContractSerializer xmlser = new DataContractSerializer(finalFrame.GetType());
                string relativePath           = Resources.WebResources.XMLPath + string.Format("Frame No.{0}.xml", finalFrame.GlobalId.ToString());
                string absolutePath           = Server.MapPath(relativePath);
                using (XmlWriter xw = XmlWriter.Create(absolutePath))
                {
                    xmlser.WriteObject(xw, finalFrame);
                }

                HttpCookie cookName = null;
                if (Request.Cookies["Frame"] == null) //mafrod 3mro ma yd5l hna bs e7tyaty
                {
                    cookName = new HttpCookie("Frame");
                }
                else
                {
                    cookName = Response.Cookies["Frame"];
                }
                cookName.Value = absolutePath;
                Response.Cookies.Add(cookName);
            }
            else
            {
                #region IFC Creation
                //HttpCookie cookNameFile = null;
                //if (Request.Cookies["FileName"] == null)
                //{
                //    cookNameFile = new HttpCookie("FileName");
                //}
                //else
                //{
                //    cookNameFile = Response.Cookies["FileName"];
                //    #region Delete old files
                //    //string oldFileName = cookName.Value;
                //    //string oldFilePath = Resources.WebResources.wexbimPath + oldFileName;
                //    //oldFilePath = Server.MapPath(oldFilePath);

                //    //if ((File.Exists(oldFilePath + ".ifc")))
                //    //{
                //    //    File.Delete(oldFilePath + ".ifc");
                //    //}
                //    //if ((File.Exists(oldFilePath + ".wexbim")))
                //    //{
                //    //    File.Delete(oldFilePath + ".wexbim");
                //    //}
                //    #endregion
                //}


                //string fileName = "DesignedFrame" + Guid.NewGuid().ToString();
                //string filePath = Resources.WebResources.wexbimPath + fileName;
                //filePath = Server.MapPath(filePath);
                //try
                //{
                //    BIM.ConvertToIFC.GenerateIFCProject(project, filePath);
                //    cookNameFile.Value = fileName;
                //    Response.Cookies.Add(cookNameFile);
                //    Response.Redirect("/Pages/Designer/DesignWizard.aspx?FrameType=");//ToDo:goto Viewer and final results page isa
                //}
                //catch (Exception ex)
                //{
                //    IsInvalidModel = true;
                //    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Alert", "$('btn_error').click();", true);//wrong
                //}
                #endregion
            }
            Session["FrameObject"] = finalFrame;
            Response.Redirect("/Pages/Designer/DesignWizard.aspx?FrameType=" + finalFrame.Type.ToString());
        }
        private void ConvertIntoFrame()
        {
            lbl_ErrorBaySpacing.Visible = false;

            double baySpacing        = 0;
            bool   baySpacingIsValid = double.TryParse(txt_BaySpacing.Text, out baySpacing);


            double width  = Length.From(double.Parse(txt_LandWidth.Text), selectedUnit).Millimeters;
            double length = Length.From(double.Parse(txt_LandLength.Text), selectedUnit).Millimeters;

            baySpacing = Length.From(baySpacing, selectedUnit).Millimeters;
            double eaveHeight = Length.From(double.Parse(txt_EaveHeight.Text), selectedUnit).Millimeters;

            if (!baySpacingIsValid || baySpacing < 5000 || baySpacing > 10000)//ToDo:need Revision
            {
                lbl_ErrorBaySpacing.Visible = true;
                return;
            }


            HndzFrame3D       finalFrame = null;
            HndzFrameTypeEnum type;
            HndzBuilding      bui    = new HndzBuilding(project);
            HndzStorey        storey = new HndzStorey(bui, 0);

            if (Enum.TryParse(Request.QueryString["FrameType"], out type))
            {
                switch (type)
                {
                case HndzFrameTypeEnum.Undefined:
                    throw new NotImplementedException("Undefined Frame");

                case HndzFrameTypeEnum.ClearSpan:
                    finalFrame = new HndzFrameSingleBay3D(length, baySpacing, width,
                                                          eaveHeight, 2000, (HndzLocationEnum)ddl_Location.SelectedIndex, (HndzRoofSlopeEnum)ddl_RoofSlope.SelectedIndex
                                                          , (HndzRoofAccessibilityEnum)ddl_RoofAccessability.SelectedIndex, HndzBuildingEnclosingEnum.PartiallyEnclosed,
                                                          HndzImportanceFactorEnum.II, null, null, null, null, null, storey);
                    break;

                case HndzFrameTypeEnum.SingleSlope:
                    finalFrame = new HndzFrameMonoSlope3D(length, baySpacing, width,
                                                          eaveHeight, 2000, (HndzLocationEnum)ddl_Location.SelectedIndex, (HndzRoofSlopeEnum)ddl_RoofSlope.SelectedIndex
                                                          , (HndzRoofAccessibilityEnum)ddl_RoofAccessability.SelectedIndex, HndzBuildingEnclosingEnum.PartiallyEnclosed,
                                                          HndzImportanceFactorEnum.II, null, null, null, null, null, storey);
                    break;

                case HndzFrameTypeEnum.MultiSpan1:
                    finalFrame = new HndzFrameMultiSpan13D(length, baySpacing, width,
                                                           eaveHeight, 2000, (HndzLocationEnum)ddl_Location.SelectedIndex, (HndzRoofSlopeEnum)ddl_RoofSlope.SelectedIndex
                                                           , (HndzRoofAccessibilityEnum)ddl_RoofAccessability.SelectedIndex, HndzBuildingEnclosingEnum.PartiallyEnclosed,
                                                           HndzImportanceFactorEnum.II, null, null, null, null, null, storey);
                    break;

                case HndzFrameTypeEnum.MultiSpan2:
                    finalFrame = new HndzFrameMultiSpan23D(length, baySpacing, width,
                                                           eaveHeight, 2000, (HndzLocationEnum)ddl_Location.SelectedIndex, (HndzRoofSlopeEnum)ddl_RoofSlope.SelectedIndex
                                                           , (HndzRoofAccessibilityEnum)ddl_RoofAccessability.SelectedIndex, HndzBuildingEnclosingEnum.PartiallyEnclosed,
                                                           HndzImportanceFactorEnum.II, null, null, null, null, null, storey);
                    break;

                case HndzFrameTypeEnum.MultiSpan3:
                    finalFrame = new HndzFrameMultiSpan33D(length, baySpacing, width,
                                                           eaveHeight, 2000, (HndzLocationEnum)ddl_Location.SelectedIndex, (HndzRoofSlopeEnum)ddl_RoofSlope.SelectedIndex
                                                           , (HndzRoofAccessibilityEnum)ddl_RoofAccessability.SelectedIndex, HndzBuildingEnclosingEnum.PartiallyEnclosed,
                                                           HndzImportanceFactorEnum.II, null, null, null, null, null, storey);
                    break;

                case HndzFrameTypeEnum.MultiGable:
                    finalFrame = new HndzFrameMultiGable3D(length, baySpacing, width,
                                                           eaveHeight, 2000, (HndzLocationEnum)ddl_Location.SelectedIndex, (HndzRoofSlopeEnum)ddl_RoofSlope.SelectedIndex
                                                           , (HndzRoofAccessibilityEnum)ddl_RoofAccessability.SelectedIndex, HndzBuildingEnclosingEnum.PartiallyEnclosed,
                                                           HndzImportanceFactorEnum.II, null, null, null, null, null, storey);
                    break;

                default:
                    break;
                }
                finalFrame.FramesCount = Convert.ToInt32(txt_FramesCount.Text);
                finalFrame.Type        = type;

                HttpCookie cookName = null;
                if (Request.Cookies["FileName"] == null)
                {
                    cookName = new HttpCookie("FileName");
                }
                else
                {
                    cookName = Response.Cookies["FileName"];
                }

                string fileName = Guid.NewGuid().ToString();
                string filePath = Resources.WebResources.wexbimPath + fileName;
                filePath = Server.MapPath(filePath);



                try
                {
                    bool isGenerated = BIM.ConvertToIFC.GenerateIFCProject(finalFrame.BuildingStorey.Building.Project, filePath);
                    cookName.Value = fileName;
                    Response.Cookies.Add(cookName);
                }
                catch (Exception)
                {
                    IsInvalidModel = true;
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Alert", "$('btn_error').click();", true);//wrong
                }
                return;
            }
        }