Ejemplo n.º 1
0
        //lbl_ProText.Text = familyPro;
        //    lbl_TypeText.Text = familyType;
        private void btn_openConfigParaPath_Click(object sender, EventArgs e)
        {
            try
            {
                string openFileDialogLastTimeTextfilePath = @"C:\ProgramData\Autodesk\Revit\Addins\2016\openConfigParaPathLastTime.txt";
                string lastTimeOpenLocation = @"c:\";
                if (File.Exists(openFileDialogLastTimeTextfilePath))
                {
                    StreamReader sr   = new StreamReader(openFileDialogLastTimeTextfilePath, Encoding.Default);
                    string       line = sr.ReadLine();
                    lastTimeOpenLocation = line;
                    sr.Close();
                }
                else
                {
                    FileStream   fs = new FileStream(openFileDialogLastTimeTextfilePath, FileMode.Create);
                    StreamWriter sw = new StreamWriter(fs);
                    sw.Write(lastTimeOpenLocation);
                    sw.Close();
                    fs.Close();
                }

                //ReviewLocalFamily ReviewLocalFamily = new ReviewLocalFamily();
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.InitialDirectory = lastTimeOpenLocation;
                openFileDialog.Filter           = "excel文件|*.xls|所有文件|*.*";
                openFileDialog.RestoreDirectory = true;

                if (openFileDialog.ShowDialog() == DialogResult.OK && openFamilyName != null)
                {
                    string pPath = openFileDialog.FileName.ToString();//获取用户选择的文件路径

                    //MessageBox.Show(Path);
                    string pName = pPath.Substring(pPath.LastIndexOf("\\") + 1);//获取用户选择的文件名称

                    originParaPath = pPath;
                    originParaName = pName;

                    //configParaPath = pPath.Replace(pName, openFamilyName);
                    //configParaPath = pPath.Replace(".xls", "").Replace(pName, openFamilyName) + "_" + ReviewLocalFamily.getFileMD5Hash(pPath) + ".xls";
                    //configParaName = pName.Replace(".xls", "").Replace(pName, openFamilyName) + "_" + ReviewLocalFamily.getFileMD5Hash(pPath) + ".xls";
                    //File.Copy(pPath, configParaPath, true);

                    txt_openConfigParaPath.Text = pPath;
                    openConfigParaName          = pName;
                }

                FileStream   fs2 = new FileStream(openFileDialogLastTimeTextfilePath, FileMode.Create);
                StreamWriter sw2 = new StreamWriter(fs2);
                sw2.Write(originParaPath);
                sw2.Close();
                fs2.Close();
            }
            catch (Exception ette)
            {
                MessageBox.Show("请先选择族\n\n" + ette.ToString());
            }

            //开始读取xls文件内的关键信息//显示所选表内容

            ExcelHelper ExcelHelper   = new ExcelHelper();
            DataTable   configKeyPara = ExcelHelper.Reading_Excel_Information(originParaPath);

            this.dataGridView2.Rows.Clear();
            try
            {
                #region  提取 XLS 与 Family 内部信息
                for (int l = 0; l < configKeyPara.Rows.Count; l++)
                {
                    if (configKeyPara.Rows[l]["paraname"].ToString().Contains("厂家"))
                    {
                        txt_Manufacturer.Text = configKeyPara.Rows[l]["paravalue"].ToString();
                        break;
                    }
                    else
                    {
                        txt_Manufacturer.Text = "NA";
                    }
                }
                for (int l = 0; l < configKeyPara.Rows.Count; l++)
                {
                    if (configKeyPara.Rows[l]["paraname"].ToString().Contains("型号"))
                    {
                        txt_DeviceType.Text = configKeyPara.Rows[l]["paravalue"].ToString();
                        break;
                    }
                    else
                    {
                        txt_DeviceType.Text = "NA";
                    }
                }
                for (int l = 0; l < configKeyPara.Rows.Count; l++)
                {
                    if (configKeyPara.Rows[l]["paraname"].ToString().Contains("名") && configKeyPara.Rows[l]["paravalue"].ToString() != null)
                    {
                        txt_SelectedFamilyName.Text = configKeyPara.Rows[l]["paravalue"].ToString();
                        break;
                    }
                    else
                    {
                        txt_SelectedFamilyName.Text = openFamilyName.Replace(".rfa", "");;
                    }
                }
                for (int l = 0; l < configKeyPara.Rows.Count; l++)
                {
                    if (configKeyPara.Rows[l]["paraname"].ToString().Contains("电压等级"))
                    {
                        cmb_ValLevel.Text = configKeyPara.Rows[l]["paravalue"].ToString();
                        break;
                    }
                    else
                    {
                        cmb_ValLevel.Text = "其他";
                    }
                }
                for (int l = 0; l < configKeyPara.Rows.Count; l++)
                {
                    if (configKeyPara.Rows[l]["paraname"].ToString().Contains("来源"))
                    {
                        cmb_Source.Text = configKeyPara.Rows[l]["paravalue"].ToString();
                        break;
                    }
                    else
                    {
                        cmb_Source.Text = "NA";
                    }
                }
                #endregion

                for (int i = 0; i < configKeyPara.Rows.Count; i++)
                {
                    int index = this.dataGridView2.Rows.Add();
                    this.dataGridView2.Rows[index].Cells[0].Value = configKeyPara.Rows[i]["paraname"].ToString();
                    this.dataGridView2.Rows[index].Cells[1].Value = configKeyPara.Rows[i]["paravalue"].ToString();
                    this.dataGridView2.Rows[index].Cells[2].Value = configKeyPara.Rows[i]["paratag"].ToString();
                }
            }
            catch (Exception excs)
            {
                MessageBox.Show(excs.ToString());
            }
        }