public outDelivery()
        {
            InitializeComponent();

            Connection cn = new Connection();
            Utilities ut = new Utilities();
            
            try
            {
                
                cn.connect();


                cn.cmd.Connection = cn.cnn;
                cn.cmd.Connection.Open();
                cn.cmd.CommandText = "SELECT Delivered FROM MilkCreameryDelivery WHere Date='" + DateTime.Now.ToShortDateString() + "' AND TimeOfDay='" + ut.TimeOfDay() + "'";
                object x=cn.cmd.ExecuteScalar();
                if (x==null)
                {
                    
                }else
                {
                   
                lock_load= bool.Parse(cn.cmd.ExecuteScalar().ToString());
              
                }
              
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            fillStaff();
                    fillTransporter();
        }
Ejemplo n.º 2
0
        private  async void fillCombo()
        {
            Utilities f=new Utilities();
            farmerNumber.Items.Clear();
             Connection cn = new Connection();
              cn.connect();
            cn.cmd.Connection = cn.cnn;
            cn.cmd.Connection.Open();
            cn.cmd.CommandText = "select FarmerNo from Farmer where FarmerNo NOT  IN (Select farmerNo from MilkDelivery where DateOfDelivery = '"+DateTime.Now.ToShortDateString()+"' And TimeofDay='"+f.TimeOfDay()+"')";
            try
            {
         
                cn.dr = cn.cmd.ExecuteReader();
                while (cn.dr.Read())
                {



                    farmerNumber.Items.Add(cn.dr.GetString(0));
                    
                }
            } catch(Exception ex){
                MessageBox.Show(ex.Message);
            }
            if (farmerNumber.Items.Count != 0)
            { 
                farmerNumber.SelectedIndex = 0; 
                fillName();
          
            }
            else
            {
                
                MessageDialogResult x;
                MetroDialogSettings yl=new MetroDialogSettings();
             
               
                yl.AffirmativeButtonText="Quit";
                yl.NegativeButtonText = "View Deliveries";
                x=await this.ShowMessageAsync("Entry Complete!", "All Farmers with Valid Farmer Numbers have been Processed. any other processing will have to be done Manualy",MessageDialogStyle.AffirmativeAndNegative,yl);
                if (x == MessageDialogResult.Affirmative)
                {
                    
                    this.Hide();
                }
                
                   
                    
                
                
            
            }
        
        }
        private List<FarmerReport> LoadCollectionData()
        {

            List<FarmerReport> farmerCollection = new List<FarmerReport>();


            Connection cn = new Connection();
            cn.connect();
            cn.cmd.Connection = cn.cnn;
            cn.cmd.Connection.Open();
            MessageBox.Show(x);
            cn.cmd.CommandText = "Select TimeOfDelivery,TimeOfDay,FarmerMilkDelivery,BoughtAt,ReceivedBy From MilkDelivery where FarmerNo='" + x.ToUpper() + "'";
            try
            {

                cn.dr = cn.cmd.ExecuteReader();
                while (cn.dr.Read())
                {

                    farmerCollection.Add(new FarmerReport()
                    {
                       
                        TimeOfDelivery = cn.dr.GetTimeSpan(0),
                        TimeOfDay = cn.dr.GetString(1),
                        Delivery = cn.dr.GetFloat(2),
                        BuyingPrice = cn.dr.GetDouble(3),
                        ReceivedBy = cn.dr.GetString(4),


                    });









                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);

            }



            return farmerCollection;
        }
Ejemplo n.º 4
0
 private void initializeDB()
 {
     try
     {
         apps.Connection cn = new apps.Connection();
         cn.connect();
         cn.cnn.Open();
         cn.cnn.Close();
     }
     catch (Exception ex)
     {
         string x = ex.Message;
     }
 }
Ejemplo n.º 5
0
        private async void AddDelivery_Click(object sender, RoutedEventArgs e)
        {
            Connection cn         = new Connection();
            String     DeliveryID = IdGen();
            float      Loaded     = float.Parse(loadedmilk.Text);
            float      UnLoaded   = 0;
            float      Deficit    = Loaded - UnLoaded;
            String     Supplier   = suppliercombo.SelectedItem.ToString();
            String     DelVehicle = Vehicle.Text;
            String     DOD        = DateTime.Now.ToShortDateString();
            String     driver     = Driver.Text;
            String     conductor  = Conductor.Text;
            String     StaffName  = staffcombo.SelectedItem.ToString();
            Utilities  f          = new Utilities();

            try
            {
                //MessageBox.Show(cn.connectionString);
                cn.connect();
                cn.cmd.Connection = cn.cnn;
                cn.cmd.Connection.Open();
                cn.cmd.CommandText = "INSERT INTO MilkCreameryDelivery(DeliveryID,Date,timeofday,Litres_loaded,Litres_Unloaded,Deficit,Loader,Driver,Conductor,Vehicle,Supplier,Delivered) VALUES('" + DeliveryID + "','" + DOD + "','" + f.TimeOfDay() + "','" + Loaded + "','" + UnLoaded + "','" + Deficit + "','" + StaffName + "','" + driver + "','" + conductor + "','" + DelVehicle + "','" + Supplier + "','0')";

                cn.cmd.ExecuteNonQuery();
                MessageDialogResult x = new MessageDialogResult();
                MetroDialogSettings y = new MetroDialogSettings();
                y.AffirmativeButtonText = "Go to Delivery Tab";
                y.NegativeButtonText    = "Close";

                x = await this.ShowMessageAsync("Delivery Added", "You have Added the Delivery Successfuly. Upon return, the Transporter(" + Supplier + ") Must enter milk unloaded at the creamery in the next Tab", MessageDialogStyle.AffirmativeAndNegative, y);

                if (x.ToString() == "Negative")
                {
                    this.Close();
                }
                else
                {
                    loadEdatCoop.IsEnabled = false;
                    fillTodayDelivery();
                    tabC.SelectedIndex = 1;
                }
                //farmerDatagrid.ItemsSource = LoadCollectionData();
                //ViewFarmersTab.BringIntoView();
                // clearRegFields();
            }
            catch (Exception ex)
            {
                displayMetroError(ex);
            }
        }
Ejemplo n.º 6
0
 private  void initializeDB()
 {
     try
     {
         apps.Connection cn = new apps.Connection();
         cn.connect();
         cn.cnn.Open();
         cn.cnn.Close();
     }
     catch (Exception ex)
     {
         string x=ex.Message;
     }
 }
Ejemplo n.º 7
0
        private async void registerFarmersDelivery_Click(object sender, RoutedEventArgs e)
        {
            if (farmerNumber.Items.Count != 0)
            {
                Connection cn       = new Connection();
                double     delivery = (double)deliveryNum.Value;
                delivery = System.Math.Round(delivery, 2);
                string deliveryhash = farmerNumber.Text.ToUpper() + DateTime.Now.ToShortDateString() + DateTime.Now.ToShortTimeString();
                try
                {
                    //MessageBox.Show(cn.connectionString);
                    Utilities f = new Utilities();
                    cn.connect();
                    cn.cmd.Connection = cn.cnn;
                    cn.cmd.Connection.Open();
                    cn.cmd.CommandText = "insert into MilkDelivery(FarmerHash,FarmerNo,FarmerName,FarmerMilkDelivery,DateOfDelivery,timeofdelivery,timeofday,BoughtAt,ReceivedBy) VALUES('" + deliveryhash + "','" + farmerNumber.Text + "','" + farmerName + "','" + delivery + "','" + DateTime.Now.ToShortDateString() + "','" + DateTime.Now.ToLongTimeString() + "','" + f.TimeOfDay() + "','" + buyingPrice + "','SELF')";
                    //MessageBox.Show( "insert into MilkDelivery(FarmerHash,FarmerNo,FarmerName,FarmerMilkDelivery,DateOfDelivery,timeofdelivery,timeofday,BoughtAt,ReceivedBy) VALUES('" + deliveryhash + "','" + farmerNumber.Text + "','" + farmerName + "','" + delivery + "','" + DateTime.Now.ToShortDateString() + "','"+DateTime.Now.ToLongTimeString()+"','"+f.TimeOfDay()+"','" + buyingPrice + "','SELF')");

                    cn.cmd.ExecuteNonQuery();
                    await this.ShowMessageAsync("Delivery Registered!", "You have entered a milk delivery of " + delivery + " kg's for " + farmerNumber.Text + " Bought at Sh" + buyingPrice + "", MessageDialogStyle.Affirmative, null);

                    deliveryNum.Value        = 0;
                    deliveryGrid.ItemsSource = LoadCollection();
                    fillCombo();
                }
                catch (Exception ex)
                {
                    ShowOverlay();
                    MessageBox.Show(ex.Message);//"Entry Failed! Most probable cause for this is that "+farmerName+ "'s has already delivered milk today", "Entry Failure", MessageBoxButton.OK, MessageBoxImage.Error);
                    HideOverlay();
                }
            }
            else
            {
                MessageDialogResult x;
                MetroDialogSettings yl = new MetroDialogSettings();


                yl.AffirmativeButtonText = "Quit";
                x = await this.ShowMessageAsync("Entry Complete!", "All Farmers with Valid Farmer Numbers have been Processed. any other processing will have to be done Manualy", MessageDialogStyle.Affirmative, yl);

                if (x == MessageDialogResult.Affirmative)
                {
                    MessageBox.Show("t");
                    this.Close();
                }
            }
        }
Ejemplo n.º 8
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();
            }
        }
        private void totalMilk(DateTime TotalDate)
        {
            if (blovkLoop == false)
            {
                float totalmilk = 0;
                String obj;
                Utilities ut = new Utilities();
                Connection cn = new Connection();
                try
                {

                    cn.connect();


                    cn.cmd.Connection = cn.cnn;
                    cn.cmd.Connection.Open();
                    cn.cmd.CommandText = "Select sum(FarmerMilkDelivery) from MilkDelivery Where DateOfDelivery='" + TotalDate + "' AND TimeofDay='"+ut.TimeOfDay()+"' AND DateOfDelivery NOT IN(SELECT Date FROM MilkCreameryDelivery WHere Date='" + TotalDate + "' AND TimeOfDay='"+ut.TimeOfDay()+"' )";
                    obj = cn.cmd.ExecuteScalar().ToString();
                    if (obj == "")
                    {
                        
                        obj = "0";
                        notifyDelivery();
                        loadEdatCoop.IsEnabled = false;
                        fillTodayDelivery();
                        tabC.SelectedIndex = 1;

                    }
                    else
                    {
                        totalmilk = float.Parse(obj);
                    }
                }
                catch (Exception ex)
                {
                    displayMetroError(ex);
                    System.Diagnostics.Debugger.Log(0, "db Error", ex.Message);

                    totalmilk = 0;
                }

                loadedmilk.Text = totalmilk.ToString();
                blovkLoop = true;
            }
        }
