Exemplo n.º 1
0
        private void UpdateStatus(TableQueryResponseModel response)
        {
            if (response == null)
            {
                pageNextGrid.Visibility = Visibility.Collapsed;
                return;
            }
            int totalPages = response.TotalPage;

            if (totalPages > 0)
            {
                lblTotalPages.Content   = string.Format("总页数:{0}", totalPages);
                lblCurrentPage.Content  = string.Format("当前页:{0}", response.PageNumber);
                lblTotalCount.Content   = string.Format("总记录数:{0}", response.TotalCount);
                txtPageNumber.Text      = response.PageNumber.ToString();
                btnPreview.IsEnabled    = response.PageNumber > 1 ? true : false;
                btnNext.IsEnabled       = response.PageNumber < totalPages ? true : false;
                btnGoPage.IsEnabled     = totalPages > 1 ? true : false;
                pageNextGrid.Visibility = Visibility.Visible;
            }
            else
            {
                pageNextGrid.Visibility = Visibility.Collapsed;
            }
        }
Exemplo n.º 2
0
        private void PageQuery(int pageNumber)
        {
            if (cmbCity.SelectedIndex == -1)
            {
                ShowWarning("请选择城市!");
                cmbCity.Focus();
                return;
            }
            cityIds[cmbTable.SelectedIndex] = cmbCity.SelectedValue;
            TableQueryResponseModel response = new TableQueryResponseModel();

            CurrentData.Instance.QueryResult[cmbTable.SelectedIndex] = response;
            SetEnabled(false);
            try
            {
                var inputObj = GetTableQueryCriteria(cmbTable.SelectedIndex, pageNumber, (int)cmbCity.SelectedValue, dpBeginDate.SelectedDate.Value, dpEndDate.SelectedDate.Value);
                DbHelper.PageQueryTable(inputObj, response);
                response.Status      = 1;
                dgResult.DataContext = response.Result;
                UpdateStatus(response);
            }
            catch (Exception ex)
            {
                response.Status  = -1;
                response.Message = ex.Message;
                CurrentData.Instance.Logger.Error(ex);
                ShowError(ex.Message);
            }
            SetEnabled(true);
        }
Exemplo n.º 3
0
        public static TableQueryResponseModel PageQueryTable(TableQueryCriteria queryCriteria, TableQueryResponseModel queryResult)
        {
            if (queryCriteria.PageNumber < 1)
            {
                queryCriteria.PageNumber = 1;
            }
            queryResult.PageNumber = queryCriteria.PageNumber;
            queryResult.PageSize   = ConfigHelper.PageSize;

            var countSql = CountSqlBuilder(queryCriteria);
            var pageSql  = PageSqlBuilder(queryCriteria);

            #region query code

            #region db server
            string serverName = queryCriteria.DBServer;
            string dbName     = queryCriteria.DBName;
            var    dbConnList = ConfigHelper.GetConnectionStrings();
            if (dbConnList == null || !dbConnList.ContainsKey(serverName))
            {
                throw new Exception("connectionStrings不存在的数据库服务器名称:" + serverName);
            }
            ConnectionStringSettings   connSettings = dbConnList[serverName];
            SqlConnectionStringBuilder cnBuilder    = new SqlConnectionStringBuilder(connSettings.ConnectionString);
            if (cnBuilder.InitialCatalog != dbName)
            {
                cnBuilder.InitialCatalog = dbName;
            }
            #endregion

            DbProviderFactory factory = null;
            DbConnection      conn    = null;
            DbCommand         command = null;
            try
            {
                factory = DbProviderFactories.GetFactory(connSettings.ProviderName);
                conn    = factory.CreateConnection();
                conn.ConnectionString = cnBuilder.ConnectionString;
                conn.Open();
                command             = conn.CreateCommand();
                command.CommandType = CommandType.Text;
                #region read table
                //读取总记录数
                command.CommandText    = countSql;
                queryResult.TotalCount = (int)command.ExecuteScalar();
                //分页读取
                command.CommandText = pageSql;
                using (DbDataAdapter reader = factory.CreateDataAdapter())
                {
                    reader.SelectCommand = command;
                    DataSet ds = new DataSet();
                    reader.Fill(ds);
                    reader.Dispose();
                    queryResult.Result = ds.Tables[0];
                }
                //移除rowNumber列
                queryResult.Result.Columns.Remove("rowNumber");
                #endregion
            }
            finally
            {
                #region dispose
                if (command != null)
                {
                    command.Dispose();
                    command = null;
                }
                if (conn != null)
                {
                    conn.Close();
                    conn = null;
                }
                #endregion
            }
            #endregion

            return(queryResult);
        }