Filling BO


Author
Message
Edhy Rijo
E
StrataFrame VIP (3.8K reputation)StrataFrame VIP (3.8K reputation)StrataFrame VIP (3.8K reputation)StrataFrame VIP (3.8K reputation)StrataFrame VIP (3.8K reputation)StrataFrame VIP (3.8K reputation)StrataFrame VIP (3.8K reputation)StrataFrame VIP (3.8K reputation)StrataFrame VIP (3.8K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Jimmy,

Glad you found it useful.  Fell free to keep searching the forums, there are a lot of good samples here for every level and if you can't find it, well, post it again here Smile

Edhy Rijo

Jimmy D Cook
Jimmy D Cook
StrataFrame Beginner (3 reputation)StrataFrame Beginner (3 reputation)StrataFrame Beginner (3 reputation)StrataFrame Beginner (3 reputation)StrataFrame Beginner (3 reputation)StrataFrame Beginner (3 reputation)StrataFrame Beginner (3 reputation)StrataFrame Beginner (3 reputation)StrataFrame Beginner (3 reputation)
Group: Forum Members
Posts: 1, Visits: 3
I was in search for this coding since long time back but you have cleared my doubts. You are too good.

Tampa Florida 3PL
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (2.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Glad you are getting it going. While programming can be frustrating, I love those "fog is clearing" moments. BigGrin
Edhy Rijo
E
StrataFrame VIP (3.8K reputation)StrataFrame VIP (3.8K reputation)StrataFrame VIP (3.8K reputation)StrataFrame VIP (3.8K reputation)StrataFrame VIP (3.8K reputation)StrataFrame VIP (3.8K reputation)StrataFrame VIP (3.8K reputation)StrataFrame VIP (3.8K reputation)StrataFrame VIP (3.8K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Ian Johnston (08/30/2010)
OK the fog is clearing.


Pretty good Ian, congratulations!!!

Edhy Rijo

Ian Johnston
Ian Johnston
StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)
Group: StrataFrame Users
Posts: 77, Visits: 470
OK the fog is clearing. I had the tab control that textbox is on disabled in the FormEditingStaeChanged event - Don't know why but at some point it must have been a good idea! Code is now working great if there is only one value to assign it is assigned, if there are more than one value the BrowseDialog appears popualted with valid choices and choice selected is entered in the textbox or if there is no selection textbox is blank and allows entry as this may be a one time transaction using this license number.
Ian Johnston
Ian Johnston
StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)
Group: StrataFrame Users
Posts: 77, Visits: 470
So in the light of day I modified the code to be

private string getTrk_lic()

{

//-- Only show one panel, and put the browse results in the visible panel

this.browseDialogtruck.AdvancedOptions = false;

this.browseDialogtruck.AllowHideResults = false;

this.browseDialogtruck.AllowSearchFieldsButton = false;

this.browseDialogtruck.SearchFields["FK_customer"].InitialValue = certificateBO1.FK_Customer2.ToString();

// '-- Show the browse dialog  From the lookup control sample by Ivan

// If CustomersBrowseDialog1.ShowDialog() = DialogResult.OK Then

// Me.txtCode.Text = CustomersBO1.cust_pk.ToString

// End If

if (this.browseDialogtruck.ShowDialog(true).Equals(DialogResult.OK))

{

return truckBO2.truck_license;

}

else

{

return "";

}

}

this now works and returns the value but the form still wants to start over, how do I get the focus back to the forms main BO (certificateBO1) and back to the textbox that calls this browsedialog?


Ian Johnston
Ian Johnston
StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)
Group: StrataFrame Users
Posts: 77, Visits: 470
OK so I have written the following code to look up the truck license it works fine if there is only one number

public bool GetTrucklic(long carrier, out string truckLic)

{

//-- Establish a return var

bool dataFound = false;

//-- Set default return value if there is no value in db.

truckLic = string.Empty;

//-- Build SQL string

StringBuilder sqlBuilder = new StringBuilder();

sqlBuilder.AppendLine("Select count(*)");

sqlBuilder.AppendLine("From truck");

sqlBuilder.AppendLine("Where FK_customer = @carr");

//-- Get data

using (SqlCommand cmd = new SqlCommand())

{

cmd.CommandText = sqlBuilder.ToString();

cmd.Parameters.AddWithValue("@carr", carrier).SqlDbType = SqlDbType.VarChar;

//-- Get Data, handle Null from database and nulls.

// This can return a DbNull.Value (i.e. a NULL from SQL) or it

// can return null (.NET) if there is no matching record in database

// (i.e. an empty recordset is returned). Thus before we can set the

// return variable, we have to test for these cases. It is also important

// to set a default value (as done above), in case no data is found

// in the database.

object result = this.ExecuteScalar(cmd);

if (!DBNull.Value.Equals(result) && result != null)

{

//-- By using an output variable (truckPdt) and a return variable

// (dataFound), I can somewhat simplify the

// client code because I can directly test

// the return value and get the value at the

// same time. It is equally valid to directly

// return the value (truckPdt) and then

// testing if it is a null or empty.

//truckPdt = result.ToString();

if (result.Equals(1))

{

dataFound = true;

}

else

{

dataFound = false;

}

}

}

if (dataFound)

{

//-- Build SQL string

StringBuilder sqlBuilder2 = new StringBuilder();

sqlBuilder2.AppendLine("Select truck_license");

sqlBuilder2.AppendLine("From truck");

sqlBuilder2.AppendLine("Where FK_customer = @carr");

//-- Get data

using (SqlCommand cmd2 = new SqlCommand())

{

cmd2.CommandText = sqlBuilder2.ToString();

cmd2.Parameters.AddWithValue("@carr", carrier).SqlDbType = SqlDbType.VarChar;

//-- Get Data, handle Null from database and nulls.

// This can return a DbNull.Value (i.e. a NULL from SQL) or it

// can return null (.NET) if there is no matching record in database

// (i.e. an empty recordset is returned). Thus before we can set the

// return variable, we have to test for these cases. It is also important

// to set a default value (as done above), in case no data is found

// in the database.

object result2 = this.ExecuteScalar(cmd2);

if (!DBNull.Value.Equals(result2) && result2 != null)

{

//-- By using an output variable (truckPdt) and a return variable

// (dataFound), I can somewhat simplify the

// client code because I can directly test

// the return value and get the value at the

// same time. It is equally valid to directly

// return the value (truckPdt) and then

// testing if it is a null or empty.

truckLic = result2.ToString();

dataFound = true;

}

}

}

//-- Return if data was found.

return dataFound;

}

