private void runCalculation() { if (strTray1Pressure != string.Empty) { DataView dvStreamOut = (DataView)gridStreamOut.ItemsSource; dtStreamOut = dvStreamOut.Table; dtFlashResult.Rows.Clear(); int count = dtStreamOut.Rows.Count; for (int i = 1; i <= count; i++) { DataRow dr = dtStreamOut.Rows[i - 1]; if (dr["TotalMolarRate"].ToString() != "0") { FlashCompute fc = new FlashCompute(); string l = string.Empty; string v = string.Empty; string prodtype = dr["prodtype"].ToString(); string tray = dr["tray"].ToString(); string streamname = dr["streamname"].ToString(); string strPressure = dr["pressure"].ToString(); string f = string.Empty; double pressure = 0; if (strPressure != "") { pressure = double.Parse(strPressure); } string content = InpReader.getUsableContent(przFile, dr["streamname"].ToString(), tempdir); int percents = (int)((i - 0.4) * 100) / count; backgroundWorker.ReportProgress(percents, i); if (prodtype == "4" || (prodtype == "2" && tray == "1")) { f = fc.compute(content, 1, Prelief.ToString(), 3, "", dr, vapor, liquid, tempdir); } else if (prodtype == "6" || prodtype == "3") { f = fc.compute(content, 2, tempTemperature, 3, "", dr, vapor, liquid, tempdir); } else { double p = Prelief + (double.Parse(dr["pressure"].ToString()) - double.Parse(strTray1Pressure)); f = fc.compute(content, 1, p.ToString(), 4, "", dr, vapor, liquid, tempdir); } DataRow drFlash = dtFlashResult.NewRow(); drFlash["przfile"] = f; drFlash["liquid"] = liquid; drFlash["vapor"] = vapor; drFlash["stream"] = streamname; drFlash["prodtype"] = prodtype; drFlash["tray"] = tray; drFlash["visiofile"] = vsdFile; dtFlashResult.Rows.Add(drFlash); percents = (i * 100) / count; backgroundWorker.ReportProgress(percents, i); } } } }
private void checkData() { tempdir = System.IO.Path.GetDirectoryName(dbFile) + @"\temp\" + Guid.NewGuid().ToString(); if (!Directory.Exists(tempdir)) { Directory.CreateDirectory(tempdir); } backgroundWorker.ReportProgress(5); PRZWriter w = new PRZWriter(); DataTable dt = w.copyStream(przFile, eqName); backgroundWorker.ReportProgress(15); FlashCompute flashc = new FlashCompute(); strTray1Pressure = dt.Rows[0]["pressure"].ToString(); if (strTray1Pressure == "") { strTray1Pressure = "0"; } strTray1Pressure = UnitConverter.unitConv(strTray1Pressure, "KPA", "MPAG", "{0:0.0000}"); backgroundWorker.ReportProgress(25); string strTray1Temperature = dt.Rows[0]["Temperature"].ToString(); if (strTray1Temperature == "") { strTray1Temperature = "0"; } strTray1Temperature = UnitConverter.unitConv(strTray1Temperature, "K", "C", "{0:0.0000}"); tray1_s = dt.Rows[0]["streamname"].ToString().ToUpper(); string gd = Guid.NewGuid().ToString(); vapor = "S_" + gd.Substring(0, 5).ToUpper(); liquid = "S_" + gd.Substring(gd.Length - 5, 5).ToUpper(); backgroundWorker.ReportProgress(30); string content = InpReader.getUsableContent(przFile, dt.Rows[0]["streamname"].ToString(), tempdir); backgroundWorker.ReportProgress(40); tray1_f = flashc.compute(content, 1, Prelief.ToString(), 3, "", dt.Rows[0], vapor, liquid, tempdir); backgroundWorker.ReportProgress(60); PRZReader reader = new PRZReader(tray1_f); DataSet ds = reader.getDataFromFile(); while (ds.Tables[0].Rows[0]["temperature"].ToString() == "") { ds = reader.getDataFromFile(); } backgroundWorker.ReportProgress(80); DBRelief dbreader = new DBRelief(); feedH = dbreader.computeH(ds.Tables[0], tray1_s.ToUpper()); vaporH = dbreader.computeH(ds.Tables[0], vapor); liqidH = dbreader.computeH(ds.Tables[0], liquid); tempTemperature = vaporH[3]; backgroundWorker.ReportProgress(100); }