public CreateForm() { InitializeComponent(); pc_form.DataContext = pc; try { using (var db = new PCEntities()) { var locations = db.Offices.AsQueryable().Select(q => q.Location).ToList(); foreach (var office in locations) { office_LocatedComboBox.Items.Add(office); } var item = new ComboBoxItem(); OtherLocation otherlocation = new OtherLocation(); item.Content = otherlocation; office_LocatedComboBox.Items.Add(item); } } catch (Exception ex) { Util.WriteLog(ex.Message + ex.StackTrace); Util.ShowMessageBoxAsync("Error", ex.Message); throw; } office_LocatedComboBox.SelectedIndex = 0; }
public static ActorEntity GetPCEntity(UInt32 key) { ActorEntity pc; PCEntities.TryGetValue(key, out pc); return(pc); }
public override ValidationResult Validate(object value, CultureInfo cultureInfo) { var inputValue = Convert.ToString(value).Trim(); using (var db = new PCEntities()) { try { if (db.Pcs.Any(q => q.PC_Name.ToLower().Equals(inputValue.ToLower()) && q.Active == true)) { return(new ValidationResult(false, "Pc Name is already existed !")); } else if (!string.IsNullOrEmpty(inputValue) && db.Pcs.Any(q => q.ServiceTag.ToLower().Equals(inputValue.ToLower()) && q.Active == true)) { return(new ValidationResult(false, "Service Tag is already existed !")); } else { return(ValidationResult.ValidResult); } } catch (Exception ex) { Util.WriteLog(ex.Message + "\n" + ex.StackTrace); Util.ShowMessageBoxAsync("Error", ex.Message); throw; } } }
//GET PC/GETPC public JsonResult GetPC() { using (var db = new PCEntities()) { List <PC> listarPC = db.PC.ToList(); return(Json(listarPC, JsonRequestBehavior.AllowGet)); } }
private void LoadDataSource(IEnumerable <Pc> PcList, Filters?option, string query) { query = Util.RejectMarks(query); using (var db = new PCEntities()) { if (option != null) { switch (option.Value) { case Filters.Pc_Name: PcList = PcList.Where(q => Util.RejectMarks(q.PC_Name).Contains(query) && q.Active == true); break; case Filters.PB: PcList = PcList.Where(q => Util.RejectMarks(q.PB).Contains(query) && q.Active == true); break; case Filters.NV: PcList = PcList.Where(q => Util.RejectMarks(q.NV).Contains(query) && q.Active == true); break; case Filters.MAC: PcList = PcList.Where(q => q.MAC != null && q.MAC.ToLower().Equals(query) && q.Active == true); break; case Filters.MAC2: PcList = PcList.Where(q => q.MAC2 != null && q.MAC2.ToLower().Equals(query) && q.Active == true); break; case Filters.IP: PcList = PcList.Where(q => q.IP.Equals(query) && q.Active == true); break; case Filters.Location: PcList = PcList.Where(q => Util.RejectMarks(q.Office_Located).Contains(query) && q.Active == true); break; case Filters.Service_Tag: PcList = PcList.Where(q => Util.RejectMarks(q.ServiceTag).Contains(query) && q.Active == true); break; case Filters.NV_Code: PcList = PcList.Where(q => Util.RejectMarks(q.NVCode).Contains(query) && q.Active); break; default: break; } } pcDataGrid.ItemsSource = Util.ToObservableCollection(PcList); } }
private IEnumerable <Pc> LoadDataSource(IEnumerable <Pc> PcList, Filters?option, string query, string location_option) { query = Util.RejectMarks(query); location_option = Util.RejectMarks(location_option); using (var db = new PCEntities()) { if (option != null) { switch (option.Value) { case Filters.Pc_Name: PcList = PcList.Where(q => Util.RejectMarks(q.PC_Name).Contains(query) && q.Active == true); break; case Filters.PB: PcList = PcList.Where(q => Util.RejectMarks(q.PB).Contains(query) && q.Active == true); break; case Filters.NV: PcList = PcList.Where(q => Util.RejectMarks(q.NV).Contains(query) && q.Active == true); break; case Filters.MAC: PcList = PcList.Where(q => q.MAC != null && q.MAC.ToLower().Equals(query) && q.Active == true); break; case Filters.MAC2: PcList = PcList.Where(q => q.MAC2 != null && q.MAC2.ToLower().Equals(query) && q.Active == true); break; case Filters.IP: PcList = PcList.Where(q => q.IP.Equals(query) && q.Active == true); break; case Filters.Location: PcList = PcList.Where(q => Util.RejectMarks(q.Office_Located).Contains(location_option) && q.Active == true); break; case Filters.NV_Code: PcList = PcList.Where(q => Util.RejectMarks(q.NVCode).Contains(query) && q.Active); break; default: break; } } return(PcList); } }
public Filter() { InitializeComponent(); if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this)) { using (var db = new PCEntities()) { db.Pcs.Where(q => q.Active).Load(); pcDataGrid.ItemsSource = db.Pcs.Local; } } }
private async void SaveFromExcelAsync() { var metroWindow = (Application.Current.MainWindow as MetroWindow); MessageDialogStyle style = MessageDialogStyle.AffirmativeAndNegative; var result = await metroWindow.ShowMessageAsync("Confirm", "Are you sure to add these records to database ?", style); if (result == MessageDialogResult.Affirmative) { var controller = await metroWindow.ShowProgressAsync("Adding", "Please wait..."); controller.SetIndeterminate(); using (var db = new PCEntities()) { try { await Task.Run(() => { var list = pcViewModelList.AsQueryable().ProjectTo <Pc>(config); foreach (Pc item in list) { item.Active = true; db.Pcs.Add(item); } }); await db.SaveChangesAsync(); await controller.CloseAsync(); var mesDialogResult = await metroWindow.ShowMessageAsync("Success", "Saved to Database."); btnSaveExcel.Content = "Saved"; btnSaveExcel.IsEnabled = false; if (mesDialogResult == MessageDialogResult.Affirmative) { metroWindow.FindChild <MetroAnimatedSingleRowTabControl>("MainTabControl").SelectedIndex = 0; } } catch (Exception ex) { await controller.CloseAsync(); await metroWindow.ShowMessageAsync("Error", ex.Message); Util.WriteLog(ex.Message + "\n" + ex.StackTrace); } } } }
private async void BtnSaveClickAsync(object sender, RoutedEventArgs e) { var validated = this.ValidateInput(); if (validated.IsValidated) { MetroAnimatedSingleRowTabControl mainTabControl = Util.FindParent <MetroAnimatedSingleRowTabControl>(this); var currentTab = (MetroTabItem)mainTabControl.SelectedItem; using (var db = new PCEntities()) { try { var otherLocation = ((office_LocatedComboBox.Items .GetItemAt(office_LocatedComboBox.Items.Count - 1) as ComboBoxItem).Content as OtherLocation) .FindChild <TextBox>("txt_otherLocation").Text; if (!string.IsNullOrEmpty(otherLocation)) { db.Offices.Add(new Office { Location = otherLocation, Active = true, }); await db.SaveChangesAsync(); pc.Office_Located = otherLocation; } pc.Active = true; db.Pcs.Add(pc); await db.SaveChangesAsync(); currentTab.Header = pc.PC_Name; btnSave.Content = "Saved"; } catch (Exception ex) { Util.WriteLog(ex.Message + "\n" + ex.StackTrace); Util.ShowMessageBoxAsync("Error", ex.Message); throw; } } } else { var metroWindow = (Application.Current.MainWindow as MetroWindow); await metroWindow.ShowMessageAsync("Warning", validated.ValidateMessage); } }
public FilteriItem() { InitializeComponent(); filter_combobox.ItemsSource = Enum.GetValues(typeof(Filters)).Cast <Filters>(); try { using (var db = new PCEntities()) { var locations = db.Offices.ToList(); location_options.ItemsSource = locations.Select(q => q.Location); } } catch (Exception ex) { Util.WriteLog(ex.Message + "\n" + ex.StackTrace); Util.ShowMessageBoxAsync("Error", ex.Message); throw; } }
private async void ValidateLoginAsync(string username, string password) { using (var db = new PCEntities()) { try { var user = db.Users.Find(username); if (user != null && user.Password.Equals(password)) { Dispatcher.Invoke(async() => { await controller.CloseAsync(); MainWindow main = new MainWindow(); Application.Current.MainWindow = main; this.Close(); main.Show(); }); } else { Dispatcher.Invoke(async() => { await controller.CloseAsync(); AuthorizeAsync("Wrong Username or Password, try again."); }); } } catch (Exception ex) { Util.WriteLog(ex.Message + "\n" + ex.StackTrace); await this.Dispatcher.Invoke(async() => { var messResult = await Util.ShowMessageBoxAsync("Error", "Cannot connect to Database !"); if (messResult == MessageDialogResult.Affirmative) { this.Close(); } }); } } }
private void BtnFilterClick(object sender, RoutedEventArgs e) { using (var db = new PCEntities()) { var result = db.Pcs.Where(q => q.Active).AsEnumerable(); foreach (var item in filters.Children) { if (item is FilteriItem) { var filterOptionObject = ((item as FilteriItem).FindName("filter_combobox") as ComboBox).SelectedItem; var filterOption = (Filters)Enum.Parse(typeof(Filters), filterOptionObject.ToString()); var filterText = ((item as FilteriItem).FindName("filter_value") as TextBox).Text; var location_option = ((item as FilteriItem).FindName("location_options") as ComboBox).SelectedItem.ToString(); result = LoadDataSource(result, filterOption, filterText.ToLower(), location_option); } } pcDataGrid.ItemsSource = Util.ToObservableCollection(result); } }
public override ValidationResult Validate(object value, CultureInfo cultureInfo) { var inputMac = Convert.ToString(value); var addMacReg1 = "^[0-9A-Fa-f]{2}-[0-9A-Fa-f]{2}-[0-9A-Fa-f]{2}-[0-9A-Fa-f]{2}-[0-9A-Fa-f]{2}-[0-9A-Fa-f]{2}$"; var addMacReg2 = "^[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}$"; var regex1 = new Regex(addMacReg1); var regex2 = new Regex(addMacReg2); using (var db = new PCEntities()) { if (!regex1.IsMatch(inputMac) && !regex2.IsMatch(inputMac)) { return(new ValidationResult(false, "Mac Address format is not valid")); } if (db.Pcs.Any(q => q.MAC.ToLower().Equals(inputMac.ToLower()) && q.Active == true)) { return(new ValidationResult(false, "Mac Address already existed !")); } return(ValidationResult.ValidResult); } }
private async Task UpdateAsync() { var mapper = config.CreateMapper(); try { using (var db = new PCEntities()) { foreach (var item in pcViewSource) { var entity = mapper.Map <Pc>(item); if (item.ID == 0) { //ad new pc entity.Active = true; db.Pcs.Add(entity); } else if (item.IsUpdated) { //update a pc db.Pcs.Attach(entity); db.Entry(entity).State = EntityState.Modified; } } await db.SaveChangesAsync(); } } catch (Exception ex) { await Util.ShowMessageBoxAsync("Error !", "Error occured: " + ex.Message); Util.WriteLog(ex.Message + "\n" + ex.StackTrace); } changesCounts = 0; }
public static bool RemovePCEntity(UInt32 key) { ActorEntity removed; return(PCEntities.TryRemove(key, out removed)); }
public static void EnsurePCEntity(UInt32 key, ActorEntity entity) { PCEntities.AddOrUpdate(key, entity, (k, v) => entity); }
public PcReposity(PCEntities context) { this.context = context; }
private static Validation ValidateInput(Pc model) { using (var db = new PCEntities()) { var check = new Validation(); if (model != null) { if (String.IsNullOrEmpty(model.PC_Name)) { check.ValidateMessage += "PC Name must not be empty.\n"; check.IsValidated = false; } if (db.Pcs.Any(q => (q.PC_Name.ToLower().Equals(model.PC_Name.ToLower()) && q.ID != model.ID && q.Active == true))) { check.ValidateMessage += "PC Name is already existed.\n"; check.IsValidated = false; } if (String.IsNullOrEmpty(model.Type)) { check.ValidateMessage += "Type must not be empty.\n"; check.IsValidated = false; } if (String.IsNullOrEmpty(model.PB)) { check.IsValidated = false; check.ValidateMessage += "PB must not be empty.\n"; } if (String.IsNullOrEmpty(model.Office_Located)) { check.IsValidated = false; check.ValidateMessage += "Office Located must not be empty.\n"; } var addMacReg1 = "^[0-9A-Fa-f]{2}-[0-9A-Fa-f]{2}-[0-9A-Fa-f]{2}-[0-9A-Fa-f]{2}-[0-9A-Fa-f]{2}-[0-9A-Fa-f]{2}$"; var addMacReg2 = "^[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}$"; var regex1 = new Regex(addMacReg1); var regex2 = new Regex(addMacReg2); if (String.IsNullOrEmpty(model.MAC) && String.IsNullOrEmpty(model.MAC2)) { check.IsValidated = false; check.ValidateMessage += "Atleast one MAC Address must be entered.\n"; } if (!String.IsNullOrEmpty(model.MAC)) { if (!regex1.IsMatch(model.MAC) && !regex2.IsMatch(model.MAC)) { check.IsValidated = false; check.ValidateMessage += "MAC format is NOT a valid mac address format (##:##:##:##:##:##)\n"; } } if (db.Pcs.Any(q => q.MAC.ToLower().Equals(model.MAC.ToLower()) && q.ID != model.ID && q.Active == true)) { check.IsValidated = false; check.ValidateMessage += "Mac Address already existed !"; } if (!String.IsNullOrEmpty(model.MAC2)) { if (!regex1.IsMatch(model.MAC2) && !regex2.IsMatch(model.MAC2)) { check.IsValidated = false; check.ValidateMessage += "MAC2 format is NOT a valid mac address format (##:##:##:##:##:##)\n"; } } } return(check); } }
private Validation ValidateInput() { var check = new Validation(); if (pc != null) { using (var db = new PCEntities()) { if (db.Pcs.Any(q => q.PC_Name.ToLower().Equals(pc.PC_Name.ToLower()) && q.Active == true)) { check.ValidateMessage = "Pc already existed"; return(check); } if (!String.IsNullOrEmpty(pc.PC_Name) && !String.IsNullOrEmpty(pc.Type) && !String.IsNullOrEmpty(pc.PB) && !String.IsNullOrEmpty(pc.Office_Located) && (!String.IsNullOrEmpty(pc.MAC) || !String.IsNullOrEmpty(pc.MAC2))) { var addMacReg1 = "^[0-9A-Fa-f]{2}-[0-9A-Fa-f]{2}-[0-9A-Fa-f]{2}-[0-9A-Fa-f]{2}-[0-9A-Fa-f]{2}-[0-9A-Fa-f]{2}$"; var addMacReg2 = "^[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}$"; var regex1 = new Regex(addMacReg1); var regex2 = new Regex(addMacReg2); if (!String.IsNullOrEmpty(pc.MAC) && !String.IsNullOrEmpty(pc.MAC2)) { if ((regex1.IsMatch(pc.MAC) || regex2.IsMatch(pc.MAC)) && (regex1.IsMatch(pc.MAC2) || regex2.IsMatch(pc.MAC2))) { check.IsValidated = true; } else { check.ValidateMessage = "MAC or MAC2 format is NOT a valid mac address format (##:##:##:##:##:##)\n"; } } else { if (!String.IsNullOrEmpty(pc.MAC)) { if (regex1.IsMatch(pc.MAC) || regex2.IsMatch(pc.MAC)) { check.IsValidated = true; } else { check.ValidateMessage = "MAC format is NOT a valid mac address format (##:##:##:##:##:##)\n"; } } if (!String.IsNullOrEmpty(pc.MAC2)) { if (regex1.IsMatch(pc.MAC2) || regex2.IsMatch(pc.MAC2)) { check.IsValidated = true; } else { check.ValidateMessage += "MAC2 format is NOT a valid mac address format (##:##:##:##:##:##)\n"; } } } } else { check.ValidateMessage += "Fields with [ * ] mark must not be empty\n"; } } } return(check); }