/// <summary> /// Create an Excel file, and write it to a file for Leverantor data. /// </summary> //KD Changes private void CreateExcelforLeverantor() { try { //KD Change DataSet ds = GetSupplierForBonusSetAmount(); string sSupplier = string.Empty; DataSet dsSupplier = new DataSet(); string sColumnName = string.Empty; for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++) { //if (sSupplier != ds.Tables[0].Rows[i]["SupplierName"].ToString()) //KD Change if (!sSupplier.Equals(ds.Tables[0].Rows[i]["SupplierName"].ToString(), StringComparison.InvariantCultureIgnoreCase)) { sColumnName = ds.Tables[0].Rows[i]["SupplierName"].ToString(); dsSupplier.Tables.Add(sColumnName); dsSupplier.Tables[sColumnName].Columns.Add(new DataColumn(ds.Tables[0].Columns[0].ColumnName, ds.Tables[0].Columns[0].DataType)); //dsSupplier.Tables[sColumnName].Columns.Add(new DataColumn(ds.Tables[0].Columns[1].ColumnName, ds.Tables[0].Columns[1].DataType)); dsSupplier.Tables[sColumnName].Columns.Add(new DataColumn(ds.Tables[0].Columns[2].ColumnName, ds.Tables[0].Columns[2].DataType)); dsSupplier.Tables[sColumnName].Columns.Add(new DataColumn(ds.Tables[0].Columns[3].ColumnName, ds.Tables[0].Columns[3].DataType)); dsSupplier.Tables[sColumnName].Columns.Add(new DataColumn(ds.Tables[0].Columns[4].ColumnName, ds.Tables[0].Columns[4].DataType)); dsSupplier.Tables[sColumnName].Columns.Add(new DataColumn(ds.Tables[0].Columns[5].ColumnName, ds.Tables[0].Columns[5].DataType)); dsSupplier.Tables[sColumnName].Columns.Add(new DataColumn(ds.Tables[0].Columns[6].ColumnName, ds.Tables[0].Columns[6].DataType)); } DataRow newRow = dsSupplier.Tables[sColumnName].NewRow(); newRow[0] = ds.Tables[0].Rows[i][0]; //newRow[1] = ds.Tables[0].Rows[i]["SupplierName"].ToString(); newRow[1] = ds.Tables[0].Rows[i][2]; newRow[2] = ds.Tables[0].Rows[i][3]; newRow[3] = ds.Tables[0].Rows[i][4]; newRow[4] = ds.Tables[0].Rows[i][5]; newRow[5] = ds.Tables[0].Rows[i][6]; dsSupplier.Tables[ds.Tables[0].Rows[i]["SupplierName"].ToString()].Rows.Add(newRow); sSupplier = ds.Tables[0].Rows[i]["SupplierName"].ToString(); } string documentPath = ConfigurationManager.AppSettings["ReportDir"]; string filename = "StatisticsBonusgroupsBySupplier" + ".xlsx"; CreateExcelFile2.CreateExcelDocument(dsSupplier, documentPath + filename); MessageBox.Show("Excel created successfully."); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Create an Excel file, and write it to a file for Medlemsnamn data. /// </summary> //KD Changes private void CreateExcelforMedlemsnamn() { try { //KD Change DataSet ds = GetMemberForBonusSetAmount(); //Task 202: Select all data for all year #region Select all data for all year For Task 202 try { while (false) { bool isFileGenerated = false; string filenameCSV = "StatisticsBonusgroupsByMember_All"; string fileSavedPath = WriteCSVFileSourcedFromDB(filenameCSV, ds, out isFileGenerated); if (!string.IsNullOrEmpty(fileSavedPath)) { MessageBox.Show("CSV Generated Successfully"); } } } catch (Exception ex) { MessageBox.Show("Error for CSV: " + ex); } #endregion #region the existing running code hide for Task 202: Select all data for all year //while (false) //Task 202: Select all data for all year, extra while loop added { string sSupplier = string.Empty; DataSet dsSupplier = new DataSet(); string sColumnName = string.Empty; for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++) { //if (sSupplier != ds.Tables[0].Rows[i]["MemberName"].ToString()) if (!sSupplier.Equals(ds.Tables[0].Rows[i]["MemberName"].ToString(), StringComparison.InvariantCultureIgnoreCase)) { sColumnName = ds.Tables[0].Rows[i]["MemberName"].ToString(); dsSupplier.Tables.Add(sColumnName); dsSupplier.Tables[sColumnName].Columns.Add(new DataColumn("Leverantörsnummer", ds.Tables[0].Columns[0].DataType)); //dsSupplier.Tables[sColumnName].Columns.Add(new DataColumn(ds.Tables[0].Columns[1].ColumnName, ds.Tables[0].Columns[1].DataType)); dsSupplier.Tables[sColumnName].Columns.Add(new DataColumn("Leverantörsnamn", ds.Tables[0].Columns[2].DataType)); dsSupplier.Tables[sColumnName].Columns.Add(new DataColumn("Startdatum", ds.Tables[0].Columns[3].DataType)); dsSupplier.Tables[sColumnName].Columns.Add(new DataColumn("Slutdatum", ds.Tables[0].Columns[4].DataType)); dsSupplier.Tables[sColumnName].Columns.Add(new DataColumn("Bonusgrupp namn", ds.Tables[0].Columns[5].DataType)); dsSupplier.Tables[sColumnName].Columns.Add(new DataColumn("Bonusgrupp belopp", ds.Tables[0].Columns[6].DataType)); } DataRow newRow = dsSupplier.Tables[sColumnName].NewRow(); newRow[0] = ds.Tables[0].Rows[i][0]; //newRow[1] = ds.Tables[0].Rows[i]["MemberName"]; newRow[1] = ds.Tables[0].Rows[i][2]; newRow[2] = ds.Tables[0].Rows[i][3]; newRow[3] = ds.Tables[0].Rows[i][4]; newRow[4] = ds.Tables[0].Rows[i][5]; newRow[5] = ds.Tables[0].Rows[i][6]; dsSupplier.Tables[ds.Tables[0].Rows[i]["MemberName"].ToString()].Rows.Add(newRow); sSupplier = ds.Tables[0].Rows[i]["MemberName"].ToString(); } string documentPath = ConfigurationManager.AppSettings["ReportDir"]; //Task 202: Select all data for all year string filename = "StatisticsBonusgroupsByMember" + ".xlsx"; //string filename = "StatisticsBonusgroupsByMember" + ".csv"; bool status = CreateExcelFile2.CreateExcelDocument(dsSupplier, documentPath + filename); MessageBox.Show("Excel created successfully.\n" + status); } #endregion } catch (Exception ex) { MessageBox.Show(ex.Message); } }