Advertisement
Guest User

avtomobili

a guest
Dec 15th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.77 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.IO;
  11.  
  12. namespace ZigaZajc4.Ra
  13. {
  14. public partial class Form1 : Form
  15. {
  16. public Form1()
  17. {
  18. InitializeComponent();
  19. }
  20.  
  21. private void Form1_Load(object sender, EventArgs e)
  22. {
  23. dataGridView1.Rows.Add("Clio", 2015, 8300, 1450, "red", false, "Uredi");
  24. dataGridView1.Rows.Add("Passat", 2010, 6700, 1180, "black", true, "Uredi");
  25. }
  26.  
  27. private void dodajNovZapisToolStripMenuItem_Click(object sender, EventArgs e)
  28. {
  29. Form2 fm = new Form2();
  30.  
  31. if (fm.ShowDialog() == DialogResult.OK)
  32. {
  33. dataGridView1.Rows.Add(fm.comboBox1.Text, fm.numericUpDown1.Value, fm.textBox1.Text, fm.textBox2.Text, fm.textBox3.Text, fm.checkBox1.Checked, "Uredi");
  34. MessageBox.Show("Zaspis je dodan v tabelo.");
  35. }
  36. }
  37.  
  38. private void letnik2010ToolStripMenuItem_Click(object sender, EventArgs e)
  39. {
  40. string model = "";
  41. for (int i = 0; i < dataGridView1.RowCount; i++)
  42. {
  43. if (dataGridView1.Rows[i].Cells[1].Value.ToString() == "2010")
  44. {
  45. model += dataGridView1.Rows[i].Cells[0].Value.ToString() + " = " + dataGridView1.Rows[i].Cells[2].Value.ToString() + "€ \n";
  46. }
  47. }
  48. MessageBox.Show("Letniki 2010:\n\n" + model);
  49. }
  50.  
  51. private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
  52. {
  53. if (e.ColumnIndex == 6)
  54. {
  55. Form2 fm2 = new Form2();
  56. fm2.comboBox1.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
  57. fm2.numericUpDown1.Value = Convert.ToDecimal(dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString());
  58. fm2.textBox1.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
  59. fm2.textBox2.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
  60. fm2.textBox3.Text = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();
  61. fm2.checkBox1.Checked = Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells[5].Value);
  62.  
  63. if (fm2.ShowDialog() == DialogResult.OK)
  64. {
  65. dataGridView1.Rows[e.RowIndex].SetValues(fm2.comboBox1.Text, fm2.numericUpDown1.Value, fm2.textBox1.Text, fm2.textBox2.Text, fm2.textBox3.Text, fm2.checkBox1.Checked, "Uredi");
  66. MessageBox.Show("Zaspis je spremenjen.");
  67. }
  68. }
  69. }
  70.  
  71. private void shraniVDatotekoToolStripMenuItem_Click(object sender, EventArgs e)
  72. {
  73. string path = "";
  74. SaveFileDialog saveFileDialog = new SaveFileDialog();
  75. if(saveFileDialog.ShowDialog() == DialogResult.OK)
  76. {
  77. path = saveFileDialog.FileName;
  78. }
  79.  
  80. StreamWriter sw = File.CreateText(path);
  81. string s = "";
  82. for (int i = 0; i < dataGridView1.RowCount; i++)
  83. {
  84. for (int j = 0; j < dataGridView1.Rows[i].Cells.Count-1; j++)
  85. {
  86. s += dataGridView1.Rows[i].Cells[j].Value.ToString() + "|";
  87. }
  88. sw.WriteLine(s);
  89. s = "";
  90. }
  91. sw.Close();
  92. MessageBox.Show("Podatki so shranjeni.");
  93. }
  94. }
  95. }
  96.  
  97. ------------------------------------------------------form2
  98.  
  99. using System;
  100. using System.Collections.Generic;
  101. using System.ComponentModel;
  102. using System.Data;
  103. using System.Drawing;
  104. using System.Linq;
  105. using System.Text;
  106. using System.Threading.Tasks;
  107. using System.Windows.Forms;
  108. using System.IO;
  109.  
  110. namespace ZigaZajc4.Ra
  111. {
  112. public partial class Form2 : Form
  113. {
  114. public Form2()
  115. {
  116. InitializeComponent();
  117. }
  118.  
  119. private void Form2_Load(object sender, EventArgs e)
  120. {
  121. comboBox1.DataSource = File.ReadAllLines("modeli.txt");
  122. }
  123.  
  124. private void button2_Click(object sender, EventArgs e)
  125. {
  126. MessageBox.Show("Ali ste prepričani da želite to storiti?", "Zapis", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
  127. }
  128.  
  129. private void button1_Click(object sender, EventArgs e)
  130. {
  131. ColorDialog color = new ColorDialog();
  132. if(color.ShowDialog() == DialogResult.OK)
  133. {
  134. textBox3.Text = color.Color.Name;
  135. }
  136. }
  137. }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement