Exemple #1
0
        private void loadUI()
        {
            String db            = "QLChuyenDi";
            String con           = $"Server=localhost; Database= master; Trusted_Connection=True;";
            bool   isHasDatabase = DatabaseHelper.isDatabaseExists(con, db);

            if (!isHasDatabase)
            {
                return;
            }

            ChuyenDiDAOImpl chuyenDiDAOImpl = new ChuyenDiDAOImpl();

            if (chuyenDiDAOImpl.GetAllChuyenDi().Count() > 0)
            {
                Random random = new Random();
                int    index  = random.Next(chuyenDiDAOImpl.GetAllChuyenDi().Count());

                ChuyenDi trip = chuyenDiDAOImpl.GetAllChuyenDi()[index];
                txtTripTittle.Text      = trip.TenChuyenDi;
                txtTripDescription.Text = trip.MoTa;

                HinhAnhChuyenDiDAOlmpl hinhAnhChuyenDiDAOlmpl = new HinhAnhChuyenDiDAOlmpl();
                HinhAnhChuyenDi        tripImage = hinhAnhChuyenDiDAOlmpl.getTripImageByTripCode(trip.MaChuyenDi);

                if (tripImage == null || tripImage.HinhAnh == null || tripImage.HinhAnh == "")
                {
                    Uri uri = new Uri("../Assets/Images/default_trip_image.jpg", UriKind.RelativeOrAbsolute);
                    imgTrip.Source = new BitmapImage(uri);
                }
                else
                {
                    Uri uri = new Uri(tripImage.HinhAnh, UriKind.RelativeOrAbsolute);
                    try
                    {
                        imgTrip.Source = new BitmapImage(uri);
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            else
            {
                //do nothing. use default screen in xml
            }
        }
        private void OnAddNewImage(object sender, RoutedEventArgs e)
        {
            var screen = new OpenFileDialog();

            screen.Multiselect = true;

            if (screen.ShowDialog() == true)
            {
                var files = screen.FileNames;

                foreach (var file in files)
                {
                    var info = new FileInfo(file);
                    fileList.Add(file);
                    HinhAnhChuyenDi newImageTemp = new HinhAnhChuyenDi()
                    {
                        HinhAnh = info.ToString(), MaChuyenDi = this.maChuyenDi
                    };

                    imagesTemp.Add(newImageTemp);
                }
            }
        }
        private void OnAddNewImage(object sender, RoutedEventArgs e)
        {
            var screen = new OpenFileDialog();

            screen.Multiselect = true;

            if (screen.ShowDialog() == true)
            {
                var files = screen.FileNames;

                foreach (var file in files)
                {
                    var info = new FileInfo(file);
                    //var newName = $"{Guid.NewGuid()}{info.Extension}";

                    //var currentFolder = AppDomain.CurrentDomain.BaseDirectory;
                    //File.Copy(file, $"{currentFolder}Assets\\Images\\{newName}");
                    fileList.Add(file);
                    HinhAnhChuyenDi newImageTemp = new HinhAnhChuyenDi()
                    {
                        HinhAnh = info.ToString(), MaChuyenDi = this.maChuyenDi
                    };
                    //HinhAnhChuyenDi newImage = new HinhAnhChuyenDi() { HinhAnh = newName, MaChuyenDi = this.maChuyenDi };

                    //foreach (HinhAnhChuyenDi image in images)
                    //{
                    //    if(image.HinhAnh.Equals(newImage.HinhAnh))
                    //    {
                    //        MessageBox.Show("Đã tồn tại hình ảnh này");
                    //        return;
                    //    }
                    //}

                    imagesTemp.Add(newImageTemp);
                }
            }
        }
        private void OnSubmit(object sender, RoutedEventArgs e)
        {
            String curStateString = cbTrangThai.Text;
            int    curState       = 1;

            if (curStateString.Equals("Đang đi"))
            {
                curState = 0;
            }

            chuyenDiDAOImpl.updateTrangThai(this.maChuyenDi, curState);

            //ChuyenDi newTrip = new ChuyenDi(maChuyenDi, curState, description);
            //chuyenDiDAOImpl.addChuyenDi(newTrip);

            if (extraExpense.Count() > 0)
            {
                foreach (MucChi mucChi in extraExpense)
                {
                    mucChiDAOlmpl.addMucChi(mucChi);
                }
            }

            if (milestones.Count() > 0)
            {
                foreach (CacMocLoTrinh milistone in milestones)
                {
                    cacMocLoTrinhDAOlmpl.addCacMocLoTrinh(milistone);
                }
            }

            if (members.Count() > 0)
            {
                foreach (ThanhVien member in members)
                {
                    thanhVienDAOlmpl.addThanhVien(member);
                }

                foreach (CHUYENDI_THANHVIEN trip_member in trip_memberList)
                {
                    chuyenDiThanhVienDAOImpl.addChuyenDiThanhVien(trip_member);
                }
            }



            if (fileList.Count() > 0)
            {
                var currentFolder = AppDomain.CurrentDomain.BaseDirectory;

                foreach (string file in fileList)
                {
                    var info    = new FileInfo(file);
                    var newName = $"{Guid.NewGuid()}{info.Extension}";
                    File.Copy(file, $"{currentFolder}Assets\\Images\\{newName}");
                    HinhAnhChuyenDi newImage = new HinhAnhChuyenDi()
                    {
                        HinhAnh = newName, MaChuyenDi = this.maChuyenDi
                    };
                    hinhAnhChuyenDiDAOlmpl.addHinhAnhChuyenDi(newImage);
                }
            }

            MessageBox.Show("Đã hoàn thành");
        }
        private void OnSubmit(object sender, RoutedEventArgs e)
        {
            String tripName       = txtTripName.Text;
            String curStateString = cbTrangThai.Text;
            String location       = txtLocation.Text;
            String description    = txtDescription.Text;

            if (tripName == "")
            {
                MessageBox.Show("Bạn chưa nhập tên chuyến đi");
            }
            else if (location == "")
            {
                MessageBox.Show("Bạn chưa nhập địa điểm chuyến đi");
            }

            int curState = 1;

            if (curStateString.Equals("Đang đi"))
            {
                curState = 0;
            }

            ChuyenDi newTrip = new ChuyenDi(maChuyenDi, tripName, curState, location, description, anhbiaChuyenDi);

            chuyenDiDAOImpl.addChuyenDi(newTrip);

            if (extraExpense.Count() > 0)
            {
                foreach (MucChi mucChi in extraExpense)
                {
                    mucChiDAOlmpl.addMucChi(mucChi);
                }
            }

            if (milestones.Count() > 0)
            {
                foreach (CacMocLoTrinh milistone in milestones)
                {
                    cacMocLoTrinhDAOlmpl.addCacMocLoTrinh(milistone);
                }
            }

            if (members.Count() > 0)
            {
                foreach (ThanhVien member in members)
                {
                    thanhVienDAOlmpl.addThanhVien(member);
                }

                foreach (CHUYENDI_THANHVIEN trip_member in trip_memberList)
                {
                    chuyenDiThanhVienDAOImpl.addChuyenDiThanhVien(trip_member);
                }
            }



            if (fileList.Count() > 0)
            {
                //foreach(HinhAnhChuyenDi image in images)
                //{
                //    hinhAnhChuyenDiDAOlmpl.addHinhAnhChuyenDi(image);
                //}

                var currentFolder = AppDomain.CurrentDomain.BaseDirectory;

                foreach (string file in fileList)
                {
                    var info    = new FileInfo(file);
                    var newName = $"{Guid.NewGuid()}{info.Extension}";
                    File.Copy(file, $"{currentFolder}Assets\\Images\\{newName}");
                    HinhAnhChuyenDi newImage = new HinhAnhChuyenDi()
                    {
                        HinhAnh = newName, MaChuyenDi = this.maChuyenDi
                    };
                    hinhAnhChuyenDiDAOlmpl.addHinhAnhChuyenDi(newImage);
                }
            }
            //ChuyenDi newTrip = new ChuyenDi(maChuyenDi, tripName, curState, location, description, anhbia);
            //chuyenDiDAOImpl.addChuyenDi(newTrip);
            if (anhbiaChuyenDi != "")
            {
                var    currentFolder = AppDomain.CurrentDomain.BaseDirectory;
                string file          = AvatarName;
                File.Copy(file, $"{currentFolder}Assets\\Images\\{newNameAvt}");
            }
            MessageBox.Show("Đã hoàn thành");
        }