コード例 #1
0
 private void OnBranchEditEnded()
 {
     if (selectedBranch.Id == 0)
     {
         EmployeeBranchRelation e = dataAccess.InserEmployeeBranchRelation(selectedBranch);
         if (e == null)
         {
             // Fehler
         }
         else
         {
             selectedBranch.Id = e.Id;
             if (selectedBranch.QuantCoBranchId != selectedItem.QuantCoBranchId)
             {
                 selectedItem.QuantCoBranchId = selectedBranch.QuantCoBranchId;
                 dataAccess.UpdateEmployee(selectedItem);
             }
             UpdatePreviousBranch();
             return;
         }
     }
     else
     {
         EmployeeBranchRelation e = dataAccess.UpdateEmployeeBranch(selectedBranch);
         if (e == null)
         {
             // Fehler
         }
         if (selectedBranch.QuantCoBranchId != selectedItem.QuantCoBranchId)
         {
             selectedItem.QuantCoBranchId = selectedBranch.QuantCoBranchId;
             dataAccess.UpdateEmployee(selectedItem);
         }
     }
 }
コード例 #2
0
        /// <summary>
        /// This Method adds records into EmployeeBranches if the databasetable is empty
        /// Foreach Employee a record is added if there is an entry in QuantCoBranchId
        /// </summary>
        private void UpdateEmployeeBranches()
        {
            List <EmployeeBranchRelation> branches = new List <EmployeeBranchRelation>();

            branches = dataAccess.GetAllEmployeeBranchesForEmployeeId(selectedItem.Id);
            if (branches.Count > 0)
            {
                return;
            }
            foreach (EmployeesForTravelExpenses employee in employees)
            {
                branches = new List <EmployeeBranchRelation>(dataAccess.GetAllEmployeeBranchesForEmployeeId(selectedItem.Id));
                if (branches.Count == 0 && employee.QuantCoBranchId > 0)
                {
                    // there is no record ==> insert record
                    EmployeeBranchRelation relation = new EmployeeBranchRelation
                    {
                        EmployeeId      = selectedItem.Id,
                        QuantCoBranchId = selectedItem.QuantCoBranchId,
                        ValidFrom       = new DateTime(DateTime.Now.Year, 1, 1),
                        ValidUntil      = null
                    };
                    dataAccess.InserEmployeeBranchRelation(relation);
                }
            }
        }
コード例 #3
0
        private void ReadEmployeeBranches()
        {
            if (selectedItem == null)
            {
                listOfBranches   = new ObservableCollection <EmployeeBranchRelation>();
                EmployeeBranches = CollectionViewSource.GetDefaultView(ConvertToEditList(listOfBranches));
                RaisePropertyChanged("EmployeeBranches");
                return;
            }
            listOfBranches = new ObservableCollection <EmployeeBranchRelation>(dataAccess.GetAllEmployeeBranchesForEmployeeId(selectedItem.Id));
            if (listOfBranches.Count == 0 && selectedItem.QuantCoBranchId > 0)
            {
                // there is no record ==> insert record
                EmployeeBranchRelation relation = new EmployeeBranchRelation
                {
                    EmployeeId      = selectedItem.Id,
                    QuantCoBranchId = selectedItem.QuantCoBranchId,
                    ValidFrom       = new DateTime(DateTime.Now.Year, 1, 1),
                    ValidUntil      = null
                };
                dataAccess.InserEmployeeBranchRelation(relation);
                listOfBranches.Add(relation);
            }
            if (listOfBranches.Count == 0 && selectedItem.QuantCoBranchId == 0)
            {
                // there is no record ==> insert record
                EmployeeBranchRelation relation = new EmployeeBranchRelation
                {
                    EmployeeId      = selectedItem.Id,
                    QuantCoBranchId = 1,
                    ValidFrom       = new DateTime(DateTime.Now.Year, 1, 1),
                    ValidUntil      = null
                };
                dataAccess.InserEmployeeBranchRelation(relation);
                listOfBranches.Add(relation);
            }
            EmployeeBranches = CollectionViewSource.GetDefaultView(ConvertToEditList(listOfBranches));
            // Sort EmployeeBranches
            EmployeeBranches.SortDescriptions.Add(new SortDescription
            {
                Direction    = ListSortDirection.Descending,
                PropertyName = "ValidFrom"
            });
            EmployeeBranches.CurrentChanged -= EmployeeBranches_CurrentChanged;
            EmployeeBranches.CurrentChanged += EmployeeBranches_CurrentChanged;

            selectedBranch = EmployeeBranches.CurrentItem as EmployeeBranchEdit;

            selectedItem.QuantCoBranchId = selectedBranch.QuantCoBranchId;
            RaisePropertyChanged("EmployeeBranches");
        }
コード例 #4
0
        private void OnRowEditEnded()
        {
            if (selectedItem.Id == 0)
            {
                EmployeesForTravelExpenses e = dataAccess.InsertEmployee(selectedItem);
                if (e == null)
                {
                    // Fehler
                }
                else
                {
                    selectedItem.Id = e.Id;

                    if (selectedItem.QuantCoBranchId > 0)
                    {
                        EmployeeBranchRelation relation = new EmployeeBranchRelation
                        {
                            EmployeeId      = selectedItem.Id,
                            QuantCoBranchId = selectedItem.QuantCoBranchId,
                            ValidFrom       = new DateTime(DateTime.Now.Year, 1, 1)
                        };
                        dataAccess.InserEmployeeBranchRelation(relation);
                    }
                    CanSelectBranch = false;

                    return;
                }
            }
            else
            {
                if (selectedBranch.QuantCoBranchId > 0)
                {
                    selectedItem.QuantCoBranchId = selectedBranch.QuantCoBranchId;
                }
                EmployeesForTravelExpenses e = dataAccess.UpdateEmployee(selectedItem);
                if (e == null)
                {
                    // Fehler
                }
            }
        }
コード例 #5
0
 private void EmployeeBranches_CurrentChanged(object sender, EventArgs e)
 {
     selectedBranch = EmployeeBranches.CurrentItem as EmployeeBranchRelation;
 }