I am calling this from the enter event of the license textbox. The problem is if a company has more than one truck and therefore more than one license number. I am trying to call a browse dialog by repopulating a BO based on the carriers PK.

private void Trk_lic_Enter(object sender, EventArgs e)

{

string trkLic = string.Empty;

string trkLic2 = string.Empty;

if (this.truckBO1.GetTrucklic(certificateBO1.FK_Customer2, out trkLic))

{

this.Trk_lic.Text = trkLic; // this works and returns either one license number or blank if none exists.

}

else

{

trkLic2 = this.getTrk_lic();

this.Trk_lic.Text = trkLic2;

}

This sets up the browseDIalog and it shows all the license numbers for a carrier

private string getTrk_lic()

{

bool trk_lic = false;

string ret_val = string.Empty;

//-- Only show one panel, and put the browse results in the visible panel

this.browseDialogtruck.AdvancedOptions = false;

this.browseDialogtruck.AllowHideResults = false;

this.browseDialogtruck.AllowSearchFieldsButton = false;

this.browseDialogtruck.SearchFields["FK_customer"].InitialValue = certificateBO1.FK_Customer2.ToString();

this.browseDialogtruck.BusinessObjectToPopulate.Equals(truckBO2);

//this.browseDialogtruck.OverrideSearchTableName.Equals(Tru);

this.browseDialogtruck.ShowDialog(true);

if (trk_lic)

{

return truckBO2.truck_license;

}

else

{

return "";

}

}

The problem is that I am back to the maintainence form it starts over again. My question is is there a way to use executeReader to return all the values and put them into the BrowseDialog?


Greg McGuffey
Greg McGuffey
Strategic Support Team Member (2.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Glad to help Ian.
Ian Johnston
Ian Johnston
StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)StrataFrame User (125 reputation)
Group: StrataFrame Users
Posts: 77, Visits: 470
Thanks to both of you for your help.
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (2.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Edhy is batting a 1000. BigGrin



You don't want to refill the BO to get the value, just create a new method in the BO to do this simple task. This will leave the bound data in the UI alone. You would do something like this:



//-- This goes in the TruckBO...

public bool GetTruckPdt(string license, out string truckPdt)

{

  //-- Establish a return var

  bool dataFound = false;



  //-- Set default return value if there is no value in db.

  truckPdt = string.Empty;



  //-- Build SQL string

  StringBuilder sqlBuilder = new StringBuilder();

  sqlBuilder.AppendLine("Select truck_pdt");

  sqlBuilder.AppendLine("From truck");

  sqlBuilder.AppendLine("Where truck_license = @lic");



  //-- Get data

  using (SqlCommand cmd = new SqlCommand())

  {

    cmd.CommandText = sqlBuilder.ToString();

    cmd.Parameters.AddWithValue("@lic", license).SqlDbType = SqlDbType.VarChar;



    //-- Get Data, handle Null from database and nulls.

    //   This can return a DbNull.Value (i.e. a NULL from SQL) or it

    //   can return null (.NET) if there is no matching record in database

    //   (i.e. an empty recordset is returned). Thus before we can set the

    //   return variable, we have to test for these cases. It is also important

    //   to set a default value (as done above), in case no data is found

    //   in the database.

    object result = this.ExecuteScalar(cmd);

    if (result != DbNull.Value && result != null)

    {

      //-- By using an output variable (truckPdt) and a return variable

      //   (dataFound), I can somewhat simplify the

      //   client code because I can directly test

      //   the return value and get the value at the

      //   same time. It is equally valid to directly

      //   return the value (truckPdt) and then

      //   testing if it is a null or empty.

      truckPdt = (string)result;

      dataFound = true;

    }

  }



  //-- Return if data was found.

  return dataFound;

}




Once you have this in you TruckBO, you can use it like:



private void Trk_lic_Leave(object sender, EventArgs e)

{

  //-- Get the data for this license.

  string truckPdt = string.Empty;

  if (this.truckBO1.GetTruckPdt(Trk_lic.Text, out truckPdt))

  {

    this.trkpdt.Text = truckPdt;

  }

}




I hope this helps. Edhy is quite right that spending a bit time with the help file/examples also can help you understand the framework better.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search