| 1 | using System;
|
|---|
| 2 | using System.Collections.Generic;
|
|---|
| 3 | using System.ComponentModel;
|
|---|
| 4 | using System.Data;
|
|---|
| 5 | using System.Drawing;
|
|---|
| 6 | using System.Text;
|
|---|
| 7 | using System.Windows.Forms;
|
|---|
| 8 | using BazaZamowien.Classes;
|
|---|
| 9 |
|
|---|
| 10 | namespace BazaZamowien
|
|---|
| 11 | {
|
|---|
| 12 | public partial class PremieWspolczynniki : Form
|
|---|
| 13 | {
|
|---|
| 14 | public PremieWspolczynniki()
|
|---|
| 15 | {
|
|---|
| 16 | InitializeComponent();
|
|---|
| 17 | wspolczynnikiTableAdapter.Connection.ConnectionString = ConnString.getConnString().PremieConnStr;
|
|---|
| 18 |
|
|---|
| 19 | choroboweTextBox.DataBindings[0].Format += new ConvertEventHandler(DecimalToProcent);
|
|---|
| 20 | choroboweTextBox.DataBindings[0].Parse += new ConvertEventHandler(ProcentToDecimal);
|
|---|
| 21 |
|
|---|
| 22 | emerytalneTextBox.DataBindings[0].Format += new ConvertEventHandler(DecimalToProcent);
|
|---|
| 23 | emerytalneTextBox.DataBindings[0].Parse += new ConvertEventHandler(ProcentToDecimal);
|
|---|
| 24 |
|
|---|
| 25 | rentoweTextBox.DataBindings[0].Format += new ConvertEventHandler(DecimalToProcent);
|
|---|
| 26 | rentoweTextBox.DataBindings[0].Parse += new ConvertEventHandler(ProcentToDecimal);
|
|---|
| 27 |
|
|---|
| 28 | zdrowotne1TextBox.DataBindings[0].Format += new ConvertEventHandler(DecimalToProcent);
|
|---|
| 29 | zdrowotne1TextBox.DataBindings[0].Parse += new ConvertEventHandler(ProcentToDecimal);
|
|---|
| 30 |
|
|---|
| 31 | zdrowotne2TextBox.DataBindings[0].Format += new ConvertEventHandler(DecimalToProcent);
|
|---|
| 32 | zdrowotne2TextBox.DataBindings[0].Parse += new ConvertEventHandler(ProcentToDecimal);
|
|---|
| 33 |
|
|---|
| 34 | podatekTextBox.DataBindings[0].Format += new ConvertEventHandler(DecimalToProcent);
|
|---|
| 35 | podatekTextBox.DataBindings[0].Parse += new ConvertEventHandler(ProcentToDecimal);
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | private void wspolczynnikiBindingNavigatorSaveItem_Click(object sender, EventArgs e)
|
|---|
| 39 | {
|
|---|
| 40 | this.Validate();
|
|---|
| 41 | this.wspolczynnikiBindingSource.EndEdit();
|
|---|
| 42 | this.wspolczynnikiTableAdapter.Update(this.pREMIEDataSet.Wspolczynniki);
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | private void PremieWspolczynniki_Load(object sender, EventArgs e)
|
|---|
| 46 | {
|
|---|
| 47 | this.wspolczynnikiTableAdapter.Fill(this.pREMIEDataSet.Wspolczynniki);
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
|
|---|
| 51 | {
|
|---|
| 52 | DataView table = (DataView)wspolczynnikiBindingSource.List;
|
|---|
| 53 | DataRowView row = table.AddNew();
|
|---|
| 54 | row["data"] = DateTime.Today;
|
|---|
| 55 | this.wspolczynnikiBindingSource.EndEdit();
|
|---|
| 56 | this.wspolczynnikiBindingSource.MoveLast();
|
|---|
| 57 |
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
|
|---|
| 61 | {
|
|---|
| 62 | if (wspolczynnikiBindingSource.Current != null)
|
|---|
| 63 | {
|
|---|
| 64 | int id = (int)((DataRowView)wspolczynnikiBindingSource.Current)["IDE"];
|
|---|
| 65 | wspolczynnikiTableAdapter.Delete(id);
|
|---|
| 66 |
|
|---|
| 67 | pREMIEDataSet.Wspolczynniki.Clear();
|
|---|
| 68 | wspolczynnikiTableAdapter.Fill(pREMIEDataSet.Wspolczynniki);
|
|---|
| 69 | }
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | /// <summary>
|
|---|
| 73 | /// formatowanie do decimal -> %
|
|---|
| 74 | /// </summary>
|
|---|
| 75 | private void DecimalToProcent(object sender, ConvertEventArgs cevent)
|
|---|
| 76 | {
|
|---|
| 77 |
|
|---|
| 78 | if (Convert.ToDecimal(cevent.Value) > 1)
|
|---|
| 79 | {
|
|---|
| 80 | // cevent.Value = Convert.ToDecimal(cevent.Value) / 100;
|
|---|
| 81 | }
|
|---|
| 82 | cevent.Value = String.Format("{0:P}", cevent.Value);
|
|---|
| 83 |
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | /// <summary>
|
|---|
| 87 | /// formatowanie do % -> decimal
|
|---|
| 88 | /// </summary>
|
|---|
| 89 | private void ProcentToDecimal(object sender, ConvertEventArgs cevent)
|
|---|
| 90 | {
|
|---|
| 91 | string pom = cevent.Value.ToString();
|
|---|
| 92 | if (cevent.Value.ToString().EndsWith("%"))
|
|---|
| 93 | {
|
|---|
| 94 | pom = cevent.Value.ToString().Substring(0, cevent.Value.ToString().Length - 1);
|
|---|
| 95 | }
|
|---|
| 96 | decimal p = Decimal.Parse(pom) / 100;
|
|---|
| 97 | cevent.Value = p.ToString();
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 | private void procentBoxEndEdit(object sender, EventArgs e)
|
|---|
| 102 | {
|
|---|
| 103 | wspolczynnikiBindingSource.EndEdit();
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | private void wspolczynnikiBindingSource_ListChanged(object sender, ListChangedEventArgs e)
|
|---|
| 107 | {
|
|---|
| 108 | if (wspolczynnikiBindingSource.List.Count == 0)
|
|---|
| 109 | {
|
|---|
| 110 | panel1.Enabled = false;
|
|---|
| 111 | }
|
|---|
| 112 | else
|
|---|
| 113 | {
|
|---|
| 114 | panel1.Enabled = true;
|
|---|
| 115 | }
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | }
|
|---|
| 119 | } |
|---|