Riyaz wrote:Hello Jiwa Admins
Can anyone pls kindly get back on this, I would really appreciate it. Thanks
The problem you have is because you are looking at grid cell contents, and also setting those instead of the business logic properties. Pretty much everywhere in Jiwa the rule is to talk to the business logic properties when examining and setting values. Don't talk to the grid unless you want to simply alter the appearance. If you want to alter values, talk to the business logic.
If you set cell contents on a grid via code the business logic doesn't receive the new value and this saving it will cause it to go back to the prior value.
To give you a some guidance, I've looked at your plugin and can see in your SaveStart where you begin to iterate through the grid cell contents for each row and make decisions / calculations based on that -
Don't do that - instead use the business logic attached to the form. In your plugin you already added a handler to the SaveStart of the business logic within the Form, so the sender argument is the business logic:
- Code: Select all
private void SaveStart(object sender, System.EventArgs e)
{
var creditorChequePaymentBusinessLogic = (JiwaFinancials.Jiwa.JiwaCreditorChqPay.CreditorChequePayment)sender;
foreach (JiwaFinancials.Jiwa.JiwaCreditorChqPay.Creditor creditor in creditorChequePaymentBusinessLogic.Creditors)
{
// read payment terms here for the creditor. No sense doing it on the following inner loop as they're the same creditor.
foreach (JiwaFinancials.Jiwa.JiwaCreditorChqPay.clsPayLineInvoice invoice in creditor.InvoicePaymentLines)
{
// apply discount here: *** NOTE *** You might want to opt to only do this if creditorChequePamentBusinessLogic.InsertFlag == true,
// as that is when it is first saved after being created
//BUT wrap that condition around ALL the code in this handler not just this inner loop, otherwise you'd be hitting the database on every save, not just the initial save.
invoice.DiscountAmount = ? ;
}
}
}
This should set you on your way.
Mike
PS: I
insist you use parameters for your SQL queries - your building of a string is
BAD.
YOU MUST FIX THIS. A malicious user could create a creditor with account no. of '111; DELETE FROM CR_Main' and your query would happily delete all creditors from the database - this is a basic
SQL Injection attack, and all your queries direct to the database should prevent against that - using parameters with your SQL command will guard against this.
You should also wrap all queries in a using statement to make sure everything is disposed of correctly.
Also, don't use GetNewConnection like you are. Use the current SQL connection or you're going to have serious integrity issues!
So instead of:
- Code: Select all
SqlCommand cmd=new SqlCommand("select EarlyPayDisOnRemitDays,EarlyPayDisOnRemitAmt from CR_Main where AccountNo ='"+ AccountNo +"'",JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.Database.GetNewConnection(JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.Database.ConnectionString));
SqlDataReader reader= JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.Database.ExecuteReader(cmd);
use:
- Code: Select all
int EarlyPayDisOnRemitDays = 0;
decimal EarlyPayDisOnRemitAmt = 0;
var db = JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.Database;
System.Data.SqlClient.SqlParameter SQLParam = null;
System.Data.SqlClient.SqlDataReader SQLReader = null;
try
{
string SQL = @"SELECT EarlyPayDisOnRemitDays, EarlyPayDisOnRemitAmt
FROM CR_Main WHERE
AccountNo = @AccountNo";
using (SqlCommand SQLCmd = new SqlCommand(SQL, db.SQLConnection, db.SQLTransaction))
{
SQLParam = new SqlParameter("@AccountNo", System.Data.SqlDbType.VarChar);
SQLParam.Value = AccountNo;
SQLCmd.Parameters.Add(SQLParam);
SQLReader = db.ExecuteReader(SQLCmd);
if (SQLReader.Read() == true)
{
EarlyPayDisOnRemitDays = int.Parse(db.Sanitise(SQLReader, "EarlyPayDisOnRemitDays").ToString());
EarlyPayDisOnRemitAmt = decimal.Parse(db.Sanitise(SQLReader, "EarlyPayDisOnRemitAmt").ToString());
}
}
SQLReader.Close();
}
finally
{
if (SQLReader != null)
{
SQLReader.Close();
}
}
That way you will use the current connection and transaction. Not doing it as per above will cause very hard to troubleshoot issues (weird errors sometimes, but not always).