GST Billing Software

header image

How to do custom Save, Update, Remove & Delete

Erachana Line

50. How to do custom Save, Update, Remove & Delete?

If you want to do this, you need to change the default button available to normal button by methods explained in question

How to make default button behave like normal button? Or remove default button functionality.

1. Save

Add an expression, in that expression, write your own code for the custom operation and to save the data, call the 'Save' function.

Note -

This will work on 'Table-Detail Entry', 'Table-grid Entry', 'Single-Entry' Forms.

In 'Parent-Child Detail Entry' only Parent Control Data will get saved.

However, in 'Parent-Child Grid Entry', Save will work for Parent as well as child Table.

try

{

if (Date_chk() == true)

{

bool myNewRecord = newRecord;

bool result = true;

result = result && ValidateParentInput();

result = result && Save();

int index = dgr1.SelectedRows[0].Index;

dgr1.ClearSelection();

dgr1.Rows[index].Selected = true;

if (result)

{

AutoClosingMessageBox.Show("Data saved successfully", "Save", MessageBoxButtons.OK, MessageBoxIcon.Information, 2000);

}

}

}

catch (Exception exc)

{

MessageBox.Show("Unexpected error occured!" + Environment.NewLine + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

}


2. Delete

Add an expression, in that expression, write your own code for the custom operation and to delete the selected record, call the ' Delete' function.

Note -

In 'Parent-Child Detail Entry' and in 'Parent-Child Grid Entry', the code is such that child records will be deleted first, followed by Parent Record.

In Single Entry Form, There is no Delete Functionality.


try

{

bool result = Delete();

}

catch (Exception exc)

{

MessageBox.Show("Unexpected error occured!" + Environment.NewLine + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

}

3. Update

Add an expression, in that expression, write your own code for the custom operation and to update the selected record, call the ' Update' function.

Note -

This will work only for 'Parent-Child Detail Entry' and in 'Parent-Child Grid Entry'. This function will first save or update the Parent record and then save or update the child record.


try

{

if (Pre_Save_Validation())

{

bool result = false;

result = result && ValidateParentInput();

result = result && ValidateChildInput();

result = UpdateChildGrid();

CalcAmount();

Save();

}

}

catch (Exception exc)

{

MessageBox.Show("Unexpected error occured!" + Environment.NewLine + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

}


4. Remove

Add an expression, in that expression, write your own code for the custom operation and to delete the selected record, call the ' Remove function.

Note -

This will work only for 'Parent-Child Detail Entry' and in 'Parent-Child Grid Entry'. This function will delete only selected child record.


try

{

bool result = Remove();

}

catch (Exception exc)

{

MessageBox.Show("Unexpected error occured!" + Environment.NewLine + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

}