コード例 #1
0
 private void RowBeginEdit(object sender, DataGridBeginningEditEventArgs e)
 {
     DataLayer.EmployeeAccount ne = (DataLayer.EmployeeAccount)e.Row.Item;
     if (ne?.AccountId == 0 && ne.Account == null)
     {
         ne.Account = new Account();
     }
 }
コード例 #2
0
 public void NewEmployeeAccount()
 {
     using (var ctx = new PayrollDB(Properties.Settings.Default.PayrollDB))
     {
         DataLayer.EmployeeAccount newemp = ctx.Accounts.CreateObject <DataLayer.EmployeeAccount>();
         ctx.Accounts.AddObject(newemp);
         CurrentEmployeeAccount = newemp;
     }
 }
コード例 #3
0
 internal void DeleteEmployeeAccount(DataLayer.EmployeeAccount p)
 {
     if (p.AccountId != 0)
     {
         using (var ctx = new PayrollDB(Properties.Settings.Default.PayrollDB))
         {
             var ritm = ctx.EmployeeAccounts.FirstOrDefault(x => x.AccountId == p.AccountId);
             ctx.EmployeeAccounts.DeleteObject(ritm);
             OnStaticPropertyChanged("CurrentEmployee");
             OnStaticPropertyChanged("EmployeeAccounts");
         }
     }
     p = null;
 }
コード例 #4
0
        private void DataGrid_RowEditEnding_1(object sender, DataGridRowEditEndingEventArgs e)
        {
            if (e.Row.IsNewItem == true && im.CurrentEmployee != null)
            {
                if (im.CurrentEmployee == null)
                {
                    return;
                }
                var emp = im.CurrentEmployee;
                im.SaveEmployee();
                using (var ctx = new PayrollDB(Properties.Settings.Default.PayrollDB))
                {
                    DataLayer.EmployeeAccount ne = (DataLayer.EmployeeAccount)e.Row.Item;

                    var inst = ctx.Institutions
                               .FirstOrDefault(i => i.InstitutionId == ne.Account.InstitutionId);
                    if (inst != null)
                    {
                        ne.EmployeeId          = emp.EmployeeId;
                        ne.Account.AccountName = emp.FirstName + " " +
                                                 inst.ShortName +
                                                 " Salary Account";
                        ne.Account.AccountTypeId = ctx.AccountTypes.First(x => x.Name == "Salary").AccountTypeId;
                        if (ne.AccountId == 0)
                        {
                            ctx.EmployeeAccounts.AddObject(ne);
                        }
                        else
                        {
                            var ritm = ctx.EmployeeAccounts.First(x => x.AccountId == ne.AccountId);
                            ctx.EmployeeAccounts.Attach(ritm);
                            ctx.EmployeeAccounts.ApplyCurrentValues(ne);
                        }

                        BaseViewModel.SaveDatabase(ctx);
                    }

                    im.LoadEmployees();
                }
            }
            e.Cancel = true;
        }