}//End of btCancel_Click(..) private void btnAdd_Click(object sender, EventArgs e) { if (btnAdd.Text.Equals("Add Vendor")) { VendorSourceItem vendorSource = new VendorSourceItem() { ProductID = _currentProduct.Id, VendorID = ((KeyValuePair <int, string>)comboVendors.SelectedItem).Key, UnitCost = nudUnitPrice.Value, ItemsPerCase = (int)nudCase.Value, MinQtyToOrder = (int)nudMinnimum.Value, Active = true, }; try { if (_vendorSource.AddVendorSourceItem(vendorSource)) { this.DialogResult = DialogResult.OK; MessageBox.Show("The vendor details were added to this product."); } else { MessageBox.Show("The vendor was not attached to the product.\nThat Product/Vendor combination may already exist."); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } else if (btnAdd.Text.Equals("Update Vendor")) { VendorSourceItem vendorSource = new VendorSourceItem() { ProductID = _currentProduct.Id, VendorID = ((KeyValuePair <int, string>)comboVendors.SelectedItem).Key, UnitCost = nudUnitPrice.Value, ItemsPerCase = (int)nudCase.Value, MinQtyToOrder = (int)nudMinnimum.Value, Active = true, }; try { if (_vendorSource.UpdateVendorSourceItem(vendorSource, _currentVendorSourceItem)) { this.DialogResult = DialogResult.OK; MessageBox.Show("The vendor details for this product were updated."); } else { MessageBox.Show("The vendor details were not updated. This information may have already been updated by another employee. Please try again."); } } catch (Exception ex) { MessageBox.Show("Error has Occured. Error Message: " + ex.Message); } } }//End of btnAdd_Click(..)
public static List <VendorSourceItem> GetVendorSourceItemsByProduct(int productId, SqlConnection myConnection) { var vendorSourceItemList = new List <VendorSourceItem>(); myConnection = myConnection ?? GetInventoryDbConnection(); try { var mySqlCommand = new SqlCommand("proc_GetVendorSourceItemsByProduct", myConnection); mySqlCommand.Parameters.AddWithValue("@productID", productId); mySqlCommand.CommandType = CommandType.StoredProcedure; myConnection.Open(); var mySqlReader = mySqlCommand.ExecuteReader(); if (mySqlReader.HasRows) { while (mySqlReader.Read()) { var vendorSrcItem = new VendorSourceItem(mySqlReader.GetInt32(0), mySqlReader.GetInt32(1)) { UnitCost = (Decimal)mySqlReader.GetSqlMoney(2), MinQtyToOrder = mySqlReader.GetInt32(3), ItemsPerCase = mySqlReader.GetInt32(4), Name = mySqlReader.GetString(5), Active = true }; //Add item to list vendorSourceItemList.Add(vendorSrcItem); } } mySqlReader.Close(); } catch (DataException ex) { Console.WriteLine(ex.Message); throw new ApplicationException(Messeges.GetMessage("DatabaseException"), ex); } catch (SqlException ex) { Console.WriteLine(ex.Message); throw new ApplicationException(Messeges.GetMessage("SqlException"), ex); } catch (Exception ex) { Console.WriteLine(ex.Message); throw new ApplicationException(Messeges.GetMessage("Exception"), ex); } finally { myConnection.Close(); } return(vendorSourceItemList); }
public static VendorSourceItem GetVendorSourceItem(int vendorSrcItemId, SqlConnection myConnection) { var vendorSrcItem = new VendorSourceItem(); myConnection = myConnection ?? GetInventoryDbConnection(); try { var mySqlCommand = new SqlCommand("proc_GetVendorSourceItem", myConnection) { CommandType = CommandType.StoredProcedure }; mySqlCommand.Parameters.AddWithValue("@productID", vendorSrcItem.ProductID); mySqlCommand.Parameters.AddWithValue("@vendorID", vendorSrcItem.VendorID); myConnection.Open(); var mySqlReader = mySqlCommand.ExecuteReader(); if (mySqlReader.HasRows) { while (mySqlReader.Read()) { vendorSrcItem = new VendorSourceItem(mySqlReader.GetInt32(0), mySqlReader.GetInt32(1)) { UnitCost = (Decimal)mySqlReader.GetSqlMoney(2), MinQtyToOrder = mySqlReader.GetInt32(3), ItemsPerCase = mySqlReader.GetInt32(4), Active = (Boolean)mySqlReader.GetSqlBoolean(5) }; } } mySqlReader.Close(); } catch (DataException ex) { Console.WriteLine(ex.Message); throw new ApplicationException(Messeges.GetMessage("DatabaseException"), ex); } catch (SqlException ex) { Console.WriteLine(ex.Message); throw new ApplicationException(Messeges.GetMessage("SqlException"), ex); } catch (Exception ex) { Console.WriteLine(ex.Message); throw new ApplicationException(Messeges.GetMessage("Exception"), ex); } finally { myConnection.Close(); } return(vendorSrcItem); }
public static bool AddVendorSourceItem(VendorSourceItem vendorSrcItem, SqlConnection myConnection) { //Questional usage of ?? its incase myConnection comes in null it will grab a new connection. //Thoughts? myConnection = myConnection ?? GetInventoryDbConnection(); try { var mySqlCommand = new SqlCommand("proc_InsertIntoVendorSourceItems", myConnection) { CommandType = CommandType.StoredProcedure }; mySqlCommand.Parameters.AddWithValue("@productID", vendorSrcItem.ProductID); mySqlCommand.Parameters.AddWithValue("@vendorID", vendorSrcItem.VendorID); mySqlCommand.Parameters.AddWithValue("@unitCost", vendorSrcItem.UnitCost); mySqlCommand.Parameters.AddWithValue("@minQtyToOrder", vendorSrcItem.MinQtyToOrder); mySqlCommand.Parameters.AddWithValue("@itemsPerCase", vendorSrcItem.ItemsPerCase); mySqlCommand.Parameters.AddWithValue("@active", vendorSrcItem.Active ? 1 : 0); //Change to bit, Ternary Operator myConnection.Open(); if (mySqlCommand.ExecuteNonQuery() == 1) { return(true); } } catch (DataException ex) { Console.WriteLine(ex.Message); throw new ApplicationException(Messeges.GetMessage("DatabaseException"), ex); } catch (SqlException ex) { if (ex.Number == 2627) { throw new ApplicationException("This vendor is already attached to this product therefore it could not be added."); } else { throw new ApplicationException(Messeges.GetMessage("SqlException"), ex); } } catch (Exception ex) { Console.WriteLine(ex.Message); throw new ApplicationException(Messeges.GetMessage("Exception"), ex); } finally { myConnection.Close(); } return(false); }
private void button1_Click(object sender, EventArgs e) { var vsiManager = new VendorSourceItemManager(); var vsrcItem = new VendorSourceItem { ProductID = (int)productCb.SelectedValue, VendorID = (int)vendorCb.SelectedValue, MinQtyToOrder = (int)minQty.Value, UnitCost = Convert.ToDecimal(unitCost.Text), Active = true }; vsiManager.AddVendorSourceItem(vsrcItem); }
}//End of FrmAttachVendorSource(.) public FrmAttachVendorSource(Product product, VendorSourceItem currentVendorSourceItem) { InitializeComponent(); _vendorSource = new VendorSourceItemManager(); _vendorManager = new VendorManager(); _currentVendorSourceItem = currentVendorSourceItem; _vendors = _vendorManager.GetVendors(); _currentProduct = product; nudCase.Value = _currentVendorSourceItem.ItemsPerCase; nudMinnimum.Value = _currentVendorSourceItem.MinQtyToOrder; nudUnitPrice.Value = _currentVendorSourceItem.UnitCost; btnAdd.Text = "Update Vendor"; comboVendors.Enabled = false; }//End of FrmAttachVendorSource(..)
public static bool UpdateVendorSourceItem(VendorSourceItem vendorSrcItem, VendorSourceItem origVendorSrcItem, SqlConnection myConnection) { myConnection = myConnection ?? GetInventoryDbConnection(); try { //Talk about checking data first in sql, Passing the old data and verifiy its still the same. var mySqlCommand = new SqlCommand("proc_UpdateVendorSourceItem", myConnection) { CommandType = CommandType.StoredProcedure }; mySqlCommand.Parameters.AddWithValue("@productID", vendorSrcItem.ProductID); mySqlCommand.Parameters.AddWithValue("@vendorID", vendorSrcItem.VendorID); mySqlCommand.Parameters.AddWithValue("@unitCost", vendorSrcItem.UnitCost); mySqlCommand.Parameters.AddWithValue("@minQtyToOrder", vendorSrcItem.MinQtyToOrder); mySqlCommand.Parameters.AddWithValue("@itemsPerCase", vendorSrcItem.ItemsPerCase); mySqlCommand.Parameters.AddWithValue("@orig_productID", origVendorSrcItem.ProductID); mySqlCommand.Parameters.AddWithValue("@orig_vendorID", origVendorSrcItem.VendorID); mySqlCommand.Parameters.AddWithValue("@orig_unitCost", origVendorSrcItem.UnitCost); mySqlCommand.Parameters.AddWithValue("@orig_minQtyToOrder", origVendorSrcItem.MinQtyToOrder); mySqlCommand.Parameters.AddWithValue("@orig_itemsPerCase", origVendorSrcItem.ItemsPerCase); myConnection.Open(); if (mySqlCommand.ExecuteNonQuery() == 1) { return(true); } } catch (DataException ex) { Console.WriteLine(ex.Message); throw new ApplicationException(Messeges.GetMessage("DatabaseException"), ex); } catch (SqlException ex) { Console.WriteLine(ex.Message); throw new ApplicationException(Messeges.GetMessage("SqlException"), ex); } catch (Exception ex) { Console.WriteLine(ex.Message); throw new ApplicationException(Messeges.GetMessage("Exception"), ex); } finally { myConnection.Close(); } return(false); }
public Boolean AddNewLineItem(Product product, VendorSourceItem vendorSrcItem, int caseAmt) { if (product == null) { throw new ArgumentNullException("Product is null"); } if (vendorSrcItem == null) { throw new ArgumentNullException("VendorSourceItem is null"); } Reorder addOrder = new Reorder(); addOrder.Product = product; addOrder.VendorSourceItem = vendorSrcItem; addOrder.ShouldReorder = true; addOrder.CasesToOrder = caseAmt; addOrder.ReorderTotal = GetReorderRowTotal(addOrder); return(true); //throw new NotImplementedException(); }
//Deletes VendorSourceItem, Two Step delete. public static bool DeleteVendorSourceItem(VendorSourceItem vendorSrcItem, SqlConnection myConnection) { myConnection = myConnection ?? GetInventoryDbConnection(); try { var mySqlCommand = new SqlCommand("proc_DeleteVendorSourceItem", myConnection) { CommandType = CommandType.StoredProcedure }; mySqlCommand.Parameters.AddWithValue("@productID", vendorSrcItem.ProductID); mySqlCommand.Parameters.AddWithValue("@vendorID", vendorSrcItem.VendorID); myConnection.Open(); if (mySqlCommand.ExecuteNonQuery() == 1) { return(true); } } catch (DataException ex) { Console.WriteLine(ex.Message); throw new ApplicationException(Messeges.GetMessage("DatabaseException"), ex); } catch (SqlException ex) { Console.WriteLine(ex.Message); throw new ApplicationException(Messeges.GetMessage("SqlException"), ex); } catch (Exception ex) { Console.WriteLine(ex.Message); throw new ApplicationException(Messeges.GetMessage("Exception"), ex); } finally { myConnection.Close(); } return(false); }
} // end GetReorderReportData(.) public static Reorder GetProductToReorder(string productName) { // List<Reorder> reorders = new List<Reorder>(); Reorder order = new Reorder(); SqlConnection conn = GetInventoryDbConnection(); try { conn.Open(); SqlCommand sqlCmd = new SqlCommand("proc_GetProductToReorder", conn); sqlCmd.CommandType = CommandType.StoredProcedure; sqlCmd.Parameters.AddWithValue("@shortDesc", productName); SqlDataReader reader = sqlCmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { var product = new Product(reader.GetInt32(0)) { Name = reader.GetString(reader.GetOrdinal("ShortDesc")), _reorderThreshold = reader.GetInt32(reader.GetOrdinal("ReorderThreshold")), _reorderAmount = reader.GetInt32(reader.GetOrdinal("ReorderAmount")), Active = true }; order.Product = product; var vendorSrcItem = new VendorSourceItem(reader.GetInt32(reader.GetOrdinal("ProductID")), reader.GetInt32(reader.GetOrdinal("VendorID"))) { UnitCost = (Decimal)reader.GetSqlMoney(reader.GetOrdinal("UnitCost")), MinQtyToOrder = reader.GetInt32(reader.GetOrdinal("MinQtyToOrder")), ItemsPerCase = reader.GetInt32(reader.GetOrdinal("ItemsPerCase")), Active = true }; order.CasesToOrder = (int)product._reorderAmount / vendorSrcItem.ItemsPerCase + (product._reorderAmount % vendorSrcItem.ItemsPerCase == 0 ? 0 : 1); order.ReorderTotal = (double)order.CasesToOrder * (double)vendorSrcItem.ItemsPerCase * (double)vendorSrcItem.UnitCost; order.ShouldReorder = true; order.VendorSourceItem = vendorSrcItem; } } reader.Close(); } catch (DataException ex) { Console.WriteLine(ex.Message); throw new ApplicationException(Messeges.GetMessage("DatabaseException"), ex); } catch (SqlException ex) { Console.WriteLine(ex.Message); throw new ApplicationException(Messeges.GetMessage("SqlException"), ex); } catch (Exception ex) { Console.WriteLine(ex.Message); throw new ApplicationException(Messeges.GetMessage("Exception"), ex); } finally { conn.Close(); } return(order); }
public Boolean DeleteVendorSourceItem(VendorSourceItem vendorSrcItem) { return(VendorSourceItemDAL.DeleteVendorSourceItem(vendorSrcItem, _connection)); }
public Boolean ReactivateVendorSourceItem(VendorSourceItem vendorSrcItem) { return(VendorSourceItemDAL.ReactivateVendorSourceItem(vendorSrcItem, _connection)); }
public Boolean UpdateVendorSourceItem(VendorSourceItem vendorSrcItem, VendorSourceItem origVendorSrcItem) { return(VendorSourceItemDAL.UpdateVendorSourceItem(vendorSrcItem, origVendorSrcItem, _connection)); }
public Boolean AddVendorSourceItem(VendorSourceItem vendorSrcItem) { //Do error checking here return(VendorSourceItemDAL.AddVendorSourceItem(vendorSrcItem, _connection)); }