Exemple #1
0
        /// <summary>
        /// 刷新控件
        /// </summary>
        void RefreshControl()
        {
            ClearControl();

            if (SelectedNode == null)
            {
                return;
            }

            if (SelectedNode.Text == "部门分类")
            {
                m_findPersonnel = m_personnelInfo.GetAllInfo();
            }
            else
            {
                View_Department dept = SelectedNode.Tag as View_Department;

                m_findPersonnel = m_personnelInfo.GetAllInfo(dept.部门代码);
                cmbDepot.Text   = dept.部门名称;
                cmbDepot.Tag    = dept.部门代码;
            }

            string strSelect = "";

            if (cmbPositionStatus.Text != "全部")
            {
                if (cmbPositionStatus.Text == "在职")
                {
                    strSelect += " and 是否在职 = 1 ";
                }
                else
                {
                    strSelect += " and 是否在职 = 0 ";
                }
            }

            if (cmbUseStatus.Text != "全  部")
            {
                if (cmbUseStatus.Text == "已停用")
                {
                    strSelect += " and DeleteFlag = 1";
                }
                else
                {
                    strSelect += " and DeleteFlag = 0";
                }
            }

            if (cmbUserStatus.Text != "全    部")
            {
                if (cmbUserStatus.Text == "操作用户")
                {
                    strSelect += " and 是否操作用户 = 1";
                }
                else
                {
                    strSelect += " and 是否操作用户 = 0";
                }
            }

            DataTable dt = GlobalObject.GeneralFunction.ConvertToDataTable <View_HR_Personnel>(m_findPersonnel);

            DataTable dtHR = new DataTable();

            if (strSelect.Trim().Length > 0 && dt.Rows.Count > 0)
            {
                dtHR = dt.Clone();

                strSelect = strSelect.Substring(5, strSelect.Length - 5);

                DataRow[] dr = dt.Select(strSelect);

                for (int i = 0; i < dr.Length; i++)
                {
                    dtHR.ImportRow(dr[i]);
                }
            }
            else
            {
                dtHR = dt;
            }

            dataGridView1.DataSource = dtHR;

            this.dataGridView1.ColumnWidthChanged -= new System.Windows.Forms.DataGridViewColumnEventHandler(
                this.dataGridView1_ColumnWidthChanged);

            ColumnWidthControl.SetDataGridView(labelTitle.Text, dataGridView1);

            this.dataGridView1.ColumnWidthChanged += new System.Windows.Forms.DataGridViewColumnEventHandler(
                this.dataGridView1_ColumnWidthChanged);

            if (m_dataLocalizer == null)
            {
                m_dataLocalizer = new UserControlDataLocalizer(dataGridView1, this.Name,
                                                               UniversalFunction.SelectHideFields(this.Name, dataGridView1.Name, BasicInfo.LoginID));

                panelTop.Controls.Add(m_dataLocalizer);
                m_dataLocalizer.Dock = DockStyle.Bottom;
            }

            if (dataGridView1.Rows.Count == 0)
            {
                panelTop.Visible = false;
            }
            else
            {
                panelTop.Visible = true;
            }


            dataGridView1.Refresh();
        }
Exemple #2
0
        /// <summary>
        /// 窗体加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FormSelectUser_Load(object sender, EventArgs e)
        {
            try
            {
                if (AllUser == null)
                {
                    if (DeptCode == null)
                    {
                        AllUser = m_personnelInfo.GetAllInfo().ToList();
                    }
                    else
                    {
                        AllUser = m_personnelInfo.GetAllInfo(DeptCode).ToList();
                    }
                }

                DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn();

                column.Visible    = true;
                column.Name       = "选中";
                column.HeaderText = "选中";
                column.ReadOnly   = false;

                dataGridView.Columns.Add(column);

                dataGridView.Columns.Add("工号", "工号");
                dataGridView.Columns.Add("姓名", "姓名");
                dataGridView.Columns.Add("部门名称", "部门名称");
                dataGridView.Columns.Add("职位", "职位");
                dataGridView.Columns.Add("备注", "备注");

                foreach (DataGridViewColumn item in dataGridView.Columns)
                {
                    if (item.Name != "选中")
                    {
                        item.ReadOnly = true;
                        item.Width    = item.HeaderText.Length * (int)this.Font.Size + 100;
                    }
                    else
                    {
                        item.Width    = 68;
                        item.ReadOnly = false;
                        item.Frozen   = false;
                    }
                }

                bool selectedFlag = false;
                int  count        = 0;

                dataGridView.Rows.Clear();
                foreach (var item in AllUser)
                {
                    selectedFlag = false;

                    if (SelectedUser != null && count < SelectedUser.Count)
                    {
                        if (SelectedUser.FindIndex(c => c.工号 == item.工号) >= 0)
                        {
                            selectedFlag = true;
                            count++;
                        }
                    }

                    dataGridView.Rows.Add(new object[] { selectedFlag, item.工号, item.姓名, item.部门名称, item.职位, item.备注 });
                }

                if (m_dataLocalizer == null)
                {
                    m_dataLocalizer = new UserControlDataLocalizer(dataGridView, this.Name,
                                                                   UniversalFunction.SelectHideFields(this.Name, dataGridView.Name, BasicInfo.LoginID));

                    panelTop.Controls.Add(m_dataLocalizer);

                    m_dataLocalizer.Dock = DockStyle.Bottom;
                }
            }
            catch (Exception err)
            {
                MessageDialog.ShowErrorMessage(err.Message);
            }
        }