public override void CommitTablesToDataSource() { using (new OpenConnection(EM.IsWrite.Yes, AdapterHelper.Connection)) { if (DataInterface.IsRowAlive(GetHeaderRow()) && GetHeaderRow().RowState != DataRowState.Added) { if (GetHeaderRow().ItemName != (string) GetHeaderRow()["ItemName", DataRowVersion.Original]) { EMDataSet tempDataSet = new EMDataSet(); using (new TurnOffConstraints(tempDataSet)) { OleDbDataAdapter adapter = new OleDbDataAdapter(); adapter.SelectCommand = new OleDbCommand(); adapter.SelectCommand.CommandText = "SELECT ItemID,ItemName,CompID FROM " + "tblItem where ItemName = '" + GetHeaderRow().ItemName + "' AND CompID = " + GetHeaderRow().CompID.ToString(); adapter.SelectCommand.Connection = AdapterHelper.Connection; adapter.Fill(tempDataSet.ItemTbl); if (tempDataSet.ItemTbl.Rows.Count > 1) throw new Exception("BUG: There are too many rows with that item name"); if (tempDataSet.ItemTbl.Rows.Count == 1) { int newItemID = (int)tempDataSet.ItemTbl.Rows[0]["ItemID"]; tempDataSet.Clear(); DialogResult res = MessageBox.Show("There is already an item with this name. Would you like " + "to merge the item with this one? This will update all purchase orders that " + "have this item.", "Merge Item?", MessageBoxButtons.YesNo); if (res == DialogResult.No) return; // We will update all the POs to the other item. Then delete the current item. UpdatePOItems(GetHeaderRow().ItemID, newItemID); GetHeaderRow().Delete(); } tempDataSet.Clear(); } } } AdapterHelper.UpdateItemsFromCompID(m_emDataSet); } }
void SetupLocationCombo(ComboBox box,int compID) { box.Items.Clear(); box.Items.Add(new TaggedItem(-1,"All Locations")); box.SelectedIndex = 0; if (compID == -1) return; EMDataSet emDataSet = new EMDataSet(); using (new TurnOffConstraints(emDataSet)) { using (new OpenConnection(EM.IsWrite.No,AdapterHelper.Connection)) { AdapterHelper.FillLocations(emDataSet,compID); } foreach (EMDataSet.LocationTblRow row in emDataSet.LocationTbl) { TaggedItem item = new TaggedItem(row.LocID,row.LocName); box.Items.Add(item); } emDataSet.Clear(); } }
public override bool IsDeleteAllowed() { using (new OpenConnection(EM.IsWrite.Yes,AdapterHelper.Connection)) { EMDataSet tempDataSet = new EMDataSet(); using (new TurnOffConstraints(tempDataSet)) { OleDbDataAdapter adapter = new OleDbDataAdapter(); adapter.SelectCommand = new OleDbCommand(); adapter.SelectCommand.CommandText = "SELECT POITEMNumber, ItemID FROM "+ "tblPOItem2 where ItemID = " + GetHeaderRow().ItemID; adapter.SelectCommand.Connection = AdapterHelper.Connection; adapter.Fill(tempDataSet.POItemTbl); if (tempDataSet.POItemTbl.Rows.Count != 0) { tempDataSet.Clear(); MessageBox.Show("Delete of item is not allowed. Item is still used by " + "Purchase Orders in the database."); return false; } tempDataSet.Clear(); } } return true; }
static decimal GetTotalContainerWeightExcludeCurrentContainer( EMDataSet tempContainerDataSet, int currentContainer,int poItemNumber,bool isMetric) { tempContainerDataSet.Clear(); tempContainerDataSet.EnforceConstraints = false; AdapterHelper.FillContBundleFromPOItemNumber(tempContainerDataSet,poItemNumber); decimal weight=0; foreach(EMDataSet.ContBundleTblRow row in tempContainerDataSet.ContBundleTbl.Rows) { if (row.ContID == currentContainer) continue; weight += GetWeightFromRow(row,isMetric); } return weight; }