Esempio n. 1
0
        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;
            }
        }
 public FormRoom()
 {
     InitializeComponent();
     grdRoom.AutoGenerateColumns = false;
     Presenter = new RoomPresenter(this);
     Name      = string.Empty;
 }
Esempio n. 3
0
        private void bwAsync_DoWork(object sender, DoWorkEventArgs e)
        {
            Stopwatch mStopWatch = new Stopwatch();

            mStopWatch.Start();

            SanitaLogEx.d(TAG, "Start database cache...");
            PostMessage("Start database cache ...");
            IsCacheCompleted = false;

            try
            {
                //Update timer
                SystemInfo.NOW = SoftUpdatePresenter.GetCurrentTime(null, null);

                //Kiểm tra và nâng cấp cấu trúc database
                Splasher.Status = "Check and update database...";
                SoftUpdatePresenter.DoUpdateDatabaseSQL();

                using (IDbConnection connection = SoftUpdatePresenter.GetConnection())
                {
                    //Open connection
                    connection.Open();

                    //Begin transtation
                    using (IDbTransaction trans = connection.BeginTransaction())
                    {
                        Splasher.Status = "Đang xử lý : Danh sách danh mục...".Translate();
                        DM_Intent_Type.InitDefaultList(DM_Intent_TypePresenter.GetDM_Intent_Types(connection, trans));
                        MyVar.mListDM_Intent_Type = DM_Intent_Type.GetDefaultList(0).OrderBy(p => p.DM_Intent_TypeID).ToList();

                        DM_Entity_Type.InitDefaultList(DM_Entity_TypePresenter.GetDM_Entity_Types(connection, trans));
                        MyVar.mListDM_Entity_Type = DM_Entity_Type.GetDefaultList(0).OrderBy(p => p.DM_Entity_TypeID).ToList();

                        MyVar.mListUser   = UserPresenter.GetUsers(connection, trans);
                        MyVar.mListHome   = HomePresenter.GetHomes(connection, trans);
                        MyVar.mListRoom   = RoomPresenter.GetRooms(connection, trans);
                        MyVar.mListDevice = DevicePresenter.GetDevices(connection, trans);

                        //-----------------------------------------------------------------------------

                        //Commit transtation
                        trans.Commit();

                        //Close connection
                        connection.Close();
                    }
                }

                SanitaLogEx.d(TAG, "End database cache...");
            }
            catch (Exception ex)
            {
                SanitaLogEx.e(TAG, "bwAsync_DoWork error !", ex);
            }

            IsCacheCompleted = true;
        }
