In grdLines_Change the sample is incorrectly using
new to instantiate a Jiwa object:
- Code: Select all
private void grdLines_Change(object sender, FarPoint.Win.Spread.ChangeEventArgs e)
{
string Key = null;
string ColID = grdLines.ActiveSheet.Columns[e.Column].Tag.ToString();
if (ColID == "SegContents") {
if (e.Row == grdLines.ActiveSheet.RowCount - 1) {
GLSegment GLSegment = new GLSegment();
GLSegment.SegContents = grdLines.get_GridText("SegContents", e.Row).ToString();
BusinessLogic.Add(GLSegment);
} else {
Key = grdLines.get_GridText("GLSegmentID", e.Row).ToString();
BusinessLogic[Key].SegContents = grdLines.get_GridText("SegContents", e.Row).ToString();
}
} else if (ColID == "SegContentsDesc") {
if (e.Row == grdLines.ActiveSheet.RowCount - 1) {
GLSegment GLSegment = new GLSegment();
GLSegment.SegContentsDesc = grdLines.get_GridText("SegContentsDesc", e.Row).ToString();
BusinessLogic.Add(GLSegment);
} else {
Key = grdLines.get_GridText("GLSegmentID", e.Row).ToString();
BusinessLogic[Key].SegContentsDesc = grdLines.get_GridText("SegContentsDesc", e.Row).ToString();
}
}
}
NO! You must always use a factory for Jiwa or Jiwa-derived objects. A factory is essentially a way of "new"-ing an object which does additional fancy stuff when setting up that object for you. In our case we give your object a JiwaApplication.Manager instance. Very important. Read here:
https://docs.jiwa.com.au/display/J7UG/How+to+convert+plugins+or+code+to+be+compatible+with+7.00.177.00+or+laterHere is the corrected function:
- Code: Select all
private void grdLines_Change(object sender, FarPoint.Win.Spread.ChangeEventArgs e)
{
string Key = null;
string ColID = grdLines.ActiveSheet.Columns[e.Column].Tag.ToString();
if (ColID == "SegContents") {
if (e.Row == grdLines.ActiveSheet.RowCount - 1) {
GLSegment GLSegment = Manager.CollectionItemFactory.CreateCollectionItem<GLSegment>();
GLSegment.SegContents = grdLines.get_GridText("SegContents", e.Row).ToString();
BusinessLogic.Add(GLSegment);
} else {
Key = grdLines.get_GridText("GLSegmentID", e.Row).ToString();
BusinessLogic[Key].SegContents = grdLines.get_GridText("SegContents", e.Row).ToString();
}
} else if (ColID == "SegContentsDesc") {
if (e.Row == grdLines.ActiveSheet.RowCount - 1) {
GLSegment GLSegment = Manager.CollectionItemFactory.CreateCollectionItem<GLSegment>();
GLSegment.SegContentsDesc = grdLines.get_GridText("SegContentsDesc", e.Row).ToString();
BusinessLogic.Add(GLSegment);
} else {
Key = grdLines.get_GridText("GLSegmentID", e.Row).ToString();
BusinessLogic[Key].SegContentsDesc = grdLines.get_GridText("SegContentsDesc", e.Row).ToString();
}
}
}
An additional problem is that it appears that a ListMaintenance form *must* have a RecID column, or the base class blows up. So I changed your grid setup to use the column name "RecID" instead of "GLSegmentID", and then changed that string throughout the plugin.
Then I hit a problem with the Save() function. In c# if a string is not initialized it is null, if you do not enter a value in one of the fields, the save gets upset. So I've initiated the privates to be the empty string.
Then I hit another problem with the save function. You were generating a RecID, which is not required. We do that upon add to the collection. Further, the "GLSegmentID" column in the GL_Segments table (into which we are pushing RecID) is a CHAR(20) field, not a uniqueidentifier as per the sample, so I had to change that parameter type in iSave, as well as set RecIDIsGUID to false in the constructor of the GLSegmentCollection class.
- Code: Select all
public GLSegmentCollection() : base()
{
base.ClientClassName = "GLSegmentCollection";
base.RecIDIsGUID = false;
}
Now when you save, you are left with an error because you cannot insert a null into GL_Segment.SegmentNo. Your plugin does not provide support for defining a segment number yet. So I'll leave that bit for you.
Here is the plugin with my changes:
Great effort though and good to see you coding in c#!