Example #1
0
        private async void UpdateDb_Click(object sender, RoutedEventArgs e)
        {
            //MessageBox.Show(Unloaded.Value.ToString());
            if (Unloaded.Value != 0)
            {
                Double loaded   = double.Parse(loadedmilk1.Text);
                Double unloaded = double.Parse(Unloaded.Value.ToString());
                Double Deficit  = loaded - unloaded;

                if (Deficit < 3.0)
                {
                    Deficit = 0;
                }
                Connection cn = new Connection();
                try{
                    cn.connect();
                    cn.cmd.Connection = cn.cnn;
                    cn.cmd.Connection.Open();
                    cn.cmd.CommandText = "update MilkCreameryDelivery Set Litres_Unloaded='" + unloaded + "', Deficit='" + Deficit + "',Delivered='True' WHERE DATE='" + DateTime.Now.ToShortDateString() + "'";

                    cn.cmd.ExecuteScalar();
                    MessageDialogResult x = new MessageDialogResult();
                    MetroDialogSettings y = new MetroDialogSettings();
                    y.AffirmativeButtonText = "Quit";

                    await this.ShowMessageAsync("Delivery Confirmed", "You have updated the Delivery Successfuly.", MessageDialogStyle.Affirmative, y);

                    if (x.ToString() == "Negative")
                    {
                        this.Close();
                    }
                    //farmerDatagrid.ItemsSource = LoadCollectionData();
                    //ViewFarmersTab.BringIntoView();
                    // clearRegFields();
                }
                catch (Exception ex)
                {
                    displayMetroError(ex);
                    //ShowOverlay();
                    //MessageBox.Show("Registration has Failed! The following Message was generated to explain why \n \n"+ex.Message+"\n \n"+ex.InnerException,"Registration Failure",MessageBoxButton.OK,MessageBoxImage.Error);
                    //HideOverlay();
                }
            }
            else
            {
                Unloaded.Focus();
            }
        }