Ejemplo n.º 10
0
        private async void fillCombo()
        {
            Utilities f = new Utilities();

            farmerNumber.Items.Clear();
            Connection cn = new Connection();

            cn.connect();
            cn.cmd.Connection = cn.cnn;
            cn.cmd.Connection.Open();
            cn.cmd.CommandText = "select FarmerNo from Farmer where FarmerNo NOT  IN (Select farmerNo from MilkDelivery where DateOfDelivery = '" + DateTime.Now.ToShortDateString() + "' And TimeofDay='" + f.TimeOfDay() + "')";
            try
            {
                cn.dr = cn.cmd.ExecuteReader();
                while (cn.dr.Read())
                {
                    farmerNumber.Items.Add(cn.dr.GetString(0));
                }
            } catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
            if (farmerNumber.Items.Count != 0)
            {
                farmerNumber.SelectedIndex = 0;
                fillName();
            }
            else
            {
                MessageDialogResult x;
                MetroDialogSettings yl = new MetroDialogSettings();


                yl.AffirmativeButtonText = "Quit";
                yl.NegativeButtonText    = "View Deliveries";
                x = await this.ShowMessageAsync("Entry Complete!", "All Farmers with Valid Farmer Numbers have been Processed. any other processing will have to be done Manualy", MessageDialogStyle.AffirmativeAndNegative, yl);

                if (x == MessageDialogResult.Affirmative)
                {
                    this.Hide();
                }
            }
        }