Esempio n. 4
0
 private void btnXoa_Click(object sender, EventArgs e)
 {
     Room data = mListViewData.SelectedObject as Room;
     if (data != null && data.RoomID > 0)
     {
         if (SanitaMessageBox.Show("Bạn có chắc chắn muốn xóa không ?", "Thông Báo", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
         {
             if (RoomPresenter.DeleteRoom(data) > 0)
             {
                 DoRefresh();
             }
         }
     }
 }
Esempio n. 5
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var studentRepository = new StudentRepository("student");
            var roomRepository    = new RoomRepository("room");
            var laptopRepository  = new LaptopRepository("laptop");

            var view = new DormitoryForm();

            var studentPresenter = new StudentPresenter(view, studentRepository);
            var roomPresenter    = new RoomPresenter(view, roomRepository);
            var laptopPresenter  = new LaptopPresenter(view, laptopRepository);

            Application.Run(view);
        }
Esempio n. 6
0
        public MainFormPresenter(IMainformView pView, LightState pState)
        {
            mView  = pView;
            mState = pState;

            mRoomPresenter = new RoomPresenter(mView.RoomView, pState);
            mRoomPresenter.RoomSaveFired += new gigaFlash.Delegates.TypedDelegate <UserPrefObj>(OnRoomSaveFired);

            mView.PreferencesLoaded    += new gigaFlash.Delegates.TypedDelegate <UserPrefObj>(LoadPreferences);
            mView.LightSelectorClicked += new gigaFlash.Delegates.VoidDelegate(OnLightSelectorClicked);
            mView.SnakeModuleClicked   += new gigaFlash.Delegates.VoidDelegate(OnSnakeModuleClicked);
            mView.AmpSineClicked       += new gigaFlash.Delegates.VoidDelegate(OnAmpSineClicked);
            mView.ThunderClicked       += new gigaFlash.Delegates.VoidDelegate(OnThunderClicked);

            mView.MoveLightLeftEvent  += new gigaFlash.Delegates.VoidDelegate(OnLightLeftEvent);
            mView.MoveLightRightEvent += new gigaFlash.Delegates.VoidDelegate(OnLightRightEvent);
            mView.ClickEventFired     += new gigaFlash.Delegates.VoidDelegate(OnClickEvent);
        }
Esempio n. 7
0
        private void bwAsync_Worker(object sender, DoWorkEventArgs e)
        {
            ProcessingType type = (ProcessingType)e.Argument;
            e.Result = type;

            switch (type)
            {
                case ProcessingType.LoadData:
                    {
                        mListData_Flat = RoomPresenter.GetRooms(null, null);
                        MyVar.mListRoom = mListData_Flat;

                        //Update dữ liệu
                        mListData = new List<Room>();
                        foreach (Home nhom_khoa in MyVar.mListHome)
                        {
                            if (mListData_Flat.Any(p => p.HomeID == nhom_khoa.HomeID))
                            {
                                Room group_Room = new Room();
                                group_Room.HomeID = nhom_khoa.HomeID;
                                group_Room.RoomID = -1;
                                group_Room.RoomName = nhom_khoa.HomeName;
                                group_Room.mListSubData = mListData_Flat.Where(p => p.HomeID == nhom_khoa.HomeID).ToList();
                                mListData.Add(group_Room);
                            }
                        }

                        //Update danh sách                 
                        {
                            mListThongTinDanhSachRoom = new List<ThongTinDanhSachRoom>();
                            mListThongTinDanhSachRoom_Flat = new List<ThongTinDanhSachRoom>();
                            ThongTinDanhSachRoom.ThongTinDanhSachRoomID_Index = 1;

                            //Add tất cả khoa
                            ThongTinDanhSachRoom root = new ThongTinDanhSachRoom();
                            root.ThongTinDanhSachRoomType = (int)ThongTinDanhSachRoom.TYPE.ROOT;
                            root.mListData = mListData;
                            root.ThongTinDanhSachRoomName = "Tất Cả Phòng (" + mListData_Flat.Where(p => p.RoomID > 0).Count() + ")";
                            mListThongTinDanhSachRoom.Add(root);
                            mListThongTinDanhSachRoom_Flat.Add(root);
                        }

                        foreach (DM_Room_Group nhom_dich_vu in DM_Room_Group.GetDefaultList(0))
                        {
                            ThongTinDanhSachRoom mData = new ThongTinDanhSachRoom();
                            mData.ThongTinDanhSachRoomType = (int)ThongTinDanhSachRoom.TYPE.GROUP;
                            mData.DM_Room_GroupID = nhom_dich_vu.DM_Room_GroupID;
                            mData.mListSubData = new List<ThongTinDanhSachRoom>();
                            mData.mListData = mListData;
                            mData.ThongTinDanhSachRoomName = DM_Room_Group.GetDefault(mData.DM_Room_GroupID).DM_Room_GroupName;

                            //Add loại khoa
                            {
                                IList<DM_Room_SubGroup> list_sub = DM_Room_SubGroup.GetDefaultList_Group(0, mData.DM_Room_GroupID);
                                foreach (DM_Room_SubGroup sub_data in list_sub)
                                {
                                    ThongTinDanhSachRoom mSubData = new ThongTinDanhSachRoom();
                                    mSubData.ThongTinDanhSachRoomType = (int)ThongTinDanhSachRoom.TYPE.SUB_GROUP;
                                    mSubData.DM_Room_GroupID = mData.DM_Room_GroupID;
                                    mSubData.DM_Room_SubGroupID = sub_data.DM_Room_SubGroupID;
                                    mSubData.mListData = new List<Room>();
                                    mSubData.ThongTinDanhSachRoomName = DM_Room_SubGroup.GetDefault(mSubData.DM_Room_SubGroupID).DM_Room_SubGroupName;

                                    //Loai 
                                    if (sub_data.DM_Room_GroupID == DM_Room_Group.HOME)
                                    {
                                        int loai_khoa = sub_data.DM_Room_SubGroupID - DM_Room_SubGroup.HOME_INIT;
                                        mSubData.mListData = mListData_Flat.Where(p => p.HomeID == loai_khoa).ToList();
                                    }

                                    if (sub_data.DM_Room_GroupID == DM_Room_Group.USER)
                                    {
                                        int loai_khoa = sub_data.DM_Room_SubGroupID - DM_Room_SubGroup.USER_INIT;
                                        mSubData.mListData = mListData_Flat.Where(p => p.UserID == loai_khoa).ToList();
                                    }

                                    //Check
                                    if (mSubData.mListData.Count > 0)
                                    {
                                        mSubData.ThongTinDanhSachRoomName += " (" + mSubData.mListData.Count + ")";
                                        mData.mListSubData.Add(mSubData);
                                        mListThongTinDanhSachRoom_Flat.Add(mSubData);
                                    }
                                }
                            }

                            //Check
                            if (mData.mListData.Count > 0)
                            {
                                mListThongTinDanhSachRoom.Add(mData);
                                mListThongTinDanhSachRoom_Flat.Add(mData);
                            }
                        }
                    }
                    break;
                default:
                    break;
            }
        }
Esempio n. 8
0
        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;
            }
        }
