private void button1_Click(object sender, EventArgs e)
        {
            dbContext = new BusinessDataBaseEntities();

            CBDepartment.ItemCheck += CBDepartment_ItemCheck;


            var q = from b in dbContext.BulletinBoards
                    join d in dbContext.Departments
                    on b.DepartmentID equals d.departmentID
                    join g in dbContext.Groups
                    on b.GroupID equals g.GroupID
                    join em in dbContext.Employees
                    on b.EmployeeID equals em.employeeID
                    select new { 部門 = d.name, 組別 = g.GroupName, 姓名 = em.EmployeeName, 留言內容 = b.Content, 張貼時間 = b.PostTime };


            dataGridView1.DataSource = q.OrderByDescending(o => o.張貼時間).ToList();

            dgvFormat(dataGridView1);

            CBDepartment.SetItemChecked(0, true);
            CBDepartment.SetItemChecked(1, true);
            CBDepartment.SetItemChecked(2, true);
            CBDepartment.SetItemChecked(3, true);
            CBDepartment.SetItemChecked(4, true);

            CBGroup.SetItemChecked(0, true);
            CBGroup.SetItemChecked(1, true);

            //this.dataGridView1.Update();
            //this.dataGridView1.Refresh();
        }
        private void BulletinBoard_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < DepartmentArr.Length; i++)
            {
                CCBoxItem item = new CCBoxItem(DepartmentArr[i], i);
                CBDepartment.Items.Add(item);
            }

            // If more then 5 items, add a scroll bar to the dropdown.
            CBDepartment.MaxDropDownItems = 5;
            // Make the "Name" property the one to display, rather than the ToString() representation.
            CBDepartment.DisplayMember  = "Name";
            CBDepartment.ValueSeparator = ", ";
            // Check the first 2 items.
            CBDepartment.SetItemChecked(0, true);
            CBDepartment.SetItemChecked(1, true);
            CBDepartment.SetItemChecked(2, true);
            CBDepartment.SetItemChecked(3, true);
            CBDepartment.SetItemChecked(4, true);
            //ccb.SetItemCheckState(1, CheckState.Indeterminate);



            if (CBDepartment.CheckedIndices.Contains(1))
            {
                for (int i = 0; i < GroupArr.Length; i++)
                {
                    CCBoxItem item2 = new CCBoxItem(GroupArr[i], i);
                    CBGroup.Items.Add(item2);
                }

                // If more then 5 items, add a scroll bar to the dropdown.
                CBGroup.MaxDropDownItems = 3;
                // Make the "Name" property the one to display, rather than the ToString() representation.
                CBGroup.DisplayMember  = "Name";
                CBGroup.ValueSeparator = ", ";
                // Check the first 2 items.
                CBGroup.SetItemChecked(0, true);
                CBGroup.SetItemChecked(1, true);
                //ccb.SetItemCheckState(1, CheckState.Indeterminate);
            }
        }
