private void button1_Click(object sender, EventArgs e) { Results.Clear(); int stalls = sim.TB.stalls; Results.AppendText("Type of Cache used:\tTWO BIT BRANCH PREDICTOR"); Results.AppendText(Environment.NewLine); Results.AppendText(sim.TB.stallstring); Results.AppendText(Environment.NewLine + Environment.NewLine); Results.AppendText("Stalls due to mispredicted branch instructions: \t" + stalls); Results.AppendText(Environment.NewLine + "Cost in Cycles:\t" + stalls / 2); Results.AppendText(Environment.NewLine + "Cost in Nano Seconds:\t" + (stalls / 2) * 9); }
private void Search2_Click(object sender, EventArgs e) { connection.Open(); string phone = TxtPrphone.Text; cmd = new SqlCommand("select * From Provider where Phone = '" + phone + "' ", connection); All_Data = cmd.ExecuteReader(); while (All_Data.Read()) { Results.AppendText("Provider Name : " + All_Data["Pr_Name"].ToString() + Environment.NewLine); Results.AppendText("Provider Number : " + All_Data["Pr_Num"].ToString() + Environment.NewLine); Results.AppendText("Provider Phone : " + All_Data["Phone"].ToString() + Environment.NewLine); Results.AppendText("Provider Mail : " + All_Data["Mail"].ToString() + Environment.NewLine); } All_Data.Close(); connection.Close(); }
private void mainBtn(object sender, EventArgs e) { Results.Clear(); Results.AppendText("Pipelined processor design"); Results.AppendText(Environment.NewLine); Results.AppendText("Clock Period = 9 nano seconds"); Results.AppendText(Environment.NewLine); Results.AppendText("Total cycles to sort the number set: " + sim.TotalCycles); Results.AppendText(Environment.NewLine); Results.AppendText("Cycles due to mispredicted branch instructions: " + (sim.TB.stalls / 2)); Results.AppendText(Environment.NewLine); Results.AppendText("Total time to finish the sort: " + sim.TimeSpan + " nano seconds"); Results.AppendText(Environment.NewLine); Results.AppendText("CPI:\t" + sim.CPI); Results.AppendText(Environment.NewLine); }
private void Search_Click(object sender, EventArgs e) { connection.Open(); string SSN = TxtEmpSSN.Text; cmd = new SqlCommand("select * From Employee where SSN = " + Convert.ToInt32(SSN) + " ", connection); All_Data = cmd.ExecuteReader(); while (All_Data.Read()) { Results.AppendText("Employee SSN : " + All_Data["SSN"].ToString() + Environment.NewLine); Results.AppendText("Employee Name : " + All_Data["E_Name"].ToString() + Environment.NewLine); Results.AppendText("Employee Gender : " + All_Data["Gender"].ToString() + Environment.NewLine); Results.AppendText("Employee Birth Date : " + All_Data["B_Date"].ToString() + Environment.NewLine); Results.AppendText("Employee Phone : " + All_Data["Phone_num"].ToString() + Environment.NewLine); Results.AppendText("Employee Mail : " + All_Data["mail"].ToString() + Environment.NewLine); Results.AppendText("Employee Address : " + All_Data["Address"].ToString() + Environment.NewLine); Results.AppendText("Employee Job Title : " + All_Data["Job_Title"].ToString() + Environment.NewLine); Results.AppendText("Employee Branch Number : " + All_Data["Br_num"].ToString() + Environment.NewLine); Results.AppendText("Employee Salary : " + All_Data["Salary"].ToString() + Environment.NewLine); } All_Data.Close(); connection.Close(); }
private async void Process_Click(object sender, EventArgs e) { // Enable Buttons Process.Enabled = false; // Variables int SentimentID = 1; int SentenceID = 1; int KeyPhraseID = 1; int FileTotalLines = 0; int ProcessTotalErrors = 0; int ProgressIncAmt = 0; string InputFileTextLine; string[] InputFileSentences; string JSONCallString = ""; string JSONCallResponse = ""; string ResultLine; string ResultScore; string ResultKeyPhrases; string ResultKeyPhrasesListSring; string ResultErrors; string ResultErrorsListString; string strnow = DateTime.Now.ToString("yyyyMMddHHmmss"); string FileLine; string FileName_Sentiment = OutputFile.Text + "\\AzureTextAPI_SentimentText_" + strnow + ".txt"; string FileName_Phrases = OutputFile.Text + "\\AzureTextAPI_KeyPhrasesText_" + strnow + ".txt"; string FileName_Sentence = OutputFile.Text + "\\AzureTextAPI_SentenceText_" + strnow + ".txt"; List <string> ResultErrorsList; List <string> ResultKeyPhrasesList; JObject JSONObject; byte[] byteData; // Clear Text Box Results.Text = ""; // Set progress to 0% ProgressBar.Value = 0; PctComplete.Text = ProgressBar.Value.ToString() + "%"; Results.AppendText("Process Starting." + Environment.NewLine); Results.AppendText(Environment.NewLine); try { // Read Source file and get max lines System.IO.StreamReader file = new System.IO.StreamReader(SourceFile.Text); FileTotalLines = System.IO.File.ReadLines(SourceFile.Text).Count(); // Set Progress Bar ProgressIncAmt = 100 / (FileTotalLines + 2); // Create 3x New Output Files and Write File Headers System.IO.StreamWriter streamWriter_Sentiment = new System.IO.StreamWriter(FileName_Sentiment); System.IO.StreamWriter streamWriter_Phrases = new System.IO.StreamWriter(FileName_Phrases); System.IO.StreamWriter streamWriter_Sentence = new System.IO.StreamWriter(FileName_Sentence); FileLine = "SentimentTextID" + "\t" + "SentimentTextLine" + "\t" + "SentimentTextScore"; streamWriter_Sentiment.WriteLine(FileLine); FileLine = "SentimentTextID" + "\t" + "SentenceTextID" + "\t" + "SentenceTextLine" + "\t" + "SentenceTextScore"; streamWriter_Sentence.WriteLine(FileLine); FileLine = "SentimentTextID" + "\t" + "KeyPhraseTextID" + "\t" + "KeyPhraseTextLine"; streamWriter_Phrases.WriteLine(FileLine); ////////// START SENTIMENT PROCESS ////////// Results.AppendText("Using Azure Cognitive API [" + TextAPIBaseURL.Text + TextAPIVersion.Text + "]." + Environment.NewLine); Results.AppendText(Environment.NewLine); ProgressBar.Value = ProgressBar.Value + ProgressIncAmt; PctComplete.Text = ProgressBar.Value.ToString() + "%"; using (var client = new HttpClient()) { client.BaseAddress = new Uri(TextAPIBaseURL.Text); // API Request Headers client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", APIKey.Text); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // Display process line by line while ((InputFileTextLine = file.ReadLine()) != null) { // Remove double blanks, trim end of line if (cbTrim.Checked == true) { InputFileTextLine = InputFileTextLine.Replace(" ", " "); InputFileTextLine = InputFileTextLine.Trim(); } // Replace TABS in Parse Text if (cbReplaceTab.Checked == true) { if (cbTAB.SelectedIndex == 0) { InputFileTextLine = InputFileTextLine.Replace("\t", " "); } if (cbTAB.SelectedIndex == 1) { InputFileTextLine = InputFileTextLine.Replace("\t", ", "); } } // Remove Hastags if (cbHashtag.Checked == true) { InputFileTextLine = Regex.Replace(InputFileTextLine, @"#\S+ *", string.Empty); } // Remove URLs if (cbURL.Checked == true) { InputFileTextLine = Regex.Replace(InputFileTextLine, @"((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)", string.Empty); } // Truncate Text to 10K (maximum document size for TEXT API) if (cb1500.Checked == true) { //Console.WriteLine(System.Text.ASCIIEncoding.Unicode.GetByteCount(InputFileTextLine)); // <-- For debugging use. if (System.Text.ASCIIEncoding.Unicode.GetByteCount(InputFileTextLine) > 10000) { InputFileTextLine = Truncate(InputFileTextLine, 10000); } } ResultLine = "Reading File Text Line [ID: " + SentimentID + "]: " + InputFileTextLine; Results.AppendText(ResultLine + Environment.NewLine); if (InputFileTextLine.Trim() != "") // not a blank line { // Define Base JSON Call Request body used for both Sentiment and Key Phrases JSONCallString = "{\"documents\":[{\"id\":\"" + SentimentID + "\",\"text\":\"" + InputFileTextLine.Replace("\"", "") + "\"}]}"; byteData = Encoding.UTF8.GetBytes(JSONCallString); // KEY PHRASES if (rbKeyPhrases.Checked == true) { ResultLine = "Detecting Text Line Key Phrases..."; Results.AppendText(ResultLine + Environment.NewLine); JSONCallResponse = await CallEndpoint(client, TextAPIBaseURL.Text + TextAPIVersion.Text + "keyPhrases", byteData); JSONObject = JObject.Parse(JSONCallResponse); ResultErrors = (JSONObject["errors"]).ToString(); ResultErrorsList = JsonConvert.DeserializeObject <List <string> >(ResultErrors); ResultErrorsListString = string.Join(", ", ResultErrorsList.ToArray()); if (ResultErrorsListString != "") { ResultLine = "### ERROR ### [" + ResultErrorsListString + "]"; Results.AppendText(ResultLine + Environment.NewLine); KeyPhraseID++; ProcessTotalErrors++; } else { ResultKeyPhrases = (JSONObject["documents"][0]["keyPhrases"]).ToString(); ResultKeyPhrasesList = JsonConvert.DeserializeObject <List <string> >(ResultKeyPhrases); ResultKeyPhrasesListSring = string.Join(", ", ResultKeyPhrasesList.ToArray()); foreach (var ListItem in ResultKeyPhrasesList) { KeyPhraseID++; //Write to File FileLine = SentimentID.ToString() + "\t" + KeyPhraseID.ToString() + "\t" + ListItem; streamWriter_Phrases.WriteLine(FileLine); } ResultLine = "Key Phrases [" + ResultKeyPhrasesListSring + "]"; Results.AppendText(ResultLine + Environment.NewLine); } } // SENTIMENT - FULL TEXT if (rbSentiment.Checked == true) { ResultLine = "Detecting Text Line Sentiment..."; Results.AppendText(ResultLine + Environment.NewLine); JSONCallResponse = await CallEndpoint(client, TextAPIBaseURL.Text + TextAPIVersion.Text + "sentiment", byteData); JSONObject = JObject.Parse(JSONCallResponse); ResultErrors = (JSONObject["errors"]).ToString(); ResultErrorsList = JsonConvert.DeserializeObject <List <string> >(ResultErrors); ResultErrorsListString = string.Join(", ", ResultErrorsList.ToArray()); if (ResultErrorsListString != "") { ResultLine = "### ERROR ### [" + ResultErrorsListString + "]"; Results.AppendText(ResultLine + Environment.NewLine); ProcessTotalErrors++; } else { ResultScore = JSONObject["documents"][0]["score"].ToString(); ResultLine = "Sentiment [" + ResultScore + "]"; Results.AppendText(ResultLine + Environment.NewLine); //Write to File FileLine = SentimentID.ToString() + "\t" + InputFileTextLine + "\t" + ResultScore; streamWriter_Sentiment.WriteLine(FileLine); } // Split into Sentences if (cbSplit.Checked == true) { ResultLine = "Splitting Text Line into Sentences ..."; Results.AppendText(ResultLine + Environment.NewLine); InputFileSentences = Regex.Split(InputFileTextLine, @"(?<=[\w\s](?:[\.\!\? ]+[\x20]*[\x22\xBB]*))(?:\s+(?![\x22\xBB](?!\w)))"); foreach (var Sentence in InputFileSentences) { ResultLine = "Reading Sentence Text Line [ID: " + SentimentID + "." + SentenceID + "]: " + Sentence; Results.AppendText(ResultLine + Environment.NewLine); // Define JSON Call Request body JSONCallString = "{\"documents\":[{\"id\":\"" + SentimentID + "\",\"text\":\"" + Sentence.Replace("\"", "") + "\"}]}"; byteData = Encoding.UTF8.GetBytes(JSONCallString); // SENTIMENT - SENTENCE TEXT ResultLine = "Detecting Sentiment in Sentence..."; Results.AppendText(ResultLine + Environment.NewLine); JSONCallResponse = await CallEndpoint(client, TextAPIBaseURL.Text + TextAPIVersion.Text + "sentiment", byteData); JSONObject = JObject.Parse(JSONCallResponse); ResultErrors = (JSONObject["errors"]).ToString(); ResultErrorsList = JsonConvert.DeserializeObject <List <string> >(ResultErrors); ResultErrorsListString = string.Join(", ", ResultErrorsList.ToArray()); if (ResultErrorsListString != "") { ResultLine = "### ERROR ### [" + ResultErrorsListString + "]"; Results.AppendText(ResultLine + Environment.NewLine); ProcessTotalErrors++; } else { ResultScore = JSONObject["documents"][0]["score"].ToString(); ResultLine = "Sentence Sentiment [" + ResultScore + "]"; Results.AppendText(ResultLine + Environment.NewLine); //Write to File FileLine = SentimentID.ToString() + "\t" + SentenceID.ToString() + "\t" + Sentence + "\t" + ResultScore; streamWriter_Sentence.WriteLine(FileLine); } SentenceID++; } } } } else // blank line in file { //Write BLANK to File FileLine = SentimentID.ToString() + "\t" + "" + "\t" + ""; streamWriter_Sentiment.WriteLine(FileLine); } SentimentID++; Results.AppendText(Environment.NewLine); ProgressBar.Value = ProgressBar.Value + ProgressIncAmt; PctComplete.Text = ProgressBar.Value.ToString() + "%"; } file.Close(); } // Increase Progress Bar ProgressBar.Value = ProgressBar.Value + ProgressIncAmt; PctComplete.Text = ProgressBar.Value.ToString() + "%"; // Close Output Files streamWriter_Sentiment.Close(); streamWriter_Sentence.Close(); streamWriter_Phrases.Close(); Results.AppendText(Environment.NewLine); Results.AppendText("Write Sentiment File [" + FileName_Sentiment + "]." + Environment.NewLine); Results.AppendText(Environment.NewLine); Results.AppendText("Write Sentence File [" + FileName_Sentence + "]." + Environment.NewLine); Results.AppendText(Environment.NewLine); Results.AppendText("Write Key Phrases File [" + FileName_Phrases + "]." + Environment.NewLine); // Set progress to 100% Results.AppendText(Environment.NewLine); Results.AppendText("Process Completed. [" + SentimentID.ToString() + "] Text Lines Processed. [" + ProcessTotalErrors.ToString() + "] Errors." + Environment.NewLine); ProgressBar.Value = 100; PctComplete.Text = ProgressBar.Value.ToString() + "%"; } catch (Exception ex) { MessageBox.Show("A processing error occured." + "\n" + "Last Error Message: " + ex.Message + "\n" + "Last API Response: " + JSONCallResponse.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } Process.Enabled = true; //System.Diagnostics.Process.Start("explorer.exe", OutputFile.Text); }
private void Calculation_Click(object sender, RoutedEventArgs e) { bool go = true; while (IsNotRotating.IsChecked == true && go == true) { double[] Inst = new double[7]; double temp; try { temp = Convert.ToDouble(Coef_of_exp.GetLineText(0)); if (temp < 0.000002 || temp > 0.00144) { throw new FormatException(); } Inst[0] = temp; } catch (FormatException) { MessageBox.Show("Значение Коэффициента линейного расширения ролика должно находиться в пределах от 0,000002 до 0,00144"); Coef_of_exp.Clear(); Coef_of_exp.Focus(); go = false; break; } try { temp = Convert.ToDouble(Width_of_slab.GetLineText(0)); if (temp > 5000 || temp < 350) { throw new FormatException(); } Inst[1] = temp; } catch (FormatException) { MessageBox.Show("Значение ширины сляба должно находиться в диапазоне от 350 до 5000"); Width_of_slab.Clear(); Width_of_slab.Focus(); go = false; break; } try { temp = Convert.ToDouble(Lenght_of_roller.GetLineText(0)); if (temp > 10000 || temp < 1000) { throw new FormatException(); } Inst[2] = temp; } catch (FormatException) { MessageBox.Show("Значение длины ролика должно находиться в диапазоне от 1000 до 10000"); Lenght_of_roller.Clear(); Lenght_of_roller.Focus(); go = false; break; } try { temp = Convert.ToDouble(Inner_radius.GetLineText(0)); if (temp > 75 || temp < 0) { throw new FormatException(); } Inst[3] = temp; } catch (FormatException) { MessageBox.Show("Значение внутреннего радиуса ролика должно находиться в диапазоне от 0 (Ролик сплошной) до 75 мм"); Inner_radius.Clear(); Inner_radius.Focus(); go = false; break; } try { temp = Convert.ToDouble(Outer_radius.GetLineText(0)); if (temp > 300 || temp < 70) { throw new FormatException(); } Inst[4] = temp; } catch (FormatException) { MessageBox.Show("Значение внешнего радиуса ролика должно находиться в диапазоне от 70 до 300 мм"); Outer_radius.Clear(); Outer_radius.Focus(); go = false; break; } try { temp = Convert.ToDouble(Coef_of_Fourier_q1.GetLineText(0)); if (temp > 100 || temp < 80) { throw new FormatException(); } Inst[5] = temp; } catch (FormatException) { MessageBox.Show("Значение коэффициента Фурье должно находиться в диапазоне от 80 до 100"); Coef_of_Fourier_q1.Clear(); Coef_of_Fourier_q1.Focus(); go = false; break; } try { temp = Convert.ToDouble(Coef_of_Fourier_q2.GetLineText(0)); if (temp > 27 || temp < 22) { throw new FormatException(); } Inst[6] = temp; } catch (FormatException) { MessageBox.Show("Значение коэффициента Фурье должно находиться в диапазоне от 22 до 27"); Coef_of_Fourier_q2.Clear(); Coef_of_Fourier_q2.Focus(); go = false; break; } rot = new NonRotating(Inst); go = false; Results.Clear(); Results.AppendText(rot.Show()); Constituent_W.Clear(); Constituent_W.AppendText(rot.ShowW()); Constituent_V.Clear(); Constituent_V.AppendText(rot.ShowV()); } while (IsRotating.IsChecked == true && go == true) { double[] Inst = new double[6]; double temp, newtemp; try { temp = Convert.ToDouble(Coef_of_exp.GetLineText(0)); if (temp < 0.000002 || temp > 0.00144) { throw new FormatException(); } Inst[0] = temp; } catch (FormatException) { MessageBox.Show("Значение Коэффициента линейного расширения ролика должно находиться в пределах от 0,000002 до 0,00144"); Coef_of_exp.Clear(); Coef_of_exp.Focus(); go = false; break; } try { temp = Convert.ToDouble(Width_of_slab.GetLineText(0)); if (temp > 5000 || temp < 350) { throw new FormatException(); } Inst[1] = temp; } catch (FormatException) { MessageBox.Show("Значение ширины сляба должно находиться в диапазоне от 350 до 5000"); Width_of_slab.Clear(); Width_of_slab.Focus(); go = false; break; } try { temp = Convert.ToDouble(Lenght_of_roller.GetLineText(0)); if (temp > 10000 || temp < 1000) { throw new FormatException(); } Inst[2] = temp; } catch (FormatException) { MessageBox.Show("Значение длины ролика должно находиться в диапазоне от 1000 до 10000"); Lenght_of_roller.Clear(); Lenght_of_roller.Focus(); go = false; break; } try { temp = Convert.ToDouble(Inner_radius.GetLineText(0)); if (temp != 0 && temp != 37.5 && temp != 45.0 && temp != 75.0) { throw new FormatException(); } Inst[3] = temp; } catch (FormatException) { MessageBox.Show("Значение внутреннего радиуса ролика может принимать значения:\n" + "0.0 при внешем радиусе 70.0 мм, 90.0 мм, 107.5 мм, 120.5 мм\n" + "37.5 мм при внешнем радуису 135.0 мм\n" + "45.0 мм при внешнем радуису 165.0 мм\n" + "75.0 мм при внешнем радуису 240.0 мм и 300.0 мм"); Inner_radius.Clear(); Inner_radius.Focus(); go = false; break; } try { newtemp = Convert.ToDouble(Outer_radius.GetLineText(0)); switch (temp) { case 0.0: if (newtemp != 70.0 && newtemp != 90 && newtemp != 107.5 && newtemp != 120.5) { throw new FormatException(); } Inst[4] = newtemp; break; case 37.5: if (newtemp != 135.0) { throw new FormatException(); } Inst[4] = newtemp; break; case 45: if (newtemp != 165.0) { throw new FormatException(); } Inst[4] = newtemp; break; case 75: if (newtemp != 240.0 && newtemp != 300.0) { throw new FormatException(); } Inst[4] = newtemp; break; default: throw new FormatException(); } } catch (FormatException) { MessageBox.Show("Значение внешнего радиуса ролика может принимать значения:\n" + "70.0 мм, 90.0 мм, 107.5 мм, 120.5 мм при внутреннем радиусе 0.0 мм\n" + "135.0 мм при внутреннем радиусе 37.5 мм\n" + "165.0 мм при внутреннем радиусе 45.0 мм\n" + "240.0 мм и 300.0 мм при внутреннем радиусе 75.0 мм"); Outer_radius.Clear(); Outer_radius.Focus(); go = false; break; } try { temp = Convert.ToDouble(Speed_of_stream.GetLineText(0)); if (temp > 5 || temp < 0.2) { throw new FormatException(); } Inst[5] = temp; } catch (FormatException) { MessageBox.Show("Значение скорости разливки должно находиться в диапазоне 0.2 до 5"); Speed_of_stream.Clear(); Speed_of_stream.Focus(); go = false; break; } rot = new Rotating(Inst); go = false; Results.Clear(); Results.AppendText(rot.Show()); Constituent_W.Clear(); Constituent_W.AppendText(rot.ShowW()); Constituent_V.Clear(); Constituent_V.AppendText(rot.ShowV()); } }