Esempio n. 9
0
        public String ExecuteCommand(Intent_Request data)
        {
            EntityParam thiet_bi = data.mListParam.FirstOrDefault(p => p.Name == "thiet_bi");

            if (thiet_bi == null)
            {
                return("<speak><p><s>Bạn hãy nói tên thiết bị</s></p></speak>");
            }

            //Danh sách thiết bị
            IList <Device> mListDevice = DevicePresenter.GetDevices(null, null);
            IList <Room>   mListRoom   = RoomPresenter.GetRooms(null, null);

            foreach (Device device in mListDevice)
            {
                device.mRoom = mListRoom.FirstOrDefault(p => p.RoomID == device.RoomID);
                device.mRoom = device.mRoom ?? new Room();
            }

            Device mDevice = null;

            while (true)
            {
                //Tìm thiết bị trùng khớp
                //ví dụ "đèn ngủ 1"
                {
                    mDevice = mListDevice.FirstOrDefault(p => p.DeviceName.EqualTextNoCase(thiet_bi.Value));
                    if (mDevice != null)
                    {
                        break;
                    }
                }

                //Tìm thiết bị gồm tên thiết bị (đầy đủ) + tên phòng
                //ví dụ "đèn ngủ 1 phòng khách"
                {
                    mDevice = mListDevice.FirstOrDefault(p => (p.DeviceName + " " + p.mRoom.RoomName).EqualTextNoCase(thiet_bi.Value));
                    if (mDevice != null)
                    {
                        break;
                    }
                }

                //Tìm thiết bị gồm tên thiết bị (ngắn gọn) + tên phòng
                //ví dụ "đèn phòng khách"
                {
                    mDevice = mListDevice.FirstOrDefault(p => (p.DeviceName_Short + " " + p.mRoom.RoomName).EqualTextNoCase(thiet_bi.Value));
                    if (mDevice != null)
                    {
                        break;
                    }
                }

                //Tìm thiết bị cùng phòng (tên đầy đủ)
                {
                    mListDevice = mListDevice.Where(p => p.RoomID == data.mDevice.RoomID).ToList();

                    {
                        mDevice = mListDevice.FirstOrDefault(p => p.DeviceName.EqualTextNoCase(thiet_bi.Value));
                        if (mDevice != null)
                        {
                            break;
                        }
                    }

                    //Tìm thiết bị cùng phòng (tên ngắn gọn)
                    {
                        mDevice = mListDevice.FirstOrDefault(p => p.DeviceName_Short.EqualTextNoCase(thiet_bi.Value));
                        if (mDevice != null)
                        {
                            break;
                        }
                    }
                }

                break;
            }

            if (mDevice != null)
            {
                switch (data.DM_Entity_TypeID)
                {
                case DM_Entity_Type.HOME_CONTROL_BAT_THIET_VI:
                {
                    if (UtilityHassIO.mInstance.Switch_Turn_OnOff(data.mDevice.mUser.HassIO_URL, data.mDevice.mUser.HassIO_KEY, mDevice.DeviceCode, "on"))
                    {
                        return(String.Format("<speak><p><s>Đã bật {0}</s></p></speak>", mDevice.DeviceName));
                    }
                    else
                    {
                        return(String.Format("<speak><p><s>Xin lỗi, tôi không thực hiện được yêu cầu của bạn</s></p></speak>", mDevice.DeviceName));
                    }
                }

                case DM_Entity_Type.HOME_CONTROL_TAT_THIET_VI:
                {
                    if (UtilityHassIO.mInstance.Switch_Turn_OnOff(data.mDevice.mUser.HassIO_URL, data.mDevice.mUser.HassIO_KEY, mDevice.DeviceCode, "off"))
                    {
                        return(String.Format("<speak><p><s>Đã tắt {0}</s></p></speak>", mDevice.DeviceName));
                    }
                    else
                    {
                        return(String.Format("<speak><p><s>Xin lỗi, tôi không thực hiện được yêu cầu của bạn</s></p></speak>", mDevice.DeviceName));
                    }
                }

                default:
                    break;
                }
            }
            else
            {
                return("<speak><p><s>Tôi không tìm được thiết bị trong nhà của bạn</s></p></speak>");
            }

            return("");
        }