예제 #1
0
        public static void StatisticsModel123_Steel4(BeamData beam, AcadDB.BlockReference blk_ref)
        {
            AcadDB.Database db = AcadApp.DocumentManager.MdiActiveDocument.Database;
            using (AcadDB.Transaction trans = db.TransactionManager.StartTransaction())
            {
                AcadDB.AttributeCollection atts = blk_ref.AttributeCollection;
                foreach (AcadDB.ObjectId att in atts)
                {
                    AcadDB.AttributeReference att_ref = trans.GetObject(att, AcadDB.OpenMode.ForWrite) as AcadDB.AttributeReference;
                    if (null == att_ref)
                    {
                        continue;
                    }

                    if (ATT_SH == att_ref.Tag)
                    {
                        att_ref.TextString = "4";
                    }
                    if (ATT_DK == att_ref.Tag)
                    {
                        att_ref.TextString = beam.dau_goi_data.first_layer_diameter.ToString();
                    }
                    if (ATT_DAI == att_ref.Tag)
                    {
                        att_ref.TextString = (beam.Length - 2 * Beam.cover).ToString();
                    }
                    if (ATT_L2 == att_ref.Tag)
                    {
                        att_ref.TextString = "2000";
                    }
                    if (ATT_L1 == att_ref.Tag)
                    {
                        att_ref.TextString = (beam.Height - 2 * Beam.cover).ToString();
                    }
                    if (ATT_SL1 == att_ref.Tag)
                    {
                        att_ref.TextString = (beam.dau_goi_data.number_steel_first_layer).ToString();
                    }
                    if (ATT_SLA == att_ref.Tag)
                    {
                        att_ref.TextString = (beam.dau_goi_data.number_steel_first_layer).ToString();
                    }
                    if (ATT_DT == att_ref.Tag)
                    {
                        double total_len = beam.dau_goi_data.number_steel_first_layer * (beam.Length - 2 * Beam.cover);
                        total_len         /= 1000.0;
                        att_ref.TextString = (total_len).ToString();
                    }
                    if (ATT_TL == att_ref.Tag)
                    {
                        att_ref.TextString = "...";
                    }
                }

                trans.Commit();
            }
        }
예제 #2
0
        public static List <BeamData> DoReadExcel(string path)
        {
            const int offset_row = 5;

            Excel.Application excel_app = null;
            Excel.Workbooks   workbooks = null;
            Excel.Workbook    workbook  = null;
            Excel.Worksheet   sheet     = null;
            Excel.Range       range     = null;
            List <BeamData>   beam_data = new List <BeamData>();

            try
            {
                excel_app = new Excel.Application();

                excel_app.DisplayAlerts = false; //Don't want Excel to display error messageboxes

                workbooks = excel_app.Workbooks;
                workbook  = workbooks.Add(path);                      //This opens the file

                sheet = (Excel.Worksheet)workbook.Sheets.get_Item(1); //Get the first sheet in the file

                int last_row = sheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell, Type.Missing).Row;
                int last_col = sheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell, Type.Missing).Column;

                range = sheet.Range[sheet.Cells[1, 1], sheet.Cells[last_row, last_col]];

                for (int i = offset_row; i < last_row;)
                {
                    BeamData data = new BeamData();

                    try
                    {
                        data.Width  = GetIntValue(range, i, WIDTH_COL);
                        data.Height = GetIntValue(range, i, HEIGHT_COL);
                        data.Length = GetIntValue(range, i, LENGTH_COL);
                    }
                    catch (Exception ex)
                    {
                        i++;
                        continue;
                    }

                    {
                        data.giua_data.number_steel_first_layer  = GetIntValue(range, i, NUM_STEEL_FIRST_LAYER);
                        data.giua_data.first_layer_diameter      = GetIntValue(range, i, DIA_STEEL_FIRST_LAYER);
                        data.giua_data.number_steel_second_layer = GetIntValue(range, i, NUM_STEEL_SECOND_LAYER);
                        data.giua_data.second_layer_diameter     = GetIntValue(range, i, DIA_STEEL_SECOND_LAYER);

                        string thep_dai_info = CellValue(range, i, THEP_DAI_INFO);
                        if (thep_dai_info[0] != '2' && thep_dai_info[0] != '3' && thep_dai_info[0] != '4')
                        {
                            i += 2;
                            continue;
                        }

                        data.giua_data.type_beam    = ConvertInt(thep_dai_info.Substring(0, 1));
                        data.giua_data.dai_diameter = ConvertInt(thep_dai_info.Substring(2, 2));
                        data.giua_data.spacing      = ConvertInt(thep_dai_info.Substring(5));

                        if (IsValidCell(range, i, THEP_DAI_2_INFO))
                        {
                            string thep_dai_info2 = CellValue(range, i, THEP_DAI_2_INFO);
                            data.giua_data.dai_diameter2 = ConvertInt(thep_dai_info2.Substring(0, 1));
                            data.giua_data.spacing2      = ConvertInt(thep_dai_info2.Substring(2));
                        }
                    }

                    i++;

                    {
                        data.dau_goi_data.number_steel_first_layer  = GetIntValue(range, i, NUM_STEEL_FIRST_LAYER);
                        data.dau_goi_data.first_layer_diameter      = GetIntValue(range, i, DIA_STEEL_FIRST_LAYER);
                        data.dau_goi_data.number_steel_second_layer = GetIntValue(range, i, NUM_STEEL_SECOND_LAYER);
                        data.dau_goi_data.second_layer_diameter     = GetIntValue(range, i, DIA_STEEL_SECOND_LAYER);

                        string thep_dai_info = CellValue(range, i, THEP_DAI_INFO);
                        if (thep_dai_info[0] != '2' && thep_dai_info[0] != '3' && thep_dai_info[0] != '4')
                        {
                            i++;
                            continue;
                        }

                        data.dau_goi_data.type_beam    = ConvertInt(thep_dai_info.Substring(0, 1));
                        data.dau_goi_data.dai_diameter = ConvertInt(thep_dai_info.Substring(2, 2));
                        data.dau_goi_data.spacing      = ConvertInt(thep_dai_info.Substring(5));

                        if (IsValidCell(range, i, THEP_DAI_2_INFO))
                        {
                            string thep_dai_info2 = CellValue(range, i, THEP_DAI_2_INFO);
                            data.dau_goi_data.dai_diameter2 = ConvertInt(thep_dai_info2.Substring(0, 1));
                            data.dau_goi_data.spacing2      = ConvertInt(thep_dai_info2.Substring(2));
                        }
                    }

                    i++;

                    beam_data.Add(data);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (null != workbook)
                {
                    workbook.Close(0);
                }
                if (null != excel_app)
                {
                    excel_app.Quit();
                }

                Marshal.ReleaseComObject(range);
                Marshal.ReleaseComObject(sheet);
                Marshal.ReleaseComObject(workbook);
                Marshal.ReleaseComObject(workbooks);
                Marshal.ReleaseComObject(excel_app);
            }


            return(beam_data);
        }