I currently have a datagridview filled with SQL objects using LINQ.
private void AddNewTICShipment()
{
//Data maping object to our database
ShipDataContext dc = new ShipDataContext();
TIC objTIC = new TIC();
//TICTypeID default value for Cleared Tics
objTIC.TICTypeID = 2;
objTIC.Year = Convert.ToInt32(textBoxYear.Text);
objTIC.ShippingDocument = textBoxShippingDocument.Text;
if (String.IsNullOrEmpty(textBoxTICRef.Text))
{
objTIC.TICRef = null;
}
else
{
objTIC.TICRef = Convert.ToInt32(textBoxTICRef.Text);
}
string receivedDate = dateTimePickerReceived.Value.ToShortDateString();
objTIC.Received = receivedDate;
objTIC.Carrier = textBoxCarrier.Text;
objTIC.BillOfLading = textBoxBillOfLading.Text;
string ETADate = dateTimePickerETA.Value.ToShortDateString();
objTIC.ETA = ETADate;
if (String.IsNullOrEmpty(textBoxPieces.Text))
{
objTIC.Pieces= null;
}
else
{
objTIC.Pieces = Convert.ToInt32(textBoxPieces.Text);
}
objTIC.Incoterms = textBoxIncoterms.Text;
objTIC.Invoices = textBoxInvoices.Text;
objTIC.IMZ = textBoxIMZ.Text;
objTIC.RectificationIMZ = textBoxRectificationIMZ.Text;
objTIC.Remarks = richTextBoxRemarks.Text;
objTIC.FreightSupplier = textBoxFreightSupplier.Text;
objTIC.FreightReference = textBoxFreightReference.Text;
objTIC.InlandHauleSupplier = textBoxInlandHauleSupplier.Text;
objTIC.InlandHauleReference = textBoxInlandHauleReference.Text;
objTIC.AdminInlandSupplier = textBoxAdminInlandSupplier.Text;
objTIC.AdminInlandReference = textBoxAdminInlandReference.Text;
objTIC.DutiesSupplier = textBoxDutiesSupplier.Text;
objTIC.DutiesReference = textBoxFreightReference.Text;
string arrivalEU = comboBoxArrivalEU.SelectedValue.ToString();
switch (arrivalEU)
{
case "BRU":
objTIC.ArrivalEUID = 1;
break;
case "ANR":
objTIC.ArrivalEUID = 2;
break;
case "RTN":
objTIC.ArrivalEUID = 3;
break;
}
string department = comboBoxDepartment.SelectedValue.ToString();
switch (department)
{
case "IRRI":
objTIC.DepartmentID = 1;
break;
case "IRRI/DE":
objTIC.DepartmentID = 2;
break;
case "SP":
objTIC.DepartmentID = 3;
break;
}
string shippingMethod = comboBoxShippingMethod.SelectedValue.ToString();
switch (shippingMethod)
{
case "R":
objTIC.ShippingMethodID = 1;
break;
case "O":
objTIC.ShippingMethodID = 2;
break;
case "A":
objTIC.ShippingMethodID = 3;
break;
case "C":
objTIC.ShippingMethodID = 4;
break;
}
string exWarehouse = comboBoxExWarehouse.SelectedValue.ToString();
switch (exWarehouse)
{
case "PLY":
objTIC.ExWarehouseID = 1;
break;
case "ELP":
objTIC.ExWarehouseID = 2;
break;
case "TOM":
objTIC.ExWarehouseID = 3;
break;
}
string inWarehouse = comboBoxInWarehouse.SelectedValue.ToString();
switch (inWarehouse)
{
case "OEV":
objTIC.InWarehouseID = 1;
break;
case "ESS":
objTIC.InWarehouseID = 2;
break;
}
//Converting Decimal . to , for Weight, Freight, Inland, adminInland and duties
string weightValue = textBoxWeight.Text;
string freightValue = textBoxFreightCosts.Text;
string inlandValue = textBoxInlandHauleCosts.Text;
string adminInlandValue = textBoxAdminInlandCosts.Text ;
string dutiesValue = textBoxDutiesCosts.Text;
{
if (weightValue.Contains(".") | freightValue.Contains(".") | inlandValue.Contains(".") | adminInlandValue.Contains(".") )
weightValue = weightValue.Replace(".", ",");
freightValue = freightValue.Replace(".", ",");
inlandValue = inlandValue.Replace(".", ",");
adminInlandValue = adminInlandValue.Replace(".", ",");
dutiesValue = dutiesValue.Replace(".", ",");
}
if (String.IsNullOrEmpty(textBoxWeight.Text) )
{
objTIC.Weight = null;
}
else
{
objTIC.Weight = Convert.ToDecimal(weightValue);
}
if (String.IsNullOrEmpty(textBoxFreightCosts.Text))
{
objTIC.FreightCosts = null;
}
else
{
objTIC.FreightCosts = Convert.ToDecimal(freightValue);
}
if (String.IsNullOrEmpty(textBoxInlandHauleCosts.Text))
{
objTIC.InlandHauleCosts = null;
}
else
{
objTIC.InlandHauleCosts = Convert.ToDecimal(inlandValue);
}
if (String.IsNullOrEmpty(textBoxAdminInlandCosts.Text))
{
objTIC.AdminInlandCosts = null;
}
else
{
objTIC.AdminInlandCosts = Convert.ToDecimal(adminInlandValue);
}
if (String.IsNullOrEmpty(textBoxDutiesCosts.Text))
{
objTIC.DutiesCosts = null;
}
else
{
objTIC.DutiesCosts = Convert.ToDecimal(dutiesValue);
}
dc.TICs.InsertOnSubmit(objTIC);
dc.SubmitChanges();
}
Another option can be to make a new windows form if that's easier? Some of the values from the existing form are from a combobox, so I think it will be better to use the existing form where i also insert new records in?