private void tvAiList_AfterSelect(object sender, TreeViewEventArgs e) { if (_LastSelectNode == tvAiList.SelectedNode) { return; } if (isUpdate) { //if (MessageBox.Show("当前配置尚未保存,确定要切换到其他库吗?", "操作提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { // isUpdate = false; //} //else // tvAiList.SelectedNode = _LastSelectNode; MessageBox.Show("请先保存当前配置!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); tvAiList.SelectedNode = _LastSelectNode; } dgvBindList.Rows.Clear(); if (tvAiList.SelectedNode == null || tvAiList.SelectedNode.Tag == null) { return; } if (tvAiList.SelectedNode.Tag is TbccCarPrjType) { TbccCarPrjType carItem = tvAiList.SelectedNode.Tag as TbccCarPrjType; AiInfoModel aim1 = GetBindValue(carItem.CarProjectId, 0, 0, 1); AiInfoModel aim2 = GetBindValue(carItem.CarProjectId, 0, 0, 2); AiInfoModel aim3 = GetBindValue(carItem.CarProjectId, 0, 0, 3); AiInfoModel aim4 = GetBindValue(carItem.CarProjectId, 0, 0, 4); AiInfoModel aim5 = GetBindValue(carItem.CarProjectId, 0, 0, 5); AiInfoModel aim6 = GetBindValue(carItem.CarProjectId, 0, 0, 6); dgvBindList.Rows[dgvBindList.Rows.Add(tvAiList.SelectedNode.Text, "AI1", aim1.aiNumber)].Tag = aim1; dgvBindList.Rows[dgvBindList.Rows.Add(tvAiList.SelectedNode.Text, "AI2", aim2.aiNumber)].Tag = aim2; dgvBindList.Rows[dgvBindList.Rows.Add(tvAiList.SelectedNode.Text, "AI3", aim3.aiNumber)].Tag = aim3; dgvBindList.Rows[dgvBindList.Rows.Add(tvAiList.SelectedNode.Text, "AI4", aim4.aiNumber)].Tag = aim4; dgvBindList.Rows[dgvBindList.Rows.Add(tvAiList.SelectedNode.Text, "经度", aim5.aiNumber)].Tag = aim5; dgvBindList.Rows[dgvBindList.Rows.Add(tvAiList.SelectedNode.Text, "纬度", aim6.aiNumber)].Tag = aim6; } else { List <TbccRefAiInfo> aiList = tvAiList.SelectedNode.Tag as List <TbccRefAiInfo>; foreach (var item in aiList) { AiInfoModel aim = GetBindValue(item.ProjectID, item.NetId, item.RefId, item.PortNo); int rowIndex = dgvBindList.Rows.Add(tvAiList.SelectedNode.Text, item.PortName, aim.aiNumber); dgvBindList.Rows[rowIndex].Tag = aim; } } _LastSelectNode = tvAiList.SelectedNode; }
private void btnSave_Click(object sender, EventArgs e) { try { this.Enabled = false; if (isUpdate) { string projectId = string.Empty; int netId = 0; int refId = 0; if (tvAiList.SelectedNode.Tag is TbccCarPrjType) { TbccCarPrjType carItem = tvAiList.SelectedNode.Tag as TbccCarPrjType; projectId = carItem.CarProjectId; } else { List <TbccRefAiInfo> aiList = tvAiList.SelectedNode.Tag as List <TbccRefAiInfo>; if (aiList.Count == 0) { isUpdate = false; return; } projectId = aiList[0].ProjectID; netId = aiList[0].NetId; refId = aiList[0].RefId; } AiInfoServer.InsertAiRelation(FrmMain._relationList, projectId, netId, refId); MessageBox.Show("保存成功!"); isUpdate = false; tvAiList_AfterSelect(sender, null); } } catch (Exception ex) { MessageBox.Show(ex.Message, "保存失败"); } finally { this.Enabled = true; } }