private static void Main() { var db = new CompanyEntities(); using (db) { var random = new RandomGenerator(); var departments = new DepartmentsDataGenerator(); var projects = new ProjectsDataGenerator(); var employees = new EmployeesDataGenerator(); var reports = new ReportDataGenerator(); var employeesProjects = new EmployeesProjectsDataGenerator(); departments.Generate(db, random, 100); db.SaveChanges(); projects.Generate(db, random, 1000); db.SaveChanges(); employees.Generate(db, random, 5000); db.SaveChanges(); reports.Generate(db, random, 50); db.SaveChanges(); employeesProjects.Generate(db, random, 10); db.SaveChanges(); } }
public void Generate(CompanyEntities db, IRandomGenerator random, int count) { var departmentIds = db.Departments.Select(d => d.Id).ToList(); var employees = new List <Employee>(); for (var i = 0; i < count; i++) { var min = departmentIds.Min(); var max = departmentIds.Max(); var departmentId = departmentIds[random.GetRandomNumber(min, max) - min]; var salary = random.GetRandomNumber(MinEmployeeSalary, MaxEmployeeSalary); var firstName = random.GetRandomString(random.GetRandomNumber(MinEmployeeNameLength, MaxEmployeeNameLength)); var lastName = random.GetRandomString(random.GetRandomNumber(MinEmployeeNameLength, MaxEmployeeNameLength)); int?managerId = null; var employee = new Employee() { DepartmentId = departmentId, FirstName = firstName, LastName = lastName, YearlySalary = salary, }; if (employees.Count > 0 && random.GetRandomNumber(1, 100) <= 95) { employee.Employee1 = employees[random.GetRandomNumber(0, employees.Count - 1)]; } employees.Add(employee); } db.Employees.AddRange(employees); }
public void Seed() { var db = new CompanyEntities(); var emplyeesIds = db.Employees.Select(x => x.Id).ToList(); db.Configuration.AutoDetectChangesEnabled = false; db.Configuration.ValidateOnSaveEnabled = false; for (int i = 0; i < NumberOfReports; i++) { var reportToBeAdded = new Report { EmployeeId = emplyeesIds[this.RandomGenerator.GetRandomNumber(0, emplyeesIds.Count - 1)], Report_time = this.RandomGenerator.GetRandomDate() }; if (i % 100 == 0) { db.SaveChanges(); db = new CompanyEntities(); db.Configuration.AutoDetectChangesEnabled = false; db.Configuration.ValidateOnSaveEnabled = false; } db.Reports.Add(reportToBeAdded); } db.SaveChanges(); db.Configuration.AutoDetectChangesEnabled = true; db.Configuration.ValidateOnSaveEnabled = true; }
private void btnEdit_Click(object sender, EventArgs e) { try { if (dataGridView1.CurrentRow != null) { CompanyEntities entities = new CompanyEntities(); int i = int.Parse(txtID.Text); AddSalary salary = entities.AddSalaries.SingleOrDefault(a => a.ID == i); if (salary != null) { salary.Amount = Convert.ToDecimal(txtAddSalary.Text); salary.Justification = txtJusfifcation.Text; if (entities.SaveChanges() > 0) { MessageBox.Show("لقد تم التعديل في البيانات", "رسالة", MessageBoxButtons.OK, MessageBoxIcon.Information); SelectInformation(); } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
//All senior tables(Companies, Parts, Orders, ect...) tend to have a generic table called TableNameCodes //i.e. CompanyCodes PartCodes, OrderCodes... //So this will constitute the meta data for that Code table... //Xerp attempts to use generic naming where possible to allow for cloning... public static List <Temp> GetMetaData(this CompanyCode entityObject) { XERP.Server.DAL.CompanyDAL.DALUtility dalUtility = new DALUtility(); List <Temp> tempList = new List <Temp>(); int id = 0; using (CompanyEntities ctx = new CompanyEntities(dalUtility.EntityConectionString)) { var c = ctx.CompanyCodes.FirstOrDefault(); var queryResults = from meta in ctx.MetadataWorkspace.GetItems(DataSpace.CSpace) .Where(m => m.BuiltInTypeKind == BuiltInTypeKind.EntityType) from query in (meta as EntityType).Properties .Where(p => p.DeclaringType.Name == entityObject.GetType().Name) select query; if (queryResults.Count() > 0) { foreach (var queryResult in queryResults.ToList()) { Temp temp = new Temp(); temp.ID = id; temp.Name = queryResult.Name.ToString(); temp.ShortChar_1 = queryResult.TypeUsage.EdmType.Name; if (queryResult.TypeUsage.EdmType.Name == "String") { temp.Int_1 = Convert.ToInt32(queryResult.TypeUsage.Facets["MaxLength"].Value); } temp.Bool_1 = false; //we use this as a error trigger false = not an error... tempList.Add(temp); id++; } } } return(tempList); }
public Employee Get(int id) { using (CompanyEntities entities = new CompanyEntities()) { return(entities.Employees.FirstOrDefault(e => e.Employee_Id == id)); } }
private void btnAdd_Click(object sender, EventArgs e) { try { if (!string.IsNullOrWhiteSpace(txtAddSalary.Text) && !string.IsNullOrWhiteSpace(txtJusfifcation.Text)) { CompanyEntities entities = new CompanyEntities(); entities.AddSalaries.Add(new AddSalary() { Amount = Convert.ToDecimal(txtAddSalary.Text), Justification = txtJusfifcation.Text }); int i = entities.SaveChanges(); if (i > 0) { MessageBox.Show("تم حفظ البيانات ", "البيانات", MessageBoxButtons.OK, MessageBoxIcon.Information); Helper.EraseAllText(this); SelectInformation(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static void Main() { System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; Console.WriteLine("USE . !!!"); Console.WriteLine(); Console.WriteLine("if you are with EXPRESS change conection string in app.config file PLEASE!\n\n"); db = new CompanyEntities(); db.Configuration.AutoDetectChangesEnabled = false; randomDataGenerator = RandomDataGenetator.Instance; int numberOfDepartments = 100; AddDepartments(numberOfDepartments); int numberOfProjects = 1000; AddProjects(numberOfProjects); int numberOfEmployees = 5000; AddEmployees(numberOfEmployees); int numberOfReports = 25000; AddReports(numberOfReports); AddProjectsToEmployees(); }
public IEnumerable <Employee> Get() { using (CompanyEntities entities = new CompanyEntities()) { return(entities.Employees.ToList()); } }
public void GenerateData(CompanyEntities data, IRandomGenerator random, int count) { var allAddedEmployees = new List <Employee>(); var departmentIds = data.Departments.Select(d => d.Id).ToList(); for (int i = 0; i < count; i++) { var employee = new Employee { FirstName = random.GetRandomString(random.GetRandomNumber(5, 20)), LastName = random.GetRandomString(random.GetRandomNumber(5, 20)), Salary = random.GetRandomNumber(50000, 200000), DepartmentId = departmentIds[random.GetRandomNumber(0, departmentIds.Count - 1)] }; if (allAddedEmployees.Count > 0 && random.GetRandomNumber(1, 100) <= 95) { employee.Employee1 = allAddedEmployees[random.GetRandomNumber(0, allAddedEmployees.Count - 1)]; } allAddedEmployees.Add(employee); } data.Employees.AddRange(allAddedEmployees); }
public TransportView() { InitializeComponent(); companyEntities = new CompanyEntities(); transports = new List <Transport>(); loadData(); }
public SettingView() { InitializeComponent(); GetDBSettings(); companyEntities = new CompanyEntities(); this.Loaded += (sender, e) => WarehouseChange.IsEnabled = companyEntities.Employee.FirstOrDefault(e => e.id == Properties.Settings.Default.IdUser).idPosition != (int)EnumPosition.Warehouseman; }
public void GenerateData(CompanyEntities data, IRandomGenerator random, int count) { var employeeIds = data.Employees.Select(x => x.EmployeeId); var projectIds = data.Projects.Select(x => x.ProjectId).ToList(); foreach (var employee in employeeIds) { var employeeProjects = random.GetRandomNumber((int)count / 2, (int)(count * 1.5)); for (var i = 0; i < employeeProjects; i++) { var projectId = projectIds[random.GetRandomNumber(1, projectIds.Count - 1)]; var startDate = DateTime.Now.AddDays(-random.GetRandomNumber(-500, 1000)); var endDate = startDate.AddDays(random.GetRandomNumber(1, 1234)); var employeeInProj = new Employees_Projects { ProjectId = projectId, Startdate = startDate, Enddate = endDate, EmployeeId = employee }; data.Employees_Projects.Add(employeeInProj); } } }
private void button1_Click(object sender, EventArgs e) { try { CompanyEntities entities = new CompanyEntities(); SubTractSalary sub = new SubTractSalary(); sub.Amount = Convert.ToDecimal(txtamont.Text); sub.Justification = txtJustification.Text; sub.SanctionsID = Convert.ToInt32(comboSen.SelectedValue); entities.SubTractSalaries.Add(sub); if (entities.SaveChanges() > 0) { MessageBox.Show("لقد تم اضافة بيانات ", "رسالة ", MessageBoxButtons.OK, MessageBoxIcon.Information); SelectInformation(entities); } } catch (FormatException) { MessageBox.Show("قم بادخال البيانات بشكل صحيح", "خطاء", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (OverflowException) { MessageBox.Show("من فضل لا تقوم بادخال البيانات بشكل عشوائي", "خطاء", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public ParcelView() { InitializeComponent(); this.companyEntities = new CompanyEntities(); gridDataInitialize(); }
public void GenerateData(CompanyEntities data, IRandomGenerator random, int count) { var employeeIds = data.Employees.Select(e => e.Id).ToList(); var projectIds = data.Projects.Select(p => p.Id).ToList(); foreach (var employeeId in employeeIds) { var employeeProjectsCount = random.GetRandomNumber((int)(count * 0.5), (int)(count * 1.5)); var currentProjects = new HashSet <int>(); while (currentProjects.Count < employeeProjectsCount) { var randomProjectId = projectIds[random.GetRandomNumber(0, projectIds.Count - 1)]; currentProjects.Add(randomProjectId); } foreach (var projectId in currentProjects) { var endDateTimeSpan = random.GetRandomNumber(-500, 1000); var startDateTimeSpan = endDateTimeSpan + random.GetRandomNumber(1, 500); data.EmployeesInProjects.Add(new EmployeesInProject { EmployeeId = employeeId, ProjectId = projectId, StartDate = DateTime.Now.AddDays(-startDateTimeSpan), EndDate = DateTime.Now.AddDays(-endDateTimeSpan) }); } } }
public IEnumerable <Company> GetCompanies(Company itemQuerryObject) { _repositoryContext = new CompanyEntities(_rootUri); _repositoryContext.MergeOption = MergeOption.AppendOnly; _repositoryContext.IgnoreResourceNotFoundException = true; var queryResult = from q in _repositoryContext.Companies select q; if (!string.IsNullOrEmpty(itemQuerryObject.Name)) { queryResult = queryResult.Where(q => q.Name.StartsWith(itemQuerryObject.Name.ToString())); } if (!string.IsNullOrEmpty(itemQuerryObject.Description)) { queryResult = queryResult.Where(q => q.Description.StartsWith(itemQuerryObject.Description.ToString())); } if (!string.IsNullOrEmpty(itemQuerryObject.CompanyTypeID)) { queryResult = queryResult.Where(q => q.CompanyTypeID.StartsWith(itemQuerryObject.CompanyTypeID.ToString())); } if (!string.IsNullOrEmpty(itemQuerryObject.CompanyCodeID)) { queryResult = queryResult.Where(q => q.CompanyCodeID.StartsWith(itemQuerryObject.CompanyCodeID.ToString())); } return(queryResult); }
public static void Main() { var dataGeneratorExecutors = new List <DataGeneratorExecutor> { new DataGeneratorExecutor(new DepartmentDataGenerator(), 100), new DataGeneratorExecutor(new EmployeeDataGenerator(), 5000), new DataGeneratorExecutor(new ProjectsDataGenerator(), 1000), new DataGeneratorExecutor(new EmployeesInProjectsDataGenerator(), 10), // per employee new DataGeneratorExecutor(new ReportsDataGenerator(), 50), // per employee }; foreach (var dataGeneratorExecutor in dataGeneratorExecutors) { using (var data = new CompanyEntities()) { data.Configuration.AutoDetectChangesEnabled = false; //// data.Configuration.ProxyCreationEnabled = false; Console.WriteLine("Staring {0}...", dataGeneratorExecutor.DataGenerator.GetType().Name); dataGeneratorExecutor.Execute(data, RandomGenerator.Instance); Console.WriteLine("Saving {0}...", dataGeneratorExecutor.DataGenerator.GetType().Name); data.SaveChanges(); Console.WriteLine("Finished {0}.", dataGeneratorExecutor.DataGenerator.GetType().Name); } } }
private CompanySingletonRepository() { ServiceUtility serviceUtility = new ServiceUtility(); _rootUri = serviceUtility.BaseUri; _repositoryContext = new CompanyEntities(_rootUri); }
public void DeleteFromRepository(Company item) { if (_repositoryContext.GetEntityDescriptor(item) != null) {//if it exists in the db delete it from the db CompanyEntities context = new CompanyEntities(_rootUri); context.MergeOption = MergeOption.AppendOnly; context.IgnoreResourceNotFoundException = true; Company deletedCompany = (from q in context.Companies where q.CompanyID == item.CompanyID select q).FirstOrDefault(); if (deletedCompany != null) { context.DeleteObject(deletedCompany); context.SaveChanges(); } context = null; _repositoryContext.MergeOption = MergeOption.AppendOnly; //if it is being tracked remove it... if (GetCompanyEntityState(item) != EntityStates.Detached) { _repositoryContext.Detach(item); } } }
public void Generate(CompanyEntities db, IRandomGenerator random, int count) { var employeeIds = db.Employees.Select(d => d.Id).ToList(); var reports = new List <Report>(); foreach (var employeeId in employeeIds) { var employeeReportsCount = random.GetRandomNumber((int)(0.5 * count), (int)(1.5 * count)); for (var i = 0; i < employeeReportsCount; i++) { var reportTime = random.GetRandomNumber(0, 24 * 60 * 60 * 1000); var report = new Report() { EmployeeId = employeeId, ReportTime = DateTime.Now.AddSeconds(-reportTime) }; reports.Add(report); } } db.Reports.AddRange(reports); }
public WarehouseAddView() { InitializeComponent(); Parcel = new List <Parcel>(); WarehouseGrid.DataContext = Parcel; companyEntities = new CompanyEntities(); }
/// <summary> /// Checks if manager with the username and pass exists in tblManager in the database. /// </summary> /// <param name="userName"></param> /// <param name="password"></param> /// <returns></returns> internal bool IsManager(string userName, string password) { try { tblAccount account = new tblAccount(); tblManager manager = new tblManager(); using (CompanyEntities context = new CompanyEntities()) { try { account = GetAccount(userName, password); } catch { account = (from a in context.tblAccounts where a.UserName == userName select a).First(); manager = (from e in context.tblManagers where e.SparePass == password select e).First(); } manager = (from e in context.tblManagers where e.AccountID == account.AccountID select e).First(); return(true); } } catch { return(false); } }
/// <summary> /// Adds new account to tblAccount and adds an employee with the acount AccountID to database. /// </summary> /// <param name="account"></param> /// <param name="sector"></param> /// <param name="position"></param> /// <param name="experience"></param> /// <param name="qualification"></param> internal void AddManager(tblManager manager, tblAccount account) { using (CompanyEntities context = new CompanyEntities()) { tblAccount newAccount = new tblAccount(); newAccount.FirstName = account.FirstName; newAccount.LastName = account.LastName; newAccount.JMBG = account.JMBG; newAccount.Gender = account.Gender.ToUpper(); newAccount.City = account.City; newAccount.MarrigeStatusID = account.MarrigeStatusID; newAccount.UserName = account.UserName; newAccount.Pass = account.Pass; context.tblAccounts.Add(newAccount); context.SaveChanges(); tblManager newManager = new tblManager(); newManager.AccountID = newAccount.AccountID; newManager.Email = manager.Email; newManager.SparePass = manager.SparePass + "WPF"; newManager.OfficeNumber = manager.OfficeNumber; context.tblManagers.Add(newManager); context.SaveChanges(); } }
public void ViewOrder() { using (var database = new CompanyEntities()) { int customerId; var customer = new Customer(); Console.WriteLine("Enter your Name:" + customer.Name); customer.Name = Console.ReadLine(); var name = database.Customers.SingleOrDefault <Customer>(t => t.Name == customer.Name); customerId = name.CustomerId; if (name != null) { var orderlist = database.vOrderItems.ToList().Where(t => t.CustomerId == name.CustomerId); { Console.WriteLine("Your Orders"); foreach (var order in orderlist) { Console.WriteLine($"{order.ToyName} - {order.Price} - {order.Quantity} - {order.TotalPrice} - {order.OrderValue}"); } } } else { Console.WriteLine("You are not registered"); Console.WriteLine("Please register yourself"); AddCustomer(); } } }
public void ShippingDetail() { using (var database = new CompanyEntities()) { var shippingDetail = database.ShippingDetails; int customerId; var customer = new Customer(); Console.WriteLine("Enter your Name:" + customer.Name); customer.Name = Console.ReadLine(); var name = database.Customers.SingleOrDefault <Customer>(t => t.Name == customer.Name); customerId = name.CustomerId; if (name != null) { var shippinglist = database.ShippingDetails.ToList().Where(t => t.CustomerId == name.CustomerId); Console.WriteLine("Select your shipping detail:"); { foreach (var sd in shippinglist) { Console.WriteLine($"{sd.Address} - {sd.City} - {sd.State} - {sd.Country}"); } } } else { Console.WriteLine("You are not registered"); Console.WriteLine("Please register yourself"); AddCustomer(); } } }
public void AddCustomer() { using (var database = new CompanyEntities()) { var customer = new Customer(); Console.WriteLine("Enter your Name:" + customer.Name); customer.Name = Console.ReadLine(); Console.WriteLine("Enter your mobile number" + customer.MobileNumber); customer.MobileNumber = Console.ReadLine(); var cust = database.Customers.SingleOrDefault(t => t.Name == customer.Name && t.MobileNumber == customer.MobileNumber); if (cust == null) { database.Customers.Add(customer); database.SaveChanges(); Console.WriteLine("Customer Added to the list"); } else { Console.WriteLine("There is already such customer in the list"); throw new DuplicateWaitObjectException("There is already such customer in the list"); } AddShippingAddress(); } }
public static List <tbl_Employee> GetAllTbl_Employees() { using (CompanyEntities dbContext = new CompanyEntities()) { return(dbContext.tbl_Employee.ToList()); } }
/// <summary> /// Gets all marrige types from the database and adds them to the list. /// </summary> /// <returns></returns> internal List <tblMarrigeStatu> GetAllMarrigeTypes() { using (CompanyEntities context = new CompanyEntities()) { List <tblMarrigeStatu> list = (from a in context.tblMarrigeStatus select a).ToList(); return(list); } }
/// <summary> /// Gets all administrator types from the database and adds them to the list. /// </summary> /// <returns></returns> internal List <tblAdministratorType> GetAllAdminTypes() { using (CompanyEntities context = new CompanyEntities()) { List <tblAdministratorType> list = (from a in context.tblAdministratorTypes select a).ToList(); return(list); } }
public void Import() { Assembly.GetExecutingAssembly().GetTypes() .Where(t => typeof(IImporter).IsAssignableFrom(t) && !t.IsInterface) .Select(t => (IImporter)Activator.CreateInstance(t)) .OrderBy(t => t.Order) .ToList() .ForEach(i => { textWriter.Write(i.Message); var db = new CompanyEntities(); i.Get(db, this.textWriter); textWriter.WriteLine(); }); }