コード例 #1
0
        /// <summary>
        /// 绑定数据
        /// </summary>
        void BindDataGridView()
        {
            int page = pages;

            //************czlt-2011-03-07*End*************


            //注销
            //DataSet ds = aBLL.GetEmployeeAttendancePersonelStatistic(dtpStartTime.Value.ToString("yyyy-MM-dd"), dtpEndTime.Value.ToString("yyyy-MM-dd"), strWhere, page, pSize, out strErr);

            //czlt-2011-10-18 考勤合并
            DataSet ds = aBLL.Czlt_GetEmployeeAttendancePersonelStatistic(isUnion, dtpStartTime.Value.ToString("yyyy-MM-dd"), dtpEndTime.Value.ToString("yyyy-MM-dd"), Where, page, pSize, endWhere, out strErr);

            try
            {
                if (ds != null && ds.Tables.Count > 0)
                {
                    DataTable dt = new DataTable();

                    //更改名称 发码器->发码器编号
                    ds.Tables[0].Columns[0].ColumnName = HardwareName.Value(CorpsName.CodeSenderAddress);
                    ds.Tables[0].TableName             = "A_AttendancePersonelStatistic";
                    if (ds.Tables[0].Columns.Contains("跟班"))
                    {
                        ds.Tables[0].Columns.Remove("跟班");
                    }
                    dgrd.Invoke(new MethodInvoker(delegate()
                    {
                        dgrd.DataSource = ds.Tables[0];
                    }));


                    // 重新设置页数
                    int sumPage = int.Parse(ds.Tables[1].Rows[0][0].ToString());
                    sumPage   = sumPage % pSize != 0 ? sumPage / pSize + 1 : sumPage / pSize;
                    countPage = sumPage;

                    if (sumPage == 0)
                    {
                        this.Invoke(new MethodInvoker(delegate()
                        {
                            lblCounts.Text = "共 0 条记录";

                            lblPageCounts.Text = "1";
                            lblSumPage.Text    = "/1页";

                            btnUpPage.Enabled   = false;
                            btnDownPage.Enabled = false;
                        }));
                    }
                    else
                    {
                        this.Invoke(new MethodInvoker(delegate()
                        {
                            lblCounts.Text = "共 " + ds.Tables[1].Rows[0][0].ToString() + " 条记录";

                            lblPageCounts.Text = page.ToString();
                            lblSumPage.Text    = "/" + sumPage + "页";

                            //控制翻页状态
                            SetPageEnable(page, sumPage);
                        }));
                    }
                    //***************czlt-2010-8-24*start*************************************
                    this.Invoke(new MethodInvoker(delegate()
                    {
                        if (ds.Tables[0].Columns.Count >= 9)
                        {
                            for (int i = 5; i < ds.Tables[0].Columns.Count; i++)
                            {
                                dgrd.Columns[i].DefaultCellStyle.ForeColor = Color.FromArgb(0, 0, 255);
                                // Font f = new Font("Tahoma",FontStyle.Underline);
                                //DataGridColumnStyle dgvStyle = new datagridviews
                                System.Windows.Forms.DataGridViewCellStyle dgvStyle = new System.Windows.Forms.DataGridViewCellStyle();
                                dgvStyle.Font                    = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
                                dgvStyle.ForeColor               = Color.FromArgb(0, 0, 255);
                                dgvStyle.SelectionForeColor      = Color.Red;
                                dgrd.Columns[i].DefaultCellStyle = dgvStyle;
                            }
                        }
                        if (dgrd.Columns["deptID"] != null)
                        {
                            dgrd.Columns["deptID"].Visible = false;
                        }
                    }));
                }
                else
                {
                    DataTable dt = new DataTable("A_AttendancePersonelStatistic_BindDataGridView");
                    dt.Columns.Add("部门名称");
                    dt.Columns.Add("班制");
                    dt.Columns.Add("出勤汇总");
                    dt.Columns.Add("早班汇总");
                    dt.Columns.Add("中班汇总");
                    dt.Columns.Add("晚班汇总");
                    dt.Columns.Add("请假汇总");
                    this.Invoke(new MethodInvoker(delegate()
                    {
                        dgrd.DataSource = dt;
                        lblCounts.Text  = "共 0 个人";
                    }));
                }
            }
            catch
            {
                DataTable dt = new DataTable("A_AttendancePersonelStatistic_BindDataGridView");
                dt.Columns.Add("部门名称");
                dt.Columns.Add("班制");
                dt.Columns.Add("出勤汇总");
                dt.Columns.Add("早班汇总");
                dt.Columns.Add("中班汇总");
                dt.Columns.Add("晚班汇总");
                dt.Columns.Add("请假汇总");
                this.Invoke(new MethodInvoker(delegate()
                {
                    dgrd.DataSource = dt;
                    lblCounts.Text  = "共 0 个人";
                }));
            }
        }