예제 #1
0
        public Job JobFromShoporderJoistDetails()
        {
            Job job = new Job();
            List<Joist> allJoists = new List<Joist>();
            List<Girder> allGirders = new List<Girder>();

            OpenFileDialog openBOMFileDialog = new OpenFileDialog();
            openBOMFileDialog.Title = "SELECT JOIST DETAILS";

            //openBOMFileDialog.Filter = "Excel WorkBook|*.xls";
            if (openBOMFileDialog.ShowDialog()==true)
            {
                string fileName = openBOMFileDialog.FileName;
                job.Number = fileName.Split(new string[] { " -", ".xls" }, StringSplitOptions.RemoveEmptyEntries)[1];

                string excelFileName = System.IO.Path.GetTempFileName();
                Byte[] BOMinByteArray = System.IO.File.ReadAllBytes(openBOMFileDialog.FileName);
                System.IO.File.WriteAllBytes(excelFileName, BOMinByteArray);
                Excel.Application oXL;
                Excel._Workbook oWB;
                Excel._Worksheet oSheet;
                Excel.Range oRng;

                oXL = new Excel.Application();
                oXL.Visible = false;

                oWB = oXL.Workbooks.Open(excelFileName);
                oSheet = (Excel._Worksheet)oWB.ActiveSheet;
                oRng = oSheet.UsedRange;

                oRng.get_Range("A1", Missing.Value);
                oRng = oRng.get_End(Excel.XlDirection.xlToRight);
                oRng = oRng.get_End(Excel.XlDirection.xlDown);
                string downJoistMarks = oRng.get_Address(Excel.XlReferenceStyle.xlA1, Type.Missing);
                oRng = oSheet.get_Range("A1", downJoistMarks);
                var joistDetailArray = (object[,])oRng.Value2;

                int joistDetailArrayRows = joistDetailArray.GetLength(0);

                for (int row = 2; row <= joistDetailArrayRows; row++)
                {
                    string joistDescription = (string)joistDetailArray[row, 1];
                    if (joistDescription.Contains("G") == true)
                    {
                        Girder girder = new Girder();
                        girder.Mark = (string)joistDetailArray[row, 1];
                        girder.Quantity = Convert.ToInt32(joistDetailArray[row, 2]);
                        girder.Description = (string)joistDetailArray[row, 3];
                        girder.dblBaseLength = Convert.ToDouble(joistDetailArray[row, 4]);
                        girder.JoistType = (string)joistDetailArray[row, 5];
                        girder.SeatsBDL = Convert.ToDouble(joistDetailArray[row, 6]);
                        girder.SeatsBDR = Convert.ToDouble(joistDetailArray[row, 7]);
                        girder.TCXL = Convert.ToDouble(joistDetailArray[row, 8]);
                        girder.TCXR = Convert.ToDouble(joistDetailArray[row, 9]);
                        girder.BCXL = Convert.ToDouble(joistDetailArray[row, 10]);
                        girder.BCXR = Convert.ToDouble(joistDetailArray[row, 11]);
                        string TCandBC = (string)joistDetailArray[row, 12];
                        girder.TC = TCandBC.Split('/')[0];
                        girder.BC = TCandBC.Split('/')[1];
                        girder.MaterialCost = Convert.ToDouble(joistDetailArray[row, 13]);
                        girder.WeightInLBS = Convert.ToDouble(joistDetailArray[row, 14]);
                        girder.TotalLH = Convert.ToDouble(joistDetailArray[row, 15]);
                        girder.BLDecimal = Convert.ToDouble(joistDetailArray[row, 19]);
                        girder.Time = Convert.ToDouble(joistDetailArray[row, 20]);
                        girder.UseWood = Convert.ToBoolean(joistDetailArray[row, 21]);
                        allGirders.Add(girder);

                    }
                    else
                    {
                        Joist joist = new Joist();
                        joist.Mark = (string)joistDetailArray[row, 1];
                        joist.Quantity = Convert.ToInt32(joistDetailArray[row, 2]);
                        joist.Description = (string)joistDetailArray[row, 3];
                        joist.dblBaseLength = Convert.ToDouble(joistDetailArray[row, 4]);
                        joist.JoistType = (string)joistDetailArray[row, 5];
                        joist.SeatsBDL = Convert.ToDouble(joistDetailArray[row, 6]);
                        joist.SeatsBDR = Convert.ToDouble(joistDetailArray[row, 7]);
                        joist.TCXL = Convert.ToDouble(joistDetailArray[row, 8]);
                        joist.TCXR = Convert.ToDouble(joistDetailArray[row, 9]);
                        joist.BCXL = Convert.ToDouble(joistDetailArray[row, 10]);
                        joist.BCXR = Convert.ToDouble(joistDetailArray[row, 11]);
                        string TCandBC = (string)joistDetailArray[row, 12];
                        joist.TC = TCandBC.Split('/')[0];
                        joist.BC = TCandBC.Split('/')[1];
                        joist.MaterialCost = Convert.ToDouble(joistDetailArray[row, 13]);
                        joist.WeightInLBS = Convert.ToDouble(joistDetailArray[row, 14]);
                        joist.TotalLH = Convert.ToDouble(joistDetailArray[row, 15]);
                        joist.BLDecimal = Convert.ToDouble(joistDetailArray[row, 19]);
                        joist.Time = Convert.ToDouble(joistDetailArray[row, 20]);
                        joist.UseWood = Convert.ToBoolean(joistDetailArray[row, 21]);
                        allJoists.Add(joist);
                    }

                }
                allJoists = allJoists.OrderBy(x => x.StrippedNumber).ToList();
                allGirders = allGirders.OrderBy(x => x.StrippedNumber).ToList();
                job.Joists = allJoists;
                job.Girders = allGirders;
            }
            return job;
        }
