Business Logic Object and Business Logic Maintenance Form  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Business Logic Object and Business Logic Maintenance Form

Postby SBarnes » Fri Dec 08, 2017 9:23 am

I am getting an error from a Business Login Object and Business Logic Maintenance form when I try to open the form where Jiwa tries to execute the following SQL where the order by is not getting completed

Code: Select all
SELECT TOP 1 HR_SalesmanGroups.SalesmanGroupID FROM HR_SalesmanGroups  order BY


The code for the business object is below but I can't work out what might be missing, if I don't assign to the forms business logic variable the form loads with out a problem

Code: Select all
class SMGroup : JiwaFinancials.Jiwa.JiwaApplication.BusinessLogic.Maintenance
    {
      

      SMGroupMembers _Members;

      string _GroupName;

      public string GroupName
        {
            get { return _GroupName; }
            set
            {
                _GroupName = value;
                NotifyPropertyChanged("GroupName");
            }
        }      
      
      
      
      public SMGroupMembers Members
        {
            get { return _Members; }
            set
            {
                _Members = value;
                NotifyPropertyChanged("Members");
            }
        }      
      
   
      
      
      public SMGroup()
        {
         System.Diagnostics.Debugger.Launch();
            base.ClientClassName = "JiwaFinancials.Jiwa.JiwaApplication.BusinessLogic.Maintenance";
          _GroupName = "";
         //SortOrder.FieldName = "Description";


         
        }
      
      

      
      private void ClearVariables()
      {
         //this.RecID = this.Manager.Database.MakeID("");

         RecID = Strings.Left(Guid.NewGuid().ToString().Replace("-", ""), 20);
            _GroupName = "";
         
         _Members.Clear();
      }
      
      
        public override string DocumentNo
        {
           
            get { return this._GroupName.ToString(); }
        }   
      
      public override string RecIDFieldName
        {
           
         get { return "HR_SalesmanGroups.SalesmanGroupID"; }
        }

      
      public override string TableName
        {
           
         get { return "HR_SalesmanGroups"; }
         
        }

      
        public override string SortFieldValue
        {
            get
            {
                switch (SortOrder.Description)
                {
                    case "Group Name.":
                        return this._GroupName.ToString();
            
                  
                    default:
                        return null;
                }
            }
        }      
      
      public override void Delete()
        {
         this.DeleteFlag = true;
         this.Save();
      }
        public override void CreateNew()
        {
         ClearVariables();
         this.InsertFlag = true;
      }
      
      
      
        public override void Setup()
        {
         base.Setup();
         
         SortOrders.Add(new JiwaFinancials.Jiwa.JiwaApplication.IJiwaNavigable.SortKey {
              Description = "Group Name.",
              FieldName = "HR_SalesmanGroups.Description"
              });   
         
   


      
        _Members = this.Manager.CollectionFactory.CreateCollection<SMGroupMembers, SMGroupMember>();
        _Members.Manager  = Manager;
        _Members.SMGroup = this;
          ClearVariables();

        }      
      
        public override void Clear()
        {
         //base.Clear();
         ClearVariables();

        }   
      
   
      
      
      
      public void Search(System.Windows.Forms.Form OwnerForm)
        {

         var search = this.Manager.Search;
         

            search.Clear();
            search.Caption = "Salesman Groups";

            var searchOption = new JiwaFinancials.Jiwa.JiwaApplication.JiwaSearch.SearchOption();
            searchOption.Title = "Salesman Groups";
            searchOption.SQLStr = @" SELECT  [SalesmanGroupID]
                              ,[Description]
                             FROM [dbo].[HR_SalesmanGroups] ";
            searchOption.OrderBy = @"order by [Description] ";
            searchOption.AddColumn("SalesmanGroupID", Microsoft.VisualBasic.VariantType.String, "", 0, 1);
         searchOption.AddColumn("Group Name", Microsoft.VisualBasic.VariantType.String, "", 50, 2);

            search.AddSearchOption(ref searchOption);

            if (search.Show(OwnerForm) == DialogResult.OK)
            {
                if (search.Results.Count > 0)
                {
                    var idField = (JiwaFinancials.Jiwa.JiwaApplication.JiwaSearch.Field)search.get_Fields(1);
                    Read(idField.FieldValue.ToString());
                }
            }
            else
            {
                throw new JiwaFinancials.Jiwa.JiwaApplication.Exceptions.ClientCancelledException();
            }
        }
      
      
      
      
      
      
      
      
      
       public override void Read(string RecID)
        {
         //System.Diagnostics.Debugger.Launch();
            string SQL = "";
            SqlDataReader SQLReader = null;
            SqlParameter SQLParam = null;
            bool oldReading = IsReading;

            try
            {
                IsReading = true;

            var db = this.Manager.Database;

                OnReadStart();

                Clear();

                SQL = @" SELECT  [SalesmanGroupID],[Description]
                        FROM [dbo].[HR_SalesmanGroups] WHERE SalesmanGroupID = @RecID ";

                using (SqlCommand SQLCmd = new SqlCommand(SQL, db.SQLConnection, db.SQLTransaction))
                {
                    SQLCmd.CommandTimeout = this.Manager.Database.DefaultCommandTimeout;

                    SQLParam = new SqlParameter("@RecID", System.Data.SqlDbType.Char);
                    SQLParam.Value = RecID;
                    SQLCmd.Parameters.Add(SQLParam);

                    SQLReader = SQLCmd.ExecuteReader();

                    if (SQLReader.Read())
                    {
                        this.RecID = db.Sanitise(SQLReader, "SalesmanGroupID").ToString();
                  this.GroupName  = db.Sanitise(SQLReader, "Description").ToString();

                    }
                    else
                    {
                        throw new JiwaFinancials.Jiwa.JiwaApplication.Exceptions.RecordNotFoundException("Salesman group Not Found");
                    }
                    SQLReader.Close();
                    Members.ReadRecords(this.RecID);
                }


                if ((SQLReader != null))
                {
                    SQLReader.Close();
                }


                OnReadEnd();

            }
            finally
            {
                if ((SQLReader != null))
                {
                    SQLReader.Close();
                }
                IsReading = oldReading;
            }


        }
      

      
      
      
      
      
      
      
      protected override void iSave()
        {
         
         

            string strSQl = "";
            SqlParameter parameter = new SqlParameter();
            database database = this.Manager.Database;
            database.BeginNewTransaction();
            if (this.DeleteFlag)
            {
                strSQl = @"delete from  HR_SalesmanGroups where SalesmanGroupID = @RecID";
                using (SqlCommand command = new SqlCommand(strSQl, database.SQLConnection, database.SQLTransaction))
                {
                    parameter = new SqlParameter("@RecID", SqlDbType.Char)
                    {
                        Value = this.RecID
                    };
                    command.Parameters.Add(parameter);
            
               Members.Delete();
               Members.Save();
                    if (database.ExecuteNonQuery(command) == 0)
                    {
                        database.RollBack();
                        string[] ErrorMessage = new string[] { "unable to delete HR_SalesmanGroups - RecID ", this.RecID };
                        throw new ConcurrencyConflictException(string.Concat(ErrorMessage));
                    }
                    else
                    {
                        database.Commit();
                    }
                }

            }
            else
            {


                if (this.InsertFlag)
                {

                    strSQl =
                         @" INSERT INTO HR_SalesmanGroups ([SalesmanGroupID],[Description])
                           values (@RecID, @GroupName )";
               

                }
                else if (this.ChangeFlag)
                {
                    strSQl =
                        @" update HR_SalesmanGroups set
                       Description = @GroupName  where  SalesmanGroupID = @RecID";
                }
                using (SqlCommand command = new SqlCommand(strSQl, database.SQLConnection, database.SQLTransaction))
                {
                    parameter = new SqlParameter("@RecID", SqlDbType.Char)
                    {
                        Value = this.RecID
                    };
                    command.Parameters.Add(parameter);

                    parameter = new SqlParameter("@GroupName", SqlDbType.Char )
                    {
                        Value = this.GroupName
                    };
                    command.Parameters.Add(parameter);
                   
 
                    if (database.ExecuteNonQuery(command) == 0)
                    {
                        database.RollBack();
                        string[] ErrorMessage = new string[] { "unable to ", this.InsertFlag ? "insert into" : "update", " HR_SalesmanGroups ", this.RecID.ToString() };
                        throw new ConcurrencyConflictException(string.Concat(ErrorMessage));
                    }
                    else
                    {
                        try
                        {
                            Members.Save();
                            database.Commit();
                     DeleteFlag = false;
                     InsertFlag = false;
                     ChangeFlag = false;
                     
                        }
                        catch (Exception)
                        {
                           
                           database.RollBack();
                           string[] ErrorMessage = new string[] { "unable to save Members for salesman group ", this.RecID.ToString() };
                           throw new ConcurrencyConflictException(string.Concat(ErrorMessage));
                        }
                    }
                }
            }         
         
         
         
         
      }
      
        public override void Deserialise(string XMLString)
        {
            throw new NotImplementedException();
        }


        public override void Copy()
        {
            throw new NotImplementedException();
        }
      
        public override void Serialise(ref string XML)
        {
          throw new NotImplementedException();
        }

        public override Type SerialiseType()
        {
            return typeof(SMGroup);
        }      
      
      
   }   


