Simple editable maintenance form  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Re: Simple editable maintenance form

Postby Scott.Pearce » Wed Apr 06, 2022 7:00 pm

DannyC wrote:I have the plugin successfully writing a record to the GL_Segments table but as soon as I save, I get this error.


Check your collection Read() function. I suspect there is a reference to “RecID” when it should be “GLSegmentID”.
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 742
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 221

Re: Simple editable maintenance form

Postby SBarnes » Wed Apr 06, 2022 7:07 pm

This will do it

Code: Select all
public override void Read()
   {
      string Sql = null;
      SqlDataReader SQLReader = null;
      bool oldReading = Reading;

      try {
         Reading = true;
         Clear();

         var db = Manager.Database;

         Sql = @"SELECT GLSegmentID, SegContents, SegContentsDesc
               FROM GL_Segments WHERE SegmentNo = 1
               ORDER BY SegContents ";

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

            SQLReader = SQLCmd.ExecuteReader();

            while (SQLReader.Read() == true) {
               //GLSegment GLSegment = new GLSegment();
                 GLSegment GLSegment = Manager.CollectionItemFactory.CreateCollectionItem<GLSegment>();

               GLSegment.RecID = db.Sanitise(SQLReader, "GLSegmentID").ToString();
               GLSegment.SegContents = db.Sanitise(SQLReader, "SegContents").ToString();
               GLSegment.SegContentsDesc = db.Sanitise(SQLReader, "SegContentsDesc").ToString();

               Add(GLSegment);
            }

            SQLReader.Close();
         }

         base.OnRead();

      } finally {
         Reading = oldReading;

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

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

Re: Simple editable maintenance form  Topic is solved

Postby DannyC » Wed Apr 06, 2022 7:16 pm

And for those playing along at home, the final plugin.

BTW, it only deals with the first segment. I'm forcing SegmentNo to INSERT as 1.

Appreciate the assistance peeps. :D
Attachments
Plugin Sample Plugin - GL Segment Maintenance.xml
(52.61 KiB) Downloaded 35 times
Last edited by DannyC on Wed Apr 06, 2022 11:19 pm, edited 1 time in total.
User avatar
DannyC
Senpai
Senpai
 
Posts: 636
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 30

Re: Simple editable maintenance form

Postby SBarnes » Wed Apr 06, 2022 7:19 pm

Whilst still playing at home :lol:

change

Code: Select all
GLSegment GLSegment = new GLSegment();


in the read to use the factory as I think if you update a line you'll get an issue
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Previous

Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 14 guests

cron