public void UpdateDataGridView() { DataTable dataTable = new DataTable(); var oldSelect = dataGridView1.CurrentCell?.RowIndex ?? 0; dataGridView1.Rows.Clear(); foreach (var item in _db.Employee.Where(x => !x.NonActive)) { var empe = new EmployeeExtended(item, _db, _rep); if (dataGridView1.Columns.Count == 0) { var colums = InitColumns(empe); dataGridView1.Columns.AddRange(colums.ToArray()); } var dgvr = new DataGridViewRow(); if (dataGridView1.Rows.Count == 0) { var rovHeader = InitRowHeader(empe); dataGridView1.Rows.Add(rovHeader); } var row = InitRow(empe); dataGridView1.Rows.Add(row); } dataGridView1.CurrentCell = dataGridView1.Rows[oldSelect].Cells[0]; }
public ActionResult DeleteConfirmed(int id) { EmployeeExtended employeeExtended = db.EmployeeExtendeds.Find(id); db.EmployeeExtendeds.Remove(employeeExtended); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,UserId,TeamName,TeamId,PositionName,PositionId,FirstName,LastName,EMail,IsManager")] EmployeeExtended employeeExtended) { if (ModelState.IsValid) { db.Entry(employeeExtended).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(employeeExtended)); }
public ActionResult Create([Bind(Include = "Id,UserId,TeamName,TeamId,PositionName,PositionId,FirstName,LastName,EMail,IsManager")] EmployeeExtended employeeExtended) { if (ModelState.IsValid) { db.EmployeeExtendeds.Add(employeeExtended); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(employeeExtended)); }
public DataGridViewRow InitRowHeader(EmployeeExtended empe) { var row = new DataGridViewRow(); row.Cells.Add(new DataGridViewTextBoxCell()); row.Frozen = true; foreach (var item2 in empe.Elt) { var cell = new DataGridViewTextBoxCell(); cell.Style = new DataGridViewCellStyle() { WrapMode = DataGridViewTriState.True }; cell.Value = "Всего : " + item2.TotalStudent.ToString() + "\nОсталось: " + item2.UnallocatedStudent.ToString() + "\nНа студента: " + item2.PerStudent; int position = row.Cells.Add(cell); row.Cells.Add(new DataGridViewTextBoxCell()); row.Cells.Add(new DataGridViewTextBoxCell()); if (item2.TotalStudent - item2.UnallocatedStudent == item2.TotalStudent) { dataGridView1.Columns[position].DefaultCellStyle = new DataGridViewCellStyle() { SelectionBackColor = Color.LightGreen, BackColor = Color.LightGreen, Alignment = DataGridViewContentAlignment.MiddleRight }; } else if (item2.TotalStudent - item2.UnallocatedStudent > item2.TotalStudent) { dataGridView1.Columns[position].DefaultCellStyle = new DataGridViewCellStyle() { SelectionBackColor = Color.Red, BackColor = Color.Red, Alignment = DataGridViewContentAlignment.MiddleRight }; } else { dataGridView1.Columns[position].DefaultCellStyle = new DataGridViewCellStyle() { Alignment = DataGridViewContentAlignment.MiddleRight }; } } row.Cells.Add(new DataGridViewTextBoxCell()); row.Cells.Add(new DataGridViewTextBoxCell()); row.Cells.Add(new DataGridViewTextBoxCell()); return(row); }
static void Main() { NorthwindEntities northwind = new NorthwindEntities(); var nancy = northwind.Employees.FirstOrDefault(); var nancyExtended = new EmployeeExtended(); nancyExtended.EmployeeID = nancy.EmployeeID; nancyExtended.GetEmployeeTerritories(); foreach (var ter in nancyExtended.Territories) { Console.WriteLine("{0} {1} {2}", ter.TerritoryID, ter.TerritoryDescription.Trim(), ter.RegionID); } }
// GET: MGEmployee/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } EmployeeExtended employeeExtended = db.EmployeeExtendeds.Find(id); if (employeeExtended == null) { return(HttpNotFound()); } return(View(employeeExtended)); }
public void GetById_Employee_RecoverOnlyExtended() { EmployeeRepository repoEmployee = new EmployeeRepository(); CreateEmployeeWithPhoto(); EmployeeExtended employeeSel = repoEmployee.GetExtendedById(employeeNew.EmployeeId); Assert.IsNotNull(employeeSel); Assert.AreEqual(employeeSel.EmployeeId, employeeNew.EmployeeId); Assert.IsNotNull(employeeSel.Photo); Assert.AreEqual(employeeSel.PhotoPath, employeeNew.EmployeeExt.PhotoPath); }
/// <summary> /// Get Employee By Name /// </summary> /// <param name="name">Name of Employee</param> /// <returns>Employee Details, if Name match</returns> public EmployeeExtended GetEmployeeByName(string name) { var employee = new EmployeeExtended(); _logger.LogTrace("GetEmployeeByName starts. Params name: {0}", name); try { var doc = XDocument.Load(Directory.GetCurrentDirectory() + xmlPath); foreach (var node in doc.Descendants("employee")) { if (node.Descendants("name").FirstOrDefault().Value.ToLower() == name.ToLower()) { employee = new EmployeeExtended { ID = Int32.Parse(node.Descendants("id")?.FirstOrDefault()?.Value ?? "0"), Name = node.Descendants("name").FirstOrDefault().Value, Age = Int32.Parse(node.Descendants("age").FirstOrDefault().Value), Designation = node.Descendants("designation").FirstOrDefault().Value, Address = node.Descendants("address")?.FirstOrDefault() == null ? new Address() : new Address() { DoorNo = node.Descendants("doorNo").FirstOrDefault().Value, State = node.Descendants("street").FirstOrDefault().Value, street = node.Descendants("town").FirstOrDefault().Value, Town = node.Descendants("state").FirstOrDefault().Value, } }; } } System.Console.WriteLine("Following Employee Details Fetched: \n"); System.Console.WriteLine(JsonConvert.SerializeObject(employee)); _logger.LogTrace("GetEmployeeByName Ends."); return(employee); } catch (Exception e) { _logger.LogError($"Exception occured: " + e.Message); return(employee); //throw; } }
public static void Main() { EmployeeExtended employee = new EmployeeExtended(); employee.CorrespondingTerritories(); }
/// <summary> /// Updates existing Employee to XML /// </summary> /// <param name="empName">Name of Employee</param> /// <returns>Update Status</returns> public bool UpdateEmployee(string empName) { _logger.LogTrace("UpdateEmployee starts. Params name: {0}", empName); if (empName == null) { System.Console.WriteLine("Name of Employee cannot be null"); return(false); } EmployeeExtended employee = new EmployeeExtended(); try { var emp = GetEmployeeByName(empName); if (emp.Name == null) { System.Console.WriteLine("Name of Employee provided did not matched with existing records. Please retry"); return(false); } var doc = XDocument.Load(Directory.GetCurrentDirectory() + xmlPath); employee.ID = emp.ID; System.Console.WriteLine("Existing value is {0}. If you want to change the Name of Employee. Enter new Name else Press # to skip", emp.Name); string updateName = GetInputsFromConsole.GetDetails <string>(); employee.Name = updateName == "#" ? emp.Name : updateName; System.Console.WriteLine("Existing value is {0}. If you want to change the Age of Employee. Enter new Age else Press 0 to skip", emp.Age); string updatedAge = GetInputsFromConsole.GetDetails <string>(); employee.Age = updatedAge == "0" ? emp.Age : int.Parse(updatedAge); System.Console.WriteLine("Existing value is {0}. If you want to change the Designation of Employee. Enter new Designation else Press # to skip", emp.Designation); string updatedDesig = GetInputsFromConsole.GetDetails <string>(); employee.Designation = updatedDesig == "#" ? emp.Designation : updatedDesig; System.Console.WriteLine("If you want to change the Address of Employee. Enter any letter else Press # and Enter to skip address"); string updatedAddress = GetInputsFromConsole.GetDetails <string>(); XElement updatedEmployee = doc.Descendants("employee").Where(_ => _.Descendants("name").FirstOrDefault().Value == emp.Name).FirstOrDefault(); updatedEmployee.Descendants("name").FirstOrDefault().Value = employee.Name; updatedEmployee.Descendants("age").FirstOrDefault().Value = employee.Age.ToString(); updatedEmployee.Descendants("designation").FirstOrDefault().Value = employee.Designation; if (updatedAddress == "#") { employee.Address = emp.Address; } else { employee.Address = emp.Address; System.Console.WriteLine("If you want to change the Address of Employee. Enter new Door Number else Press # to skip"); string doorNoValue = GetInputsFromConsole.GetDetails <string>(); employee.Address.DoorNo = doorNoValue == "#" ? emp.Address.DoorNo : doorNoValue; System.Console.WriteLine("If you want to change the street of Employee. Enter new street else Press # to skip"); string streetValue = GetInputsFromConsole.GetDetails <string>(); employee.Address.street = streetValue == "#" ? emp.Address.street : streetValue; System.Console.WriteLine("If you want to change the Town of Employee. Enter new Town else Press # to skip"); string townValue = GetInputsFromConsole.GetDetails <string>(); employee.Address.Town = townValue == "#" ? emp.Address.Town : townValue; System.Console.WriteLine("If you want to change the state of Employee. Enter new state else Press # to skip"); string stateValue = GetInputsFromConsole.GetDetails <string>(); employee.Address.State = stateValue == "#" ? emp.Address.Town : stateValue; updatedEmployee.Descendants("doorNo").FirstOrDefault().Value = employee.Address.DoorNo; updatedEmployee.Descendants("street").FirstOrDefault().Value = employee.Address.street; updatedEmployee.Descendants("town").FirstOrDefault().Value = employee.Address.Town; updatedEmployee.Descendants("state").FirstOrDefault().Value = employee.Address.State; } SaveXML(doc); System.Console.WriteLine("Successfully Updated new Employee"); System.Console.WriteLine(JsonConvert.SerializeObject(employee)); } catch (Exception e) { _logger.LogError($"Exception occured: " + e.Message); return(false); } _logger.LogTrace("UpdateEmployee Ends."); return(true); }
/// <summary> /// Adds new Employee to XML /// </summary> /// <returns>Add Status</returns> public bool AddEmployee() { EmployeeExtended employee = new EmployeeExtended(); _logger.LogTrace("AddEmployee starts."); try { var doc = XDocument.Load(Directory.GetCurrentDirectory() + xmlPath); employee.ID = GetAllEmployeesCount() + 1; System.Console.WriteLine("Please Enter Name of Employee and press Enter"); employee.Name = GetInputsFromConsole.GetDetails <string>(); System.Console.WriteLine("Please Enter Age of {0} and press Enter", employee.Name); employee.Age = Int32.Parse(GetInputsFromConsole.GetDetails <int>()); System.Console.WriteLine("Please Enter Designation of {0} and press Enter", employee.Name); employee.Designation = GetInputsFromConsole.GetDetails <string>(); System.Console.WriteLine("If you don't want to Enter Address of {0} then press Enter else Please enter DoorNo", employee.Name); string doorNoValue = GetInputsFromConsole.GetDetails <string>(); if (doorNoValue == "") { employee.Address = new Address(); } else { System.Console.WriteLine("Please enter street"); string streetValue = GetInputsFromConsole.GetDetails <string>(); System.Console.WriteLine("Please enter town"); string townValue = GetInputsFromConsole.GetDetails <string>(); System.Console.WriteLine("Please enter state"); string stateValue = GetInputsFromConsole.GetDetails <string>(); employee.Address = new Address() { DoorNo = doorNoValue, State = streetValue, street = townValue, Town = stateValue, }; } XElement newEmployee = new XElement("employee"); XElement newAddress = new XElement("address"); XElement id = new XElement("id"); id.Value = employee.ID.ToString(); XElement name = new XElement("name"); name.Value = employee.Name; XElement age = new XElement("age"); age.Value = employee.Age.ToString(); XElement designation = new XElement("designation"); designation.Value = employee.Designation; XElement doorNo = new XElement("doorNo"); doorNo.Value = employee.Address?.DoorNo ?? ""; XElement street = new XElement("street"); street.Value = employee.Address?.street ?? ""; XElement town = new XElement("town"); town.Value = employee.Address?.Town ?? ""; XElement state = new XElement("state"); state.Value = employee.Address?.State ?? ""; newAddress.Add(doorNo, street, town, state); newEmployee.Add(id, name, age, designation, newAddress); doc.Root.Add(newEmployee); SaveXML(doc); System.Console.WriteLine("Successfully Added new Employee"); System.Console.WriteLine(JsonConvert.SerializeObject(newEmployee)); } catch (Exception e) { _logger.LogError($"Exception occured: " + e.Message); return(false); } _logger.LogTrace("AddEmployee Ends."); return(true); }
public IEnumerable <DataGridViewColumn> InitColumns(EmployeeExtended empe) { var colums = new List <DataGridViewColumn>(); colums.Add(new DataGridViewTextBoxColumn() { Name = "Fio", HeaderText = "ФИО", ReadOnly = true, Frozen = true, Width = 200 }); foreach (var item2 in empe.Elt) { colums.Add(new DataGridViewTextBoxColumn() { Name = item2.Name, HeaderText = item2.Name + "\n" + item2.Groups, ReadOnly = true, Width = 120, DefaultCellStyle = new DataGridViewCellStyle() { Alignment = DataGridViewContentAlignment.MiddleRight }, SortMode = DataGridViewColumnSortMode.NotSortable }); colums.Add(new DataGridViewButtonColumn() { Name = item2.Name + "+", HeaderText = "", Width = 20, Resizable = DataGridViewTriState.False, SortMode = DataGridViewColumnSortMode.NotSortable }); colums.Add(new DataGridViewButtonColumn() { Name = item2.Name + "-", HeaderText = "", Width = 20, Resizable = DataGridViewTriState.False, SortMode = DataGridViewColumnSortMode.NotSortable }); } colums.Add(new DataGridViewTextBoxColumn() { Name = "Total", HeaderText = "Всего", ReadOnly = true, DefaultCellStyle = new DataGridViewCellStyle() { Alignment = DataGridViewContentAlignment.MiddleCenter } }); colums.Add(new DataGridViewTextBoxColumn() { Name = "Secure", HeaderText = "Загруженно", ReadOnly = true, DefaultCellStyle = new DataGridViewCellStyle() { Alignment = DataGridViewContentAlignment.MiddleCenter } }); colums.Add(new DataGridViewTextBoxColumn() { Name = "Free", HeaderText = "Свободно", ReadOnly = true, DefaultCellStyle = new DataGridViewCellStyle() { Alignment = DataGridViewContentAlignment.MiddleCenter } }); return(colums); }
public DataGridViewRow InitRow(EmployeeExtended empe) { var dgvr = new DataGridViewRow(); dgvr.Cells.Add(new DataGridViewTextBoxCell() { Value = empe.Fio }); foreach (var item2 in empe.Elt) { var cell = new DataGridViewTextBoxCell(); cell.Value = item2.CountStudents; dgvr.Cells.Add(cell); dgvr.Cells.Add(new DataGridViewButtonCell() { Value = "+", Tag = item2 }); dgvr.Cells.Add(new DataGridViewButtonCell() { Value = "-", Tag = item2 }); } dgvr.Cells.Add(new DataGridViewTextBoxCell() { Value = empe.Total }); dgvr.Cells.Add(new DataGridViewTextBoxCell() { Value = empe.Secure }); dgvr.Cells.Add(new DataGridViewTextBoxCell() { Value = empe.Free }); if (empe.Free > empe.Total * _percentageDeviation) { dgvr.DefaultCellStyle = new DataGridViewCellStyle() { SelectionBackColor = Color.LightGray, BackColor = Color.White }; } else if (empe.Free < -empe.Total * _percentageDeviation) { dgvr.DefaultCellStyle = new DataGridViewCellStyle() { SelectionBackColor = Color.Red, BackColor = Color.LightCoral }; } else { dgvr.DefaultCellStyle = new DataGridViewCellStyle() { SelectionBackColor = Color.Green, BackColor = Color.LightGreen }; } return(dgvr); }