The following is the code in the setup for the form that links the business object to the form

Code: Select all
_SMGroup = this.Manager.BusinessLogicFactory.CreateBusinessLogic<SMGroup>(this);
         this.BusinessLogic = _SMGroup;
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Business Logic Object and Business Logic Maintenance For

Postby Mike.Sheen » Fri Dec 08, 2017 9:31 am

Hi Stuart,

Either in your setup method or even your constructor you need to add to the SortOrders collection - e.g.:

Code: Select all
SortOrders.Add(New JiwaApplication.IJiwaNavigable.SortKey With {.Description = "Invoice No.", .FieldName = "SO_Main.InvoiceNo"})
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Business Logic Object and Business Logic Maintenance For

Postby SBarnes » Fri Dec 08, 2017 9:55 am

Hi Mike,


Thanks for the quick reply.


This is already the case for the Business Logic Class SMGroup, the setup function is below.

Code: Select all
public override void Setup()
        {
         base.Setup();
         
         SortOrders.Add(new JiwaFinancials.Jiwa.JiwaApplication.IJiwaNavigable.SortKey {
              Description = "Group Name.",
              FieldName = "HR_SalesmanGroups.Description"
              });   
         
   


      
        _Members = this.Manager.CollectionFactory.CreateCollection<SMGroupMembers, SMGroupMember>();
        _Members.Manager  = Manager;
        _Members.SMGroup = this;
          ClearVariables();

        }      


