/// <summary> /// 找出某工作表在数据库集合中所对应的那一项,如果没有对应项,则返回Nothing /// </summary> /// <param name="DataSheet">要进行匹配的Excel工作表</param> /// <param name="DatasheetCollection">要进行搜索的数据库集合。</param> private DataSheet CorrespondingInCollection(Worksheet DataSheet, List <DataSheet> DatasheetCollection) { DataSheet dtSheet = null; foreach (DataSheet dbSheet in F_DbSheets) { if (ExcelFunction.SheetCompare(dbSheet.WorkSheet, DataSheet)) { dtSheet = dbSheet; break; } } return(dtSheet); }
/// <summary> /// 将项目文件中的工作表添加到组合列表框中 /// </summary> /// <param name="cmbx">进行添加的组合列表框</param> /// <param name="destinationSheet">要添加到组合列表框中的工作表对象</param> /// <remarks></remarks> private void SheetToComboBox(ComboBox cmbx, Worksheet destinationSheet) { LstbxDisplayAndItem lstbxItem = default(LstbxDisplayAndItem); Worksheet sht = default(Worksheet); ComboBox with_1 = cmbx; foreach (LstbxDisplayAndItem tempLoopVar_lstbxItem in with_1.Items) { lstbxItem = tempLoopVar_lstbxItem; if (!lstbxItem.Value.Equals(LstbxDisplayAndItem.NothingInListBox.None)) { //有可能会出现列表中的项目不能转换为工作表对象的情况,比如第一项"" sht = (Worksheet)lstbxItem.Value; if (ExcelFunction.SheetCompare(sht, destinationSheet)) { with_1.SelectedItem = lstbxItem; break; } } } }
//对施工进度表的列表项进行操作 /// <summary> /// 在项目中添加施工进度工作表 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <remarks></remarks> public void BtnAddSheet_Click(object sender, EventArgs e) { switch (this.P_ProjectState) { case Miscellaneous.ProjectState.NewProject: //直接用LstbxDisplayAndItem对象来进行比较 //项目文件中的施工进度工作表的列表框中的所有工作表项 object OldDataSource = this.LstbxSheetsProgressInProject.DataSource; List <LstbxDisplayAndItem> NewDataSource = new List <LstbxDisplayAndItem>(); if (this.LstbxSheetsProgressInProject.DataSource != null) { foreach (LstbxDisplayAndItem i in (IEnumerable)OldDataSource) { NewDataSource.Add(i); } } // foreach (LstbxDisplayAndItem lstItem_Wkbk in this.LstbxSheetsProgressInWkbk.SelectedItems) { //看选择的工作表是否已经包含在项目工作表中 if (!NewDataSource.Contains(lstItem_Wkbk)) { NewDataSource.Add(lstItem_Wkbk); } } this.LstbxSheetsProgressInProject.DataSource = NewDataSource; break; case Miscellaneous.ProjectState.EditProject: //用工作表的路径来进行比较 //工作簿中选择的工作表 Worksheet sht_InWkbk = default(Worksheet); //项目文件中已经存在的工作表 Worksheet sht_InProject = default(Worksheet); // List <LstbxDisplayAndItem> ItemsAddToProject = new List <LstbxDisplayAndItem>(); object OldDataSource_SheetsInProject = this.LstbxSheetsProgressInProject.DataSource; List <LstbxDisplayAndItem> NewDataSource_SheetsInProject = new List <LstbxDisplayAndItem>(); // if (OldDataSource_SheetsInProject == null) { foreach (LstbxDisplayAndItem lstbxItem_Wkbk in this.LstbxSheetsProgressInWkbk.SelectedItems) { NewDataSource_SheetsInProject.Add(lstbxItem_Wkbk); } this.LstbxSheetsProgressInProject.DataSource = NewDataSource_SheetsInProject; } else { foreach (LstbxDisplayAndItem lstbxItem_Wkbk in (IEnumerable)OldDataSource_SheetsInProject) { NewDataSource_SheetsInProject.Add(lstbxItem_Wkbk); } // foreach (LstbxDisplayAndItem lstbxItem_Wkbk in this.LstbxSheetsProgressInWkbk.SelectedItems) { //判断两个工作表是否相等 bool blnSheetsMatched = false; // sht_InWkbk = (Worksheet)lstbxItem_Wkbk.Value; foreach (LstbxDisplayAndItem lstbxItem_Project in (IEnumerable)OldDataSource_SheetsInProject) { sht_InProject = (Worksheet)lstbxItem_Project.Value; if (ExcelFunction.SheetCompare(sht_InProject, sht_InWkbk) == true) { blnSheetsMatched = true; break; } } //lstbxItem_Project //如果两个工作表不匹配,则添加到项目文件中。 if (!blnSheetsMatched) { NewDataSource_SheetsInProject.Add(lstbxItem_Wkbk); } } //lstbxItem_Wkbk this.LstbxSheetsProgressInProject.DataSource = NewDataSource_SheetsInProject; } break; } }