Exemplo n.º 1
0
        private void executeQuery()
        {
            this.Cursor = Cursors.WaitCursor;
            string colName = GridViewBusStation.FocusedColumn.FieldName;
            string value   = String.Empty;

            if (!string.IsNullOrWhiteSpace(GridViewBusStation.GetFocusedDisplayText()))
            {
                value = GridViewBusStation.GetFocusedDisplayText();
            }
            if (!string.IsNullOrWhiteSpace(value))
            {
                string query   = String.Format("it.Name like '{0}%'", GridViewBusStation.GetRowCellDisplayText(GridControl.AutoFilterRowHandle, "Name"));
                var    special = context.BusStation.Where(query);

                if (!string.IsNullOrWhiteSpace(GridViewBusStation.GetRowCellDisplayText(GridControl.AutoFilterRowHandle, "Code")))
                {
                    query   = String.Format("it.{0} like '{1}%'", "Code", GridViewBusStation.GetRowCellDisplayText(GridControl.AutoFilterRowHandle, "Code"));
                    special = special.Where(query);
                }

                int count = special.Count();
                if (count > 0)
                {
                    BusStationBindingSource.DataSource = special;
                    GridViewBusStation.ClearColumnsFilter();
                }
                else
                {
                    MessageBox.Show("No records in database.");
                    GridViewBusStation.ClearColumnsFilter();
                }
            }
            this.Cursor = Cursors.Default;
        }
Exemplo n.º 2
0
 private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
 {
     GridViewBusStation.ClearColumnsFilter();
     if (BusStationBindingSource.Current == null)
     {
         //fake query in order to create a link between the database table and the binding source
         BusStationBindingSource.DataSource = from opt in context.BusStation where opt.Code == "KJM9" select opt;
         BusStationBindingSource.AddNew();
         if (GridViewBusStation.FocusedRowHandle == GridControl.AutoFilterRowHandle)
         {
             GridViewBusStation.FocusedRowHandle = GridViewBusStation.RowCount - 1;
         }
         setValues();
         codeTextBox.Focus();
         setReadOnly(false);
         newRec = true;
         return;
     }
     codeTextBox.Focus();
     // bindingNavigatorPositionItem.Focus();  //trigger field leave event
     GridViewBusStation.CloseEditor();
     temp = newRec;
     if (checkForms())
     {
         if (!temp)
         {
             context.Refresh(System.Data.Entity.Core.Objects.RefreshMode.StoreWins, ( BusStation)BusStationBindingSource.Current);
         }
         BusStationBindingSource.AddNew();
         if (GridViewBusStation.FocusedRowHandle == GridControl.AutoFilterRowHandle)
         {
             GridViewBusStation.FocusedRowHandle = GridViewBusStation.RowCount - 1;
         }
         setValues();
         codeTextBox.Focus();
         setReadOnly(false);
         newRec = true;
     }
 }