partial void DeleteUserLevel(UserLevel instance);
partial void InsertUserLevel(UserLevel instance);
partial void UpdateUserLevel(UserLevel instance);
private void Button_Click(object sender, RoutedEventArgs e) { string uid = (sender as Button).Uid; roleError.Visibility = System.Windows.Visibility.Collapsed; descriptionError.Visibility = System.Windows.Visibility.Collapsed; SuccessMessgage.Visibility = System.Windows.Visibility.Collapsed; saveButton.Visibility = System.Windows.Visibility.Visible; if (dispathTimer != null) { dispathTimer.Stop(); dispathTimer = null; } if (uid == "addNew") { dgUserLevel.SelectedItem = null; toEditUserLevel = null; } if (uid == "rowEdit") { pawnguardDb = new PawnGuardDBDataContext(); toEditUserLevel = pawnguardDb.UserLevels .SingleOrDefault<UserLevel>(usrl => usrl.id.ToString() == (sender as Button).Content.ToString()); dgUserLevel.SelectedItem = toEditUserLevel; VisualStateManager.GoToElementState(this.LayoutRoot, "ShowState", true); } if (uid == "closePanel") { VisualStateManager.GoToElementState(this.LayoutRoot, "HideState", true); Page_Loaded(sender, e); } if (uid == "deleteAll") { if (toDeleteUserLevel.Count > 0) { pawnguardDb = new PawnGuardDBDataContext(); List<UserLevel> deleteUserLevel = new List<UserLevel>(); for (int i = 0; i < toDeleteUserLevel.Count; i++) { var _usrlvl = pawnguardDb.UserLevels .FirstOrDefault(usrl => usrl.id == toDeleteUserLevel[i].id); deleteUserLevel.Add(_usrlvl); } if (deleteUserLevel.Count > 0) { pawnguardDb.UserLevels.DeleteAllOnSubmit(deleteUserLevel); pawnguardDb.SubmitChanges(); Page_Loaded(sender, e); isCheckAll.IsChecked = false; toDeleteUserLevel.Clear(); } } } if (uid == "save") { if (toEditUserLevel == null) { if (string.IsNullOrWhiteSpace(txtRole.Text) && string.IsNullOrWhiteSpace(txtDescription.Text)) { roleError.Visibility = System.Windows.Visibility.Visible; descriptionError.Visibility = System.Windows.Visibility.Visible; errorMsgRole.Text = MSG_REQUIRED_ROLE; errorMsgDesc.Text = MSG_REQUIRED_DESCRIPTION; return; } if (string.IsNullOrWhiteSpace(txtRole.Text)) { roleError.Visibility = System.Windows.Visibility.Visible; errorMsgRole.Text = MSG_REQUIRED_ROLE; return; } if (string.IsNullOrWhiteSpace(txtDescription.Text)) { descriptionError.Visibility = System.Windows.Visibility.Visible; errorMsgDesc.Text = MSG_REQUIRED_DESCRIPTION; return; } pawnguardDb = new PawnGuardDBDataContext(); bool exist = pawnguardDb.UserLevels.AsEnumerable() .Where(usrl => usrl.role.ToLower() == txtRole.Text.ToLower()) .Any(); if (exist) { roleError.Visibility = System.Windows.Visibility.Visible; errorMsgRole.Text = MSG_EXIST; return; } pawnguardDb.UserLevels.InsertOnSubmit(new UserLevel() { role = txtRole.Text, description = txtDescription.Text, createdAt = DateTime.Now, updatedAt = DateTime.Now }); } else { string editName = toEditUserLevel.role; if (!editName.Equals(txtRole.Text, StringComparison.InvariantCultureIgnoreCase)) { bool exist = pawnguardDb.UserLevels.AsEnumerable() .Where(usrl => usrl.role.ToLower() == txtRole.Text.ToLower()) .Any(); if (exist) { roleError.Visibility = System.Windows.Visibility.Visible; errorMsgRole.Text = MSG_EXIST; return; } } else { VisualStateManager.GoToElementState(this.LayoutRoot, "HideState", true); return; } toEditUserLevel.role = txtRole.Text; toEditUserLevel.description = txtDescription.Text; toEditUserLevel.updatedAt = DateTime.Now; } try { pawnguardDb.SubmitChanges(); saveButton.Visibility = System.Windows.Visibility.Collapsed; dispathTimer = new DispatcherTimer(); dispathTimer.Interval = new TimeSpan(0, 0, 1); dispathTimer.Start(); int time = 3; SuccessMessgage.Visibility = System.Windows.Visibility.Visible; dispathTimer.Tick += delegate(object s, EventArgs ea) { if (time >= 0) runTime.Text = time + " sec."; else { dispathTimer.Stop(); SuccessMessgage.Visibility = System.Windows.Visibility.Collapsed; VisualStateManager.GoToElementState(this.LayoutRoot, "HideState", true); runTime.Text = "3 sec."; txtRole.Clear(); txtDescription.Clear(); Page_Loaded(sender, e); } time--; }; } catch (Exception) { } } }