Esempio n. 1
0
        private void btn_delete_Click(object sender, EventArgs e)
        {
            //fetch.
            Freight ft = data.Fetch_frieght(G_id);

            //check.
            if (ft != null)
            {
                //delete.
                bool temp = data.Delete_frieght(ft);
                if (temp)
                {
                    MessageBox.Show(" Freight deleted ");
                    read();
                }
                else
                {
                    MessageBox.Show(" failed to delete Freight ");
                }
            }
            else
            {
                MessageBox.Show(" Freight doesnt exist ");
            }
        }
Esempio n. 2
0
 //delete freight.
 public bool Delete_frieght(Freight fr)
 {
     context.Freights.Remove(fr);
     try
     {
         context.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         ex.GetBaseException();
         return(false);
     }
 }
Esempio n. 3
0
        private void btn_update_Click(object sender, EventArgs e)
        {
            //fetch.
            Freight fr = data.Fetch_frieght(G_id);

            //check.
            if (fr != null)
            {
                //create new object.
                Freight nfr = new Freight()
                {
                    // incoming update
                    CustomerId           = int.Parse(txt_c_number.Text.Trim()),
                    Height               = txt_height.Text.Trim(),
                    Weight               = txt_weight.Text.Trim(),
                    Lenght               = txt_length.Text.Trim(),
                    DestinationAddressId = int.Parse(txt_destination.Text.Trim()),
                    OriginAddressId      = int.Parse(txt_origin_address.Text.Trim()),
                    StatusId             = int.Parse(txt_status.Text.Trim()),
                    Date = DateTime.Parse(txt_date.Text)
                };

                //call update methode.
                var status = data.Update_frieght(fr, nfr);

                //check status
                if (status)
                {
                    MessageBox.Show(" Freight successfully updated ");
                    read();
                }
                else
                {
                    MessageBox.Show(" failed to update Freight ");
                }
            }
            else
            {
                MessageBox.Show(" Freight doesnt exist ");
            }
        }
Esempio n. 4
0
        private void btn_create_Click(object sender, EventArgs e)
        {
            try
            {
                // create new object.

                Freight fr = new Freight()
                {
                    // incoming update
                    CustomerId           = int.Parse(txt_c_number.Text.Trim()),
                    Height               = txt_height.Text.Trim(),
                    Weight               = txt_weight.Text.Trim(),
                    Lenght               = txt_length.Text.Trim(),
                    DestinationAddressId = int.Parse(txt_destination.Text.Trim()),
                    OriginAddressId      = int.Parse(txt_origin_address.Text.Trim()),
                    StatusId             = int.Parse(txt_status.Text.Trim()),
                    Date = DateTime.Parse(txt_date.Text)
                };
                //call function
                bool status = data.Add_frieght(fr);
                if (status)
                {
                    //saved.
                    MessageBox.Show(" Frieght added");
                    read();
                }
                else
                {
                    //failed.
                    MessageBox.Show(" Failed to create Freight ");
                }
            }
            catch
            {
                MessageBox.Show(" Could not create Freight ");
            }
        }
Esempio n. 5
0
        //update frieght.
        public bool Update_frieght(Freight oldfr, Freight newfr)
        {
            // incoming update
            oldfr.CustomerId           = newfr.CustomerId;
            oldfr.Height               = newfr.Height;
            oldfr.Weight               = newfr.Weight;
            oldfr.Lenght               = newfr.Lenght;
            oldfr.DestinationAddressId = newfr.DestinationAddressId;
            oldfr.OriginAddressId      = newfr.OriginAddressId;
            oldfr.StatusId             = newfr.StatusId;
            oldfr.Date = newfr.Date;

            //save changes.
            try
            {
                context.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                ex.GetBaseException();
                return(false);
            }
        }