Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.IO;
- namespace ZigaZajc4.Ra
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- dataGridView1.Rows.Add("Clio", 2015, 8300, 1450, "red", false, "Uredi");
- dataGridView1.Rows.Add("Passat", 2010, 6700, 1180, "black", true, "Uredi");
- }
- private void dodajNovZapisToolStripMenuItem_Click(object sender, EventArgs e)
- {
- Form2 fm = new Form2();
- if (fm.ShowDialog() == DialogResult.OK)
- {
- dataGridView1.Rows.Add(fm.comboBox1.Text, fm.numericUpDown1.Value, fm.textBox1.Text, fm.textBox2.Text, fm.textBox3.Text, fm.checkBox1.Checked, "Uredi");
- MessageBox.Show("Zaspis je dodan v tabelo.");
- }
- }
- private void letnik2010ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- string model = "";
- for (int i = 0; i < dataGridView1.RowCount; i++)
- {
- if (dataGridView1.Rows[i].Cells[1].Value.ToString() == "2010")
- {
- model += dataGridView1.Rows[i].Cells[0].Value.ToString() + " = " + dataGridView1.Rows[i].Cells[2].Value.ToString() + "€ \n";
- }
- }
- MessageBox.Show("Letniki 2010:\n\n" + model);
- }
- private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
- {
- if (e.ColumnIndex == 6)
- {
- Form2 fm2 = new Form2();
- fm2.comboBox1.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
- fm2.numericUpDown1.Value = Convert.ToDecimal(dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString());
- fm2.textBox1.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
- fm2.textBox2.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
- fm2.textBox3.Text = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();
- fm2.checkBox1.Checked = Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells[5].Value);
- if (fm2.ShowDialog() == DialogResult.OK)
- {
- dataGridView1.Rows[e.RowIndex].SetValues(fm2.comboBox1.Text, fm2.numericUpDown1.Value, fm2.textBox1.Text, fm2.textBox2.Text, fm2.textBox3.Text, fm2.checkBox1.Checked, "Uredi");
- MessageBox.Show("Zaspis je spremenjen.");
- }
- }
- }
- private void shraniVDatotekoToolStripMenuItem_Click(object sender, EventArgs e)
- {
- string path = "";
- SaveFileDialog saveFileDialog = new SaveFileDialog();
- if(saveFileDialog.ShowDialog() == DialogResult.OK)
- {
- path = saveFileDialog.FileName;
- }
- StreamWriter sw = File.CreateText(path);
- string s = "";
- for (int i = 0; i < dataGridView1.RowCount; i++)
- {
- for (int j = 0; j < dataGridView1.Rows[i].Cells.Count-1; j++)
- {
- s += dataGridView1.Rows[i].Cells[j].Value.ToString() + "|";
- }
- sw.WriteLine(s);
- s = "";
- }
- sw.Close();
- MessageBox.Show("Podatki so shranjeni.");
- }
- }
- }
- ------------------------------------------------------form2
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.IO;
- namespace ZigaZajc4.Ra
- {
- public partial class Form2 : Form
- {
- public Form2()
- {
- InitializeComponent();
- }
- private void Form2_Load(object sender, EventArgs e)
- {
- comboBox1.DataSource = File.ReadAllLines("modeli.txt");
- }
- private void button2_Click(object sender, EventArgs e)
- {
- MessageBox.Show("Ali ste prepričani da želite to storiti?", "Zapis", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
- }
- private void button1_Click(object sender, EventArgs e)
- {
- ColorDialog color = new ColorDialog();
- if(color.ShowDialog() == DialogResult.OK)
- {
- textBox3.Text = color.Color.Name;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement