Exemplo n.º 1
0
 public PFFilterForm(string queryText, DataTable queryDataTable, PFFilter filter)
 {
     this.QueryText      = queryText;
     this.QueryDataTable = queryDataTable;
     this.Filter         = filter;
 }
Exemplo n.º 2
0
        public void ShowFilterForm(string tableName, string filterFile)
        {
            PFFilterForm frm            = new PFFilterForm();
            DialogResult res            = DialogResult.None;
            string       dbPlatformDesc = DatabasePlatform.Unknown.ToString();
            PFDatabase   db             = null;
            string       connStr        = string.Empty;
            string       nmSpace        = string.Empty;
            string       clsName        = string.Empty;
            string       dllPath        = string.Empty;
            DataTable    dt             = null;
            PFFilter     filter         = new PFFilter();
            DataView     dv             = null;
            string       configValue    = string.Empty;
            string       configKey      = string.Empty;

            try
            {
                _msg.Length = 0;
                _msg.Append("ShowFilterForm started ...\r\n");
                WriteToMessageLog(_msg.ToString());

                configValue = AppConfig.GetStringValueFromConfigFile("DefaultConnection_SQLServerCE35", string.Empty);
                if (configValue == string.Empty)
                {
                    _msg.Length = 0;
                    _msg.Append("Unable to find config.sys entry for DefaultConnection_SQLServerCE35");
                    throw new System.Exception(_msg.ToString());
                }
                dbPlatformDesc = DatabasePlatform.SQLServerCE35.ToString();
                connStr        = configValue;

                dbPlatformDesc = DatabasePlatform.SQLServerCE35.ToString();
                configValue    = AppConfig.GetStringValueFromConfigFile(dbPlatformDesc, string.Empty);
                string[] parsedConfig = configValue.Split('|');
                nmSpace = parsedConfig[0];
                clsName = parsedConfig[1];
                dllPath = parsedConfig[2];

                db = new PFDatabase(dbPlatformDesc, dllPath, nmSpace + "." + clsName);
                db.ConnectionString = connStr;
                db.OpenConnection();

                if (String.IsNullOrEmpty(filterFile))
                {
                    configKey   = dbPlatformDesc + "_" + tableName;
                    configValue = AppConfig.GetStringValueFromConfigFile(configKey, string.Empty);
                    if (configValue == string.Empty)
                    {
                        _msg.Length = 0;
                        _msg.Append("Unable to find ");
                        _msg.Append(configKey);
                        _msg.Append(" in config.sys.");
                        AppMessages.DisplayErrorMessage(_msg.ToString());
                        return;
                    }
                    //db.SQLQuery = "select  CustomerKey ,GeographyKey ,CustomerAlternateKey ,Title ,FirstName ,MiddleName ,LastName ,NameStyle ,BirthDate ,MaritalStatus ,Suffix ,Gender ,EmailAddress ,YearlyIncome ,TotalChildren ,NumberChildrenAtHome ,EnglishEducation ,SpanishEducation ,FrenchEducation ,EnglishOccupation ,SpanishOccupation ,FrenchOccupation ,HouseOwnerFlag ,NumberCarsOwned ,AddressLine1 ,AddressLine2 ,Phone ,DateFirstPurchase ,CommuteDistance from DimCustomer where 1=0";
                    db.SQLQuery = configValue;
                    filter      = new PFFilter();
                }
                else
                {
                    if (File.Exists(filterFile))
                    {
                        filter      = PFFilter.LoadFromXmlFile(filterFile);
                        db.SQLQuery = filter.QueryText;
                    }
                    else
                    {
                        configKey   = dbPlatformDesc + "_" + tableName;
                        configValue = AppConfig.GetStringValueFromConfigFile(configKey, string.Empty);
                        if (configValue == string.Empty)
                        {
                            _msg.Length = 0;
                            _msg.Append("Unable to find ");
                            _msg.Append(configKey);
                            _msg.Append(" in config.sys.");
                            AppMessages.DisplayErrorMessage(_msg.ToString());
                            return;
                        }
                        //db.SQLQuery = "select  CustomerKey ,GeographyKey ,CustomerAlternateKey ,Title ,FirstName ,MiddleName ,LastName ,NameStyle ,BirthDate ,MaritalStatus ,Suffix ,Gender ,EmailAddress ,YearlyIncome ,TotalChildren ,NumberChildrenAtHome ,EnglishEducation ,SpanishEducation ,FrenchEducation ,EnglishOccupation ,SpanishOccupation ,FrenchOccupation ,HouseOwnerFlag ,NumberCarsOwned ,AddressLine1 ,AddressLine2 ,Phone ,DateFirstPurchase ,CommuteDistance from DimCustomer where 1=0";
                        db.SQLQuery = configValue;
                        filter      = new PFFilter();
                    }
                }
                db.CommandType = CommandType.Text;

                dt = db.GetQueryDataSchema();

                filter.QueryText = db.SQLQuery;

                frm.QueryText      = db.SQLQuery;
                frm.QueryDataTable = dt;
                frm.Filter         = filter;

                frm.MessageLogUI = _messageLog;
                res = frm.ShowDialog();

                filter = frm.Filter;
                dv     = frm.QueryDataView;

                _msg.Length = 0;
                _msg.Append("Form closed with DialogResult = ");
                _msg.Append(res.ToString());
                WriteToMessageLog(_msg.ToString());

                if (res == DialogResult.Abort)
                {
                    _msg.Length = 0;
                    _msg.Append("Form open failed due to error.");
                    WriteToMessageLog(_msg.ToString());
                }

                if (res == DialogResult.OK)
                {
                    _msg.Length = 0;
                    _msg.Append(Environment.NewLine);
                    _msg.Append("FILTER OBJECT:\r\n\r\n");
                    _msg.Append(filter.ToXmlString());
                    _msg.Append(Environment.NewLine);
                    _msg.Append(Environment.NewLine);
                    WriteToMessageLog(_msg.ToString());
                    if (String.IsNullOrEmpty(filterFile) == false)
                    {
                        filter.SaveToXmlFile(filterFile);
                    }
                }
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                WriteToMessageLog(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                if (db.IsConnected)
                {
                    db.CloseConnection();
                }
                db = null;

                if (frm != null)
                {
                    if (FormIsOpen(frm.Name))
                    {
                        frm.Close();
                    }
                }
                frm = null;

                _msg.Length = 0;
                _msg.Append("\r\n... ShowFilterForm finished.");
                WriteToMessageLog(_msg.ToString());
            }
        }