A call to SortFieldValue as shown below is handing in null for SortOrder.Description

Code: Select all
 public override string SortFieldValue
        {
            get
            {
                switch (SortOrder.Description)
                {
                    case "Group Name.":
                        return this._GroupName.ToString();
            
                  
                    default:
                        return null;
                }
            }
        }      
      
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Business Logic Object and Business Logic Maintenance For

Postby Mike.Sheen » Fri Dec 08, 2017 10:12 am

SBarnes wrote:This is already the case for the Business Logic Class SMGroup, the setup function is below.


Ok - I missed seeing that somehow.

The sort field isn't being send through to the Business logic Find method - this is handled by the base Maintenance Form - when a form is loaded the ribbon tool drop-down "ID_RecordSortOrder" is populated with the SortOrders from the business logic and when the business logic find is invoked, it looks at the selected item in the "ID_RecordSortOrder" tool to obtain the sort field - in your case it's blank for some reason.

There are defensive measures in there, so if the selected item of the "ID_RecordSortOrder" tool is null, it would behave the same as blank - so I think the problem is not the business logic, but the form. Are you overriding the Setup method of the form - and if so, are you calling the base.Setup() as the first thing you do in that method?
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Business Logic Object and Business Logic Maintenance For  Topic is solved

Postby SBarnes » Fri Dec 08, 2017 10:15 am

HI Mike,

I found the problem the actual Setup on the form was missing some code, what looked like an error on the business logic object was actually being called by the maintenance for itself.

Code: Select all
         base.Setup();
         SetupWindow();



Thanks for the help.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Business Logic Object and Business Logic Maintenance For

Postby SBarnes » Fri Dec 08, 2017 10:17 am

Look like we both found the issue at the same time :lol:
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 36 guests