private void saveRecipeButton_Click(object sender, RoutedEventArgs e) { recipe.ID_RECIPE = _dbUtilitiesInstance.GetMaxIDRecipe() + 1; //Check name if (recipeNameTextBox.Text.Length == 0) { notiMessageSnackbar.MessageQueue.Enqueue("Không được bỏ trống tên món ăn", "Cancel", () => { }); return; } else { recipe.NAME = recipeNameTextBox.Text; } //check description if (recipeDescriptionTextBox.Text.Length == 0) { notiMessageSnackbar.MessageQueue.Enqueue("Không được bỏ trống phần mô tả", "Cancel", () => { }); return; } else { recipe.DESCRIPTION = recipeDescriptionTextBox.Text; } //Allow to empty recipe.LINK_VIDEO = linkVideoTextBox.Text; //Check empty Avatar if (avatarImage.Source.ToString() == FindResource("IconEmptyAvt").ToString()) { notiMessageSnackbar.MessageQueue.Enqueue("Không được bỏ trống hình đại diện", "Cancel", () => { }); return; } if (isValidTime()) { recipe.TIME = int.Parse(hourTextBox.Text) * 60 + int.Parse(minuteTextBox.Text); } else { if (int.Parse(minuteTextBox.Text) >= 60) { notiMessageSnackbar.MessageQueue.Enqueue("Số phút thực hiện phải nhỏ hơn 60", "Cancel", () => { }); } else { notiMessageSnackbar.MessageQueue.Enqueue("Không được bỏ trống thời gian hoàn thành", "Cancel", () => { }); } hourTextBox.Text = ""; minuteTextBox.Text = ""; return; } recipe.FOOD_GROUP = groupComboBox.Text; recipe.FOOD_LEVEL = levelComboBox.SelectedIndex; if (recipe.Igredients.Count == 0) { notiMessageSnackbar.MessageQueue.Enqueue("Không được bỏ trống nguyên liệu", "Cancel", () => { }); return; } else { //Do Nothing } if (recipe.Steps.Count == 0) { notiMessageSnackbar.MessageQueue.Enqueue("Không được bỏ trống các bước thực hiện", "Cancel", () => { }); return; } else { try { var srcAvatar = avatarImage.Source.ToString(); recipe.LINK_AVATAR = _appUtilities.getTypeOfImage(srcAvatar); var today = DateTime.Now; Debug.WriteLine(recipe.NAME); if (_dbUtilitiesInstance.InsertRecipe(recipe.ID_RECIPE, recipe.NAME, recipe.DESCRIPTION, recipe.LINK_VIDEO, recipe.LINK_AVATAR, recipe.TIME, recipe.FOOD_GROUP, recipe.FOOD_LEVEL, false, false, today) == 1) { _appUtilities.createIDDirectory(recipe.ID_RECIPE); _appUtilities.copyImageToIDDirectory(recipe.ID_RECIPE, srcAvatar, "avatar"); foreach (var igredient in recipe.Igredients) { try { _dbUtilitiesInstance.InsertIgredient(recipe.ID_RECIPE, igredient.NAME, igredient.QUANTITY); } catch (Exception excep) { Debug.WriteLine(excep.Message); } var steps = recipe.Steps.ToList(); for (int no_step = 1; no_step <= steps.Count; ++no_step) { var step = steps[no_step - 1]; step.ID_RECIPE = recipe.ID_RECIPE; try { _dbUtilitiesInstance.InsertStep(recipe.ID_RECIPE, no_step, step.DETAIL); } catch (Exception excep) { Debug.WriteLine(excep.Message); } var images = step.StepImages.ToList(); for (int no_image = 1; no_image <= images.Count; ++no_image) { var image = images[no_image - 1]; image.ID_RECIPE = recipe.ID_RECIPE; var srcImage = image.LINK_IMAGES; var linkImage = $"{no_step}_{no_image}"; try { _appUtilities.copyImageToIDDirectory(recipe.ID_RECIPE, srcImage, linkImage); } catch (Exception excep) { Debug.WriteLine(excep.Message); } try { _dbUtilitiesInstance.InsertStepImages(recipe.ID_RECIPE, no_step, $"{linkImage}.{_appUtilities.getTypeOfImage(srcImage)}"); } catch (Exception excep) { Debug.WriteLine(excep.Message); } } notiMessageSnackbar.MessageQueue.Enqueue("Thêm món ăn thành công", "BACK HOME", BackHome); } } } else { notiMessageSnackbar.MessageQueue.Enqueue($"Đã tồn tại {recipe.NAME}", "BACK HOME", BackHome); } } catch (Exception excep) { Debug.WriteLine(excep.Message); } } clearForm(); totalStep = 0; }
private void saveJourneyButton_Click(object sender, RoutedEventArgs e) { //Get Data _journey.Journey_Name = journeyNameTextBox.Text; if (_journey.Journey_Name.Length == 0) { notiMessageSnackbar.MessageQueue.Enqueue($"Không được bỏ trống tên chuyến đi", "OK", () => { }); return; } _journey.Start_Place = journeyStartPlaceTextBox.Text; if (_journey.Start_Place.Length == 0) { notiMessageSnackbar.MessageQueue.Enqueue($"Không được bỏ trống địa điểm xuất phát", "OK", () => { }); return; } _journey.Start_Province = ((Province)startProvinceComboBox.SelectedItem).Province_Name; if (isCurrentJourneyCheckBox.IsChecked.Value) { _journey.Status = 0; _databaseUtilities.FinishCurrentJourney(); } else { } Route startRoute = new Route(); startRoute.Place = _journey.Start_Place; startRoute.Province = _journey.Start_Province; if (endSiteComboBox.SelectedIndex == -1) { notiMessageSnackbar.MessageQueue.Enqueue($"Hiện tại chưa có địa điểm nào được thêm ở tỉnh {((Province)endProvinceComboBox.SelectedItem).Province_Name}", "OK", () => { }); notiMessageSnackbar.MessageQueue.Enqueue($"Vui lòng chọn địa điểm khác hoặc thêm địa điểm mới vào tỉnh {((Province)endProvinceComboBox.SelectedItem).Province_Name} và thử lại", "OK", () => { }); return; } Route endRoute = new Route(); endRoute.Place = ((Site)endSiteComboBox.SelectedItem).Site_Name; endRoute.Province = ((Province)endProvinceComboBox.SelectedItem).Province_Name; _journey.ID_Site = ((Site)endSiteComboBox.SelectedItem).ID_Site; _journey.StartDate = startDatePicker.SelectedDate; _journey.EndDate = endDatePicker.SelectedDate; //Get distance var routeForCalcDistance = (from r in Route_For_Binding where r.Is_Active == 1 select r).ToList(); _journey.Distance = _googleMapUtilities.GetDistanceByRoutes(routeForCalcDistance, startRoute, endRoute); //Insert _databaseUtilities.UpdateJourney( _journey.ID_Journey, _journey.Journey_Name, _journey.ID_Site, _journey.Start_Place, _journey.Start_Province, _journey.Status, _journey.StartDate, _journey.EndDate, _journey.Distance); foreach (var expense in Expens_For_Binding) { _databaseUtilities.UpdateExpense(expense.ID_Expenses, expense.ID_Journey, expense.Expenses_Money, expense.Expenses_Description, expense.Is_Active ?? 0); } foreach (var route in Route_For_Binding) { _databaseUtilities.UpdateRoute(route.ID_Journey, route.Ordinal_Number, route.Place, route.Province, route.Route_Description, route.Route_Status, route.Is_Active ?? 0); } foreach (var member in JourneyAttendances) { _databaseUtilities.UpdateJourneyAttendance(member.ID_Member, member.ID_Journey, member.Member_Name, member.Phone_Number, member.Receivables_Money, member.Role, member.Is_Active ?? 0); } _appUtilities.createIDDirectory(_journey.ID_Journey); foreach (var image in Images_For_Binding) { _databaseUtilities.UpdateJourneyImage(_journey.ID_Journey, image.Ordinal_Number, _appUtilities.getTypeOfImage(image.Link_Image), image.Is_Active); _appUtilities.copyImageToIDirectory(_journey.ID_Journey, image.Link_Image, $"{image.Ordinal_Number}", false); } foreach (var advance in Advances_For_Binding) { _databaseUtilities.UpdateAdvance(advance.ID_Journey, advance.ID_Borrower, advance.ID_Lender, advance.Advance_Money, advance.Is_Active); } notiMessageSnackbar.MessageQueue.Enqueue($"Đã update thành công chuyến đi \"{_journey.Journey_Name}\"", "BACK", () => { BackCurentJourney?.Invoke(_journey.ID_Journey); }); //Reset //journeyNameTextBox.Text = ""; //journeyStartPlaceTextBox.Text = ""; //startProvinceComboBox.SelectedIndex = 0; //startDatePicker.Text = ""; //endSiteComboBox.SelectedIndex = 0; //endProvinceComboBox.SelectedIndex = 0; //endDatePicker.Text = ""; //startProvinceRouteComboBox.SelectedIndex = 0; //routesListView.ItemsSource = null; //membersListView.ItemsSource = null; //expensesListView.ItemsSource = null; }