I am a newbie at programming and I helped my dad with making this program which orders multiple products to a website from a table of Excel.It involves 3 processes:Passing orders from Excel to website by injecting JavaScript.The website provides a function for ordering a product: (in JavaScript)updateProduct('{reference}','0','/products/update'{quantity},110,'divAlertQteDispoMessage',0,900,'divAlertNbRowsMessage');Comparing the product list between the website and the Excel sheet.My current solution is to get all reference id found in website and compare it with the Excel's reference idDeleting products which have been ordered before.Using .cmd according to the reference, we can get the quantity of the product ordered before.Here is the entire class:using System;using System.Collections.Generic;using System.Data;using System.Data.OleDb;using System.Drawing;using System.IO;using System.Linq;using System.Text;using System.Text.RegularExpressions;using System.Threading;using System.Threading.Tasks;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media.Imaging;using System.Windows.Navigation;using System.Windows.Shapes;using Awesomium.Core;using Awesomium.Windows.Controls;using ClosedXML.Excel;using FirstFloor.ModernUI.Windows.Controls;using Brushes = System.Windows.Media.Brushes;using SystemFonts = System.Windows.SystemFonts;namespace ModernUINavigationApp1.Pages{    /// <summary>    /// Interaction logic for Home.xaml    /// </summary>    ///     public partial class Home : UserControl    {        private Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();        public Home()        {            InitializeComponent();            Startup();            MainwebBrowser.ViewType = WebViewType.Offscreen;        }        private async void Startup()        {            await Task.Delay(2000);            while (!MainwebBrowser.IsDocumentReady)            {                await Task.Delay(1000);            }            await Task.Delay(1000);                MainwebBrowser.ExecuteJavascript(       document.getElementById('login_login').value = ' + Properties.Settings.Default.Username + ';);                MainwebBrowser.ExecuteJavascript(                    document.getElementById('login_password').value = ' + Properties.Settings.Default.Password + ';);                    MainwebBrowser.ExecuteJavascript(document.forms['loginForm'].submit());        }        private void BrowseButton_Click(object sender, RoutedEventArgs e)        {            Nullable<bool> result = dlg.ShowDialog();            if (result == true)            {                string filename = dlg.FileName;                TextBoxFile.Text = filename;                DataTable dt = LoadXls(dlg.FileName);                _label.Content = dt.Rows.Count +  Produits;            }        }        public bool _checkcancelled;        private async void CommanderButtonImport_Click(object sender, RoutedEventArgs e)        {            if (string.IsNullOrEmpty(TextBoxFile.Text))            {                MessageBox.Show(                    Vous n'avez pas entr l'emplacement du fichier!, Attention, MessageBoxButton.OK,                    MessageBoxImage.Exclamation);            }            else            {                _checkcancelled = false;                DisableControl();                CommanderButtonImport.IsEnabled = false;                DataTable dt = LoadXls(dlg.FileName);                if (dt != null)                {                    PassProduct(dt);                    //CompareProduct();                }                else                {                    progressBar1.Value = 0;                    EnableControl();                    CommanderButtonImport.IsEnabled = true;                    //  button5.Visible = false;                    //  label4.Text = Annul...;                    await Task.Delay(2000);                    //   label4.Text = Libre;                }            }        }        private async void DeleteProduct()        {            _label2.Content = tape 3 : Supprimmer les produits dupliqus;            _label3.Content = 0 %;            if (string.IsNullOrEmpty(TextBoxFile.Text))            {                MessageBox.Show(                    Vous n'avez pas entr l'emplacement du fichier!, Attention, MessageBoxButton.OK,                    MessageBoxImage.Exclamation);            }            else            {                do                {                    MainwebBrowser.ExecuteJavascript(function GetIsHome() {if (document.getElementById('topNav') != null) { return 'true'; }};);                    if (MainwebBrowser.Source != new Uri(http://www.easyrea.net/cart/detail))                    {                        MainwebBrowser.Source = new Uri(http://www.easyrea.net/cart/detail);                    }                    else                    {                        MainwebBrowser.Reload(true);                    }                    do                    {                        await Task.Delay(1000);                    } while (!MainwebBrowser.IsDocumentReady);                    MainwebBrowser.ExecuteJavascript(           document.getElementById('login_login').value = ' + Properties.Settings.Default.Username + ';);                    MainwebBrowser.ExecuteJavascript(                        document.getElementById('login_password').value = ' + Properties.Settings.Default.Password + ';);                    MainwebBrowser.ExecuteJavascript(document.forms['loginForm'].submit());                    do                    {                        await Task.Delay(1000);                    } while (!MainwebBrowser.IsDocumentReady);                } while ((string)MainwebBrowser.ExecuteJavascriptWithResult(GetIsHome()) != true);            DataTable dt = LoadXls(dlg.FileName);                progressBar1.Value = 0.0;                progressBar1.Maximum = dt.Rows.Count;                foreach (DataRow row in dt.Rows)                {                    if (!_checkcancelled)                    {                        string text = #product + row[Rfrence];                        string cmd =                            MainwebBrowser.ExecuteJavascriptWithResult(                                string.Format($('{0}').find('.cmd').text();, text));                        string existed =                            MainwebBrowser.ExecuteJavascriptWithResult(                                string.Format($('{0}').find('#quantity').text();, text));                        if (cmd !=  & existed != )                        {                            int intcmd;                            bool isintcmd = int.TryParse(Regex.Match(cmd, @\d+).Value, out intcmd);                            int intexisted;                            bool isintexisted = int.TryParse(existed, out intexisted);                            if (isintcmd & isintexisted)                            {                                if (intcmd >= intexisted)                                {                                    MainwebBrowser.ExecuteJavascriptWithResult(                                        string.Format(                                            updateCartProduct('{0}','0','/cart/update',-{1},'72','1',0.65, 1),                                            row[Rfrence], intexisted));                                }                                else if (intcmd < intexisted)                                {                                    int inttobesubed = intexisted - (intexisted - intcmd);                                    MainwebBrowser.ExecuteJavascriptWithResult(                                        string.Format(                                            updateCartProduct('{0}','0','/cart/update',-{1},'72','1',0.65, 1),                                            row[Rfrence], inttobesubed));                                }                            }                        }                        progressBar1.Value++;                        int percent = (int)(progressBar1.Value / progressBar1.Maximum * 100);                        _label3.Content = percent +  %;                    }                    else                    {                        progressBar1.Value = 0;                        EnableControl();                        _label3.Content = ;                        _label2.Content = Annul...;                        await Task.Delay(2000);                        _label2.Content = Libre;                        deleteProductSuccess = false;                        CommanderButtonImport.IsEnabled = true;                        break;                    }                    deleteProductSuccess = true;                    await Task.Delay(1000);                }                if (!deleteProductSuccess)                {                    progressBar1.Value = 0;                    EnableControl();                    CommanderButtonImport.IsEnabled = true;                      _label3.Content = ;                      _label2.Content = Annul...;                    await Task.Delay(2000);                      _label2.Content = Libre;                }                else                {                    progressBar1.Value = 0;                    EnableControl();                    CommanderButtonImport.IsEnabled = true;                    MainwebBrowser.Reload(false);                    await Task.Delay(5000);                    _label2.Content = Libre;                    _label3.Content = ;                    if (                        ModernDialog1.ShowMessage(                            L'Opration est termine. + Environment.NewLine +                            Voulez-vous ouvrir la ficher excel pour les produits manquant?, Termine,                            MessageBoxButton.YesNo) == MessageBoxResult.Yes)                    {                        System.Diagnostics.Process.Start(missingproduct.xlsx);                    }                }            }        }        private DataTable LoadXls(string strFile)        {            var dtXLS = new DataTable(importedexcel);            try            {                string strConnectionString = ;                if (strFile.Trim().EndsWith(.xlsx))                {                    strConnectionString =                        string.Format(                            Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\Excel 12.0 Xml;HDR=YES;IMEX=1\;,                            strFile);                }                else if (strFile.Trim().EndsWith(.xls))                {                    strConnectionString =                        string.Format(                            Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=\Excel 8.0;HDR=Yes;IMEX=1\;,                            strFile);                }                var SQLConn = new OleDbConnection(strConnectionString);                SQLConn.Open();                var SQLAdapter = new OleDbDataAdapter();                DataTable dtSchema = SQLConn.GetOleDbSchemaTable(                    OleDbSchemaGuid.Tables, new object[] { null, null, null, TABLE });                string Sheet1 = dtSchema.Rows[0].Field<string>(TABLE_NAME);                string sql = string.Format(SELECT * FROM [{0}], Sheet1);                var selectCMD = new OleDbCommand(sql, SQLConn);                SQLAdapter.SelectCommand = selectCMD;                SQLAdapter.Fill(dtXLS);                SQLConn.Close();            }            catch (Exception ex)            {                progressBar1.Maximum = 0;                MessageBox.Show(                    Le fichier excel est en cour d'utilisation, il faut le fermer pour que nous puissions l'utiliser. +                    ex.ToString());                dtXLS = null;            }            return dtXLS;        }        private void DisableControl()        {            mainTabControl.IsEnabled = false;        }        private void EnableControl()        {            mainTabControl.IsEnabled = true;        }        private bool passProductSuccess;        private bool deleteProductSuccess;        private bool compareProductSuccess;        private async void PassProduct(DataTable dt)        {            _label2.Content = tape 1 : Passer les produits;            _label3.Content = 0 %;            MainwebBrowser.ExecuteJavascript(window.alert = function() {};);            progressBar1.Value = 0.0;            progressBar1.Maximum = dt.Rows.Count;            foreach (DataRow row in dt.Rows)            {                string text = row[Rfrence].ToString();                string qtestring = row[Nb# Colis].ToString();                int qte;                int.TryParse(qtestring, out qte);                if (text.Any(char.IsDigit) & _checkcancelled == false)                {                    if (qte < 1 || qte > 0)                    {                        qte = 1;                    }                    MainwebBrowser.ExecuteJavascript(                        string.Format(                            updateProduct('{0}','0','/products/update',{1},110,'divAlertQteDispoMessage',0,900,'divAlertNbRowsMessage');,                            text, qte));                    //    label5.Text = Sur:;                    //     label4.Text = row[Libell].ToString();                    //    label3.Text = text;                    await Task.Delay(2500);                    progressBar1.Value++;                    int percent = (int) (progressBar1.Value / progressBar1.Maximum * 100);                    _label3.Content = percent +  %;                }                else                {                    progressBar1.Value = 0;                    EnableControl();                    _label3.Content = ;                    _label2.Content = Annul...;                    await Task.Delay(2000);                    _label2.Content = Libre;                    passProductSuccess = false;                    break;                }                passProductSuccess = true;            }            if (passProductSuccess)            {                _label2.Content = tape 1.5 : Attendre la systeme de JJA...;                _label3.Content = 20 secondes restant;                progressBar1.Value = 0.0;                progressBar1.Maximum = 20;                for (int a = 0; a < 20; a = a + 1)                {                    await Task.Delay(1000);                    progressBar1.Value++;                    _label3.Content = 20 - a +  secondes restant;                }                CompareProduct();             }            else            {                CommanderButtonImport.IsEnabled = true;                progressBar1.Value = 0;                EnableControl();                _label3.Content = ;                _label2.Content = Annul...;                await Task.Delay(2000);                _label2.Content = Libre;            }        }        private async void CompareProduct()        {            progressBar1.Value = 0.0;            _label2.Content = tape 2 : Exporter les produits manqants au fichier Excel;            _label3.Content = 0 %;            if (string.IsNullOrEmpty(TextBoxFile.Text))            {                MessageBox.Show(                    Vous n'avez pas entr l'emplacement du fichier!, Attention, MessageBoxButton.OK,                    MessageBoxImage.Exclamation);            }            else            {                do                {                        MainwebBrowser.Source = new Uri(http://www.easyrea.net/cart/detail);                    do                    {                        await Task.Delay(1000);                    } while (!MainwebBrowser.IsDocumentReady);                    MainwebBrowser.ExecuteJavascript(           document.getElementById('login_login').value = ' + Properties.Settings.Default.Username + ';);                    MainwebBrowser.ExecuteJavascript(                        document.getElementById('login_password').value = ' + Properties.Settings.Default.Password + ';);                    MainwebBrowser.ExecuteJavascript(document.forms['loginForm'].submit());                    await Task.Delay(2000);                    MainwebBrowser.ExecuteJavascript(function GetIsHome() {if (document.getElementById('topNav') != null) { return 'true'; }};);                } while ((string)MainwebBrowser.ExecuteJavascriptWithResult(GetIsHome();) != true);                await Task.Delay(5000);                DataTable dt = LoadXls(dlg.FileName);                progressBar1.Maximum = dt.Rows.Count;                DataTable missingProductTable = new DataTable();                missingProductTable.Columns.Add(Libell, typeof(String));                missingProductTable.Columns.Add(Rfrence, typeof(String));                missingProductTable.Columns.Add(Codein, typeof(String));                missingProductTable.Columns.Add(Gencode, typeof(String));                foreach (DataRow row in dt.Rows)                {                    if (!_checkcancelled)                    {                        string text = row[Rfrence].ToString();                        string name = row[Libell].ToString();                        string code = row[Codein].ToString();                        string gene = row[Gencode].ToString();                        string caps = text.ToUpper();                        if (caps.Any(char.IsDigit) & _checkcancelled == false)                        {                            MainwebBrowser.ExecuteJavascript(                                function GetMissingProduct() {if (document.getElementById('product + caps +                                ') == null) { return 'true'; }};);                            var missingProduct =                                (string) MainwebBrowser.ExecuteJavascriptWithResult(GetMissingProduct());                            if (missingProduct == true)                            {                                DataRow missingProductRow = missingProductTable.NewRow();                                missingProductRow[Libell] = name;                                missingProductRow[Rfrence] = text;                                missingProductRow[Codein] = code;                                missingProductRow[Gencode] = gene;                                missingProductTable.Rows.Add(missingProductRow);                            }                        }                        await Task.Delay(500);                    }                    else                    {                        progressBar1.Value = 0;                        EnableControl();                        _label3.Content = ;                        _label2.Content = Annul...;                        await Task.Delay(2000);                        _label2.Content = Libre;                        compareProductSuccess = false;                        MessageBox.Show(Failed);                        CommanderButtonImport.IsEnabled = true;                        break;                    }                    progressBar1.Value++;                    int percent = (int)(progressBar1.Value / progressBar1.Maximum * 100);                    _label3.Content = percent +  %;                }                XLWorkbook wb = new XLWorkbook();                wb.Worksheets.Add(missingProductTable, Produit Manquant);                wb.SaveAs(missingproduct.xlsx);                compareProductSuccess = true;                if (compareProductSuccess)                {                    DeleteProduct();                }                else                {                    CommanderButtonImport.IsEnabled = true;                    progressBar1.Value = 0;                    EnableControl();                    _label3.Content = ;                    _label2.Content = Annul...;                    await Task.Delay(2000);                    _label2.Content = Libre;                }            }        }    }}Remark: CommanderButtonImport is a button for triggering everything.Please provide some comments because I feel like it is unorganized but I don't know where to start.
Injecting JavaScript to website for ordering products
c#;javascript;beginner;excel;wpf