Cancel update on form close

I am creating a UD form. The forms is trying to perform a save on form close and new (if I have a record loaded into the for and i try to close the form or get a new record, it says that there is a duplicate record) how can I stop the update, I have a separate button the performs the update.

Do you only want the form to save when the user presses the button?

Can you paste your code? It sounds it is trying to add a new record each time, rather than update existing matching records.

  • Joe

I think this is the relevant piece of code here
//CB - check to see if there is already a drawing for the order
var rQuery = (from r in rdt.AsEnumerable() where r.Field(“UD01_Character01”).ToString() == epiTextBoxJobNumber.Text select r).ToList();
if (rQuery.Count > 0)
{
drawigsDataView.CurrentDataRow[“Key1”] = rQuery[0][“UD01_Key1”];
drawigsDataView.CurrentDataRow.CancelEdit();
HasDrawing = true;
epiButtonGetNextNumber.Enabled = false;
}
if i find an order that has a drawing number, i put the drawing number into the bound textbox, then when i go to close the form it asks me if i want to save, i do not and never will because that would be a duplicate entry and we can’t have those any way.

Hi
So if the drawing already exists, you want it to do nothing? (not save)
You could try the below, only in the else statement remove the messagebox if you don’t want anythingto show…,
/////////////////////////////////////////////////////////////////////////////
var rQuery = (from r in rdt.AsEnumerable() where r.Field(“UD01_Character01”).ToString() == epiTextBoxJobNumber.Text select r).ToList();
if (rQuery.Count < 0)
{
drawigsDataView.CurrentDataRow[“Key1”] = rQuery[0][“UD01_Key1”];
var OrderDrawNum = rQuery[0][“UD01_Key1”];
drawigsDataView.CurrentDataRow.CancelEdit();
HasDrawing = true;
epiButtonGetNextNumber.Enabled = false;
}
else
{
this.PublishInfoMessage(“Draw Num” + OrderDrawNum + “Already Exists”, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, “”, “”);
}
//////////////////////////////////////////////////////////////////////////////

Thanks,
Joe

I already tried this, i also tried a rejectchanges(), but with this, if i enter a new order number and tab out my validate order routine gives me a null reference exception. Her is the full validate method .

private void ValidateOrderNum()
{
    try
    {
        DataTable dt = new DataTable();
        // CB = Create a Query excution data set, excecute the BAQ, and store the results in a data table
        QueryExecutionDataSet ds = new QueryExecutionDataSet();
        adapter.ExecuteByID("OrderInfo", ds);
        dt = adapter.QueryResults.Tables["Results"];
        //CB - Query the orders to chick that the user entered a valid order number
        var query = (from o in dt.AsEnumerable() where o.Field<int>("OrderHed_OrderNum").ToString() == this.epiTextBoxJobNumber.Text select o).ToList<DataRow>();
        if (query.Count > 0)
        {
            IsOrder = true;
            //CB - Get the customer name on the order 
            epiTextBoxCustomer.Text = query[0]["Customer_Name"].ToString();
            QueryExecutionDataSet rds = new QueryExecutionDataSet();
            DataTable rdt = new DataTable();
            adapter.ExecuteByID("Drawing_Numbers", rds);
            rdt = adapter.QueryResults.Tables["Results"];
            //CB - check to see if there is already a drawing for the order
            var rQuery = (from r in rdt.AsEnumerable() where r.Field<string>("UD01_Character01").ToString() == epiTextBoxJobNumber.Text select r).ToList<DataRow>();
            if (rQuery.Count > 0)
            {
                //CB - Show the drawing number 
                drawigsDataView.CurrentDataRow["Key1"] = rQuery[0]["UD01_Key1"];
                HasDrawing = true;
                epiButtonGetNextNumber.Enabled = false;
            }

            else
            {
                drawigsDataView.CurrentDataRow["Key1"] = "";
                HasDrawing = false;
                epiButtonGetNextNumber.Enabled = true;
            }
        }
        else
        {
            IsOrder = false;
            HasDrawing = false;
            epiTextBoxCustomer.Text = "";
            drawigsDataView.CurrentDataRow["Key1"] = "";
            epiTextBoxJobNumber.Focus();
            epiButtonGetNextNumber.Enabled = false;
            MessageBox.Show("Please enter a valid order number.");
        }
    }
    catch (Exception e)
    {
        MessageBox.Show(e.Message + "\n" + e.InnerException);
    }
}

What is your “OrderInfo” baq returning?

Where are you calling the ValifateOrderNum Method from? Is it on save?

Thanks
joe

The order info baq returns a list of orders, i call the validate order when the user tabs out the order number field. I think what may be going on is i am setting the dataview field an therefor it thinks I am trying to update the record, but I am not. The drawing number is the primary key of the UD01 table.

HI
The issue could well be here,
Why are you setting Key1 to null?
Can you try commenting it out and re-testing to see what happens

No, I do not think that is where the problem lies. I set it to blank because after I enterer an order that already has a drawing then I enter one that does not, i want it to clear the number. I think the issue that I am trying to solve has to do with the fact that first thing I do when the form opens is I hit the new button, that puts the row in an added state and when i try to close it, there are unsaved changes and it wants to save them.

Can you put an
" oTrans.Refresh(); "
on form close and see if that works, please.

Unfortunately I have tried this many times to no avail.

Solved my problem by manipulating the row state of the current row. Here is my code in case any others out the need are having similar issues.

            //CB - check to see if there is already a drawing for the order
            var rQuery = (from r in rdt.AsEnumerable() where r.Field<string>("UD01_Character01").ToString() == epiTextBoxJobNumber.Text select r).ToList<DataRow>();
            if (rQuery.Count > 0)
            {
                //CB - Order already has a drawing number. Display order and drawing number and accept the changes to tha datarow to change its state to unchanged.
                //CB - Rows with state unchanged do not get pushed to the database
                drawigsDataView.CurrentDataRow["Key1"] = rQuery[0]["UD01_Key1"];
                drawigsDataView.CurrentDataRow["Character01"] = rQuery[0]["UD01_Character01"];
                drawigsDataView.CurrentDataRow.AcceptChanges();
                HasDrawing = true;
                epiButtonGetNextNumber.Enabled = false;
            }
            else
            {
                //CB Order does not already have a drowing number set roow state to added to allow it to be added to the database table
                drawigsDataView.CurrentDataRow.AcceptChanges();
                drawigsDataView.CurrentDataRow.SetAdded();
                drawigsDataView.CurrentDataRow["Key1"] = "";
                HasDrawing = false;
                epiButtonGetNextNumber.Enabled = true;
            }

This is part of my ValidateOrderNum method and I also call Ac ceptChanges just before ValidateOrderNum