private void Button_Click(object sender, RoutedEventArgs e) { string uid = (sender as Button).Uid; SuccessMessgage.Visibility = System.Windows.Visibility.Collapsed; saveButton.Visibility = System.Windows.Visibility.Visible; if (dispathTimer != null) { dispathTimer.Stop(); dispathTimer = null; } if (uid == "rowEdit") { pawnguardDb = new PawnGuardDBDataContext(); toEditStone = pawnguardDb.Stones .SingleOrDefault<Stone>(gld => gld.Id.ToString() == (sender as Button).Content.ToString()); dgStones.SelectedItem = toEditStone; VisualStateManager.GoToElementState(this.LayoutRoot, "ShowState", true); } if (uid == "closePanel") { VisualStateManager.GoToElementState(this.LayoutRoot, "HideState", true); FillGrid(); page_Loaded(sender, e); } //if (uid == "save") { // if (toEditGold == null) { // if (!IsValid()) // return; // pawnguardDb = new PawnGuardDBDataContext(); // bool exist = pawnguardDb.ItemCategories.AsEnumerable() // .Where(itm => itm.main.ToLower() == txtCategory.Text.ToLower() || // itm.option1.ToLower() == txtOption1.Text.ToLower() || // itm.option2.ToLower() == txtOption2.Text.ToLower()) // .Any(); // if (exist) { // categoryError.Visibility = System.Windows.Visibility.Visible; // errorMsgCategory.Text = MSG_EXIST; // return; // } // decimal price = 0; // decimal.TryParse(txtPrice.Text, out price); // pawnguardDb.ItemCategories.InsertOnSubmit(new ItemCategory() { // parentId = AppData.parentId, // code = txtCode.Text, // main = txtCategory.Text, // option1 = txtOption1.Text, // option2 = txtOption2.Text, // price = price, // createdAt = DateTime.Now, // updatedAt = DateTime.Now // }); // } else { // if (!IsValid()) // return; // string editEmail = toEditGold.main; // string editoption1 = toEditGold.option1; // string editoption2 = toEditGold.option2; // if (!editEmail.Equals(txtCategory.Text, StringComparison.InvariantCultureIgnoreCase) && // !editoption1.Equals(txtOption1.Text, StringComparison.InvariantCultureIgnoreCase) && // !editoption2.Equals(txtOption2.Text, StringComparison.InvariantCultureIgnoreCase)) { // bool exist = pawnguardDb.ItemCategories.AsEnumerable() // .Where(itm => itm.main.ToLower() == txtCategory.Text.ToLower() || // itm.option1.ToLower() == txtOption1.Text.ToLower() || // itm.option2.ToLower() == txtOption2.Text.ToLower()) // .Any(); // if (exist) { // categoryError.Visibility = System.Windows.Visibility.Visible; // errorMsgCategory.Text = MSG_EXIST; // return; // } // } // decimal price = 0; // decimal.TryParse(txtPrice.Text, out price); // toEditGold.parentId = AppData.parentId; // toEditGold.code = txtCode.Text; // toEditGold.main = txtCategory.Text; // toEditGold.option1 = txtOption1.Text; // toEditGold.option2 = txtOption2.Text; // toEditGold.price = price; // toEditGold.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."; // FillGrid(); // page_Loaded(sender, e); // } // time--; // }; // } catch (Exception) { // } //} }
private void ImportExcel(string path) { object rarity = null; object name = null; object carat = null; object price = null; object misValue = System.Reflection.Missing.Value; excelApp = new Excel.Application(); Excel.Range range; worker = new BackgroundWorker(); worker.WorkerSupportsCancellation = true; worker.WorkerReportsProgress = true; ProgStackPanel.Visibility = System.Windows.Visibility.Visible; ProgTextCancel.Visibility = System.Windows.Visibility.Collapsed; ProgressGrid.Visibility = System.Windows.Visibility.Visible; StoneListGrid.Visibility = System.Windows.Visibility.Hidden; Import.IsEnabled = false; Export.IsEnabled = false; this.MinHeight = 500; ProgText.Text = "Importing Data..."; ProgressStone.Value = 0; worker.DoWork += delegate(object sdr, DoWorkEventArgs dw) { Excel.Application _excelApp = (Excel.Application)dw.Argument; xlWorkBook = _excelApp.Workbooks.Open(path, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); range = xlWorkSheet.UsedRange; List<Stone> stoneItem = new List<Stone>(); for (int row = 0; row <= range.Rows.Count; row++) { for (int col = 0; col <= range.Columns.Count; col++) { if ((range.Cells[row + 2, col + 1] as Excel.Range).Value2 != null) { if (col == 0) rarity = (range.Cells[row + 2, col + 1] as Excel.Range).Value2; if (col == 1) name = (range.Cells[row + 2, col + 1] as Excel.Range).Value2; if (col == 2) carat = (range.Cells[row + 2, col + 1] as Excel.Range).Value2; if (col == 3) price = (range.Cells[row + 2, col + 1] as Excel.Range).Value2; } else { if (col == 0) rarity = string.Empty; if (col == 1) name = string.Empty; if (col == 2) carat = string.Empty; if (col == 3) price = string.Empty; } } if (worker.CancellationPending) { ProgText.Dispatcher.Invoke(new Action(() => { ProgText.Text = "Canceling..."; })); System.Threading.Thread.Sleep(3000); dw.Cancel = true; return; } try { if (!string.IsNullOrWhiteSpace(name.ToString())) { stoneItem.Add(new Stone { Id = row + 1, name = name.ToString(), rarity = rarity.ToString(), carat = carat.ToString(), price = price.ToString(), }); } } catch (Exception) { ProgText.Dispatcher.Invoke(new Action(() => { ProgText.Text = "Invalid Template!"; })); System.Threading.Thread.Sleep(1300); worker.CancelAsync(); } worker.ReportProgress(Convert.ToInt32(((decimal)row / (decimal)range.Rows.Count) * 100)); System.Threading.Thread.Sleep(5); dw.Result = stoneItem; } }; worker.ProgressChanged += delegate(object s, ProgressChangedEventArgs args) { ProgressStone.Value = args.ProgressPercentage; }; worker.RunWorkerCompleted += delegate(object sdr, RunWorkerCompletedEventArgs rwc) { xlWorkBook.Close(true, misValue, misValue); excelApp.Quit(); releaseObject(xlWorkSheet); releaseObject(xlWorkBook); releaseObject(excelApp); ProgressGrid.Visibility = System.Windows.Visibility.Hidden; StoneListGrid.Visibility = System.Windows.Visibility.Visible; Import.IsEnabled = true; Export.IsEnabled = true; this.MinHeight = 300; if (rwc.Error != null) { MessageBox.Show(rwc.Error.Message); return; } if (!rwc.Cancelled) { List<Stone> stone = (List<Stone>)rwc.Result; for (int i = 0; i < stone.Count; i++) { stone[i].parentId = AppData.parentId; stone[i].updatedAt = DateTime.Now; stone[i].createdAt = DateTime.Now; } pawnguardDb = new PawnGuardDBDataContext(); LinqExt.Truncate(pawnguardDb.Stones); pawnguardDb.Stones.InsertAllOnSubmit(stone); pawnguardDb.SubmitChanges(); FillGrid(); page_Loaded(null, new RoutedEventArgs()); } }; worker.RunWorkerAsync(excelApp); }
private void SearchTextBox_TextChange(object sender, TextChangedEventArgs e) { pawnguardDb = new PawnGuardDBDataContext(); var searchItems = GoldRecords .Where(usr => usr.name.Contains((sender as TextBox).Text)) .ToList<Stone>(); dgStones.ItemsSource = searchItems; }
private void ExportExcel(string path) { bool success = false; object misValue = System.Reflection.Missing.Value; excelApp = new Microsoft.Office.Interop.Excel.Application(); if (excelApp == null) { MessageBox.Show("Excel is not properly installed!!"); return; } worker = new BackgroundWorker(); worker.WorkerSupportsCancellation = true; worker.WorkerReportsProgress = true; PawnGuardDBDataContext pawnguard = new PawnGuardDBDataContext(); ProgStackPanel.Visibility = System.Windows.Visibility.Visible; ProgTextCancel.Visibility = System.Windows.Visibility.Collapsed; ProgressGrid.Visibility = System.Windows.Visibility.Visible; StoneListGrid.Visibility = System.Windows.Visibility.Hidden; Import.IsEnabled = false; Export.IsEnabled = false; this.MinHeight = 500; ProgText.Text = "Exporting Data..."; ProgressStone.Value = 0; worker.DoWork += delegate(object sdr, DoWorkEventArgs dw) { Excel.Application _excelApp = (Excel.Application)dw.Argument; xlWorkBook = _excelApp.Workbooks.Open(path); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); List<Stone> stones = pawnguard.Stones.ToList<Stone>(); for (int row = 0; row < stones.Count; row++) { for (int col = 0; col < 13; col++) { if (col == 0) xlWorkSheet.Cells[row + 2, col + 1] = stones[row].rarity; if (col == 1) xlWorkSheet.Cells[row + 2, col + 1] = stones[row].name; if (col == 2) xlWorkSheet.Cells[row + 2, col + 1] = stones[row].carat; if (col == 3) xlWorkSheet.Cells[row + 2, col + 1] = stones[row].price; } worker.ReportProgress(Convert.ToInt32(((decimal)row / (decimal)stones.Count) * 100)); System.Threading.Thread.Sleep(100); if (worker.CancellationPending) { ProgText.Dispatcher.Invoke(new Action(() => { ProgText.Text = "Canceling..."; })); System.Threading.Thread.Sleep(2000); dw.Cancel = true; return; } } }; worker.ProgressChanged += delegate(object s, ProgressChangedEventArgs args) { ProgressStone.Value = args.ProgressPercentage; }; worker.RunWorkerCompleted += delegate(object sdr, RunWorkerCompletedEventArgs rwc) { if (rwc.Error != null) { MessageBox.Show(rwc.Error.Message); return; } if (!rwc.Cancelled) { ProgressStone.Value = 100; SaveFileDialog dlg = new SaveFileDialog(); dlg.FileName = "Stone Template.xlsx"; dlg.DefaultExt = ".xlsx"; dlg.Filter = "Stone Template|*.xlsx"; Nullable<bool> result = dlg.ShowDialog(); if (result == true) { string filename = dlg.FileName; xlWorkBook.SaveAs(filename); success = true; path = filename; } } else { ProgText.Dispatcher.Invoke(new Action(() => { ProgText.Text = "Cancelled"; })); } xlWorkBook.Close(true, misValue, misValue); excelApp.Quit(); releaseObject(xlWorkSheet); releaseObject(xlWorkBook); releaseObject(excelApp); ProgressGrid.Visibility = System.Windows.Visibility.Hidden; StoneListGrid.Visibility = System.Windows.Visibility.Visible; Import.IsEnabled = true; Export.IsEnabled = true; this.MinHeight = 300; if (success) { System.Diagnostics.Process.Start(path); } }; worker.RunWorkerAsync(excelApp); }
private void FillGrid() { pawnguardDb = new PawnGuardDBDataContext(); var lambdaJoin = pawnguardDb.Stones.AsQueryable<Stone>(); GoldRecords = lambdaJoin; }
private void SearchTextBox_TextChange(object sender, TextChangedEventArgs e) { pawnguardDb = new PawnGuardDBDataContext(); var searchPos = pawnguardDb.Positions .Where(pos => pos.name.Contains((sender as TextBox).Text)) .ToList<Position>(); dgPosition.ItemsSource = searchPos; }
private void SaveSetUp() { using (PawnGuardDBDataContext db = new PawnGuardDBDataContext()) { LinqExt.Truncate(db.Branches); LinqExt.Truncate(db.AppSettings); LinqExt.Truncate(db.Moneys); LinqExt.Truncate(db.Currencies); LinqExt.Truncate(db.ItemCategories); LinqExt.Truncate(db.Golds); LinqExt.Truncate(db.Stones); LinqExt.Truncate(db.InitialSetups); db.Branches.InsertOnSubmit(Branch); db.AppSettings.InsertOnSubmit(BranchPrimaryCurreny); db.Moneys.InsertAllOnSubmit(BranchMoney); db.Currencies.InsertAllOnSubmit(BranchCurrency); db.ItemCategories.InsertAllOnSubmit(ItemCategories); db.Golds.InsertAllOnSubmit(GoldList); db.Stones.InsertAllOnSubmit(StoneList); InitialSetup inSetup = new InitialSetup() { parentId = "000001", step = "SetState", createdAt = DateTime.Now, updateAt = DateTime.Now }; db.InitialSetups.InsertOnSubmit(inSetup); db.SubmitChanges(); ProgressBarFinal.Dispatcher.Invoke(new Action(() => { ProgressBarFinal.Visibility = Visibility.Hidden; })); ButtonStartApp.Dispatcher.Invoke(new Action(() => { ButtonStartApp.Visibility = Visibility.Visible; })); } }
private void Page_Loaded(object sender, RoutedEventArgs e) { pawnguardDb = new PawnGuardDBDataContext(); var userlevel = from userLevel in pawnguardDb.UserLevels select userLevel; dgUserLevel.ItemsSource = userlevel; }
private void SearchTextBox_TextChange(object sender, TextChangedEventArgs e) { pawnguardDb = new PawnGuardDBDataContext(); var searchUsrLvl = pawnguardDb.UserLevels .Where(usrl => usrl.role.Contains((sender as TextBox).Text)) .ToList<UserLevel>(); dgUserLevel.ItemsSource = searchUsrLvl; }
private void Button_Click(object sender, RoutedEventArgs e) { string uid = (sender as Button).Uid; SuccessMessgage.Visibility = System.Windows.Visibility.Collapsed; saveButton.Visibility = System.Windows.Visibility.Visible; if (dispathTimer != null) { dispathTimer.Stop(); dispathTimer = null; } if (uid == "addNew") { dgItems.SelectedItem = null; toEditItem = null; } if (uid == "rowEdit") { pawnguardDb = new PawnGuardDBDataContext(); toEditItem = pawnguardDb.ItemCategories .SingleOrDefault<ItemCategory>(pos => pos.id.ToString() == (sender as Button).Content.ToString()); dgItems.SelectedItem = toEditItem; VisualStateManager.GoToElementState(this.LayoutRoot, "ShowState", true); } if (uid == "closePanel") { VisualStateManager.GoToElementState(this.LayoutRoot, "HideState", true); FillGrid(); page_Loaded(sender, e); } if (uid == "deleteAll") { if (toDeleteItem.Count > 0) { pawnguardDb = new PawnGuardDBDataContext(); List<ItemCategory> deleteUser = new List<ItemCategory>(); for (int i = 0; i < toDeleteItem.Count; i++) { var itemCategory = pawnguardDb.ItemCategories .FirstOrDefault(usr => usr.id == toDeleteItem[i].id); deleteUser.Add(itemCategory); } if (deleteUser.Count > 0) { pawnguardDb.ItemCategories.DeleteAllOnSubmit(deleteUser); pawnguardDb.SubmitChanges(); isCheckAll.IsChecked = false; toDeleteItem.Clear(); FillGrid(); page_Loaded(sender, e); } } } if (uid == "save") { if (toEditItem == null) { if (!IsValid()) return; pawnguardDb = new PawnGuardDBDataContext(); bool exist = pawnguardDb.ItemCategories.AsEnumerable() .Where(itm => itm.main.ToLower() == txtCategory.Text.ToLower() || itm.option1.ToLower() == txtOption1.Text.ToLower() || itm.option2.ToLower() == txtOption2.Text.ToLower()) .Any(); if (exist) { categoryError.Visibility = System.Windows.Visibility.Visible; errorMsgCategory.Text = MSG_EXIST; return; } decimal price = 0; decimal.TryParse(txtPrice.Text, out price); pawnguardDb.ItemCategories.InsertOnSubmit(new ItemCategory() { parentId = AppData.parentId, code = txtCode.Text, main = txtCategory.Text, option1 = txtOption1.Text, option2 = txtOption2.Text, price = price, createdAt = DateTime.Now, updatedAt = DateTime.Now }); } else { if (!IsValid()) return; string editEmail = toEditItem.main; string editoption1 = toEditItem.option1; string editoption2 = toEditItem.option2; if (!editEmail.Equals(txtCategory.Text, StringComparison.InvariantCultureIgnoreCase) && !editoption1.Equals(txtOption1.Text, StringComparison.InvariantCultureIgnoreCase) && !editoption2.Equals(txtOption2.Text, StringComparison.InvariantCultureIgnoreCase)) { bool exist = pawnguardDb.ItemCategories.AsEnumerable() .Where(itm => itm.main.ToLower() == txtCategory.Text.ToLower() || itm.option1.ToLower() == txtOption1.Text.ToLower() || itm.option2.ToLower() == txtOption2.Text.ToLower()) .Any(); if (exist) { categoryError.Visibility = System.Windows.Visibility.Visible; errorMsgCategory.Text = MSG_EXIST; return; } } decimal price = 0; decimal.TryParse(txtPrice.Text, out price); toEditItem.parentId = AppData.parentId; toEditItem.code = txtCode.Text; toEditItem.main = txtCategory.Text; toEditItem.option1 = txtOption1.Text; toEditItem.option2 = txtOption2.Text; toEditItem.price = price; toEditItem.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."; FillGrid(); page_Loaded(sender, e); } time--; }; } catch (Exception) { } } }
private void checkItem_Click(object sender, RoutedEventArgs e) { string content = (sender as CheckBox).Name; if (content == "isCheckAll") { if ((bool)(sender as CheckBox).IsChecked == true) { toDeleteUserLevel = dgUserLevel.ItemsSource .OfType<UserLevel>() .ToList<UserLevel>(); } if ((bool)(sender as CheckBox).IsChecked == false) { toDeleteUserLevel.Clear(); } } else { string id = (sender as CheckBox).Content.ToString(); if ((bool)(sender as CheckBox).IsChecked == true) { pawnguardDb = new PawnGuardDBDataContext(); UserLevel position = pawnguardDb.UserLevels .FirstOrDefault(usrl => usrl.id.ToString() == id); if (!toDeleteUserLevel.Contains(position)) toDeleteUserLevel.Add(position); } else if ((bool)(sender as CheckBox).IsChecked == false) { UserLevel position = toDeleteUserLevel .FirstOrDefault(usrl => usrl.id.ToString() == id); if (toDeleteUserLevel.Contains(position)) toDeleteUserLevel.Remove(position); } } }
private void SearchTextBox_TextChange(object sender, TextChangedEventArgs e) { pawnguardDb = new PawnGuardDBDataContext(); var searchItems = UserRecords .Where(usr => usr.main.Contains((sender as TextBox).Text) || usr.option1.Contains((sender as TextBox).Text) || usr.option2.Contains((sender as TextBox).Text) || usr.code.Contains((sender as TextBox).Text)) .ToList<ItemCategory>(); dgItems.ItemsSource = searchItems; }
private void FillGrid() { pawnguardDb = new PawnGuardDBDataContext(); var lambdaJoin = pawnguardDb.ItemCategories.AsQueryable<ItemCategory>(); UserRecords = lambdaJoin; }
private void checkItem_Click(object sender, RoutedEventArgs e) { string content = (sender as CheckBox).Name; if (content == "isCheckAll") { if ((bool)(sender as CheckBox).IsChecked == true) { toDeleteItem = dgItems.ItemsSource .OfType<ItemCategory>() .ToList<ItemCategory>(); } if ((bool)(sender as CheckBox).IsChecked == false) { if (toDeleteItem != null) toDeleteItem.Clear(); } } else { string id = (sender as CheckBox).Content.ToString(); if ((bool)(sender as CheckBox).IsChecked == true) { pawnguardDb = new PawnGuardDBDataContext(); ItemCategory itemCategory = pawnguardDb.ItemCategories .FirstOrDefault(pos => pos.id.ToString() == id); if (!toDeleteItem.Contains(itemCategory)) toDeleteItem.Add(itemCategory); } else if ((bool)(sender as CheckBox).IsChecked == false) { ItemCategory itemCategory = toDeleteItem.FirstOrDefault(usr => usr.id.ToString() == id); if (toDeleteItem.Contains(itemCategory)) toDeleteItem.Remove(itemCategory); } } }
private void checkItem_Click(object sender, RoutedEventArgs e) { string content = (sender as CheckBox).Name; if (content == "isCheckAll") { if ((bool)(sender as CheckBox).IsChecked == true) { toDeletePosition = dgPosition.ItemsSource .OfType<Position>() .ToList<Position>(); } if ((bool)(sender as CheckBox).IsChecked == false) { toDeletePosition.Clear(); } } else { string id = (sender as CheckBox).Content.ToString(); if ((bool)(sender as CheckBox).IsChecked == true) { pawnguardDb = new PawnGuardDBDataContext(); Position position = pawnguardDb.Positions .FirstOrDefault(pos => pos.id.ToString() == id); if (!toDeletePosition.Contains(position)) toDeletePosition.Add(position); } else if ((bool)(sender as CheckBox).IsChecked == false) { Position position = toDeletePosition .FirstOrDefault(pos => pos.id.ToString() == id); if (toDeletePosition.Contains(position)) toDeletePosition.Remove(position); } } }
private void checkItem_Click(object sender, RoutedEventArgs e) { string content = (sender as CheckBox).Name; if (content == "isCheckAll") { if ((bool)(sender as CheckBox).IsChecked == true) { toDeleteGold = dgGolds.ItemsSource .OfType<Gold>() .ToList<Gold>(); } if ((bool)(sender as CheckBox).IsChecked == false) { if (toDeleteGold != null) toDeleteGold.Clear(); } } else { string id = (sender as CheckBox).Content.ToString(); if ((bool)(sender as CheckBox).IsChecked == true) { pawnguardDb = new PawnGuardDBDataContext(); Gold gold = pawnguardDb.Golds .FirstOrDefault(pos => pos.Id.ToString() == id); if (!toDeleteGold.Contains(gold)) toDeleteGold.Add(gold); } else if ((bool)(sender as CheckBox).IsChecked == false) { Gold gold = toDeleteGold.FirstOrDefault(usr => usr.Id.ToString() == id); if (toDeleteGold.Contains(gold)) toDeleteGold.Remove(gold); } } }
private void Page_Loaded(object sender, RoutedEventArgs e) { pawnguardDb = new PawnGuardDBDataContext(); var position = from positions in pawnguardDb.Positions select positions; dgPosition.ItemsSource = position; }
private void SigninButton_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(Email.Text)) { Email.Focus(); return; } if (string.IsNullOrWhiteSpace(Password.Password)) { Password.Focus(); return; } try { using (PawnGuardDBDataContext tblUser = new PawnGuardDBDataContext()) { var data = tblUser.Users.AsEnumerable() .FirstOrDefault(usr => usr.email == Email.Text && usr.password == Password.Password); if (data != null) { User user = data; LoginError.Visibility = System.Windows.Visibility.Collapsed; PawnGuardPro.Properties.Settings.Default.UserID = user.Id.ToString(); PawnGuardPro.Properties.Settings.Default.Name = user.name; PawnGuardPro.Properties.Settings.Default.Branch = TablesGetData.tblBranch(user.branchCode, "code", "name").ToString(); PawnGuardPro.Properties.Settings.Default.BranchCode = user.branchCode; PawnGuardPro.Properties.Settings.Default.Company = user.company; PawnGuardPro.Properties.Settings.Default.ParentID = user.parentId; //PawnGuardPro.Properties.Settings.Default.Currency = "PHP"; PawnGuardPro.Properties.Settings.Default.Save(); VisualStateManager.GoToElementState(this.LayouRoot, "UserSignin", true); MainWindow main = Application.Current.MainWindow as MainWindow; main.IsLogin(this, new EventArgs()); this.Dispose(); } else { LoginError.Visibility = System.Windows.Visibility.Visible; } } } catch (SqlException ex) { if (ex.Number == -2) { MessageBox.Show("Timeout occurred"); } else { MessageBox.Show(ex.Message, "Error Occured", MessageBoxButton.OK, MessageBoxImage.Error); } } }
private void Button_Click(object sender, RoutedEventArgs e) { string uid = (sender as Button).Uid; positionError.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") { dgPosition.SelectedItem = null; toEditPosition = null; } if (uid == "rowEdit") { pawnguardDb = new PawnGuardDBDataContext(); toEditPosition = pawnguardDb.Positions .SingleOrDefault<Position>(pos => pos.id.ToString() == (sender as Button).Content.ToString()); dgPosition.SelectedItem = toEditPosition; VisualStateManager.GoToElementState(this.LayoutRoot, "ShowState", true); } if (uid == "closePanel") { VisualStateManager.GoToElementState(this.LayoutRoot, "HideState", true); Page_Loaded(sender, e); } if (uid == "deleteAll") { if (toDeletePosition.Count > 0) { pawnguardDb = new PawnGuardDBDataContext(); List<Position> deletePosition = new List<Position>(); for (int i = 0; i < toDeletePosition.Count; i++) { var _pos = pawnguardDb.Positions .FirstOrDefault(pos => pos.id == toDeletePosition[i].id); deletePosition.Add(_pos); } if (deletePosition.Count > 0) { pawnguardDb.Positions.DeleteAllOnSubmit(deletePosition); pawnguardDb.SubmitChanges(); Page_Loaded(sender, e); isCheckAll.IsChecked = false; toDeletePosition.Clear(); } } } if (uid == "save") { if (toEditPosition == null) { if (string.IsNullOrWhiteSpace(txtPositionName.Text)) { positionError.Visibility = System.Windows.Visibility.Visible; errorMsg.Text = MSG_REQUIRED; return; } pawnguardDb = new PawnGuardDBDataContext(); bool exist = pawnguardDb.Positions.AsEnumerable() .Where(pos => pos.name.ToLower() == txtPositionName.Text.ToLower()) .Any(); if (exist) { positionError.Visibility = System.Windows.Visibility.Visible; errorMsg.Text = MSG_EXIST; return; } pawnguardDb.Positions.InsertOnSubmit(new Position() { name = txtPositionName.Text, createdAt = DateTime.Now, updatedAt = DateTime.Now }); } else { string editName = toEditPosition.name; if (!editName.Equals(txtPositionName.Text, StringComparison.InvariantCultureIgnoreCase)) { bool exist = pawnguardDb.Positions.AsEnumerable() .Where(pos => pos.name.ToLower() == txtPositionName.Text.ToLower()) .Any(); if (exist) { positionError.Visibility = System.Windows.Visibility.Visible; errorMsg.Text = MSG_EXIST; return; } } else { VisualStateManager.GoToElementState(this.LayoutRoot, "HideState", true); return; } toEditPosition.name = txtPositionName.Text; toEditPosition.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."; txtPositionName.Clear(); Page_Loaded(sender, e); } time--; }; } catch (Exception) { } } }
public UserDataSource() { _appUser = new ObservableCollection<AppUser>(); using (PawnGuardDBDataContext db = new PawnGuardDBDataContext()) { List<User> users = db.Users.ToList<User>(); for (int i = 0; i < users.Count; i++) { //_appUser.Add((AppUser)users[i]); _appUser.Add(new AppUser() { name = users[i].name }); } } }