Ejemplo n.º 11
0
        private void totalMilk(DateTime TotalDate)
        {
            if (blovkLoop == false)
            {
                float      totalmilk = 0;
                String     obj;
                Utilities  ut = new Utilities();
                Connection cn = new Connection();
                try
                {
                    cn.connect();


                    cn.cmd.Connection = cn.cnn;
                    cn.cmd.Connection.Open();
                    cn.cmd.CommandText = "Select sum(FarmerMilkDelivery) from MilkDelivery Where DateOfDelivery='" + TotalDate + "' AND TimeofDay='" + ut.TimeOfDay() + "' AND DateOfDelivery NOT IN(SELECT Date FROM MilkCreameryDelivery WHere Date='" + TotalDate + "' AND TimeOfDay='" + ut.TimeOfDay() + "' )";
                    obj = cn.cmd.ExecuteScalar().ToString();
                    if (obj == "")
                    {
                        obj = "0";
                        notifyDelivery();
                        loadEdatCoop.IsEnabled = false;
                        fillTodayDelivery();
                        tabC.SelectedIndex = 1;
                    }
                    else
                    {
                        totalmilk = float.Parse(obj);
                    }
                }
                catch (Exception ex)
                {
                    displayMetroError(ex);
                    System.Diagnostics.Debugger.Log(0, "db Error", ex.Message);

                    totalmilk = 0;
                }

                loadedmilk.Text = totalmilk.ToString();
                blovkLoop       = true;
            }
        }
Ejemplo n.º 12
0
        private void fillTransporter()
        {
            Connection cn = new Connection();

            cn.connect();
            cn.cmd.Connection = cn.cnn;
            cn.cmd.Connection.Open();
            cn.cmd.CommandText = "select SupplierName from Supplier";
            try
            {
                cn.dr = cn.cmd.ExecuteReader();
                while (cn.dr.Read())
                {
                    suppliercombo.Items.Add(cn.dr.GetString(0));
                }
            } catch (Exception ex) {
                displayMetroError(ex);
            }
            fillTransporterDetails();
        }
Ejemplo n.º 13
0
        private void fillStaff()
        {
            staffcombo.Items.Clear();
            Connection cn = new Connection();

            cn.connect();
            cn.cmd.Connection = cn.cnn;
            cn.cmd.Connection.Open();
            cn.cmd.CommandText = "select StaffName from Staff Where Active='True'";
            try
            {
                cn.dr = cn.cmd.ExecuteReader();
                while (cn.dr.Read())
                {
                    staffcombo.Items.Add(cn.dr.GetString(0));
                }
            } catch (Exception ex) {
                displayMetroError(ex);
            }
        }
Ejemplo n.º 14
0
        private String IdGen()
        {
            Connection cn = new Connection();

            String pattID = "", Prodid = "";
            int Temp1 = 0;


            String k = DateTime.Now.Year.ToString();
        Start:
            Temp1 += 1;
            Prodid = "KDFC/SUPPLIER/";

            try
            {

                cn.connect();
                pattID = Prodid + Temp1 + k;
                String CheckString;
                cn.cmd.Connection = cn.cnn;
                cn.cmd.Connection.Open();
                cn.cmd.CommandText = "Select top 1 supplierNo from Supplier Where supplierNo='" + pattID + "' Order By supplierNo DESC";
                CheckString = cn.cmd.ExecuteScalar().ToString();
                if (CheckString == null)
                {
                    return Temp1.ToString();
                }
                else goto Start;


            }
            catch (Exception ex)
            {
                System.Diagnostics.Debugger.Log(0, "db Error", ex.Message);


            }

            return pattID;
        }
Ejemplo n.º 15
0
        private List <Staff> LoadCollectionData()
        {
            List <Staff> farmer = new List <Staff>();
            Connection   cn     = new Connection();

            cn.connect();
            cn.cmd.Connection = cn.cnn;
            try { cn.cmd.Connection.Open(); }
            finally { }
            cn.cmd.CommandText = "Select * From Staff";
            try
            {
                cn.dr = cn.cmd.ExecuteReader();
                while (cn.dr.Read())
                {
                    farmer.Add(new Staff()
                    {
                        StaffNo  = cn.dr.GetString(0),
                        staff    = cn.dr.GetString(1),
                        IDNumber = int.Parse(cn.dr.GetString(4)),
                        Phone    = cn.dr.GetString(2),
                        DOE      = cn.dr.GetDateTime(5),
                        Bank     = cn.dr.GetString(8),
                        Bankacc  = cn.dr.GetString(7),
                        isActive = cn.dr.GetBoolean(6),
                        nhif     = cn.dr.GetString(9),
                        kra      = cn.dr.GetString(10)
                    });
                }
            }
            catch (Exception ex)
            {
                ShowOverlay();
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                HideOverlay();
            }


            return(farmer);
        }
