public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { string sqlConnectionLocation = "server=10.193.217.38,1433;uid=sa;Password=SanWei2209;database=DB_Family_Library"; const string defaultLoginPath = @"C:\ProgramData\Autodesk\Revit\Addins\2016\SepdBuliding"; const string defaultTempPath = @"C:\RFA_TMP\"; DotNet.Utilities.LogHelper.LogMonitor("table_Log", "族库平台管理功能"); //认证文件确认 if (configFileX() == null) { } else { sqlConnectionLocation = configFileX(); } RevitFamilyManagerFormMB RevitFamilyManagerFormMD = new RevitFamilyManagerFormMB(); Document doc = commandData.Application.ActiveUIDocument.Document; #region 用户权限控制 //初始化数据库连接 SqlCompose SqlCompose = new SqlCompose(sqlConnectionLocation); //获取当前登录用户 string userVerifyFile = null; string getUserName = null; try { userVerifyFile = @"C:\ProgramData\Autodesk\Revit\Addins\2016\NearestUserName.txt"; //获取认证文件中的用户名密码 进入验证环节 StreamReader sr = new StreamReader(userVerifyFile, Encoding.Default); string line = sr.ReadLine(); string[] VerifyInfo = line.Split('/'); string currentUser = VerifyInfo[0]; //开始操作sql string userVerify = "select * from table_User where u_Name = " + "'" + currentUser + "'"; DataSet ds = SqlCompose.ExecuteSqlQuery(userVerify); getUserName = ds.Tables[0].Rows[0]["u_Name"].ToString(); } catch (Exception) { MessageBox.Show("无法认证当前用户,无法使用功能。"); return(Result.Succeeded); } //判断获得用户是否符合要求 若否 则直接结束该方法 if (getUserName == null) { MessageBox.Show("当前用户权限限制,无法使用功能。"); return(Result.Succeeded); } #endregion RevitFamilyManagerFormMD.Show(); return(Result.Succeeded); }
private void tvw_Family_MouseCaptureChanged(object sender, EventArgs e) { TreeNode tn = new TreeNode(); try { foreach (TreeNode x in this.tvw_Family.SelectedNode.Parent.Nodes) { if (x.IsSelected == true) { tn = x; } } } catch (Exception exx) { } if (tn != null && tn.Parent != null) { familyPro = tn.Parent.Name; familyType = tn.Name; lbl_ProText.Text = familyPro; lbl_TypeText.Text = familyType; } #region datagridview显示操作 //sql查询 //sql链接初始化 SqlCompose SqlCompose = new SqlCompose(sqlConnectionLocation); //SqlCompose.Con.Close(); //this.dataGridView1.Rows.Clear(); string readPath = "SELECT * FROM table_p_Family WHERE f_Path LIKE '%" + @"/DB_Family_Library_FTP/" + familyPro + "/" + familyType + "/%'"; DataSet ds = SqlCompose.ExecuteSqlQuery(readPath); DataTable dt = new DataTable(); //MessageBox.Show(ds.Tables[1].ToString()); dt = ds.Tables[0]; dgvDataTable = dt; try { //MessageBox.Show(dt.Rows[1]["f_Path"].ToString()); for (int i = 0; i < dt.Rows.Count; i++) { //int index = this.dataGridView1.Rows.Add(); ////var dd = dt.Rows[i]["f_Path"]; ////MessageBox.Show(dd.ToString()); ////this.dataGridView1.Rows[i].Cells[0].Value = ; //this.dataGridView1.Rows[index].Cells["dgv_FamilyName"].Value = dt.Rows[i]["f_Name"].ToString(); //this.dataGridView1.Rows[index].Cells["dgv_Version"].Value = "1.0"; //this.dataGridView1.Rows[index].Cells["dgv_Date"].Value = dt.Rows[i]["f_UploadDate"].ToString(); //this.dataGridView1.Rows[index].Cells["dgv_Type"].Value = familyType; //this.dataGridView1.Rows[index].Cells["dgv_Hash"].Value = dt.Rows[i]["f_Hash"].ToString(); //this.dataGridView1.Rows[index].Cells["dgv_FamilyLoc"].Value = dt.Rows[i]["f_Path"].ToString(); //this.dataGridView1.Rows[index].Cells["dgv_ParaLoc"].Value = dt.Rows[i]["f_ConfigParaLocation"].ToString(); //this.dataGridView1.Rows[index].Cells["dgv_ValLevel"].Value = dt.Rows[i]["f_ValLevel"].ToString(); //this.dataGridView1.Rows[index].Cells["dgv_Manufacturer"].Value = dt.Rows[i]["f_manufacturer"].ToString(); //this.dataGridView1.Rows[index].Cells["dgv_Source"].Value = dt.Rows[i]["f_Source"].ToString(); } } catch (Exception eex) { MessageBox.Show(eex.ToString()); } #endregion }
private void btn_UploadFamily_Click(object sender, EventArgs e) { LogMonitor.logMonitorUpdate(sqlConnectionLocation, "族库平台:上传,专业:" + lbl_ProText.Text.ToString() + ",类型:" + lbl_TypeText.Text.ToString() + "," + txt_SelectedFamilyName.Text.ToString()); //cmb_allFamilyTypes.Text = lbl_TypeText.Text.ToString(); //if (cmb_allFamilyTypes.Text.ToString() == null) //{ MessageBox.Show("请选择族类型"); } if (lbl_ProText.Text.ToString() == "NA" || lbl_TypeText.Text.ToString() == "NA") { MessageBox.Show("请选择族类型"); } else { try { //sql链接初始化 SqlCompose SqlCompose = new SqlCompose(sqlConnectionLocation); ReviewLocalFamily ReviewLocalFamily = new ReviewLocalFamily(); string familyHash = ReviewLocalFamily.getFileMD5Hash(familyPath.ToString()); //判断库内是否已有相同模型 string checkSameFamilySQL = "SELECT * FROM table_p_Family WHERE f_Hash=" + "'" + familyHash + "'"; //MessageBox.Show(checkSameFamilySQL); DataSet ds = SqlCompose.ExecuteSqlQuery(checkSameFamilySQL); DataTable dt = new DataTable(); dt = ds.Tables[0]; //MessageBox.Show(ds.Tables[0].Rows[0]["f_Name"].ToString()); //MessageBox.Show(dt.Rows.Count.ToString()); DecisionForm DecisionForm = new DecisionForm(dt); DecisionForm.Continue = true; if (dt.Rows.Count.ToString() != "0") { MessageBox.Show("库中已经存在相同模型文件" + dt.Rows.Count.ToString() + "个"); DecisionForm.ShowDialog(); } #region 判断信息完整性 int upLoadKey = 0; string familyValLevel = null; string familyManufacturer = null; string familySource = null; string familyDeviceType = null; string familyName0 = null; if (cmb_ValLevel.Text == null) { MessageBox.Show("请选择电压等级"); } else { familyValLevel = cmb_ValLevel.Text.ToString(); upLoadKey++; } if (txt_Manufacturer.Text == null || txt_Manufacturer.Text == "NA") { MessageBox.Show("请填写厂家"); } else { familyManufacturer = txt_Manufacturer.Text.ToString(); upLoadKey++; } if (cmb_Source.Text == null || cmb_Source.Text == "NA") { MessageBox.Show("请填写需要上传的族来源"); } else { familySource = cmb_Source.Text.ToString(); upLoadKey++; } if (txt_DeviceType == null || txt_DeviceType.Text == "NA") { MessageBox.Show("请填写设备型号"); } else { familyDeviceType = txt_DeviceType.Text.ToString(); upLoadKey++; } if (txt_SelectedFamilyName.Text == null && txt_SelectedFamilyName.Text == "NA") { MessageBox.Show("请填写设备名称"); } else { //familyName0 = txt_SelectedFamilyName.Text.ToString(); upLoadKey++; } if (upLoadKey < 5) { MessageBox.Show("请将信息填写完整,否则无法上传!"); } #endregion #region 判断族名和表名问题 bool isSameName = true; #endregion for (int k = 0; k < familyInfo.Rows.Count; k++) { originFamilyPath = familyInfo.Rows[k]["familyPathss"].ToString(); originFamilyName = Path.GetFileName(originFamilyPath); originParaPath = familyInfo.Rows[k]["familyParass"].ToString(); originParaName = Path.GetFileName(originParaPath); localPicPath = familyInfo.Rows[k]["familyPicss"].ToString(); familyName0 = originFamilyName; if (DecisionForm.Continue == false) { //等待其他操作 } else if (DecisionForm.Continue == true && upLoadKey >= 5 && isSameName == true) { //FTP操作 需确定上传至文件服务器路径 var ftp = new FtpHelper0(serverIP, ftpUserName, ftpPassword); //string tagetFtpDir = @"DB_Family_Library_FTP\" + familyPro + "\\" + familyType + "\\"; string tagetFtpDir = @"DB_Family_Library_FTP\" + familyPro + "\\" + lbl_TypeText.Text.ToString() + "\\"; //MessageBox.Show(familyPro); //MessageBox.Show(familyType); string tagetFtpDirPara = @"DB_Family_Library_FTP\paracast\"; //处理族文件名称路径 modifyFamilyPath = originFamilyPath.Replace(".rfa", "") + "_" + ReviewLocalFamily.getFileMD5Hash(originFamilyPath) + ".rfa"; modifyFamilyName = originFamilyName.Replace(".rfa", "") + "_" + ReviewLocalFamily.getFileMD5Hash(originFamilyPath) + ".rfa"; File.Copy(originFamilyPath, modifyFamilyPath, true); //MessageBox.Show("族路径已处理" + modifyFamilyPath.ToString()); //处理表文件名称路径 //modifyParaPath = originParaPath.Replace(".rfa", "") + "_" + ReviewLocalFamily.getFileMD5Hash(originParaPath) + ".rfa"; //modifyParaName = originParaName.Replace(".rfa", "") + "_" + ReviewLocalFamily.getFileMD5Hash(originParaName) + ".rfa"; modifyParaPath = originParaPath.Replace(".xls", "") + ReviewLocalFamily.getFileMD5Hash(originParaPath) + ".xls"; modifyParaName = originParaName.Replace(".xls", "") + ReviewLocalFamily.getFileMD5Hash(originParaPath) + ".xls"; //modifyParaPath = originParaPath.Replace(originParaName, originFamilyName); File.Copy(originParaPath, modifyParaPath, true); //MessageBox.Show("族路径已处理" + modifyParaPath.ToString()); //MessageBox.Show("族路径已处理\n\n" + modifyFamilyPath.ToString()); //MessageBox.Show("族路径已处理\n\n" + tagetFtpDir.ToString()); ftp.UploadFile(modifyFamilyPath.ToString(), tagetFtpDir); ftp.UploadFile(modifyParaPath.ToString(), tagetFtpDirPara); ftp.UploadFile(localPicPath, @"DB_Family_Library_FTP\pics\"); //sql同步操作 //SqlHelper.Con.Close(); //获取需填写内容 string familyLocation = ftpConnectionLocation + tagetFtpDir.Replace("\\", "/") + modifyFamilyName; string familySize = (ReviewLocalFamily.getFileSize(modifyFamilyPath) / 1024).ToString() + "KB"; string familyUploadDate = DateTime.Now.ToString(); string familyParaLocation = null; string familyConfigParaLocation = ftpConnectionLocation + "DB_Family_Library_FTP/paracast/" + modifyParaName; string familyPicLocation = ftpConnectionLocation + "DB_Family_Library_FTP/pics/" + Path.GetFileName(localPicPath); //MessageBox.Show(familyPicLocation); //开始sql语句操作 bool queryNum = false; //string getFamilySQLSync = "INSERT INTO table_ParameterDefault (pmd_Resource,pmd_Location,pmd_Hash,pmd_Date) VALUES ('Administraror','" + paraLocation + "','" + paraHash + "','" + paraUploadDate + "'" + ");"; string getFamilySQLSync = "INSERT INTO table_p_Family " + "(f_Name,f_Path,f_Value,f_Pro,f_ValLevel,f_Cat,f_Hash,f_UploadDate,f_ParaLocation,f_ConfigParaLocation,f_manufacturer,f_Source,f_DeviceType,f_Pic) " + "VALUES ('" + familyName0 + "','" + familyLocation + "','" + familySize + "','" + familyPro + "','" + familyValLevel + "','" + familyType + "','" + familyHash + "','" + familyUploadDate + "','" + familyParaLocation + "','" + familyConfigParaLocation + "','" + familyManufacturer + "','" + familySource + "','" + familyDeviceType + "','" + familyPicLocation + "')"; //MessageBox.Show(getFamilySQLSync); //SqlHelper.Con.Close(); queryNum = SqlCompose.ExecuteSqlNonQuery(getFamilySQLSync); if (queryNum != false) { MessageBox.Show("上传完成"); } //清除临时哈文件项 File.Delete(modifyFamilyPath); File.Delete(modifyParaPath); //File.Delete(localPicPath); } else { MessageBox.Show("由于信息填写不全,目前无法上传。"); } } } catch (Exception efc) { MessageBox.Show(efc.ToString()); } } }
private void btn_uploadx_Click(object sender, EventArgs e) { count = 0; LogMonitor LogMonitor = new LogMonitor(); DataTable dtUpload = DataUB.dataTempTable; if (lbl_ProText.Text.ToString() == "NA" || lbl_TypeText.Text.ToString() == "NA") { MessageBox.Show("请选择族类型"); } for (int i = 0; i < dtUpload.Rows.Count; i++) { LogMonitor.logMonitorUpdate(sqlConnectionLocation, "族库平台:上传,专业:" + lbl_ProText.Text.ToString() + ",类型:" + lbl_TypeText.Text.ToString() + "," + dtUpload.Rows[i]["familyNamess"].ToString()); //sql链接初始化 SqlCompose SqlCompose = new SqlCompose(sqlConnectionLocation); ReviewLocalFamily ReviewLocalFamily = new ReviewLocalFamily(); string familyHash = ReviewLocalFamily.getFileMD5Hash(familyPath.ToString()); ////判断库内是否已有相同模型 //string checkSameFamilySQL = "SELECT * FROM table_p_Family WHERE f_Hash=" + "'" + familyHash + "'"; //DataSet ds = SqlCompose.ExecuteSqlQuery(checkSameFamilySQL); //DataTable dt = new DataTable(); //dt = ds.Tables[0]; //for (int j = 0; j < dt.Rows.Count; j++) //{ // string exsistFamilyInfo = dt.Rows[i]["f_Name"].ToString() + "; " + dt.Rows[i]["f_UploadDate"].ToString() + "; " + dt.Rows[i]["f_ValLevel"].ToString() + "; " + dt.Rows[i]["f_DeviceType"].ToString() + "; " + dt.Rows[i]["f_manufacturer"].ToString(); // MessageBox.Show(exsistFamilyInfo + "___更新版本"); //} #region 判断信息完整性 int upLoadKey = 0; string familyValLevel = null; string familyManufacturer = null; string familySource = null; string familyDeviceType = null; string familyName0 = null; if (cmb_ValLevel.Text == null) { MessageBox.Show("请选择电压等级"); } else { familyValLevel = cmb_ValLevel.Text.ToString(); upLoadKey++; } if (txt_Manufacturer.Text == null || txt_Manufacturer.Text == "NA") { MessageBox.Show("请填写厂家"); } else { familyManufacturer = txt_Manufacturer.Text.ToString(); upLoadKey++; } if (cmb_Source.Text == null || cmb_Source.Text == "NA") { MessageBox.Show("请填写需要上传的族来源"); } else { familySource = cmb_Source.Text.ToString(); upLoadKey++; } if (txt_DeviceType == null || txt_DeviceType.Text == "NA") { MessageBox.Show("请填写设备型号"); } else { familyDeviceType = txt_DeviceType.Text.ToString(); upLoadKey++; } familyName0 = dtUpload.Rows[i]["familyNamess"].ToString(); if (upLoadKey < 4) { MessageBox.Show("请将信息填写完整,否则无法上传!"); } #endregion if (upLoadKey >= 4) { originFamilyPath = dtUpload.Rows[i]["familyPathss"].ToString(); originFamilyName = dtUpload.Rows[i]["familyNamess"].ToString(); originParaPath = dtUpload.Rows[i]["familyParass"].ToString(); originParaName = Path.GetFileName(dtUpload.Rows[i]["familyParass"].ToString()); localPicPath = dtUpload.Rows[i]["familyPicss"].ToString(); //FTP操作 需确定上传至文件服务器路径 var ftp = new FtpHelper0(serverIP, ftpUserName, ftpPassword); string tagetFtpDir = @"DB_Family_Library_FTP\" + lbl_ProText.Text + "\\" + lbl_TypeText.Text + "\\"; string tagetFtpDirPara = @"DB_Family_Library_FTP\paracast\"; //处理族文件名称路径 modifyFamilyPath = originFamilyPath.Replace(".rfa", "") + "_" + ReviewLocalFamily.getFileMD5Hash(originFamilyPath) + ".rfa"; modifyFamilyName = originFamilyName.Replace(".rfa", "") + "_" + ReviewLocalFamily.getFileMD5Hash(originFamilyPath) + ".rfa"; File.Copy(originFamilyPath, modifyFamilyPath, true); //MessageBox.Show("族路径已处理" + modifyFamilyPath.ToString()); //处理表文件名称路径 modifyParaPath = originParaPath.Replace(".xls", "").Replace(originParaName, originFamilyName) + "_" + ReviewLocalFamily.getFileMD5Hash(originParaPath) + ".xls"; modifyParaName = originParaName.Replace(".xls", "").Replace(originParaName, originFamilyName) + "_" + ReviewLocalFamily.getFileMD5Hash(originParaPath) + ".xls"; File.Copy(originParaPath, modifyParaPath, true); //MessageBox.Show("族路径已处理" + modifyParaPath.ToString()); //MessageBox.Show("族路径已处理\n\n" + modifyFamilyPath.ToString()); //MessageBox.Show("族路径已处理\n\n" + tagetFtpDir.ToString()); ftp.UploadFile(modifyFamilyPath.ToString(), tagetFtpDir); ftp.UploadFile(modifyParaPath.ToString(), tagetFtpDirPara); ftp.UploadFile(localPicPath, @"DB_Family_Library_FTP\pics\"); //sql同步操作 //SqlHelper.Con.Close(); //获取需填写内容 string familyLocation = ftpConnectionLocation + tagetFtpDir.Replace("\\", "/") + modifyFamilyName; string familySize = (ReviewLocalFamily.getFileSize(modifyFamilyPath) / 1024).ToString() + "KB"; string familyUploadDate = DateTime.Now.ToString(); string familyParaLocation = null; string familyConfigParaLocation = ftpConnectionLocation + "DB_Family_Library_FTP/paracast/" + modifyParaName; string familyPicLocation = ftpConnectionLocation + "DB_Family_Library_FTP/pics/" + Path.GetFileName(localPicPath); //MessageBox.Show(familyPicLocation); //开始sql语句操作 bool queryNum = false; //string getFamilySQLSync = "INSERT INTO table_ParameterDefault (pmd_Resource,pmd_Location,pmd_Hash,pmd_Date) VALUES ('Administraror','" + paraLocation + "','" + paraHash + "','" + paraUploadDate + "'" + ");"; string getFamilySQLSync = "INSERT INTO table_p_Family " + "(f_Name,f_Path,f_Value,f_Pro,f_ValLevel,f_Cat,f_Hash,f_UploadDate,f_ParaLocation,f_ConfigParaLocation,f_manufacturer,f_Source,f_DeviceType,f_Pic) " + "VALUES ('" + familyName0 + "','" + familyLocation + "','" + familySize + "','" + familyPro + "','" + familyValLevel + "','" + familyType + "','" + familyHash + "','" + familyUploadDate + "','" + familyParaLocation + "','" + familyConfigParaLocation + "','" + familyManufacturer + "','" + familySource + "','" + familyDeviceType + "','" + familyPicLocation + "')"; //MessageBox.Show(getFamilySQLSync); //SqlHelper.Con.Close(); queryNum = SqlCompose.ExecuteSqlNonQuery(getFamilySQLSync); if (queryNum != false) { count++; } //清除临时文件项 File.Delete(modifyFamilyPath); File.Delete(modifyParaPath); } else { MessageBox.Show("由于信息填写不全,目前无法上传。"); } } MessageBox.Show("完成上传项" + count + "个"); }