//method reading .CSV source using OleDB (NOT IN USE!) private void prepareDefaultDataOleDB() { if (!stoper) { try {Response.Write(@"<script>alert('1 Please, contact administrator (mailto: [email protected]), providing following information: \n');</script>"); string name = ""; double pdi = 0, idv = 0, mas = 0, uai = 0, lto = 0, ivr = 0; string path = HttpContext.Current.Server.MapPath(@"~/docs/Aldunin_dimensions_clasters.xls"); string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + path + ";" + "Extended Properties=Excel 8.0;"; OleDbConnection conn = new OleDbConnection(strConn); conn.Open(); Response.Write(@"<script>alert('2 Please, contact administrator (mailto: [email protected]), providing following information: \n');</script>"); Response.Write(@"<script>alert('2 " + path + " Please, contact administrator (mailto: [email protected]), providing following information: \n');</script>"); Response.Write(@"<script>alert('3 Please, contact administrator (mailto: [email protected]), providing following information: \n');</script>"); string strExcel = ""; OleDbDataAdapter myCommand = null; strExcel = "select * from [6 dimensions$]"; myCommand = new OleDbDataAdapter(strExcel, strConn); ds = new DataSet(); Response.Write(@"<script>alert('2 " + path + " Please, contact administrator (mailto: [email protected]), providing following information: \n');</script>"); try { myCommand.Fill(ds, "table"); } catch (Exception ex) { Response.Write(@"<script>alert('TEST! Failed to get data about counties from Excel. Please, contact administrator (mailto: [email protected]), providing following information: \n');</script>"); } Response.Write(@"<script>alert('TEST1 " + ds.Tables["table"].Rows.Count + " " + ds.Tables["table"].Columns.Count + " (mailto: [email protected]), providing following information: \n');</script>"); for (int rCnt = 0; rCnt < ds.Tables["table"].Rows.Count; rCnt++) { Response.Write(@"<script>alert('TEST ROW Failed to get data about counties from Excel. Please, contact administrator (mailto: [email protected]), providing following information: \n');</script>"); for (int cCnt = 1; cCnt < ds.Tables["table"].Columns.Count; cCnt++) { Response.Write(@"<script>alert('TEST COLUMN Failed to get data about counties from Excel. Please, contact administrator (mailto: [email protected]), providing following information: \n');</script>"); switch (cCnt) { case 1: name = ds.Tables["table"].Rows[rCnt][cCnt].ToString(); //name = Convert.ToString((range.Cells[rCnt, cCnt] as Excel.Range).Value2); Response.Write(@"<script>alert('TEST2 Please, contact administrator (mailto: [email protected]), providing following information: \n');</script>"); break; case 2: try { pdi = double.Parse(ds.Tables["table"].Rows[rCnt][cCnt].ToString()); } catch { Response.Write(@"<script>alert('TEST3Please, contact administrator (mailto: [email protected]), providing following information: \n');</script>"); pdi = -1; } break; case 3: try { idv = double.Parse(ds.Tables["table"].Rows[rCnt][cCnt].ToString()); } catch { idv = -1; } break; case 4: try { mas = double.Parse(ds.Tables["table"].Rows[rCnt][cCnt].ToString()); } catch { mas = -1; } break; case 5: try { uai = double.Parse(ds.Tables["table"].Rows[rCnt][cCnt].ToString()); } catch { uai = -1; } break; case 6: try { lto = double.Parse(ds.Tables["table"].Rows[rCnt][cCnt].ToString()); } catch { Response.Write(@"<script>alert('Test4 Please, contact administrator (mailto: [email protected]), providing following information: \n');</script>"); lto = -1; } break; case 7: try { ivr = double.Parse(ds.Tables["table"].Rows[rCnt][cCnt].ToString()); } catch { ivr = -1; } break; } } Country c = new Country(name, pdi, idv, mas, uai, lto, ivr); countries.Add(c); } Label1.Text = "Data delivered!"; this.Session["arrow1state"] = false; this.Session["arrow2state"] = true; this.Session["arrow3state"] = false; arrowsCheck((bool)this.Session["arrow1state"], (bool)this.Session["arrow2state"], (bool)this.Session["arrow2state"]); } catch (Exception ex) { Response.Write(@"<script>alert('Failed to get data about counties from Excel. Please, contact administrator (mailto: [email protected]), providing following information: \n" + ex.Message.ToString().Substring(0, ex.Message.Length - 3) + "');</script>"); Label1.Text = "Data delivery failed!"; //Response.Write("<script>alert('Failed to get data about counties from Excel. Please, contact administrator (mailto: [email protected]), providing following information: \\n" + ex.Message + "');</script>"); //Response.Write("<script>function window.onload() { alert( 'Hi!');}</script>"); //Response.Write("<script>function window.onload() { alert( 'Failed to get data about counties from Excel. Please, contact administrator (mailto: [email protected]), providing following information: \n');}</script>"); //MessageBox.Show("Failed to get data about counties from Excel. Please, contact administrator (mailto: [email protected]), providing following information: \n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } //filling listbox with countries //this.Dispatcher.Invoke(new ThreadStart(delegate //{ this.DropDownList1.AutoPostBack = true; this.DropDownList1.Items.Clear(); foreach (Country country in countries) { this.DropDownList1.Items.Add(country._name); } } }
//method reading .CSV source using Excel driver (NOT IN USE!) private void prepareDefaultData() { //Thread t = new Thread(new ThreadStart(delegate // { //Preparing countries if (!stoper) { try { Label1.Text = "Waiting for data preparation..."; Recomendation.SetToDefault(); Excel.Application xlApp; Excel.Workbook xlWorkBook; Excel.Worksheet xlWorkSheet; Excel.Range range; string name = ""; double pdi = 0, idv = 0, mas = 0, uai = 0, lto = 0, ivr = 0; int rCnt = 0; int cCnt = 0; xlApp = new Excel.Application(); //string path = HttpContext.Current.Server.MapPath("~/docs/Aldunin_dimensions_clasters.xls"); //xlWorkBook = xlApp.Workbooks.Open(HttpContext.Current.Server.MapPath(@"~/docs/Aldunin_dimensions_clasters.xls"));//, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); xlWorkBook = xlApp.Workbooks.Open(HttpContext.Current.Server.MapPath(@"~/docs/Aldunin_dimensions_clasters.xls"), 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); //xlWorkBook = xlApp.Workbooks.Open(@"liti.somee.com/www.liti.somee.com/v4/docs/Aldunin_dimensions_clasters.xls", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); range = xlWorkSheet.UsedRange; double progressStep = range.Rows.Count / 20; int progressStepCounter = 0; for (rCnt = 2; rCnt <= range.Rows.Count; rCnt++) { progressStepCounter++; if (progressStep < progressStepCounter) { //this.Dispatcher.Invoke(new ThreadStart(delegate //{ // progressBar1.Value += 5; //})); //progressStepCounter = 0; } for (cCnt = 2; cCnt <= range.Columns.Count; cCnt++) { switch (cCnt) { case 2: name = Convert.ToString((range.Cells[rCnt, cCnt] as Excel.Range).Value2); break; case 3: pdi = double.Parse(Convert.ToString(((range.Cells[rCnt, cCnt] as Excel.Range).Value2))); if (pdi < 0) pdi = -1; break; case 4: idv = double.Parse(Convert.ToString(((range.Cells[rCnt, cCnt] as Excel.Range).Value2))); if (idv < 0) idv = -1; break; case 5: mas = double.Parse(Convert.ToString(((range.Cells[rCnt, cCnt] as Excel.Range).Value2))); if (mas < 0) mas = -1; break; case 6: uai = double.Parse(Convert.ToString(((range.Cells[rCnt, cCnt] as Excel.Range).Value2))); if (uai < 0) uai = -1; break; case 7: lto = double.Parse(Convert.ToString(((range.Cells[rCnt, cCnt] as Excel.Range).Value2))); if (lto < 0) lto = -1; break; case 8: ivr = double.Parse(Convert.ToString(((range.Cells[rCnt, cCnt] as Excel.Range).Value2))); if (ivr < 0) ivr = -1; break; } } Country c = new Country(name, pdi, idv, mas, uai, lto, ivr); countries.Add(c); } xlWorkBook.Close(true, null, null); xlApp.Quit(); releaseObject(xlWorkSheet); releaseObject(xlWorkBook); releaseObject(xlApp); Label1.Text = "Data delivered!"; this.Session["arrow1state"] = false; this.Session["arrow2state"] = true; this.Session["arrow3state"] = false; arrowsCheck((bool)this.Session["arrow1state"], (bool)this.Session["arrow2state"], (bool)this.Session["arrow2state"]); } catch (Exception ex) { Response.Write(@"<script>alert('Failed to get data about counties from Excel. Please, contact administrator (mailto: [email protected]), providing following information: \n" + ex.Message.ToString().Substring(0, ex.Message.Length - 3) + "');</script>"); Label1.Text = "Data delivery failed!"; //Response.Write("<script>alert('Failed to get data about counties from Excel. Please, contact administrator (mailto: [email protected]), providing following information: \\n" + ex.Message + "');</script>"); //Response.Write("<script>function window.onload() { alert( 'Hi!');}</script>"); //Response.Write("<script>function window.onload() { alert( 'Failed to get data about counties from Excel. Please, contact administrator (mailto: [email protected]), providing following information: \n');}</script>"); //MessageBox.Show("Failed to get data about counties from Excel. Please, contact administrator (mailto: [email protected]), providing following information: \n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } //filling listbox with countries //this.Dispatcher.Invoke(new ThreadStart(delegate //{ this.DropDownList1.AutoPostBack = true; this.DropDownList1.Items.Clear(); foreach (Country country in countries) { this.DropDownList1.Items.Add(country._name); } //this.waitingLabel.Content = "Data is ready!"; //progressBar1.Value = progressBar1.Maximum; //})); //})); //t.Start(); } }
//method reading .CSV source using IOstream (IN USE) private void prepareDefaultDataCSV() { try { countries = new List<Country>(); string name = ""; double pdi = 0, idv = 0, mas = 0, uai = 0, lto = 0, ivr = 0; string path = HttpContext.Current.Server.MapPath(@"~/docs/Aldunin_dimensions_clasters.csv"); //path to .CSV - data source System.IO.StreamReader file = new System.IO.StreamReader(path); string line = file.ReadLine(); //missing 1st line while ((line = file.ReadLine()) != null) { string[] cells = line.Split(';'); for (int i = 0; i < cells.Length; i++) { switch (i) { case 1: name = cells[i]; break; case 2: try { pdi = double.Parse(cells[i]); } catch { pdi = -1; } break; case 3: try { idv = double.Parse(cells[i]); } catch { idv = -1; } break; case 4: try { mas = double.Parse(cells[i]); } catch { mas = -1; } break; case 5: try { uai = double.Parse(cells[i]); } catch { uai = -1; } break; case 6: try { lto = double.Parse(cells[i]); } catch { lto = -1; } break; case 7: try { ivr = double.Parse(cells[i]); } catch { ivr = -1; } break; } } Country c = new Country(name, pdi, idv, mas, uai, lto, ivr); countries.Add(c); } file.Close(); this.DropDownList1.AutoPostBack = true; this.DropDownList1.Items.Clear(); foreach (Country country in countries) { this.DropDownList1.Items.Add(country._name); } Label1.Text = "Data delivered!"; this.Session["arrow1state"] = false; this.Session["arrow2state"] = true; this.Session["arrow3state"] = false; arrowsCheck((bool)this.Session["arrow1state"], (bool)this.Session["arrow2state"], (bool)this.Session["arrow2state"]); } catch (Exception ex) { Response.Write(@"<script>alert('Failed to get data about counties from Excel. Please, contact administrator (mailto: [email protected]), providing following information: \n" + ex.Message.ToString().Substring(0, ex.Message.Length - 3) + "');</script>"); Label1.Text = "Data delivery failed!"; } }
private void prepareDefaultData() { //Thread t = new Thread(new ThreadStart(delegate // { //Preparing countries if (!stoper) { try { Label1.Text = "Waiting for data preparation..."; Recomendation.SetToDefault(); Excel.Application xlApp; Excel.Workbook xlWorkBook; Excel.Worksheet xlWorkSheet; Excel.Range range; string name = ""; double pdi = 0, idv = 0, mas = 0, uai = 0, lto = 0, ivr = 0; int rCnt = 0; int cCnt = 0; xlApp = new Excel.Application(); xlWorkBook = xlApp.Workbooks.Open(@"C:\ВШЭ\4 курс\Диплом\Hofstede's Dimensions Analysier\Hofstede's Dimensions Analysier\bin\Debug\Aldunin_dimensions_clasters.xls", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); range = xlWorkSheet.UsedRange; double progressStep = range.Rows.Count / 20; int progressStepCounter = 0; for (rCnt = 2; rCnt <= range.Rows.Count; rCnt++) { progressStepCounter++; if (progressStep < progressStepCounter) { //this.Dispatcher.Invoke(new ThreadStart(delegate //{ // progressBar1.Value += 5; //})); //progressStepCounter = 0; } for (cCnt = 2; cCnt <= range.Columns.Count; cCnt++) { switch (cCnt) { case 2: name = Convert.ToString((range.Cells[rCnt, cCnt] as Excel.Range).Value2); break; case 3: pdi = double.Parse(Convert.ToString(((range.Cells[rCnt, cCnt] as Excel.Range).Value2))); if (pdi < 0) pdi = -1; break; case 4: idv = double.Parse(Convert.ToString(((range.Cells[rCnt, cCnt] as Excel.Range).Value2))); if (idv < 0) idv = -1; break; case 5: mas = double.Parse(Convert.ToString(((range.Cells[rCnt, cCnt] as Excel.Range).Value2))); if (mas < 0) mas = -1; break; case 6: uai = double.Parse(Convert.ToString(((range.Cells[rCnt, cCnt] as Excel.Range).Value2))); if (uai < 0) uai = -1; break; case 7: lto = double.Parse(Convert.ToString(((range.Cells[rCnt, cCnt] as Excel.Range).Value2))); if (lto < 0) lto = -1; break; case 8: ivr = double.Parse(Convert.ToString(((range.Cells[rCnt, cCnt] as Excel.Range).Value2))); if (ivr < 0) ivr = -1; break; } } Country c = new Country(name, pdi, idv, mas, uai, lto, ivr); countries.Add(c); } xlWorkBook.Close(true, null, null); xlApp.Quit(); releaseObject(xlWorkSheet); releaseObject(xlWorkBook); releaseObject(xlApp); } catch (Exception ex) { MessageBox.Show("Failed to get data about counties from Excel. Please, contact administrator (mailto: [email protected]), providing following information: \n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } //filling listbox with countries //this.Dispatcher.Invoke(new ThreadStart(delegate //{ this.DropDownList1.AutoPostBack = true; this.DropDownList1.Items.Clear(); foreach (Country country in countries) { this.DropDownList1.Items.Add(country._name); } Label1.Text = "Data delivered!"; //this.waitingLabel.Content = "Data is ready!"; //progressBar1.Value = progressBar1.Maximum; //})); //})); //t.Start(); } }