On Wed, Oct 17, 2012 at 9:47 PM, MB Software Solutions, LLC
<[email protected]> wrote:
> On 10/17/2012 10:27 PM, Stephen Russell wrote:
>>
>> And that UDF() is not a good idea. You should just ask for it
>> straight to the @PK and then use it in the next insert statement.
>
>
>
> Send me the correct code, please...thanks!
------------------------------
This is a three table update using C# / Entity Framework
I pass in a complex object with all the data for a PO that my have
multiple lines as well as any line could have multiple shipment dates.
public static Boolean updatePO(PO myPO, String ConStr)
{
String ponum = myPO.poNumber;
Boolean flag = true;
using (RingEDIEntities db = new RingEDIEntities(efCon(ConStr)))
{
try
{
//get the new ID for the New version of the PO
PurchaseOrders PO = new PurchaseOrders();
PO.dtmAdded = DateTime.Now;
PO.ErrorChecked = myPO.errorChecked;
PO.FileID = myPO.fileID;
PO.POCurrency = myPO.poCurrency;
PO.PODate = myPO.poDate;
PO.PONumber = myPO.poNumber;
PO.POStatus = myPO.poStatus;
PO.POTime = myPO.poTime;
PO.Printed = myPO.printed;
PO.ReferenceID = myPO.referenceID;
PO.RequestMade = (Boolean)myPO.requestMade;
PO.TradingPartnerID = myPO.tradingPartnerID;
db.AddToPurchaseOrders(PO);
db.SaveChanges();
// get that new ID
Int32 HeaderID = (Int32)PO.POID; // gets the ID
for future use below. This is int vs Guid but the way the db works it
is the same.
foreach (POLine line in myPO.POLines)
{
if (line.poLinesID>=0)
{
PurchaseOrderLines pol = new PurchaseOrderLines();
pol.POID = HeaderID;
pol.BaseUnitCode = line.baseUnitCode;
pol.CustomerItemNumber = line.customerItemNumber;
pol.Description = line.description;
pol.LineNumber = line.lineNumber;
pol.Price = line.price;
pol.Quantity = line.quantity;
pol.RingItemNumber = line.ringItemNumber;
pol.UOM = line.uom;
pol.Warehouse = line.warehouse;
db.AddToPurchaseOrderLines(pol);
db.SaveChanges();
Int32 POLHeaderID = (Int32)pol.POLinesID;
foreach (POShipment ship in line.poShipments)
{
if (ship.poShipmentID>= 0 )
{
PurchaseOrderShipments pos = new
PurchaseOrderShipments();
pos.POLinesID = POLHeaderID;
pos.RequestedDeliveryTime =
ship.RequestedDeliveryTime;
pos.RequesteDeliveryDate =
ship.requestedDeliveryDate;
pos.ShipQuantity = ship.shipQuantity;
pos.ShipUOM = ship.shipUOM;
db.AddToPurchaseOrderShipments(pos);
}
}
db.SaveChanges();
}
}
foreach (POAddress poa in myPO.POAddresses)
{
PurchaseOrderAddresses POA = new
PurchaseOrderAddresses();
POA.Address = poa.address;
POA.Address2 = poa.address2;
POA.AddressType = poa.addressType;
POA.City = poa.city;
POA.LocationID = poa.locationID;
POA.Name = poa.name;
POA.POID = HeaderID;
POA.State = poa.state;
POA.Zip = POA.Zip;
db.AddToPurchaseOrderAddresses(POA);
}
db.SaveChanges();
return flag;
}
catch (Exception ex)
{
string sdefd = ex.Message;
return false;
}
}
}
--
Stephen Russell
Sr. Analyst
Ring Container Technology
Oakland TN
901.246-0159 cell
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message:
http://leafe.com/archives/byMID/profox/cajidmyka_fo977u8++3n7f_npr3chpnfk4sceyc1zv0ka1l...@mail.gmail.com
** All postings, unless explicitly stated otherwise, are the opinions of the
author, and do not constitute legal or medical advice. This statement is added
to the messages for those lawyers who are too stupid to see the obvious.