Exemple #1
0
        public void RefreshDisplayGrid( )
        {
            DisplayGridView.TableName = this.TableName;
            DisplayGridView.Columns.Clear();
            DisplayGridView.ColumnConfigs = this.ColumnList;
            DisplayGridView.InitColumns();

            #region Script
            if (String.IsNullOrWhiteSpace(this.TableName))
            {
                if (String.IsNullOrWhiteSpace(Script) == false)
                {
                    DataSet ds = ConnectionManager.DatabaseHelper.RunQuery(Script);
                    if (ds != null && ds.Tables.Count > 0)
                    {
                        this.DisplayGridCtrl.DataSource = ds.Tables[0];
                        this.DisplayGridCtrl.RefreshDataSource();
                        DisplayGridView.ShowCustomization();
                    }
                }
                return;
            }
            #endregion

            if (ABCDataLib.Tables.CachingProvider.LookupTables.ContainsKey(this.TableName))
            {
                this.DisplayGridCtrl.DataSource = ABCDataLib.Tables.CachingProvider.LookupTables[this.TableName];
            }
            else
            {
                ConditionBuilder strBuilder = new ConditionBuilder();
                strBuilder.Append(String.Format(@"SELECT TOP 5 * FROM {0} ", this.TableName));
                if (ABCDataLib.Tables.StructureProvider.IsExistABCStatus(this.TableName))
                {
                    strBuilder.AddCondition(ABCDataLib.Generation.QueryGenerator.GenerateCondition(this.TableName, DataDefine.ColumnType.ABCStatus));
                }
                strBuilder.Append(String.Format(@" ORDER BY {0} DESC", ABCDataLib.Tables.StructureProvider.GetPrimaryKeyColumn(this.TableName)));

                try
                {
                    DataSet ds = ConnectionManager.DatabaseHelper.RunQuery(strBuilder.ToString());
                    if (ds != null && ds.Tables.Count > 0)
                    {
                        this.DisplayGridCtrl.DataSource = ds.Tables[0];
                    }
                }
                catch (Exception ex)
                {
                }
            }

            this.DisplayGridCtrl.RefreshDataSource();
            DisplayGridView.ShowCustomization();
        }
        public void Search( )
        {
            if (BindingObject != null && GridCtrl != null)
            {
                if (BindingObject.DataManager.MainObject == null)
                {
                    return;
                }

                BusinessObject           mainObj = BindingObject.DataManager.MainObject.DataObject as BusinessObject;
                BusinessObjectController ctrl    = BusinessControllerFactory.GetBusinessController(mainObj.AATableName);

                ConditionBuilder strBuilder = BindingObject.GenerateQuery(true);

                if (strBuilder == null || String.IsNullOrWhiteSpace(strBuilder.ToString()))
                {
                    return;
                }

                if (SearchPanel != null)
                {
                    SearchPanel.GetSearchQuery(strBuilder, SearchPanel);
                }

                if (BindingObject.DataManager.Screen.UIManager.View.DataField != null)
                {
                    GEVouchersInfo config = VoucherProvider.GetConfig(BindingObject.TableName, BindingObject.DataManager.Screen.UIManager.View.DataField.STViewNo);
                    if (config != null && !String.IsNullOrWhiteSpace(config.ConditionString))
                    {
                        strBuilder.AddCondition(config.ConditionString);
                    }
                }

                if (DataStructureProvider.IsTableColumn(BindingObject.TableName, ABCCommon.ABCConstString.colApprovalStatus))
                {
                    if (chkNotYetApproved.Checked)
                    {
                        strBuilder.AddCondition(String.Format("{0}<>'{1}'", ABCCommon.ABCConstString.colApprovalStatus, ABCCommon.ABCConstString.ApprovalTypeApproved));
                    }
                }

                if (DataStructureProvider.IsTableColumn(BindingObject.TableName, ABCCommon.ABCConstString.colLockStatus))
                {
                    if (chkLocked.Checked)
                    {
                        strBuilder.AddCondition(String.Format("{0}='{1}'", ABCCommon.ABCConstString.colLockStatus, ABCCommon.ABCConstString.LockStatusLocked));
                    }
                }

                if (DataStructureProvider.IsTableColumn(BindingObject.TableName, ABCCommon.ABCConstString.colJournalStatus))
                {
                    if (chkNotYetPosted.Checked)
                    {
                        strBuilder.AddCondition(String.Format("{0}<>'{1}'", ABCCommon.ABCConstString.colJournalStatus, ABCCommon.ABCConstString.PostStatusPosted));
                    }
                }

                object datasource = null;
                Type   objType    = BusinessObjectFactory.GetBusinessObjectType(GridCtrl.TableName);
                if (objType != null)
                {
                    Type       typeABCList = typeof(ABCList <>).MakeGenericType(objType);
                    MethodInfo method;
                    if (typeABCList != null)
                    {
                        datasource = ABCBusinessEntities.ABCDynamicInvoker.CreateInstanceObject(typeABCList);
                        method     = typeABCList.GetMethod("LoadData", new Type[] { typeof(List <BusinessObject>) });
                        method.Invoke(datasource, new object[] { ctrl.GetListByQuery(strBuilder.ToString()) });
                    }
                }
                binding.DataSource = datasource;
                binding.ResetBindings(false);

                this.GridCtrl.GridDefaultView.BestFitColumns();

                for (int i = 0; i < this.GridCtrl.GridDefaultView.DataRowCount; i++)
                {
                    BusinessObject obj = this.GridCtrl.GridDefaultView.GetRow(i) as BusinessObject;
                    if (obj != null && obj.GetID() == mainObj.GetID())
                    {
                        this.GridCtrl.GridDefaultView.FocusedRowHandle = i;
                        return;
                    }
                }
            }
        }