private void btn_get_data_Click(object sender, RoutedEventArgs e) { ItemList.get_Excell_columns = getExcelColumns(); if (ItemList.get_Excell_columns != "") { List <ExcellGridRow> ticketList = new List <ExcellGridRow>(); ExcellGridRow[] ti = new ExcellGridRow[get_grid_header_names.Length]; for (int i = 0; i <= get_grid_header_names.Length - 1; i++) { ti[i] = new ExcellGridRow(); ti[i].ExcellCol = "انتخاب کنید"; // ti[i].MainGridCols = "Item " + (i + 1).ToString(); ti[i].MainGridCols = get_grid_header_names[i]; ticketList.Add(ti[i]); } grd_excel.ItemsSource = ticketList; } }
private void btn_rev_data_Click(object sender, RoutedEventArgs e) { if (range != null) { string str = ""; int num_dataGrid_col = get_grid_header_names.Length; int num_excel_row = range.Rows.Count - 1; int c = 1; // int c = 0; /*string[,]*/ array_f_excel = new string[num_excel_row + 1, num_dataGrid_col]; //array_f_excel = new string[num_excel_row, num_dataGrid_col]; // all valuae must be selected ///////////////////////////////////////////////////// // check all row for has valid selection bool check_all_row = true; for (int cac = 0; cac <= /*range.Rows.Count - 2*/ get_grid_header_names.Length - 1; cac++) { DataGridRow row = this.grd_excel.ItemContainerGenerator.ContainerFromIndex(cac) as DataGridRow; ExcellGridRow v = row.Item as ExcellGridRow; if (v.ExcellCol == "انتخاب کنید") { check_all_row = false; } } //////////////////////////////////////////////////// bool check_all_row_for_dublication = true; for (int card = 0; card <= /*range.Rows.Count - 2*/ get_grid_header_names.Length - 1; card++) { DataGridRow row = this.grd_excel.ItemContainerGenerator.ContainerFromIndex(card) as DataGridRow; ExcellGridRow v = row.Item as ExcellGridRow; for (int ci = 0; ci <= /*range.Rows.Count - 2*/ get_grid_header_names.Length - 1; ci++) { DataGridRow row_i = this.grd_excel.ItemContainerGenerator.ContainerFromIndex(ci) as DataGridRow; ExcellGridRow v_i = row_i.Item as ExcellGridRow; if (ci != card) { if (v.ExcellCol == v_i.ExcellCol) { check_all_row_for_dublication = false; } } } } ///////////////////////////////////////////////////// if (check_all_row == false) { MessageBox.Show("لطفا تمام موارد را انتخاب نمایید"); } if (check_all_row_for_dublication == false) { MessageBox.Show("موارد تکراری قابل قبول نمیباشد"); } /// در صورت وارد شدن مقادیر if (check_all_row && check_all_row_for_dublication) { for (int i = 0; i <= get_grid_header_names.Length - 1; i++) { DataGridRow row = this.grd_excel.ItemContainerGenerator.ContainerFromIndex(i) as DataGridRow; ExcellGridRow v = row.Item as ExcellGridRow; for (int cCnt = 1; cCnt <= range.Columns.Count; cCnt++) { str = (string)(range.Cells[1, cCnt] as Excel1.Range).Value2.ToString(); if (v.ExcellCol == str) { //// get col data and set to array for (int r = 2; r <= range.Rows.Count; r++) { array_f_excel[0, i] = str; if ((range.Cells[r, cCnt] as Excel1.Range).Value2 != null) { array_f_excel[c, i] = (string)(range.Cells[r, cCnt] as Excel1.Range).Value2.ToString(); c++; } else { MessageBox.Show(""); } } c = 1; break; } } } this.Hide(); } // return array } else { MessageBox.Show("فایلی انتخاب نشده است"); } }