Ejemplo n.º 1
0
 /// <summary>
 /// 报表设置
 /// </summary>
 /// <returns></returns>
 protected void SetReportSet()
 {
     //查报表的DataGridView
     foreach (Control ctr in pnlReport.Controls)
     {
         if (ctr is DataGridViewReport)
         {
             DataGridViewReport dgv = (DataGridViewReport)ctr;
             //查询用户对报表的设置
             DataTable dt = DBHelper.GetTable("", "tb_report_set", "*", string.Format("set_object='{0}' and set_user='******'", styleObject, GlobalStaticObj.UserID), "", "");
             if (dt == null || dt.Rows.Count == 0)
             {
                 return;
             }
             foreach (DataRow dr in dt.Rows)
             {
                 int columnIndex = Convert.ToInt32(dr["set_num"]);
                 dgv.Columns[columnIndex].Visible = CommonCtrl.IsNullToString(dr["is_show"]) == "1"; //控制是否显示
                 dgv.Columns[columnIndex].Width   = Convert.ToInt32(dr["set_width"]);                //列宽
             }
             //设置列不能排序
             foreach (DataGridViewColumn dgvc in dgv.Columns)
             {
                 dgvc.SortMode = DataGridViewColumnSortMode.NotSortable;
             }
             break;
         }
     }
 }
Ejemplo n.º 2
0
        //报表加载
        private void UCReport_Load(object sender, EventArgs e)
        {
            #region 设置
            //设置页面按钮可见性
            var btnCols = new ObservableCollection <ButtonEx_sms>
            {
                btnExport, btnView, btnPrint, btnSet
            };
            UIAssistants.SetUCBaseFuncationVisible(this, btnCols);
            #endregion
            UIAssistants.SetButtonStyle4QueryAndClear(btnSearch, btnClear);  //设置查询按钮和清除按钮样式
            if (string.IsNullOrEmpty(styleObject))
            {
                return;
            }
            foreach (Control ctr in pnlReport.Controls)
            {
                if (ctr is DataGridViewReport)
                {
                    DataGridViewReport dgv = (DataGridViewReport)ctr;
                    #region 判断是否有当前用户、当前报表的设置,如果没有则创建
                    if (!DBHelper.IsExist("", "tb_report_set", string.Format("set_object='{0}' and set_user='******'", styleObject, GlobalStaticObj.UserID)))
                    {
                        List <SysSQLString> listSql = new List <SysSQLString>();
                        foreach (DataGridViewColumn dgvc in dgv.Columns)
                        {
                            if (dgvc.Visible)
                            {
                                SysSQLString sql = new SysSQLString();
                                sql.cmdType   = CommandType.Text;
                                sql.sqlString = @"insert INTO tb_report_set (set_id,set_num,set_object,set_user,set_name,set_data_name,set_width,is_show,is_print) 
                                            values (@set_id,@set_num,@set_object,@set_user,@set_name,@set_data_name,@set_width,@is_show,@is_print)";
                                sql.Param     = new Dictionary <string, string>();
                                sql.Param.Add("set_id", Guid.NewGuid().ToString());
                                sql.Param.Add("set_num", dgvc.Index.ToString());
                                sql.Param.Add("set_object", styleObject);
                                sql.Param.Add("set_user", GlobalStaticObj.UserID);
                                sql.Param.Add("set_name", dgvc.HeaderText);
                                sql.Param.Add("set_data_name", dgvc.DataPropertyName);
                                sql.Param.Add("set_width", dgvc.Width.ToString());
                                sql.Param.Add("is_show", "1");
                                sql.Param.Add("is_print", "1");
                                listSql.Add(sql);
                            }
                        }
                        if (listSql.Count > 0)
                        {
                            DBHelper.BatchExeSQLStringMultiByTrans("", listSql);
                        }
                    }
                    #endregion
                    dgv.CellFormatting += new DataGridViewCellFormattingEventHandler(dgv_CellFormatting);
                    break;
                }
            }

            SetReportSet();
        }