Hopefully someone here can help me/point me in the right direction.
I've found tons of references towards making relations, creating rows,
saving said rows, using datagrids, databinding objects, and etc in
regards to Windows Forms, C#, and Visual Studio .Net 2003.
I seem to have run into a bit of a problem however. I'm not using
datagrids to show related data, my users wouldn't have any idea how to
use them, and they want to see all of their information in the same
place (So they don't want to see a Customer ID number when they are
looking at an order - They want to see that customer's Name). As such
I've created a form with 4 tabs in a TabControl, each tab shows the
related table's data (Shipment Profile, Dangerous Goods, Notes,
Products Used). The tabs use Combo boxes, Text Boxes, etc to show the
important fields. I have a dataset that is filled at runtime. This
dataset also has all the relations defined (parent and child tables are
linked by QuoteID field). The tables in the dataset are filling. The
relations (QuotesShipmentProfile, QuotesDGs, QuotesNotes,
QuotesProductsUsedInQuotes) seem to be working/defined. However, the
databinding seems off when I switch between rows and if I create
new/modify old/delete rows (in the parent tables [Quotes] and/or the
child tables [ShipmentProfile, DG, Notes, ProductsUsedInQuotes]), the
Update commands fail and nothing is written to the SQL Server. I
assume this is due to the binding as well.
Follows is a small part of my code. If you want to see more, just let
me know.
Thanks,
Beth
On Form Load:
//sql stuff
private ClassicLogistics.DatasetCL objDataSet;
private ClassicLogistics.DatasetCL objDataSet2;
private System.Data.SqlClient.SqlConnection cl;
private System.Data.SqlClient.SqlDataAdapter
HAWBTableAdapter;
private System.Data.SqlClient.SqlCommandBuilder HAWBCom;
private System.Data.SqlClient.SqlDataAdapter
DimTableAdapter;
private System.Data.SqlClient.SqlCommandBuilder DimCom;
private System.Data.SqlClient.SqlDataAdapter
DGTableAdapter;
private System.Data.SqlClient.SqlCommandBuilder DGCom;
private System.Data.SqlClient.SqlDataAdapter
NoteTableAdapter;
private System.Data.SqlClient.SqlCommandBuilder NoteCom;
private System.Data.SqlClient.SqlDataAdapter
ProdUsedTableAdapter;
private System.Data.SqlClient.SqlCommandBuilder
ProdUsedCom;
private System.Data.SqlClient.SqlCommand selectCom;
private System.Data.SqlClient.SqlCommand addCom;
private System.Data.SqlClient.SqlCommand delCom;
private System.Data.SqlClient.SqlCommand upCom;
private System.Data.SqlClient.SqlCommand DselectCom;
private System.Data.SqlClient.SqlCommand DaddCom;
private System.Data.SqlClient.SqlCommand DdelCom;
private System.Data.SqlClient.SqlCommand DupCom;
private System.Data.SqlClient.SqlCommand DGselectCom;
private System.Data.SqlClient.SqlCommand DGaddCom;
private System.Data.SqlClient.SqlCommand DGdelCom;
private System.Data.SqlClient.SqlCommand DGupCom;
private System.Data.SqlClient.SqlCommand NselectCom;
private System.Data.SqlClient.SqlCommand NaddCom;
private System.Data.SqlClient.SqlCommand NdelCom;
private System.Data.SqlClient.SqlCommand NupCom;
private System.Data.SqlClient.SqlCommand PselectCom;
private System.Data.SqlClient.SqlCommand PaddCom;
private System.Data.SqlClient.SqlCommand PdelCom;
private System.Data.SqlClient.SqlCommand PupCom;
private DataRow[] shipdet;
private DataRow[] shipprofdet;
private DataRow[] dgdet;
private DataRow[] notedet;
private DataRow[] proddet;
private int numOfRows;
private StringBuilder errorMessages;
//set up sql stuff, bind objects
objDataSet = new DatasetCL();
objDataSet2 = new DatasetCL();
//prints dataset defined relations
foreach (DataRelation r in
objDataSet.Quotes.ChildRelations)
Console.WriteLine("Name: " +
r.RelationName.ToString() + " Parent:" +
r.ParentKeyConstraint.ConstraintName.ToString() + " Child: " +
r.ChildKeyConstraint.ConstraintName.ToString());
cl = new
SqlConnection("server=SERVER1;uid=ClassicUser;Pwd= admin;database=ClassicLogisticsBE");
cl.Open();
selectCom = cl.CreateCommand();
selectCom.CommandText = "SELECT QuoteID, HAWB,
CustomerID, " +
"CustomerContact, EnteredBy, QuoteDate,
OriginZip, " +
"DestinationZip, Commodity,
RecoveryDate, ShipperID, "+
"ConsigneeID, CustomerRef, CarrierID,
Pieces, ActWgt, " +
"ChgWgt, Charge, Cost, MAWB, ManifestNo,
DeliveryDate, " +
"DropOrder, DriverNote, OnHandNo,
RateConfirmCheck, " +
"CompleteCheck, Cancel FROM Quotes ORDER
BY QuoteID";
addCom = cl.CreateCommand();
addCom.CommandText = "INSERT INTO Quotes ( " +
"HAWB, CustomerID, CustomerContact,
EnteredBy, " +
"QuoteDate, OriginZip, DestinationZip,
Commodity, " +
"RecoveryDate, ShipperID, ConsigneeID,
CustomerRef, " +
"CarrierID, Pieces, ActWgt, ChgWgt,
Charge, Cost, " +
"MAWB, ManifestNo, DeliveryDate,
DropOrder, DriverNote, " +
"OnHandNo, RateConfirmCheck,
CompleteCheck, Cancel)" +
" VALUES ( @HAWB, @CustomerID,
@CustomerContact, " +
"@EnteredBy, @QuoteDate, @OriginZip,
@DestinationZip, " +
"@Commodity, @RecoveryDate, @ShipperID,
@ConsigneeID, " +
"@CustomerRef, @CarrierID, @Pieces,
@ActWgt, @ChgWgt, " +
"@Charge, @Cost, @MAWB, @ManifestNo,
@DeliveryDate, " +
"@DropOrder, @DriverNote, @OnHandNo,
@RateConfirmCheck, " +
"@CompleteCheck, @Cancel);" +
"SELECT @QuoteID = SCOPE_IDENTITY();";
addCom.Parameters.Add("@QuoteID", SqlDbType.Int,
15, "QuoteID");
addCom.Parameters.Add("@HAWB",
SqlDbType.NVarChar, 20, "HAWB");
addCom.Parameters.Add("@CustomerID",
SqlDbType.Int, 100,
"CustomerID");
addCom.Parameters.Add("@CustomerContact",
SqlDbType.NVarChar, 100,
"CustomerContact");
addCom.Parameters.Add("@EnteredBy",
SqlDbType.Int, 100,
"EnteredBy");
addCom.Parameters.Add("@QuoteDate",
SqlDbType.SmallDateTime, 20,
"QuoteDate");
addCom.Parameters.Add("@OriginZip",
SqlDbType.NVarChar, 15,
"OriginZip");
addCom.Parameters.Add("@DestinationZip",
SqlDbType.NVarChar, 150,
"DestinationZip");
addCom.Parameters.Add("@Commodity",
SqlDbType.NVarChar, 50,
"Commodity");
addCom.Parameters.Add("@RecoveryDate",
SqlDbType.SmallDateTime, 20,
"RecoveryDate");
addCom.Parameters.Add("@ShipperID",
SqlDbType.Int, 100,
"ShipperID");
addCom.Parameters.Add("@ConsigneeID",
SqlDbType.Int, 100,
"ConsigneeID");
addCom.Parameters.Add("@CustomerRef",
SqlDbType.NVarChar, 100,
"CustomerRef");
addCom.Parameters.Add("@CarrierID",
SqlDbType.Int, 100,
"CarrierID");
addCom.Parameters.Add("@Pieces", SqlDbType.Int,
10, "Pieces");
addCom.Parameters.Add("@ActWgt",
SqlDbType.Decimal, 10, "ActWgt");
addCom.Parameters.Add("@ChgWgt",
SqlDbType.Decimal, 10, "ChgWgt");
addCom.Parameters.Add("@Charge",
SqlDbType.Money, 20, "Charge");
addCom.Parameters.Add("@Cost", SqlDbType.Money,
20, "Cost");
addCom.Parameters.Add("@MAWB",
SqlDbType.NVarChar, 20, "MAWB");
addCom.Parameters.Add("@ManifestNo",
SqlDbType.NVarChar, 100,
"ManifestNo");
addCom.Parameters.Add("@DeliveryDate",
SqlDbType.SmallDateTime, 20,
"DeliveryDate");
addCom.Parameters.Add("@DropOrder",
SqlDbType.Int, 50, "DropOrder");
addCom.Parameters.Add("@DriverNote",
SqlDbType.NText, 1000,
"DriverNote");
addCom.Parameters.Add("@OnHandNo",
SqlDbType.NVarChar, 100,
"OnHandNo");
addCom.Parameters.Add("@RateConfirmCheck",
SqlDbType.Bit, 1,
"RateConfirmCheck");
addCom.Parameters.Add("@CompleteCheck",
SqlDbType.Bit, 1,
"CompleteCheck");
addCom.Parameters.Add("@Cancel", SqlDbType.Bit,
1, "Cancel");
addCom.Parameters["@QuoteID"].Direction =
ParameterDirection.Output;
//there is also a delete and update command that follow
HAWBTableAdapter = new SqlDataAdapter();
HAWBTableAdapter.SelectCommand = selectCom;
HAWBTableAdapter.InsertCommand = addCom;
HAWBTableAdapter.UpdateCommand = upCom;
HAWBTableAdapter.DeleteCommand = delCom;
HAWBTableAdapter.ContinueUpdateOnError = true;
HAWBCom = new
SqlCommandBuilder(HAWBTableAdapter);
objDataSet.Quotes.Columns["QuoteID"].AllowDBNull
= false;
objDataSet.Quotes.Columns["QuoteID"].AutoIncrement = true;
objDataSet.Quotes.Columns["QuoteID"].AutoIncrementSeed = -1;
objDataSet.Quotes.Columns["QuoteID"].AutoIncrementStep = -1;
objDataSet.Quotes.Columns["QuoteID"].ReadOnly =
true;
objDataSet.Quotes.Columns["QuoteID"].Unique =
true;
//table is filled
//this is for the ShipmentProfile table. I created D..Coms for each
command, but those didn't work any better than the CommandBuilder,
there are similar lines of code for DG (DGKey), Notes (NotesKey), and
ProductsUsedInQuotes (PUIQKey)
DimTableAdapter = new SqlDataAdapter("SELECT *
FROM ShipmentProfile
ORDER BY QuoteID", cl);
/*DimTableAdapter = new SqlDataAdapter();
DimTableAdapter.SelectCommand = DselectCom;
DimTableAdapter.InsertCommand = DaddCom;
DimTableAdapter.DeleteCommand = DdelCom;
DimTableAdapter.UpdateCommand = DupCom;*/
DimTableAdapter.ContinueUpdateOnError = true;
DimCom = new SqlCommandBuilder(DimTableAdapter);
objDataSet.ShipmentProfile.Columns["SPKey"].AllowDBNull = false;
objDataSet.ShipmentProfile.Columns["SPKey"].AutoIncrement = true;
objDataSet.ShipmentProfile.Columns["SPKey"].AutoIncrementSeed = -1;
objDataSet.ShipmentProfile.Columns["SPKey"].AutoIncrementStep = -1;
objDataSet.ShipmentProfile.Columns["SPKey"].ReadOnly = true;
objDataSet.ShipmentProfile.Columns["SPKey"].Unique = true;
//fill those child tables
//Bind boxes
//HAWB Main
QuoteNoBox.DataBindings.Add("Text", objDataSet,
"Quotes.QuoteID");
EnteredByBox.DataBindings.Add("SelectedValue",
objDataSet,
"Quotes.EnteredBy");
DateBox.DataBindings.Add("Text", objDataSet,
"Quotes.QuoteDate");
MAWBBox.DataBindings.Add("Text", objDataSet,
"Quotes.MAWB");
CustBox.DataBindings.Add("SelectedValue",
objDataSet,
"Quotes.CustomerID");
ComBox.DataBindings.Add("Text", objDataSet,
"Quotes.Commodity");
ShipBox.DataBindings.Add("SelectedValue",
objDataSet,
"Quotes.ShipperID");
ConBox.DataBindings.Add("SelectedValue",
objDataSet,
"Quotes.ConsigneeID");
ChargeBox.DataBindings.Add("Text", objDataSet,
"Quotes.Charge");
CostBox.DataBindings.Add("Text", objDataSet,
"Quotes.Cost");
TotPcsBox.DataBindings.Add("Text", objDataSet,
"Quotes.Pieces");
TotWgtBox.DataBindings.Add("Text", objDataSet,
"Quotes.ActWgt");
TotChgBox.DataBindings.Add("Text", objDataSet,
"Quotes.ChgWgt");
RateCheck.DataBindings.Add("Checked",
objDataSet,
"Quotes.RateConfirmCheck");
CompCheck.DataBindings.Add("Checked",
objDataSet,
"Quotes.CompleteCheck");
CancelCheck.DataBindings.Add("Checked",
objDataSet,
"Quotes.Cancel");
//Dims Tab
PcsBox.DataBindings.Add("Text",
objDataSet.Quotes,
"QuotesShipmentProfile.Pieces");
LINBox.DataBindings.Add("Text",
objDataSet.Quotes,
"QuotesShipmentProfile.Length");
LCMBox.DataBindings.Add("Text",
objDataSet.Quotes,
"QuotesShipmentProfile.LengthMetric");
WINBox.DataBindings.Add("Text",
objDataSet.Quotes,
"QuotesShipmentProfile.Width");
WCMBox.DataBindings.Add("Text",
objDataSet.Quotes,
"QuotesShipmentProfile.WidthMetric");
HINBox.DataBindings.Add("Text",
objDataSet.Quotes,
"QuotesShipmentProfile.Height");
HCMBox.DataBindings.Add("Text",
objDataSet.Quotes,
"QuotesShipmentProfile.HeightMetric");
WLBBox.DataBindings.Add("Text",
objDataSet.Quotes,
"QuotesShipmentProfile.ActWgt");
WKGBox.DataBindings.Add("Text",
objDataSet.Quotes,
"QuotesShipmentProfile.ActWgtMetric");
DWLBBox.DataBindings.Add("Text",
objDataSet.Quotes,
"QuotesShipmentProfile.DimWgt");
DWKGBox.DataBindings.Add("Text",
objDataSet.Quotes,
"QuotesShipmentProfile.DimWgtMetric");
CWLBBox.DataBindings.Add("Text",
objDataSet.Quotes,
"QuotesShipmentProfile.ChgWgt");
CWKGBox.DataBindings.Add("Text",
objDataSet.Quotes,
"QuotesShipmentProfile.ChgWgtMetric");
CFBox.DataBindings.Add("Text",
objDataSet.Quotes,
"QuotesShipmentProfile.CubicFeet");
CIBox.DataBindings.Add("Text",
objDataSet.Quotes,
"QuotesShipmentProfile.CubicInches");
CMBox.DataBindings.Add("Text",
objDataSet.Quotes,
"QuotesShipmentProfile.CubicMeters");
//more binding for the rest of the tabs
cl.Close()
There is a button called Save that pushes the changes to the server.
The commented out sections do not seem to work any better than the
uncommented.
private void push()
{
//actually does push work
complete = true;
errorMessages = new StringBuilder();
cl.Open();
try
{
//checks for completeness and fills in
checkbox accordingly
if
(objDataSet.Relations["QuotesProductsUsedInQuotes"].ChildTable.Rows.Count.Equals(0))
complete = false;
if
(objDataSet.Relations["QuotesShipmentProfile"].ChildTable.Rows.Count.Equals(0))
complete = false;
if (ChargeBox.Text.Length.Equals(0))
complete = false;
if (CostBox.Text.Length.Equals(0))
complete = false;
if (ShipBox.Text.Length.Equals(0))
complete = false;
if (CustBox.Text.Length.Equals(0))
complete = false;
if (ConBox.Text.Length.Equals(0))
complete = false;
if (ComBox.Text.Length.Equals(0))
complete = false;
if (DateBox.Text.Length.Equals(0))
complete = false;
if (TotWgtBox.Text.Length.Equals(0))
complete = false;
if (TotChgBox.Text.Length.Equals(0))
complete = false;
if (TotPcsBox.Text.Length.Equals(0))
complete = false;
if (complete)
CompCheck.Checked = true;
//store new rows
//this.BindingContext[objDataSet,"Quotes"].EndCurrentEdit();
//this.BindingContext[objDataSet,"QuotesShipmentProfile"].EndCurrentEdit();
//this.BindingContext[objDataSet,"QuotesDG"].EndCurrentEdit();
//this.BindingContext[objDataSet,"QuotesNotes"].EndCurrentEdit();
//this.BindingContext[objDataSet,"QuotesProductsUsedInQuotes"].EndCurrentEdit();
maxQuoteID = (int)
objDataSet.Quotes.Rows[objDataSet.Quotes.Rows.Count-1]["QuoteID"];
numOfRows =
HAWBTableAdapter.Update(objDataSet, "Quotes");
Console.WriteLine("saved " +
numOfRows.ToString() + " rows");
numOfRows =
DimTableAdapter.Update(objDataSet,
"ShipmentProfile");
Console.WriteLine("saved " +
numOfRows.ToString() + " rows");
numOfRows =
DGTableAdapter.Update(objDataSet, "DG");
Console.WriteLine("saved " +
numOfRows.ToString() + " rows");
numOfRows =
NoteTableAdapter.Update(objDataSet, "Notes");
Console.WriteLine("saved " +
numOfRows.ToString() + " rows");
numOfRows =
ProdTableAdapter.Update(objDataSet,
"ProductsUsedInQuotes");
Console.WriteLine("saved " +
numOfRows.ToString() + " rows");
/*shipdet =
objDataSet.Quotes.Select("","",DataViewRowState.Ad ded);
Console.WriteLine("found " +
shipdet.Length + " rows");
numOfRows =
HAWBTableAdapter.Update(shipdet);
Console.WriteLine("saved " +
numOfRows.ToString() + " rows");
shipdet =
objDataSet.Quotes.Select("QuoteID " + maxQuoteID);
for (int x = 0; x < shipdet.Length; x++)
{
DataRow mySysLogRow =
objDataSet.SystemLog.NewRow();
mySysLogRow["DayTime"] =
System.DateTime.Now.ToString();
mySysLogRow["Username"] =
myuser.Username.ToString();
mySysLogRow["Message"] =
"Created in Quotes QuoteID " +
shipdet[x]["QuoteID"];
objDataSet.SystemLog.Rows.Add(mySysLogRow);
}
test =
SysTableAdapter.Update(objDataSet, "SystemLog");
Console.WriteLine("saved " +
test.ToString() + " log rows");
shipprofdet =
objDataSet.ShipmentProfile.Select("","",DataViewRo wState.Added);
Console.WriteLine("found " +
shipprofdet.Length + " rows");
numOfRows =
DimTableAdapter.Update(shipprofdet);
Console.WriteLine("saved " +
numOfRows.ToString() + " rows");
for (int x = 0; x < shipprofdet.Length;
x++)
{
DataRow mySysLogRow =
objDataSet.SystemLog.NewRow();
mySysLogRow["DayTime"] =
System.DateTime.Now.ToString();
mySysLogRow["Username"] =
myuser.Username.ToString();
mySysLogRow["Message"] =
"Created in Shipment Profile QuoteID " +
shipprofdet[x]["QuoteID"];
objDataSet.SystemLog.Rows.Add(mySysLogRow);
}
test =
SysTableAdapter.Update(objDataSet, "SystemLog");
Console.WriteLine("saved " +
test.ToString() + " log rows");
dgdet =
objDataSet.DG.Select("","",DataViewRowState.Added) ;
Console.WriteLine("found " +
dgdet.Length + " rows");
numOfRows =
DGTableAdapter.Update(dgdet);
Console.WriteLine("saved " +
numOfRows.ToString() + " rows");
for (int x = 0; x < dgdet.Length; x++)
{
DataRow mySysLogRow =
objDataSet.SystemLog.NewRow();
mySysLogRow["DayTime"] =
System.DateTime.Now.ToString();
mySysLogRow["Username"] =
myuser.Username.ToString();
mySysLogRow["Message"] =
"Created in DG QuoteID " +
dgdet[x]["QuoteID"];
objDataSet.SystemLog.Rows.Add(mySysLogRow);
}
test =
SysTableAdapter.Update(objDataSet, "SystemLog");
Console.WriteLine("saved " +
test.ToString() + " log rows");
notedet =
objDataSet.Notes.Select("","",DataViewRowState.Add ed);
Console.WriteLine("found " +
notedet.Length + " rows");
numOfRows =
NoteTableAdapter.Update(notedet);
Console.WriteLine("saved " +
numOfRows.ToString() + " rows");
for (int x = 0; x < notedet.Length; x++)
{
DataRow mySysLogRow =
objDataSet.SystemLog.NewRow();
mySysLogRow["DayTime"] =
System.DateTime.Now.ToString();
mySysLogRow["Username"] =
myuser.Username.ToString();
mySysLogRow["Message"] =
"Created in Notes QuoteID " +
notedet[x]["QuoteID"];
objDataSet.SystemLog.Rows.Add(mySysLogRow);
}
test =
SysTableAdapter.Update(objDataSet, "SystemLog");
Console.WriteLine("saved " +
test.ToString() + " log rows");
proddet =
objDataSet.ProductsUsedInQuotes.Select("","",DataV iewRowState.Added);
Console.WriteLine("found " +
proddet.Length + " rows");
numOfRows =
ProdUsedTableAdapter.Update(proddet);
Console.WriteLine("saved " +
numOfRows.ToString() + " rows");
for (int x = 0; x < proddet.Length; x++)
{
DataRow mySysLogRow =
objDataSet.SystemLog.NewRow();
mySysLogRow["DayTime"] =
System.DateTime.Now.ToString();
mySysLogRow["Username"] =
myuser.Username.ToString();
mySysLogRow["Message"] =
"Created in ProductsUsedInQuotes QuoteID
" + proddet[x]["QuoteID"];
objDataSet.SystemLog.Rows.Add(mySysLogRow);
}
test =
SysTableAdapter.Update(objDataSet, "SystemLog");
Console.WriteLine("saved " +
test.ToString() + " log rows");
//store modified changes
shipdet =
objDataSet.Quotes.Select("","",DataViewRowState.Mo difiedCurrent);
Console.WriteLine("found " +
shipdet.Length + " rows");
numOfRows =
HAWBTableAdapter.Update(shipdet);
Console.WriteLine("saved " +
numOfRows.ToString() + " rows");
for (int x = 0; x < shipdet.Length; x++)
{
DataRow mySysLogRow =
objDataSet.SystemLog.NewRow();
mySysLogRow["DayTime"] =
System.DateTime.Now.ToString();
mySysLogRow["Username"] =
myuser.Username.ToString();
mySysLogRow["Message"] =
"Modified in Quotes QuoteID " +
shipdet[x]["QuoteID"];
objDataSet.SystemLog.Rows.Add(mySysLogRow);
}
test =
SysTableAdapter.Update(objDataSet, "SystemLog");
Console.WriteLine("saved " +
test.ToString() + " log rows");
shipprofdet =
objDataSet.ShipmentProfile.Select("","",DataViewRo wState.ModifiedCurrent);
Console.WriteLine("found " +
shipprofdet.Length + " rows");
numOfRows =
DimTableAdapter.Update(shipprofdet);
Console.WriteLine("saved " +
numOfRows.ToString() + " rows");
for (int x = 0; x < shipprofdet.Length;
x++)
{
DataRow mySysLogRow =
objDataSet.SystemLog.NewRow();
mySysLogRow["DayTime"] =
System.DateTime.Now.ToString();
mySysLogRow["Username"] =
myuser.Username.ToString();
mySysLogRow["Message"] =
"Modified in Shipment Profile QuoteID " +
shipprofdet[x]["QuoteID"];
objDataSet.SystemLog.Rows.Add(mySysLogRow);
}
test =
SysTableAdapter.Update(objDataSet, "SystemLog");
Console.WriteLine("saved " +
test.ToString() + " log rows");
dgdet =
objDataSet.DG.Select("","",DataViewRowState.Modifi edCurrent);
Console.WriteLine("found " +
dgdet.Length + " rows");
numOfRows =
DGTableAdapter.Update(dgdet);
Console.WriteLine("saved " +
numOfRows.ToString() + " rows");
for (int x = 0; x < dgdet.Length; x++)
{
DataRow mySysLogRow =
objDataSet.SystemLog.NewRow();
mySysLogRow["DayTime"] =
System.DateTime.Now.ToString();
mySysLogRow["Username"] =
myuser.Username.ToString();
mySysLogRow["Message"] =
"Modified in DG QuoteID " +
dgdet[x]["QuoteID"];
objDataSet.SystemLog.Rows.Add(mySysLogRow);
}
test =
SysTableAdapter.Update(objDataSet, "SystemLog");
Console.WriteLine("saved " +
test.ToString() + " log rows");
notedet =
objDataSet.Notes.Select("","",DataViewRowState.Mod ifiedCurrent);
Console.WriteLine("found " +
notedet.Length + " rows");
numOfRows =
NoteTableAdapter.Update(notedet);
Console.WriteLine("saved " +
numOfRows.ToString() + " rows");
for (int x = 0; x < notedet.Length; x++)
{
DataRow mySysLogRow =
objDataSet.SystemLog.NewRow();
mySysLogRow["DayTime"] =
System.DateTime.Now.ToString();
mySysLogRow["Username"] =
myuser.Username.ToString();
mySysLogRow["Message"] =
"Modified in Notes QuoteID " +
notedet[x]["QuoteID"];
objDataSet.SystemLog.Rows.Add(mySysLogRow);
}
test =
SysTableAdapter.Update(objDataSet, "SystemLog");
Console.WriteLine("saved " +
test.ToString() + " log rows");
proddet =
objDataSet.ProductsUsedInQuotes.Select("","",DataV iewRowState.Added);
Console.WriteLine("found " +
proddet.Length + " rows");
numOfRows =
ProdUsedTableAdapter.Update(proddet);
Console.WriteLine("saved " +
numOfRows.ToString() + " rows");
for (int x = 0; x < proddet.Length; x++)
{
DataRow mySysLogRow =
objDataSet.SystemLog.NewRow();
mySysLogRow["DayTime"] =
System.DateTime.Now.ToString();
mySysLogRow["Username"] =
myuser.Username.ToString();
mySysLogRow["Message"] =
"Modified in ProductsUsedInQuotes QuoteID
" + proddet[x]["QuoteID"];
objDataSet.SystemLog.Rows.Add(mySysLogRow);
}
test =
SysTableAdapter.Update(objDataSet, "SystemLog");
Console.WriteLine("saved " +
test.ToString() + " log rows");
//store deletes
shipprofdet =
objDataSet.ShipmentProfile.Select("","",DataViewRo wState.Deleted);
Console.WriteLine("found " +
shipprofdet.Length + " rows");
numOfRows =
DimTableAdapter.Update(shipprofdet);
Console.WriteLine("saved " +
numOfRows.ToString() + " rows");
for (int x = 0; x < shipprofdet.Length;
x++)
{
DataRow mySysLogRow =
objDataSet.SystemLog.NewRow();
mySysLogRow["DayTime"] =
System.DateTime.Now.ToString();
mySysLogRow["Username"] =
myuser.Username.ToString();
mySysLogRow["Message"] =
"Deleted in Shipment Profile QuoteID " +
shipprofdet[x]["QuoteID"];
objDataSet.SystemLog.Rows.Add(mySysLogRow);
}
test =
SysTableAdapter.Update(objDataSet, "SystemLog");
Console.WriteLine("saved " +
test.ToString() + " log rows");
dgdet =
objDataSet.DG.Select("","",DataViewRowState.Delete d);
Console.WriteLine("found " +
dgdet.Length + " rows");
numOfRows =
DGTableAdapter.Update(dgdet);
Console.WriteLine("saved " +
numOfRows.ToString() + " rows");
for (int x = 0; x < dgdet.Length; x++)
{
DataRow mySysLogRow =
objDataSet.SystemLog.NewRow();
mySysLogRow["DayTime"] =
System.DateTime.Now.ToString();
mySysLogRow["Username"] =
myuser.Username.ToString();
mySysLogRow["Message"] =
"Deleted in DG QuoteID " +
dgdet[x]["QuoteID"];
objDataSet.SystemLog.Rows.Add(mySysLogRow);
}
test =
SysTableAdapter.Update(objDataSet, "SystemLog");
Console.WriteLine("saved " +
test.ToString() + " log rows");
notedet =
objDataSet.Notes.Select("","",DataViewRowState.Del eted);
Console.WriteLine("found " +
notedet.Length + " rows");
numOfRows =
NoteTableAdapter.Update(notedet);
Console.WriteLine("saved " +
numOfRows.ToString() + " rows");
for (int x = 0; x < notedet.Length; x++)
{
DataRow mySysLogRow =
objDataSet.SystemLog.NewRow();
mySysLogRow["DayTime"] =
System.DateTime.Now.ToString();
mySysLogRow["Username"] =
myuser.Username.ToString();
mySysLogRow["Message"] =
"Deleted in Notes QuoteID " +
notedet[x]["QuoteID"];
objDataSet.SystemLog.Rows.Add(mySysLogRow);
}
test =
SysTableAdapter.Update(objDataSet, "SystemLog");
Console.WriteLine("saved " +
test.ToString() + " log rows");
proddet =
objDataSet.ProductsUsedInQuotes.Select("","",DataV iewRowState.Deleted);
Console.WriteLine("found " +
proddet.Length + " rows");
numOfRows =
ProdUsedTableAdapter.Update(proddet);
Console.WriteLine("saved " +
numOfRows.ToString() + " rows");
for (int x = 0; x < proddet.Length; x++)
{
DataRow mySysLogRow =
objDataSet.SystemLog.NewRow();
mySysLogRow["DayTime"] =
System.DateTime.Now.ToString();
mySysLogRow["Username"] =
myuser.Username.ToString();
mySysLogRow["Message"] =
"Deleted in ProductsUsedInQuotes QuoteID
" + proddet[x]["QuoteID"];
objDataSet.SystemLog.Rows.Add(mySysLogRow);
}
test =
SysTableAdapter.Update(objDataSet, "SystemLog");
Console.WriteLine("saved " +
test.ToString() + " log rows");
shipdet =
objDataSet.Quotes.Select("","",DataViewRowState.De leted);
Console.WriteLine("found " +
shipdet.Length + " rows");
numOfRows =
HAWBTableAdapter.Update(shipdet);
Console.WriteLine("saved " +
numOfRows.ToString() + " rows");
for (int x = 0; x < shipdet.Length; x++)
{
DataRow mySysLogRow =
objDataSet.SystemLog.NewRow();
mySysLogRow["DayTime"] =
System.DateTime.Now.ToString();
mySysLogRow["Username"] =
myuser.Username.ToString();
mySysLogRow["Message"] =
"Deleted in Quotes QuoteID " +
shipdet[x]["QuoteID"];
objDataSet.SystemLog.Rows.Add(mySysLogRow);
}
test =
SysTableAdapter.Update(objDataSet, "SystemLog");
Console.WriteLine("saved " +
test.ToString() + " log rows");
*/
}
catch (SqlException ex)
{
for (int i = 0; i < ex.Errors.Count;
i++)
{
errorMessages.Append("Index #" +
i + "\n" +
"Message: " +
ex.Errors[i].Message + "\n" +
"LineNumber: " +
ex.Errors[i].LineNumber + "\n" +
"Source: " +
ex.Errors[i].Source + "\n" +
"Procedure: " +
ex.Errors[i].Procedure + "\n");
}
Console.WriteLine(errorMessages.ToString());
MessageBox.Show("An Error Occured.
Please check your page and try
again.");
}
cl.Close();
}