Ejemplo n.º 16
0
        private String IdGen()
        {
            Connection cn = new Connection();

            String pattID = "", Prodid = "";
            int    Temp1 = 0;


            String k = DateTime.Now.Year.ToString();

Start:
            Temp1 += 1;
            Prodid = "KDFC/STAFF/";

            try
            {
                cn.connect();
                pattID = Prodid + Temp1 + k;
                String CheckString;
                cn.cmd.Connection = cn.cnn;
                cn.cmd.Connection.Open();
                cn.cmd.CommandText = "Select top 1 staffNo from Staff Where staffNo='" + pattID + "' Order By staffNo DESC";
                CheckString        = cn.cmd.ExecuteScalar().ToString();
                if (CheckString == null)
                {
                    return(Temp1.ToString());
                }
                else
                {
                    goto Start;
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debugger.Log(0, "db Error", ex.Message);
            }

            return(pattID);
        }
Ejemplo n.º 17
0
        private List <Farmer> LoadCollectionData()
        {
            List <Farmer> farmer = new List <Farmer>();
            Connection    cn     = new Connection();

            cn.connect();
            cn.cmd.Connection = cn.cnn;
            cn.cmd.Connection.Open();
            cn.cmd.CommandText = "Select * From Farmer";
            try
            {
                cn.dr = cn.cmd.ExecuteReader();
                while (cn.dr.Read())
                {
                    farmer.Add(new Farmer()
                    {
                        farmerNO           = cn.dr.GetString(0),
                        farmerName         = cn.dr.GetString(1),
                        farmerID           = int.Parse(cn.dr.GetString(5)),
                        phoneNumber        = cn.dr.GetString(2),
                        dateOfRegistration = cn.dr.GetDateTime(6),
                        Bank      = cn.dr.GetString(9),
                        BankNum   = cn.dr.GetString(8),
                        isActive  = cn.dr.GetBoolean(7),
                        nextOfKin = cn.dr.GetString(4),
                    });
                }
            }
            catch (Exception ex)
            {
                ShowOverlay();
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                HideOverlay();
            }


            return(farmer);
        }
Ejemplo n.º 18
0
        private List <inDelivery> LoadCollection()
        {
            List <inDelivery> farmerCollection = new List <inDelivery>();


            Connection cn = new Connection();

            cn.connect();
            cn.cmd.Connection = cn.cnn;
            cn.cmd.Connection.Open();
            cn.cmd.CommandText = "Select FarmerNo,FarmerName,TimeOfDelivery,TimeOfDay,FarmerMilkDelivery,BoughtAt,ReceivedBy From MilkDelivery where DateOfDelivery='" + DateTime.Now.ToShortDateString() + "'";
            try
            {
                cn.dr = cn.cmd.ExecuteReader();
                while (cn.dr.Read())
                {
                    farmerCollection.Add(new inDelivery()
                    {
                        FarmerNO       = cn.dr.GetString(0),
                        FarmerName     = cn.dr.GetString(1),
                        TimeOfDelivery = cn.dr.GetTimeSpan(2),
                        TimeOfDay      = cn.dr.GetString(3),
                        Delivery       = cn.dr.GetFloat(4),
                        BuyingPrice    = cn.dr.GetDouble(5),
                        ReceivedBy     = cn.dr.GetString(6),
                    });
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }



            return(farmerCollection);
        }
Ejemplo n.º 19
0
        private async void RegisterTransporter_Click(object sender, RoutedEventArgs e)
        {
            Connection cn       = new Connection();
            String     SupNo    = txtSupno.Text;
            String     SupName  = txtsupName.Text.ToUpper();
            String     Phone    = txtSupPhone.Text;
            int        IDNumber = Int32.Parse(txtsupId.Text);
            String     vehicle  = travehicle.Text.ToUpper() + "(" + travehicleType.Text.ToUpper() + ")";
            String     Driver   = tradriver.Text.ToUpper();
            String     TurnBoy  = traTurnBoy.Text.ToUpper();
            String     DOR      = DateTime.Now.ToShortDateString();
            String     Bankacc  = bankacc.Text;
            String     Bank     = banklist.Text.ToUpper();
            Boolean    isActive = isActivestatus;

            try
            {
                //MessageBox.Show(cn.connectionString);
                cn.connect();
                cn.cmd.Connection = cn.cnn;
                cn.cmd.Connection.Open();
                cn.cmd.CommandText = "insert into Supplier(SupplierNo,SupplierName,SupplierID,DOR,SupplierTelNo,SupplierBank,SupplierBankacc,SupplierActive,Misc1,Misc2,Misc3) Values('" + SupNo + "','" + SupName + "','" + IDNumber + "','" + DOR + "','" + Phone + "','" + Bank + "','" + Bankacc + "','" + isActive + "','" + vehicle + "','" + Driver + "','" + TurnBoy + "')";
                cn.cmd.ExecuteNonQuery();
                await this.ShowMessageAsync("Registration is a Success", " The Transporter has been entered into the system Successfuly", MessageDialogStyle.Affirmative, null);

                //farmerDatagrid.ItemsSource = LoadCollectionData();
                //ViewFarmersTab.BringIntoView();
                // clearRegFields();
            }
            catch (Exception 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();
            }
            this.Close();
        }
Ejemplo n.º 20
0
        private List <FarmerReport> LoadCollectionData()
        {
            List <FarmerReport> farmerCollection = new List <FarmerReport>();


            Connection cn = new Connection();

            cn.connect();
            cn.cmd.Connection = cn.cnn;
            cn.cmd.Connection.Open();
            MessageBox.Show(x);
            cn.cmd.CommandText = "Select TimeOfDelivery,TimeOfDay,FarmerMilkDelivery,BoughtAt,ReceivedBy From MilkDelivery where FarmerNo='" + x.ToUpper() + "'";
            try
            {
                cn.dr = cn.cmd.ExecuteReader();
                while (cn.dr.Read())
                {
                    farmerCollection.Add(new FarmerReport()
                    {
                        TimeOfDelivery = cn.dr.GetTimeSpan(0),
                        TimeOfDay      = cn.dr.GetString(1),
                        Delivery       = cn.dr.GetFloat(2),
                        BuyingPrice    = cn.dr.GetDouble(3),
                        ReceivedBy     = cn.dr.GetString(4),
                    });
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }



            return(farmerCollection);
        }
Ejemplo n.º 21
0
        private void fillTransporterDetails()
        {
            Connection cn = new Connection();

            cn.connect();
            cn.cmd.Connection = cn.cnn;
            cn.cmd.Connection.Open();
            cn.cmd.CommandText = "Select Misc3,Misc2,Misc1 From Supplier Where SupplierActive='True' AND SupplierName='" + suppliercombo.Text + "'";
            try
            {
                cn.dr = cn.cmd.ExecuteReader();
                while (cn.dr.Read())
                {
                    Driver.Text    = (cn.dr.GetString(1));
                    Conductor.Text = (cn.dr.GetString(0));
                    Vehicle.Text   = (cn.dr.GetString(2));
                    //MessageBox.Show(cn.dr.GetString(0) + cn.dr.GetString(1) + cn.dr.GetString(2));
                }
            }
            catch (Exception ex)
            {
                displayMetroError(ex);
            }
        }
Ejemplo n.º 22
0
        private async void btnRegisterStaff_Click(object sender, RoutedEventArgs e)
        {
            Connection cn       = new Connection();
            String     StaffNo  = txtregNo.Text;
            String     Staff    = firstName.Text + " " + surName.Text;//FarmerFName.Text+" "+FarmerOtherName.Text;
            String     Phone    = phoneNumber.Text;
            int        IDNumber = Int32.Parse(idNumber.Text);
            String     kra      = krapin.Text.ToUpper();
            String     nhif     = nhifno.Text.ToUpper();
            String     DOE      = DateTime.Now.ToShortDateString();
            String     Bankacc  = accountnumber.Text;
            String     Bank     = banklist.Text.ToUpper();

            MessageBox.Show(isActivestatus.ToString());
            try
            {
                //MessageBox.Show(cn.connectionString);
                cn.connect();
                cn.cmd.Connection = cn.cnn;
                cn.cmd.Connection.Open();
                cn.cmd.CommandText = "insert into Staff(staffNo,staffName,PhoneNumber,staffID,Date_of_Employment,Active,AccountNo,Bank,kraPIN,nhifNo) VALUES('" + StaffNo.ToUpper() + "','" + Staff.ToUpper() + "','" + Phone.ToUpper() + "','" + IDNumber + "','" + DOE + "','" + isActivestatus.ToString() + "','" + Bankacc + "','" + Bank + "','" + kra.ToUpper() + "','" + nhif.ToUpper() + "')";
                cn.cmd.ExecuteNonQuery();
                await this.ShowMessageAsync("Registration is a Success", "You have Registered " + Staff.ToUpper() + " Successfuly", MessageDialogStyle.Affirmative, null);

                staffDatagrid.ItemsSource = LoadCollectionData();
                //farmerDatagrid.ItemsSource = LoadCollectionData();
                //ViewFarmersTab.BringIntoView();
                clearRegFields();
            }
            catch (Exception 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();
            }
        }
Ejemplo n.º 23
0
        private string checkNumber(String Check)
        {
            Connection cn          = new Connection();
            String     CheckString = "";

            try
            {
                cn.connect();

                cn.cmd.Connection = cn.cnn;
                cn.cmd.Connection.Open();
                cn.cmd.CommandText = "Select FarmerNo from Farmer Where FarmerNo='" + Check + "' ";
                CheckString        = cn.cmd.ExecuteScalar().ToString();
                if (CheckString == null)
                {
                    return("");
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debugger.Log(0, "db Error", ex.Message);
            }
            return(CheckString);
        }
Ejemplo n.º 24
0
        private void suppliercombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Driver.Clear();
            Conductor.Clear();
            Vehicle.Clear();
            Connection cn = new Connection();
            cn.connect();
            cn.cmd.Connection = cn.cnn;
            cn.cmd.Connection.Open();
            cn.cmd.CommandText = "Select Misc3,Misc2,Misc1 From Supplier Where SupplierActive='True' and SupplierName='" + suppliercombo.SelectedItem.ToString() + "'";
            try
            {

                cn.dr = cn.cmd.ExecuteReader();
                while (cn.dr.Read())
                {
                    Driver.Text = (cn.dr.GetString(1));
                    Conductor.Text = (cn.dr.GetString(0));
                    Vehicle.Text = (cn.dr.GetString(2));
                   // MessageBox.Show(cn.dr.GetString(0) + cn.dr.GetString(1) + cn.dr.GetString(2));
                }
            }
            catch (Exception ex)
            {
                displayMetroError(ex);
            }
           
        }
Ejemplo n.º 25
0
        private async void registerFarmersDelivery_Click(object sender, RoutedEventArgs e)
        {
            if (farmerNumber.Items.Count != 0)
            {
                Connection cn = new Connection();
                double delivery = (double)deliveryNum.Value;
                delivery = System.Math.Round(delivery, 2);
                string deliveryhash = farmerNumber.Text.ToUpper() + DateTime.Now.ToShortDateString()+DateTime.Now.ToShortTimeString();
              try
                {
                    //MessageBox.Show(cn.connectionString);
                    Utilities f=new Utilities();
                    cn.connect();
                    cn.cmd.Connection = cn.cnn;
                    cn.cmd.Connection.Open();
                    cn.cmd.CommandText = "insert into MilkDelivery(FarmerHash,FarmerNo,FarmerName,FarmerMilkDelivery,DateOfDelivery,timeofdelivery,timeofday,BoughtAt,ReceivedBy) VALUES('" + deliveryhash + "','" + farmerNumber.Text + "','" + farmerName + "','" + delivery + "','" + DateTime.Now.ToShortDateString() + "','"+DateTime.Now.ToLongTimeString()+"','"+f.TimeOfDay()+"','" + buyingPrice + "','SELF')";
                  //MessageBox.Show( "insert into MilkDelivery(FarmerHash,FarmerNo,FarmerName,FarmerMilkDelivery,DateOfDelivery,timeofdelivery,timeofday,BoughtAt,ReceivedBy) VALUES('" + deliveryhash + "','" + farmerNumber.Text + "','" + farmerName + "','" + delivery + "','" + DateTime.Now.ToShortDateString() + "','"+DateTime.Now.ToLongTimeString()+"','"+f.TimeOfDay()+"','" + buyingPrice + "','SELF')");
                
                  cn.cmd.ExecuteNonQuery();
                    await this.ShowMessageAsync("Delivery Registered!", "You have entered a milk delivery of " + delivery + " kg's for " + farmerNumber.Text + " Bought at Sh" + buyingPrice + "", MessageDialogStyle.Affirmative, null);
                    deliveryNum.Value = 0;
                    deliveryGrid.ItemsSource = LoadCollection();
                    fillCombo();
                }
                 catch (Exception ex)
                {
                    ShowOverlay();
                    MessageBox.Show(ex.Message);//"Entry Failed! Most probable cause for this is that "+farmerName+ "'s has already delivered milk today", "Entry Failure", MessageBoxButton.OK, MessageBoxImage.Error);
                    HideOverlay();

                }
                 
            }
            else
            {
                MessageDialogResult x;
                MetroDialogSettings yl=new MetroDialogSettings();
             
               
                yl.AffirmativeButtonText="Quit";
                x=await this.ShowMessageAsync("Entry Complete!", "All Farmers with Valid Farmer Numbers have been Processed. any other processing will have to be done Manualy",MessageDialogStyle.Affirmative,yl);
                if (x == MessageDialogResult.Affirmative)
                {
                    MessageBox.Show("t");
                    this.Close();
                }
                
                   
                    
                
                
            }
        }
        private List<Staff> LoadCollectionData()
        {

            List<Staff> farmer = new List<Staff>();
            Connection cn = new Connection();
            cn.connect();
            cn.cmd.Connection = cn.cnn;
            try { cn.cmd.Connection.Open(); }
            finally { }
            cn.cmd.CommandText = "Select * From Staff";
            try
            {

                cn.dr = cn.cmd.ExecuteReader();
                while (cn.dr.Read())
                {

                    farmer.Add(new Staff()
                    {
                        StaffNo = cn.dr.GetString(0),
                        staff  = cn.dr.GetString(1),
                        IDNumber = int.Parse(cn.dr.GetString(4)),
                        Phone = cn.dr.GetString(2),
                        DOE = cn.dr.GetDateTime(5),
                        Bank = cn.dr.GetString(8),
                        Bankacc = cn.dr.GetString(7),
                        isActive = cn.dr.GetBoolean(6),
                        nhif = cn.dr.GetString(9),
                        kra=cn.dr.GetString(10)

                        
                    });









                }
            }
            catch (Exception ex)
            {
                ShowOverlay();
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                HideOverlay();
            }


            return farmer;
        }
 private async void btnRegisterStaff_Click(object sender, RoutedEventArgs e)
 {
      Connection cn = new Connection();
     String StaffNo = txtregNo.Text;
     String Staff=firstName.Text+" "+surName.Text;//FarmerFName.Text+" "+FarmerOtherName.Text;
     String Phone = phoneNumber.Text;
     int IDNumber=Int32.Parse(idNumber.Text);
      String kra =krapin.Text.ToUpper();
      String nhif = nhifno.Text.ToUpper();
     String DOE=DateTime.Now.ToShortDateString();
     String Bankacc=accountnumber.Text;
     String Bank = banklist.Text.ToUpper();
     MessageBox.Show(isActivestatus.ToString());
     try
     {
         //MessageBox.Show(cn.connectionString);
         cn.connect();
         cn.cmd.Connection = cn.cnn;
         cn.cmd.Connection.Open();
         cn.cmd.CommandText = "insert into Staff(staffNo,staffName,PhoneNumber,staffID,Date_of_Employment,Active,AccountNo,Bank,kraPIN,nhifNo) VALUES('" + StaffNo.ToUpper() + "','" + Staff.ToUpper() + "','" + Phone.ToUpper() + "','" +IDNumber + "','" + DOE +"','"+isActivestatus.ToString()+"','"+Bankacc+"','"+Bank+"','"+kra.ToUpper()+"','"+nhif.ToUpper()+"')";
         cn.cmd.ExecuteNonQuery();
         await this.ShowMessageAsync("Registration is a Success", "You have Registered " + Staff.ToUpper() + " Successfuly", MessageDialogStyle.Affirmative, null);
         staffDatagrid.ItemsSource = LoadCollectionData();
         //farmerDatagrid.ItemsSource = LoadCollectionData();
         //ViewFarmersTab.BringIntoView();
       clearRegFields();
     }
     catch (Exception 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();
     }
     
 }
Ejemplo n.º 28
0
        private void fillName(){
             Connection cn = new Connection();
            cn.connect();
            cn.cmd.Connection = cn.cnn;
            cn.cmd.Connection.Open();
            cn.cmd.CommandText = "Select Farmer_Name,Phone_Number From Farmer Where FarmerNo='"+farmerNumber.Text+"'";
            try
            {
                
                cn.dr = cn.cmd.ExecuteReader();
              while (cn.dr.Read())
                {
                  PhoneNumber=(cn.dr.GetString(1));
                  farmerName = (cn.dr.GetString(0));

                  selectedfarmerName.Content = "Farmer: " + farmerName; 
                 selectedFarmerContact.Content = "Contact Number: " + PhoneNumber; 
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            getTotal();
        }
Ejemplo n.º 29
0
 private  void getTotal()
 {
    
     if (farmerNumber.Items.Count != 0) {
    String FirstMonthDate=DateTime.Now.Month.ToString()+"/1/"+DateTime.Now.Year.ToString();
     //farmerNumber.Items.Clear();
     Connection cn = new Connection();
     double x,y;
        
     cn.connect();
     cn.cmd.Connection = cn.cnn;
     cn.cmd.Connection.Open();
     cn.cmd.CommandText = "select sum(FarmerMilKDelivery) from MilkDelivery where FarmerNo like '%" + farmerNumber.SelectedValue.ToString() + "%' and DateOfDelivery Between '" + FirstMonthDate + "' and '" + DateTime.Now.Date.ToShortDateString() + "'";
     try
     {
       
         if (cn.cmd.ExecuteScalar().ToString() != "") { 
         x =double.Parse(cn.cmd.ExecuteScalar().ToString());
         y = Math.Round(x,1);
        
         }
         else
         {
             y = 0.0;
         }
             deliverythisMonth.Content = "Delivery This Month:" + y.ToString()+" Kilogrammes ";
         
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     } 
     }else
     {
     }
 
 }
Ejemplo n.º 30
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();
            }
        }
        private  List<Farmer> LoadCollectionData()
        {
             
            List<Farmer> farmer = new List<Farmer>();
            Connection cn = new Connection();
              cn.connect();
            cn.cmd.Connection = cn.cnn;
            cn.cmd.Connection.Open();
           cn.cmd.CommandText = "Select * From Farmer";
            try
            {
         
                cn.dr = cn.cmd.ExecuteReader();
                while (cn.dr.Read())
                {
            
            farmer.Add(new Farmer()
            {
                        farmerNO = cn.dr.GetString(0),
                        farmerName = cn.dr.GetString(1),
                        farmerID =int.Parse(cn.dr.GetString(5)),
                        phoneNumber = cn.dr.GetString(2),
                        dateOfRegistration = cn.dr.GetDateTime(6),
                        Bank = cn.dr.GetString(9),
                        BankNum = cn.dr.GetString(8),
                        isActive = cn.dr.GetBoolean(7),
                        nextOfKin = cn.dr.GetString(4),
            });
                        

                       





                   
    }
            }
            catch (Exception ex)
            {
                 ShowOverlay();
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                HideOverlay();
            }
            

                    return farmer;
        }
Ejemplo n.º 32
0
 private async void RegisterTransporter_Click(object sender, RoutedEventArgs e)
 {
       Connection cn = new Connection();
     String SupNo = txtSupno.Text;
     String SupName=txtsupName.Text.ToUpper();
     String Phone = txtSupPhone.Text;
     int IDNumber=Int32.Parse(txtsupId.Text);
      String vehicle=travehicle.Text.ToUpper()+"("+travehicleType.Text.ToUpper()+")";
      String Driver = tradriver.Text.ToUpper();
     String TurnBoy=traTurnBoy.Text.ToUpper();
     String DOR=DateTime.Now.ToShortDateString();
     String Bankacc=bankacc.Text;
     String Bank = banklist.Text.ToUpper();
     Boolean isActive= isActivestatus ;
    
     try
     {
         //MessageBox.Show(cn.connectionString);
         cn.connect();
         cn.cmd.Connection = cn.cnn;
         cn.cmd.Connection.Open();
         cn.cmd.CommandText = "insert into Supplier(SupplierNo,SupplierName,SupplierID,DOR,SupplierTelNo,SupplierBank,SupplierBankacc,SupplierActive,Misc1,Misc2,Misc3) Values('"+SupNo+"','"+SupName+"','"+IDNumber+"','"+DOR+"','"+Phone+"','"+Bank+"','"+Bankacc+"','"+isActive+"','"+vehicle+"','"+Driver+"','"+TurnBoy+"')";
         cn.cmd.ExecuteNonQuery();
         await this.ShowMessageAsync("Registration is a Success", " The Transporter has been entered into the system Successfuly", MessageDialogStyle.Affirmative, null);
        
         //farmerDatagrid.ItemsSource = LoadCollectionData();
         //ViewFarmersTab.BringIntoView();
        // clearRegFields();
     }
     catch (Exception 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();
     }
     this.Close();
 }
Ejemplo n.º 33
0
        private void fillTransporterDetails()
        {
            
            Connection cn = new Connection();
            cn.connect();
            cn.cmd.Connection = cn.cnn;
            cn.cmd.Connection.Open();
            cn.cmd.CommandText = "Select Misc3,Misc2,Misc1 From Supplier Where SupplierActive='True' AND SupplierName='" + suppliercombo.Text + "'";
            try
            {

                cn.dr = cn.cmd.ExecuteReader();
                while (cn.dr.Read())
                {
                    Driver.Text = (cn.dr.GetString(1));
                    Conductor.Text= (cn.dr.GetString(0));
                    Vehicle.Text = (cn.dr.GetString(2));
                    //MessageBox.Show(cn.dr.GetString(0) + cn.dr.GetString(1) + cn.dr.GetString(2));
                }
            }
            catch (Exception ex)
            {
                displayMetroError(ex);
            }
        }
Ejemplo n.º 34
0
        private void fillTransporter()
        {
        
            
             Connection cn = new Connection();
              cn.connect();
            cn.cmd.Connection = cn.cnn;
            cn.cmd.Connection.Open();
            cn.cmd.CommandText = "select SupplierName from Supplier";
            try
            {
         
                cn.dr = cn.cmd.ExecuteReader();
                while (cn.dr.Read())
                {



                    suppliercombo.Items.Add(cn.dr.GetString(0));
                    
                }
            } catch(Exception ex){
                displayMetroError(ex);
            }
            fillTransporterDetails();
        }
Ejemplo n.º 35
0
        private  void fillStaff()
        {
             staffcombo.Items.Clear();
             Connection cn = new Connection();
              cn.connect();
            cn.cmd.Connection = cn.cnn;
            cn.cmd.Connection.Open();
            cn.cmd.CommandText = "select StaffName from Staff Where Active='True'";
            try
            {
         
                cn.dr = cn.cmd.ExecuteReader();
                while (cn.dr.Read())
                {



                    staffcombo.Items.Add(cn.dr.GetString(0));
                    
                }
            } catch(Exception ex){
                displayMetroError(ex);
            }

            
        }
Ejemplo n.º 36
0
        private void fillTodayDelivery()
        {
            Connection cn = new Connection();
            cn.connect();
            cn.cmd.Connection = cn.cnn;
            cn.cmd.Connection.Open();
            cn.cmd.CommandText = "Select litres_loaded,Loader,Supplier,Driver,Conductor,Vehicle From MilkCreameryDelivery Where Date='" + DateTime.Now.ToShortDateString() + "' and Delivered='False'";
            try
            {

                cn.dr = cn.cmd.ExecuteReader();
                while (cn.dr.Read())
                {
                  loadedmilk1.Text=cn.dr.GetDouble(0).ToString();
                    staffcombo1.Text = (cn.dr.GetString(1));
                    suppliercombo1.Text=(cn.dr.GetString(2));
                    Driver1.Text=(cn.dr.GetString(3));
                    Conductor1.Text = (cn.dr.GetString(4));
                    Vehicle1.Text = (cn.dr.GetString(5));
                    //MessageBox.Show(cn.dr.GetString(0) + cn.dr.GetString(1) + cn.dr.GetString(2));
                }
            }
            catch (Exception ex)
            {
                displayMetroError(ex);
            }
            fillStaff();
            fillTransporter();
        }
Ejemplo n.º 37
0
        private List<inDelivery> LoadCollection()
        {
            List<inDelivery> farmerCollection = new List<inDelivery>();
         
          
            Connection cn = new Connection();
            cn.connect();
            cn.cmd.Connection = cn.cnn;
            cn.cmd.Connection.Open();
            cn.cmd.CommandText = "Select FarmerNo,FarmerName,TimeOfDelivery,TimeOfDay,FarmerMilkDelivery,BoughtAt,ReceivedBy From MilkDelivery where DateOfDelivery='"+DateTime.Now.ToShortDateString()+"'";
            try
            {

                cn.dr = cn.cmd.ExecuteReader();
                while (cn.dr.Read())
                {

                    farmerCollection.Add(new inDelivery()
                    {
                        FarmerNO = cn.dr.GetString(0),
                        FarmerName = cn.dr.GetString(1),
                        TimeOfDelivery=cn.dr.GetTimeSpan(2),
                    TimeOfDay=cn.dr.GetString(3),
                        Delivery = cn.dr.GetFloat(4),
                        BuyingPrice = cn.dr.GetDouble(5),
                       ReceivedBy = cn.dr.GetString(6),
                        
                        
                    });









                }
            }
            catch (Exception ex)
            {
               
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
               
            }


            
            return farmerCollection;
        }
Ejemplo n.º 38
0
        private async void AddDelivery_Click(object sender, RoutedEventArgs e)
        {
             Connection cn = new Connection();
            String DeliveryID = IdGen();
            float Loaded=float.Parse(loadedmilk.Text);
            float UnLoaded = 0;
            float Deficit=Loaded-UnLoaded;
             String Supplier =suppliercombo.SelectedItem.ToString();
             String DelVehicle = Vehicle.Text;
            String DOD=DateTime.Now.ToShortDateString();
            String driver=Driver.Text;
            String conductor = Conductor.Text;
            String StaffName=staffcombo.SelectedItem.ToString();
            Utilities f = new Utilities();
          try
            {
                //MessageBox.Show(cn.connectionString);
                cn.connect();
                cn.cmd.Connection = cn.cnn;
                cn.cmd.Connection.Open();
                cn.cmd.CommandText = "INSERT INTO MilkCreameryDelivery(DeliveryID,Date,timeofday,Litres_loaded,Litres_Unloaded,Deficit,Loader,Driver,Conductor,Vehicle,Supplier,Delivered) VALUES('" + DeliveryID + "','" + DOD + "','"+f.TimeOfDay()+"','" + Loaded + "','" + UnLoaded + "','" + Deficit + "','" + StaffName + "','" + driver + "','" + conductor + "','" + DelVehicle + "','" + Supplier + "','0')";
                
                cn.cmd.ExecuteNonQuery();
                MessageDialogResult x = new MessageDialogResult();
                MetroDialogSettings y = new MetroDialogSettings();
                y.AffirmativeButtonText = "Go to Delivery Tab";
                y.NegativeButtonText = "Close";

               x= await this.ShowMessageAsync("Delivery Added", "You have Added the Delivery Successfuly. Upon return, the Transporter("+Supplier+") Must enter milk unloaded at the creamery in the next Tab", MessageDialogStyle.AffirmativeAndNegative, y);
               if (x.ToString() == "Negative")
               {
                   this.Close();

               }
               else
               {
                   
                   loadEdatCoop.IsEnabled = false;
                   fillTodayDelivery();
                   tabC.SelectedIndex = 1;
               }
                //farmerDatagrid.ItemsSource = LoadCollectionData();
                //ViewFarmersTab.BringIntoView();
               // clearRegFields();
            }
          catch (Exception ex)
            {
                displayMetroError(ex);
            }
        }
        private async void  btnRegister_Click(object sender, RoutedEventArgs e)
        {
             Connection cn = new Connection();
            String FarmerNo = txtregNo.Text;
            String Farmer=FarmerFName.Text+" "+FarmerOtherName.Text;
            String Phone = FarmerPhone.Text;
            String NextOfKin = NextofKinFName.Text +" "+ NextOfKinOtherNames.Text;
            String Family = FarmerFamilyName.Text;
            String DOR=DateTime.Now.ToShortDateString();
            String Bankacc = FarmerBankNo.Text;
            String Bank = BankList.Text;
           
            try
            {
                //MessageBox.Show(cn.connectionString);
                cn.connect();
                cn.cmd.Connection = cn.cnn;
                cn.cmd.Connection.Open();
                cn.cmd.CommandText = "insert into Farmer(FarmerNo,Farmer_Name,Phone_Number,NextOfKin_Name,FarmerID,Date_of_Registration,Active,AccountNo,Bank) VALUES('" + FarmerNo.ToUpper() + "','" + Farmer.ToUpper() + "','" + Phone.ToUpper() + "','" + NextOfKin.ToUpper() + "','" + Family.ToUpper() + "','" + DOR +"','1','"+Bankacc+"','"+Bank+"')";
                cn.cmd.ExecuteNonQuery();
                await this.ShowMessageAsync("Registration is a Success", "You have Registered " + Farmer.ToUpper() + " Successfuly", MessageDialogStyle.Affirmative, null);
                farmerDatagrid.ItemsSource = LoadCollectionData();
                ViewFarmersTab.BringIntoView();
                txtregNo.Text = IdGen();
                clearRegFields();
            }
            catch (Exception 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();
            }


        }
        private string checkNumber(String Check)
        {
            Connection cn = new Connection();
            String CheckString="";
            try
            {

                cn.connect();
                
                cn.cmd.Connection = cn.cnn;
                cn.cmd.Connection.Open();
                cn.cmd.CommandText = "Select FarmerNo from Farmer Where FarmerNo='" + Check + "' ";
                CheckString = cn.cmd.ExecuteScalar().ToString();
                if (CheckString == null)
                {
                    return "";
                }
               
                   
                


            }
            catch (Exception ex)
            {
                System.Diagnostics.Debugger.Log(0, "db Error", ex.Message);
            }
           return CheckString;
        }