private void CreateRowsDataGrid(ObservableCollection <EventFieldUserSet> list) { this._dt.Rows.Clear(); var size = this._nbFields + 1; var obj = new object[size]; int i = 0; int nbUser = 0; var lastObj = new object[size]; var allPrintBadge = this._mainWindowImpl.GetAllPrintBadge(); EventFieldUserSet lastUser = null; foreach (var efu in list) { if (!this._mainWindowImpl.FieldToShow.Contains(efu.EventFieldSet.FieldSet.Name)) { continue; } if (i == this._nbFields) { var datePrint = allPrintBadge.Where(p => p.UserID_User == lastUser.UserID_User).OrderByDescending(p => p.PrintDate).FirstOrDefault(); obj[i] = datePrint != null?datePrint.PrintDate.ToString() : EMPTY_COLUMN; this._dt.Rows.Add(obj); obj = new object[size]; i = 0; nbUser++; } obj[i] = efu.Value.Trim(); i++; lastObj = obj; lastUser = efu; } if (lastObj[0] != null) { var datePrint2 = allPrintBadge.Where(p => p.UserID_User == lastUser.UserID_User).OrderByDescending(p => p.PrintDate).FirstOrDefault(); obj[i] = datePrint2 != null?datePrint2.PrintDate.ToString() : EMPTY_COLUMN; this._dt.Rows.Add(lastObj); } this._mainWindowImpl.NbrUser = lastObj[0] != null ? ++nbUser : 0; this.DataGridUsers.ItemsSource = this._dt.DefaultView; }
private bool InsertInEventFieldUserTable(EventFieldUserSet eventFieldUser) { return(CheckBeforeInsert(EVENTFIELDUSER, null, null, eventFieldUser, this._repostitoryFactory.GetEventFieldUserRepository(this._dbContext))); }
public void InsertNewUser(int index, string field, string data, bool visibility, bool onsite = false) { //INSERT IN USER TABLE UserSet user = new UserSet(); if (index == 0) { user.Active = true; user.CreationDate = DateTime.Now; user.Onsite = onsite; if (field.ToLower().Equals("barcode")) { user.Barcode = data; } else { //CHECK IN THE DB THE LASTBARCODE UserSet userDb = this._repostitoryFactory.GetUserRepository(this._dbContext).GetLastUser(); if (userDb == null) { //IF THE DB IS EMPTY AND THE MAP DOESN'T CONTAINS SOMEONE, START WITH 100000 user.Barcode = !this._myUsers.ContainsKey(USER) ? "100000" : (Int32.Parse(this._myUsers[USER].Cast <UserSet>().OrderByDescending(u => u.Barcode).FirstOrDefault().Barcode) + 1).ToString(); } else { user.Barcode = this._myUsers.ContainsKey(USER) ? (Int32.Parse(this._myUsers[USER].Cast <UserSet>().OrderByDescending(u => u.Barcode).FirstOrDefault().Barcode) + 1).ToString() : (Int32.Parse(userDb.Barcode) + 1).ToString(); } } InsertInUserTable(user); } else { user = this._myUsers[USER].Cast <UserSet>().OrderByDescending(u => u.Barcode).FirstOrDefault(); } //INSERT IN EVENTFIELD EventSet ev = this._repostitoryFactory.GetEventRepository(this._dbContext).GetById(this._idEvent); bool inDico = this._myUsers.ContainsKey(FIELD); FieldSet fieldDb = inDico ? this._myUsers[FIELD].Cast <FieldSet>().Where(f2 => f2.Name.ToLower().Equals(field.ToLower())).FirstOrDefault() ?? this._repostitoryFactory.GetFieldRepository(this._dbContext).SearchFor(f => f.Name.ToLower().Equals(field.ToLower())).FirstOrDefault() : this._repostitoryFactory.GetFieldRepository(this._dbContext).SearchFor(f => f.Name.ToLower().Equals(field.ToLower())).FirstOrDefault(); EventFieldSet evf = this._repostitoryFactory.GetEventFieldRepository(this._dbContext) .SearchFor(e => e.EventSet.Name.Equals(ev.Name) && e.FieldSet.Name.Equals(fieldDb.Name)).FirstOrDefault(); if (evf == null) { if (this._myUsers.ContainsKey(EVENTFIELD)) { evf = this._myUsers[EVENTFIELD].Cast <EventFieldSet>().Where(e => e.EventSet.Name.Equals(ev.Name) && e.FieldSet.Name.Equals(fieldDb.Name)).FirstOrDefault(); } } if (evf == null) { evf = new EventFieldSet(); evf.EventSet = ev; evf.FieldSet = fieldDb; evf.Visibility = visibility; evf.Unique = false; } bool isInserted = InsertInEventFieldTable(evf); if (!isInserted) { this._repostitoryFactory.GetEventFieldRepository(this._dbContext).Update(evf); } EventFieldUserSet evfu = new EventFieldUserSet(); evfu.UserSet = user; evfu.EventFieldSet = evf; evfu.Value = data; InsertInEventFieldUserTable(evfu); }
/*********************************************************************************************************************************************************************/ /*********** FILL USERS TABLE *************/ /*********************************************************************************************************************************************************************/ private void CreateColumnsDataGrid() { HashSet <string> myFields = this._mainWindowImpl.FieldToShow; if (myFields == null) { this._mainWindowImpl.FieldToShow = new HashSet <string>(); myFields = new HashSet <string>(); var tt = this._mainWindowImpl.GetEventFieldByEvent(this._idEvent).Where(e => e.Visibility == true); foreach (var eu in tt) { this._mainWindowImpl.FieldToShow.Add(eu.FieldSet.Name); myFields.Add(eu.FieldSet.Name); } } this._nbFields = myFields.Count; DataTable dt = new DataTable(); foreach (string field in myFields) { dt.Columns.Add(new DataColumn(field, typeof(string))); } if (myFields.Count > 0) { dt.Columns.Add(new DataColumn(PRINT_BADGE, typeof(string))); } var size = myFields.Count + 1; var obj = new object[size]; int i = 0; int nbUser = 0; var lastObj = new object[size]; EventFieldUserSet lastUser = null; var allPrintBadge = this._mainWindowImpl.GetAllPrintBadge(); var list = this._mainWindowImpl.MainFields.Where(e => e.EventFieldSet.Visibility == true); foreach (var efu in list) { if (i == myFields.Count) { //Get printbadge var datePrint = allPrintBadge.Where(p => p.UserID_User == lastUser.UserID_User).OrderByDescending(p => p.PrintDate).FirstOrDefault(); obj[i] = datePrint != null?datePrint.PrintDate.ToString() : EMPTY_COLUMN; dt.Rows.Add(obj); obj = new object[size]; i = 0; nbUser++; } obj[i] = efu.Value.Trim(); i++; lastObj = obj; lastUser = efu; } if (lastObj[0] != null) { var datePrint2 = allPrintBadge.Where(p => p.UserID_User == lastUser.UserID_User).OrderByDescending(p => p.PrintDate).FirstOrDefault(); obj[i] = datePrint2 != null?datePrint2.PrintDate.ToString() : EMPTY_COLUMN; dt.Rows.Add(lastObj); } this._mainWindowImpl.NbrUser = lastObj[0] != null ? ++nbUser : 0; this.DataGridUsers.ColumnWidth = new DataGridLength(10, DataGridLengthUnitType.Star); this.DataGridUsers.ItemsSource = dt.DefaultView; this._dt = dt; }