Esempio n. 3
0
        private void OnErrorOccurred(object sender, EventArgs e)
        {
            if (_manageDriverViewModel.IsErrorInFirstName)
            {
                LblErrorMsg.Text = "First Name must be not null and contains alphabet only.";
                TxtFirstName.Focus();
                return;
            }

            if (_manageDriverViewModel.IsErrorInLastName)
            {
                LblErrorMsg.Text = "Last Name must be not null and contains alphabet only.";
                TxtLastName.Focus();
                return;
            }

            if (_manageDriverViewModel.IsErrorInUsername && _manageDriverViewModel.IsAddingDriver)
            {
                LblErrorMsg.Text = string.IsNullOrEmpty(_manageDriverViewModel.ErrorMessage) ? "Username must be not null and contains alphanumberic only." : _manageDriverViewModel.ErrorMessage;;
                TxtUsername.Focus();
                return;
            }

            if (_manageDriverViewModel.IsErrorInPin)
            {
                LblErrorMsg.Text = "Pin number must be four digit only, no any aphabet allowed.";
                TxtPin.Focus();
                return;
            }

            if (_manageDriverViewModel.IsErrorInGroup)
            {
                LblErrorMsg.Text = "Please select any Group.";
                CBGroup.Focus();
                return;
            }
        }
        private void CBDepartment_DropDownClosed(object sender, EventArgs e)
        {
            BusinessDataBaseEntities dbContext;

            this.dataGridView1.DataSource = null;

            CBGroup.Items.Clear();


            //Department
            if (CBDepartment.CheckedIndices.Contains(1))
            {
                for (int i = 0; i < GroupArr.Length; i++)
                {
                    CCBoxItem item2 = new CCBoxItem(GroupArr[i], i);
                    CBGroup.Items.Add(item2);
                }

                // If more then 5 items, add a scroll bar to the dropdown.
                CBGroup.MaxDropDownItems = 2;
                // Make the "Name" property the one to display, rather than the ToString() representation.
                CBGroup.DisplayMember  = "Name";
                CBGroup.ValueSeparator = ", ";
                // Check the first 2 items.
                CBGroup.SetItemChecked(0, true);
                CBGroup.SetItemChecked(1, true);
                //CBGroup.SetItemCheckState(1, CheckState.Indeterminate);



                //foreach (CCBoxItem item in CBDepartment.CheckedItems)
                //{
                //    sb.Append(item.Name).Append(CBDepartment.ValueSeparator);
                //}
            }
            else
            {
                CBGroup.Items.Clear();
                CBGroup.Text = "(無組別)";
            }

            DataTable dt = new DataTable();

            dt.Columns.Add(new DataColumn("部門", typeof(string)));
            dt.Columns.Add(new DataColumn("組別", typeof(string)));
            dt.Columns.Add(new DataColumn("姓名", typeof(string)));
            dt.Columns.Add(new DataColumn("留言內容", typeof(string)));
            dt.Columns.Add(new DataColumn("張貼時間", typeof(DateTime)));


            dbContext = new BusinessDataBaseEntities();


            this.dataGridView1.DataSource = null;
            this.dataGridView1.DataSource = dt;
            dgvFormat(dataGridView1);

            if (CBDepartment.CheckedIndices.Contains(0))
            {
                var q = from b in dbContext.BulletinBoards.AsEnumerable()
                        join d in dbContext.Departments.AsEnumerable()
                        on b.DepartmentID equals d.departmentID
                        join g in dbContext.Groups.AsEnumerable()
                        on b.GroupID equals g.GroupID
                        join em in dbContext.Employees.AsEnumerable()
                        on b.EmployeeID equals em.employeeID
                        where b.DepartmentID == 2
                        select new { 部門 = d.name, 組別 = g.GroupName, 姓名 = em.EmployeeName, 留言內容 = b.Content, 張貼時間 = b.PostTime };

                q.OrderByDescending(o => o.張貼時間).ToList().ForEach(q1 => dt.Rows.Add(q1.部門, q1.組別, q1.姓名, q1.留言內容, q1.張貼時間));
            }


            if (CBDepartment.CheckedIndices.Contains(1))
            {
                var q = from b in dbContext.BulletinBoards.AsEnumerable()
                        join d in dbContext.Departments.AsEnumerable()
                        on b.DepartmentID equals d.departmentID
                        join g in dbContext.Groups.AsEnumerable()
                        on b.GroupID equals g.GroupID
                        join em in dbContext.Employees.AsEnumerable()
                        on b.EmployeeID equals em.employeeID
                        where b.DepartmentID == 3
                        select new { 部門 = d.name, 組別 = g.GroupName, 姓名 = em.EmployeeName, 留言內容 = b.Content, 張貼時間 = b.PostTime };

                q.OrderByDescending(o => o.張貼時間).ToList().ForEach(q1 => dt.Rows.Add(q1.部門, q1.組別, q1.姓名, q1.留言內容, q1.張貼時間));
            }

            if (CBDepartment.CheckedIndices.Contains(2))
            {
                var q = from b in dbContext.BulletinBoards.AsEnumerable()
                        join d in dbContext.Departments.AsEnumerable()
                        on b.DepartmentID equals d.departmentID
                        join g in dbContext.Groups.AsEnumerable()
                        on b.GroupID equals g.GroupID
                        join em in dbContext.Employees.AsEnumerable()
                        on b.EmployeeID equals em.employeeID
                        where b.DepartmentID == 4
                        select new { 部門 = d.name, 組別 = g.GroupName, 姓名 = em.EmployeeName, 留言內容 = b.Content, 張貼時間 = b.PostTime };

                q.OrderByDescending(o => o.張貼時間).ToList().ForEach(q1 => dt.Rows.Add(q1.部門, q1.組別, q1.姓名, q1.留言內容, q1.張貼時間));
            }


            if (CBDepartment.CheckedIndices.Contains(3))
            {
                var q = from b in dbContext.BulletinBoards.AsEnumerable()
                        join d in dbContext.Departments.AsEnumerable()
                        on b.DepartmentID equals d.departmentID
                        join g in dbContext.Groups.AsEnumerable()
                        on b.GroupID equals g.GroupID
                        join em in dbContext.Employees.AsEnumerable()
                        on b.EmployeeID equals em.employeeID
                        where b.DepartmentID == 5
                        select new { 部門 = d.name, 組別 = g.GroupName, 姓名 = em.EmployeeName, 留言內容 = b.Content, 張貼時間 = b.PostTime };

                q.OrderByDescending(o => o.張貼時間).ToList().ForEach(q1 => dt.Rows.Add(q1.部門, q1.組別, q1.姓名, q1.留言內容, q1.張貼時間));
            }


            if (CBDepartment.CheckedIndices.Contains(4))
            {
                var q = from b in dbContext.BulletinBoards.AsEnumerable()
                        join d in dbContext.Departments.AsEnumerable()
                        on b.DepartmentID equals d.departmentID
                        join g in dbContext.Groups.AsEnumerable()
                        on b.GroupID equals g.GroupID
                        join em in dbContext.Employees.AsEnumerable()
                        on b.EmployeeID equals em.employeeID
                        where b.DepartmentID == 6
                        select new { 部門 = d.name, 組別 = g.GroupName, 姓名 = em.EmployeeName, 留言內容 = b.Content, 張貼時間 = b.PostTime };

                q.OrderByDescending(o => o.張貼時間).ToList().ForEach(q1 => dt.Rows.Add(q1.部門, q1.組別, q1.姓名, q1.留言內容, q1.張貼時間));
            }
        }