private void DGV_Moto_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                object item = DGV_Moto.SelectedItem;
                ID = (DGV_Moto.SelectedCells[0].Column.GetCellContent(item) as TextBlock).Text;

                if (RoleType == "Administrator" || RoleType == "Manager")
                {
                    if (DGV_Moto.Items.IsEmpty)
                    {
                        addmoto = new AddMotorCycle();
                        Moto_page.Navigate(addmoto);
                    }

                    else
                    {
                        upMoto = new UpdateMotorCycle();
                        upMoto.txt_Brand.Text = (DGV_Moto.SelectedCells[1].Column.GetCellContent(item) as TextBlock).Text;
                        upMoto.txt_Model.Text = (DGV_Moto.SelectedCells[2].Column.GetCellContent(item) as TextBlock).Text;
                        upMoto.txt_Color.Text = (DGV_Moto.SelectedCells[3].Column.GetCellContent(item) as TextBlock).Text;
                        upMoto.txt_Price.Text = (DGV_Moto.SelectedCells[4].Column.GetCellContent(item) as TextBlock).Text;
                        upMoto.ID             = ID;
                        upMoto.Department     = Department;

                        Moto_page.Navigate(upMoto);
                    }
                }

                connect.SelectMotorPic(int.Parse(ID));
                byte[]       data = (byte[])connect.set.Tables[0].Rows[0][1];
                MemoryStream strm = new MemoryStream();
                strm.Write(data, 0, data.Length);
                strm.Position = 0;

                System.Drawing.Image imgs = System.Drawing.Image.FromStream(strm);
                BitmapImage          bi   = new BitmapImage();

                bi.BeginInit();
                MemoryStream ms = new MemoryStream();

                imgs.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
                strm.Seek(0, SeekOrigin.Begin);

                bi.StreamSource = strm;
                bi.EndInit();
                im.Source = bi;
            }
            catch (Exception)
            {
            }
        }
Ejemplo n.º 2
0
        private void Can_AddMoto_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            ViewMoto = new ViewMotorCycle();
            AddMoto  = new AddMotorCycle();

            ViewMoto.Moto_page = null;
            DependencyObject currParent = VisualTreeHelper.GetParent(this);

            while (currParent != null && ViewMoto.Moto_page == null)
            {
                ViewMoto.Moto_page = currParent as Frame;
                currParent         = VisualTreeHelper.GetParent(currParent);
            }

            if (ViewMoto.Moto_page != null)
            {
                ViewMoto.Moto_page.Source = new Uri("AddMotorCycle.xaml", UriKind.Relative);
            }
        }