Пример #1
0
        private void buttonTendonSel_Click(object sender, EventArgs e)
        {
            buttonTendonSel.Text = "添加钢束";
            this.Visible         = false;
            //启动CAD相关对象
            Document doc       = AcadApp.DocumentManager.MdiActiveDocument;
            Database db        = doc.Database;
            Editor   ed        = doc.Editor;
            bool     isTdInTbl = false;//初始化判断所选钢束是否已在表中的布尔值

            //1.1管道偏差系数
            if (!double.TryParse(textBoxKii.Text, out kii))
            {
                MessageBox.Show("管道偏差系数输入有误!");
                this.Visible = true;
                return;
            }
            //1.2摩阻系数
            if (!double.TryParse(textBoxMiu.Text, out miu))
            {
                MessageBox.Show("摩阻系数输入有误!");
                this.Visible = true;
                return;
            }
            //1.3钢束弹模
            double Ep = 1.95e5;

            if (!double.TryParse(textBoxEp.Text, out Ep))
            {
                MessageBox.Show("钢束弹模输入有误!");
                this.Visible = true;
                return;
            }
            //1.4张拉控制应力
            if (!double.TryParse(textBoxCtrlStress.Text, out ctrlStress))
            {
                MessageBox.Show("张拉控制应力输入有误!");
                this.Visible = true;
                return;
            }
            //1.5工作长度
            if (!double.TryParse(textBoxWorkLen.Text, out workLen))
            {
                MessageBox.Show("工作长度输入有误!");
                this.Visible = true;
                return;
            }
            using (Transaction trans = db.TransactionManager.StartTransaction())//开始事务处理
            {
                #region 1.选择钢束
                List <Polyline> tds = new List <Polyline>(); //初始化存储钢束的List
                for (;;)                                     //无限循环
                {
                    tds = new List <Polyline>();             //清空tds
                    PromptSelectionOptions tdsOpt = new PromptSelectionOptions();
                    tdsOpt.MessageForAdding = "\n选择钢束线,需为无折角的多段线";
                    PromptSelectionResult tdsRes = ed.GetSelection(tdsOpt);
                    if (tdsRes.Status == PromptStatus.Cancel)
                    {
                        this.Visible = true;//重新显示对话框
                        return;
                    }
                    bool isPolyline = true;//设置是否选择集中均为多段线的布尔参数
                    if (tdsRes.Status == PromptStatus.OK)
                    {
                        SelectionSet sSet = tdsRes.Value;
                        foreach (ObjectId tdId in sSet.GetObjectIds())
                        {
                            Polyline td = tdId.GetObject(OpenMode.ForRead) as Polyline; //获取钢束线
                            if (td == null)                                             //选择集中有非多段线
                            {
                                AcadApp.ShowAlertDialog("选择集中含有非多段线,重新选择");
                                isPolyline = false;
                                break;//退出循环
                            }
                            tds.Add(td);
                        }
                        if (isPolyline == false)
                        {
                            continue; //如果存在非多段线,则重新提示选择
                        }
                        break;        //结束选择
                    }
                }
                #endregion
                #region 2.扩展字典的读取或添加,并将信息列入表格
                for (int i = 0; i < tds.Count; i++)
                {
                    if (idsInTbl.Contains(tds[i].ObjectId))
                    {
                        isTdInTbl = true;
                        break;                                               //钢束已在表中,不继续添加,退出循环
                    }
                    idsInTbl.Add(tds[i].ObjectId);                           //将新的钢束加入列表中便于后续判断
                    int    index = (int)(XrecordManipulate.ReadXRecordToRow(this, tds[i], kii, miu, Ep, ctrlStress, workLen));
                    string tdKey = "TendonHdl_" + tds[i].Handle.ToString();  //钢束键值
                    dataGridViewTendons.Rows[index].Cells[10].Value = tdKey; //键值加入最后一列
                    tdIdsInTable.Add(tdKey, tds[i].ObjectId);                //加入表中钢束字典列表便于后续操作
                }
                #endregion
                trans.Commit();  //执行事务处理
            }
            this.Visible = true; //重新显示对话框
            if (isTdInTbl)
            {
                MessageBox.Show("\n选择集中有表中已有钢束,已自动剔除!");
            }
        }