| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- 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;
- using System.Xml.Linq;
- using Excel=Microsoft.Office.Interop.Excel;
- namespace Fuel01
- {
- public partial class f_station : Form
- {
- DataSet1.tb_stationDataTable tb_station = new DataSet1.tb_stationDataTable();
- string keysta;
- f_presta fpresta;
- List<Pays> lpays = new List<Pays>();
- public f_station(DataSet1.tb_stationDataTable tb_station,string keysta)
- {
- InitializeComponent();
- this.tb_station = tb_station;
- this.keysta = keysta;
- }
- private void f_station_Load(object sender, EventArgs e)
- {
- tb_station.AcceptChanges();
- tbstationBindingSource.DataSource = tb_station;
-
- TurnTxt(false);
- TurnBt(false);
- if (Program.key_ope != null)
- this.Text = "Stations " + Program.nom_ope;
- if (File.Exists(Program.folder + @"\param\pays.xml"))
- InitListPays();
- tbstationBindingSource.MoveFirst();
- DataRowView myRow = tbstationBindingSource.Current as DataRowView;
- if (myRow != null)
- while (myRow.Row["key_sta"].ToString() != keysta)
- {
- int i = tbstationBindingSource.Position;
- tbstationBindingSource.MoveNext();
- myRow = tbstationBindingSource.Current as DataRowView;
- if (i == tbstationBindingSource.Position)
- break;
- }
- }
- private void f_station_FormClosing(object sender, FormClosingEventArgs e)
- {
- if (fpresta != null)
- fpresta.Close();
- DataSet1.tb_stationDataTable tb_station_tmp = new DataSet1.tb_stationDataTable();
- foreach (DataRow dr in tb_station.OrderBy(p => p.date_sta))
- tb_station_tmp.ImportRow(dr);
- DbUtil.SaveToJson<DataSet1.tb_stationDataTable>(Program.subfolder + @"\station.json", tb_station_tmp);
-
- tb_station_tmp.Dispose();
- e.Cancel = false;
- }
- #region affichage
- private void TurnTxt(bool act)
- {
- text_etp_sta.Enabled = act;
- dt_date_sta.Enabled = act;
- nn_num_sta.Enabled = act;
- text_contact_sta.Enabled = act;
- text_nom_sta.Enabled = act;
- text_adr1_sta.Enabled = act;
- text_adr2_sta.Enabled = act;
- combo_pays_sta.Enabled = act;
- text_cp_sta.Enabled = act;
- text_ville_sta.Enabled = act;
- text_tel_sta.Enabled = act;
- text_tva_sta.Enabled = act;
- text_divers_sta.Enabled = act;
- }
- private void TurnBt(bool act)
- {
- Bt_Abort.Enabled = act;
- bt_Valid.Enabled = act;
- bt_Mod.Enabled = !act;
- bt_Aj.Enabled = !act;
- bt_Sup.Enabled = !act;
- dg_station.Enabled = !act;
- }
- #endregion
- private void InitListPays()
- {
- XDocument xRoot = XDocument.Load(Program.folder + @"\param\pays.xml");
- var data = from item in xRoot.Descendants("tb_pays")
- orderby item.Element("order_pays").Value
- select new Pays()
- {
- key_pays = item.Element("key_pays").Value,
- nom_pays = item.Element("nom_pays").Value,
- code_pays = item.Element("code_pays").Value,
- concat_pays = item.Element("code_pays").Value + "-" + item.Element("nom_pays").Value
- };
- lpays = data.ToList();
- combo_pays_sta.Items.Clear();
- combo_pays_sta.DisplayMember = "key_pays";
- foreach (Pays p in lpays)
- combo_pays_sta.Items.Add(p);
- }
- #region Boutons
- private void bt_Mod_Click(object sender, EventArgs e)
- {
- TurnBt(true);
- TurnTxt(true);
- }
- private void bt_Aj_Click(object sender, EventArgs e)
- {
- TurnTxt(true);
- TurnBt(true);
- string key = findNewkey();
- DataSet1.tb_stationRow myNewRow = tb_station.Newtb_stationRow();
- myNewRow["key_sta"] = key;
- myNewRow["epr_sta"] = Program.key_ope;
- tb_station.Addtb_stationRow(myNewRow);
- tbstationBindingSource.MoveFirst();
- DataRowView myRow = tbstationBindingSource.Current as DataRowView;
- while (myRow.Row["key_sta"].ToString() != key)
- {
- tbstationBindingSource.MoveNext();
- myRow = tbstationBindingSource.Current as DataRowView;
- }
- }
- private void bt_Sup_Click(object sender, EventArgs e)
- {
- DataRowView myRow = tbstationBindingSource.Current as DataRowView;
- if (myRow == null) return;
- string msg = string.Format("Station {0}\n Etape {1} du {2} \n Etes-vous certain de vouloir la supprimer", myRow.Row["nom_sta"].ToString(), myRow.Row["etp_sta"].ToString(), myRow.Row["date_sta"].ToString());
- string caption = "Suppression définitive";
- if (MessageBox.Show(msg, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
- {
- DataSet1.tb_stationRow stationRow = tb_station.FindBykey_sta(myRow.Row["key_sta"].ToString());
- if (stationRow != null)
- tb_station.Removetb_stationRow(stationRow);
- }
- }
- private void bt_Valid_Click(object sender, EventArgs e)
- {
- tb_station.AcceptChanges();
- TurnTxt(false);
- TurnBt(false);
- }
- private void Bt_Abort_Click(object sender, EventArgs e)
- {
- tb_station.RejectChanges();
- TurnTxt(false);
- TurnBt(false);
- }
- #endregion
- #region fonctions
- private string findNewkey()
- {
- Random rand1 = new Random();
- string key = rand1.Next(99999).ToString();
- while (tb_station.FindBykey_sta(key) != null)
- {
- MessageBox.Show(key);
- key = rand1.Next(99999).ToString();
- }
- return key;
- }
- #endregion
- private void combo_pays_sta_SelectedIndexChanged(object sender, EventArgs e)
- {
- Pays cur_Pays=lpays.Find(p => p.key_pays == combo_pays_sta.Text);
- if ( cur_Pays!=null)
- StatusLabel1.Text = cur_Pays.nom_pays;
- else
- StatusLabel1.Text = "...";
- }
- private void bt_Presta_Click(object sender, EventArgs e)
- {
- if ( fpresta==null)
- fpresta = new f_presta(text_key_sta);
- try
- {
- fpresta.Show();
- }
- catch (System.ObjectDisposedException )
- {
- fpresta = new f_presta(text_key_sta);
- fpresta.Show();
- }
-
- }
- private void label11_Click(object sender, EventArgs e)
- {
- }
- private void t_facture_Click(object sender, EventArgs e)
- {
- }
- //if (!File.Exists(Program.subfolder + @"\Facture_Carbu.xlsx"))
- // return;
- //string fileName=Program.subfolder+@"\Facture_"+text_key_sta.Text+".xlsx";
- //File.Copy(Program.subfolder + @"\Facture_Carbu.xlsx", fileName,true);
- //Excel.Application xlApp;
- //Excel.Workbook xlWorkBook;
- //Excel.Worksheet xlWorkSheet;
- //object misValue = System.Reflection.Missing.Value;
- //xlApp = new Excel.Application();
- //xlWorkBook = xlApp.Workbooks.Add(misValue);
- //try
- //{
- // xlApp = new Excel.Application();
- // xlWorkBook = xlApp.Workbooks.Open(fileName, misValue);
- // xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
- //}
- //catch (Exception ex)
- //{
- // MessageBox.Show("Vérifier que le fichier n'est pas ouvert et est un fichier Excel correct", "Ouverture de " + fileName + " impossible", MessageBoxButtons.OK, MessageBoxIcon.Error);
- // return;
- //}
- //xlWorkSheet.Cells[2, 2].Value = text_nom_sta.Text;
- //xlWorkSheet.Cells[3, 2].Value = text_adr1_sta.Text;
- //xlWorkSheet.Cells[4, 2].Value = text_adr2_sta.Text;
- //xlWorkSheet.Cells[5, 2].Value = text_cp_sta.Text+"-"+text_ville_sta.Text;
- //xlWorkSheet.Cells[6, 2].Value = combo_pays_sta.Text;
- //xlWorkSheet.Cells[8, 2].Value = text_tel_sta.Text;
- //xlWorkSheet.Cells[3, 8].Value = DateTime.Now.ToString("Le : dd/MM/yyyy");
- //xlWorkSheet.Cells[14, 2].Value = "Ref : Ravitaillement "+Program.nom_ope+" du "+dt_date_sta.Value.ToString("dd/MM/yy");
- //xlWorkBook.Save();
- //xlApp.Quit();
- }
- }
|