private void dgwPodatki_CellValueChanged(object sender, DataGridViewCellEventArgs e) { int vrstica = e.RowIndex; int stolpec = e.ColumnIndex; Darovi d = new Darovi(); d.ZapŠt = int.Parse(dgwPodatki.Rows[vrstica].Cells["ZapŠt"].Value.ToString()); d.Datum = DateTime.Parse(dgwPodatki.Rows[vrstica].Cells["Datum"].Value.ToString()); d.Namen = dgwPodatki.Rows[vrstica].Cells["Namen"].Value.ToString(); d.Znesek = double.Parse(dgwPodatki.Rows[vrstica].Cells["Znesek"].Value.ToString()); d.Opombe = dgwPodatki.Rows[vrstica].Cells["Opombe"].Value.ToString(); spremembe[vrstica] = d; štSprememb++; }
private void button1_Click(object sender, EventArgs e) { Darovi d = new Darovi(); try { d.ZapŠt = int.Parse(txtZapŠt.Text); } catch { lblStatus.Text = "Zaporedna številka je napačna"; txtZapŠt.Text = ""; txtZapŠt.Focus(); } d.Datum = dtpDatum.Value; d.Namen = txtNamen.Text; try { d.Znesek = double.Parse(txtZnesek.Text); } catch { lblStatus.Text = "Znesek je napačen"; txtZnesek.Text = ""; txtZnesek.Focus(); } d.Opombe = txtOpombe.Text; if (d.ZapŠt != 0 && d.Znesek != 0) { FileStream fs = new FileStream(pot, FileMode.Append); BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(fs, d); fs.Close(); lblStatus.Text = "Vnos uspešen"; txtNamen.Text = ""; txtOpombe.Text = ""; txtZapŠt.Text = ""; txtZnesek.Text = ""; txtZapŠt.Focus(); } }
private void button1_Click(object sender, EventArgs e) { //beri iz binarne datoteke FileStream fs = new FileStream(pot, FileMode.Open); BinaryFormatter bf = new BinaryFormatter(); try { while (true) { Darovi d = (Darovi)bf.Deserialize(fs); vsi.Add(d); } } catch (SerializationException) { } //piši v xml datoteko string imeD = @"D:\Pro2\Zascita" + DateTime.Now.ToShortDateString() + ".xml"; FileStream fs1 = new FileStream(imeD, FileMode.Create); XmlSerializer sr = new XmlSerializer(typeof(List <Darovi>)); sr.Serialize(fs1, vsi); fs1.Close(); MessageBox.Show("Opravljeno"); }