private void AddEmployeeAddress_Click(object sender, RoutedEventArgs e) { if (this.AddressBox.SelectedIndex < 0) { MessageBox.Show("Please select an address", "NO ADDRESS SELECTED", MessageBoxButton.OK, MessageBoxImage.Error); return; } List <EmployeeAddress> checklist = EntityContentSelector.SelectEmployeeAddress(); bool containsResidence = checklist.Where(ea => ea.Bsn == this._employee.Bsn).Select(r => r.IsResidence).Contains(true); if (containsResidence && this.ResidenceBox.IsChecked == true) { MessageBox.Show("This employee already has a residence", "Residence Already Exists", MessageBoxButton.OK, MessageBoxImage.Error); return; } InsertIntoTable.InsertEmployeeAddress(this._employee.Bsn, this._addressList.ElementAt(this.AddressBox.SelectedIndex).PostalCode, this._addressList.ElementAt(this.AddressBox.SelectedIndex).Country, this.ResidenceBox.IsChecked == true); this.GetData(); var list = this.GetAddressesAssociatedWithEmployee(this._employeeAddressList, this._addressList); this.AddressListViewer.PopulateList(list); this.ShowResidence(); }
public static SqlBuilder Insert <T>(T instance, string TableName = null, string[] Properties = null, string[] ExcludeProperties = null) { InsertIntoTable table = SqlBuilder.Insert() .Into(TableName ?? instance.GetType().Name); Metadata.MetadataTable mt = SqlBuilder.DefaultMetadata.FindTable(TableName ?? instance.GetType().Name); if (Properties == null) { Properties = instance.GetType().GetProperties().Select(x => x.Name).ToArray(); } if (ExcludeProperties != null) { Properties = Properties.Except(ExcludeProperties).ToArray(); } foreach (Metadata.MetadataColumn col in mt.Columns.Values) { if (Properties.Contains(col.Name) && !col.IsIdentity && !col.IsReadOnly) { PropertyInfo prop = instance.GetType().GetProperty(col.Name); if (prop.CanRead && prop.CanWrite) { table.Value(prop.Name, prop.GetValue(instance)); } } } return(table.Output().PrimaryKey().Builder()); }
private void AddButton_Click(object sender, RoutedEventArgs e) { if (this.HeadquarterBox.SelectedIndex < 0) { MessageBox.Show("Please select a Headquarters", "NO HQ SELECTED", MessageBoxButton.OK, MessageBoxImage.Error); return; } float budget; int totalHours; if (!float.TryParse(this.Budget.Text, out budget)) { MessageBox.Show("Please enter a valid budget", "INVALID BUDGET", MessageBoxButton.OK, MessageBoxImage.Error); return; } float.TryParse(budget.ToString("0.00"), out budget); if (!int.TryParse(this.TotalHours.Text, out totalHours)) { MessageBox.Show("Please enter a valid amount of hours", "INVALID AMOUNT OF HOURS", MessageBoxButton.OK, MessageBoxImage.Error); return; } InsertIntoTable.InsertProject(budget, totalHours, this._hqList[this.HeadquarterBox.SelectedIndex].BuildingName); }
private void InsertIntoEmployeeTable_Click(object sender, RoutedEventArgs e) { int employeeBsn; if (!int.TryParse(this.EmployeeBsn.Text, out employeeBsn) || this.EmployeeBsn.Text.Length != 9) { MessageBox.Show("Please enter a valid BSN\n\nTIP: A valid BSN is 9 numbers long", "Invalid BSN", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (this.EmployeeName.Text.Length < 2 || this.EmployeeSurname.Text.Length <= 1) { MessageBox.Show("Please make sure the new employee his Name and Surname are filled in!", "Empty Fields", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (this.MainHeadquarters.SelectedIndex < 0 || this.MainHeadquarters.SelectedIndex > this._headquartersList.Count) { MessageBox.Show("Please make sure to select a main headquarters for the new employee", "Select main HQ", MessageBoxButton.OK, MessageBoxImage.Error); return; } InsertIntoTable.InsertEmployee(employeeBsn, this.EmployeeName.Text, this.EmployeeSurname.Text, this._headquartersList[this.MainHeadquarters.SelectedIndex].BuildingName); }
private string InsertSql() { StringBuilder sb = new StringBuilder(); InsertIntoTable BaseTable = this.BaseTable() as InsertIntoTable; string set = ""; string outputSelect = ""; SqlBuilder tb = this.TopBuilder; foreach (ParameterField field in BaseTable.FieldList) { tb.AddDeclaration(field.ParameterName, field.DeclareParameter()); set += field.SetParameter() + "\r\n"; } if (BaseTable.Output != null && BaseTable.Output.ParameterTable.FieldList.Count > 0) { tb.AddDeclaration(BaseTable.Output.ParameterName, BaseTable.Output.DeclareParameter()); outputSelect += BaseTable.Output.SetParameter() + "\r\n"; } sb.AppendLine(set); sb.AppendFormat(" INSERT INTO {0}({1})\r\n", BaseTable.Alias, BaseTable.ToSql()); if (BaseTable.Output != null && BaseTable.Output.ParameterTable.FieldList.Count > 0) { sb.AppendFormat("OUTPUT {0}\r\n", BaseTable.Output.ToSql()); } sb.AppendFormat("VALUES({0})\r\n", BaseTable.FieldParameters()); if (!string.IsNullOrEmpty(outputSelect)) { sb.AppendLine(outputSelect); } return(sb.ToString()); }
private void AddPosition_Click(object sender, RoutedEventArgs e) { if (this.PositionBox.SelectedIndex < 0) { MessageBox.Show("Please select a position", "NO POSITION SELECTED", MessageBoxButton.OK, MessageBoxImage.Error); return; } InsertIntoTable.InsertEmployeePosition(this._employee.Bsn, this._positionList[this.PositionBox.SelectedIndex].PositionName); this.PositionListViewer.PopulateList(this.GetPositionsOfEmployee()); }
private void AddDegree_Click(object sender, RoutedEventArgs e) { if (this.DegreeBox.SelectedIndex < 0) { MessageBox.Show("Please select a degree", "NO DEGREE SELECTED", MessageBoxButton.OK, MessageBoxImage.Error); return; } InsertIntoTable.InsertEmployeeDegree(this._employee.Bsn, this._degreeList[this.DegreeBox.SelectedIndex].Course); this.GetData(); this.DegreeViewer.PopulateList(this.GetDegreesOfEmployee(this._employeeDegreeList, this._degreeList)); }
private void AssignEmployee_Click(object sender, RoutedEventArgs e) { if (this.EmployeeBox.SelectedIndex < 0) { MessageBox.Show("Please select a employee", "NO EMPLOYEE SELECTED", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (this.EmployeePositionBox.SelectedIndex < 0) { MessageBox.Show("Please select a position", "NO POSITION SELECTED", MessageBoxButton.OK, MessageBoxImage.Error); return; } int workingHours; if (this.WorkingHours.Text == "" || !int.TryParse(this.WorkingHours.Text, out workingHours)) { MessageBox.Show("Please enter a valid amount of hours", "INVALID AMOUNT OF HOURS", MessageBoxButton.OK, MessageBoxImage.Error); return; } InsertIntoTable.InsertEmployeeProject(this._employeeList[this.EmployeeBox.SelectedIndex].Bsn, this._project.ProjectId, this._selectedPositionList[this.EmployeePositionBox.SelectedIndex].PositionName, workingHours); this.GetData(); }