Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.11 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using System.Drawing.Drawing2D;
  12. using System.Windows.Forms.DataVisualization.Charting;
  13.  
  14.  
  15. namespace Projekt3_Gwiazdowski51192
  16. {
  17. public partial class Analizator : Form
  18. {
  19. public Analizator()
  20. {
  21. InitializeComponent();
  22. }
  23.  
  24. bool PKpobranieWynik(out float PKx, out float PKepsX)
  25. {
  26. float PKgranXd = -1.0F;
  27. float PKgranXg = 1.0F;
  28.  
  29. float PKgranEpsXd = 0.0F;
  30. float PKgranEpsXg = 1.0F;
  31.  
  32.  
  33. PKx = 0.0F; PKepsX = 0.0F;
  34.  
  35.  
  36. if (string.IsNullOrEmpty(txtX.Text) || !float.TryParse(txtX.Text, out PKx))
  37. {
  38.  
  39. errorProvider1.SetError(txtX, "Podaj poprawną wartość X");
  40. return false;
  41. }
  42. else
  43. {
  44. errorProvider1.Dispose();
  45. }
  46.  
  47.  
  48. if (PKgranXd > PKx || PKx >= PKgranXg)
  49. {
  50. errorProvider1.SetError(txtX, "X musi spełniać wyznaczone warunki!");
  51. return false;
  52. }
  53. else
  54. {
  55. errorProvider1.Dispose();
  56. }
  57. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  58.  
  59. if (string.IsNullOrEmpty(txtEpsX.Text) || !float.TryParse(txtEpsX.Text, out PKepsX))
  60. {
  61.  
  62. errorProvider1.SetError(txtEpsX, "Wartość EpsX wykracza poza wytyczne");
  63. return false;
  64. }
  65.  
  66.  
  67. if (PKgranEpsXd >= PKepsX || PKepsX >= PKgranEpsXg)
  68. {
  69. errorProvider1.SetError(txtEpsX, "Wartość wykracza poza granice");
  70. return false;
  71. }
  72.  
  73. else
  74. {
  75. errorProvider1.Dispose();
  76. }
  77.  
  78.  
  79. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  80. return true;
  81. }
  82.  
  83. bool PKpobranieTabela(out float PKxd, out float PKxg, out float PKh, out float PKepsXdlaTablicy)
  84. {
  85. float PKgranHd = 0.0F;
  86. float PKgranHg = 1.0F;
  87. PKxd = 0.0F;
  88. PKxg = 0.0F;
  89. PKh = 0.0F;
  90. PKepsXdlaTablicy = 0.0F;
  91.  
  92. if (string.IsNullOrEmpty(txtXd.Text) || !float.TryParse(txtXd.Text, out PKxd))
  93. {
  94.  
  95. errorProvider1.SetError(txtXd, "Wartość Xd wykracza poza wytyczne");
  96. return false;
  97. }
  98.  
  99. else
  100. {
  101. errorProvider1.Dispose();
  102. }
  103.  
  104. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  105.  
  106. if (string.IsNullOrEmpty(txtXg.Text) || !float.TryParse(txtXg.Text, out PKxg))
  107. {
  108.  
  109. errorProvider1.SetError(txtXg, "Wartość Xg wykracza poza wytyczne");
  110. return false;
  111. }
  112.  
  113.  
  114. if (PKxg < PKxd)
  115. {
  116. errorProvider1.SetError(txtXg, "Xg nie może być mniejsze niż Xd");
  117. return false;
  118. }
  119.  
  120. else
  121. {
  122. errorProvider1.Dispose();
  123. }
  124.  
  125.  
  126. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  127.  
  128. if (string.IsNullOrEmpty(txtH.Text) || !float.TryParse(txtH.Text, out PKh))
  129. {
  130.  
  131. errorProvider1.SetError(txtH, "Wartość H wykracza poza wytyczne");
  132. return false;
  133. }
  134.  
  135. if (PKgranHd >= PKh || PKh >= PKgranHg)
  136. {
  137. errorProvider1.SetError(txtH, "H nie spełnia reguł zadania");
  138. return false;
  139. }
  140.  
  141. else
  142. {
  143. errorProvider1.Dispose();
  144. }
  145. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  146. float PKgranEpsXdt = 0.0F;
  147. float PKgranEpsXgt = 1.0F;
  148.  
  149. if (string.IsNullOrEmpty(txtEpsTablica.Text) || !float.TryParse(txtEpsTablica.Text, out PKepsXdlaTablicy))
  150. {
  151.  
  152. errorProvider1.SetError(txtEpsTablica, "Wartość EpsX wykracza poza wytyczne");
  153. return false;
  154. }
  155.  
  156.  
  157. if (PKepsXdlaTablicy <= PKgranEpsXdt || PKepsXdlaTablicy >= PKgranEpsXgt)
  158. {
  159.  
  160.  
  161. errorProvider1.SetError(txtEpsTablica, "Wartość wykracza poza granice");
  162. return false;
  163. }
  164.  
  165. else
  166. {
  167. errorProvider1.Dispose();
  168. }
  169.  
  170.  
  171. return true;
  172. }
  173.  
  174. bool PKpobranieCalka(out float PKepsCalka, out float PKcd, out float PKcg, out float PKdokladnosc)
  175. {
  176. float PKgranEpsXdCalka = 0.0F;
  177. float PKgranEpsXgCalka = 1.0F;
  178. float PKgranCd = -1.0F;
  179. float PKgranCg = 1.0F;
  180.  
  181. PKepsCalka = 0.0F; PKcd = 0.0F; PKcg = 0.0F; PKdokladnosc = 0.0F;
  182.  
  183. if (string.IsNullOrEmpty(txtEpsCalka.Text) || !float.TryParse(txtEpsCalka.Text, out PKepsCalka))
  184. {
  185.  
  186. errorProvider1.SetError(txtEpsCalka, "Wartość EpsX wykracza poza wytyczne");
  187. return false;
  188. }
  189.  
  190.  
  191. if (PKepsCalka <= PKgranEpsXdCalka || PKepsCalka >= PKgranEpsXgCalka)
  192. {
  193. errorProvider1.SetError(txtEpsCalka, "Wartość wykracza poza granice");
  194. return false;
  195. }
  196.  
  197. else
  198. {
  199. errorProvider1.Dispose();
  200. }
  201.  
  202.  
  203. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  204.  
  205. if (string.IsNullOrEmpty(txtCD.Text) || !float.TryParse(txtCD.Text, out PKcd))
  206. {
  207.  
  208. errorProvider1.SetError(txtCD, "Wartość dolnej granicy nie jest liczbą");
  209. return false;
  210. }
  211.  
  212. if (PKcd <= PKgranCd || PKcd >= PKgranCg)
  213. {
  214.  
  215. errorProvider1.SetError(txtCD, "Wartość nie jest w zakresie");
  216. return false;
  217. }
  218.  
  219. else
  220. {
  221. errorProvider1.Dispose();
  222. }
  223.  
  224. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  225.  
  226. if (string.IsNullOrEmpty(txtCG.Text) || !float.TryParse(txtCG.Text, out PKcg))
  227. {
  228.  
  229. errorProvider1.SetError(txtCG, "Wartość górnej granicy nie jest liczbą");
  230. return false;
  231. }
  232. if (PKgranCd >= PKcg || PKcg >= PKgranCg)
  233. {
  234.  
  235. errorProvider1.SetError(txtCD, "Wartość nie jest w zakresie");
  236. return false;
  237. }
  238.  
  239. if (PKcg < PKcd)
  240. {
  241. errorProvider1.SetError(txtCG, "Górna granica nie może być mniejsza niż dolna");
  242. return false;
  243. }
  244.  
  245. else
  246. {
  247. errorProvider1.Dispose();
  248. }
  249.  
  250.  
  251. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  252.  
  253. if (string.IsNullOrEmpty(txtDokladnosc.Text) || !float.TryParse(txtDokladnosc.Text, out PKdokladnosc))
  254. {
  255.  
  256. errorProvider1.SetError(txtDokladnosc, "Wartość dokładności nie jest liczbą");
  257. return false;
  258. }
  259.  
  260. if (PKdokladnosc <= PKgranEpsXdCalka || PKdokladnosc > PKgranEpsXgCalka)
  261. {
  262. errorProvider1.SetError(txtDokladnosc, "Wartość wykracza poza granice");
  263. return false;
  264. }
  265.  
  266. else
  267. {
  268. errorProvider1.Dispose();
  269. }
  270.  
  271. return true;
  272. }
  273.  
  274. float PKsumaSzeregu(float KGx, float PKepsX, out ushort KGlicznik)
  275. {
  276. float KGw, KGsuma;
  277.  
  278. KGlicznik = 1;
  279. KGw = (float)Math.Pow(KGx, (2 * (KGlicznik + 1))) / (2 * (KGlicznik + 1));
  280. KGsuma = 0.0F;
  281.  
  282.  
  283. do
  284. {
  285. KGsuma += KGw;
  286. KGlicznik++;
  287. KGw = KGw * (float)Math.Pow(KGx, (2 * (KGlicznik + 1))) / (2 * (KGlicznik + 1));
  288. } while (Math.Abs(KGw) > PKepsX);
  289. KGsuma = KGsuma * 2;
  290. return KGsuma;
  291. }
  292.  
  293. float PKtablicowanie(float PKxd, float PKxg, float PKh, float PKepsXdlaTablicy, out float[,] Tablica)
  294. {
  295. int ile = 0;
  296.  
  297. for (float i = PKxd; i <= PKxg; i += PKh)
  298. {
  299. ile++;
  300. }
  301.  
  302. Tablica = new float[ile, 3];
  303.  
  304.  
  305. for (int j = 0; j < Tablica.GetLength(0); j++)
  306. {
  307.  
  308.  
  309. Tablica[j, 0] = PKxd;
  310. Tablica[j, 1] = PKsumaSzeregu(PKxd, PKepsXdlaTablicy, out ushort PKlicznikTablica);
  311. Tablica[j, 2] = PKlicznikTablica;
  312.  
  313. PKxd = PKxd + PKh;
  314.  
  315. dgvTablicaSzeregu.Rows.Add();
  316.  
  317. dgvTablicaSzeregu.Rows[j].Cells[0].Value = string.Format("{0:0.000000}", Tablica[j, 0]);
  318. dgvTablicaSzeregu.Rows[j].Cells[1].Value = string.Format("{0:0.0000000000000}", Tablica[j, 1]);
  319. dgvTablicaSzeregu.Rows[j].Cells[2].Value = string.Format("{0:0}", Tablica[j, 2]);
  320.  
  321. if (j % 2 == 0)
  322. {
  323. dgvTablicaSzeregu.Rows[j].DefaultCellStyle.BackColor = Color.LightGray;
  324. }
  325. else
  326. {
  327. dgvTablicaSzeregu.Rows[j].DefaultCellStyle.BackColor = Color.White;
  328. }
  329.  
  330. }
  331.  
  332. return PKxd;
  333. }
  334.  
  335. float PKcalkowanieProstokat(float PKepsCalka, float PKcd, float PKcg, float PKdokladnosc, out int PKlicznikPrzedzialu, out float PKszerokosc)
  336. {
  337. float PKh, PKci, PKci_1, PKsumaFx;
  338. ushort PKlicznikWyrazowSzeregu;
  339. float PKxxx;
  340.  
  341. PKlicznikPrzedzialu = 1;
  342. PKci = (PKcg - PKcd) * PKsumaSzeregu((PKcd + PKcg) / 2.0F, PKepsCalka, out PKlicznikWyrazowSzeregu);
  343. do
  344. {
  345. PKci_1 = PKci;
  346. PKlicznikPrzedzialu = PKlicznikPrzedzialu + PKlicznikPrzedzialu;
  347. PKh = (PKcg - PKcd) / PKlicznikPrzedzialu;
  348. PKxxx = PKcd + PKh / 2.0F;
  349. PKsumaFx = 0.0F;
  350. for (ushort i = 0; i < PKlicznikPrzedzialu; i++)
  351. {
  352. PKsumaFx += PKsumaSzeregu(PKxxx + i * PKh, PKepsCalka, out PKlicznikWyrazowSzeregu);
  353. }
  354. PKci = PKh * PKsumaFx;
  355. } while (Math.Abs(PKci - PKci_1) > PKdokladnosc);
  356. PKszerokosc = PKh;
  357. return PKci;
  358.  
  359. }
  360.  
  361. float PKcalkowanieTrapez(float PKepsCalka, float PKcd, float PKcg, float PKdokladnosc, out int PKlicznikPrzedzialu, out float PKszerokosc)
  362. {
  363.  
  364. float PKX;
  365. float PKh, PKci, PKci_1, PKsumaFx;
  366. PKlicznikPrzedzialu = 0;
  367. ushort PKlicznikWyrazowSzeregu;
  368. float PKxxx;
  369.  
  370. float PKsumaTrapez = 0;
  371.  
  372. for (int i = 1; i < PKdokladnosc; i++)
  373. {
  374. PKX = PKcd + (i / PKdokladnosc) * (PKcg - PKcd);
  375. PKsumaTrapez += PKsumaSzeregu((PKcd + PKcg) / 2.0F, PKepsCalka, out PKlicznikWyrazowSzeregu); ;
  376. }
  377. PKX = PKcd;
  378. float KPPierwszaFunkcja = PKsumaSzeregu((PKX) / 2.0F, PKepsCalka, out PKlicznikWyrazowSzeregu);
  379. PKX = PKcd + (PKcg - PKcd);
  380. float KPOstatniaFunkcja = PKsumaSzeregu((PKX) / 2.0F, PKepsCalka, out PKlicznikWyrazowSzeregu);
  381. PKsumaTrapez += (KPPierwszaFunkcja + KPOstatniaFunkcja) / 2;
  382. PKszerokosc = ((PKcg - PKcd) / PKdokladnosc);
  383. return PKszerokosc * PKsumaTrapez;
  384. }
  385.  
  386. private void btnWynik_Click(object sender, EventArgs e)
  387. {
  388. float PKx, PKepsX;
  389. ushort PKlicznik;
  390.  
  391. if (!PKpobranieWynik(out PKx, out PKepsX))
  392. {
  393. return;
  394. }
  395.  
  396. txtWynik.Text = string.Format("{0:0.00000000}", PKsumaSzeregu(PKx, PKepsX, out PKlicznik));
  397. txtN.Text = PKlicznik.ToString();
  398.  
  399. pbRownosc.Visible = true;
  400. txtWynik.Visible = true;
  401. lblN.Visible = true;
  402. txtN.Visible = true;
  403. }
  404.  
  405. private void btnTabelaryczna_Click(object sender, EventArgs e)
  406. {
  407.  
  408.  
  409. float PKxd, PKxg, PKh;
  410. float PKepsXdlaTablicy;
  411. if (!PKpobranieTabela(out PKxd, out PKxg, out PKh, out PKepsXdlaTablicy))
  412. {
  413. return;
  414. }
  415. else
  416. {
  417. PKtablicowanie(PKxd, PKxg, PKh, PKepsXdlaTablicy, out float[,] Tablica);
  418. }
  419.  
  420. dgvTablicaSzeregu.Visible = true;
  421. btnTabelaryczna.Visible = false;
  422. chWykresFunkcji.Visible = false;
  423. }
  424.  
  425. private void btnGraficzna_Click(object sender, EventArgs e)
  426. {
  427. this.chWykresFunkcji.Visible = true;
  428. btnTabelaryczna.Visible = true;
  429.  
  430. dgvTablicaSzeregu.Visible = false;
  431. btnGraficzna.Visible = false;
  432.  
  433. float PKxd, PKxg, PKh;
  434. float PKepsXdlaTablicy;
  435.  
  436. if (!PKpobranieTabela(out PKxd, out PKxg, out PKh, out PKepsXdlaTablicy))
  437. {
  438. return;
  439. }
  440. else
  441. {
  442. PKtablicowanie(PKxd, PKxg, PKh, PKepsXdlaTablicy, out float[,] Tablica);
  443.  
  444. chWykresFunkcji.Series.Clear();
  445. chWykresFunkcji.Titles.Clear();
  446. chWykresFunkcji.Titles.Add("Wykres sumy szeregów funkcji");
  447. chWykresFunkcji.Series.Add("Series");
  448. chWykresFunkcji.ChartAreas[0].AxisX.Title = "Numer obliczenia";
  449. chWykresFunkcji.ChartAreas[0].AxisY.Title = "Wartość sumy";
  450. chWykresFunkcji.Series[0].IsVisibleInLegend = true;
  451. chWykresFunkcji.Legends.FindByName("Legend1").Docking = Docking.Bottom;
  452. chWykresFunkcji.Series[0].Name = "Wykres zmiany sumy szeregu";
  453. chWykresFunkcji.Series[0].ChartType = SeriesChartType.Line;
  454. chWykresFunkcji.Series[0].Color = Color.Red;
  455. chWykresFunkcji.Series[0].BorderDashStyle = ChartDashStyle.Dot;
  456. chWykresFunkcji.Series[0].BorderWidth = 2;
  457.  
  458. for (int i = 0; i < Tablica.GetLength(0); i++)
  459. {
  460. chWykresFunkcji.Series[0].Points.AddXY(i, Tablica[i, 1]);
  461. }
  462. }
  463. }
  464.  
  465. private void btnObliczCalke_Click(object sender, EventArgs e)
  466. {
  467. float PKepsCalka, PKcd, PKcg, PKdokladnosc;
  468. if (!PKpobranieCalka(out PKepsCalka, out PKcd, out PKcg, out PKdokladnosc))
  469. {
  470. return;
  471. }
  472.  
  473. if (cbMetody.SelectedIndex == 0)
  474. {
  475. txtWynikCalki.Text = string.Format("{0:0.00000000}", PKcalkowanieProstokat(PKepsCalka, PKcd, PKcg, PKdokladnosc, out int PKlicznikPrzedzialu, out float PKszerokosc));
  476. lblWynikCalki.Visible = true;
  477. txtWynikCalki.Visible = true;
  478. }
  479. else if (cbMetody.SelectedIndex == 1)
  480. {
  481. txtWynikCalki.Text = string.Format("{0:0.00000000}", PKcalkowanieTrapez(PKepsCalka, PKcd, PKcg, PKdokladnosc, out int PKlicznikPrzedzialu, out float PKszerokosc));
  482. lblWynikCalki.Visible = true;
  483. txtWynikCalki.Visible = true;
  484. lblWynikCalki.Visible = true;
  485. txtWynikCalki.Visible = true;
  486. }
  487. else
  488. {
  489. errorProvider1.SetError(cbMetody, "Wybierz metodę!");
  490. }
  491. }
  492.  
  493. private void btnResetuj_Click(object sender, EventArgs e)
  494. {
  495. Application.Restart();
  496. }
  497.  
  498. /* Opisy lini wykresu */
  499. private void OpisLini_CheckedChanged(object sender, EventArgs e)
  500. {
  501.  
  502. chWykresFunkcji.Titles.Clear();
  503. chWykresFunkcji.Titles.Add("Wykres sumy szeregów funkcji");
  504. chWykresFunkcji.Legends.Clear();
  505. chWykresFunkcji.Legends.Add("Legend1").Docking = Docking.Bottom;
  506. chWykresFunkcji.Series[0].Name = "Wykres zmiany sumy szeregu";
  507. chWykresFunkcji.ChartAreas[0].AxisX.Title = "Numer obliczenia";
  508. chWykresFunkcji.ChartAreas[0].AxisY.Title = "Wartość sumy";
  509. }
  510.  
  511. private void BrakOpisuLini_CheckedChanged(object sender, EventArgs e)
  512. {
  513. chWykresFunkcji.Titles.Clear();
  514. chWykresFunkcji.Legends.Clear();
  515. chWykresFunkcji.ChartAreas[0].AxisX.Title = "";
  516. chWykresFunkcji.ChartAreas[0].AxisY.Title = "";
  517. }
  518.  
  519. /* Kolory menu */
  520.  
  521. private void kolorTłaWykresuToolStripMenuItem_Click(object sender, EventArgs e)
  522. {
  523. ColorDialog PKkolorTla = new ColorDialog();
  524.  
  525. PKkolorTla.Color = chWykresFunkcji.BackColor;
  526.  
  527. if (PKkolorTla.ShowDialog() == DialogResult.OK)
  528. {
  529.  
  530. chWykresFunkcji.BackColor = PKkolorTla.Color;
  531. }
  532. }
  533.  
  534. private void kolorLiniiWykresuToolStripMenuItem_Click(object sender, EventArgs e)
  535. {
  536. ColorDialog PKkolorLinia = new ColorDialog();
  537.  
  538.  
  539. PKkolorLinia.Color = chWykresFunkcji.Series[0].Color;
  540.  
  541. if (PKkolorLinia.ShowDialog() == DialogResult.OK)
  542. {
  543. chWykresFunkcji.Series[0].Color = PKkolorLinia.Color;
  544. }
  545. }
  546.  
  547. /*Grubość lini na wykresie */
  548. private void toolStripMenuItem2_Click(object sender, EventArgs e)
  549. {
  550. chWykresFunkcji.Series[0].BorderWidth = 1;
  551. }
  552.  
  553. private void toolStripMenuItem3_Click(object sender, EventArgs e)
  554. {
  555. chWykresFunkcji.Series[0].BorderWidth = 2;
  556. }
  557.  
  558. private void toolStripMenuItem4_Click(object sender, EventArgs e)
  559. {
  560. chWykresFunkcji.Series[0].BorderWidth = 3;
  561. }
  562.  
  563. private void toolStripMenuItem5_Click(object sender, EventArgs e)
  564. {
  565. chWykresFunkcji.Series[0].BorderWidth = 4;
  566. }
  567.  
  568. /*Styl lini na wykresie */
  569.  
  570. private void kropkowaToolStripMenuItem_Click(object sender, EventArgs e)
  571. {
  572. chWykresFunkcji.Series[0].BorderDashStyle = ChartDashStyle.Dot;
  573. }
  574.  
  575. private void kreskowaToolStripMenuItem_Click(object sender, EventArgs e)
  576. {
  577. chWykresFunkcji.Series[0].BorderDashStyle = ChartDashStyle.Dash;
  578. }
  579.  
  580. private void kreskowokropkowaToolStripMenuItem_Click(object sender, EventArgs e)
  581. {
  582. chWykresFunkcji.Series[0].BorderDashStyle = ChartDashStyle.DashDot;
  583. }
  584.  
  585. private void ciagłaToolStripMenuItem_Click(object sender, EventArgs e)
  586. {
  587. chWykresFunkcji.Series[0].BorderDashStyle = ChartDashStyle.Solid;
  588. }
  589.  
  590. /*Typy wykresu */
  591. private void punktowyToolStripMenuItem_Click_1(object sender, EventArgs e)
  592. {
  593. chWykresFunkcji.Series[0].ChartType = SeriesChartType.Point;
  594. }
  595.  
  596. private void liniowyToolStripMenuItem_Click_1(object sender, EventArgs e)
  597. {
  598. chWykresFunkcji.Series[0].ChartType = SeriesChartType.Line;
  599. }
  600.  
  601. private void kolumnowyToolStripMenuItem_Click_1(object sender, EventArgs e)
  602. {
  603.  
  604. chWykresFunkcji.Series[0].ChartType = SeriesChartType.Column;
  605. }
  606.  
  607. private void słupkowyToolStripMenuItem_Click(object sender, EventArgs e)
  608. {
  609.  
  610. chWykresFunkcji.Series[0].ChartType = SeriesChartType.Bar;
  611. }
  612.  
  613. /*Event zamykania */
  614. private void zamknijToolStripMenuItem_Click(object sender, EventArgs e)
  615. {
  616. DialogResult PKpytanie = MessageBox.Show("Czy rzeczywiście chcesz zamknąć ten formularz?", this.Text,
  617. MessageBoxButtons.YesNoCancel,
  618. MessageBoxIcon.Question,
  619. MessageBoxDefaultButton.Button3
  620. );
  621.  
  622. switch (PKpytanie)
  623. {
  624. case DialogResult.Yes:
  625. MessageBox.Show("Teraz nastąpi zamknięcie formularza: " + this.Text);
  626. this.Close();
  627. break;
  628. case DialogResult.No:
  629. MessageBox.Show("Formularz nie będzie jednak zamknięty!!! ");
  630. break;
  631. case DialogResult.Cancel:
  632. MessageBox.Show("Anulowanie zamknięcia formularza!");
  633. break;
  634. }
  635. }
  636.  
  637. /*zapis/odczyt pliku */
  638. private void zapiszTablicęWPlikuToolStripMenuItem_Click(object sender, EventArgs e)
  639. {
  640. float PKxd, PKxg, PKh;
  641. float PKepsXdlaTablicy;
  642. if (!PKpobranieTabela(out PKxd, out PKxg, out PKh, out PKepsXdlaTablicy))
  643. {
  644. return;
  645. }
  646. else
  647. {
  648. PKtablicowanie(PKxd, PKxg, PKh, PKepsXdlaTablicy, out float[,] Tablica);
  649.  
  650. SaveFileDialog PKoknoZapisuPliku = new SaveFileDialog();
  651.  
  652. PKoknoZapisuPliku.Filter = "txt files (*.txt)|*.txt|All Files(*,*)|*.*";
  653. PKoknoZapisuPliku.FilterIndex = 1;
  654. PKoknoZapisuPliku.RestoreDirectory = true;
  655. PKoknoZapisuPliku.InitialDirectory = "D:\\";
  656. PKoknoZapisuPliku.Title = "Zapisanie wyników";
  657.  
  658. if (PKoknoZapisuPliku.ShowDialog() == DialogResult.OK)
  659. {
  660. StreamWriter PKplikZnakow = new StreamWriter(PKoknoZapisuPliku.OpenFile());
  661.  
  662. for (int i = 0; i < Tablica.GetLength(0); i++)
  663. {
  664. PKplikZnakow.Write(string.Format(" {0,8:0.000000} \t", Tablica[i, 0]));
  665. PKplikZnakow.Write(string.Format(" {0,6:0.0000000000000} \t", Tablica[i, 1]));
  666. PKplikZnakow.Write(string.Format(" {0,8:0} \t", Tablica[i, 2]));
  667. PKplikZnakow.WriteLine("\t");
  668.  
  669. }
  670. PKplikZnakow.Dispose();
  671. PKplikZnakow.Close();
  672. }
  673. }
  674. }
  675.  
  676. private void odczytajTablicęZPlikuToolStripMenuItem_Click(object sender, EventArgs e)
  677. {
  678.  
  679. dgvTablicaSzeregu.Rows.Clear();
  680.  
  681. OpenFileDialog PKoknoOdczytu = new OpenFileDialog();
  682.  
  683. PKoknoOdczytu.Title = "Otwarcie pliku z rozliczeniem lokaty kapitałowej";
  684.  
  685. if (PKoknoOdczytu.ShowDialog() == DialogResult.OK)
  686. {
  687. string PKnazwaPlik = PKoknoOdczytu.FileName;
  688. string[] PKzawartosc = File.ReadAllLines(PKnazwaPlik);
  689.  
  690. dgvTablicaSzeregu.RowTemplate.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
  691.  
  692. foreach (string PKwiersz in PKzawartosc)
  693. {
  694. dgvTablicaSzeregu.Rows.Add(PKwiersz.Split('\t'));
  695. }
  696. dgvTablicaSzeregu.Visible = true;
  697.  
  698.  
  699. }
  700. }
  701.  
  702. private void Analizator_Load(object sender, EventArgs e)
  703. {
  704.  
  705. }
  706. }
  707. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement