| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Xml.Linq;
- namespace Fuel01
- {
- public partial class f_saisie2 : Form
- {
- DataSet1.tb_stationDataTable tb_station = new DataSet1.tb_stationDataTable();
- DataSet1.tb_prestaDataTable tb_presta = new DataSet1.tb_prestaDataTable();
- DataSet1.tb_venteDataTable tb_vente = new DataSet1.tb_venteDataTable();
- DataSet1.tb_venteDataTable tb_ventetmp = new DataSet1.tb_venteDataTable();
- DataSet1.tb_vehiDataTable tb_vehi = new DataSet1.tb_vehiDataTable();
- List<DataSet1.tb_prestaRow> Lcarb = new List<DataSet1.tb_prestaRow>(); //Liste carbu hors diesel
- List<DataSet1.tb_prestaRow> Ldies = new List<DataSet1.tb_prestaRow>(); //Liste diesel
- List<DataSet1.tb_prestaRow> Lprod = new List<DataSet1.tb_prestaRow>(); //Liste des prestations
- List<DataSet1.tb_prestaRow> Lmycarb = new List<DataSet1.tb_prestaRow>(); //Liste tous les carbuants
- DataSet1.tb_stationRow myStation = null;
- DataSet1.tb_vehiRow myVehi = null;
- int Retry = 0;
- bool hasChanged = false;
- bool isDiesel = false;
- int indiceCarb = -1;
- string id_vehi="";
- public f_saisie2()
- {
- InitializeComponent();
- }
- private void f_saisie_Load(object sender, EventArgs e)
- {
- Program.subfolder = Program.folder + @"\" + Program.key_ope;
- if (File.Exists(Program.subfolder + @"\vehicule.json"))
- tb_vehi = DbUtil.LoadFromJson<DataSet1.tb_vehiDataTable>(Program.subfolder + @"\station.json", tb_vehi);
- tbvehiBindingSource.DataSource = tb_vehi;
- if (File.Exists(Program.subfolder + @"\station.json"))
- tb_station = DbUtil.LoadFromJson<DataSet1.tb_stationDataTable>(Program.subfolder + @"\station.json", tb_station);
- tbstationBindingSource.DataSource = tb_station;
- myStation = tb_station.FindBykey_sta(Program.key_sta);
- DataRowView rowView = null;
- if (myStation != null)
- {
- tbstationBindingSource.MoveFirst();
- while (true)
- {
- rowView = tbstationBindingSource.Current as DataRowView;
- if (myStation != rowView.Row)
- if (tbstationBindingSource.Position == tbstationBindingSource.Count)
- break;
- else
- tbstationBindingSource.MoveNext();
- else
- break;
- }
- }
- if (File.Exists(Program.subfolder + @"\presta_base.json"))
- tb_presta = DbUtil.LoadFromJson<DataSet1.tb_prestaDataTable>(Program.subfolder + @"\presta_base.json", tb_presta);
- tbprestaBindingSource.DataSource = tb_presta;
- if (File.Exists(Program.subfolder + @"\vente.json"))
- tb_vente = DbUtil.LoadFromJson<DataSet1.tb_venteDataTable>(Program.subfolder + @"\vente.json", tb_vente);
-
- tb_vente.AcceptChanges();
- tbventeBindingSource.DataSource = tb_vente;
- tbprestaBindingSource.Filter = " sta_pr='" + Program.key_sta + "'";
- tbventeBindingSource.Filter = " station_vt='" + Program.key_sta + "'";
- tbprestaBindingSource.Sort = "sta_pr,kind_pr,prod_pr";
- tbstationBindingSource_PositionChanged(null, null);
- tbventetmpbindingSource.DataSource = tb_ventetmp;
- lblstadt.Text= myStation.date_sta.ToString("dd/MM/yy") + " " + myStation.nom_sta;
- turnBlock(false);
- }
- private void tbstationBindingSource_PositionChanged(object sender, EventArgs e)
- {
- Lprod.Clear();
- Lcarb.Clear();
- //id_sta = key_sta.Text;
- tbprestaBindingSource.Filter = " sta_pr='" + Program.key_sta + "'";
- tbventeBindingSource.Filter = " station_vt='" + Program.key_sta + "'";
- tbprestaBindingSource.MoveFirst();
- int old_pos = -1;
- while (tbprestaBindingSource.Position != -1 && tbprestaBindingSource.Position < tbprestaBindingSource.Count && old_pos < tbprestaBindingSource.Position)
- {
- old_pos = tbprestaBindingSource.Position;
- DataSet1.tb_prestaRow mydata = null;
- DataRowView myrow = tbprestaBindingSource.Current as DataRowView;
- if (myrow != null)
- {
- mydata = myrow.Row as DataSet1.tb_prestaRow;
- if (mydata["kind_pr"].ToString() == "Carburant")
- {
- if (mydata["prod_pr"].ToString().ToUpper().Contains("DIESEL"))
- Ldies.Add(mydata);
- else
- Lcarb.Add(mydata);
- }
- else
- Lprod.Add(mydata);
- }
- tbprestaBindingSource.MoveNext();
- }
- aff_zero();
-
- }
- private void aff_carb(string curcarb)
- {
- rdCarb1.Enabled = rdCarb2.Enabled = rdCarb3.Enabled = rdCarb4.Enabled = rdCarb5.Enabled = rdCarb6.Enabled = false;
- rdCarb1.Text = rdCarb2.Text = rdCarb3.Text = rdCarb4.Text = rdCarb5.Text = rdCarb6.Text = "";
- nuPxCarb.Value = 0;
- if (isDiesel)
- Lmycarb = Ldies;
- else
- Lmycarb = Lcarb;
- if (Lmycarb.Count >= 1)
- {
- rdCarb1.Enabled = true;
- rdCarb1.Text = Lmycarb[0].prod_pr;
- rdCarb1.Checked = (curcarb == rdCarb1.Text);
- if ( rdCarb1.Checked ) rdCarb_CheckedChanged(rdCarb1, null);
- }
- if (Lmycarb.Count >= 2)
- {
- rdCarb2.Enabled = true;
- rdCarb2.Text = Lmycarb[1].prod_pr;
- rdCarb2.Checked = (curcarb == rdCarb2.Text);
- if (rdCarb2.Checked) rdCarb_CheckedChanged(rdCarb2, null);
- }
- if (Lmycarb.Count >= 3)
- {
- rdCarb3.Enabled = true;
- rdCarb3.Text = Lmycarb[2].prod_pr;
- rdCarb3.Checked = (curcarb == rdCarb3.Text);
- if (rdCarb3.Checked) rdCarb_CheckedChanged(rdCarb3, null);
- }
- if (Lmycarb.Count >= 4)
- {
- rdCarb4.Enabled = true;
- rdCarb4.Text = Lmycarb[3].prod_pr;
- rdCarb4.Checked = (curcarb == rdCarb4.Text);
- if (rdCarb4.Checked) rdCarb_CheckedChanged(rdCarb4, null);
- }
- if (Lmycarb.Count >=5 )
- {
- rdCarb5.Enabled = true;
- rdCarb5.Text = Lmycarb[4].prod_pr;
- rdCarb5.Checked = (curcarb == rdCarb5.Text);
- if (rdCarb5.Checked) rdCarb_CheckedChanged(rdCarb5, null);
- }
- if (Lmycarb.Count >= 6)
- {
- rdCarb6.Enabled = true;
- rdCarb6.Text = Lmycarb[5].prod_pr;
- rdCarb6.Checked = (curcarb == rdCarb6.Text);
- if (rdCarb6.Checked) rdCarb_CheckedChanged(rdCarb6, null);
- }
- //if (Lcarb.Count > 0)
- //{
- // rdCarb1.Checked = true;
- // rdCarb_CheckedChanged(rdCarb1, null);
- //}
- }
- private void aff_prod()
- {
- chkPrFree.Enabled = true;
- if (Lprod.Count >= 1)
- {
- chkPr1.Enabled = true; //nuTot1.Enabled = nuQtt1.Enabled = true;
- chkPr1.Text = Lprod[0].prod_pr;
- nuPr1.Value = Lprod[0].ttc_pr;
- }
- if (Lprod.Count >= 2)
- {
- chkPr2.Enabled = true; //nuTot2.Enabled = nuQtt2.Enabled = true;
- chkPr2.Text = Lprod[1].prod_pr;
- nuPr2.Value = Lprod[1].ttc_pr;
- }
- if (Lprod.Count >= 3)
- {
- chkPr3.Enabled = true; //= nuTot3.Enabled = nuQtt3.Enabled = true;
- chkPr3.Text = Lprod[2].prod_pr;
- nuPr3.Value = Lprod[2].ttc_pr;
- }
- }
- private void nu_ValueChanged(object sender, EventArgs e)
- {
- if (Retry++>15) //on evite la boucle infinie
- {
- Retry = 0;
- return;
- }
- string from = ((NumericUpDown)sender).Name;
- switch (from)
- {
- case "nuPxCarb":
- case "nuMntCarb":
- if (nuPxCarb.Value > 0)
- {
- nuVolCarb.Value = nuMntCarb.Value / nuPxCarb.Value;
- }
- break;
- case "nuVolCarb":
- nuMntCarb.Value = nuVolCarb.Value * nuPxCarb.Value;
- break;
- case "nuPr1":
- case "nuTot1":
- if (nuPr1.Value > 0)
- {
- nuQtt1.Value = nuTot1.Value / nuPr1.Value;
- }
- break;
- case "nuQtt1":
- nuTot1.Value = nuQtt1.Value * nuPr1.Value;
- break;
- case "nuPr2":
- case "nuTot2":
- if (nuPr2.Value > 0)
- {
- nuQtt2.Value = nuTot2.Value / nuPr2.Value;
- }
- break;
- case "nuQtt2":
- nuTot2.Value = nuQtt2.Value * nuPr2.Value;
- break;
- case "nuPr3":
- case "nuTot3":
- if (nuPr3.Value > 0)
- {
- nuQtt3.Value = nuTot3.Value / nuPr3.Value;
- }
- break;
- case "nuQtt3":
- nuTot3.Value = nuQtt3.Value * nuPr3.Value;
- break;
- case "nuPrFree":
- case "nuQttFree":
- nuTotFree.Value = nuPrFree.Value * nuQttFree.Value;
- break;
- case "nuTotFree":
- nuQttFree.Value = 1;
- nuPrFree.Value= nuTotFree.Value / nuQttFree.Value;
- break;
- }
- }
- private void rdCarb_CheckedChanged(object sender, EventArgs e)
- {
- if (((RadioButton)sender).Checked == true)
- {
- //on récupère le nom pour l'indice du tableau
- indiceCarb = Convert.ToInt16(((RadioButton)sender).Name.Substring(6, 1))-1;
- if (indiceCarb < Lmycarb.Count && indiceCarb >= 0)
- nuPxCarb.Value = Lmycarb[indiceCarb].ttc_pr;
- else
- MessageBox.Show("Carburant non disponible pour ce véhicule!");
- }
- }
- private void bt_abort_Click(object sender, EventArgs e)
- {
- aff_zero();
- text_no.Focus();
- }
- private void bt_valid_Click(object sender, EventArgs e)
- {
- if (chkPrFree.Checked)
- {
- if ( nuPrFree.Value * nuQttFree.Value ==0 || txtPrFree.Text.Trim(new char[]{ ' ','a' })=="" )
- {
- MessageBox.Show("Incohérence dans les données libres (libellé ou prix ou qtt ou tva");
- return;
- }
- }
- if (nuVolCarb.Value > 0) ajpresta(Lmycarb[indiceCarb], nuPxCarb.Value, nuVolCarb.Value, nuMntCarb.Text);
- if (chkPr1.Checked) ajpresta(Lprod[0], nuPr1.Value, nuQtt1.Value, nuTot1.Text);
- if (chkPr2.Checked) ajpresta(Lprod[1], nuPr2.Value, nuQtt2.Value, nuTot2.Text);
- if (chkPr3.Checked) ajpresta(Lprod[2], nuPr3.Value, nuQtt3.Value, nuTot3.Text);
- if (chkPrFree.Checked) ajpresta(txtPrFree.Text, nuPrFree.Value, nuQttFree.Value, nuTotFree.Text,numTvaFree.Value);
- f_ticket ticket = new f_ticket(myStation, myVehi, tb_ventetmp);
- if (ticket.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- foreach (DataSet1.tb_venteRow myVt in tb_ventetmp)
- {
- tb_vente.Addtb_venteRow(myVt.epreuve_vt, myVt.station_vt, myVt.vehi_vt, myVt.prod_vt, myVt.date_vt, myVt.qtt_vt, myVt.pu_vt, myVt.tva_vt, myVt.ht_vt, myVt.ttc_vt);
- }
- hasChanged = true;
- bt_save.Enabled = hasChanged;
- }
- tb_ventetmp.Clear();
- aff_zero();
- }
- /// <summary>
- /// Presta enregistrée
- /// </summary>
- /// <param name="prRow"></param>
- /// <param name="pu"></param>
- /// <param name="qtt"></param>
- /// <param name="total_str"></param>
- private void ajpresta(DataSet1.tb_prestaRow prRow, decimal pu, decimal qtt, string total_str)
- {
- decimal tva = 0;
- decimal totht = 0;
- decimal total = Convert.ToDecimal(total_str);
- string lib = prRow.prod_pr;
- tva = prRow.tva_pr;
- totht = Math.Round(total / (1 + tva / 100),2);
- DateTime dt = DateTime.Now;
- tb_ventetmp.Addtb_venteRow(Program.key_ope, Program.key_sta, id_vehi, lib, dt, qtt, pu, tva, totht, total);
- }
- /// <summary>
- /// Presta libre
- /// </summary>
- /// <param name="lib"></param>
- /// <param name="pu"></param>
- /// <param name="qtt"></param>
- /// <param name="total_str"></param>
- /// <param name="tva"></param>
- private void ajpresta(string lib, decimal pu, decimal qtt, string total_str,decimal tva)
- {
- decimal totht = 0;
- decimal total = Convert.ToDecimal(total_str);
- totht = Math.Round(total / (1 + tva / 100), 2);
- DateTime dt = DateTime.Now;
- tb_ventetmp.Addtb_venteRow(Program.key_ope, Program.key_sta, id_vehi, lib, dt, qtt, pu, tva, totht, total);
- }
- private void bt_search_Click(object sender, EventArgs e)
- {
- Retry = 0;
- UInt32 num;
- if (UInt32.TryParse(text_no.Text, out num))
- {
- myVehi = tb_vehi.FirstOrDefault(v => v.num_vehi == num && v.categ_vehi == (rdAuto.Checked ? "A" : "M"));
- if (myVehi != null)
- {
- lbl_pilote.Text = myVehi.cond_vehi ;
- isDiesel = myVehi.carbu_vehi.ToUpper().Contains("DIESEL");
- aff_carb(myVehi.carbu_vehi);
- aff_prod();
- id_vehi = myVehi.sort1_vehi;
- rdCarb1.Checked = true;
- }
- else
- {
- aff_zero();
- text_no.Text = num.ToString();
- text_no.SelectionStart = 0;
- text_no.SelectionLength = text_no.Text.Length;
- }
- }
- turnBlock(myVehi != null);
- }
- private void turnBlock(bool status)
- {
- grpCarb.Enabled = status;
- grpServ.Enabled = status;
- bt_abort.Enabled = status;
- bt_valid.Enabled = status;
- }
- private void aff_zero()
- {
- chkPr1.Enabled = chkPr2.Enabled = chkPr3.Enabled = chkPrFree.Enabled= false;
- chkPr1.Checked = chkPr2.Checked = chkPr3.Checked = chkPrFree.Checked = false;
- nuPr1.Enabled = nuPr2.Enabled = nuPr3.Enabled = false;
- nuQtt1.Enabled = nuQtt2.Enabled = nuQtt3.Enabled = false;
- nuTot1.Enabled = nuTot2.Enabled = nuTot3.Enabled = false;
- chkPr1.Text = chkPr2.Text = chkPr3.Text = txtPrFree.Text = "";
- nuVolCarb.Value= nuPr1.Value = nuPr2.Value = nuPr3.Value = nuPrFree.Value = 0;
- nuQtt1.Value = nuQtt2.Value = nuQtt3.Value = nuQttFree.Value = 0;
- nuTot1.Value = nuTot2.Value = nuTot3.Value = 0;
- nuPxCarb.Value = nuMntCarb.Value = nuPxCarb.Value = 0;
- text_no.Text = "";
- }
- private void text_no_KeyUp(object sender, KeyEventArgs e)
- {
- if (e.KeyValue == 13)
- bt_search_Click(null, null);
- }
- private void bt_save_Click(object sender, EventArgs e)
- {
- DbUtil.SaveToJson<DataSet1.tb_venteDataTable>(Program.subfolder + @"\vebnte.json", tb_vente);
- hasChanged = false;
- bt_save.Enabled = hasChanged;
- }
- private void f_saisie_FormClosing(object sender, FormClosingEventArgs e)
- {
- if (hasChanged)
- bt_save_Click(null, null);
- e.Cancel = false;
- }
- private void chkPrFree_CheckStateChanged(object sender, EventArgs e)
- {
- nuTotFree.Enabled = ((CheckBox)sender).Checked;
- if (!((CheckBox)sender).Checked)
- nuTotFree.Value = 1;
- }
- private void chkProduit_CheckedChanged(object sender, EventArgs e)
- {
- bool Checked= ((CheckBox)sender).Checked;
- var Name= ((CheckBox)sender).Name;
- switch (Name)
- {
- case "chkPr1":
- nuQtt1.Enabled = nuTot1.Enabled = Checked;
- nuQtt1.Value = nuTot1.Value = 0;
- break;
- case "chkPr2":
- nuQtt2.Enabled = nuTot2.Enabled = Checked;
- nuQtt2.Value = nuTot2.Value = 0;
- break;
- case "chkPr3":
- nuQtt3.Enabled = nuTot3.Enabled = Checked;
- nuQtt3.Value = nuTot3.Value = 0;
- break;
- }
- }
- }
- }
|