Пример #1
0
        private void currlst_SelectedIndexChanged(object sender, EventArgs e)
        {
            txtDGVItem.Visible = false;
            try
            {
                if (currlst.SelectedIndex != -1)
                {
                    txtSaveResult.Text = "";
                    mylastIndex        = currlst.SelectedIndex;//140530_1

                    myEquipName = this.currlst.SelectedItem.ToString();
                    int lastChar = myEquipName.IndexOf("_");
                    myQueryEquipName = myEquipName.Substring(0, lastChar);
                    myGlobalEquipID  = Convert.ToInt64(PNInfo.getDTColumnInfo(PNInfo.GlobalTotalDS.Tables["GlobalAllEquipmentList"], "ID", "ItemName='" + myQueryEquipName + "'"));

                    DataTable myPrmtrDT = new DataTable();
                    if (!blnAddNewEquip)
                    {
                        //140529 TBD 若Global的EquipParameter参数有新增? 但是查询TopoTable无法新增资料?
                        //140529 TBD 如何处理? 删除原Equip 后新增?
                        btnEditPrmtrOK.Enabled = true;
                        getInfoFromDT(PNInfo.TopoToatlDS.Tables["TopoEquipment"], currlst.SelectedIndex);

                        PNInfo.showTablefilterStrInfo(PNInfo.TopoToatlDS.Tables["TopoEquipmentParameter"], dgvEquipPrmtr, "PID=" + myPrmtrPID);

                        //140709_3
                        if (dgvEquipPrmtr.Columns["Item"].Width + dgvEquipPrmtr.Columns["ItemValue"].Width < dgvEquipPrmtr.Size.Width)
                        {
                            dgvEquipPrmtr.Columns["ItemValue"].Width = dgvEquipPrmtr.Size.Width - dgvEquipPrmtr.Columns["Item"].Width;
                        }

                        int myTopoEquipPrmtrCount   = dgvEquipPrmtr.Rows.Count;
                        int myGlobalEquipPrmtrCount = PNInfo.currPrmtrCountExisted(PNInfo.GlobalTotalDS.Tables["GlobalAllEquipmentParamterList"], "PID=" + +myGlobalEquipID);

                        string[,] myValues = new string[myGlobalEquipPrmtrCount, 2];

                        for (int i = 0; i < myGlobalEquipPrmtrCount; i++)
                        {
                            if (i < myTopoEquipPrmtrCount)
                            {
                                myValues[i, 0] = dgvEquipPrmtr.Rows[i].Cells["Item"].Value.ToString();
                                myValues[i, 1] = dgvEquipPrmtr.Rows[i].Cells["ItemValue"].Value.ToString();
                            }
                            else   //140707_0
                            {
                                myValues[i, 0] = "";
                                myValues[i, 1] = "";
                            }
                        }

                        if (myTopoEquipPrmtrCount != myGlobalEquipPrmtrCount)
                        {
                            MessageBox.Show("发现Topo表参数数目:" + myTopoEquipPrmtrCount + " Global参数数目:" + myGlobalEquipPrmtrCount
                                            + ";\n 参数数目不一致,即将新增" + (myGlobalEquipPrmtrCount - myTopoEquipPrmtrCount) + "条仪器参数!!!");
                            PNInfo.showTablefilterStrInfo(PNInfo.GlobalTotalDS.Tables["GlobalAllEquipmentParamterList"], dgvEquipPrmtr, "PID=" + myGlobalEquipID);
                            //若Topo表中存在部分资料则需要覆盖掉此部分Global的默认参数!

                            //140709_3
                            if (dgvEquipPrmtr.Columns["Item"].Width + dgvEquipPrmtr.Columns["ItemValue"].Width < dgvEquipPrmtr.Size.Width)
                            {
                                dgvEquipPrmtr.Columns["ItemValue"].Width = dgvEquipPrmtr.Size.Width - dgvEquipPrmtr.Columns["Item"].Width;
                            }

                            for (int i = 0; i < myGlobalEquipPrmtrCount; i++)
                            {
                                if (myValues[i, 0] == dgvEquipPrmtr.Rows[i].Cells["Item"].Value.ToString())
                                {
                                    dgvEquipPrmtr.Rows[i].Cells["ItemValue"].Value = myValues[i, 1];
                                }
                            }
                        }
                    }
                    else
                    {
                        btnEditPrmtrOK.Enabled = false;

                        PNInfo.showTablefilterStrInfo(PNInfo.GlobalTotalDS.Tables["GlobalAllEquipmentParamterList"], dgvEquipPrmtr, "PID=" + myGlobalEquipID);

                        myPrmtrPID = PNInfo.mylastIDTestEquip + 1;
                    }
                    PNInfo.hideMyIDPID(dgvEquipPrmtr);
                    if (dgvEquipPrmtr.Columns.Contains("ItemDescription")) //140530_1
                    {
                        PNInfo.hideMyColumn(dgvEquipPrmtr, "ItemDescription");
                    }
                    if (dgvEquipPrmtr.Columns.Contains("ItemType")) //140530_1
                    {
                        PNInfo.hideMyColumn(dgvEquipPrmtr, "ItemType");
                    }

                    if (dgvEquipPrmtr.Columns.Contains("Item")) //140530_1
                    {
                        dgvEquipPrmtr.Columns["Item"].HeaderText = "项目";
                    }
                    if (dgvEquipPrmtr.Columns.Contains("ItemValue")) //140530_1
                    {
                        dgvEquipPrmtr.Columns["ItemValue"].HeaderText = "内容";
                    }
                }
                else
                {
                    mylastIndex = -1;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }