コード例 #1
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            SetPageTitle(L10n.Term("Terminology.LBL_LIST_FORM_TITLE"));
            // 06/04/2006 Paul.  Visibility is already controlled by the ASPX page, but it is probably a good idea to skip the load.
            this.Visible = SplendidCRM.Security.IS_ADMIN;
            if (!this.Visible)
            {
                return;
            }

            try
            {
                DbProviderFactory dbf = DbProviderFactories.GetFactory();
                using (IDbConnection con = dbf.CreateConnection())
                {
                    string sSQL;
                    sSQL = "select *                 " + ControlChars.CrLf
                           + "  from vwTERMINOLOGY_List" + ControlChars.CrLf
                           + " where 1 = 1             " + ControlChars.CrLf;
                    using (IDbCommand cmd = con.CreateCommand())
                    {
                        cmd.CommandText = sSQL;
                        // 01/12/2006 Paul.  ctlSearch.LANGUAGE is not working.
                        if (!IsPostBack)
                        {
                            Sql.AppendParameter(cmd, L10N.NormalizeCulture(L10n.NAME), 10, Sql.SqlFilterMode.Exact, "LANG");                             //ctlSearch.LANGUAGE = L10n.NAME;
                        }
                        else
                        {
                            ctlSearch.SqlSearchClause(cmd);
                        }
                        if (ctlSearch.GLOBAL_TERMS)
                        {
                            cmd.CommandText += "   and MODULE_NAME is null" + ControlChars.CrLf;
                        }
                        if (!ctlSearch.INCLUDE_LISTS)
                        {
                            cmd.CommandText += "   and LIST_NAME is null" + ControlChars.CrLf;
                        }

                        if (bDebug)
                        {
                            RegisterClientScriptBlock("SQLCode", Sql.ClientScriptBlock(cmd));
                        }

                        using (DbDataAdapter da = dbf.CreateDataAdapter())
                        {
                            ((IDbDataAdapter)da).SelectCommand = cmd;
                            using (DataTable dt = new DataTable())
                            {
                                da.Fill(dt);
                                vwMain             = dt.DefaultView;
                                grdMain.DataSource = vwMain;
                                if (!IsPostBack)
                                {
                                    // 12/14/2007 Paul.  Only set the default sort if it is not already set.  It may have been set by SearchView.
                                    if (String.IsNullOrEmpty(grdMain.SortColumn))
                                    {
                                        grdMain.SortColumn = "NAME";
                                        grdMain.SortOrder  = "asc";
                                    }
                                    grdMain.ApplySort();
                                    grdMain.DataBind();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                lblError.Text = ex.Message;
            }
            if (!IsPostBack)
            {
                // 06/09/2006 Paul.  Remove data binding in the user controls.  Binding is required, but only do so in the ASPX pages.
                //Page.DataBind();
            }
        }