Beispiel #1
0
    protected void Query(int offset)
    {
        try
        {
            GameServer server = ServerDropDownList.SelectedGameServer;
            if (server == null)
            {
                LabelOpMsg.Text = string.Format(StringDef.MsgCannotBeNone, StringDef.GameServer);
                return;
            }
            if (!server.IsConnected)
            {
                LabelOpMsg.Text = StringDef.NoConnectionAlert;
                return;
            }
            ArrayList     paramList       = new ArrayList();
            StringBuilder searchCondition = new StringBuilder();

            string seller = TextBoxSeller.Text.Trim();
            if (seller.Length != 0)
            {
                if (CheckBoxSeller.Checked)
                {
                    searchCondition.Append(string.Format(" AND {0}='?'", FS2TableString.AuctionFieldSellerName));
                }
                else
                {
                    searchCondition.Append(string.Format(" AND {0} LIKE '%?%'", FS2TableString.AuctionFieldSellerName));
                }
                paramList.Add(seller);
            }

            string buyer = TextBoxBuyer.Text.Trim();
            if (buyer.Length != 0)
            {
                if (CheckBoxBuyer.Checked)
                {
                    searchCondition.AppendFormat(" AND {0}='?'", FS2TableString.AuctionFieldBuyerName);
                }
                else
                {
                    searchCondition.AppendFormat(" AND {0} LIKE '%?%'", FS2TableString.AuctionFieldBuyerName);
                }
                paramList.Add(buyer);
            }

            string itemName = TextBoxItemName.Text.Trim();
            if (itemName.Length != 0)
            {
                if (CheckBoxItemName.Checked)
                {
                    searchCondition.AppendFormat(" AND {0}='?'", FS2TableString.AuctionFieldGoodsName);
                }
                else
                {
                    searchCondition.AppendFormat(" AND {0} LIKE '%?%'", FS2TableString.AuctionFieldGoodsName);
                }
                paramList.Add(itemName);
            }

            //if (StartDate.Selected)
            //{
            //    searchCondition.AppendFormat(" AND {0}>='{1}'", FS2TableString.LogFieldLogTime, StartDate.SelectedDate);
            //}
            //if (EndDate.Selected)
            //{
            //    searchCondition.AppendFormat(" AND {0}<'{1}'", FS2TableString.LogFieldLogTime, EndDate.SelectedDate.AddDays(1));
            //}

            if (searchCondition.Length > 0)
            {
                searchCondition.Remove(0, 4);
                searchCondition.Insert(0, " WHERE");
            }

            string orderByType = string.Empty;
            switch (ListBoxOrderByType.SelectedIndex)
            {
            case 0:
                orderByType = "ASC";
                break;

            case 1:
                orderByType = "DESC";
                break;
            }
            string orderByStatement = string.Empty;
            switch (ListBoxOrderBy.SelectedIndex)
            {
            case 0:
                orderByStatement = string.Format(" ORDER BY {0} {1}", FS2TableString.AuctionFieldCurrentPrice, orderByType);
                break;

            case 1:
                orderByStatement = string.Format(" ORDER BY {0} {1}", FS2TableString.AuctionFieldPassPrice, orderByType);
                break;
            }

            int    limitCount     = _recordPerPage;
            string limitStatement = string.Format(" LIMIT {0},{1}", offset, limitCount);

            string cmdText      = "SELECT {0} FROM {1} {2} {3} {4}";
            string cmdFieldText = string.Format("{0},{1},{2},{3},{4},{5},{6},{7}",
                                                FS2TableString.AuctionFieldSellerName,
                                                FS2TableString.AuctionFieldGoodsName,
                                                FS2TableString.AuctionFieldBuyerName,
                                                FS2TableString.AuctionFieldStartTime,
                                                FS2TableString.AuctionFieldFinishTime,
                                                FS2TableString.AuctionFieldCurrentPrice,
                                                FS2TableString.AuctionFieldPassPrice,
                                                FS2TableString.AuctionFieldItemData);

            SqlCommand cmd    = new SqlCommand(string.Format(cmdText, cmdFieldText, FS2TableString.AuctionTableName, searchCondition.ToString(), orderByStatement, limitStatement), paramList.ToArray());
            SqlResult  result = WebUtil.QueryGameServerDb(CurrentUser.Id, server, cmd);
            if (result != null && result.Success)
            {
                result.SetFieldType(new SqlDataType[] {
                    SqlDataType.String,
                    SqlDataType.String,
                    SqlDataType.String,
                    SqlDataType.DateTime,
                    SqlDataType.DateTime,
                    SqlDataType.UInt32,
                    SqlDataType.UInt32,
                    SqlDataType.Blob
                });

                object[]  record = null;
                ArrayList infos  = new ArrayList();

                while ((record = result.ReadRecord()) != null)
                {
                    AuctionRoomItem info = new AuctionRoomItem();
                    info.SellerName   = record[0] as string;
                    info.GoodsName    = record[1] as string;
                    info.BuyerName    = record[2] as string;
                    info.StartTime    = (DateTime)record[3];
                    info.FinishTime   = (DateTime)record[4];
                    info.CurrentPrice = (uint)record[5];
                    info.PassPrice    = (uint)record[6];
                    info.ItemData     = FS2ItemDataInfo.ParseItem((byte[])record[7]);

                    infos.Add(info);
                }

                ViewState[WebConfig.SessionQueryLogOffset] = offset;

                ButtonPreviousPage.Enabled = (offset > 0);
                ButtonFirstPage.Enabled    = (offset > 0);
                ButtonNextPage.Enabled     = (infos.Count >= limitCount);

                ViewState[WebConfig.ParamServerId] = server.Id;
                if (infos.Count != 0)
                {
                    DataGridAuctionItem.DataSource = CreateDataSource(infos);
                    DataGridAuctionItem.DataBind();
                    PanelResult.Visible = true;
                }
                else
                {
                    LabelOpMsg.Text     = StringDef.NoMatchingRecord;
                    PanelResult.Visible = false;
                }
            }
            else
            {
                if (result == null)
                {
                    LabelOpMsg.Text = StringDef.QueryTimeOut;
                }
                else
                {
                    LabelOpMsg.Text = StringDef.OperationFail;
                }
                PanelResult.Visible = false;
            }
        }
        catch (Exception ex)
        {
            LabelOpMsg.Text     = ex.Message;
            PanelResult.Visible = false;
        }
    }