예제 #2
0
        public Job JobFromBlueBeamMarkups()
        {
            Job job = new Job();
            List<Joist> allJoists = new List<Joist>();
            List<Girder> allGirders = new List<Girder>();

            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Title = "SELECT BLUE BEAM MARKUP FILE (.XML)";
            openFileDialog.Filter = "Markup File (.xml)|*.xml";
            openFileDialog.Multiselect = true;

            if (openFileDialog.ShowDialog() == true)
            {
                List<Girder> girders = new List<Girder>();
                List<Joist> joists = new List<Joist>();

                foreach (String fileName in openFileDialog.FileNames)
                {

                    //CREATE A COPY OF THE SELECTED FILE AND STORE IT IN A TEMPORARY FILE
                    string markupFileName = System.IO.Path.GetTempFileName();
                    Byte[] markupInByteArray = System.IO.File.ReadAllBytes(fileName);
                    System.IO.File.WriteAllBytes(markupFileName, markupInByteArray);

                    //LOAD THE BLUEBEAM MARKUP FILE INTO AN XElement
                    XElement markUpFile = XElement.Load(markupFileName);

                    //QUERY THE MARKUP XElement TO FIND ALL GIRDER MARKUPS
                    var girderMarkups =
                        from el in markUpFile.Elements("Markup")
                        where (string)el.Element("Subject") == "GIRDER"
                        select el;

                    //QUERY THE MARKUP XElement TO FIN ALL JOIST MARKUPS
                    var joistMarkups =
                        from el in markUpFile.Elements("Markup")
                        where (string)el.Element("Subject") == "JOIST"
                        select el;

                    //EXTRACT ALL GIRDERS AND THEIR VALUES FROM THE QUERRIED GIRDERS

                    foreach (XElement girderMarkup in girderMarkups)
                    {
                        Girder girder = new Girder();

                        girder.Mark = (string)girderMarkup.Element("Label");
                        girder.Description = (string)girderMarkup.Element("JOIST_DESC");
                        girder.Quantity = (int)girderMarkup.Element("Count");

                        string allNotes = (string)girderMarkup.Element("NOTES");
                        girder.Notes = Regex.Split(allNotes, "\n").ToList();

                        string allLoads = (string)girderMarkup.Element("LOADS");
                        girder.Loads = Regex.Split(allLoads, "\n").ToList();

                        girder.strBaseLength = (string)girderMarkup.Element("J-G_Length");
                        girders.Add(girder);
                    }

                    //EXTRACT ALL JOISTS AND THEIR VALUES FROM THE QUERRIED JOISTS

                    foreach (XElement joistMarkup in joistMarkups)
                    {
                        Joist joist = new Joist();

                        joist.Mark = (string)joistMarkup.Element("Label");
                        joist.Description = (string)joistMarkup.Element("JOIST_DESC");

                        string joistQuantity = (string)joistMarkup.Element("Count");
                        int joistQuantity_int = Convert.ToInt32(joistQuantity.Replace(",", ""));
                        joist.Quantity = joistQuantity_int;

                        string allNotes = (string)joistMarkup.Element("NOTES");
                        joist.Notes = Regex.Split(allNotes, "\n").ToList();

                        string allLoads = (string)joistMarkup.Element("LOADS");
                        joist.Loads = Regex.Split(allLoads, "\n").ToList();

                        joist.strBaseLength = (string)joistMarkup.Element("J-G_Length");

                        joists.Add(joist);
                    }
                }

                //CREATE EXCEL COM OBJECT

                //TEST
                //foreach (Joist joist in joists)
                //{
                //    foreach(string str in joist.Loads)
                //    {
                //        MessageBox.Show(str);
                //    }

                //}

                //ADD JOISTS AND GIRDERS TO JOB
                joists = joists.OrderBy(x => x.StrippedNumber).ToList();
                girders = girders.OrderBy(x => x.StrippedNumber).ToList();
                job.Joists = joists;
                job.Girders = girders;

            }
            return job;
        }