Exemple #1
0
        public void UpdateStaff(StaffData newitem)
        {
            hasError = false;
            try
            {
                using (TraditionAssetEntities db = new TraditionAssetEntities())
                {
                    var staff_ = db.staff.FirstOrDefault(x => x.staff_id == newitem.staff_id);
                    if (staff_ != null)
                    {
                        staff_.firstname     = newitem.firstname;
                        staff_.lastname      = newitem.lastname;
                        staff_.aka           = newitem.aka;
                        staff_.start_date    = newitem.start_date;
                        staff_.end_date      = newitem.end_date;
                        staff_.is_active     = newitem.is_active;
                        staff_.modified_date = DateTime.Now;

                        db.staff.AddOrUpdate(staff_);
                        db.SaveChanges();
                        MessageBox.Show("Update complete");
                    }
                    else
                    {
                        MessageBox.Show("Can not update");
                    }
                }
            }
            catch (Exception ex)
            {
                errorMessage = "Update error, " + ex.Message;
                hasError     = true;
            }
        }
Exemple #2
0
        public ObservableCollection <StaffData> GetStaff()
        {
            hasError = false;
            ObservableCollection <StaffData> _staff = new ObservableCollection <StaffData>();

            try
            {
                TraditionAssetEntities db = new TraditionAssetEntities();
                var query = db.staff.ToList();
                foreach (var item in query)
                {
                    StaffData pTemp = new StaffData(/*item*/);
                    pTemp.staff_id      = item.staff_id;
                    pTemp.aka           = item.aka;
                    pTemp.firstname     = item.firstname;
                    pTemp.lastname      = item.lastname;
                    pTemp.start_date    = (DateTime)item.start_date;
                    pTemp.end_date      = (DateTime)item.end_date;
                    pTemp.is_active     = (bool)item.is_active;
                    pTemp.create_date   = (DateTime)item.create_date;
                    pTemp.modified_date = (DateTime)item.modified_date;

                    //if (pTemp.is_active == true)
                    //{
                    _staff.Add(pTemp);
                    //}
                }
            }
            catch (Exception ex)
            {
                errorMessage = "GetStaff() error, " + ex.Message;
                hasError     = true;
            }
            return(_staff);
        }
Exemple #3
0
        public ObservableCollection <StaffData> GetStaffFromAsset(AssetData item)
        {
            hasError = false;
            ObservableCollection <StaffData> _result = new ObservableCollection <StaffData>();

            try
            {
                TraditionAssetEntities db = new TraditionAssetEntities();

                var query = db.staff.FirstOrDefault(x => x.staff_id == item.Using_by_staff_id);

                if (query != null)
                {
                    StaffData pTemp = new StaffData(/*item*/);
                    pTemp.staff_id = query.staff_id;

                    _result.Add(pTemp);
                }
                else
                {
                    MessageBox.Show("NOT FOUND");
                }
            }
            catch (Exception ex)
            {
                errorMessage = "GetAssetTypeFromAsset() error, " + ex.Message;
                hasError     = true;
            }
            return(_result);
        }
Exemple #4
0
 public void AddStaff(StaffData item)
 {
     hasError = false;
     try
     {
         TraditionAssetEntities db = new TraditionAssetEntities();
         var data = new staff()
         {
             //staff_id = item.staff_id,
             firstname     = item.firstname,
             lastname      = item.lastname,
             aka           = item.aka,
             start_date    = item.start_date,
             end_date      = item.end_date,
             is_active     = item.is_active,
             create_date   = DateTime.Now,
             modified_date = DateTime.Now
         };
         db.staff.Add(data);
         db.SaveChanges();
         MessageBox.Show("Insert complete");
     }
     catch (Exception ex)
     {
         errorMessage = "Add error, " + ex.Message;
         hasError     = true;
     }
 }