private void bwAsync_Worker(object sender, DoWorkEventArgs e) { ProcessingType type = (ProcessingType)e.Argument; e.Result = type; switch (type) { case ProcessingType.SaveData: { if (mRoom.RoomID > 0) { RoomPresenter.UpdateRoom(mRoom); } else { RoomPresenter.InsertRoom(mRoom); } } break; default: break; } }
private void bwAsync_Worker(object sender, DoWorkEventArgs e) { ProcessingType type = (ProcessingType)e.Argument; e.Result = type; switch (type) { case ProcessingType.LoadData: { mListUser = UserPresenter.GetUsers(null, null); MyVar.mListUser = mListUser; } break; case ProcessingType.PhanQuyenHome: { IList <int> _list_id = new List <int>(); if (!String.IsNullOrEmpty(ListHomeID)) { foreach (String strID in ListHomeID.Split(';')) { int id = 0; int.TryParse(strID, out id); if (id > 0) { _list_id.Add(id); } } } foreach (Home home in MyVar.mListHome) { if (_list_id.Contains(home.HomeID)) { if (home.UserID != mUser.UserID) { home.UserID = mUser.UserID; HomePresenter.UpdateHome(home); } } else { if (home.UserID == mUser.UserID) { home.UserID = 0; HomePresenter.UpdateHome(home); } } } } break; case ProcessingType.PhanQuyenPhong: { IList <int> _list_id = new List <int>(); if (!String.IsNullOrEmpty(ListRoomID)) { foreach (String strID in ListRoomID.Split(';')) { int id = 0; int.TryParse(strID, out id); if (id > 0) { _list_id.Add(id); } } } foreach (Room mRoom in MyVar.mListRoom) { if (_list_id.Contains(mRoom.HomeID)) { if (mRoom.UserID != mUser.UserID) { mRoom.UserID = mUser.UserID; RoomPresenter.UpdateRoom(mRoom); } } else { if (mRoom.UserID == mUser.UserID) { mRoom.UserID = 0; RoomPresenter.UpdateRoom(mRoom); } } } } break; case ProcessingType.PhanQuyenThietBi: { IList <int> _list_id = new List <int>(); if (!String.IsNullOrEmpty(ListDeviceID)) { foreach (String strID in ListDeviceID.Split(';')) { int id = 0; int.TryParse(strID, out id); if (id > 0) { _list_id.Add(id); } } } foreach (Device mDevice in MyVar.mListDevice) { if (_list_id.Contains(mDevice.HomeID)) { if (mDevice.UserID != mUser.UserID) { mDevice.UserID = mUser.UserID; DevicePresenter.UpdateDevice(mDevice); } } else { if (mDevice.UserID == mUser.UserID) { mDevice.UserID = 0; DevicePresenter.UpdateDevice(mDevice); } } } } break; default: break; } }