public void buttonr1_b_click(Object sender, System.EventArgs e) { try { classE1_1.username = username; CalcClass.CalculationResult result = CalcClass.CalculateResults(classE1_1); txtResults.Text = result.resultMessage; txtErrors.Text = result.errorMessage; pnlResults.Visible = true; pnlErrors.Visible = !result.errorMessage.Trim().Equals(String.Empty); bool vis1 = !result.errorMessage.Trim().Equals(String.Empty); if (vis1 == true) { pnlErrors.Visible = true; pnlErrors.BorderColor = Color.Black; pnlErrors.BorderWidth = 3; pnlErrors.BorderStyle = BorderStyle.Solid; } else { pnlErrors.Visible = false; pnlResults.BorderStyle = BorderStyle.None; } MPXRunChoices.SetActiveView(viewResults); SetActiveView(2); } catch (Exception calcEx) { Master.ShowErrorMessage(calcEx.Message); } }
public override object ProvideValue(IServiceProvider serviceProvider) { var borderClass = new BorderClass { Positioner = this }; IProvideValueTarget service = (IProvideValueTarget)serviceProvider.GetService(typeof(IProvideValueTarget)); borderClass.Border = service.TargetObject as FrameworkElement;; if (borderClass.Border == null) { return(this); } var cc = new CalcClass { BorderClass = borderClass, Popup = borderClass.Border.FindAncestor <Popup>() }; if (cc.Popup != null) { cc.Popup.Opened += cc.Openend; } return(new Thickness(1.0)); }
private static void CalcTest1() { try { Console.WriteLine("Test 1\r\n" + "Input data: a = 25, b = 25"); Console.WriteLine("Expected result: 625"); int result = CalcClass.Mult(25, 25); if (CalcClass.lastError == "") { Console.WriteLine("Result: " + result); Console.WriteLine("Test completed"); } else { Console.WriteLine("Error code: " + CalcClass.lastError); Console.WriteLine("Test failed"); } } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("Test failed"); } }
private static void CalcTest2() { try { Console.WriteLine("Test 2\r\n" + "Input data: a = {0}, b = 2", (long)int.MaxValue * 2); Console.WriteLine("Expected result: Error 06"); int result = CalcClass.Mult((long)(int.MaxValue) * 2, 1); string str = CalcClass.lastError; if (str.Equals("")) { Console.WriteLine("Result: " + result); Console.WriteLine("Test completed"); } else { Console.WriteLine("Result: error"); Console.WriteLine("Error code: " + str); Console.WriteLine("Test failed"); } } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("Test failed"); } }
private void PositiveModTest(int testNumber, long a, long b) { long result = CalcClass.Mod(a, b); long expected = a % b; Log.CreateLog(logger, component, testNumber, a.ToString(), expected.ToString(), result.ToString()); Assert.AreEqual(result, expected); }
private void PositiveAbsTest(long a, int testNumber) { long result = CalcClass.ABS(a); long expected = Math.Abs(a); Log.CreateLog(logger, "CalcClass.Abs", testNumber, a.ToString(), expected.ToString(), result.ToString()); Assert.AreEqual(result, expected); }
protected void AddGraphMLcolumn() { if (!ColumnExists("graphML", "tblprodfore")) { string alterTable = "Alter table tblprodfore ADD COLUMN graphML Memo;"; CalcClass calcClass = new CalcClass(GetDirectory() + userDir + "curr_mpx.mdb"); calcClass.runsql(alterTable); } }
startCalc() { //your code CalcClass calc = new CalcClass(); calc.ProgressUpdate += (s, e) => { Dispatcher.Invoke((Action)delegate() { /* update UI */ }); }; Thread calcthread = new Thread(new ParameterizedThreadStart(calc.testMethod); calcthread.Start(input); }
CalcClass PrepareCalc() { //your code var calc = new CalcClass(); calc.ProgressUpdate += (s, e) => Dispatcher.Invoke((Action) delegate() { // update UI }); return(calc); }
protected void AddEquipTypeNameColumn() { string alterTable = "Alter table tblequip ADD COLUMN equiptypename Text (15) "; CalcClass calcClass = new CalcClass(GetDirectory() + userDir + "curr_mpx.mdb"); calcClass.runsql(alterTable); calcClass.runsql("UPDATE tblequip SET equiptypename = 'Standard' WHERE EquipType = 0;"); calcClass.runsql("UPDATE tblequip SET equiptypename = 'Delay' WHERE EquipType = 1;"); calcClass = new CalcClass(GetDirectory() + userDir + MAIN_USER_DATABASE); //calcClass.runsql(alterTable); alterTable = "Alter table zztblequip ADD COLUMN equiptypename Text (15) "; calcClass.runsql(alterTable); }
private void NegativeModTest(int testNumber, long a, long b, string exeption) { long result = CalcClass.Mod(a, b); string exep = CalcClass.lastError; if (result == 0 && exep.Contains(exeption)) { Log.CreateLog(logger, component, testNumber, a.ToString(), "0 " + exeption, result.ToString() + " " + exep); Assert.AreEqual(result, 0); } else { Log.CreateBugReport(logger, component, testNumber, a.ToString(), "0 " + exeption, result.ToString() + " " + exep, ""); } }
private void PositiveIAbsTest(int testNumber, long a) { long result = CalcClass.IABS(a); long expected = 0; if (a < 0) { expected = a; } if (a > 0) { expected = -a; } Log.CreateLog(logger, component, testNumber, a.ToString(), expected.ToString(), result.ToString()); Assert.AreEqual(result, expected); }
public void bMPlus_ForTest() { if (result != "") { try { BaseCalc.mem = CalcClass.Add(BaseCalc.mem, Convert.ToInt32(result)); } catch (OverflowException ex) { // Слишком малое или слишком большое значение числа для int\nЧисла должны быть в пределах от -2147483648 до 2147483647 exception = 1; } catch (Exception ex) { // "Невозможно преобразовать к числу!", "Ошибка" exception = 2; } } }
private void AddTest(int testNumber) { Random ran = new Random(); long a = ran.Next(int.MaxValue); long b = ran.Next(int.MaxValue); long expected = 0; long result = CalcClass.Add(a, b); if (a + b <= int.MaxValue) { expected = a + b; } if (expected == result) { Log.CreateLogInfo(logger, testNumber, InputToString(a, b), expected.ToString(), result.ToString()); } else { Log.CreateBugReport(logger, COMPANENT_NAME, testNumber, InputToString(a, b), expected.ToString(), result.ToString()); } }
protected void btnSaveShowWhatifs_Click(object sender, EventArgs e) { try { CalcClass calc = new CalcClass(GetDirectory() + userDir + MAIN_USER_DATABASE); int numOfWhatifShow = 0; for (int i = 0; i < lstCheckWhatifs.Items.Count; i++) { ListItem item = lstCheckWhatifs.Items[i]; string key = item.Value; string show = item.Selected ? "-1" : "0"; if (key.Equals("0")) { if (calc.runsql("UPDATE zs0tblWhatif SET display = " + show + " WHERE WID = " + key + ";") && item.Selected) { numOfWhatifShow++; } } else { if (calc.runsql("UPDATE tblWhatif SET display = " + show + " WHERE WID = " + key + ";") && item.Selected) { numOfWhatifShow++; } } } if (numOfWhatifShow == 0) { // the user chose no results to display - by default display basecase results calc.runsql("UPDATE zs0tblWhatif SET display = -1 WHERE WID = 0;"); Master.ShowErrorMessage("No results are selected to display. The basecase results will be shown by default."); } BindCheckWhatifs(); } catch (Exception ex) { logFiles.ErrorLog(ex); Master.ShowErrorMessage("MPX internal error has occured."); } }
static void Main(string[] args) { Random ran = new Random(); for (int i = 0; i < 3; i++) { long a = ran.Next(int.MaxValue); long b = ran.Next(int.MaxValue); Console.WriteLine("a = " + a); Console.WriteLine("b = " + b); if ((a + b) > int.MaxValue) { Console.WriteLine("Ожидаемый результат - слишком большое число"); } else { Console.WriteLine("Ожидаемый результат = " + (a + b)); } long result = CalcClass.Add(a, b); Console.WriteLine("Полученный результат = " + result); } Console.ReadKey(); }
public void save_errors_results(string msgResults, string msgErrors) { CalcClass.save_errors_results(classE1_1, msgResults, msgErrors); }
private void buttonStartDel_Click(object sender, EventArgs e) { try { richTextBox1.Text = ""; richTextBox1.Text += "Test Case 1\n"; richTextBox1.Text += "Входные данные: a= 78508, b = -304\n"; richTextBox1.Text += "Ожидаемый результат: res = 78204 && error = \"\"" + "\n"; int res = CalcClass.Add(78508, -304); string error = CalcClass.lastError; richTextBox1.Text += "Код ошибки: " + error + "\n"; richTextBox1.Text += "Получившийся результат: " + "res = " + res.ToString() + " error = " + error.ToString() + "\n"; if (res == 78204 && error == "") { richTextBox1.Text += "Тест пройден\n\n"; } else { richTextBox1.Text += "Тест не пройден\n\n"; } } catch (Exception ex) { richTextBox1.Text += "Перехвачено исключение: " + ex.ToString() + "\nТест не пройден.\n"; } try { richTextBox1.Text += "Test Case 2\n"; richTextBox1.Text += "Входные данные: a= -2850800078, b = 3000000000\n"; richTextBox1.Text += "Ожидаемый результат: res = 0 && error = \"Error 06\"\n"; int res = CalcClass.Add(-2850800078, 3000000000); string error = CalcClass.lastError; richTextBox1.Text += "Код ошибки: " + error + "\n"; richTextBox1.Text += "Получившийся результат: " + "res = " + res.ToString() + " error = " + error.ToString() + "\n"; if (res == 0 && error == "Error 06") { richTextBox1.Text += "Тест пройден\n\n"; } else { richTextBox1.Text += "Тест не пройден\n\n"; } } catch (Exception ex) { richTextBox1.Text += "Перехвачено исключение: " + ex.ToString() + "\nТест не пройден.\n"; } try { richTextBox1.Text += "Test Case 3\n"; richTextBox1.Text += "Входные данные: a= 3000000000, b = -2850800078\n"; richTextBox1.Text += "Ожидаемый результат: res = 0 && error = \"Error 06\"\n"; int res = CalcClass.Add(3000000000, -2850800078); string error = CalcClass.lastError; richTextBox1.Text += "Код ошибки: " + error + "\n"; richTextBox1.Text += "Получившийся результат: " + "res = " + res.ToString() + " error = " + error.ToString() + "\n"; if (res == 0 && error == "Error 06") { richTextBox1.Text += "Тест пройден\n\n"; } else { richTextBox1.Text += "Тест не пройден\n\n"; } } catch (Exception ex) { richTextBox1.Text += "Перехвачено исключение: " + ex.ToString() + "\nТест не пройден.\n"; } try { richTextBox1.Text += "Test Case 4\n"; richTextBox1.Text += "Входные данные: a= 2000000000, b = 2000000000\n"; richTextBox1.Text += "Ожидаемый результат: res = 0 && error = \"Error 06\"\n"; int res = CalcClass.Add(2000000000, 2000000000); string error = CalcClass.lastError; richTextBox1.Text += "Код ошибки: " + error + "\n"; richTextBox1.Text += "Получившийся результат: " + "res = " + res.ToString() + " error = " + error.ToString() + "\n"; if (res == 0 && error == "Error 06") { richTextBox1.Text += "Тест пройден\n\n"; } else { richTextBox1.Text += "Тест не пройден\n\n"; } } catch (Exception ex) { richTextBox1.Text += "Перехвачено исключение: " + ex.ToString() + "\nТест не пройден.\n"; } }
// Кнопка для тестирования математической операции private void button1_Click(object sender, EventArgs e) { mainTextBox.Text = ""; mainTextBox.Text = "Тестирование метода деления с остатком." + Environment.NewLine; // 1 тестовый пример try { mainTextBox.Text += "Test Case 1" + Environment.NewLine; mainTextBox.Text += "Входные данные: a = -2147483648, b = -2147483648" + Environment.NewLine; mainTextBox.Text += "Ожидаемый результат: res = 0" + Environment.NewLine; int res = CalcClass.Mod(-2147483648, -2147483648); string error = CalcClass.lastError; mainTextBox.Text += "Код ошибки: " + error + Environment.NewLine; mainTextBox.Text += "Получившийся результат: " + "res = " + res.ToString() + Environment.NewLine; if (res == 0 && error == "") { mainTextBox.Text += "Тест пройден" + Environment.NewLine + Environment.NewLine; } else { mainTextBox.Text += "Тест не пройден" + Environment.NewLine + Environment.NewLine; } } catch (Exception ex) { mainTextBox.Text += "Перехвачено исключение: " + ex.ToString() + Environment.NewLine + "Тест не пройден." + Environment.NewLine; } // 2 тестовый пример try { mainTextBox.Text += "Test Case 2" + Environment.NewLine; mainTextBox.Text += "Входные данные: a = 2147483647, b = -2147483648" + Environment.NewLine; mainTextBox.Text += "Ожидаемый результат: res = 2147483647" + Environment.NewLine; int res = CalcClass.Mod(2147483647, -2147483648); string error = CalcClass.lastError; mainTextBox.Text += "Код ошибки: " + error + Environment.NewLine; mainTextBox.Text += "Получившийся результат: " + "res = " + res.ToString() + Environment.NewLine; if (res == 2147483647 && error == "") { mainTextBox.Text += "Тест пройден" + Environment.NewLine + Environment.NewLine; } else { mainTextBox.Text += "Тест не пройден" + Environment.NewLine + Environment.NewLine; } } catch (Exception ex) { mainTextBox.Text += "Перехвачено исключение: " + ex.ToString() + Environment.NewLine + "Тест не пройден." + Environment.NewLine; } // 3 тестовый пример try { mainTextBox.Text += "Test Case 3" + Environment.NewLine; mainTextBox.Text += "Входные данные: a = -2147483648, b = 2147483647" + Environment.NewLine; mainTextBox.Text += "Ожидаемый результат: res = -1" + Environment.NewLine; int res = CalcClass.Mod(-2147483648, 2147483647); string error = CalcClass.lastError; mainTextBox.Text += "Код ошибки: " + error + Environment.NewLine; mainTextBox.Text += "Получившийся результат: " + "res = " + res.ToString() + Environment.NewLine; if (res == -1 && error == "") { mainTextBox.Text += "Тест пройден" + Environment.NewLine + Environment.NewLine; } else { mainTextBox.Text += "Тест не пройден" + Environment.NewLine + Environment.NewLine; } } catch (Exception ex) { mainTextBox.Text += "Перехвачено исключение: " + ex.ToString() + Environment.NewLine + "Тест не пройден." + Environment.NewLine; } // 4 тестовый пример try { mainTextBox.Text += "Test Case 4" + Environment.NewLine; mainTextBox.Text += "Входные данные: a = 2147483647, b = 2147483647" + Environment.NewLine; mainTextBox.Text += "Ожидаемый результат: res = 0" + Environment.NewLine; int res = CalcClass.Mod(2147483647, 2147483647); string error = CalcClass.lastError; mainTextBox.Text += "Код ошибки: " + error + Environment.NewLine; mainTextBox.Text += "Получившийся результат: " + "res = " + res.ToString() + Environment.NewLine; if (res == 0 && error == "") { mainTextBox.Text += "Тест пройден" + Environment.NewLine + Environment.NewLine; } else { mainTextBox.Text += "Тест не пройден" + Environment.NewLine + Environment.NewLine; } } catch (Exception ex) { mainTextBox.Text += "Перехвачено исключение: " + ex.ToString() + Environment.NewLine + "Тест не пройден." + Environment.NewLine; } // 5 тестовый пример try { mainTextBox.Text += "Test Case 5" + Environment.NewLine; mainTextBox.Text += "Входные данные: a = 66882233, b = 2147483646" + Environment.NewLine; mainTextBox.Text += "Ожидаемый результат: res = 66882233" + Environment.NewLine; int res = CalcClass.Mod(66882233, 2147483646); string error = CalcClass.lastError; mainTextBox.Text += "Код ошибки: " + error + Environment.NewLine; mainTextBox.Text += "Получившийся результат: " + "res = " + res.ToString() + Environment.NewLine; if (res == 66882233 && error == "") { mainTextBox.Text += "Тест пройден" + Environment.NewLine + Environment.NewLine; } else { mainTextBox.Text += "Тест не пройден" + Environment.NewLine + Environment.NewLine; } } catch (Exception ex) { mainTextBox.Text += "Перехвачено исключение: " + ex.ToString() + Environment.NewLine + "Тест не пройден." + Environment.NewLine; } // 6 тестовый пример try { mainTextBox.Text += "Test Case 6" + Environment.NewLine; mainTextBox.Text += "Входные данные: a = -2147483647, b = -112244" + Environment.NewLine; mainTextBox.Text += "Ожидаемый результат: res = -31439" + Environment.NewLine; int res = CalcClass.Mod(-2147483647, -112244); string error = CalcClass.lastError; mainTextBox.Text += "Код ошибки: " + error + Environment.NewLine; mainTextBox.Text += "Получившийся результат: " + "res = " + res.ToString() + Environment.NewLine; if (res == -31439 && error == "") { mainTextBox.Text += "Тест пройден" + Environment.NewLine + Environment.NewLine; } else { mainTextBox.Text += "Тест не пройден" + Environment.NewLine + Environment.NewLine; } } catch (Exception ex) { mainTextBox.Text += "Перехвачено исключение: " + ex.ToString() + Environment.NewLine + "Тест не пройден." + Environment.NewLine; } // 7 тестовый пример try { mainTextBox.Text += "Test Case 7" + Environment.NewLine; mainTextBox.Text += "Входные данные: a = 0, b = 2147483646" + Environment.NewLine; mainTextBox.Text += "Ожидаемый результат: res = 0" + Environment.NewLine; int res = CalcClass.Mod(0, 2147483646); string error = CalcClass.lastError; mainTextBox.Text += "Код ошибки: " + error + Environment.NewLine; mainTextBox.Text += "Получившийся результат: " + "res = " + res.ToString() + Environment.NewLine; if (res == 0 && error == "") { mainTextBox.Text += "Тест пройден" + Environment.NewLine + Environment.NewLine; } else { mainTextBox.Text += "Тест не пройден" + Environment.NewLine + Environment.NewLine; } } catch (Exception ex) { mainTextBox.Text += "Перехвачено исключение: " + ex.ToString() + Environment.NewLine + "Тест не пройден." + Environment.NewLine; } // 8 тестовый пример try { mainTextBox.Text += "Test Case 8" + Environment.NewLine; mainTextBox.Text += "Входные данные: a = 0, b = -2147483647" + Environment.NewLine; mainTextBox.Text += "Ожидаемый результат: res = 0" + Environment.NewLine; int res = CalcClass.Mod(0, -2147483647); string error = CalcClass.lastError; mainTextBox.Text += "Код ошибки: " + error + Environment.NewLine; mainTextBox.Text += "Получившийся результат: " + "res = " + res.ToString() + Environment.NewLine; if (res == 0 && error == "") { mainTextBox.Text += "Тест пройден" + Environment.NewLine + Environment.NewLine; } else { mainTextBox.Text += "Тест не пройден" + Environment.NewLine + Environment.NewLine; } } catch (Exception ex) { mainTextBox.Text += "Перехвачено исключение: " + ex.ToString() + Environment.NewLine + "Тест не пройден." + Environment.NewLine; } // 9 тестовый пример try { mainTextBox.Text += "Test Case 9" + Environment.NewLine; mainTextBox.Text += "Входные данные: a = -2147483647, b = 2147483646" + Environment.NewLine; mainTextBox.Text += "Ожидаемый результат: res = -1" + Environment.NewLine; int res = CalcClass.Mod(-2147483647, 2147483646); string error = CalcClass.lastError; mainTextBox.Text += "Код ошибки: " + error + Environment.NewLine; mainTextBox.Text += "Получившийся результат: " + "res = " + res.ToString() + Environment.NewLine; if (res == -1 && error == "") { mainTextBox.Text += "Тест пройден" + Environment.NewLine + Environment.NewLine; } else { mainTextBox.Text += "Тест не пройден" + Environment.NewLine + Environment.NewLine; } } catch (Exception ex) { mainTextBox.Text += "Перехвачено исключение: " + ex.ToString() + Environment.NewLine + "Тест не пройден." + Environment.NewLine; } // 10 тестовый пример try { mainTextBox.Text += "Test Case 10" + Environment.NewLine; mainTextBox.Text += "Входные данные: a = 2147483646, b = -2147483647" + Environment.NewLine; mainTextBox.Text += "Ожидаемый результат: res = 2147483646" + Environment.NewLine; int res = CalcClass.Mod(2147483646, -2147483647); string error = CalcClass.lastError; mainTextBox.Text += "Код ошибки: " + error + Environment.NewLine; mainTextBox.Text += "Получившийся результат: " + "res = " + res.ToString() + Environment.NewLine; if (res == 2147483646 && error == "") { mainTextBox.Text += "Тест пройден" + Environment.NewLine + Environment.NewLine; } else { mainTextBox.Text += "Тест не пройден" + Environment.NewLine + Environment.NewLine; } } catch (Exception ex) { mainTextBox.Text += "Перехвачено исключение: " + ex.ToString() + Environment.NewLine + "Тест не пройден." + Environment.NewLine; } // 11 тестовый пример try { mainTextBox.Text += "Test Case 11" + Environment.NewLine; mainTextBox.Text += "Входные данные: a = 2147483647, b = 779955" + Environment.NewLine; mainTextBox.Text += "Ожидаемый результат: res = 267532" + Environment.NewLine; int res = CalcClass.Mod(2147483647, 779955); string error = CalcClass.lastError; mainTextBox.Text += "Код ошибки: " + error + Environment.NewLine; mainTextBox.Text += "Получившийся результат: " + "res = " + res.ToString() + Environment.NewLine; if (res == 267532 && error == "") { mainTextBox.Text += "Тест пройден" + Environment.NewLine + Environment.NewLine; } else { mainTextBox.Text += "Тест не пройден" + Environment.NewLine + Environment.NewLine; } } catch (Exception ex) { mainTextBox.Text += "Перехвачено исключение: " + ex.ToString() + Environment.NewLine + "Тест не пройден." + Environment.NewLine; } // 12 тестовый пример try { mainTextBox.Text += "Test Case 12" + Environment.NewLine; mainTextBox.Text += "Входные данные: a = -2147483648, b = 123123" + Environment.NewLine; mainTextBox.Text += "Ожидаемый результат: res = -95405" + Environment.NewLine; int res = CalcClass.Mod(-2147483648, 123123); string error = CalcClass.lastError; mainTextBox.Text += "Код ошибки: " + error + Environment.NewLine; mainTextBox.Text += "Получившийся результат: " + "res = " + res.ToString() + Environment.NewLine; if (res == -95405 && error == "") { mainTextBox.Text += "Тест пройден" + Environment.NewLine + Environment.NewLine; } else { mainTextBox.Text += "Тест не пройден" + Environment.NewLine + Environment.NewLine; } } catch (Exception ex) { mainTextBox.Text += "Перехвачено исключение: " + ex.ToString() + Environment.NewLine + "Тест не пройден." + Environment.NewLine; } // 13 тестовый пример try { mainTextBox.Text += "Test Case 13" + Environment.NewLine; mainTextBox.Text += "Входные данные: a = 456, b = 2147483647" + Environment.NewLine; mainTextBox.Text += "Ожидаемый результат: res = 456" + Environment.NewLine; int res = CalcClass.Mod(456, 2147483647); string error = CalcClass.lastError; mainTextBox.Text += "Код ошибки: " + error + Environment.NewLine; mainTextBox.Text += "Получившийся результат: " + "res = " + res.ToString() + Environment.NewLine; if (res == 456 && error == "") { mainTextBox.Text += "Тест пройден" + Environment.NewLine + Environment.NewLine; } else { mainTextBox.Text += "Тест не пройден" + Environment.NewLine + Environment.NewLine; } } catch (Exception ex) { mainTextBox.Text += "Перехвачено исключение: " + ex.ToString() + Environment.NewLine + "Тест не пройден." + Environment.NewLine; } // 14 тестовый пример try { mainTextBox.Text += "Test Case 14" + Environment.NewLine; mainTextBox.Text += "Входные данные: a = 3010789, b = -2147483648" + Environment.NewLine; mainTextBox.Text += "Ожидаемый результат: res = 3010789" + Environment.NewLine; int res = CalcClass.Mod(3010789, -2147483648); string error = CalcClass.lastError; mainTextBox.Text += "Код ошибки: " + error + Environment.NewLine; mainTextBox.Text += "Получившийся результат: " + "res = " + res.ToString() + Environment.NewLine; if (res == 3010789 && error == "") { mainTextBox.Text += "Тест пройден" + Environment.NewLine + Environment.NewLine; } else { mainTextBox.Text += "Тест не пройден" + Environment.NewLine + Environment.NewLine; } } catch (Exception ex) { mainTextBox.Text += "Перехвачено исключение: " + ex.ToString() + Environment.NewLine + "Тест не пройден." + Environment.NewLine; } // 15 тестовый пример try { mainTextBox.Text += "Test Case 15" + Environment.NewLine; mainTextBox.Text += "Входные данные: a = 2147483648, b = 3" + Environment.NewLine; mainTextBox.Text += "Ожидаемый результат: Error 06" + Environment.NewLine; int res = CalcClass.Mod(2147483648, 3); string error = CalcClass.lastError; mainTextBox.Text += "Код ошибки: " + error + Environment.NewLine; mainTextBox.Text += "Получившийся результат: " + "res = " + res.ToString() + Environment.NewLine; if (res == 0 && error == "Error 06") { mainTextBox.Text += "Тест пройден" + Environment.NewLine + Environment.NewLine; } else { mainTextBox.Text += "Тест не пройден" + Environment.NewLine + Environment.NewLine; } } catch (Exception ex) { mainTextBox.Text += "Перехвачено исключение: " + ex.ToString() + Environment.NewLine + "Тест не пройден." + Environment.NewLine; } // 16 тестовый пример try { mainTextBox.Text += "Test Case 16" + Environment.NewLine; mainTextBox.Text += "Входные данные: a = 3, b = -2147483649" + Environment.NewLine; mainTextBox.Text += "Ожидаемый результат: Error 06" + Environment.NewLine; int res = CalcClass.Mod(3, -2147483649); string error = CalcClass.lastError; mainTextBox.Text += "Код ошибки: " + error + Environment.NewLine; mainTextBox.Text += "Получившийся результат: " + "res = " + res.ToString() + Environment.NewLine; if (res == 0 && error == "Error 06") { mainTextBox.Text += "Тест пройден" + Environment.NewLine + Environment.NewLine; } else { mainTextBox.Text += "Тест не пройден" + Environment.NewLine + Environment.NewLine; } } catch (Exception ex) { mainTextBox.Text += "Перехвачено исключение: " + ex.ToString() + Environment.NewLine + "Тест не пройден." + Environment.NewLine; } // 17 тестовый пример try { mainTextBox.Text += "Test Case 17" + Environment.NewLine; mainTextBox.Text += "Входные данные: a = 671, b = 0" + Environment.NewLine; mainTextBox.Text += "Ожидаемый результат: Error 09" + Environment.NewLine; int res = CalcClass.Mod(671, 0); string error = CalcClass.lastError; mainTextBox.Text += "Код ошибки: " + error + Environment.NewLine; mainTextBox.Text += "Получившийся результат: " + "res = " + res.ToString() + Environment.NewLine; if (res == 0 && error == "Error 09") { mainTextBox.Text += "Тест пройден" + Environment.NewLine + Environment.NewLine; } else { mainTextBox.Text += "Тест не пройден" + Environment.NewLine + Environment.NewLine; } } catch (Exception ex) { mainTextBox.Text += "Перехвачено исключение: " + ex.ToString() + Environment.NewLine + "Тест не пройден." + Environment.NewLine; } }
public static string RunAll(string username, string path, string sessionID) { string resultMessage = ""; var resultArray = new List <string[]>(); if (isCalculating(path)) { resultMessage = "Calculations are still in process from the previous run, please wait"; } else { int ret; DbUse.CreateRunFile(path, username); ClassF classE1_1 = new ClassF(path); classE1_1.Open(); try { int totalCalc = 0; int currentCalc = -1; classE1_1.username = username; classE1_1.SetBasicModelInfo(); classE1_1.calc_return = 0; //0 - none, 1 labor, 2 eq over util, 4 warnings 8 errors ADODB.Recordset recNeedCalc = new ADODB.Recordset(); //check if basecase needs recalc and add to totalCalc DbUse.open_ado_rec(classE1_1.globaldb, ref recNeedCalc, "SELECT * FROM zs0tblWhatIf WHERE zs0tblWhatIf.WID=0;"); totalCalc++; bool recOpened = DbUse.OpenAdoRec(classE1_1.globaldb, recNeedCalc, "SELECT * FROM tblWhatIf WHERE FamilyID = 0 AND display = -1;"); //bool recOpened = DbUse.OpenAdoRec(classE1_1.globaldb, recNeedCalc, "SELECT * FROM tblWhatIf;"); while (!recNeedCalc.EOF) { totalCalc++; recNeedCalc.MoveNext(); } DbUse.CloseAdoRec(recNeedCalc); DbUse.RunMysql("INSERT INTO usercalc (id) SELECT userlist.id FROM userlist WHERE userlist.sessionid = '" + sessionID + "';"); DbUse.RunMysql("UPDATE usercalc INNER JOIN userlist ON usercalc.id = userlist.id SET total = " + totalCalc + ", calc = " + currentCalc + ", lastCheck = " + DateTime.Now.Ticks + ", cancel = 0, timePerCalc = 100000000 WHERE userlist.sessionid = '" + sessionID + "';"); classE1_1.global_runalldone = false; classE1_1.global_initwid = classE1_1.glngwid; classE1_1.errorMessageGlobal = ""; while (classE1_1.global_runalldone == false) { classE1_1.calc_return = 0; //classE1_1.Run_All_ReCalc(1); resultArray = classE1_1.CalculateResults(1, sessionID); } if (classE1_1.global_initwid != classE1_1.glngwid) { if (classE1_1.global_initwid != 0) { classE1_1.LoadBaseCase(); ret = classE1_1.LoadWhatIf(classE1_1.global_initwid); } else { classE1_1.LoadBaseCase(); } } ; resultMessage = CalcClass.GetErrorMessage(classE1_1); if (resultMessage.Trim().Equals(String.Empty)) { foreach (var result in resultArray) { if (result[4].Equals("true")) { resultMessage += "<span style='color:#27ae60;'>"; } else { resultMessage += "<span style='color:#c0392b;'>"; } resultMessage += result[0] + ": "; if (!String.IsNullOrEmpty(result[1])) { resultMessage += result[1]; } if (!String.IsNullOrEmpty(result[2])) { resultMessage += result[2]; } if (!String.IsNullOrEmpty(result[3])) { resultMessage += result[3]; } resultMessage += "</span>"; } } //if (resultMessage.Trim().Equals(String.Empty)) //{ // if ((classE1_1.calc_return & CalcClass.ERR_FLAG) > 0) // { // resultMessage = CalcClass.do_calc_msg(classE1_1.calc_return, 0); // } // else // { // resultMessage = CalcClass.do_calc_msg(classE1_1.calc_return, 1); // } //} classE1_1.runsqlado("UPDATE zs0tblWhatif SET display = -1 WHERE WID = " + classE1_1.glngwid + ";"); } catch (Exception) { resultMessage = "MPX internal error has occured"; } classE1_1.Close(); DbUse.RunMysql("DELETE usercalc.* FROM usercalc INNER JOIN userlist ON usercalc.id = userlist.id WHERE userlist.sessionid = '" + sessionID + "';"); DbUse.DeleteRunFile(path, username); } return(resultMessage); }
string do_calc_msg(int calc_r, int mtype) { return(CalcClass.do_calc_msg(calc_r, mtype)); }
public void buttonr4_opt(Object sender, System.EventArgs e) { bool b1; /*options 1) basecase a. add opt here b. new whatif name if not new return = message whatif xxx exists already * 2) in whatif a. add opt here b. new whatif name (+save/close cur whatif xxx or trash changes since last save for cur whatif xxx * if not new return = message whatif xxx exists already * */ int wid; string str1; string str2; ADODB.Recordset recprod = null; int fstatus; string name1; int newwhatifid; double val1; double val2; double val3; int ret1; logFiles.RunLog(); if (DbUse.InRunProcess(userDir)) { Master.ShowErrorMessage("Cannot start verification and calculations. The verification and calculations are still in process from the previous run. Please wait."); logFiles.DuplicateRunEndLog(); return; } bool unavailable = false; if (unavailable) { Master.ShowInfoMessage("Optimize lot sizes feature is under construction and currently unavailable."); return; } CreateRunFile(); long currTime = DateTime.Now.Ticks; DbUse.RunMysql("INSERT INTO usercalc (id) SELECT userlist.id FROM userlist WHERE userlist.sessionid = '" + HttpContext.Current.Session.SessionID + "';"); DbUse.RunMysql("UPDATE usercalc INNER JOIN userlist ON usercalc.id = userlist.id SET total = 2, calc = 1, lastCheck = " + currTime + ", cancel = 0 WHERE userlist.sessionid = '" + HttpContext.Current.Session.SessionID + "';"); try { classE1_1.Open(); //today whatif name change to whatif field on second time around ??? classE1_1.SetBasicModelInfo(); // sets glngwid etc. name1 = MyUtilities.clean(TextBox9.Text).ToUpper(); //name1 = name1.ToUpper(); // get into whatif as needed /* * 1. in basecase - stay * 2. in whatif - stay * 3. if basecase/whatif - switch to new whatif * 4. if in whatif getting new - save old whatif * */ str1 = "New What-If Scenario for lot size optimization"; int currentWhatif = classE1_1.glngwid; if (classE1_1.glngwid == 0) { if (RadioButtonList1.Items[1].Selected) { //start ewhatif if (name1.Length == 0) { classE1_1.Close(); Master.ShowErrorMessage("Invalid name for the new What-If Scenario. Please enter a name for the optimization What-If Scenario to be created."); DeleteRunFile(); DbUse.RunMysql("DELETE usercalc.* FROM usercalc INNER JOIN userlist ON usercalc.id = userlist.id WHERE userlist.sessionid = '" + HttpContext.Current.Session.SessionID + "';"); logFiles.RunEndLog(); return; } if (WhatifExists(name1)) { classE1_1.Close(); Master.ShowErrorMessage("A What-If Scenario with the same name already exists. Please choose a different name."); DeleteRunFile(); DbUse.RunMysql("DELETE usercalc.* FROM usercalc INNER JOIN userlist ON usercalc.id = userlist.id WHERE userlist.sessionid = '" + HttpContext.Current.Session.SessionID + "';"); logFiles.RunEndLog(); return; } // add new whatif , get into it newwhatifid = classE1_1.addnewwhatif(name1, str1); classE1_1.glngwid = newwhatifid; classE1_1.saveWid(); classE1_1.model_modified = -1; classE1_1.saveModel_modified(); classE1_1.dowhatif_all_start(); // start a new whatif Master.PassCurrentWhatifName(name1); Master.SetCurrentWhatifLabel(); WriteTableValuesToDb(); } else { WriteTableValuesToDb(); } } else // in whatif now { if (RadioButtonList3.Items[0].Selected) { //savewehatif classE1_1.dowhatif_all_end(); classE1_1.SaveWhatIfAudit(classE1_1.glngwid); } if (RadioButtonList2.Items[1].Selected) { //close whatif, start new whatif if (name1.Length == 0) { classE1_1.Close(); Master.ShowErrorMessage("Invalid name for the new What-If Scenario. Please enter a name for the optimization What-If Scenario to be created."); DeleteRunFile(); DbUse.RunMysql("DELETE usercalc.* FROM usercalc INNER JOIN userlist ON usercalc.id = userlist.id WHERE userlist.sessionid = '" + HttpContext.Current.Session.SessionID + "';"); logFiles.RunEndLog(); return; } if (WhatifExists(name1)) { classE1_1.Close(); Master.ShowErrorMessage("A What-If Scenario with the same name already exists. Please choose a different name."); DeleteRunFile(); DbUse.RunMysql("DELETE usercalc.* FROM usercalc INNER JOIN userlist ON usercalc.id = userlist.id WHERE userlist.sessionid = '" + HttpContext.Current.Session.SessionID + "';"); logFiles.RunEndLog(); return; } // get out of old whatif ... classE1_1.LoadBaseCase(); classE1_1.model_modified = -1; classE1_1.saveModel_modified(); // start whatif // add new whatif , get into it newwhatifid = classE1_1.addnewwhatif(name1, str1); classE1_1.glngwid = newwhatifid; classE1_1.saveWid(); classE1_1.model_modified = -1; classE1_1.saveModel_modified(); str1 = "UPDATE zstblwhatifaudit SET zstblwhatifaudit.WID = " + newwhatifid + ";"; classE1_1.runsql(str1); classE1_1.dowhatif_all_start(); Master.PassCurrentWhatifName(name1); Master.SetCurrentWhatifLabel(); SetCalculationLabels(); } WriteTableValuesToDb(); } if (CalcClass.CalculationsCancelled(HttpContext.Current.Session.SessionID)) { classE1_1.Close(); DeleteRunFile(); DbUse.RunMysql("DELETE usercalc.* FROM usercalc INNER JOIN userlist ON usercalc.id = userlist.id WHERE userlist.sessionid = '" + HttpContext.Current.Session.SessionID + "';"); logFiles.RunEndLog(); Master.ShowInfoMessage("Value Stream Modeling optimization cancelled."); return; } classE1_1.runsqlado("UPDATE zs0tblWhatif SET display = -1 WHERE WID = " + classE1_1.glngwid + ";"); // base line run ... classE1_1.calc_return = 0; ret1 = classE1_1.RunDLL(); if (ret1 == 0) { // problem in dll run str1 = do_calc_msg(classE1_1.calc_return, 1); string resultsMessage = str1; string errorsMessage = GetErrorMessage(); save_errors_results(resultsMessage, errorsMessage); MPXRunChoices.SetActiveView(viewResults); SetActiveView(2); /* todaytoday if ... public const short LAB_OVER_U = 1; * public const short EQ_OVER_U = 2; * show .... * */ txtResults.Text = resultsMessage + DbUse.toRedColor(" You need to fix the errors before starting optimization."); txtErrors.Text = errorsMessage; pnlResults.Visible = true; pnlErrors.Visible = !errorsMessage.Trim().Equals(String.Empty); classE1_1.Close(); DeleteRunFile(); DbUse.RunMysql("DELETE usercalc.* FROM usercalc INNER JOIN userlist ON usercalc.id = userlist.id WHERE userlist.sessionid = '" + HttpContext.Current.Session.SessionID + "';"); logFiles.RunEndLog(); return; } //-------------------------------------------------------------- str1 = do_baseline_opt_msg(classE1_1.calc_return); if (str1.Length > 0) { // "warn user about problem - not in allowed area"; //Button38.Enabled = false; // .ViewStateMode; // = Disabled; TextBox22.Rows = 8; TextBox22.Height = 128; //TextBox22.Visible = true; //Buttonr4_exe2.Visible = true; TextBox22.Text = str1; // Lucie commmented out 11-3-14 /*if (classE1_1.glngwid != 0) { * classE1_1.LoadBaseCase(); * classE1_1.dowhatif_all_start(); * * Master.PassCurrentWhatifName(""); * Master.SetCurrentWhatifLabel(); * }*/ classE1_1.Close(); MPXRunChoices.SetActiveView(PageR1); SetActiveView(0); Master.ShowErrorMessage(str1); DeleteRunFile(); DbUse.RunMysql("DELETE usercalc.* FROM usercalc INNER JOIN userlist ON usercalc.id = userlist.id WHERE userlist.sessionid = '" + HttpContext.Current.Session.SessionID + "';"); logFiles.RunEndLog(); return; } val1 = get_opt_value(); // value of J at start ... if (val1 <= 0.0) { str1 = "current WIP value = 0, no optimization can be done."; TextBox22.Rows = 2; TextBox22.Height = 128; //TextBox22.Visible = true; //Buttonr4_exe2.Visible = true; TextBox22.Text = str1; classE1_1.Close(); MPXRunChoices.SetActiveView(PageR1); SetActiveView(0); Master.ShowErrorMessage("Optimization cancelled because current WIP value is 0. Production must be achieved before starting optimization."); DeleteRunFile(); DbUse.RunMysql("DELETE usercalc.* FROM usercalc INNER JOIN userlist ON usercalc.id = userlist.id WHERE userlist.sessionid = '" + HttpContext.Current.Session.SessionID + "';"); logFiles.RunEndLog(); return; } if (CalcClass.CalculationsCancelled(HttpContext.Current.Session.SessionID)) { classE1_1.Close(); DeleteRunFile(); DbUse.RunMysql("DELETE usercalc.* FROM usercalc INNER JOIN userlist ON usercalc.id = userlist.id WHERE userlist.sessionid = '" + HttpContext.Current.Session.SessionID + "';"); logFiles.RunEndLog(); Master.ShowInfoMessage("Value Stream Modeling optimization cancelled."); return; } long lastTime = currTime; currTime = DateTime.Now.Ticks; long timePerCalc = currTime - lastTime; DbUse.RunMysql("UPDATE usercalc INNER JOIN userlist ON usercalc.id = userlist.id SET calc = 2, lastCheck = " + currTime + ", timePerCalc = " + timePerCalc + " WHERE userlist.sessionid = '" + HttpContext.Current.Session.SessionID + "';"); //classA.Opt(long numberOfParts, long *partid, float * weight, long * optimizeLotSize, long * OptimizeTbatch, float * lotsizeValue, float * tbatchValue) classE1_1.do_opt(); string popupResult = "Lot size optimization has finished. Original WIP value was " + Convert.ToString(classE1_1.dig_round(val1, 4)) + "."; str1 = do_calc_msg(classE1_1.calc_return, 1); str1 += "<br/><br/> Original WIP value was " + Convert.ToString(classE1_1.dig_round(val1, 4)) + "."; val2 = get_opt_value(); // value of J at start ... str1 += "<br/> New WIP value is " + Convert.ToString(classE1_1.dig_round(val2, 4)) + "."; popupResult += " New WIP value is " + Convert.ToString(classE1_1.dig_round(val2, 4)) + "."; val3 = 100 * (val1 - val2) / val1; if (Math.Abs(val3) < 0.1) { val3 = 0.0; } str1 += "<br/><br/> Change in WIP value is " + classE1_1.dig_round(val3, 3) + " % decrease."; popupResult += " Change in WIP value is " + classE1_1.dig_round(val3, 3) + " % decrease."; MPXRunChoices.SetActiveView(viewResults); SetActiveView(2); string msgResults = str1; txtResults.Text = msgResults; save_errors_results(msgResults, ""); pnlResults.Visible = true; pnlErrors.Visible = false; Master.ShowInfoMessage(popupResult); } catch (Exception ex) { logFiles.ErrorLog(ex); Master.ShowErrorMessage("MPX internal error has occured. "); } finally { classE1_1.Close(); DeleteRunFile(); DbUse.RunMysql("DELETE usercalc.* FROM usercalc INNER JOIN userlist ON usercalc.id = userlist.id WHERE userlist.sessionid = '" + HttpContext.Current.Session.SessionID + "';"); logFiles.RunEndLog(); } /* long all lotsize and demand range * * start * setup whatif family for the whole ... * * loop lot size * do range for 1 paert * do loop for next part in dataset . * no more * * * start * demand loop * do range for 1 part * do loop for next part in recordset * no more ? * * do whatif new (name + number) * rundll */ /* start with just 1 part demand and lot size * * * string whatif_family; * int whatiffamily_no; * ADODB.Recordset recprod_d = null; * ADODB.Recordset recprod_l = null; * string prod_name_d; * string prod_name_l; * void strart_big_whatif() { * * string str1; * string str2; * str1= "delete zswhatif_prod _l"; * runsql(str1); * str1 = "delete zswhatif_prod_d"; * runsql(str1); * open_ado_rec(globaldb, ref recwhatif, "whatif - max family id"); * * * * * * open_ado_rec(global_db, ref recprod_l, "sdasda"); */ // xxx /* * * 2. The plan ?? * * * //doing the big whatif -- adding whatif glngwid issues * * //testing ... * // whatif reread all code and add whatif glngwid issues code ... * //do optmization stuff * * * * */ }
/* * 1. Add Error text box on results page before results table Done. * * 2. Add buttons to see results/errors page Done. * * 3. add zstblresults to mpxmdb.mdb (send me your copy of mpxmdb.mdb so I can also update the sort table) * * 4. After do_calc_msg * call * do_err_msg * save_errors_results ( msg1 from do_vcalc_msg, msg2 from do_err_msg) * * msg2 from do_err_msg goes into error tex box.... * hide warning/error text box if msg2 = null * * */ /* * * * ------------------------------------------------- * */ public string GetErrorMessage() { return(CalcClass.GetErrorMessage(classE1_1)); }
/// <summary> /// Обчислення зворотнього польського запису /// </summary> ///<returns>результат обчислень,або повідомлення про помилку</returns> public static string RunEstimate(ArrayList stack) { ArrayList temp = new ArrayList(); for (int i = 0; i < stack.Count; i++) { int number; if (Int32.TryParse(stack[i].ToString(), out number)) { if (Convert.ToInt64(stack[i]) < -2147483648 || Convert.ToInt64(stack[i]) > 2147483647) { //Дуже мале, або дуже велике значення числа для int. Числа повинні бути в межах від -2147483648 до 2147483647 ShowMessage = true; lastError = "Error 06"; return("Error 06"); } temp.Add(stack[i]); } else { double left = Convert.ToDouble(temp[temp.Count - 2]); double right = Convert.ToDouble(temp[temp.Count - 1]); temp.RemoveAt(temp.Count - 1); temp.RemoveAt(temp.Count - 1); switch (stack[i]) { case "+": temp.Add(CalcClass.Add(left, right).ToString()); break; case "-": temp.Add(CalcClass.Sub(left, right).ToString()); break; case "*": temp.Add(CalcClass.Mult(left, right).ToString()); break; case "/": if (right == 0) { ShowMessage = true; lastError = "Error 09"; return("Error 09"); } temp.Add(CalcClass.Div(left, right).ToString()); break; case "%": if (right == 0) { ShowMessage = true; lastError = "Error 09"; return("Error 09"); } temp.Add(CalcClass.Mod(left, right).ToString()); break; } } } expression = temp[0].ToString(); return(temp[0].ToString()); }
public static string RunEstimate() { /* string InputExpression = "2 2 - 33 * 11 - 5 6 + +"; * ICollection<string> listExpression; // = new List<string>(); * listExpression = InputExpression.Split(' ');*/ List <decimal> res = new List <decimal>(); foreach (string ie in InputExpression) { if (!(ie == "+" || ie == "-" || ie == "*" || ie == "/" || ie == "%" || ie == "m" || ie == "p")) { decimal r; if (Decimal.TryParse(ie, out r)) { res.Add(r); } else { ShowMessage = false; expression = "Error 07"; return(expression); } } else { switch (ie[0]) { case '+': res[res.Count - 2] = CalcClass.Add(res[res.Count - 2], res[res.Count - 1]); break; case '-': res[res.Count - 2] = CalcClass.Sub(res[res.Count - 2], res[res.Count - 1]); break; case '*': res[res.Count - 2] = CalcClass.Mult(res[res.Count - 2], res[res.Count - 1]); break; case '/': res[res.Count - 2] = CalcClass.Div(res[res.Count - 2], res[res.Count - 1]); break; case '%': res[res.Count - 2] = CalcClass.Mod(res[res.Count - 2], res[res.Count - 1]); break; case 'm': res[res.Count - 1] = CalcClass.IABS(res[res.Count - 1]); break; case 'p': res[res.Count - 1] = (res[res.Count - 1]); break; } if (CalcClass.isError) { expression = CalcClass._lastError; ShowMessage = false; return(expression); } if (ie[0] != 'm' && ie[0] != 'p') { res.RemoveAt(res.Count - 1); } } } expression = res[0].ToString(); return(expression); }